Skip to content

Commit

Permalink
Use the correct normals for maya exports with more than one mesh
Browse files Browse the repository at this point in the history
Includes a few other minor refactorings. Fixes #5252
  • Loading branch information
sgrif committed Sep 2, 2014
1 parent 220475b commit 973096d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions utils/exporters/maya/plug-ins/threeJsFileTranslator.py
Expand Up @@ -30,6 +30,7 @@ def write(self, path, optionString, accessMode):

self.verticeOffset = 0
self.uvOffset = 0
self.normalOffset = 0
self.vertices = []
self.materials = []
self.faces = []
Expand Down Expand Up @@ -128,6 +129,7 @@ def _exportMesh(self, mesh):
self._exportFaces(mesh)
self.verticeOffset += len(mesh.getPoints())
self.uvOffset += mesh.numUVs()
self.normalOffset += mesh.numNormals()
if self.options['normals']:
print("Exporting normals")
self._exportNormals(mesh)
Expand All @@ -141,7 +143,7 @@ def _getMaterialIndex(self, face, mesh):

if self.options['materials']:
for engine in mesh.listConnections(type='shadingEngine'):
if sets(engine, isMember=face):
if sets(engine, isMember=face) or sets(engine, isMember=mesh):
for material in engine.listConnections(type='lambert'):
if self._materialIndices.has_key(material.name()):
return self._materialIndices[material.name()]
Expand Down Expand Up @@ -204,7 +206,7 @@ def _exportFaceBitmask(self, face, typeBitmask, hasMaterial=True):

def _exportFaceVertexNormals(self, face):
for i in range(face.polygonVertexCount()):
self.faces.append(face.normalIndex(i))
self.faces.append(face.normalIndex(i) + self.normalOffset)

def _exportNormals(self, mesh):
for normal in mesh.getNormals():
Expand Down Expand Up @@ -268,9 +270,11 @@ def _exportSpecularMap(self, result, mat):
self._exportFile(result, f, "Specular")

def _exportFile(self, result, mapFile, mapType):
fName = os.path.basename(mapFile.ftn.get())
src = mapFile.ftn.get()
targetDir = os.path.dirname(self.path)
fName = os.path.basename(src)
if self.options['copyTextures']:
shutil.copy2(mapFile.ftn.get(), os.path.dirname(self.path) + "/" + fName)
shutil.copy2(src, os.path.join(targetDir, fName))
result["map" + mapType] = fName
result["map" + mapType + "Repeat"] = [1, 1]
result["map" + mapType + "Wrap"] = ["repeat", "repeat"]
Expand Down

0 comments on commit 973096d

Please sign in to comment.