Box

In this exercise, we are going to create a Box. It is a simple geometric object and one of the fundamental parts of a Virtual World.

The size of the box will be determined by the X/Y/Z dimensions you enter into the script, whose centerpoint is at 0/0/0 (X/Y/Z). As an example, if the dimension on the X axis is 2.0, then one half of the 2.0 (or 1.0) will be on the right side(+) of zero and the other half (1.0) will be on the left side(-) of zero. The value of each dimension must be a decimal. The VRML viewer does the calculation of the box automatically.

Presently, the color of the box is set at a shade of green. If you wish to change the color, you will need to change the values of red, green and blue on line 5, "diffuseColor 0.0 1.0 0.0". Go back to the Discussion section and click on RGB Color, which will give additional information about color and a color chart.

Here is the code for the creation of a box:

#VRML V2.0 utf8
Shape {
appearance Appearance {
material Material {
diffuseColor 0.0 1.0 0.0
}
}
geometry Box {
size 1.0 3.0 5.0
}
}

box.wrl

Here is something for you to play with. First, download and install Cosmo Player, or Cortona 3D and it might be best if you start a new folder on your drive and keep all of your VRML stuff in it. Second, download the code file "box.wrl" by right clicking on the link and "Save Target as". In line 9 of the code you will see (size 1.0 3.0 5.0), which determines the size of the box. It might be best if you leave these numbers alone initially to see what the box looks like on the viewer. If you want to change the size, put in a new number and save the file.

To open this file, go to your VRML folder and double click, or open the box.wrl file. This will open a browser window (off line), the Cosmo Player, Cortona 3D screen will appear, as will the box. Now you can make the box do anything you want. Click on the "Examine" button to spin the box in virtually any direction, or speed. This can take a little practice. You'll see what I mean. For more info, go to Discussion and click on "VRML Viewer" and check out the section on controls.

Special Notes:

1. When the VRML viewer creates an object, it only shows the surface. The object is not solid.

2. VRML, like other programing languages, is very unforgiving. The format, shown above, will prove to be very useful as you progress into more complex scripts. Particularly when you are trying to find an error. If you are missing a component, such as a bracket, or a misspelling, the script will not run.

Have fun!!

SL Button 125

Contact Blog Privacy