Sharing specific VertexBuffers between Geometries

I understand that Instances are a way to share VertexBuffers between meshes.

I am now looking for a way to only share specific VertexBuffers (say of Color, or Position kind) but let meshes keep their own materials and other VertexBuffers.

The PG I have in mind which would show my attempt at that would create box1 with blue vertex colors, then box2, and then set the color kind VertexBuffer of box2 as a reference to the color kind VertexBuffer of box1.

Finally, perhaps change the VertexData (and therefore VertexBuffer) of box1.

Of course, I should just try that but perhaps there are some first caveats or feedback to consider ?

The motivation is that in X3D (another 3d framework) any kind of node including vertex data equivalents can be shared (by reference) between meshes, and I want to see if it is possible to avoid copying, or reprocessing on updates of the source node in BJS.

Apologies if this is too abstract, I will try to come up with a PG.

1 Like

Instances are not meant to share them but moreover to only have one draw call for all the instances increasing perfs by a ton.

Sharing vertex buffers could be done by setting the vertex data as you suggested.

This will have the advantage to lower the memory but will not in any case increase performances.

2 Likes

Thanks. I understand that. Currently not looking for performance, just a reasonable way to share data structures between objects.

1 Like

https://playground.babylonjs.com/#VE6GP#306

shows how a position vertex buffer can be shared between two meshes.

2 Likes

A last thought: It occurred to me that this referencing probably does not survive serialization as I do not see how it could. I think it would be then necessary and not to difficult to put a hint in metadata, and then reestablish the reference after loading. The hint would need to have the source, eg. mesh id and the data kind. Unless there is a supported way of serializing sharing data between meshes ? (This could perhaps be generalized.)