How to use the pyassimp.load function in pyassimp

To help you get started, we’ve selected a few pyassimp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikedh / trimesh / trimesh / mesh_io.py View on Github external
Also, you need a very recent version of PyAssimp for this function to work 
    (the commit was merged into the assimp github master on roughly 9/5/2014)
    '''

    def LPMesh_to_Trimesh(lp):
        return Trimesh(vertices       = lp.vertices,
                       vertex_normals = lp.normals,
                       faces          = lp.faces,
                       vertex_colors  = lp.colors)

    if not hasattr(file_obj, 'read'):
        # if there is no read attribute, we assume we've been passed a file name
        file_type = (str(file_obj).split('.')[-1]).lower()
        file_obj  = open(file_obj, 'rb')

    scene  = pyassimp.load(file_obj, file_type=file_type)
    meshes = list(map(LPMesh_to_Trimesh, scene.meshes))
    pyassimp.release(scene)

    if len(meshes) == 1: 
        return meshes[0]
    return meshes
 
github assimp / assimp / port / PyAssimp / scripts / 3d_viewer.py View on Github external
def load_model(self, path, postprocess = aiProcessPreset_TargetRealtime_MaxQuality):
        logger.info("Loading model:" + path + "...")

        if postprocess:
            self.scene = pyassimp.load(path, postprocess)
        else:
            self.scene = pyassimp.load(path)
        logger.info("Done.")

        scene = self.scene
        #log some statistics
        logger.info("  meshes: %d" % len(scene.meshes))
        logger.info("  total faces: %d" % sum([len(mesh.faces) for mesh in scene.meshes]))
        logger.info("  materials: %d" % len(scene.materials))
        self.bb_min, self.bb_max = get_bounding_box(self.scene)
        logger.info("  bounding box:" + str(self.bb_min) + " - " + str(self.bb_max))

        self.scene_center = [(a + b) / 2. for a, b in zip(self.bb_min, self.bb_max)]

        for index, mesh in enumerate(scene.meshes):
            self.prepare_gl_buffers(mesh)

        # Finally release the model
github personalrobotics / prpy / src / prpy / ipython / __init__.py View on Github external
# Store information about the render mesh.
    geometry_renderfilename = geometry.GetRenderFilename()
    geometry_renderscale = geometry.GetRenderScale()
    props['render'] = {
        'filename': geometry_renderfilename,
        'scale': geometry_renderscale
    }

    if geometry_renderfilename:
        if geometry_renderfilename not in _render_cache:
            # TODO: format me better!
            print "Loading mesh: '{:s}'".format(geometry_renderfilename)

            import pyassimp
            scene = pyassimp.load(geometry_renderfilename)
            _render_cache[geometry_renderfilename] = scene

    return props
github mikeferguson / moveit_python / src / moveit_python / planning_scene_interface.py View on Github external
def makeMesh(self, name, pose, filename):
        if not use_pyassimp:
            rospy.logerr('pyassimp is broken on your platform, cannot load meshes')
            return
        scene = pyassimp.load(filename)
        if not scene.meshes:
            rospy.logerr('Unable to load mesh')
            return

        mesh = Mesh()
        for face in scene.meshes[0].faces:
            triangle = MeshTriangle()
            if len(face.indices) == 3:
                triangle.vertex_indices = [face.indices[0],
                                           face.indices[1],
                                           face.indices[2]]
            mesh.triangles.append(triangle)
        for vertex in scene.meshes[0].vertices:
            point = Point()
            point.x = vertex[0]
            point.y = vertex[1]
github andreasBihlmaier / gazebo2rviz / scripts / sdf2moveit_collision.py View on Github external
def make_mesh(co, name, pose, filename, scale = (1, 1, 1)):
    #print("make_mesh(name=%s filename=%s)" % (name, filename))
    scene = pyassimp.load(filename)
    if not scene.meshes or len(scene.meshes) == 0:
        raise MoveItCommanderException("There are no meshes in the file")
    if len(scene.meshes[0].faces) == 0:
        raise MoveItCommanderException("There are no faces in the mesh")
    co.operation = CollisionObject.ADD
    co.id = name
    co.header = pose.header

    mesh = Mesh()
    first_face = scene.meshes[0].faces[0]
    if hasattr(first_face, '__len__'):
        for face in scene.meshes[0].faces:
            if len(face) == 3:
                triangle = MeshTriangle()
                triangle.vertex_indices = [face[0], face[1], face[2]]
                mesh.triangles.append(triangle)
github personalrobotics / dartpy / dart / gui / vispy / shapes / mesh_shape_node.py View on Github external
def _updateShapeData(self, firstTime):
        if firstTime:
            uri = self.meshShape.getMeshUri2()
            retriever = self.meshShape.getResourceRetriever()
            meshPath = retriever.getFilePath(uri)
            try:
                scene = assimp.load(meshPath)
            except:
                # TODO(JS): Better error handling
                warnings.warn("Failed to load a mesh '{}'.".format(uri))
                return

            # Materials
            # for material in scene.materials:
            #     self.materials += [Material(material)]
            #
            # # Texture images
            # for texture in scene.textures:
            #     self.textures += [Texture(texture)]

            self.rootAssimpNodeNode = AssimpNodeNode(scene.rootnode, assimpScene=scene, parent=self)
        else:
            self.rootAssimpNodeNode.refresh()
github ipab-slmc / exotica / exotica_python / src / pyexotica / planning_scene_utils.py View on Github external
def create_mesh(name, pose, filename, scale=(1, 1, 1),
                frame_id='/world_frame'):
    co = CollisionObject()
    scene = pyassimp.load(str(exo.Tools.parsePath(filename)))
    if not scene.meshes or len(scene.meshes) == 0:
        raise Exception("There are no meshes in the file")
    if len(scene.meshes[0].faces) == 0:
        raise Exception("There are no faces in the mesh")
    co.operation = CollisionObject.ADD
    co.id = name
    co.header.frame_id = frame_id

    mesh = Mesh()
    first_face = scene.meshes[0].faces[0]
    if hasattr(first_face, '__len__'):
        for face in scene.meshes[0].faces:
            if len(face) == 3:
                triangle = MeshTriangle()
                triangle.vertex_indices = [face[0], face[1], face[2]]
                mesh.triangles.append(triangle)