VRMLSite

Subscribe for FREE

Discussion Area

VRML 2.0 URLs
VRML by the Pound

Tell a Friend
We'll Link to You!!

Aereal, Inc.
   Instant VRML
   Proteinman's Top 10

BackContentsNext
view me!



The Atomic Proto
by Pioneer Joel

Deep in the crease of the Net, low-down, dirty modem speeds still squeeze precious life-times from innocent cruisers. Megabyte monsters lurk behind every graphically intense corner, waiting to slit poor 28.8 throats. Can nothing be done?

Contrary to popular belief, VRML does not have to aid and abet the bandwidth criminals so often encountered on the Web. Carefully crafted, shrewdly coded, well planned .wrl's are a refuge from the bloated polygons of conventional 3D weaponrey, and a stunning demonstration of VRML's atomic capabilities.

Along with DEF/USE and Primitives, VRML allows for the implimentation of Proto's. Proto's are a lot like a fast food Combo Meal. When you order a Combo Meal, you know that you are going to get a sandwich, fries, and a medium drink. That is the Proto: sandwich, fries, drink. What you don't know is, what kind of sandwich, or what kind of drink. When you use the "Combo Meal Proto," you have to tell the guy that you want a Diet~Coketm as the "value for the drink field," or a chicken sandwich as the "value for the sandwich field." Combo Meals exists, because the same meal (with a different beverage) is ordered all the time. What we need to do, is take some "common orders" of VRML, and convert them into PROTO's.

By far, the most commonly occuring node in VRML2.0 is a Transform node with a Shape child. Take a look at The Atomic PROTO quickly now.

#VRML Draft #2 V2.0 utf8

#pioneer.joel@digitalage.com

PROTO X [
 eventIn SFVec3f set_T
 eventIn SFRotation set_R
 eventIn SFColor set_C
 exposedField SFVec3f T 0 0 0
 exposedField SFRotation R 0 0 0 0
 exposedField SFRotation O 0 0 0 0
 exposedField SFVec3f S 1 1 1
 exposedField SFColor C .8 .4 0
 exposedField SFNode G NULL
]
{
 Transform {
  translation IS T
  rotation IS R
  scale IS S
  scaleOrientation IS O
  children[
   Shape{
    appearance Appearance{
     material Material{
      diffuseColor IS C
      emissiveColor 0 0 0
      specularColor 1 1 1
     }
    }
    geometry IS G
   }
  ]
 }
}

That may seem like a lot. Don't worry, it's only 556bytes, we can get through it. PROTO's have three parts:

  • the name
  • the hard bracket[] part
  • the curly bracket{} part

In The Atomic PROTO, the name is

PROTO X

No big deal, and we're two thirds of the way done! The name of the PROTO is what you use when you want to create an instance of the PROTO. To create an instance of The Atomic PROTO, simply type:

X{}

That's it. Of course, nothing will happen, but keep reading.

Now, don't get confused. We are going to skip ahead to the curly bracket part (it'll make things easier to understand). Take a look at that part now:

{
 Transform {
  translation IS T
  rotation IS R
  scale IS S
  scaleOrientation IS O
  children[
   Shape{
    appearance Appearance{
     material Material{
      diffuseColor IS C
      emissiveColor 0 0 0
      specularColor 1 1 1
     }
    }
    geometry IS G
   }
  ]
 }
}

This pretty much looks like the VRML2.0 you've seen before, except for the "IS" statements. Reading through this code, we see that we have defined a Transform{}. Transform's have several fields, one of which is translation. In our PROTO, instead of entering a numerical value for the xyz translation, we have told that browser to use "T" as the value. When ever we use this PROTO, we will enter a value for "T" instead of translation. PROTO's are similar to inventing your own VRML node. We also determine default values when defining the PROTO. Re-examine the hard bracket part:

[
 eventIn SFVec3f set_T
 eventIn SFRotation set_R
 eventIn SFColor set_C
 exposedField SFVec3f T 0 0 0
 exposedField SFRotation R 0 0 0 0
 exposedField SFRotation O 0 0 0 0
 exposedField SFVec3f S 1 1 1
 exposedField SFColor C .8 .4 0
 exposedField SFNode G NULL
]
This code tells the browser what parameters may be set when the PROTO is used. Also, the numbers after each capital letter variable name defines the default value for that field. For instance, if you chose not to enter a value for the rotation field, the default value will be no rotation at all, as shown:

exposedField SFRotation R 0 0 0 0

So, if you don't tell me what kind of drink you want, you're just going to get Iced Tea.

The three eventIn's:

eventIn SFVec3f set_T
eventIn SFRotation set_R
eventIn SFColor set_C

are values that can be dynamically set (just like you would ROUTE an Interpolation to any Transform node). And again, the exposedFields:

exposedField SFVec3f T 0 0 0
exposedField SFRotation R 0 0 0 0
exposedField SFRotation O 0 0 0 0
exposedField SFVec3f S 1 1 1
exposedField SFColor C .8 .4 0
exposedField SFNode G NULL

are the variables that may be set with each instance of the PROTO. Also, the default values are set here, incase no value is mentioned when the PROTO is used somewhere else in the code.

O.k., so, how do you use the PROTO once you've defined it?

Good question. When we tell the browser to use the X PROTO, we need also to indicate values for the variable fields, unless we want the default values. Here is an example of an instance of the X PROTO:

DEF Floor X{
 T 0 -1 0
 S 10 .1 10
 C .3 .2 .2
 G Box{}
}

It tells the browser to create an instance of the X PROTO, which it defines as Floor. Then, translate the node 0 -1 0 (T 0 -1 0), scale it (S 10 .1 10) and make whatever geometry we are going to pick slithtly redish (C .3 .2 .2). Finally, a Box{} is drawn (G Box{}). Since we didn't use "R" the default rotation is 0 0 0 0, and the Box{} isn't rotated. That code was taken from an actual .wrl, which you should really see if you fully want to understand the VRML2.0 PROTO. Another instance of The Atomic PROTO might look like this:

   DEF Face X{
     T -.19 2.2 0
     R 1 0 0 3.14
     S .4 .2 .25
     O .5 1 0 3.14
     C .8 .4 .35
     G Cone{ height 2.5}
    }

This instance creates a Cone (obviously) which is
Translated a little bit,
Rotated pi radians around the x-axis,
Scaled into shape along an
Orientation, and finally
Colored sort of pinkish.
This node has also been has been DEF'ed as Face so that Interpolators may be ROUTED to it. When you ROUTE to a PROTO, the syntax is the same at to a non-PROTO node, but use the names that you have defined in the PROTO. For instance, to ROUTE to the value for the rotation field of PROTO X, use set_R (as was defined in the PROTO):

DEF Spin1 OrientationInterpolator{
 key [0, .5, 1]
 keyValue[0 1 0 0, 0 1 0 3.14, 0 1 0 6.28]
}
DEF Death X{
 T 2 -3 .34
 R 0 1 0 1.57
 C .5 .01 .01
 G Box{}
}
ROUTE Spin1.fraction_changed TO Death.set_R

As you can see, PROTO X allows you can create, animate, and fully manipulate any primitive (or even coords, if you must) with minimal file size. A single instance of X, can be as small as 40 characters!!! With the line:

exposedField SFColor C .8 .4 0

We have reset the default color! If no diffuseColor is given, the object will default to yellow, instead of white. This shaves off excess K that would have been used applying the same color to many objects. The default value for the geometry field is NULL but it could just have easily been Box{}:

exposedField SFNode G Box{}

That way, if your .wrl had a great number of yellow boxes, you could drop even more extraneous characters.

And here is some wonderful exit statment about how powerful this PROTO is, and blah blah blah, and it ends with an atomic blast...


Pioneer Joel
Back Contents Next
Have you tried out our new Discussion Area yet?

LinkExchange
LinkExchange Member

Need sponsorship or advertiser information? E-mail adrian@aereal.com.

Have an idea for an article? Thought of a way we can improve VRMLSite? E-mail suggest@vrmlsite.com.

Please Tell a Friend about VRMLSite!

© 1997 Aereal, Inc. All rights reserved. VRMLSite is a trademark of Aereal Inc.