VRML 2.0

The Virtual Reality Modeling Language

 

This section describes key concepts relating to the VRML specification. This describes how to use scene graphs, nodes, events and prototypes.

1.1 Nodes

VRML is simply a file format for describing objects. The objects can be anything: 3D Geometry, music data, images and so on. These objects are called nodes. Nodes are the basic object in a VRML scene. A node has three properties:

field

Private property of a node.

ExposedField

Public property of a node. It can be modified by other nodes.

eventIn

It denotes an incoming event for a node. An eventIn typically changes a property of the node and its prototype is usually set_events. For example, set_position, set_color, set_intensity.

The declaration is:

eventIn set_foo

EventOut

It denotes an outgoing event for a node. It indicates that something in the node has changed and so an event has been generated. The prototype is usually events_changed. For example, position_changed, color_changed.

The declaration is:

EventOut foo_changed

A field declared as exposedField has both the events declaration. For example:

            ExposedField foo

Is equivalent to:

            field foo

            eventIn set_foo

            eventOut foo_changed

The set_foo event is generated when another node want to change the foo field. The foo_changed event is generated by the node when the foo property changes.

For example, here is the declaration of TouchSensor:

          TouchSensor {

              exposedField SFBool enabled TRUE

              eventOut SFVec3f hitNormal_changed

              eventOut SFVec3f hitPoint_changed

              eventOut SFVec2f hitTexCoord_changed

              eventOut SFBool isActive

              eventOut SFBool isOver

              eventOut SFTime touchTime

          }

isOver event is generated every time the mouse passes over the sensor.
enabled is the only field of the node. It can receive the event set_enabled and enabled_changed.

 

1.2 The Structure of the Scene Graph

A VRML scene has an hierarchical structure. The Scene Graph is described by Grouping nodes. Each grouping node has a children field that contains a list of nodes. Each grouping node defines a coordinate space for its children. There are five grouping nodes:

Anchor
Billboard
Collision
Group
Transform

For examples, the declaration of Group is:

          Group {

              eventIn MFNode addChildren

              eventIn MFNode removeChildren

              exposedField MFNode children []

              field SFVec3f bboxCenter 0 0 0

              field SFVec3f bboxSize -1 -1 -1

          }

The field children is used to add nodes to the Group. Grouping nodes can be added to the children field to generate an hierarchical structure.

A typical VRML file is:

#VRML V2.0 utf8

Transform {

 translation 3 0 1

 children [

  Transform {

   Translation 1 0 0 

    children [

     Shape {

      Geometry Sphere { radius 3 }

      Appearance Appearance { material

       Material { diffuseColor 1 0 0 }

      }

    ]

  }

 Shape { geometry Box {} }

 TouchSensor {}

 ]

}

 

 

1.3 Events

Nodes communicate with themselves sending events. A connection between two nodes is called ROUTE. A ROUTE is a connection between an eventOut and an eventIn of nodes. The syntax is:

ROUTE NodeName.eventOutName TO NomeName.eventInName

NodeName is the name of a node. DEF is used to set the name of a node.

An example :

Transform {

    children [ 

        Shape { Sphere {} } 

        DEF Clicker TouchSensor { }

    ]

}

Transform {

    children [

        DEF Light PointLight {}

    ]

}

ROUTE Clicker.isActive TO Light.on

When the sphere is clicked the light turns on.

 

1.4 Prototypes

It allows the encapsulation and parameterization of VRML objects.

The syntax is:

PROTO prototypename [ eventIn eventtypename name

                      eventOut eventtypename name

                      exposedField fieldtypename name defaultValue

                      field fieldtypename name defaultValue ... ] {

                      Geometry description

                      }

In the interface of the prototype there is the list of eventOuts, eventIns, exposedFields and fields of the node. Only these properties can be access from other nodes.

In the implementation there is the description of the VRML object. The IS statement can be used to associate a field in the interface with a field in the implementation.

This definition only defines a new type that can be used later as if it were a built-in node. An instantiation is used to create a node of this type.

For example:

PROTO fooSphere [ field SFFloat fooRadius 3.0 ] { #Prototype definition

      Sphere { 

          radius 3

          radius IS fooRadius

      }

}



fooSphere { fooRadius 42.0 } #Instantiation

 

1.5 References

VRML 2.0 Specifications: official specifications

http://www.vrml.org/Specifications/VRML2.0/

VRML 2.0 Concepts: general concepts about VRML 2.0

http://www.vrml.org/Specifications/VRML2.0/FINAL/spec/part1/concepts.html

VRML 2.0 Nodes Reference: detailed description of all built-in nodes

http://www.vrml.org/Specifications/VRML2.0/FINAL/spec/part1/nodesRef.html