© TMC Computer School
HC20203 VRML 2 - 1
HIGHER DIPLOMA IN COMPUTING
Chapter 2 – Basic VRML
© TMC Computer School
HC20203 VRML 2 - 2
HIGHER DIPLOMA IN COMPUTING
Structure of VRML File
VRML file consists of the following majorfunctional components
the VRML header
the scene graph which includes
Shapes
Interpolators
sensors and scripts
the prototypes
event routing
© TMC Computer School
HC20203 VRML 2 - 3
HIGHER DIPLOMA IN COMPUTING
#VRML V2.0 utf8
brown hut
Group {
        children [
        Draw the hut walls
                Shape {
                        appearance DEF Brown Appearance {
                                material Material {
                                        diffuseColor 0.6 0.4 0.0
                                }
                        }
           geometry Cylinder {
                                height 2.0
                                radius 2.0
                        }
                },
 
© TMC Computer School
HC20203 VRML 2 - 4
HIGHER DIPLOMA IN COMPUTING
 Draw the hut roof
                Transform {
                        translation 0.0 2.0 0.0
                        children Shape {
                                appearance USE Brown
                                geometry Cone {
                                        height 2.0
                                        bottomRadius 2.5
                                }
                        }
                }
        ]
}
 
E:\BOOK\WIN\CH02\02FIG01.GIF
© TMC Computer School
HC20203 VRML 2 - 5
HIGHER DIPLOMA IN COMPUTING
VRML Header
For easy identification of VRML files, every VRMLfile shall begin with
#VRML V2.0 <encoding type>
The <encoding type> is either "utf8" or any otherauthorized values defined in other parts of ISO/IEC14772
In this course, we are using "utf8" which indicates aclear text encoding that allows for internationalcharacters to be displayed in VRML
© TMC Computer School
HC20203 VRML 2 - 6
HIGHER DIPLOMA IN COMPUTING
UTF-8 File Format
# character begins a comment
Only the first comment (the file header) has semantic meaning
The only exception is within double-quoted SFString andMFString fields where the # character is defined to be part ofthe string
Commas, spaces, tabs, linefeeds, and carriage-returns areseparator characters wherever they appear outside of stringfields
One or more separator characters separate the syntacticalentities in VRML
The separator characters collectively are termed whitespace
© TMC Computer School
HC20203 VRML 2 - 7
HIGHER DIPLOMA IN COMPUTING
VRML Statements
VRML file may contain any combination of thefollowing :
Any number of PROTO or EXTERNPROTOstatements
Any number of root children node statements
Any number of USE statements
Any number of ROUTE statements
© TMC Computer School
HC20203 VRML 2 - 8
HIGHER DIPLOMA IN COMPUTING
Scene Graph
The scene graph contains nodes, which describeobjects and their properties
It contains hierarchically grouped geometry toprovide an audio-visual representation of objects
It also provides a means for nodes to participate inthe event generation and routing mechanism
© TMC Computer School
HC20203 VRML 2 - 9
HIGHER DIPLOMA IN COMPUTING
Nodes
Nodes are used to describe shapes and properties ofthe world such as:
shapes
colors
lights
viewpoints, how to position and orient shapes
animation times, sensors and interpolators
© TMC Computer School
HC20203 VRML 2 - 10
HIGHER DIPLOMA IN COMPUTING
Nodes
A node contains the following information:
type of nodes
a set of curly brackets
fields
For example, a cylinder node could be described:
cylinder
{
height 2.0
radius 2.0
}
© TMC Computer School
HC20203 VRML 2 - 11
HIGHER DIPLOMA IN COMPUTING
Fields and Field Values
Fields define the attributes of a node
In the above example, the height field defines theheight of the cylinder
Fields are optional within the nodes
If the values are not given, then a default value wouldbe assigned
For example, the default values of cylinder haveradius = 1.0 units and height = 2.0 units
Field values defines the attributes like color, size orposition
© TMC Computer School
HC20203 VRML 2 - 12
HIGHER DIPLOMA IN COMPUTING
Defining and Using Node Name
Any node can be defined in the world
The name of the node must begin with a letter,followed by any combination of characters and/ordigits
DEF node_name name_type
Once a node has a name, we could reuse the node.
The node with defined name is called original nodewhile the reuse nodes are called instances
USE node_name
Note that the node names are case-sensitive
© TMC Computer School
HC20203 VRML 2 - 13
HIGHER DIPLOMA IN COMPUTING
Describing Shapes
A VRML shape has appearance (based on material),color and surface texture
These attributes are specified by the field valueswithin a shape node
VRML supports several primitives shape geometriesthat include boxes, cylinders, cones, and shapes
VRML also supports advanced shape geometries likeextruded shapes and elevation grids
Using these primitive shapes, we could group themand build more complex shapes
Shapes can be grouped by the Group node
© TMC Computer School
HC20203 VRML 2 - 14
HIGHER DIPLOMA IN COMPUTING
Event Routing
Some VRML nodes generate events in response toenvironmental changes or user interaction
Event routing provides a mechanism, which allowevents to be propagated to effect changes in othernodes
Once generated, events are sent to their routeddestinations in time order and processed by thereceiving node
This processing can change the state of the node,generate additional events, or change the structure ofthe scene graph
© TMC Computer School
HC20203 VRML 2 - 15
HIGHER DIPLOMA IN COMPUTING
Event Routing
In order to build a dynamic world and propagateevents based on environmental changes, we need“wiring instructions”
This process involves
a pair of nodes to wire together
a wiring route or path between these two nodes
Once the nodes are wired, messages could be sentalong that route
Such message is called events which containscommunicating values
© TMC Computer School
HC20203 VRML 2 - 16
HIGHER DIPLOMA IN COMPUTING
Event Routing
For a successful routing, nodes must have eventInand the corresponding eventOut
An eventIn receives events when it is connected to aroute and a message is being sent to it
An eventOut sends the events out along the connectedroute
VRML “wiring” architecture is built by describing aroute from one node’s eventOut to another node’seventIn
© TMC Computer School
HC20203 VRML 2 - 17
HIGHER DIPLOMA IN COMPUTING
Event Routing
The receiving node reacts based on the event dependson the following:
type of node receiving the event
node input jack to which the route is wired
values contained in the event
current activities of the node
© TMC Computer School
HC20203 VRML 2 - 18
HIGHER DIPLOMA IN COMPUTING
Presentation and Interaction
The interpretation, execution, and presentation ofVRML files will typically be undertaken a browser,which displays the shapes and sounds in the scenegraph
This presentation is known as a virtual world and isnavigated in the browser by a human or mechanicalentity, known as a user
The world is displayed as if experienced from aparticular location; that position and orientation inthe world is known as the viewer
© TMC Computer School
HC20203 VRML 2 - 19
HIGHER DIPLOMA IN COMPUTING
Presentation and Interaction
The browser may define navigation paradigms (suchas walking or flying) that enables the user to move theviewer through the virtual world
The browser may provide a mechanism allowing theuser to interact with the world through sensor nodesin the scene graph hierarchy
Sensors respond to user interaction with geometricobjects in the world, the movement of the userthrough the world, or the passage of time
© TMC Computer School
HC20203 VRML 2 - 20
HIGHER DIPLOMA IN COMPUTING
Presentation and Interaction
The visual presentation of geometric objectsin a VRML world follows a conceptual modeldesigned to resemble the physicalcharacteristics of light
The VRML lighting model describes howappearance properties and lights in the worldare combined to produce displayed colours
Refer to the diagram for the conceptualmodel of the VRML browser
© TMC Computer School
HC20203 VRML 2 - 21
HIGHER DIPLOMA IN COMPUTING
Presentation and Interaction
VRML architecture overview
Conceptual Model of VRML Browser
© TMC Computer School
HC20203 VRML 2 - 22
HIGHER DIPLOMA IN COMPUTING
USE Statement
The USE statement enables us to reuse all the objectsthat we have defined earlier in the scene graph
A USE statement consists of the USE keywordfollowed by a node name as follows:
USE <name>
© TMC Computer School
HC20203 VRML 2 - 23
HIGHER DIPLOMA IN COMPUTING
ROUTE Statement
A ROUTE statement provides the message passingmechanism from one node to another
A ROUTE statement consists of the ROUTE keywordfollowed in order by a node name, a period character,a field name, the TO keyword, a node name, a periodcharacter, and a field name.
Whitespace is allowed but not required before orafter the period characters:
ROUTE <name>.<field/eventName> TO<name>.<field/eventName>
All these commands will be covered in more details asthe course proceeds