mirror of
https://git.mirrors.martin98.com/https://github.com/google/draco
synced 2025-08-12 02:09:01 +08:00
added preliminar implementation of write method
This commit is contained in:
parent
42e1a46f04
commit
b958fac85c
@ -16,7 +16,7 @@ class DracoTranslator(OpenMayaMPx.MPxFileTranslator):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def haveWriteMethod(self):
|
def haveWriteMethod(self):
|
||||||
return False
|
return True
|
||||||
|
|
||||||
def haveReadMethod(self):
|
def haveReadMethod(self):
|
||||||
return True
|
return True
|
||||||
@ -27,6 +27,118 @@ class DracoTranslator(OpenMayaMPx.MPxFileTranslator):
|
|||||||
def defaultExtension(self):
|
def defaultExtension(self):
|
||||||
return "drc"
|
return "drc"
|
||||||
|
|
||||||
|
def writer(self, fileObject, optionString, accessMode):
|
||||||
|
# Get the selection and create a selection list of all the nodes meshes
|
||||||
|
selection = OpenMaya.MSelectionList()
|
||||||
|
OpenMaya.MGlobal.getActiveSelectionList(selection)
|
||||||
|
|
||||||
|
# Create an MItSelectionList class to iterate over the selection
|
||||||
|
# Use the MFn class to as a filter to filter node types
|
||||||
|
iter = OpenMaya.MItSelectionList(selection, OpenMaya.MFn.kGeometric)
|
||||||
|
|
||||||
|
# This uses built in functions of the MItSelectionList class to loop through the list of objects
|
||||||
|
# NB: isn't a basic array, you must use the built in functions
|
||||||
|
while not iter.isDone(): # iterate selection
|
||||||
|
|
||||||
|
vertexList = []
|
||||||
|
normalList = []
|
||||||
|
edgeList = []
|
||||||
|
polytriVertsList = []
|
||||||
|
polyList = []
|
||||||
|
connectedPolyList = []
|
||||||
|
|
||||||
|
# get dag path of current iterated selection
|
||||||
|
dagPath = OpenMaya.MDagPath()
|
||||||
|
iter.getDagPath(dagPath)
|
||||||
|
|
||||||
|
# get the selection as an MObject
|
||||||
|
mObj = OpenMaya.MObject()
|
||||||
|
iter.getDependNode(mObj)
|
||||||
|
|
||||||
|
# create iterator of current mesh polygons
|
||||||
|
polygonsIterator = OpenMaya.MItMeshPolygon(mObj)
|
||||||
|
|
||||||
|
# Iterate through polygons on current mesh
|
||||||
|
while not polygonsIterator.isDone():
|
||||||
|
|
||||||
|
# Get current polygons index
|
||||||
|
polyList.append(polygonsIterator.index())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Get current polygons vertices
|
||||||
|
verts = OpenMaya.MIntArray()
|
||||||
|
polygonsIterator.getVertices(verts)
|
||||||
|
|
||||||
|
normalIndices = []
|
||||||
|
# Append the current polygons vertex indices
|
||||||
|
for i in range(verts.length()):
|
||||||
|
vertexList.append(verts[i])
|
||||||
|
normalIndices.append(polygonsIterator.normalIndex()) #return the index in the normals buffer
|
||||||
|
|
||||||
|
# Get current polygons normals
|
||||||
|
norms = OpenMaya.MVectorArray()
|
||||||
|
# polygonsIterator.getNormals(norms)
|
||||||
|
|
||||||
|
#Append current polygons normal indices
|
||||||
|
for index in normalIndices:
|
||||||
|
normalList.append(norms[index].x)
|
||||||
|
normalList.append(norms[index].y)
|
||||||
|
normalList.append(norms[index].z)
|
||||||
|
|
||||||
|
# Get current polygons edges
|
||||||
|
edges = OpenMaya.MIntArray()
|
||||||
|
polygonsIterator.getEdges(edges)
|
||||||
|
|
||||||
|
# Append the current polygons edge indices
|
||||||
|
for i in range(edges.length()):
|
||||||
|
edgeList.append(edges[i])
|
||||||
|
|
||||||
|
# Get current polygons connected faces
|
||||||
|
indexConnectedFaces = OpenMaya.MIntArray()
|
||||||
|
polygonsIterator.getConnectedFaces(indexConnectedFaces)
|
||||||
|
|
||||||
|
# Append the connected polygons indices
|
||||||
|
for i in range(indexConnectedFaces.length()):
|
||||||
|
connectedPolyList.append(indexConnectedFaces[i])
|
||||||
|
|
||||||
|
# Get current polygons triangles
|
||||||
|
pointArray = OpenMaya.MPointArray()
|
||||||
|
intArray = OpenMaya.MIntArray()
|
||||||
|
space = OpenMaya.MSpace.kObject
|
||||||
|
|
||||||
|
# Get the vertices and vertex positions of all the triangles in the current face's triangulation.
|
||||||
|
polygonsIterator.getTriangles(pointArray, intArray, space)
|
||||||
|
|
||||||
|
# Append vertices that are part of the triangles
|
||||||
|
for i in range(intArray.length()):
|
||||||
|
polytriVertsList.append(intArray[i])
|
||||||
|
|
||||||
|
# next poligon
|
||||||
|
polygonsIterator.next()
|
||||||
|
|
||||||
|
#TODO: CREATE DRACOMESH
|
||||||
|
drcMesh = DrcMesh()
|
||||||
|
drcMesh.faces_num = len(polytriVertsList) / 3
|
||||||
|
drcMesh.faces_len = len(polytriVertsList)
|
||||||
|
drcMesh.faces = polytriVertsList
|
||||||
|
|
||||||
|
drcMesh.vertices_num = len(vertexList) / 3
|
||||||
|
drcMesh.vertices_len = len(vertexList)
|
||||||
|
drcMesh.vertices = vertexList
|
||||||
|
|
||||||
|
# print data for current selection being iterated on,
|
||||||
|
print ("Object name: {}".format(dagPath.fullPathName()))
|
||||||
|
print ("Vertex list: {} size: {}".format(vertexList, len(vertexList)))
|
||||||
|
print ("Edge list: {} size: {}".format(edgeList, len(edgeList)))
|
||||||
|
print ("Poly Triangle Vertices: ***INDEX BUFFER*** {} size: {}".format(polytriVertsList,
|
||||||
|
len(polytriVertsList)))
|
||||||
|
print ("Polygon index list: {} size: {}".format(polyList, len(polyList)))
|
||||||
|
print ("Connected Polygons list: {} size: {}".format(connectedPolyList, len(connectedPolyList)))
|
||||||
|
|
||||||
|
# next selected
|
||||||
|
iter.next()
|
||||||
|
|
||||||
def reader(self, fileObject, optionString, accessMode):
|
def reader(self, fileObject, optionString, accessMode):
|
||||||
drc = Draco()
|
drc = Draco()
|
||||||
mesh = drc.decode(fileObject.fullName())
|
mesh = drc.decode(fileObject.fullName())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user