#57 ✓resolved
lindsay.kay (at xeolabs)

Branching - Provide SceneJS.Selector Node

Reported by lindsay.kay (at xeolabs) | May 7th, 2010 @ 09:44 AM | in V0.7.4

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

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

SceneJS provides easy access to WebGL through a simple and declarative JavaScript API. The SceneJS API is functional, which enables its scene definitions to be really compact and expressive, while hooking into other JavaScript code just that little bit more smoothly.

Shared Ticket Bins

People watching this ticket

Pages