任何加载文件的 PyAssimp 错误 - 场景没有属性网格、材质或纹理

问题描述 投票:0回答:1

我正在尝试让任何示例(包括在 Assimp 存储库中找到的示例)正常工作。在 Python 3.11.6 中使用

pyassimp 5.2.5
。下面是一个非常基本的调用示例。我正在加载一个立方体的 OBJ,甚至可以手动写入。 :D

import pyassimp
import pyassimp.postprocess

def main(filename=None):

    scene = pyassimp.load(filename, processing=pyassimp.postprocess.aiProcess_Triangulate)
    
    
    print("Meshes:" + str(len(scene.meshes)))
    pyassimp.release(scene)

立方体

# Blender v2.61 (sub 0) OBJ File: ''
# www.blender.org
mtllib bigger-cube.mtl
o Cube
v 0.700000 -0.700000 -0.700000
v 0.700000 -0.700000 0.700000
v -0.700000 -0.700000 0.700000
v -0.700000 -0.700000 -0.700000
v 0.700000 0.700000 -0.700000
v 0.700000 0.700000 0.700000
v -0.700000 0.700000 0.700000
v -0.700000 0.700000 -0.700000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 1.000000 0.000000 0.000000
vn -0.000000 -0.000000 1.000000
vn -1.000000 -0.000000 -0.000000
vn 0.000000 0.000000 -1.000000
usemtl Material.001
s off
f 1/1/1 2/2/1 3/3/1 4/4/1
f 5/1/2 8/2/2 7/3/2 6/4/2
f 1/1/3 5/2/3 6/3/3 2/4/3
f 2/1/4 6/2/4 7/3/4 3/4/4
f 3/1/5 7/2/5 8/3/5 4/4/5
f 5/1/6 1/2/6 4/3/6 8/4/6

痕迹是

INFO:pyassimp:Adding Anaconda lib path:/home/user/miniconda3/envs/computergraphics/lib/
MODEL:bigger-cube.obj
SCENE:
Traceback (most recent call last):
  File "/home/ale56337/Projects/cgi/playground.py", line 83, in <module>
    main(sys.argv[1])
  File "/home/user/Projects/cgi/playground.py", line 24, in main
    print("  meshes:" + str(len(scene.meshes)))
                                ^^^^^^^^^^^^
AttributeError: '_GeneratorContextManager' object has no attribute 'meshes'

我也尝试打电话给

materials
textures
,但结果是一样的。官方仓库中有一个问题,大约两年前已修复。然而,在当前版本中,问题仍然存在(也许是回归或问题的另一个来源导致了相同的结果?)。

有什么想法可以让 PyAssimp 工作吗?

python assimp
1个回答
0
投票

我猜这个问题是由于缺少materiallib文件引起的。当模型加载失败时,返回的场景将为None。所以所有内部属性也都是None

© www.soinside.com 2019 - 2024. All rights reserved.