trimesh
trimesh copied to clipboard
Bug when copying trimesh.primitives: Density is not copied
In previous versions (e.g. 3.15.5) this worked:
import trimesh
a = trimesh.primitives.Box()
a.density = 2.0
print(a.density)
print(a.copy().density)
Output:
2.0
2.0
It doesn't work in newer versions (e.g. the latest 3.22.5, and also 3.20.1). The same code produces the following output:
2.0
1.0
The same is true for metadata, the behavior also changed recently:
import trimesh
a = trimesh.primitives.Box()
a.metadata['foo'] = 'bar'
print(a.metadata)
print(a.copy().metadata)
Output:
{'foo': 'bar'}
{}
Yeah the behavior of primitives changed in https://github.com/mikedh/trimesh/pull/1942 due to some hard to track bugs for example when someone applied face_colors=... in the constructor.
Looking at the center_mass and density overrides they aren't using either the _cache or _data system as they were special cased (although they probably shouldn't be just assigning to an internal variable) which also confuses this issue. Seems like a fix might be:
densitywhen overridden gets applied todatawhich dumps the cache (or selectively dumps just mass_properties), same for thecenter_massoverrideprimitive.copygets a test to make sure density override survives