OpenGL VRML Shockwave 3D
Home Tutorials Books Applications Tools Docs Models Textures

Send me bugs and suggestions, please
VRML Script Tutorial
Full list

VRML Interactive Tutorial

Introduction
VRML File Structure
Drawing: Shape node
Geometry Nodes:
Box
Sphere
Cone
Cylinder
PointSet
IndexedLineSet
IndexedFaceSet
Extrusion
ElevationGrid
Example: Chessboard
Text
FontStyle
Appearance
Material
Textures
Image Texture
Movie Texture
Pixel Texture
Texture Coordinate
Texture Transform
Let there be Light
Directional Light
Point Light
Spot Light
Materials with Colored Lights
Hierarchical Node Structures
Group
Transform
Collision
Anchor
Billboard
Switch
Inlining Files
Defining and Instancing Nodes
Defining Levels of Detail
Events in VRML
Creating Paths between events: ROUTE
Generating Events based on Timers or User Actions
Timers
Touch Sensor
Visibility Sensor
Dragging Sensors
Plane Sensor
Sphere Sensor
Cylinder Sensor
Proximity Sensors
Example: Proximity sensor
Interpolators
Color
Coordinate
Normal
Orientation
Position
Scalar
Example
Let the Music Play
Sound
AudioClip
Bindable Nodes
Who Am I: NavigationInfo
Where Am I: ViewPoint
Adding Realism to the world
Background
Fog
Information about your world
WorldInfo
Definition for Auxiliary Nodes
Coordinate
Color
Normal

Defining and Instancing Nodes


VRML allows you to define a a set of nodes, or a node with particular field values, as a new node type. Suppose you want to draw a set of shapes, all having the same Appearance node.

There are two ways of doing this: the hard way, which requires the Appearance node to be repeated for each shape; or the easy way in which you define the common Appearance node as being a new node type.

The latter approach is not only easier, since you don't have to rewrite the defined node over and over again, but it also guarantees that the shapes share the same Appearance node.

This has clear advantages when, for instance, you decide that the defined node should be altered. Defining the node once and using it multiple times you have to change only the node which is being defined instead of changing all occurrences of the defined node.

Two keywords are provided: DEF and USE.

Syntax:
{
DEF name node
}


where node is any of the VRML nodes, and name is the new node identifier.

Syntax:
{
USE name
}


where name is an identifier which has been previously defined using DEF.

Note: When defining nodes in a inlined file the defined identifier can only be instanciated inside the inlined file, i.e. the identifier is not recognized outside the file where it is defined.

Example: suppose that you want two red Shapes in your world. The VRML code to define this world could be something like:

Example:
Shape { appearance
DEF common_appearance Appearance {
material Material {diffuseColor 1 0 0}
}
geometry Sphere { }
}

Transform {
translation -2 0 0
children [
Shape {
appearance USE common_appearance
geometry Cone { }
}
]
}


The result of the above code is:



Site designed and maintained by António Ramires Fernandes
Your comments, suggestions and references to further material are welcome!

Lighthouse 3D privacy statement