Ejemplo n.º 1
0
    def doIt(self, args):
        """
        Print string to the console.
        """
        try:
            argData = om.MArgDatabase(
                self.syntax(),
                args)  # if this fails, it will raise its own exception...
        except:
            print "failed..."
            pass  # ...so we can just pass here
        else:
            print "converting..."
            # get the active selection
            selection = om.MSelectionList()
            om.MGlobal.getActiveSelectionList(selection)
            iterSel = om.MItSelectionList(selection, om.MFn.kMesh)
            if argData.isFlagSet(MP_WriteMeshCmd.kVoxelSizeFlag):
                self.__voxelSize = argData.flagArgumentDouble(
                    MP_WriteMeshCmd.kVoxelSizeFlag, 0)
            if argData.isFlagSet(MP_WriteMeshCmd.kFileNameFlag):
                self.__fileName = argData.flagArgumentString(
                    MP_WriteMeshCmd.kFileNameFlag, 0)
            # go through selection
            while not iterSel.isDone():

                # get dagPath
                dagPath = om.MDagPath()
                iterSel.getDagPath(dagPath)

                # create empty point array
                inMeshMPointArray = om.MPointArray()
                # create empy normal array
                inMeshMNormalArray = om.MFloatVectorArray()
                # create function set and get points and normals in world space
                currentInMeshMFnMesh = om.MFnMesh(dagPath)
                currentInMeshMFnMesh.getPoints(inMeshMPointArray,
                                               om.MSpace.kWorld)
                currentInMeshMFnMesh.getNormals(inMeshMNormalArray,
                                                om.MSpace.kWorld)
                #get the number of faces for the selection
                numFaces = currentInMeshMFnMesh.numPolygons()
                normalList = []
                faceList = []
                #get normals
                for i in range(0, numFaces):
                    normal = om.MVector()
                    currentInMeshMFnMesh.getPolygonNormal(
                        i, normal, om.MFn.kMesh)
                    normal = normal.normal()
                    normalList.append(
                        [str(normal[0]),
                         str(normal[1]),
                         str(normal[2])])

                #get faces
                for i in range(0, numFaces):
                    vertexL = om.MIntArray()
                    currentInMeshMFnMesh.getPolygonVertices(i, vertexL)
                    vertices = []
                    for n in range(vertexL.length()):
                        vertices.append(str(vertexL[n] + 1))
                        faceList.append(vertices)
                        # put each point to a list
                pointList = []
                for i in range(inMeshMPointArray.length()):
                    pointList.append([
                        str(inMeshMPointArray[i][0]),
                        str(inMeshMPointArray[i][1]),
                        str(inMeshMPointArray[i][2])
                    ])
                # return the vertices, normals and faces
                omesh_cube = vdbout.VDBOutputMesh()
                meshspec = mepo.MeshSpec()
                meshspec.voxelSize = self.__voxelSize
                omesh_cube.loadMesh(mepo.getPythonList(pointList),
                                    mepo.getPythonList(normalList),
                                    mepo.getPythonList(faceList), meshspec)
                omesh_cube.writeMesh(str(self.__fileName))
                print("Wrote mesh %s" % self.__fileName)

                return [pointList, normalList, faceList]
Ejemplo n.º 2
0
print "Example 1: agripa obj to agripa vdb"
#imesh = LoadMesh("/home/kcoley/projects/MeshPotato/examples/testOBJ/ajax.obj")
#omesh = WriteMesh(imesh, "vdbtest.vdb")
print "Done Conversion!"
imesh = LoadMesh("smoothAgripa.obj")
omesh = WriteMesh(imesh, "newagripaSmooth.vdb")
#imesh = LoadMesh("/home/kcoley/projects/MeshPotato/examples/testOBJ/ajax.vdb")
#imesh.loadMesh("/home/kcoley/projects/MeshPotato/examples/testOBJ/ajax.vdb")

print "Printing number of vertices"
print imesh.getNumberVertices()
omesh = vdbout.VDBOutputMesh()

vertices = [["0", "0", "0"], ["0", "0", "1"], ["0", "1", "0"], ["0", "1", "1"],
            ["1", "0", "0"], ["1", "0", "1"], ["1", "1", "0"], ["1", "1", "1"]]
normals = [["0", "0", "1"], ["0", "0", "-1"], ["0", "1", "0"],
           ["0", "-1", "0"], ["1", "0", "0"], ["-1", "0", "0"]]
faces = [["1", "7", "5"], ["1", "3", "7"], ["1", "4", "3"], ["1", "2", "4"],
         ["3", "8", "7"], ["3", "4", "8"], ["5", "7", "8"], ["5", "8", "6"],
         ["1", "5", "6"], ["1", "6", "2"], ["2", "6", "8"], ["2", "8", "4"]]
print "Done Conversion!"

print "Example 2: Manual conversion of cube"
omesh_cube = vdbout.VDBOutputMesh()
omesh_cube.loadMesh(mepo.getPythonList(vertices), mepo.getPythonList(normals),
                    mepo.getPythonList(faces), mepo.MeshSpec())
omesh_cube.writeMesh("cube.vdb")

print "Done Manual Conversion for cube!"
Ejemplo n.º 3
0
    def doIt(self, args):
        """
        Print string to the console.
        """
        try: argData = om.MArgDatabase(self.syntax(), args) # if this fails, it will raise its own exception...
        except:
            print "failed..." 
            pass # ...so we can just pass here
        else:
            print "converting..."
            # get the active selection
            selection = om.MSelectionList()
            om.MGlobal.getActiveSelectionList( selection )
            iterSel = om.MItSelectionList(selection, om.MFn.kMesh)
            if argData.isFlagSet(MP_WriteMeshCmd.kVoxelSizeFlag):
                self.__voxelSize = argData.flagArgumentDouble(MP_WriteMeshCmd.kVoxelSizeFlag, 0)
            if argData.isFlagSet(MP_WriteMeshCmd.kFileNameFlag):
                self.__fileName = argData.flagArgumentString(MP_WriteMeshCmd.kFileNameFlag, 0)
            # go through selection
            while not iterSel.isDone():
     
                # get dagPath
                dagPath = om.MDagPath()
                iterSel.getDagPath( dagPath )
     
                # create empty point array
                inMeshMPointArray = om.MPointArray()
                # create empy normal array
                inMeshMNormalArray = om.MFloatVectorArray() 
                # create function set and get points and normals in world space
                currentInMeshMFnMesh = om.MFnMesh(dagPath)
                currentInMeshMFnMesh.getPoints(inMeshMPointArray, om.MSpace.kWorld)
                currentInMeshMFnMesh.getNormals(inMeshMNormalArray, om.MSpace.kWorld)
                #get the number of faces for the selection
                numFaces = currentInMeshMFnMesh.numPolygons() 
                normalList = []
                faceList = []
                #get normals
                for i in range(0,numFaces):
                    normal = om.MVector()
                    currentInMeshMFnMesh.getPolygonNormal(i, normal, om.MFn.kMesh)
                    normal = normal.normal()
                    normalList.append([str(normal[0]), str(normal[1]), str(normal[2])])

                #get faces
                for i in range(0, numFaces):
                    vertexL = om.MIntArray()
                    currentInMeshMFnMesh.getPolygonVertices(i, vertexL)
                    vertices = []
                    for n in range(vertexL.length()):
                        vertices.append(str(vertexL[n] + 1))
                        faceList.append(vertices)
                        # put each point to a list
                pointList = []
                for i in range( inMeshMPointArray.length() ) :
                    pointList.append( [str(inMeshMPointArray[i][0]), str(inMeshMPointArray[i][1]), str(inMeshMPointArray[i][2])] )
                # return the vertices, normals and faces
                omesh_cube = vdbout.VDBOutputMesh()
                meshspec = mepo.MeshSpec()
                meshspec.voxelSize = self.__voxelSize
                omesh_cube.loadMesh(mepo.getPythonList(pointList), mepo.getPythonList(normalList), mepo.getPythonList(faceList), meshspec)
                omesh_cube.writeMesh(str(self.__fileName))
                print("Wrote mesh %s" % self.__fileName)

                return [pointList, normalList, faceList]
Ejemplo n.º 4
0
	["1","1","1"]
]
normals = [["0","0","1"],
	["0","0","-1"],
	["0","1","0"],
	["0","-1","0"],
	["1","0","0"],
	["-1","0","0"]
]
faces = [["1","7","5"],
	["1","3","7"],
	["1","4","3"],
	["1","2","4"],
	["3","8","7"],
	["3","4","8"],
	["5","7","8"],
	["5","8","6"],
	["1","5","6"],
	["1","6","2"],
	["2","6","8"],
	["2","8","4"]
]
print "Done Conversion!"

print "Example 2: Manual conversion of cube"
omesh_cube = vdbout.VDBOutputMesh()
omesh_cube.loadMesh(mepo.getPythonList(vertices), mepo.getPythonList(normals), mepo.getPythonList(faces), mepo.MeshSpec())
omesh_cube.writeMesh("cube.vdb")

print "Done Manual Conversion for cube!"