def main(path): name = os.path.basename(path) vertices = [] with open(path, 'r') as f: step = float(f.readline()) / 2.0 gen.iter_lines(f, lambda line, data: data.append(Vec3.fromSequence(map(float, line.split(", ")))), vertices) #print vertices print "loaded" mesh = Mesh() for v in vertices: xp = v.x + step xm = v.x - step yp = v.y + step ym = v.y - step zp = v.z + step zm = v.z - step added = mesh.extend_vlist([(xm, ym, zp), #0 (xp, ym, zp), #1 (xm, ym, zm), #2 (xp, ym, zm), #3 (xm, yp, zp), #4 (xp, yp, zp), #5 (xm, yp, zm), #6 (xp, yp, zm) #7 ]) flist = [(0, 1, 3, 2), (1, 5, 7, 3), (2, 6, 7, 3), (4, 5, 7, 6), (0, 2, 6, 4), (0, 4, 5, 1)] for face in flist: extant_face = mesh.has_face(added, face) if (extant_face): #Since each face can be shared by at most 2 cubes, if a face #already exists and this cube would share it, it is safe to #remove that face because it is interior. mesh.remove_face(extant_face) else: #If this face doesn't exist, then this is the first cube with #that face and thus it is exterior. mesh.make_face(added, face) print "built mesh" mesh.remove_orphaned_vertices(no_faces = True, no_edges = False) print "removed vertices not part of faces" mesh.save(name + "_shell") print "saved mesh"
def __init__(self, x, y, z): Vec3.__init__(self, x, y, z) self.edges = [] self.faces = []