Python源码示例:trimesh.load_mesh()

示例1
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) 
示例2
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 
示例3
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 
示例4
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 
示例5
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) 
示例6
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