Grouping Nodes

Motivation

You can group shapes to compose complex shapes

X3D has several grouping nodes, including:

XML Encoding

<Group><!-- ... --></Group>
<Switch><!-- ... --></Switch>
<Transform><!-- ... --></Transform>
<Billboard><!-- ... --></Billboard>
<Anchor><!-- ... --></Anchor>
<Inline/>
<!-- and more -->

Classic Encoding

Group       { ... }
Switch      { ... }
Transform   { ... }
Billboard   { ... }
Anchor      { ... }
Inline      { ... }
and more

Syntax: Group

The Group node creates a basic group.

  • Every child node in the group is displayed.

XML Encoding

<Group>
  <!-- children ... -->
</Group>

Classic Encoding

Group {
  children [ ... ]
}

Syntax: Switch

The Switch group node creates a switched group

  • Only one child node in the group is displayed
  • You select which child
    • Children implicitly numbered from 0
    • A -1 selects no children

XML Encoding

<Switch
    whichChoice='0'>
  <!-- children ... -->
</Switch>

Classic Encoding

Switch {
  whichChoice 0
  children [ ... ]
}

Syntax: Transform

The Transform group node creates a group with its own coordinate system.

  • Every child node in the group is displayed.

XML Encoding

<Transform
    translation='0.0 0.0 0.0'
    rotation='0.0 1.0 0.0 0.0'
    scale='1.0 1.0 1.0'>
  <!-- children ... -->
</Transform>

Classic Encoding

Transform {
  translation 0.0 0.0 0.0
  rotation 0.0 1.0 0.0 0.0
  scale 1.0 1.0 1.0
  children [ ... ]
}

Syntax: Billboard

The Billboard group node creates a group with a special coordinate system.

  • Every child node in the group is displayed.
  • The coordinate system is turned to face viewer.

XML Encoding

<Billboard
    axisOfRotation='0.0 1.0 0.0'>
  <!-- children ... -->
</Billboard>

Classic Encoding

Billboard {
  axisOfRotation 0.0 1.0 0.0
  children [ ... ]
}

Billboard rotation axes

  • A rotation axis defines a pole to rotate round
  • Similar to a Transform node’s rotation field, but no angle (auto computed)
  • A standard rotation axis limits rotation to spin about that axis
  • A zero rotation axis enables rotation around any axis
Rotate about Axis
X-Axis 1.0 0.0 0.0
Y-Axis 0.0 1.0 0.0
Z-Axis 0.0 0.0 1.0
Any Axis 0.0 0.0 0.0

A sample billboard group

XML Encoding

<!-- Y-axis -->
<Billboard
    axisOfRotation='0.0 1.0 0.0'>
  <Shape><!-- ... --></Shape>
  <Shape><!-- ... --></Shape>
  <Shape><!-- ... --></Shape>
  <!-- ... -->
</Billboard>

Classic Encoding

Billboard {
  # Y-axis
  axisOfRotation 0.0 1.0 0.0
  children [
    Shape { ... }
    Shape { ... }
    Shape { ... }
    ...
  ]
}

Syntax: Anchor

An Anchor node creates a group that acts as a clickable anchor

  • Every child node in the group is displayed
  • Clicking any child follows a URL
  • A description names the anchor

XML Encoding

<Anchor
    url='"stairwy.wrl"'
    description='Twisty Stairs'>
  <!-- children ... -->
</Anchor>

Classic Encoding

Anchor {
  url "stairwy.wrl"
  description "Twisty Stairs"
  children [ ... ]
}

Syntax: Inline

An Inline node creates a special group from another X3D file’s contents

  • Children read from file selected by a URL
  • Every child node in group is displayed

XML Encoding

<Inline
  url='"table.wrl"'/>

Classic Encoding

Inline {
  url "table.wrl"
}

Summary

  • The Group node creates a basic group
  • The Switch node creates a group with 1 choice used
  • The Transform node creates a group with a new coordinate system
  • The Billboard node creates a group with a coordinate system that rotates to face the viewer
  • The Anchor node creates a clickable group
    • Clicking any child in the group loads a URL
  • The Inline node creates a special group loaded from another X3D file