Python trimesh.load_mesh() Examples

The following are 6 code examples of trimesh.load_mesh(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module trimesh , or try the search function .
Example #1
Source File: pointcloud.py    From AlignNet-3D with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, fname):
        self.mesh = trimesh.load_mesh(fname)
        median = np.mean(self.mesh.bounds[:, :], axis=0)
        self.mesh.apply_translation(-median)
        max_length = np.max(np.abs(self.mesh.bounds[:, :]))
        length = 1.0 / (max_length * 2.0)
        self.mesh.apply_scale(length) 
Example #2
Source File: em_3d_help.py    From mapper-tda with MIT License 5 votes vote down vote up
def read_3d_obj(fname="lion_data.npy", fname_obj="lion-reference.obj"):

    if os.path.isfile(fname):
        return np.load(fname)
    else:

        mesh = trimesh.load_mesh(fname_obj)
        a = np.array(mesh.vertices)
        x,y,z = -a[:,0],a[:,2],a[:,1]
        data = np.array(list(zip(x,y,z)))
        
        np.save(fname, data)

        return data 
Example #3
Source File: dataset.py    From s2cnn with MIT License 5 votes vote down vote up
def __call__(self, path):
        mesh = trimesh.load_mesh(path)
        mesh.remove_degenerate_faces()
        mesh.fix_normals()
        mesh.fill_holes()
        mesh.remove_duplicate_faces()
        mesh.remove_infinite_values()
        mesh.remove_unreferenced_vertices()

        mesh.apply_translation(-mesh.centroid)

        r = np.max(np.linalg.norm(mesh.vertices, axis=-1))
        mesh.apply_scale(1 / r)

        if self.tr > 0:
            tr = np.random.rand() * self.tr
            rot = rnd_rot()
            mesh.apply_transform(rot)
            mesh.apply_translation([tr, 0, 0])

            if not self.rot:
                mesh.apply_transform(rot.T)

        if self.rot:
            mesh.apply_transform(rnd_rot())

        r = np.max(np.linalg.norm(mesh.vertices, axis=-1))
        mesh.apply_scale(0.99 / r)

        return mesh 
Example #4
Source File: collect_grasps.py    From multi-contact-grasping with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def load_mesh(mesh_path):
    """Loads a mesh from file &computes it's centroid using V-REP style."""

    mesh = trimesh.load_mesh(mesh_path)

    # V-REP encodes the object centroid as the literal center of the object,
    # so we need to make sure the points are centered the same way
    center = lib.utils.calc_mesh_centroid(mesh, center_type='vrep')
    mesh.vertices -= center
    return mesh 
Example #5
Source File: utils.py    From multi-contact-grasping with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def plot_mesh(mesh_path, workspace2obj, axis=None):
    """Visualize where we will sample grasp candidates from

    Parameters
    ----------
    mesh_path : path to a given mesh
    workspace2obj : 4x4 transform matrix from the workspace to object
    axis : (optional) a matplotlib axis for plotting a figure
    """

    if axis is None:
        figure = plt.figure()
        axis = Axes3D(figure)
        axis.autoscale(False)

    # Load the object mesh
    mesh = trimesh.load_mesh(mesh_path)

    # V-REP encodes the object centroid as the literal center of the object,
    # so we need to make sure the points are centered the same way
    center = calc_mesh_centroid(mesh, center_type='vrep')
    mesh.vertices -= center

    # Rotate the vertices so they're in the frame of the workspace
    mesh.apply_transform(workspace2obj)

    # Construct a 3D mesh via matplotlibs 'PolyCollection'
    poly = Poly3DCollection(mesh.triangles, linewidths=0.05, alpha=0.25)
    poly.set_facecolor([0.5, 0.5, 1])
    axis.add_collection3d(poly)

    return plot_equal_aspect(mesh.vertices, axis) 
Example #6
Source File: doneshapes.py    From SciSlice with MIT License 5 votes vote down vote up
def _getMesh(fname, change_units_from='mm'):
    change_units_from = change_units_from.lower()
    mesh = trimesh.load_mesh(fname)
    if change_units_from is not 'mm':
        mesh.units = change_units_from
        mesh.convert_units('mm')
    return mesh