[Closed] Multiple parents in scenegraph

scene-graph
scene

#21

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.modelViewMatrix...
...

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.


#22

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


#23

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

https://raw.githack.com/pailhead/three-webpack-es6/dag/build/index.html

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.);.