[scripting] , <<VRML 2.0 - An Introductory view by examples

Script

[TouchCube-html] [Balls-html]               [run-TouchCube] [run-Balls]

Script nodes bring decision logic and state management into VRML. A Script node is activated when it receives an event. At that point the browser executes the program defined in the Script node's URL field (passing the program to an external interpreter if necessary).

The syntax of a script node in a .wrl program is :

Script programs can be written in any language (e.g. Java, JavaScript). The mime-type of the returned data defines the language type. In this tutorial the script example programs are java programs which have the following general structure : (they have to be compiled generating a .class)

// Example of a Java program to implement a Script Node 
// (this example generates name.class

   import vrml.*         // system libraries
   import vrml.field.* 
   import vrml.node.* 

   public class name extends Script{ // declares a public script

     private Nodes declarations // parameters to be used in the function

     public void initialize( ) { 
     initialization commands       // executed once
                                   }
     public void processEvent (Event e) {  // actual script procedure 
              ...............................
                                              }
                                        } // end of Java routine