PyAssimp error for any loaded file - Scene has not attribute meshes, materials or textures

34 Views Asked by At

I am trying to get any sample (including the ones found in the Assimp repo) to work. Using pyassimp 5.2.5 with Python 3.11.6. Below there is an example for a very basic call. I am loading an OBJ of a cube, which one can even write manually. :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)

The cube

# 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

The trace is

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'

I also tried calling materials and textures but the result is the same. There is an issue in the official repo, which was fixed two years or so ago. Yet with the current version the issue is still there (perhaps regression or another source of the problem leading to the same outcome?).

Any ideas how to make PyAssimp work?

1

There are 1 best solutions below

0
KimKulling On

I guess the isse was caused by the missing materiallib file. When the loading of the model failes the returned scne will be None. So all internal attributes are None as well.