if firstWord == 'v':
triangleMesh.vertexes.append( getVertexGivenLine(line) )
elif firstWord == 'f':
- triangleMesh.faces.append( getFaceGivenLine( line, triangleMesh ) )
+ addFacesGivenLine( triangleMesh.faces, line )
def getCarving(fileName=''):
"Get the triangle mesh for the obj file."
addFacesGivenText(objText, triangleMesh)
return triangleMesh
-def getFaceGivenLine( line, triangleMesh ):
+def addFacesGivenLine( faces, line ):
"Add face given line index and lines."
- faceGivenLine = face.Face()
- faceGivenLine.index = len( triangleMesh.faces )
- splitLine = line.split()
- for vertexStringIndex in xrange( 1, 4 ):
- vertexString = splitLine[ vertexStringIndex ]
- vertexStringWithSpaces = vertexString.replace('/', ' ')
- vertexStringSplit = vertexStringWithSpaces.split()
- vertexIndex = int( vertexStringSplit[0] ) - 1
- faceGivenLine.vertexIndexes.append(vertexIndex)
- return faceGivenLine
+ parts = map(lambda p: p.split('/')[0], line.split())
+ for idx in xrange(1, len(parts)-2):
+ addface = face.Face()
+ addface.index = len( faces )
+ addface.vertexIndexes.append(int(parts[1]) - 1)
+ addface.vertexIndexes.append(int(parts[idx+1]) - 1)
+ addface.vertexIndexes.append(int(parts[idx+2]) - 1)
+ faces.append(addface)
def getVertexGivenLine(line):
"Get vertex given obj vertex line."
if parts[0] == 'v':
vertexList.append([float(parts[1]), float(parts[2]), float(parts[3])])
if parts[0] == 'f':
- parts[1] = parts[1].split('/')[0]
- parts[2] = parts[2].split('/')[0]
- parts[3] = parts[3].split('/')[0]
- faceList.append([int(parts[1]), int(parts[2]), int(parts[3])])
+ parts = map(lambda p: p.split('/')[0], parts)
+ for idx in xrange(1, len(parts)-2):
+ faceList.append([int(parts[1]), int(parts[idx+1]), int(parts[idx+2])])
f.close()
self._prepareVertexCount(len(faceList) * 3)