You are on page 1of 31

Virtual Reality Modeling Language

(VRML97)

©Anthony Steed 1998-2005

1
Introduction to VRML

■ Virtual Reality Modelling Language


• A file format to describe 3D scenes
– identified by “.wrl” extension
• Also a description of a run-time system for
animating worlds
• Designed to be used in network situations
• Supports interaction and simulation of behaviour
of objects
• Designed to run on desktop PCs through to high-
end workstations
• MIME type is model/vrml
2
VRML Basics

■ VRML file contains ■ Example Node specification


Nodes that describe
the scene Cone {
field SFFloat bottomRadius 1
■ A Node is defined field SFFloat height 2
with several Fields field SFBool side TRUE
• Each line give the field SFBool bottom TRUE
field, the type of the }
field, the name and
the default value.

3
Sample VRML File “example1.wrl”

#VRML V2.0 utf8


Transform {
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 0.1 0.7 0.2
}
}
geometry Sphere {
radius 2
} }
] Every VRML97 file starts
} #VRML V2.0 utf8
4
Classes of Node

■ Shapes
• Geometry
• Appearance
■ Transformations
■ Lights
■ Groups

5
Shapes

■ Each Shape has a geometry ■ Example (from


field that contains a geometry example1.wrl)
node and an appearance field
that contains an Appearance Shape {
node
appearance Appearance {
material Material {
Shape { diffuseColor 0.1 0.7 0.2
appearance <some appearance> }
geometry <some geometry> }
geometry Sphere {
}
radius 2
}

6
Geometry Nodes

■ Basic types ■ Box


• • defined by its size field
Box
Box {
• Sphere size 2.0 2.0 2.0
• Cylinder }
• Cone ■ Sphere
• Text • defined by its radius field
Sphere {
radius 1.5
}

7
Geometry Nodes

■ Cylinder ■ Text
• defined by its height and • defined by the string
radius fields
Cylinder {
and the font
height 2.0 geometry Text {
radius 1.0 string ["Hi!"]
} fontStyle FontStyle {
■ Cone family "TYPEWRITER"
• defined by its height and style "ITALIC"
radius fields }
Cone { }
radius 1.3
height 1.8
}
8
Complex Geometry
■ Many objects can not be described with
standard solids
■ General geometry described with
• IndexedFaceSet, IndexedLineSet,
PointSet, ElevationGrid, Extrusion
■ Each uses some of the following nodes
in definition
• Coordinate, Normal, Color,
TextureCoordinate
9
PointSet
■ Define a set of points and the colour of
each point
11

10
5
3
0
7 1 4
2
6
9
8

10
IndexedFaceSet
IndexedFaceSet { field SFBool ccw TRUE
eventIn MFInt32 set_colorIndex field MFInt32 colorIndex []
eventIn MFInt32 set_coordIndex field SFBool colorPerVertex TRUE
eventIn MFInt32 set_normalIndex field SFBool convex TRUE
eventIn MFInt32 set_texCoordIndex field MFInt32 coordIndex []
exposedField SFNode color NULL field SFFloat creaseAngle 0
exposedField SFNode coord NULL field MFInt32 normalIndex []
exposedField SFNode normal NULL field SFBool normalPerVertex TRUE
exposedField SFNode texCoord NULL field SFBool solid TRUE
field MFInt32 texCoordIndex []
}

11
IndexedFaceSet
■ Components
• the points to construct the face from
• the normals to give at the points
• the colours of the points
• the texture coordinates of the points
■ Can define normals and colours
• for each vertex or each face
■ Texture coordinate defined at each vertex Hints
• each face is “convex”
• the faces are defined in counter-clockwise order
• the object is solid (i.e. each triangle is one-sided)

12
IndexedFaceSet
■ Coordinate
■ Define faces using list of vertices each
terminated by -1
geometry IndexedFaceSet {
coord USE COORDS
coordIndex [ 0, 2, 9, 5, 0, -1, 3, 0, 5, 11, 3, -1,
1, 3, 11, 7, 1, -1, 2, 1, 7, 9, 2, -1
0, 3, 10 ,4, 0, -1, 3, 1, 6, 10, 3, -1,
2, 8, 6, 1, 2, -1, 2, 0, 4, 8, 2, -1,
9, 8, 4, 5, 9, -1, 5, 4, 10, 11, 5, -1,
11, 10, 6, 7, 11, -1, 7, 6, 8, 9, 7, -1
] 13
IndexedFaceSet
■ Colour per face ■ Colour per vertex
color Color { color [ 1 1 1, 0.3 0.3 color Color { color [ 1 1 1, 0.3
0.3]} 0.3 0.3]}
colorPerVertex FALSE colorPerVertex TRUE
colorIndex [ 0, 0, 0, 0, 0, 0, colorIndex
0, 0, 1, 1, 1, 1] [ 0, 1, 1, 0, 0, -1, 1, 0, 0, 1, 1,
-1,
0, 1, 1, 0, 0, -1, 1, 0, 0, 1, 1, -1
0, 1, 1 ,0, 0, -1, 1, 0, 0, 1, 1, -1,
0, 1, 1 ,0, 0, -1, 1, 0, 0, 1, 1, -1,
0, 1, 1 ,0, 0, -1, 1, 0, 0, 1, 1, -1,
0, 1, 1 ,0, 0, -1, 1, 0, 0, 1, 1, -1
]
12 colours = 1 per face 72 indices = 1 for each vertex in the
face set definition 14
IndexedFaceSet
normal Normal {
■ Normal vector [
-1 0 -1, 1 0 1, 1 0 -1, -1 0 1,
• defines the direction of 1 0 0, -1 0 0, 0 0 1, 0 0 -1
each point and the way it ]
}
reflects light normalPerVertex TRUE
• default normal is normalIndex [
5, 7, 7, 5, 5, -1, 6, 5, 5, 6, 6, -1,
perpendicular to surface 4, 6, 6, 4, 4, -1, 7, 4, 4, 7, 7, -1
of polygon 5, 6, 6 ,5, 5, -1, 6, 4, 4, 6, 6, -1,
7, 7, 4, 4, 7, -1, 7, 5, 5, 7, 7, -1,
• polygon is flat if all 1, 1, 1, 1, 1, -1, 2, 2, 2 ,2, 2, -1,
normals point same way 0, 0, 0, 0, 0, -1, 3, 3, 3, 3, 3, -1
]
• otherwise smooth
interpolation

15
IndexedFaceSet
■ Texture Coordinates texCoord TextureCoordinate {
• specify the position on the point [ 0 0, 0 1, 1 1 , 1 0 ]
texture map of each point on
the shape }
• fractional points are allowed texCoordIndex [
• measure from bottom left of 0, 1, 2, 3, 0, -1, 0, 1, 2, 3, 0, -1,
image 0, 1, 2, 3, 0, -1, 0, 1, 2, 3, 0, -1,
■ Ugly example: 0, 1, 2, 3, 0, -1, 0, 1, 2, 3, 0, -1,
0, 1, 2, 3, 0, -1, 0, 1, 2, 3, 0, -1,
0, 1, 2, 3, 0, -1, 0, 1, 2, 3, 0, -1,
0, 1, 2, 3, 0, -1, 0, 1, 2, 3, 0, -1
]

16
IndexedLineSet
■ Defines a line set
■ Colour per line or per vertex
geometry IndexedLineSet {
coord USE COORDS
coordIndex [ 0, 4, 5, 0, -1, 3, 10 , 11, 3, -1,
1, 6, 7, 1, -1, 2, 8, 9, 2, -1,
0, 2, 1, 3, 0, -1,
4, 8, 6, 10, 4, -1,
5, 9, 7, 11, 5, -1]
color Color { color 1 1 1}
colorPerVertex FALSE
colorIndex [ 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}
17
Transformations

■ Define the positions of objects in 3D


space
■ XY are the plane of the screen
■ Z is towards the Viewer Y
■ Transformation basically contains
• X
rotation
• scale
• translation
Z
• a set of children nodes
■ Rotations follow “right-hand screw
rule” 18
Effects of Transformation

■ translation
Transform {
translation 1 1 -1
children [

]}
■ rotation
translation 1 1 -1
rotation 0 1 0 0.785
■ scale
translation 1 1 -1
rotation 0 1 0 0.785
scale 0.5 1.0 0.5
19
Scene Graph
Transform {
■ Transforms are translation 0 2 0
children [
hierarchical Shape { <OBJECT1> }
Transform {
• forms a directed translation 2 0 0
children [
acyclic graph Shape { <OBJECT2> }
Transform {
translation 0 0 -2
children [
Shape { <OBJECT3> }
]
}
]
}
]
}

20
Transform Hierarchy Example

Transformation

Box Transformation

Box Transformation

Box

21
Node Re-Use
■ Objects can be re-used DEF UCL_BOX Shape {
using DEF/USE pairs appearance Appearance {
■ DEF a name for a node texture ImageTexture {
when it is first being url ["logo.jpeg"]
decsribed }
}
USE a node geometry Box {
whenever a node of that size 2 2 2
type is required
}
• I.E. if you DEF an
}
Appearance node then
USE of that node must
be in a place that is valid
for an Appearance node
to be
22
DEF/USE Example
#VRML V2.0 utf8

Transform {
translation 0 0 0
children [
DEF UCL_BOX Shape {
appearance Appearance {
texture ImageTexture {
url ["logo.jpeg"]
}
}
geometry Box {
size 2 2 2
}
}
]
}

Transform {
translation 0 3 0
children [
USE UCL_BOX
]
} 23
Appearance

■ Defines the look of some piece of geometry


• Material
– combination of
• ambient colour, diffuse colour, emmisive colour,shinines,
transparency, specular colour
• Texture
– defines a picture to paste to the object
• fetch from a URL
• supports movies
• TextureTransform
– defines how the picture is applied to the object

24
Material Examples
■ Material Colour components defined in
• Shiny Material RGB (red, green, blue triplets)
ambientIntensity 0.3
diffuseColor 0.1 0.7 0.2
specularColor 0.6 0.8 0.6
shininess 0.6
• Dull Material
ambientIntensity 0.1
diffuseColor 0.1 0.7 0.2
shininess 0.0
• Transparent Material
diffuseColor 0.1 0.7 0.2
transparency 0.5

25
Lights

■ Provide illumination in the scene


• DirectionalLight
• PointLight
• SpotLight
■ DirectionalLight
• light rays travelling in parallel lines e.g. sunlight
DirectionalLight {
direction -1 -1 -1
intensity 0.8
}

26
Lights

■ PointLight
• radiate in all directions
■ SpotLight
• radiate only in certain directions, and with
volumes of different intensity
■ SpotLight and PointLight “attenuate” -
their effect can decrease over distance

27
Other Things …
■ Interaction ■ Fog
■ Scripting ■ Background
• Java ■ Audio
• JavaScript ■ Video
■ Interpolators ■ LOD
■ Sensors ■ Billboard

28
LOD
■ Switches between two or
more views depending on
distance

■ Nearby View
Bunny1 = ~56K polygons

■ Distant View
Bunny2= ~1K polygons

29
Billboards

■ Billboards
• object always faces the
viewer

Transform {
translation 0 3 0
children [
Billboard {
children [
USE UCL_BOX
]
}
]
} 30
Summary
■ VRML97 provides a simply file format to
put 3D objects on the web
■ Animation and scripting are allowed, but
we haven’t discussed these
■ Somewhat restricted model of local
lighting compared to today’s graphics
cards

31

You might also like