Skip to content
Lindsay Kay edited this page Aug 24, 2013 · 11 revisions

Methods for traversing the nodes in a scene

eachNode

A method on node which iterates over the nodes in its subtree.

Options

  • andSelf - include selected node in iteration
  • depthFirst - depth-first iteration of all sub-nodes
  • breadthFirst - breadth-first iteration of all sub-nodes

If neither depthFirst nor breadthFirst are selected then only the immediate children of the target node are visited.

The following example iterates depth-first over all sub-nodes of a given scene node, changing the baseColor attribute of each material encountered:

var myNode = myScene.findNode("my-node");

myNode.eachNode(
    function() {
        if (this.get("type") == "material") {
            this.set({ baseColor: { r: 1, g: 0, b: 0}});
        }
    },
    {
        andSelf: true,     // Visit our myLookat node as well
        depthFirst: true   // Descend depth-first into tree
    }
);

eachParent

A method on node which iterates over nodes on the path up to the scene at the root

myNode.eachParent(
    function() {
        alert("At parent node: " + this.get("ID"));
    }
);
Clone this wiki locally