A SceneJS.Selector is a scene branch node that selects which
among its children are currently active.
This node is useful for dynamically controlling traversal within
a scene graph.
Examples
var s = new SceneJS.Selector({ selection: [0, 2]},
new SceneJS.objects.teapot(), // Child 0
new SceneJS.objects.cube(), // Child 1
new SceneJS.objects.sphere()) // Child 2
s.setSelection([0,1,2]); // Select all three child nodes
A more advanced example - the selector in this example switches
between three viewpoints of the scene content. The content is
instanced within each child of the Selector using Instance and
Symbol nodes. When we render the scene, we can pass in the
selection.
var myScene = new SceneJS.Scene({ ... },
new SceneJS.symbol({ name: "theScene" },
new SceneJS.objects.Teapot()
),
new SceneJS.Selector(
function(data) { // Child index as a dynamic config
return {
selection: [data.get("activeCamera")] // Selection
};
},
new SceneJS.LookAt({ eye : { z: 10.0 } },
new SceneJS.Instance({ name: "theScene"})),
new SceneJS.LookAt({ eye : { x: 10.0 }},
new SceneJS.Instance({ name: "theScene"})),
new SceneJS.LookAt({ eye : { x: -5.0, y: 5, z: 5 }},
new SceneJS.Instance({ name: "theScene" })
)
)
);
myScene.render({ activeCamera: 0 }); // Render scene for first viewpoint
myScene.render({ activeCamera: 1 }); // Once more for second viewpoint