Advanced javascript in VRML

Introduction

This tutorial page assumes a basic understanding of vrmlscript in particular Browser functions.

Status bar text

This example uses a Script node with Browser.setDescription to display text in the browser status bar when the mouse is over an object. Usefull for providing basic instructions or applying names to objects.

DEF Object Transform {
 translation 0 0.5 0
 children [
  DEF Sensor TouchSensor {}
  Shape{
   appearance Appearance {
    material Material {
     diffuseColor 1 0 0
     specularColor .5 .5 .5
     ambientIntensity 0
     emissiveColor .15 .15 .15
    }
   }
   geometry Sphere {
    radius 0.5
   }
  }
 ]
}
DEF TouchScript Script {
 eventIn SFBool isActive
 eventIn SFBool isOver
 eventOut SFTime startTime
 url "javascript:
  function isActive (val,ts) {
   if (val) {
    // start Timer
    startTime=ts;
   }
  }
  function isOver (val,ts) {
   if (val) {
    // text to display when mouse is over Object
    Browser.setDescription('mouse over object');
   }
  }
 "
}
# route status of pointer and timer to Script
ROUTE Sensor.isOver TO TouchScript.isOver
ROUTE Sensor.isActive TO TouchScript.isActive

# animation routes
# un comment the line below to route an event to an animation timer
# ROUTE TouchScript.startTime TO Timer.startTime

Examples

The above example in completed form Status bar text

Notes

The startTime event is included in the script node to provide a basis for additional modifications.