Welcome
About VRML
VRML Worlds
Mars Craters
Mars Valleys
Mars Mountains
Moon Topography
Internet Links
VRML Tutorial
E Cubed
Site Map
e-mail me

Sponsored Links
 

Inline files and objects

A VRML scene/world can contain many objects and the nodes that manipulate those objects. A large world may contain a lot of nodes and this could be confusing to the designer when trying to debug any problems. The Inline node allows a node or a node and it's manipulator nodes to be stored in a separate file and referenced to when the main world is viewed. This cuts down on the various nodes in the main file and allows the author to locate the main objects in the world. To figure out where a problem may be, the designer only has to comment (#) out the Inline node and the object will disapppear from the world, yet the code won't have to be rewritten. Comment out everything and then systematically remove the comment (#) from one node - if the scene doesn't work correctly, you can then open the file with the inlined object and search for errors.

While the Inline node assists the designer with troubleshooting, it adds another file to the overall world. Too many different world files can become hard to manage so keep that in mind. But the Inline node comes in handy when you have an object that will be reused throughout the VRML world.

Inline { url ["Box.wrl"] }

or

Transform 
{ children Inline { url ["failure.wrl"] }
} # end Transform node

The Transform node allow you to move the object just like any other shape. By placing the file to be inlined in the same directory as the main file, you can use relative addressing and exclude the whole url address. This way, if you move your world's location, everything should work without you having to edit the addresses.

Prototype an object

Instead of inlining an object, the VRML designer can turn the object into a prototype. The PROTO node allows the designer to convert an object into a node, with fields that allow the designer to manipulate the object. The prototype can be in the main file or in another file and referenced to just like the Inline node. The main difference between the PROTO and Inline options is that the Inline node doesn't allow the designer to change anything about the object. If you inline a helicopter that has it's blades rotating and the entire object moves in a wide circle, that's all it will do. You can place the Inline node as a child of a Transform node and manipulate the Transform node to change the direction or position of the whole copter and its circular route, but you can't redefine the route itself. The Transform node acts on the entire file.

If you turn that same helicopter into a PROTO node, you can change the route, the copter's angle, or even stop the blades from spinning. You would have to define fields that relate to the fields of the manipulating nodes located in the helicopter file. Let's turn our previous moving box into a prototype:

PROTO Moving Box 
[ exposedField SFTime speed 4 ]
{ # the nodes of the prototype follows
  DEF BlueBox Transform
  { rotation 0 1 0 .78
    children Shape 
             { appearance Appearance 
                         { material Material
                                   { diffuseColor 0 0 1 }
                         } # end Appearance node
               geometry Box {size 2 3 5 }
             } # end of Shape node
  } # end Transform BlueBox
  DEF BoxTime TimeSensor
  { cycleInterval IS speed
    loop TRUE
    stopTime -1
  } # end TimeSensor BoxTime
  DEF BoxMovement PositionInterpolator
  { key [ 0, .5, .6, 1]
    keyValue [0 0 0, 10 0 0, 10 0 0, 0 0 0]
  } # end PositionInterpolator BoxMovement
  ROUTE BoxTime.fraction TO BoxMovement.fraction
  ROUTE BoxMovement.value TO BlueBox.translation
} # end proto node implementation

The box is now a prototype. Note the cycleInterval field in the TimeSensor node. The IS keyword is used to connect the field to the PROTO nodes new userdefined field (speed). This is how you access the fields inside the PROTO node. The field types must match and if the PROTO node has eventIn fields, then they will have to match values in a Script node. To access and manipulate the box prototype, declare a new node of the type of the name that you called the PROTO node. Example:

DEF NewBox MovingBox { speed 10 }

This gives the name NewBox to the node of type MovingBox. By declaring the speed field 10, the box will move very slow. Make the speed 1 and the box will move very fast. Both the PROTO node and the NewBox node are in the same file. But you can put the PROTO node in another file and still reference it. Your main file will now look like this:

EXTERNPROTO MovingBox 
[exposedField SFTime speed] 
"MovingBox.wrl"
DEF NewBox MovingBox
{ speed 10 }

You now identify the node as EXTERNPROTO and just list the fields. Don't include the initial values for the fields. You then identify the file where there is a PROTO node. The name of the EXTERNPROTO doesn't have to match the name of the PROTO node in the external file. The browser will look up the file you identify and if the node it finds doesn't match field-by-field, it will send an error message. Prototypes are not that hard once you get the hang of it. This box is a very simple example - more advanced prototypes utilize the Script node to implement various coded functions.

Search
 
Google


 


|Welcome| |About VRML| |VRML Worlds| |Mars Craters| |Mars Valleys| |Mars Mountains| |Moon Topography| |Internet Links| |VRML Tutorial| |E Cubed| |Site Map|


Web Hosting Provided by midPhase.com