#VRML V2.0 utf8
WorldInfo {
  title "Lightbulb - getting silly"
  info [ "Copyright 1999 by Bob Crispen " ]
}
NavigationInfo {
  type [ "EXAMINE" "ANY" ]
  headlight FALSE
}
Group {
  children [
    DEF Entry Viewpoint {
      description "Entry"
      position 0 0 1
    }
    DEF The_Box Transform {
      translation -0.2 -0.2 0
      rotation 0 1 0 0.78
      children [
	Shape {
	  appearance Appearance {
	    material Material {
	      diffuseColor 1 0 0
	      ambientIntensity 0
	    }
	  }
	  geometry Box { size 0.1 0.1 0.1 }
	}
      ]
    }
    DEF Lightbulb Transform {
      scale 0.35 0.35 0.35
      children [
        # Just enough light so you can see the lightbulb
	# Because this light is grouped with the lightbulb, you shouldn't
	# be able to see the box.
	DEF Dim_Bulb DirectionalLight {
	  direction 0 0 -1
	  intensity 0.3
	}
	Transform {
	  scale 0.193 0.193 0.193
	  children [
	    DEF Light1 PointLight {
	      intensity 1
	      on FALSE
	    }
	    Shape {
	      appearance Appearance {
		material DEF Lightbulb_Color Material {
		  diffuseColor 1 1 1
		  specularColor 1 1 1
		}
	      }
	      geometry Sphere {
		radius 1.4
	      }
	    }
	  ]
	}
	Transform {
	  translation 0 -0.35 0
	  children [
	    Shape {
	      appearance Appearance {
		material DEF Base_Color Material {
		  diffuseColor 1 1 0
		  specularColor 1 1 0
		}
	      }
	      geometry Cylinder {
		height 0.3
		radius 0.135
	      }
	    }
	  ]
	}
	DEF Sensor1 TouchSensor { }
      ]
    }

    DEF Illuminator Script {
      eventIn SFBool touched
      eventIn SFBool mouseover
      field SFBool lit FALSE
      eventOut SFBool light_changed
      eventOut SFColor lightbulb_emissive_color
      eventOut SFColor base_emissive_color
      url [ "javascript:
	function touched(value) {
	  if (value) {
	    if (lit) {
	      lit = false;
	      light_changed = false;
	      lightbulb_emissive_color = new SFColor(0,0,0);
	      base_emissive_color = new SFColor(0,0,0);
	    } else {
	      lit = true;
	      light_changed = true;
	      lightbulb_emissive_color = new SFColor(1,1,1);
	      base_emissive_color = new SFColor(.4,.4,0);
	    }
	  }
	}
	function mouseover(value) {
	  if (value)
	    Browser.setDescription('Click me to turn the light '+
		(lit ? 'off' : 'on'));
	  else
	    Browser.setDescription('');
	}
    " ]
    } 
  ]
  ROUTE Sensor1.isActive TO Illuminator.touched
  ROUTE Sensor1.isOver TO Illuminator.mouseover
  ROUTE Illuminator.light_changed TO Light1.set_on
  ROUTE Illuminator.lightbulb_emissive_color TO Lightbulb_Color.set_emissiveColor
  ROUTE Illuminator.base_emissive_color TO Base_Color.set_emissiveColor
}