def _mesh_import(name, file): """Internal function to load meshes using the correct loader. Name and file might be the same but not always, e.g. temp files.""" file_extension = _get_file_format(name) if file_extension not in SUPPORTED_FORMATS: raise NotImplementedError( 'Mesh type not supported: {}'.format(file_extension)) if file_extension == 'obj': return Mesh.from_obj(file) elif file_extension == 'stl': return Mesh.from_stl(file) elif file_extension == 'ply': return Mesh.from_ply(file) raise Exception
def _mesh_import(url, filename): """Internal function to load meshes using the correct loader. Name and file might be the same but not always, e.g. temp files.""" file_extension = _get_file_format(url) if file_extension not in SUPPORTED_FORMATS: raise NotImplementedError( 'Mesh type not supported: {}'.format(file_extension)) print(filename) if file_extension == "dae": # no dae support yet #mesh = Mesh.from_dae(filename) obj_filename = filename.replace(".dae", ".obj") if os.path.isfile(obj_filename): mesh = Mesh.from_obj(obj_filename) # former DAE files have yaxis and zaxis swapped # TODO: already fix in conversion to obj frame = Frame([0,0,0], [1,0,0], [0,0,1]) T = Transformation.from_frame(frame) mesh_transform(mesh, T) return mesh else: raise FileNotFoundError("Please convert '%s' into an OBJ file, \ since DAE is currently not supported \ yet." % filename) if file_extension == 'obj': return Mesh.from_obj(filename) elif file_extension == 'stl': return Mesh.from_stl(filename) elif file_extension == 'ply': return Mesh.from_ply(filename) raise Exception
import compas from math import radians from compas.datastructures import Mesh from compas.geometry import Point, Rotation, Scale, Translation, Box from compas.geometry import trimesh_remesh from compas_view2.app import App # ============================================================================== # Get Bunny # ============================================================================== before = Mesh.from_ply(compas.get_bunny()) # ============================================================================== # Clean up # ============================================================================== before.cull_vertices() # ============================================================================== # Transform # ============================================================================== T = Translation.from_vector(Point(0, 0, 0) - Point(*before.centroid())) S = Scale.from_factors([100, 100, 100]) R = Rotation.from_axis_and_angle([1, 0, 0], radians(90)) before.transform(R * S * T) # ==============================================================================
import compas import compas_rhino from compas.datastructures import Mesh __author__ = [ 'Tom Van Mele', ] __copyright__ = 'Copyright 2016 - Block Research Group, ETH Zurich' __license__ = 'MIT License' __email__ = '*****@*****.**' mesh = Mesh.from_ply(compas.get('stanford_armadillo.ply')) compas_rhino.mesh_draw(mesh)
def from_ply(self): filename, _ = get_ply_file() if filename: self.mesh = Mesh.from_ply(filename) self.view.make_buffers() self.view.updateGL()
from scipy.sparse.linalg import spsolve from compas.datastructures import Mesh from compas.plotters import MeshPlotter __author__ = ['Tom Van Mele', ] __copyright__ = 'Copyright 2016 - Block Research Group, ETH Zurich' __license__ = 'MIT' __email__ = '*****@*****.**' # make a *stanford bunny* mesh mesh = Mesh.from_ply(compas.get_bunny()) mesh.cull_vertices() # get any vertex of the mesh # and its neighbours v1 = mesh.get_any_vertex() nbrs = mesh.vertex_neighbours(v1, ordered=True) # make a quad containing: # one of the neighbours # and the CCW and CW neighbours of that neighbour, respectively # and set them as anchors
import compas import compas_rhino from compas.datastructures import Mesh mesh = Mesh.from_ply(compas.get('stanford_dragon.ply')) compas_rhino.mesh_draw(mesh)
def test_from_ply(): mesh = Mesh.from_ply(compas.get('bunny.ply')) assert mesh.number_of_faces() == 69451 assert mesh.number_of_vertices() == 35947 assert mesh.number_of_edges() == 104288
import compas from numpy import zeros from scipy.sparse import coo_matrix from scipy.sparse import block_diag from scipy.sparse.linalg import spsolve from compas.datastructures import Mesh from compas_plotters import MeshPlotter # make a *stanford bunny* mesh mesh = Mesh.from_ply(compas.get('bunny.ply')) # get any vertex of the mesh # and its neighbors v1 = mesh.get_any_vertex() nbrs = mesh.vertex_neighbors(v1, ordered=True) # make a quad containing: # one of the neighbors # and the CCW and CW neighbors of that neighbor, respectively # and set them as anchors v2 = nbrs[0] v3 = nbrs[1] v4 = nbrs[-1]
def test_from_ply(): mesh = Mesh.from_ply(compas.get('tubemesh.ply')) assert mesh.number_of_faces() == 342 assert mesh.number_of_vertices() == 200 assert mesh.number_of_edges() == 541