How to remove a node from the tree while preserving its children

78 views
Skip to first unread message

Guido

unread,
Mar 26, 2012, 2:10:26 PM3/26/12
to SceneJS
Hi,

for selection I'm temporarily adding a shader node to the scene graph
as a parent to the node I want to highlight (using insert). Is there
any way I can remove that temporary node and have its children get
moved to the original spot (the parent of that temporary node).

Thanks,
Guido

Benjamin Drucker

unread,
Mar 26, 2012, 7:46:16 PM3/26/12
to sce...@googlegroups.com
change the node type to "node"?  

Lindsay Kay

unread,
Mar 26, 2012, 8:00:51 PM3/26/12
to sce...@googlegroups.com
Hi,

I'm playing catchup here on the forum, work's a bit intense at the
moment. I'll try to work on some more github wiki pages soon as well.

Try the node's "splice" method:

myScene.findNode("my-mode").splice();

This method destroys node and moves its children up to parent,
inserting them where this node resided.

cheers,
Lindsay

On 27 March 2012 01:46, Benjamin Drucker

eric

unread,
Mar 28, 2012, 10:37:19 PM3/28/12
to sce...@googlegroups.com
Thanks so much for the quick reply!

Lindsay Kay

unread,
Mar 29, 2012, 12:23:19 PM3/29/12
to sce...@googlegroups.com
Hey no problem - 

just wanted to mention that adding and removing scene nodes has significant overhead, so try to avoid doing that often because it causes the display list to be recompiled from the scene graph. If you can avoid doing node additions and removals, then in most cases SceneJS will be able to cache the display list, pushing scene node state updates straight through into display list nodes without needing recompile.

Using "enabled" flags is an efficient way to enable and disable scene nodes (instead of removing and adding them), and those nodes can share state cores to reduce duplication of memory.


BTW In the next version I aim to expand the optimal performance sweet spot to include node additions and removals.

cheers,
LK
Reply all
Reply to author
Forward
0 new messages