Post

Grouping Nodes

Grouping Nodes

Motivation

You can group shapes to compose complex shapes

X3D has several grouping nodes, including:

XML Encoding

1
2
3
4
5
6
7
<Group><!-- ... --></Group>
<Switch><!-- ... --></Switch>
<Transform><!-- ... --></Transform>
<Billboard><!-- ... --></Billboard>
<Anchor><!-- ... --></Anchor>
<Inline/>
<!-- and more -->

Classic VRML Encoding

1
2
3
4
5
6
7
Group       { ... }
Switch      { ... }
Transform   { ... }
Billboard   { ... }
Anchor      { ... }
Inline      { ... }
and more

Syntax: Group

The Group node creates a basic grouping.

  • Every child node in the group is displayed.

XML Encoding

1
2
3
<Group>
  <!-- children ... -->
</Group>

Classic VRML Encoding

1
2
3
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

1
2
3
4
<Switch
    whichChoice='0'>
  <!-- children ... -->
</Switch>

Classic VRML Encoding

1
2
3
4
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

1
2
3
4
5
6
<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 VRML Encoding

1
2
3
4
5
6
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

1
2
3
4
<Billboard
    axisOfRotation='0.0 1.0 0.0'>
  <!-- children ... -->
</Billboard>

Classic VRML Encoding

1
2
3
4
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 aboutAxis
X-Axis1.0 0.0 0.0
Y-Axis0.0 1.0 0.0
Z-Axis0.0 0.0 1.0
Any Axis0.0 0.0 0.0

A sample billboard group

XML Encoding

1
2
3
4
5
6
7
8
<!-- Y-axis -->
<Billboard
    axisOfRotation='0.0 1.0 0.0'>
  <Shape><!-- ... --></Shape>
  <Shape><!-- ... --></Shape>
  <Shape><!-- ... --></Shape>
  <!-- ... -->
</Billboard>

Classic VRML Encoding

1
2
3
4
5
6
7
8
9
10
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

1
2
3
4
5
<Anchor
    url='"stairwy.wrl"'
    description='Twisty Stairs'>
  <!-- children ... -->
</Anchor>

Classic VRML Encoding

1
2
3
4
5
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

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

Classic VRML Encoding

1
2
3
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
This post is licensed under CC BY 4.0 by the author.