trimesh icon indicating copy to clipboard operation
trimesh copied to clipboard

Bug when copying trimesh.primitives: Density is not copied

Open clemense opened this issue 2 years ago • 2 comments

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

clemense avatar Jul 28 '23 02:07 clemense

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'}
{}

clemense avatar Jul 28 '23 19:07 clemense

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:

  • density when overridden gets applied to data which dumps the cache (or selectively dumps just mass_properties), same for the center_mass override
  • primitive.copy gets a test to make sure density override survives

mikedh avatar Jul 28 '23 21:07 mikedh