the selector node

The selector node is a special type of grouping node that displays one child at a time, and can switch between them. This can make an object appear to change into a different object, or be replaced by another object. By default, the selector begins by showing the first child in its list. To make it show a different child, send it the select message with the name of the child you want to show.

You can also choose children by number instead of by name. This is handy if you have a lot of selection options, because you don't have to explicitly name all the nodes. It's also useful if you're controlling the selector using variables - for instance, you could set up a value node as a counter to step through the different selections.

The children of the selector can be any node type, not just object nodes. If you want to make the selector choose between whole groups of multiple nodes, just make each group a transform node. The transform would be the child of the selector, so when it gets selected, it turns on all of its children too.

The selector is not just a visibility control - it completely activates and deactivates its children. So, nodes like lights, triggers, and animations are deactivated when they are not selected. You can then swap whole sections of your scene in and out, deactivating parts of the world that you don't need. Sometimes this can make complex scenes run faster.

However, nodes like timers, animations, and sounds will not automatically start when they are selected - you do have to send them their start and stop messages after selecting them to start them running. This is particularly true of sounds, since sound playback is really handled by a completely separate program from YG itself.

Using the selector

This example uses the selector and pointAtTrigger to let the user choose a large shape from 3 small shapes. Point and click at the small cone, and a large cone appears. Click on the small donut, and the large shape turns into a donut.

Note that the pointAtTrigger also makes the small shapes grow slightly when you just point at them, which lets the user know that they are "active" in some way.

Also, the first child of the selector is just "node ()". this is a completely empty YG node, and is used to make the selector begin with nothing shown.

initial state click on the sphere click on the cone click on the torus

#include "User0"

light(position(1 -1 1))
light(position(-1 -.5 .75),diffuse(.4 .4 .4))


pointAtTrigger (when(start,ball.size(1.1)),
		when(stop,ball.size(1)),
		when(button1,shapeSelector.select("bigball")))
{
	object ball (file("redsphere.b3d"),position(-3 5 3))
}

pointAtTrigger (when(start,cone.size(1.1)),
		when(stop,cone.size(1)),
		when(button1,shapeSelector.select("bigcone")))
{
	object cone  (file("greencone.b3d"),position(0 5 3))
}

pointAtTrigger (when(start,donut.size(1.1)),
		when(stop,donut.size(1)),
		when(button1,shapeSelector.select("bigdonut")))
{
	object donut (file("purpletorus.b3d"),position(3 5 3))
}

selector shapeSelector ()
{
	node()
	object bigball (file("redsphere.b3d"),position(0 15 5),size(4))
	object bigcone  (file("greencone.b3d"),position(0 15 5),size(4))
	object bigdonut (file("purpletorus.b3d"),position(0 15 5),
		size(4),orientation(15 0 0))
}

Node Reference

Derived from: ygNode
Usage:
selector ()
{
	childnode0 ()
	childnode1 () 
	childnode2 ()
	...
}

Messages

MessageParametersDefaultDescription
select string Select a child node by name
selectNum int Select a child node by number, starting with 0

(c) Ben Chang