In The Beginning...

This time out, we're going to cover the basic node types in a VRML file, the WorldInfo node, and the Shape node.

WorldInfo

OK, now we can start to add information to the file. The first node to deal with is the WorldInfo node. This node contains general information about the world, such as a title for the world. This is displayed in the title bar of the browser window, the same as a TITLE tag in HTML. WorldInfo can also contain an info string, which contain other information about the file. You can put what you like in this, such as keywords for search engines, or whatever. A sample WorldInfo node is shown below:

WorldInfo {
	title "Floppy's VRML97 Tutorial Example 1"
	info ["(C) Copyright 1999 Vapour Technology"
 	        "vrmlguide@vapourtech.com"]
}

You can have multiple strings in the info field, by putting them all inside square brackets. A VRML file can have as many WorldInfo fields as you like, but only the first will be parsed. The rest will be ignored.

Basic Shapes

Now, this is all very nice, but not good at all at the moment, as there's nothing to see! Let's add a simple object to the scene. We'll add a Box object, with the default values, just so you can get the idea of how the structure works. There are a number of nodes required, such as appearance and so on, but just ignore those, they're for the next tutorial. Just remember, if you don't specify a value for a field, it will use the default. So, this will use the default values. We add a Shape node to the world now, as shown below.

Shape {
	appearance Appearance {
		material Material {
		}
	}
	geometry Box {
	}
}

This adds a Shape node, which contains two fields for describing an object. These are the appearance and geometry fields, which describe the look and shape of the object respectively. These will be covered in a later tutorial. For now, it is enough to have a Box with the default values and colours in our world.

Object Reuse

If you have a lot of identical objects, it's often awkward to keep writing in many objects of exactly the same type. Therefore, you can reuse previous definitions. Using our box, we could define it to have the name FBOX. Then, whenever we want to use that box again, we can just type USE FBOX instead of the complete definition. An example is shown below.

DEF FBOX Shape {
	appearance Appearance {
		material Material {
		}
	}
	geometry Box {
	}
}

USE FBOX

Another way to reuse VRML code is to use Inline nodes. These take the data from an external file and insert it into your file. So, if you had a model of a chair called chair.wrl you could insert it into your scene like so:

Inline {
	url "chair.wrl"
}

The file you are including in this way has to be valid VRML, so it must have the headers and everything that a normal VRML world has to have. If you can't load it legally into a browser, you can't inline it either.

End Bits

The complete code for the world as it stands so far is shown here.

You can see what this all looks like (not particularly impressive yet) by checking it out the way it's meant to be seen. You can use this to get used to moving around in your browser as well, and using the different types of movement.
Tutorial 1 World

That concludes the tutorial for the absolute basics, with a grey box in an otherwise empty world. Thrilling, isn't it. Never mind, we'll get onto more complex stuff later on. There's Point Sets, Backgrounds, Animation, Sensors, Lights, Cameras and everything. You'll see!


© Copyright 1999 Vapour Technology - vrmlguide@vapourtech.com

Back Top Next