refactored variables initialization

This commit is contained in:
MattiaPezzanoAiv 2018-05-17 11:30:39 +02:00
parent 8c88b5b2c8
commit f16ab8b767

View File

@ -4,6 +4,7 @@ import maya.api.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx import maya.OpenMayaMPx as OpenMayaMPx
from draco_maya_wrapper import Draco from draco_maya_wrapper import Draco
from draco_maya_wrapper import DrcMesh
__author__ = "Mattia Pezzano, Federico de Felici, Duccio Lenkowicz" __author__ = "Mattia Pezzano, Federico de Felici, Duccio Lenkowicz"
__version__ = "0.1" __version__ = "0.1"
@ -29,7 +30,6 @@ class DracoTranslator(OpenMayaMPx.MPxFileTranslator):
def writer(self, fileObject, optionString, accessMode): def writer(self, fileObject, optionString, accessMode):
# Get the selection and create a selection list of all the nodes meshes # Get the selection and create a selection list of all the nodes meshes
selection = OpenMaya.MSelectionList()
selection = OpenMaya.MGlobal.getActiveSelectionList() selection = OpenMaya.MGlobal.getActiveSelectionList()
# Create an MItSelectionList class to iterate over the selection # Create an MItSelectionList class to iterate over the selection
@ -48,11 +48,9 @@ class DracoTranslator(OpenMayaMPx.MPxFileTranslator):
connectedPolyList = [] connectedPolyList = []
# get dag path of current iterated selection # get dag path of current iterated selection
dagPath = OpenMaya.MDagPath()
dagPath = iter.getDagPath() dagPath = iter.getDagPath()
# get the selection as an MObject # get the selection as an MObject
mObj = OpenMaya.MObject()
mObj = iter.getDependNode() mObj = iter.getDependNode()
# create iterator of current mesh polygons # create iterator of current mesh polygons
@ -65,10 +63,9 @@ class DracoTranslator(OpenMayaMPx.MPxFileTranslator):
polyList.append(polygonsIterator.index()) polyList.append(polygonsIterator.index())
# Get current polygons vertices # Get current polygons vertices
verts = OpenMaya.MIntArray()
verts = polygonsIterator.getVertices() verts = polygonsIterator.getVertices()
normalIndices = [] #normalIndices = []
# Append the current polygons vertex indices # Append the current polygons vertex indices
for i in range(len(verts)): for i in range(len(verts)):
vertexList.append(verts[i]) vertexList.append(verts[i])
@ -80,7 +77,6 @@ class DracoTranslator(OpenMayaMPx.MPxFileTranslator):
# normalIndices.append(polygonsIterator.normalIndex(vertex)) #return the index in the normals buffer # normalIndices.append(polygonsIterator.normalIndex(vertex)) #return the index in the normals buffer
# Get current polygons edges # Get current polygons edges
edges = OpenMaya.MIntArray()
edges = polygonsIterator.getEdges() edges = polygonsIterator.getEdges()
# Append the current polygons edge indices # Append the current polygons edge indices
@ -88,7 +84,6 @@ class DracoTranslator(OpenMayaMPx.MPxFileTranslator):
edgeList.append(edges[i]) edgeList.append(edges[i])
# Get current polygons connected faces # Get current polygons connected faces
indexConnectedFaces = OpenMaya.MIntArray()
indexConnectedFaces = polygonsIterator.getConnectedFaces() indexConnectedFaces = polygonsIterator.getConnectedFaces()
# Append the connected polygons indices # Append the connected polygons indices
@ -96,8 +91,6 @@ class DracoTranslator(OpenMayaMPx.MPxFileTranslator):
connectedPolyList.append(indexConnectedFaces[i]) connectedPolyList.append(indexConnectedFaces[i])
# Get current polygons triangles # Get current polygons triangles
pointArray = OpenMaya.MPointArray()
intArray = OpenMaya.MIntArray()
space = OpenMaya.MSpace.kObject space = OpenMaya.MSpace.kObject
# Get the vertices and vertex positions of all the triangles in the current face's triangulation. # Get the vertices and vertex positions of all the triangles in the current face's triangulation.
@ -110,6 +103,8 @@ class DracoTranslator(OpenMayaMPx.MPxFileTranslator):
# next poligon # next poligon
polygonsIterator.next(None) # idk what arguments i need to pass here polygonsIterator.next(None) # idk what arguments i need to pass here
print(fileObject.fullName())
drcMesh = DrcMesh() drcMesh = DrcMesh()
drcMesh.faces_num = len(polytriVertsList) / 3 drcMesh.faces_num = len(polytriVertsList) / 3
drcMesh.faces_len = len(polytriVertsList) drcMesh.faces_len = len(polytriVertsList)
@ -120,7 +115,7 @@ class DracoTranslator(OpenMayaMPx.MPxFileTranslator):
drcMesh.vertices = vertexList drcMesh.vertices = vertexList
draco = Draco() draco = Draco()
draco.encode(drcMesh, fileObject) draco.encode(drcMesh, fileObject.fullName())
# print data for current selection being iterated on, # print data for current selection being iterated on,
print ("Object name: {}".format(dagPath.fullPathName())) print ("Object name: {}".format(dagPath.fullPathName()))
@ -152,10 +147,11 @@ class DracoTranslator(OpenMayaMPx.MPxFileTranslator):
normals.append(OpenMaya.MFloatVector(mesh.normals[i], mesh.normals[i + 1], mesh.normals[i + 2])) normals.append(OpenMaya.MFloatVector(mesh.normals[i], mesh.normals[i + 1], mesh.normals[i + 2]))
if mesh.uvs: if mesh.uvs:
i = 2 * n i = 2 * n
us.append(mesh.uvs[i]) us.append(float(mesh.uvs[i]))
vs.append(mesh.uvs[i + 1]) vs.append(float(mesh.uvs[i + 1]))
#indices #indices
#TODO: verify if index array is effectively useful (we can use directly mesh.faces?)
indices = [] indices = []
for index in mesh.faces: for index in mesh.faces:
indices.append(index) indices.append(index)