HEADER (a must for all files)
# VRML V1.0 ascii
COMMENTS
# This line is a comment
PRIMITIVES
Cube
{
width 2.00
height 2.00
depth 2.00
}
Sphere
{
radius 1.00
}
Cylinder
{
height 2.00
radius 1.00
parts ALL/TOP/BOTTOM/SIDES
}
Cone
{
height 2.00
bottomRadius 1.00
parts ALL/SIDES/BOTTOM
}
AsciiText
{
string " "
justification LEFT/RIGHT/CENTER
width 0.0 # width of line of text, 0.0 no compression or expansion
#each line can be changed: width [100.0 200.0 300.0]
spacing 1.0 # spacing factor of each line below the other
}
Font
# Note: set font first, then AsciiText
{
family SERIF/SANS/TYPEWRITER
style NONE/BOLD/ITALIC/BOLD|ITALIC
size 10
}
BACKGROUND COLOR OR IMAGE
DEF BackgroundColor Info
{
string " 0.0 0.0 0.0 " # RGB color
}
DEF BackgroundImage Info
{
string "name_of_image_file" # name of graphic file
}
POSITIONING SHAPES:
AXIS TRANSFORMATIONS
Translation
{
translation 0.0 0.0 0.0
}
Rotation
{
rotation 0.0 0.0 0.0 0.0
#X,Y,Z, amount in radians: rad=(degrees/180)*PI
#180° = 3.14159 rad
}
Scale
{
ScaleFactor 1.0 1.0 1.0
# neg numbers turn objects inside out, less than 1.0 reduce size can be
used to squash objects, for example. Retains scaling till changed again
}
Transform
{
translation 0.0 0.0 0.0
rotation 0.0 0.0 0.0 0.0
scaleFactor 1.0 1.0 1.0
scaleOrientation 0.0 0.0 0.0 0.0 # rotation axis and amount of scale factor
center 0.0 0.0 0.0 # X, Y, Z distance
{
MatrixTransform
{
matrix
|
1.0 |
0.0 |
0.0 |
0.0 |
|
0.0 |
1.0 |
0.0 |
0.0 |
|
0.0 |
0.0 |
1.0 |
0.0 |
|
0.0 |
0.0 |
0.0 |
1.0 |
}
EXAMPLE MATRIX TRANSFORMATIONS
RSS (Rotation, Scale Shear)
|
1.0 |
0.0 |
0.0 |
0.0 |
|
0.0 |
1.0 |
0.0 |
0.0 |
|
0.0 |
0.0 |
1.0 |
0.0 |
|
0.0 |
0.0 |
0.0 |
1.0 |
Scale (X, Y, Z)
|
1.0 |
0.0 |
0.0 |
0.0 |
|
0.0 |
1.0 |
0.0 |
0.0 |
|
0.0 |
0.0 |
1.0 |
0.0 |
|
0.0 |
0.0 |
0.0 |
1.0 |
X Rotation C = cosine, S = sine
|
1.0 |
0.0 |
0.0 |
0.0 |
|
0.0 |
C |
S |
0.0 |
|
0.0 |
-S |
C |
0.0 |
|
0.0 |
0.0 |
0.0 |
1.0 |
Y Rotation
|
C |
0.0 |
S |
0.0 |
|
0.0 |
1.0 |
0.0 |
0.0 |
|
S |
0.0 |
C |
0.0 |
|
0.0 |
0.0 |
0.0 |
1.0 |
Z Rotation
|
C |
S |
0.0 |
0.0 |
|
-S |
C |
0.0 |
0.0 |
|
0.0 |
0.0 |
1.0 |
0.0 |
|
0.0 |
0.0 |
0.0 |
1.0 |
Shear
|
1.0 |
0.0 |
0.0 |
0.0 |
|
0.0 |
1.0 |
0.0 |
0.0 |
|
0.0 |
0.0 |
1.0 |
0.0 |
|
0.0 |
0.0 |
0.0 |
1.0 |
Taper (X, Y, Z), always between -1.0 and 1.0
(better between -0.5 and 0.5)
|
1.0 |
0.0 |
0.0 |
0.0 |
|
0.0 |
1.0 |
0.0 |
0.0 |
|
0.0 |
0.0 |
1.0 |
0.0 |
|
0.0 |
0.0 |
0.0 |
1.0 |
Transform
|
1.0 |
0.0 |
0.0 |
0.0 |
|
0.0 |
1.0 |
0.0 |
0.0 |
|
0.0 |
0.0 |
1.0 |
0.0 |
|
0.0 |
0.0 |
0.0 |
1.0 |
Global Scaling Factor
|
1.0 |
0.0 |
0.0 |
0.0 |
|
0.0 |
1.0 |
0.0 |
0.0 |
|
0.0 |
0.0 |
1.0 |
0.0 |
|
0.0 |
0.0 |
0.0 |
1.0 |
SHADING NODES
Material
{
diffuseColor 0.0 0.0 0.0 # RGB color
emissiveColor 0.0 0.0 0.0 # "glowing" color
transparency 0.0 # transparency factor (0.0 = opaque, 1.0 = transparent)
ambientColor 0.0 0.0 0.0 # for lighting nodes
specularColor 0.0 0.0 0.0 # for lighting nodes
shininess 0.0 0.0 0.0 # for lighting nodes
}
GROUPING NODES
Group{ }
# groups children together, i.e. parts of a chair, not used much
TransformSeparator { }
# translations, rotations, scales only affect members within the separations,
settings restored to previous settings before the separation
Separator { }
# like TransformSeparator, but restores all settings
Separator
{
renderCulling AUTO/ON/OFF
# will not draw shapes if outside view, speeds rendering of nodes
}
Switch
{
whichChild -1
# numbers from 0, 1, 2, 3
etc., tells browser which child node to
draw, -1 to draw none, -3 to draw all. Used to easily switch various nodes
to try variations, or to DEF a shape without instancing it.
}
SPIN GROUPS
To spin parts of your world. NOTE: WORKED WITH LIVE3D
ONLY, may make other browsers crash... not sure where to get viewer....
DEF name_of_group SpinGroup
{
rotation 0 1 0 0.1 # angle and amount
# material, etc and name of node
}
INSTANCING SHAPES
Used to create a node, material or font style, then duplicate
original as many times as required
DEF node_name node
# where node_name is your name of object, (no spaces), node is the
object itself (primitive, materials, etc.)
USE node_name
#instance the named node, perhaps after translation, etc.
LINKING AND INLINING
You can join several files together by inlining your files,
(even across the Internet). Example is inlining a door to another room,
or using a furniture file in several rooms, used to create complex worlds
and reusing files
WWWAnchor
{
name "" # URL: VRML, HTML site, graphic, sound, etc.
description "" # a text string
map NONE/POINT # mapping type
# mapping is a program that runs on a server to select different links
depending on coordinates clicked
}
WWWInline
{
name "" # URL, example: file:table.wrl
bboxSize 0.0 0.0 0.0 # bounding box of file, width, height, depth
bboxCenter 0.0 0.0 0.0 # 3D coordinates, relative to current origin
# bounding box not necessary, but saves time by skipping the reading of
file
}
CREATING FACES, LINES, POINTS
Complex shapes can be created by describing vertices of
faces, typically triangles. Usually difficult by typing by hand! You use
the Coordinate3 node with IndexedFaceSet for faces, IndexedLineSet for
polylines, and PointSet for points (like stars) Use for complex shapes,
landscapes, grids, patterns, stars, city lights:
Coordinate3
{
point [ # list of XYZ vertices i.e.
1.0 0.0 0.0
-1.0 0.0 0.0
1.0 0.0 0.0
so on
]
}
IndexedFaceSet
{
coordIndex [ # list of vertices above, use any combination
0, 1, 2
..
]
}
IndexedFaceSet
{
coordIndex [0,1] # as above
materialIndex -1 # material or color list for each face
normalIndex -1 # normal or perpendicular
textureCoordIndex -1 # texture list
}
IndexedLineSet
{
coordIndex [0, 1] # as above
materialIndex -1 # material or color list for each face
normalIndex -1 # normal or perpendicular
textureCoordIndex -1 # texture list
}
PointSet
{
startIndex 0 # coordinate index
numpoints -1 # number of points to draw
MATERIAL BINDING
Used for shading, coloring, etc. Can shade faces, parts,
etc. separately. Can create rainbow effects, shaded or blended colors.
Material Binding can be
- Overall entire shape
- Per_part different material for each part
- Per_face different material for each face
- Per_vertex different material for each vertex
Material
{
diffuseColor [0.0 0.0 0.0 # list of RGB colors
0.0 0.0 0.0
0.0 0.0 0.0]
}
MaterialBinding
{
value DEFAULT
# also use OVERALL, PER_PART, PER_FACE, PER_VERTEX, PER_FACE_INDEXED,
PER_VERTEX_INDEXED
}
ADVANCED SHADING TECHNIQUES
Nodes can be shaded and smoothed with techniques involving
setting and binding normal vectors, smoothing, and using ShapeHints. See
the VRML Source Book for information on these techniques. (Someday I will
have time to write this up!)
MAPPING TEXTURES
You can use .GIF, TIF, .JPG, .PCX, .TGA files as patterns
or textures on surfaces of nodes, including text. Complex patterns can
be put on complex nodes using index lists. The way that patterns wrap
on nodes is complex, see the Source Book for details. Easy way is to create
only parts of a node, and apply patterns to each part, like the sides
of a cylinder for a can, for example.
Texture2Transform
{
translation 0.0 0.0 # S (horizontal), T (vertical) distance
rotation 0 # rotation amount
scaleFactor 1 1 # S, T scale factor
center 0 0 # S, T texture coordinate
{
Texture2
{
filename "" # name of file URL
wrapS REPEAT/CLAMP # horizontal texture wrap type
wrapT REPEAT/CLAMP # vertical texture wrap type
# only filename required
}
LIGHTING
PointLight # point source
{
on TRUE/FALSE
intensity 1 # Light intensity, 0.0 to 1.0
color 1.0 1.0 1.0 # RGB color
location 0.0 0.0 0.0 # X Y Z coordinates
}
DirectionLight # parallel directional light
{
on TRUE/FALSE
intensity 1 # Light intensity, 0.0 to 1.0
color 1.0 1.0 1.0 # RGB color
location 0.0 0.0 0.0 # X Y Z coordinates
}
SpotLight
{
on TRUE/FALSE
intensity 1 # Light intensity, 0.0 to 1.0
color 1.0 1.0 1.0 # RGB color
location 0.0 0.0 0.0 # X Y Z coordinates
direction 0.0 0.0 -1.0 # X Y Z coordinates
dropOffRate 0 # drop off factor
cutOffAngle 0.785 # cone angle, radians, default 45°
}
LOD
Level of detail. You can create different shapes that appear
at specified distances from viewer to node. Used to reduce detail at distances
to give more perspective clues. Can be used for animation effects too.
LOD
{
range [ ] # range list
center 0.0 0.0 0.0 # x Y Z coordinates (center of shape)
}
CAMERAS
Can be used to predetermine viewer's viewpoint. Can use
perspective camera for more realistic view of world, or orthographic camera
for unrealistic view, used in mechanical or drafting views. Cameras are
used at top of file.
PerspectiveCamera
{
position 0.0 0.0 1.0 # X Y Z position
orientation 0.0 0.0 1.0 0.0 # rotation angle and amount
focalDistance 5 # distance amount
heightAngle 0.789 # angle radians, 90° like fisheye
nearDistance 0.01 # not supported by all browsers
farDistance 5.0 # not supported by all browsers
# near and far distances are for clipping planes
}
OrthographicCamera
{
position 0.0 0.0 1.0 # X Y Z position
orientation 0.0 0.0 1.0 0.0 # rotation angle and amount
focalDistance 5 # distance amount
height 2 # height of viewing volume
nearDistance 0.01 # not supported by all browsers
farDistance 5.0 # not supported by all browsers
# near and far distances are for clipping planes
}