| Authoring VRML 1.0 (Part 1 of 4)
|
| by Len Bullard
|
|
In this series, we will work through the steps for building a
VRML 1.0 world. VRML 1.0 has now been superceded by VRML 2.0, and I
encourage you to begin work with 2.0. However, there are reasons
one could still need to create 1.0 worlds.
- Simpler: It is easier to build 1.0 worlds, although, not much.
- Tools: You bought a 1.0 editor. Good. Now you want to get your
money's worth out of it. Smart. There are conversion tools, and since
2.0 editors have not yet begun to appear in any numbers, this is how you
are likely to work for awhile to build 2.0.
- Lack of Tools: You need to edit the ASCII files manually.
- Browser: The Netscape plugin for VRML is Live3D. It is an
excellent 1.0 browser, but it does not yet support VRML 2.0. VRML 2.0 browsers are
betas at this time. The 2.0 browsers work well, but it is understood if you don't want
to be a penguin testing the waters for walruses.
- Customer: You have a customer that prefers VRML 1.0. Whatever...
|
|
|
This first article will step you through the basics of creating a VRML 1.0
world. I'll emphasize the use of the VRML 1.0 geometric primitives. Why?
In most cases, they are not only efficient but also easy to apply. Further, creating objects
with primitives teaches a Modeler (that's you!) to decompose a complex
object into simple shapes, a crucial skill in world building.
|
|
|
Using VRML Editors and Browsers
VRML 1.0 makes it easy to create compact 3D graphics in a human-readable
form. VRML can be authored with a VRML browser and
an ASCII text editor. I will step you through this as if you were using
a text editor, and thusly teach you VRML syntax and proper structure.
I discuss editors later in the series.
I encourage you to download beta/demo editors, test them, then purchase
the ones you like. There are also some suggestions for those who aren't
ready to invest in a VRML editor at this time.
|
|
|
An editor that has a VRML rendering capability supports visualization
for interactive design. Think of this as a browser window (usually four),
built into the editor that lets you see the object and interactively
change its shape, color, scale, position, etc. In my experience, this
is the easiest way to model. The text equivalent is a WYSIWYG editor.
|
|
|
There is one drawback to visualization techniques. This is discussed
in more detail later, but in short, it is state accumulation. In VRML,
operations such as transforms, rotations and scaling which alter the
position, angle or shape of an object can compound or "accumulate".
In the excitement of interactive thrall, you may not notice. I'll show
you how to prevent this.
|
What is Browser Hell?
|
Although they all use the VRML language, browsers produce more varied
results than we in the VRML community like, particularly with respect to
rendering (getting the same look). It is fair to say that
getting a VRML world to look and perform the same in all of the browsers
is substantial effort (a.k.a. Browser Hell). This situation improves
slightly in VRML 2.0, but it may be some time before perfect VRML
interoperability is achieved. It is more efficient if the editor you use and the browser you target
for your work have similar rendering; so, test these together.
|
|
|
Building Worlds
Each of us has different techniques for building worlds.
Since part of my background is in theatre, I conceptualize VRML
as a stage set or TheatreInABox. I typically organize the building
process in in eight major stages:
- Plan the Scene
- Make Objects
- Lay Out the Scene
- Insert Cameras.
- Light the Scene
- Apply Extensions
- Test the World
- Publish the World
|
|
|
We will examine these stages separately. VRML 2.0 has extra stages
such as animating, but we won't discuss this except to teach you
how to ensure that your 1.0 objects can be converted into animatible 2.0
objects.
Often, it is good just to improvise, or "noodle"
|
Often, it is good just to improvise, or "noodle"
|
Planning the Scene
How much planning you need or should do varies. Often,
it is good just to improvise, or "noodle" as some artists
call the practice of sitting down with the tools to play
with no preconceived goals. I recommend this. However,
at other times, one is building for a reason: a customer, err..
a gig.
|
|
|
Planning can be as simple as setting constraints like
maximum size of the target scene or as
complex as determining colors schemes, styles of objects,
limits on object complexity, insides or outsides, use
of extensions, etc. Particularly when working with teams,
it is prudent to document your goals, assumptions, etc., and
answer questions such as:
- What do I want to build - how big is it, what color, what environment?
- What sources do I have - pictures, textures, real world models, blueprints, imagination?
- What media do I want to incorporate - sounds (midi or wav), gif animation, mpegs?
- What are the performance requirements - what computer platform, World
Wide Web, modem speeds, available RAM?
- Do I plan to evolve the piece - is this an object for a larger scene,
a scene for a series of scenes, do I care right now?
|
|
|
The publicity articles for the Disney/Pixar animated feature "Toy Story"
state that it took four years to make that movie. Two of those
years were spent planning and prototyping. VRML isn't up to
the production value of a Disney feature. Nonetheless, some
planning will help. You may want to use your VRML
1.0 objects in VRML 2.0 worlds, you may be working with a large
and geographically dispersed team, you may have a customer
with firm requirements, or you may just be the anal type that
keeps lots of lists.
|
|
|
Let's look at animation, for instance. VRML 1.0 extensions supported
by some 1.0 browsers for spin or orbital motion have been used in
many online worlds. Using these without knowing how the orbits
of objects would intersect or what their relationships was to local and
world coordinate systems is difficult. In this case, a world builder will probably
need to do some rewriting.
|
|
|
In VRML 2.0, animation features enable you to create characters
and animate them to perform a scene or interact with the user.
That is beyond the scope of this article, but keep it in mind.
Conceptualizing a scene in 1.0 with motion in mind for 2.0 is an
important skill to learn. You must plan for animation if indeed you are
going to animate. Good techniques, particularly paying attention
to how objects are grouped using a VRML node called a "separator",
pay off.
Planning has a sibling called testing
|
Planning has a sibling called testing
|
Here's another example; planning has a sibling called testing.
They share a parent called requirements. If for example, your
customer delivers a set of firm and well-written requirements for your work,
you should use those requirements to plan tests or demonstrations for
the customer that prove you have met the requirements. Make a table
that not only cites 1)each requirement by paragraph number, 2) the plan
for meeting the requirement and 3) the test that proves you met the requirement,
but also has the initial of the customer when you prove this. If you ever have
to bid on contract work, showing that this Plan/Test cycle is part of
your work processes can be a valuable discriminator for winning the contract.
|
|
|
Nodes are the VRML building blocks organized in a tree
Making Objects
Now for the nitty-gritty; let's start building. VRML 1.0 is a node
language as is HTML. This is a tree of objects. It is also a declarative
language. That means you create nodes that have the information that
describes or declares an object. The operations that implement the
objects are left to the browser. Just remember, nodes are the
VRML building blocks organized in a tree. Nodes are used to:
- Create geometry
- Color objects and apply textures
- Change the properties of objects such as shape and size
- Position the objects
- Light the objects
- Position cameras for different viewpoints
- Add non-conforming VRML 1.0 behaviors
- Create Hyperlinks
|
Cube
|
Creating Geometry
Here is a VRML instance with a cube node.
#VRML V1.0 ascii
Separator {
DEF Floor Cube {
width 20
height 1
depth 20
}
}
|
|
|
The first line contains the VRML declaration.
#VRML V1.0 ascii
The # flag indicates a comment in a VRML instance and must begin
each line of a comment. The declaration comment must be in every
VRML 1.0 file exactly as shown. It indicates the version of the
VRML file, version 1.0, and the character set, which is ASCII.
|
|
|
The next line declares a Separator
Separator {
.... nodes
}
A Separator has two curly brackets that declare a scope.
A Separator keeps the content inside encapsulated. In more practical terms, a
Separator groups the nodes inside it. We will look more at this later
because effective use of Seperators is key to organizing shapes and shape
properties inside objects and objects inside scenes.
For now, think of the Seperator as a container around the content so
that what is inside is related, and what is outside affects
its contents as a unit.
|
|
|
The next set of statements declare a cube and name it, Floor.
DEF Floor Cube {
width 20
height 1
depth 20
}
Notice the first line. Read "Define or name (DEF) Floor Of Type Cube".
The practice of DEF naming is important because I will show
you how to reuse these nodes by referring to this name. For
now, just keep to the practice of only using a name once in a file,
or in other words, use unique names. While a VRML 1.0 browser will
let you slide on this, if you don't keep DEFs
unique and try to reuse the node by reference, you may not get the
results you want. It's acceptable to enumerate names, e.g, Floor01,
Floor02, etc.
|
|
|
Within the paired curly brackets are the shape values of the Floor.
A cube has shape characteristics of width, height and depth. The
characteristics are given the values width=20, height=1, and depth=20.
Notice that no equal sign is included as it is not needed. Get into the
habit of thinking of the spatial values as metric. A width of 20 equals
20 meters wide. A height of one equals one meter high, and so on.
|
|
|
Coloring Nodes and Adding Textures
If you copy the example into a text file and open that file in a
VRML 1.0 browser, you will see a flat cube. It isn't much to look
at yet, but on this flat cube, we can build. Still, it is boring
looking, so let's give it a color. Right above the Floor node, add
the following Material node. It must be inside the Separator open
bracket.
DEF Gray_Plastic Material {
ambientColor 0.2 0.2 0.2
diffuseColor 0.8 0.8 0.8
specularColor 1 1 1
shininess 0.2
}
|
|
|
Just like the cube, the DEF names the Material node, Gray_Plastic.
The Material node has different characteristics that define the color
and light properties. Because they are inside the Separator, they
affect the Floor cube. In the sense of a VRML tree, they are on the
same branch.
|
Grey Cube
|
There are more material characteristics available to the
modeler than are shown in the example. For a node by node description
of the available characteristics, see the VRML 1.0 specification. Your
example should look like the following:
#VRML V1.0 ascii
Separator {
DEF Gray_Plastic Material {
ambientColor 0.2 0.2 0.2
diffuseColor 0.8 0.8 0.8
specularColor 1 1 1
shininess 0.2
}
DEF Floor Cube {
width 20
height 1
depth 20
}
}
|
|
Grass Cube
|
You may not want a gray cube. You may want a cube with the
surface of a lawn on it. No problem. In VRML this is done using
a texture. Here is an example of a Texture node on the cube:
#VRML V1.0 ascii
Separator {
Texture2 {
filename "grass.jpg"
}
DEF Floor Cube {
width 20
height 1
depth 20
}
}
|
Understanding How Textures Work
|
This node uses the grass.jpg graphic as a texture and applies it to
all of the cube surfaces. That is pretty easy. Texturing simple
objects is a simple task. Texturing irregular objects or having a
different texture for each side of the cube is a bit more complex.
This subject requires a complete tutorial on its own. A fine VRML
artist named Cindy Reed-Ballreich wrote one for VRMLSite.
|
|
|
Different browsers support different file formats for textures. The
two common ones that you can count on are .gif and .jpg. A rule of thumb
is to use .gif for black and white images and .jpg for color. These
are compressed formats and give you the best performance. Some browsers
support .bmp as well. Try to avoid these as they are uncompressed,
increase the file size, and slow the load cycle down considerably. One
use for a texture editor is to convert graphics formats to .gif or .jpg.
Be aware that textures slow down a world more than almost any other
feature in VRML. Why?
- Each texture is downloaded separately as a file. That means the browser
client has to reconnect to the server for each file.
- Each texture has to be rendered and sometimes sized to
fit the area of the surface it covers.
|
|
The best rule of thumb is to use color nodes as much as
possible. Mixing colors is a real art, but good editors come
with libraries of color nodes you can apply. Use textures sparingly, and
reuse them in the scene if possible. A smart browser will only
load the texture once, then reuse it as it needs it. Some browser
rendering engines will reduce the size of the texture to a 128 x 128
pixel map. To speed things up, do that yourself using a graphics
editor such as Corel Draw or PhotoShop. In fact, when considering
tools for your set, do buy a good 2D paint package for working
with textures. There is one exception to this sizing issue. This is
a VRML extension called BackgroundInfo which is discussed later.
Check out my HomeGround Towers world for an example of texturing
pushed over the edge. I have reused textures, sized them, etc. and
the world still takes between fifteen and twenty minutes to load on
a good day. Most of that time, the browser is texturing.
|
|
|
Believe it or not, you are past the hardest part of building
VRML worlds in VRML 1.0. It is simply a matter of arranging
geometric objects, giving values for the characteristics, and
including other nodes that affect the geometry. That's it.
You are now a Modeler... kiss on both cheeks.
|
|
Len Bullard is a systems analyst
and a married father of two children.
He splits his consciousness between his job as a hypermedia consultant
and his rock band of ten years, Ground Level Sound. His interests
in VRML spawned from a conviction that this was the technology that
would rejoin his divorced psyches and help him fight a lifelong
addiction to endorphins. He spends his copious spare time recording
original music with his band at their studio, Blind Dillo, performing
in the southeast region with GLS, beta testing and answering email.
|