VRML : The Basics

VRML files contain a set of objects. Technically these objects are called nodes. Nodes are arranged in "hierarchical structures", similar to directories and sub-directories on a disk. For example, on a PC, the directory C:\WINDOWS\SYSTEM comes under (is a member of) the C:\WINDOWS directory. In VRML, things at higher levels (in this example, the C:\WINDOWS directory) affect their members (C:\WINDOWS\SYSTEM). For example, if a statement at the C:\WINDOWS level to make new objects red existed, then any objects created at the C:\WINDOWS\SYSTEM level would also be red. However, if a statement at the C:\WINDOWS\SYSTEM level then changed it so that new objects were blue, objects at the C:\WINDOWS level are not necisarily blue, because the statement came at a lower level. Therefore, when a node is closed, any changes made to the default material, translation, rotation etc. are lost. A special node, called the separator node exists to separate these defaults. Whilst this may sound complicated, it isn't that bad, and is easy to pick up.

Headers
Every VRML file must start with the same line so as to identify it easily as a VRML file :
#VRML V1.0 ascii

Comments
Comments can be started by using the '#' (hash) character. Anything after this on the same line is ignored. The comment is ended by the end of the line (ASCII newline or carriage return). There is one exception to this where the '#' character is inside a string data type. Note that some servers may strip out comments, so if you want to include copyright info or a bit about the author then use the Info node (see later). Example:
#My Comment ...

General Layout
Each VRML file contains exactly 1 node at the highest level (in our example, each disk drive has only 1 root directory, C:\). This node is therefore usually either the "Separator" or "SpinGroup" node. You will see later that both of these nodes can contain any number of 'child' nodes, (or subdirectories in our example). A typical VRML file might look like this:

#VRML V1.0 ascii

Separator {
	#The first level-2 node
	#The second leve-2 node
	'
	'
	#The 'n'th level-2 node {
		#The first level-3 node
		'
		'
		#The last level-3 node
	}
	'
	'
	#The last level-2 node
}
Obviously, in a real VRML file, '#The first level-2 node' would replaced with for example 'Sphere {' etc.

Node Parameters
Almost every node has an ascosiated set of parameters. For example, the 'Sphere' node has the parameter 'radius'. In VRML, you do not have to specify parameters that you do not wish to change from the default value. For the 'Sphere' node, the 'radius' parameter has a default value of 1 unit, so

Sphere {}
Sphere { radius 1 }
Sphere {
	radius 1
}
all produce the same effect. Many nodes, for example the 'Cube' node have more than one parameter. In this case, you can specify 0 or more of the parameters. Unspecified parameters use the default values. For the 'Cube' node, all three of it's parameters ('width', 'height', and 'depth') have a default value of 2. Therefore
Cube {}
would produce a 2*2*2 cuboid, whilst
Cube {
	width 8
	depth 1
}
would produce a 8*2*1 cuboid.

Coordinate System
VRML worlds use a "cartesian, right-handed, 3D coordinate system". What does this mean? Well, if you were looking at the origin (0,0,0) with +x going off to the right, and +y going straight up, then +z would be coming out towards you.

[Picture of RH carterian axes]

You can also visualise it by thinking about opening a bottle of wine. If you are screwing-in the corkscrew, with the handle centered on the x-axis (the screw going down the z axis), and you turn it so that the half of the handle that was on positive x goes through 90 degrees onto positive y, the the corkscrew moves in the positive z direction.

Standard VRML Units
VRML uses meters as the standard unit of distance, and radians as the standard unit for angles. If you don't know how to convert from radians to degrees then use these formulas:

radians=(Pi/180)*degrees
degreed=radians / (Pi/180)
Pi=3.14159


Next Topic (Data Types)
Previous Topic (Introduction)
Back to the VRML Reference
Back to the Main Page

©Tom Thurston, 1997
Please feel free to use and redistribute this NONcommercially!