def test_empty_mesh(self): """ What happens when we call functions on an empty mesh? """ mesh = Mesh(np.zeros((0, 3), np.float32), np.zeros((0, 3), int)) mesh.simplify(1.0) assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.simplify(0.1) assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.laplacian_smooth(0) assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.laplacian_smooth(2) assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.stitch_adjacent_faces() assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.serialize(fmt='obj') assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.serialize(fmt='drc') assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.compress() concatenate_meshes((mesh, mesh)) assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0
def test_stitch(): vertices = np.zeros((10, 3), np.float32) vertices[:, 0] = np.arange(10) # Make 3 and 6 duplicates of 2 and 4, respectively vertices[3] = vertices[2] vertices[6] = vertices[4] faces = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [7, 8, 4]] # <- duplicate face (different vertex order, and 4=6) # After mapping away from dupe vertices remapped_faces = [[0, 1, 2], [2, 4, 5], [4, 7, 8], [7, 8, 4]] # duplicated face (different vertex order) remapped_faces = np.array(remapped_faces) # After dropping dupe rows remapped_faces[(remapped_faces > 6)] -= 1 remapped_faces[(remapped_faces > 3)] -= 1 # Drop last face (duplicated) remapped_faces = remapped_faces[:-1, :] reduced_vertices = list(vertices) del reduced_vertices[9] # wasn't referenced to begin with del reduced_vertices[6] # was duplicated del reduced_vertices[3] # was duplicated reduced_vertices = np.asarray(reduced_vertices) mesh = Mesh(vertices, faces) mesh.stitch_adjacent_faces() assert (mesh.faces == remapped_faces).all() assert (mesh.vertices_zyx == reduced_vertices).all()