VRML Nodes

Prefined VRML Shapes

Shape

Shape {
   appearance NULL
   geometry   NULL
}

Box

geometry Box { size 2.0 2.0 2.0 }

Cylinder

geometry Cylinder {
   radius 1.0
   height 2.0
}

Cone

geometry Cone { 
   bottomRadius 1.0
   height 2.0 
}

Sphere

geometry Sphere { radius 1.0 }

Text

geometry Text { 
   string "3D Text"
   fontStyle FontStyle {
      family "SERIF"
      style  "BOLD"
   }
}

Complex VRML shapes

Sets

  • PointSet (set of points)
  • IndexedLineSet (ordered points to draw lines)
  • IndexedFaceSet (ordered points to draw 'solid' shapes)

Elevation Grids

  • ElevationGrid (ordered list of heights for an x-z grid)

Extruded Shapes

  • Extrusion (2D cross section swept across a 3D path)

Transformation

A Transformation node is a kind of grouping node that is used to translate, rotate and scale its children

Translation

  • Used to position an object by specifying its location relative to a fixed point

VRML Translation Example

#VRML V2.0 utf8
Group {
  children [
 
    ...
  
    Transform {
      translation 2.0 2.0 0.0
      children [
        Shape {
          appearance Appearance {
            material Material {
              diffuseColor 1.0 0.0 0.0
            }
          }
          geometry Box {
          size 2.0 2.0 2.0
          }
        }
      ]
    }
  ]
}

Rotation

  • Pitch, rotation around X axis
  • Yaw, rotation around Y axis
  • Roll, rotation around Z axis
  • VRML uses Quaternions to describe rotations
    • R(X,Y,Z,theta), where X,Y,Z is a vector and theta is the angle

VRML Rotation Example

#VRML V2.0 utf8
Group {
  children [

    ...

    Transform {
      rotation    0.0 1.0 0.0  0.785
      translation 2.0 2.0 0.0
      children [
        Shape {
          appearance Appearance {
            material Material {
              diffuseColor 1.0 0.0 0.0
            }
          }
          geometry Box {
          size 2.0 2.0 2.0
          }
        }
      ]
    }
  ]
}

Scaling

  • Vertices multiplied by a scaling factor to scale an object
  • Can also be used to deform objects

VRML Scaling Example

#VRML V2.0 utf8
Group {
  children [

    ...

    Transform {
      scale       0.5 0.5 0.5
      translation 0.0 1.5 0.0
      children [
        Shape {
          appearance Appearance {
            material Material {
              diffuseColor 1.0 0.0 0.0
            }
          }
          geometry Box {
          size 2.0 2.0 2.0
          }
        }
      ]
    }
  ]
}

Appearance

The appearance of a surface is defined by setting properties that define the material from which it is made. A texture can also be defined to improve the appearance of a surface.

Diffuse colour
Colour of reflected light from diffuse reflection (light scattered randomly)
Specular colour
Colour of reflected light from specular reflection (light reflected in a regular manner)
Emissive color
Colour of light emitted by a the surface
Ambient intensity
Amount of background light the surface reflects
Shininess
Amount of specular reflection
Transparency
Transparency of the surface
Texture
Image (ImageTexture) or Movie (MovieTexture) mapped onto the surface

VRML Material Example

#VRML V2.0 utf8
Group {
  children [

    ...

    Shape {
      appearance Appearance {
        material Material {
          diffuseColor      0.22 0.15 0.0
          specularColor     0.71 0.70 0.56
          emissiveColor     0.0  0.0  0.0 
          ambientIntensity  0.4
          shininess         0.16
          transparency      0.0
        }
      }
      geometry Box {
        size 2.0 2.0 2.0
      }
    }
  ]
}

VRML Texture Example

#VRML V2.0 utf8
Group {
  children [

    ...
 
    Shape {
      appearance Appearance {
        material Material {}
        texture ImageTexture {
          url "surface.gif"
        }
      }
      geometry Box {
        size 2.0 2.0 2.0
      }
    }
  ]
}

Without textures

With textures

Lighting

Light can be...

  • Ambient (background)
  • Directional
  • Point (Omni-directional)
  • Spot

VRML Lighting Example

#VRML V2.0 utf8
Group {
  children [
  
    ...
  
    DirectionalLight {
      on               TRUE 
      intensity        0.6
      ambientIntensity 0.0
      color            0.0 1.0  0.0
      direction        0.0 0.5 -1.0
    },
    PointLight {
      on               TRUE
      intensity        0.8
      color            0.0 0.0 1.0
      location         5.0 5.0 0.0
    },
    SpotLight {
      on               TRUE
      intensity        0.6
      color            1.0  0.0 0.0
      location         5.0 -2.0 0.0
      direction       -1.0  0.0 0.0
      cutOffAngle      0.5
    }
  ]
}

Fog

Fog can be used to provide a depth cue, add atmosphere, and increase realism.

VRML Fog Example

  
#VRML V2.0 utf8
Group {
  children [

    ...
    
    Fog {
      color 1.0 1.0 1.0
      fogType "EXPONENTIAL"
      visibilityRange 30.0
    }
  ]
}

Without fog

With fog

Animation

  • Static environments are not usually very interesting
  • Interpolation is typically used to define animation in a virtual environment
  • In VRML, interpolator nodes can be used to control animation
    • A TimeSensor is used to generate events that can be sent to an interpolator node to set it's fraction time
    • An interpolator has a set of key fractional times and a set of key values
    • When the current key value of an interpolator changes, an event can be sent to another node to update a property such as position, orientation, or colour
    • The type of the event generated depends on the type of interpolator node used
    • A PositionInterpolator and OrientationInterpolator can be used to implement simple keyframe animation

VRML animation using an OrientationInterpolator

This is a rotating box.

VRML Animation example

#VRML V2.0 utf8
Group {

    ...

    DEF GreenBox Transform {
      children [
        Shape {
          appearance Appearance {
            material Material {
              diffuseColor 0.0 1.0 0.0
            }
          }
          geometry Box {
            size 2.0 2.0 2.0
          }
        }
      ]
    },
    DEF Clock TimeSensor {
      enabled TRUE
      cycleInterval 5.0
      loop TRUE
    },
    DEF Path OrientationInterpolator {
      key [ 0.0 0.5 1.0 ]
      keyValue [
        0.0 1.0 1.0 0.0,
        0.0 1.0 1.0 3.14,
        0.0 1.0 1.0 6.28
      ]
    }
  ]
}

ROUTE Clock.fraction_changed TO Path.set_fraction
ROUTE Path.value_changed     TO GreenBox.set_rotation

Interaction

  • Objects need to be able to receive event messages triggered by user actions, and react on them, in order to be able to support interaction
  • In VRML, sensor nodes are used to detect user actions and generate events
  • A TouchSensor is used to detect touch and can generate several different output events that describe how, when and where a user touched an object
  • A CylinderSensor, PlaneSensor, or SphereSensor can be used both to detect whether a shape is 'active' and to update it's position or orientation
  • Other sensor node types exist to detect proximity and visibility
  • Collision and Anchor nodes also detect user actions
  • Typical reactions include
    • Modifying a node's property
    • Starting an animation
    • Providing audio feedback
    • Deforming an object
    • Passing a value to a script node for processing
    • ...

VRML Interaction using a SphereSensor

This is a box that that the user can rotate by dragging it.

VRML Interaction example

#VRML V2.0 utf8
Group {
  children [

    ...

    DEF GreenBox Transform {
      children [
        Shape {
          appearance Appearance {
            material Material {
              diffuseColor 0.0 1.0 0.0
            }
          }
          geometry Box {
            size 2.0 2.0 2.0
          }
        }
      ]
    },
    DEF Drag SphereSensor { },
  ]
}

ROUTE Drag.rotation_changed TO GreenBox.rotation

Anchors

In VRML, objects can represent links that can be used to access other virtual worlds or Net resources such as Web pages.

VRML Anchor example

#VRML V2.0 utf8
  Group {
    children [

      ... 

      Anchor {
        url "../index.html"
        description "Return to lecture"
        children [
          Shape {
            geometry Text {
              string ["Go back to", "Web3D Lecture" ]
              fontStyle FontStyle {
                justify "MIDDLE"
              }
            }
          }
        ]
      }
    ]
  }

Inline nodes

Inline nodes are used to reference other VRML files, enabling their contents to be included in a virtual environment.

The basic syntax is simply Inline { url "url_goes_here" }

Inlined nodes are loaded after the main file has been loaded.




Michael Louka, October 10, 2001