mmatl / pyrender

Easy-to-use glTF 2.0-compliant OpenGL renderer for visualization of 3D scenes.
http://pyrender.readthedocs.io/
MIT License
1.29k stars 224 forks source link

trimesh 3.9.33 test regression #203

Open traversaro opened 2 years ago

traversaro commented 2 years ago

Since trimesh 3.9.33 (I tested with pip, and trimesh 3.9.32 works fine) the test_meshes.py test fails with error:

        bm = trimesh.load('tests/data/WaterBottle.glb').dump()[0]
        x = Mesh.from_trimesh(bm)
        assert x.primitives[0].material.baseColorTexture is not None
>       assert x.primitives[0].material.emissiveTexture is not None
E       assert None is not None
E        +  where None = <pyrender.material.MetallicRoughnessMaterial object at 0x7fa1a0e760a0>.emissiveTexture
E        +    where <pyrender.material.MetallicRoughnessMaterial object at 0x7fa1a0e760a0> = <pyrender.primitive.Primitive object at 0x7fa1a0e76130>.material

tests/unit/test_meshes.py:121: AssertionError
mikedh commented 2 years ago

Hey, is this still happening? Checking on my local machine it looks OK:

n [4]: m = trimesh.load('/home/mikedh/Downloads/WaterBottle.glb')
primitive has no mode! trying GL_TRIANGLES?

In [5]: m
Out[5]: <trimesh.Scene(len(geometry)=1)>

In [9]: m.geometry
Out[9]: 
OrderedDict([('WaterBottle',
              <trimesh.Trimesh(vertices.shape=(2549, 3), faces.shape=(4510, 3))>)])

In [10]: m.geometry['WaterBottle'].visual.material
Out[10]: <trimesh.visual.material.PBRMaterial at 0x7f66ab235520>

In [11]: mat = m.geometry['WaterBottle'].visual.material

In [12]: mat._data
Out[12]: 
{'emissiveFactor': array([1., 1., 1.]),
 'baseColorTexture': <PIL.PngImagePlugin.PngImageFile image mode=RGB size=2048x2048 at 0x7F66AB240A30>,
 'doubleSided': False}

In [13]: mat.emissiveFactor
Out[13]: array([1., 1., 1.])

In [14]: mat.emissiveTexture
Out[14]: <PIL.PngImagePlugin.PngImageFile image mode=RGB size=2048x2048 at 0x7F66A31BA130>

Is it possible the runner is missing pillow, which would be required to load the texture?

traversaro commented 2 years ago

I missed the reply @mikedh ! I will trigger a new build in https://github.com/conda-forge/pyrender-feedstock/pull/2 to check.

eyllanesc commented 2 years ago

@traversaro I reproduce the same thing on my local machine and also on GitHub Workflow (See #216)

eyllanesc commented 2 years ago

I was debugging code and found the following behavior change:

import trimesh

print(trimesh.__version__)

bm = trimesh.load("tests/data/WaterBottle.glb").dump()[0]
print(bm.visual.material.emissiveTexture)
eyllanesc commented 2 years ago

@mikedh Your analysis helped me a lot. It seems that the dump method has changed in trimesh 3.9.33 so it does not take into account some materials. So I have changed the test based on your code which is in my PR #216.

Also note that prior to 3.9.33 emissive Texture was of type PIL.Image.Image but is now PIL.PngImagePlugin.PngImageFile. It can be a starting point to know the effects of the changes introduced in 3.9.33