frykauf / o3d

Automatically exported from code.google.com/p/o3d

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RFE: Instanceable sub-graphs of scenegraph

GoogleCodeExporter opened this issue · comments

Currently, only Shapes are instance-able.  Unfortunately modern 3D modeling 
tools often cook models into entire scenegraph sub-graphs with transforms 
to place the objects in the desired location.  A great example is the 
"table" example in the O3D docs where a table model is a scene graph of one 
master transform, with the table-top attached to it, and for sub-transforms 
with legs attached.

I have written my own shallow-copy code for the scenegraph (not complete, 
just enough for my needs) which i have attached below.  However this is an 
imperfect solution as it both requires more memory for the duplicated 
scenegraphs, and doesn't allow for simultaneous changes to all instances.  
(Imagine a row of 1,000 soldiers marching in unison, or a synchronized swim 
team.  Both require precisely synchronized changes to their transforms 
across all members.)

The best thing would be truly instance-able sub-graphs.  The next best 
thing would be a formal and complete shallow-copy as part of the library.

[code]

    shallowScenegraphCopy: function(pack,root){
        function copyNode(pack, original){
            var copy = pack.createObject('Transform')
            // add shapes if any, this is a shallow copy, shapes are shared
            var shapes = original.shapes;
            for (var i = 0; i < shapes.length; i++) {
                copy.addShape(shapes[i]);
            }
            // copy transform matrix
            var localMatrix = original.localMatrix
            copy.localMatrix = o3djs.math.copyMatrix(localMatrix)
            // descend tree
            var children = original.children;
            for (var i = 0; i < children.length; i++) {
                var childCopy = copyNode(pack,children[i])
                childCopy.parent = copy
            }
            return copy
        }
        return copyNode(pack,root)
    }
[/code]


Original issue reported on code.google.com by jef...@gmail.com on 17 Feb 2010 at 4:57