The Annotated VRML 97 Reference

1 Intro     Concepts     3 Nodes     4 Fields/Events    Conformance
A Grammar     B Java     C JavaScript     D Examples     E Related Info    References
Quick Java         Quick JavaScript         Quick Nodes   
 

  About the Book
  
Help
  Copyright © 1997-99
  Purchase the book from Amazon.com

Chapter 3:
Node Reference


Intro
Anchor
Appearance
AudioClip
Background
Billboard
Box
Collision
Color
ColorInterpolator
Cone
Coordinate
CoordinateInterpolator
Cylinder
CylinderSensor
DirectionalLight
ElevationGrid
Extrusion
Fog
FontStyle
Group
ImageTexture
IndexedFaceSet
IndexedLineSet
Inline
LOD
Material
MovieTexture
NavigationInfo
Normal
NormalInterpolator
OrientationInterpolator
PixelTexture
PlaneSensor
PointLight
PointSet
PositionInterpolator
ProximitySensor
ScalarInterpolator
Script
Shape
Sound
Sphere
SphereSensor
SpotLight
Switch
Text
TextureCoordinate
TextureTransform
TimeSensor
TouchSensor
Transform
Viewpoint
VisibilitySensor
WorldInfo

+3.7 Box

Box { 
  field    SFVec3f size  2 2 2        # (0, INF)
}

The Box node specifies a rectangular parallelepiped box centred at (0, 0, 0) in the local coordinate system and aligned with the local coordinate axes. By default, the box measures 2 units in each dimension, from -1 to +1. The Box node's size field specifies the extents of the box along the X-, Y-, and Z-axes respectively and each component value must be greater than 0.0. Figure 3-6 illustrates the Box node.

Box node diagram

Figure 3-6: Box node

Textures are applied individually to each face of the box. On the front (+Z), back (-Z), right (+X), and left (-X) faces of the box, when viewed from the outside with the +Y-axis up, the texture is mapped onto each face with the same orientation as if the image were displayed normally in 2D. On the top face of the box (+Y), when viewed from above and looking down the Y-axis toward the origin with the -Z-axis as the view up direction, the texture is mapped onto the face with the same orientation as if the image were displayed normally in 2D. On the bottom face of the box (-Y), when viewed from below looking up the Y-axis toward the origin with the +Z-axis as the view up direction, the texture is mapped onto the face with the same orientation as if the image were displayed normally in 2D. TextureTransform affects the texture coordinates of the Box.

The Box node's geometry requires outside faces only. When viewed from the inside the results are undefined.

TIP: Box nodes are specified in the geometry field of a Shape node; they may not be children of a Transform or Group node.

TIP: To change the size of a Box node after it is created, use a Script node that sends changes to the Transform node that parents the Shape containing the Box:
     DEF BoxTransform Transform { 
       children Shape {
         geometry Box { size 3 4 2 } # initial size 
       }
     } 
     ... 
     DEF BoxScaler Script { 
       eventIn ...            # event triggers the change
       eventOut SFVec3f scale # the Box's computed size
       url "..."              # Script computes scale
     } 
     ROUTE BoxScaler.scale TO BoxTransform.scale

TECHNICAL NOTE: Box was called Cube in VRML 1.0 (which was a misnomer because its width, height, and depth could be varied). Implementations usually draw boxes as 12 triangles (you should keep this in mind if you are tempted to create a scene that contains 1,000 boxes). If you can, instead, create the same scene using fewer than 12,000 triangles in an IndexedFaceSet, you should use the IndexedFaceSet.

TECHNICAL NOTE: The size field of Box is not exposed and so cannot change once the Box has been created. This was done to make very efficient, lightweight implementations possible.

EXAMPLE (click to run): The following example illustrates the use of the Box node (see Figure 3-7). Note the default mapping of the texture on the faces of the box:
#VRML V2.0 utf8 
Transform { children [ 
  Shape { 
    geometry Box { } 
    appearance Appearance { 
      material Material { diffuseColor 1 1 1 } 
      texture ImageTexture { url "marble2.gif" } 
    } 
  } 
  Shape { 
    geometry Box { size 1 1 3 } 
    appearance Appearance { 
      material Material { diffuseColor 0.8 0.8 0.8 } 
    } 
  } 
  Shape { 
    geometry Box { size 3 1 1 } 
    appearance Appearance { 
      material Material { diffuseColor 0.6 0.6 0.6 } 
    } 
  } 
  Shape { 
    geometry Box { size 1 3 1 } 
    appearance Appearance { 
      material Material { diffuseColor 1 1 1 } 
    } 
  } 
  NavigationInfo { type "EXAMINE" } 
  Background { skyColor 1 1 1 } 
]}

Box node example

Figure 3-7: Example Box Nodes with Texture Image