From: daid303 Date: Fri, 11 Jan 2013 12:45:00 +0000 (+0100) Subject: Fixing issue #319 - OBJ support with quads instead of triangles. X-Git-Tag: 13.03~110 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f46ab19979aeca07fabc8a3cc7c8fe39e9b24e21;p=cura.git Fixing issue #319 - OBJ support with quads instead of triangles. --- diff --git a/Cura/slice/cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/obj.py b/Cura/slice/cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/obj.py index 493062f6..2a479b30 100644 --- a/Cura/slice/cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/obj.py +++ b/Cura/slice/cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/obj.py @@ -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." diff --git a/Cura/util/obj.py b/Cura/util/obj.py index f2261c10..d6b2cd7d 100644 --- a/Cura/util/obj.py +++ b/Cura/util/obj.py @@ -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)