03: composition

quick overview of the bindable nodes

grouping nodes

can be thought of as containers, since most have an MFNode field for 'wrapping around' sub-nodes.

as a performance hint to the browser, most grouping nodes allow you to specify a bounding box, which gives the browser a short cut approximation of the extents of the contained geometry. if not specified, the vrml browser will calculate it automatically.

grouping nodes make sense when you have a single effect you want to apply to multiple nodes.

collectors

selectors

connectors

effectors

node instancing

creating variables in the scene graph
#VRML V2.0 utf8

DEF CUBE Shape {
   appearance Appearance {
      material Material {}
   }
   geometry Box {
      size 1 1 1
   }
}

Transform {
   translation -2 0 0
   children [
      USE CUBE
   ]
}

Transform {
   translation 2 0 0
   children [
      USE CUBE
   ]
}

working with transforms

a cube

DEF CUBE Shape {
   appearance Appearance {
      material Material {}
   }
   geometry Box {
      size 1 1 1
   }
}

a translated cube

specify amount of translation with an SFVec3f: x y z
Transform {
   translation -2 0 0
   children [
      USE CUBE
   ]
}

a scaled cube

specify amount of scale with an SFVec3f: x y z.
numbers greater than 1 increase scale; numbers less than one decrease scale. negative numbers are not formally allowed.
Transform {
   scale .5 3 .5
   children [
      USE CUBE
   ]
}

SFRotation

an SFVec3f defining an axis combined with an SFFloat specifying (in radians) the amount to rotate about the axis.
example: 30 degrees positive rotation around the y axis: 0 1 0 .524

360 degrees = 2 * PI radians:
radians = degrees / 180 * PI
degrees = radians / PI * 180
degrees   radians
which way around? remember the right-hand rule: point the thumb of your right hand along the positive direction of the axis in question. the direction that your fingers curl into your palm is the direction of positive rotation about that axis.

a rotated cube

Transform {
   rotation 0 1 0  .7853
   children [
      USE CUBE
   ]
}

combining transforms

all transformations applied in the same Transform node happen together, in a 'natural' order (scale, rotate, translate):
Transform {
   rotation 0 0 1   .7853
   translation 2 0 0
   scale .5 .5 .5
   children [
      USE CUBE
   ]
}

nesting transforms

by nesting Transform nodes, you can control the order of transformations. Inner-most nodes are evaluated first, so the following will translate, then rotate:
Transform {
   rotation 0 0 1   .7853 # second
   children [
      Transform {
         translation 2 0 0 # first
         children [
            USE CUBE
         ]
      }
   ]
}
example [»]

and this example will translate, then scale:
Transform {
   scale .5 .5 .5 # second
   children [
      Transform {
         translation 2 0 0 # first
         children [
            USE CUBE
         ]
      }
   ]
}
example [»]

task02 [»]