chiark / gitweb /
Fixing issue #319 - OBJ support with quads instead of triangles.
authordaid303 <daid303@gmail.com>
Fri, 11 Jan 2013 12:45:00 +0000 (13:45 +0100)
committerdaid303 <daid303@gmail.com>
Fri, 11 Jan 2013 12:45:00 +0000 (13:45 +0100)
Cura/slice/cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/obj.py
Cura/util/obj.py

index 493062f66e58eb44a3975aa7715ef3365250dcaa..2a479b304028cdbf150e243415c69c06899cbee1 100644 (file)
@@ -43,7 +43,7 @@ def addFacesGivenText( objText, triangleMesh ):
                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."
@@ -56,18 +56,16 @@ def getCarving(fileName=''):
        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."
index f2261c10dadd5865e75bd1878fd3f0914c151808..d6b2cd7ddde0b806d9db134d3334e0c854dc9a32 100644 (file)
@@ -18,10 +18,9 @@ class objModel(mesh.mesh):
                        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)