当前位置: 首页>>代码示例>>Python>>正文


Python pyassimp.load方法代码示例

本文整理汇总了Python中pyassimp.load方法的典型用法代码示例。如果您正苦于以下问题:Python pyassimp.load方法的具体用法?Python pyassimp.load怎么用?Python pyassimp.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyassimp的用法示例。


在下文中一共展示了pyassimp.load方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_meshes_sixd

# 需要导入模块: import pyassimp [as 别名]
# 或者: from pyassimp import load [as 别名]
def load_meshes_sixd( obj_files, vertex_tmp_store_folder , recalculate_normals=False):
    from . import inout
    hashed_file_name = hashlib.md5( (''.join(obj_files) + 'load_meshes_sixd' + str(recalculate_normals)).encode("utf-8")).hexdigest() + '.npy'

    out_file = os.path.join( vertex_tmp_store_folder, hashed_file_name)
    if os.path.exists(out_file):
        return np.load(out_file, allow_pickle=True)
    else:
        bar = progressbar.ProgressBar()
        attributes = []
        for model_path in bar(obj_files):
            model = inout.load_ply(model_path)
            vertices = np.array(model['pts'] ).astype(np.float32)
            if recalculate_normals:
                normals = calc_normals(vertices)
            else:
                normals = np.array(model['normals']).astype(np.float32)
            faces = np.array(model['faces']).astype(np.uint32)
            if 'colors' in model:
                colors = np.array(model['colors']).astype(np.uint32)
                attributes.append( (vertices, normals, colors, faces) )
            else:
                attributes.append( (vertices, normals, faces) )
        np.save(out_file, attributes)
        return attributes 
开发者ID:DLR-RM,项目名称:AugmentedAutoencoder,代码行数:27,代码来源:geometry.py

示例2: load_meshes

# 需要导入模块: import pyassimp [as 别名]
# 或者: from pyassimp import load [as 别名]
def load_meshes(obj_files, vertex_tmp_store_folder, recalculate_normals=False):
    hashed_file_name = hashlib.md5((''.join(obj_files) + 'load_meshes' + str(recalculate_normals)).encode('utf-8') ).hexdigest() + '.npy'

    out_file = os.path.join( vertex_tmp_store_folder, hashed_file_name)
    if os.path.exists(out_file):
        return np.load(out_file)
    else:
        bar = progressbar.ProgressBar()
        attributes = []
        for model_path in bar(obj_files):
            scene = pyassimp.load(model_path, pyassimp.postprocess.aiProcess_Triangulate)
            mesh = scene.meshes[0]
            vertices = mesh.vertices
            normals = calc_normals(vertices) if recalculate_normals else mesh.normals
            attributes.append( (vertices, normals) )
            pyassimp.release(scene)
        np.save(out_file, attributes)
        return attributes 
开发者ID:DLR-RM,项目名称:AugmentedAutoencoder,代码行数:20,代码来源:geometry.py

示例3: __init__

# 需要导入模块: import pyassimp [as 别名]
# 或者: from pyassimp import load [as 别名]
def __init__(self, obj_file, material_file=None, load_materials=True,
               name_prefix='', name_suffix=''):
    if material_file is not None:
      logging.error('Ignoring material file input, reading them off obj file.')
    load_flags = self.get_pyassimp_load_options()
    scene = assimp.load(obj_file, processing=load_flags)
    filter_ind = self._filter_triangles(scene.meshes)
    self.meshes = [scene.meshes[i] for i in filter_ind]
    for m in self.meshes:
      m.name = name_prefix + m.name + name_suffix

    dir_name = os.path.dirname(obj_file)
    # Load materials
    materials = None
    if load_materials:
      materials = []
      for m in self.meshes:
        file_name = os.path.join(dir_name, m.material.properties[('file', 1)])
        assert(os.path.exists(file_name)), \
            'Texture file {:s} foes not exist.'.format(file_name)
        img_rgb = cv2.imread(file_name)[::-1,:,::-1]
        if img_rgb.shape[0] != img_rgb.shape[1]:
          logging.warn('Texture image not square.')
          sz = np.maximum(img_rgb.shape[0], img_rgb.shape[1])
          sz = int(np.power(2., np.ceil(np.log2(sz))))
          img_rgb = cv2.resize(img_rgb, (sz,sz), interpolation=cv2.INTER_LINEAR)
        else:
          sz = img_rgb.shape[0]
          sz_ = int(np.power(2., np.ceil(np.log2(sz))))
          if sz != sz_:
            logging.warn('Texture image not square of power of 2 size. ' +
                         'Changing size from %d to %d.', sz, sz_)
            sz = sz_
            img_rgb = cv2.resize(img_rgb, (sz,sz), interpolation=cv2.INTER_LINEAR)
        materials.append(img_rgb)
    self.scene = scene
    self.materials = materials 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:39,代码来源:swiftshader_renderer.py

示例4: load

# 需要导入模块: import pyassimp [as 别名]
# 或者: from pyassimp import load [as 别名]
def load(filename):
    scene = pyassimp.load(filename, processing=pyassimp.postprocess.aiProcess_GenUVCoords|pyassimp.postprocess.aiProcess_Triangulate )
    mesh = scene.meshes[0]
    return mesh.vertices, mesh.normals, mesh.texturecoords[0,:,:2] 
开发者ID:DLR-RM,项目名称:AugmentedAutoencoder,代码行数:6,代码来源:geometry.py

示例5: _make_mesh

# 需要导入模块: import pyassimp [as 别名]
# 或者: from pyassimp import load [as 别名]
def _make_mesh(self, c, scale = (1, 1, 1)):
    '''
    This was taken from moveit commander and slightly modified.
    '''
    filename = c.geometry.filename
    if pyassimp is False:
        raise RuntimeError("Pyassimp needs patch https://launchpadlibrarian.net/319496602/patchPyassim.txt")
    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")
    
    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)
    elif hasattr(first_face, 'indices'):
        for face in scene.meshes[0].faces:
            if len(face.indices) == 3:
                triangle = MeshTriangle()
                triangle.vertex_indices = [face.indices[0],
                                           face.indices[1],
                                           face.indices[2]]
                mesh.triangles.append(triangle)
    else:
        raise RuntimeError("Unable to build triangles from mesh due to mesh object structure")
    for vertex in scene.meshes[0].vertices:
        point = Point()
        point.x = vertex[0]*scale[0]
        point.y = vertex[1]*scale[1]
        point.z = vertex[2]*scale[2]
        mesh.vertices.append(point)
    pyassimp.release(scene)
    return mesh 
开发者ID:jhu-lcsr,项目名称:costar_plan,代码行数:41,代码来源:urdf_to_collision_object.py

示例6: getTextureForMaterial

# 需要导入模块: import pyassimp [as 别名]
# 或者: from pyassimp import load [as 别名]
def getTextureForMaterial(self, material):

        materialDict = dict(list(material.properties.items()))

        if 'file' not in materialDict:
            return None

        textureFile = materialDict['file']

        if textureFile in self.textureCache:
            return self.textureCache[textureFile]

        if not os.path.isabs(textureFile):
            imageFile = os.path.join(self.baseDir, textureFile)
        else:
            imageFile = textureFile

        if os.path.isfile(imageFile):
            image = ioUtils.readImage(imageFile)

            if image:
                texture = vtk.vtkTexture()
                texture.SetInput(image)
                texture.EdgeClampOn()
                texture.RepeatOn()
            else:
                print('failed to load image file:', imageFile)
                texture = None
        else:
            print('cannot find texture file:', textureFile)
            texture = None

        self.textureCache[textureFile] = texture
        return texture 
开发者ID:RobotLocomotion,项目名称:director,代码行数:36,代码来源:assimp2vtk.py

示例7: loadAssimpSceneFromFile

# 需要导入模块: import pyassimp [as 别名]
# 或者: from pyassimp import load [as 别名]
def loadAssimpSceneFromFile(inFile):
    baseDir = os.path.dirname(inFile)
    scene = pyassimp.load(inFile, pyassimp.postprocess.aiProcess_Triangulate)
    return AssimpScene(scene, baseDir) 
开发者ID:RobotLocomotion,项目名称:director,代码行数:6,代码来源:assimp2vtk.py


注:本文中的pyassimp.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。