def form_mesh(vertices, faces, voxels=None): """ Convert raw mesh data into a Mesh object. Args: vertices (`numpy.ndarray`): ndarray of floats with size (num_vertices, dim). faces: ndarray of ints with size (num_faces, vertex_per_face). voxels: optional ndarray of ints with size (num_voxels, vertex_per_voxel). Use ``None`` for forming surface meshes. Returns: A :py:class:`Mesh` object formed by the inputs. Example: >>> vertices = np.array([ ... [0.0, 0.0], ... [1.0, 0.0], ... [1.0, 1.0], ... [0.0, 1.0], ... ]); >>> faces = np.array([ ... [0, 1, 2], ... [0, 2, 3], ... ]); >>> mesh = pymesh.form_mesh(vertices, faces); """ voxels = deduce_voxel_type(faces, voxels) faces = deduce_face_type(faces, voxels) factory = PyMesh.MeshFactory() factory.load_data(vertices.ravel(order="C"), faces.ravel(order="C"), voxels.ravel(order="C"), vertices.shape[1], faces.shape[1], voxels.shape[1]) return Mesh(factory.create())
def load_mesh(filename, extension_hint=None, drop_zero_dim=False): """ Load mesh from a file. Args: filename: Input filename. File format is auto detected based on extension. drop_zero_dim (bool): If true, convert flat 3D mesh into 2D mesh. Returns: A :py:class:`Mesh` object representing the loaded mesh. """ ext = os.path.splitext(filename)[1] if extension_hint is None else extension_hint if ext == ".geogram": return Mesh(PyMesh.load_geogram_mesh(filename)); if not os.path.exists(filename): raise IOError("File not found: {}".format(filename)); factory = PyMesh.MeshFactory(); if extension_hint is None: factory.load_file(filename); else: factory.load_file_with_hint(filename, extension_hint) if drop_zero_dim: factory.drop_zero_dim(); return Mesh(factory.create());
def form_mesh(vertices, faces, voxels=None): """ Convert raw mesh data into a Mesh object. Args: vertices (`numpy.ndarray`): ndarray of floats with size (num_vertices, dim). faces: ndarray of ints with size (num_faces, vertex_per_face). voxels: optional ndarray of ints with size (num_voxels, vertex_per_voxel). Use ``None`` for forming surface meshes. Returns: A Mesh object. """ voxels = deduce_voxel_type(faces, voxels); faces = deduce_face_type(faces, voxels); factory = PyMesh.MeshFactory(); factory.load_data( vertices.ravel(order="C"), faces.ravel(order="C"), voxels.ravel(order="C"), vertices.shape[1], faces.shape[1], voxels.shape[1]); return Mesh(factory.create());
def load_mesh(self, mesh_file): mesh_file = os.path.join(self.data_dir, mesh_file) if not os.path.exists(mesh_file): raise IOError("mesh file {} does not exist!".format(mesh_file)) factory = PyMesh.MeshFactory() factory.load_file(mesh_file) return factory.create_shared()
def load_mesh(self, mesh_file): mesh_file = os.path.join(self.data_dir, mesh_file) if not os.path.exists(mesh_file): raise IOError("mesh file {} does not exist!".format(mesh_file)) factory = PyMesh.MeshFactory() factory.load_file(mesh_file) factory.with_connectivity("all") factory.with_attribute("face_normal") factory.with_attribute("vertex_normal") factory.with_attribute("face_area") factory.with_attribute("voxel_volume") return factory.create_shared()
def load_mesh(filename, drop_zero_dim=False): """ Load mesh from a file. Args: filename: Input filename. File format is auto detected based on extension. drop_zero_dim (bool): If true, convert flat 3D mesh into 2D mesh. Returns: A :py:class:`Mesh` object representing the loaded mesh. """ if not os.path.exists(filename): raise IOError("File not found: {}".format(filename)) factory = PyMesh.MeshFactory() factory.load_file(filename) if drop_zero_dim: factory.drop_zero_dim() return Mesh(factory.create())
def load_mesh(self, filename): filename = os.path.join(self.mesh_data_dir, filename) factory = PyMesh.MeshFactory() factory.load_file(filename) return factory.create_shared()
def form_mesh(self, vertices, faces): factory = PyMesh.MeshFactory() factory.load_data(vertices.ravel(order="C"), faces.ravel(order="C"), np.array([]), vertices.shape[1], faces.shape[1], 4) factory.with_attribute("face_area") return factory.create()