def offset(mesh,offset=1,doclose=True): newMesh=Mesh() # calculate vertex normals for vertex in mesh.vertices: vertex.vertex = Vertex(0,0,0) vertex.nfaces = 0 for face in mesh.faces: normal = faceUtils.normal(face) for vertex in face.vertices: vertex.vertex.add(normal) vertex.nfaces += 1 for vertex in mesh.vertices: vertex.vertex.scale(offset / vertex.nfaces) vertex.vertex.add(vertex) # create faces for face in mesh.faces: offsetVertices = [] for vertex in face.vertices: offsetVertices.append(vertex.vertex) offsetVertices.reverse() newFace = Face(offsetVertices) newMesh.faces.append(newFace) newMesh.faces.append(face) # create sides if doclose: for edge in mesh.edges: if edge.face1 == None or edge.face2 == None: offsetVertices = [edge.v1, edge.v2, edge.v2.vertex, edge.v1.vertex] if edge.face2 == None: offsetVertices.reverse() newFace = Face(offsetVertices) newMesh.faces.append(newFace) newMesh.updateAdjacencies() return newMesh
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