trimesh
trimesh copied to clipboard
Glitches in cube imported as scene (but not mesh!) from Blender .glb
I create a cube in Blender, scale it on one or more axes, and export as a glb/gltf. When I import it with trimesh, the faces "pop in and out" as you orbit around the model. This does not happen if you force='mesh' on import and this does not happen if the cube is not scaled (i.e. scale = 1,1,1).
Example .glb and .gltf attached as .zip: cubeScaled.zip
Issue first mentioned here: https://github.com/mikedh/trimesh/issues/1235
Side note: If there's a way to get/set the transformation matrices for each node in a scene, please let me know (unclear after digging around docs) - happy to dig around a bit!
I think this is probably something in trimesh.viewer.windowed and how it's doing camera matrices for nested/scaling transforms.
Getting transforms per node is probably easiest doing something like:
In [1]: import trimesh
In [2]: m = trimesh.load('models/nested.glb')
primitive has no mode! trying GL_TRIANGLES?
primitive has no mode! trying GL_TRIANGLES?
primitive has no mode! trying GL_TRIANGLES?
In [3]: m.graph.nodes
Out[3]: {'block01', 'block02', 'block03', 'world'}
In [7]: trimesh.util.attach_to_log()
In [8]: {n: m.graph[n][0] for n in m.graph.nodes}
Out[8]:
{'block03': array([[ 0.17714, 0. , 0. , -0. ],
[ 0. , 0.61021, 0. , -1.72639],
[ 0. , 0. , 0.17714, 0. ],
[ 0. , 0. , 0. , 1. ]]),
'world': array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]]),
'block01': array([[ 0.26938, 0. , 0. , -0.89763],
[ 0. , 0.28434, 0. , 0.68295],
[ 0. , 0. , 0.26938, 0. ],
[ 0. , 0. , 0. , 1. ]]),
'block02': array([[ 0.26938, 0. , 0. , -0. ],
[ 0. , 1. , 0. , 0. ],
[ 0. , 0. , 0.26938, 0. ],
[ 0. , 0. , 0. , 1. ]])}
I think I'm running into a very similar issue with a scene made up of a single mesh geometry:
- For scale 1 everything looks as expected.
- For scales > 1 the lighting becomes darker/duller (at 2–4) until the surface material is completely monochrome (at 10).
- For scales < 1 the lighting becomes "blocky" (at 0.8).
See my minimal working example code (incl. a demo mesh) and play around with the --scale= command-line option.