VRML Libraries

In VRML, it is very easy to integrate someone else's objects into your world. Using the Inline node, you can specify a URL to another object located anywhere on the Internet. The following node will add a vase to your world:

Group { children [ Inline { url "http://www.vrml_lib.org/vase.wrl" } ] }

The above code simply retrieves the vase.wrl from the server and draws the object in your world. Of course, you can rotate and tranlate the object as you desire. The limitation of using the Inline node is that you can not interact with the object. For instance, you may want to change the color of the vase. The only way to do this using the Inline node would be to download the vase.wrl file and change the color attributes of the vase.

Fortunately, VRML provides a crude but serviceable way to interact with external objects and worlds. This entails use of PROTO and the EXTERNPROTO definitions. Basically, the PROTO statement defines variables that can be used to interface with the object. For instance, in my demo world, I used a PROTO statement to interact with my skylight object. The following code demonstrates use of the PROTO statement:

PROTO skylight [ EventIn SFBool set_transparency ] Group { ... }

In the above code, the PROTO statements defines an EventIn that can be referenced externally. In my demo world, I send an eventIn message to all the skylight objects instructing them to either make the skylight transparent or visible. However, in order for VRML to know that the PROTO statement exists, you must also define an EXTERPROTO section in the calling object. In my world, the calling object is the roof object. The roof.wrl file has a EXTERNPROTO section that defines the EventIn set_transparency and makes it accessible to send messages to. The following code snippet demonstrates an EXTERPROTO definition:
EXTERNPROTO skylight [ eventIn SFBool set_transparency ] "skylight.wrl#skylight"
This code specifies that the SFBool eventIn is an external variable than can be manipulated. Note that "skylight.wrl#skylight" tells VRML to find the set_transparency definition iin the skylight.wrl file inside the skylight PROTO statement.

Using EXTERNPROTO and PROTO is clumsy compared to using #include statements in C or C++. However, as VRML worlds become more and more popular, it will become very important to be able to interact with objects created by a third party.