Object.to_mesh() with Float Layers

I have a large number of custom mesh float layers (i.e. the float layers you can store in “ob.data.layers_float”.) associated with a large mesh object.

When I call:


mesh = ob.to_mesh(scene, apply_modifiers=True, settings='PREVIEW')

I notice that all the float layers are duplicated onto the new mesh. They aren’t just linked, because if I change the data on one, the result is not updated on the other.

I’m worried that calling “to_mesh()” is becoming a bottleneck, unnecessarily duplicating a ton of really long arrays. All I actually need out of “to_mesh()” is the final vertex locations, nothing more.

Any thoughts?

And by “I’m worried”, I mean “I know”, for two reasons:

  1. I have script that successively calls “to_mesh()”, and then performs computations on that mesh, and stores the results as a float layer on the original object. At first “to_mesh()” runs lightning fast. As more and more mesh layers are added, “to_mesh()” gets slower and slower.

  2. Once I have a decent number of float layers (50-100) on a good size mesh (~50K vertices), using Edit Mode becomes impossibly slow. (It basically just hangs.) I surmise that in Edit Mode, mesh layers are updated? Again, this is unnecessary for my purposes, so I’d love to know some way around it.

The only solution I can see is to use 2 identical mesh objects, and store the layers only on one of them. I can call “to_mesh()” on the clean object and then store the computed data with the second “storage” mesh.

It’s not very elegant. If any developers drop by, let me know what your thoughts/intentions are with custom mesh layers. Is there an important reason why mesh operations should dramatically slow down when using lots of mesh layers? Is there a way around it?

I’d also be interested whether anything will change with BMesh.