Ejemplo n.º 1
0
	def test_miss_voxel(self):
		self.assertEqual(PolyVoxCore.raycastWithEndpointsSimpleVolumeuint8(self.vol, PolyVoxCore.Vector3Dfloat(0,0,0), PolyVoxCore.Vector3Dfloat(0,31,31), test_functor), 0)
def sv_main(vol_region=32, sphere_radius=30):
    in_sockets = [['s', 'Volume region', vol_region],
                  ['s', 'Sphere radius', sphere_radius]]

    #Create a 64x64x64 volume of integers
    volume = vol_region - 1

    r = pv.Region(pv.Vector3Dint32_t(0, 0, 0),
                  pv.Vector3Dint32_t(volume, volume, volume))
    vol = pv.SimpleVolumeuint8(r)

    #Now fill the volume with our data (a sphere)
    v3dVolCenter = pv.Vector3Dint32_t(vol.getWidth() // 2,
                                      vol.getHeight() // 2,
                                      vol.getDepth() // 2)
    sphereRadius = sphere_radius
    #print(sphere_radius)
    #This three-level for loop iterates over every voxel in the volume
    for z in range(vol.getDepth()):
        for y in range(vol.getHeight()):
            for x in range(vol.getWidth()):

                #compute Noise so we add to the distance field
                plusFactor = noise.fractal(Vector(
                    (x, y, z)), 0.25, 0.75, 3, 1) * 6.0
                #print(plusFactor)

                #Compute how far the current position is from the center of the volume
                fDistToCenter = (pv.Vector3Dint32_t(x, y, z) -
                                 v3dVolCenter).length()
                #print(fDistToCenter)

                #If the current voxel is less than 'radius' units from the center then we make it solid.

                #if(fDistToCenter + plusFactor <= sphereRadius + (noise.random()*3)):
                if (fDistToCenter + plusFactor <= sphereRadius):
                    #Our new voxel value
                    uVoxelValue = 255
                else:
                    uVoxelValue = 0

                #Write the voxel value into the volume
                #print(uVoxelValue)
                vol.setVoxelAt(x, y, z, uVoxelValue)

    #Create a mesh, pass it to the extractor and generate the mesh
    mesh = pv.SurfaceMeshPositionMaterialNormal()
    extractor = pv.CubicSurfaceExtractorWithNormalsSimpleVolumeuint8(
        vol, r, mesh)
    extractor.execute()

    #That's all of the PolyVox generation done, now to convert the output to something OpenGL can read efficiently

    vertices = []
    verts_out = []

    #Throw in the vertex indices into an array
    indices = mesh.getIndices()
    Nindx = mesh.getNoOfIndices()

    #uncomment the line above for testing pourpose only
    #print("Indices: " + str(indices))
    #print("N. of Indices: " + str(Nindx))

    for vertex in mesh.getVertices():

        p = vertex.getPosition()

        vertices.append(tuple([p.getX(), p.getY(), p.getZ()]))

    verts_out.append(vertices)

    #uncomment the line above for testing pourpose only
    #print("Vertices: " + str(vertices))
    #print("N. vert: " + str(mesh.getNoOfVertices()))

    Tris = [(indices[i:i + 3]) for i in range(0, len(indices) - 1, 3)]

    out_sockets = [
        ['v', 'Verts', [verts_out]],
        ['s', 'Tris', [Tris]],
    ]

    #verts_out.append(vertices)

    return in_sockets, out_sockets
def sv_main(uVoxelValue=[], vol_region=4):
    in_sockets = [['s', 'Voxel value', uVoxelValue],
                  ['s', 'Volume region', vol_region]]
    #64 voxels values as volume region of 4x4x4 (for testing pourpose)
    #uVoxelValue=[[0, 255, 255, 0, 255, 255, 255, 255, 255, 255, 255, 0, 0, 255, 0, 0, 0, 0, 0, 255, 0, 255, 255, 0, 0, 255, 255, 255, 255, 0, 255, 0, 255, 0, 255, 255, 0, 255, 255, 0, 0, 255, 0, 255, 255, 255, 255, 255, 0, 255, 0, 255, 255, 255, 255, 0, 255, 0, 0, 255, 255, 0, 255, 0]]

    #print(len(voxel_value[0]))
    print("Voxel_value inside_script: {0}".format(uVoxelValue))

    #Create a volume of integers
    volume = vol_region - 1

    r = pv.Region(pv.Vector3Dint32_t(0, 0, 0),
                  pv.Vector3Dint32_t(volume, volume, volume))

    vol = pv.SimpleVolumeuint8(r)
    #Now fill the volume with our data
    #v3dVolCenter = pv.Vector3Dint32_t(vol.getWidth() // 2, vol.getHeight() // 2, vol.getDepth() // 2)
    print(vol.getDepth() * vol.getHeight() * vol.getWidth())
    #This three-level for loop iterates over every voxel in the volume
    for z in range(vol.getDepth()):
        for y in range(vol.getHeight()):
            for x in range(vol.getWidth()):

                if uVoxelValue:
                    #print("ok")
                    vol.setVoxelAt(x, y, z, uVoxelValue[0][0][x * y * z])

    #Create a mesh, pass it to the extractor and generate the mesh
    mesh = pv.SurfaceMeshPositionMaterialNormal()
    extractor = pv.CubicSurfaceExtractorWithNormalsSimpleVolumeuint8(
        vol, r, mesh)
    extractor.execute()

    #That's all of the PolyVox generation done, now to convert the output to something OpenGL can read efficiently

    vertices = []
    verts_out = []

    #Throw in the vertex indices into an array
    indices = mesh.getIndices()
    Nindx = mesh.getNoOfIndices()

    #uncomment the line above for testing pourpose only
    #print("Indices: " + str(indices))
    #print("N. of Indices: " + str(Nindx))

    for vertex in mesh.getVertices():

        p = vertex.getPosition()

        vertices.append(tuple([p.getX(), p.getY(), p.getZ()]))

    verts_out.append(vertices)

    #uncomment the line above for testing pourpose only
    #print("Vertices: " + str(vertices))
    #print("N. vert: " + str(mesh.getNoOfVertices()))

    Tris = [(indices[i:i + 3]) for i in range(0, len(indices) - 1, 3)]

    out_sockets = [
        ['v', 'Verts', [verts_out]],
        ['s', 'Tris', [Tris]],
    ]

    #verts_out.append(vertices)

    return in_sockets, out_sockets
def sv_main(
    vol_region=64,
    h_factor=1.0,
    lacunarity=1.5,
    octaves=3,
):
    in_sockets = [['s', 'Volume region', vol_region],
                  ['s', 'H Factor ', h_factor],
                  ['s', 'lacunarity', lacunarity], ['s', 'octaves', octaves]]

    #Create a volume of integers
    volume = vol_region - 1
    #volume = 32
    r = pv.Region(pv.Vector3Dint32_t(0, 0, 0),
                  pv.Vector3Dint32_t(volume, volume, volume))
    vol = pv.SimpleVolumeuint8(r)

    #This three-level for loop iterates over every voxel in the volume
    createPerlinTerrain(vol, h_factor, lacunarity, octaves)
    print("terain: Done! > let's go w the extractor...")
    #Create a mesh, pass it to the extractor and generate the mesh
    mesh = pv.SurfaceMeshPositionMaterialNormal()
    extractor = pv.CubicSurfaceExtractorWithNormalsSimpleVolumeuint8(
        vol, r, mesh)
    extractor.execute()

    #That's all of the PolyVox generation done, now to convert the output to something OpenGL can read efficiently

    vertices = []
    verts_out = []

    #Throw in the vertex indices into an array
    indices = mesh.getIndices()
    Nindx = mesh.getNoOfIndices()

    #uncomment the line above for testing pourpose only
    #print("Indices: " + str(indices))
    #print("N. of Indices: " + str(Nindx))

    for vertex in mesh.getVertices():

        p = vertex.getPosition()

        vertices.append(tuple([p.getX(), p.getY(), p.getZ()]))

    verts_out.append(vertices)

    #uncomment the line above for testing pourpose only
    #print("Vertices: " + str(vertices))
    #print("N. vert: " + str(mesh.getNoOfVertices()))

    Tris = [(indices[i:i + 3]) for i in range(0, len(indices) - 1, 3)]

    out_sockets = [
        ['v', 'Verts', [verts_out]],
        ['s', 'Tris', [Tris]],
    ]

    #verts_out.append(vertices)

    return in_sockets, out_sockets
Ejemplo n.º 5
0
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################

import sys
sys.path.append("../../library/bindings/"
                )  #This is just to point to the generated bindings

import PolyVoxCore as pv

#Create a 64x64x64 volume of integers
r = pv.Region(pv.Vector3Dint32_t(0, 0, 0), pv.Vector3Dint32_t(63, 63, 63))
vol = pv.SimpleVolumeuint8(r)

#Now fill the volume with our data (a sphere)
v3dVolCenter = pv.Vector3Dint32_t(vol.getWidth() // 2,
                                  vol.getHeight() // 2,
                                  vol.getDepth() // 2)
sphereRadius = 30
#This three-level for loop iterates over every voxel in the volume
for z in range(vol.getDepth()):
    for y in range(vol.getHeight()):
        for x in range(vol.getWidth()):
            #Compute how far the current position is from the center of the volume
            fDistToCenter = (pv.Vector3Dint32_t(x, y, z) -
                             v3dVolCenter).length()
Ejemplo n.º 6
0
 def test_miss_voxel(self):
     self.assertEqual(
         PolyVoxCore.raycastWithEndpointsSimpleVolumeuint8(
             self.vol, PolyVoxCore.Vector3Dfloat(0, 0, 0),
             PolyVoxCore.Vector3Dfloat(0, 31, 31), test_functor), 0)