def _collectNewFaces(mesh): newMesh=Mesh() for face in mesh.faces: v1 = face.vertices[-2] v2 = face.vertices[-1] for v3 in face.vertices: edge1 = mesh.getEdgeAdjacentToVertices(v1,v2) edge2 = mesh.getEdgeAdjacentToVertices(v2,v3) if (edge1 != None) and (edge2!= None): newFace = Face([edge1.vertex, v2.vertex, edge2.vertex, face.vertex]) newFace.color = face.color newFace.group = face.group newMesh.faces.append(newFace) v1 = v2 v2 = v3 newMesh.updateAdjacencies() return newMesh
def importOBJ(filename): """Loads a Wavefront OBJ file. """ mesh = Mesh() group = "" for line in open(filename, "r"): if line.startswith('#'): continue values = line.split() if not values: continue if values[0] == 'g': group = values[1] elif values[0] == 'v': v = [float(c) for c in values[1:4]] #v = map(float, values[1:4]) mesh.vertices.append(Vertex(v[0], v[1], v[2])) elif values[0] == 'f': face = Face([]) face.group = group for v in values[1:]: w = v.split('/') vertex = mesh.vertices[int(w[0]) - 1] face.vertices.append(vertex) mesh.faces.append(face) return mesh