[Closed] Multiple parents in scenegraph

More notes on how Three seems to render the scene graph, roughly.

The traversal happens in the renderer, WebGLRenderer.

First, a renderlist is constructed in projectObject. It contains a flat list of renderables constructed from traversing the scene from top to bottom.

Then, the renderlist is rendered in sequence in renderObjects(), renderObject(), renderBufferDirect()

The modelViewMatrix() is computed and stored per object or mesh, as well as the world transform of the object.

So for multi-parenting this is where either cloning would be necessary, probably when constructing the renderlist. Or, there could be a separation, by introducing a renderObject which references the mesh and world related matrices separately:

renderObject.object = object;
renderObject.worldMatrix.mult(object.localMatrix, parent.worldMatrix);

renderObject() then would take renderObject rather than object

Of course, there are likely many other properties (needMatrixUpdate or so) and events(onbeforerender) which are tied to object safely assuming it occurs only once in the renderlist.

Well, I have a better appreciation now of how three works at the scene graph level. It looks like cloning and keeping track of clones perhaps via Proxys would be necessary to simulate multi-parenting.

The other structure that allows for this seems to be called. VRML used this.

I played some with this, kinda hacky but it works:


update one group = THREE.Objject3D and all createInstance(group) will update

Here;s how its done:

I basically introduced another hook onBeforeUpdate and manage the matrix updates manually. It can be cleaned up some more, with better dirty flags. Also wasn’t sure if this should be done on the cpu, could limit the level of nesting and do matrix0 * matrix1 * matrix2... * vec4(position,1.);.