VRML Basics

 

VRML Lesson 2

The Virtual Reality Markup Language (VRML) is similar to HTML in that it uses a set of tags to describe a 3D space in the same way that HTML uses a set of tags to describe a 2D space (a page). Is it hard to do? Not really. Do you need special tools? Not really. Really? Yes, really. For instance, open up notepad and type in this simple code, save the file as vrml1.wrl (the .wrl file type is the important part).

#VRML V2.0 utf8
Box { size 2 2 2 }

There we go, if you double click on the file you just saved, your browser should open up and you should see a box that is two meters by two meters, by two meters. Yes, you may say, but what about more complicated shapes. Well, you are lucky. Several have been predefined for you. Try this two line example...

#VRML V2.0 utf8
Sphere {  radius 1 }

Wow, you've just made a ball!

OK, now let's get real fancy....

#VRML V2.0 utf8
Cone {
    bottomRadius 1    
    height 2
    side TRUE
    bottom TRUE
}

A cone you say! Nothing could be easier.

What about something complicated, well let's try a cylinder.

#VRML V2.0 utf8
Cylinder {
    height 2
    radius 1
    side TRUE
    top TRUE
    bottom TRUE
}

Is it that easy? Well, "it is easy if you know how"™ I always say! You might notice some things in these examples. They all seem to start with the same header line (  #VRML V2.0 utf8  ), this line tells the browser that you are using VRML version 2 (also known as VRML97). There is nothing else on that line. The # sign means what follows in line 1 is a header, everywhere else it stands for a comment character.

You may also notice that there is what we call a geometry "node" followed by curly brackets with parameters inside of them which describe or modify the geometry of the object.

As the examples get more complex, pay close attention to the nesting of the braces and brackets. For every opening bracket "[" there is a closing bracket "]" for every opening brace "{" there is a closing brace "}". Sounds simple, but when I have problems, that's usually where it is.

You may ask "Radius 1, one what?". The answer my friends is Meters. Since VRML97 is an International Standard it is all in the metric system. We Americans have a harder time with this than our European friends, but once you start working in metric, you will see that it is much easier to use. Like how many inches are in 3 yards (108in.) is a tougher question to answer than how many centimeters are in 3 meters (300cm).

So, keep this in mind when making VRML objects. I am 1.76 meters (or 5.8 Feet) tall, so that is a good size for my avatars. If I recall the conversion correctly, one inch = 2.54 cm, one foot=30.48cm or 0.3048m or you can rely on a handy converter tool like this one. A room in my house has an interior height of 8 Feet (or 2.43840 Meters), dang near 2 and a half meters.

Ok, for extra credit and a fun afternoon, try varying the parameters in these examples. You can make slabs out of boxes and tall skinny cylinders, or short squat cones. Now we are having fun.

Oh yea, do you know how to cut and paste? It might be quicker than typing in the next example. Highlight the text below and hit <Ctrl>c to cut the text into the computers cut & paste buffer, then open up the notepad program and hit <Ctrl>v to paste the text from the buffer into notepad. If you've never done this before, you'll think it is magic. If you are lazy like I am, it will become your best friend.

Well, how can I combine these objects into one scene? You will have to learn about the properties of a Group node that we call the Transform node. It is used to transform whatever is inside of it, in this case we will use the Translation parameter. Looks like this...

#VRML V2.0 utf8
Transform {
    translation -2 0 0
    children
    [
        Box { size 1 1 1 }
    ]
}
Transform {
    translation 0 0 0
    children
    [
    Sphere { radius 0.5 }
    ]
}
Transform {
    translation 2 0 0
    children
    [
        Cone {
            bottomRadius 0.5
            height 1
            side TRUE
            bottom TRUE
        }
    ]
}

Did I scare you off with that one? I hope not. We can still see our friends the Box, the Sphere, and the Cone, but they are wrapped in some additional code. If we view the example we will see that the Box is Translated or moved 2 meters to the left, the Sphere is centered in the window, and the Cone is translated 2 meters to the right. In VRML the coordinate system is labeled XYZ with X being to the left and right, Y being up and down, and Z being toward or away from you. See, I told you it was simple.

For extra credit, try to stack the cone on the cube, and put the ball on top of them all. HINT: X and Z will be zero, just vary the Y value. Now you have all the knowledge that I had when I built my first VRML thing (click here for a plain text copy). You will see that it is just a bunch of slabs and cylinders translated around in an orderly fashion. You are probably thinking, "Gosh, he ain't so cool after all". Don't worry about my self esteem, I can take it.

Do you care to go on to Lesson2?

Home ] Up ]