#VRML V2.0 utf8								
# Library for VRML menuing tools - a component of a 3D plotting application 
#   Background switching 
#   Anchor OnClick Control button  
#   OnClick script control buttons 
#   Text labels 

# Kurt A. Fisher fisherka@csolutions.net  beginner level VRML coder 
# 1/2004

# =========================================================================
# PROTOTYPES 

# =========================================================================
# Component for background switching 

PROTO Background_Switcher_Script [ 
	exposedField	SFInt32		ctrlChoiceActionBG	0		#  sets which control choice will be sent onlclick 	
	eventIn		SFBool		set_booleanBG 			#  switch trigger 
] # end PROTO Fields
# Begin PROTO OBJECT
{

DEF WORLD_BACKGROUND Group { 

	children [ 

#  version 0: White universe 
DEF WhiteBack Background {
	skyColor 		[ 1.0 1.0 1.0,  1.0 1.0 1.0,  1.0 1.0 1.0 ]
	skyAngle 		[ 1.0, 1.0 ]
	groundColor 		[ 1.0 1.0 1.0,  1.0 1.0 1.0,  1.0 1.0 1.0 ]
	groundAngle 		[ 1.0, 1.0 ]
} # End of Initial background

#  version 1: Gray universe 
DEF GrayBack Background {
	skyColor 		[ 0.9 0.9 0.9,  0.9 0.9 0.9,  0.9 0.9 0.9 ]
	skyAngle 		[ 1.0, 1.0 ]
	groundColor 		[ 0.9 0.9 0.9,  0.9 0.9 0.9,  0.9 0.9 0.9 ]
	groundAngle 		[ 1.0, 1.0 ]
} # End of Initial background

# version 2: Black universe 
DEF BlackBack Background {
	skyColor 		[ 0.0 0.0 0.0,  0.0 0.0 0.0,  0.0 0.0 0.0 ]
	skyAngle 		[ 1.0, 1.0 ]
	groundColor 		[ 0.0 0.0 0.0,  0.0 0.0 0.0,  0.0 0.0 0.0 ]
	groundAngle 		[ 1.0, 1.0 ]
} # End of Initial background


#  version 3: Red universe 
DEF RedBack Background {
	skyColor 		[ 0.6 0.0 0.0, 0.6 0.0 0.0,  0.6 0.0 0.0 ]   #  Dark red.  Pure red is 1.0 
	skyAngle 		[ 1.0, 1.0 ]
	groundColor 		[ 0.6 0.0 0.0, 0.6 0.0 0.0,  0.6 0.0 0.0 ]
	groundAngle 		[ 1.0, 1.0 ]
} # End of Initial background


	] # end children WORLD_BACKGROUND 
} # end Group WORLD_BACKGROUND 

# PASS DATA FROM EXPOSED FIELDS IN PROTOTYPE TO OBJECT INSTANCE 
DEF tmp_ctrlChoiceAction Switch { whichChoice IS ctrlChoiceActionBG }			# Pass SFInt32 to script 

DEF Background_Switcher Script {
 field SFNode bgBack0 USE WhiteBack
 field SFNode bgBack1 USE GrayBack
 field SFNode bgBack2 USE BlackBack
 field SFNode bgBack3 USE RedBack
 field SFNode ChoiceAction USE tmp_ctrlChoiceAction
eventIn SFBool set_boolean IS set_booleanBG
 directOutput TRUE
 url [  "javascript:
	 function set_boolean( ){
// 		Control_choice = 2
		if ( ChoiceAction.whichChoice == 0 ) { bgBack0.set_bind = true ; }
		if ( ChoiceAction.whichChoice == 1 ) { bgBack1.set_bind = true ; }
		if ( ChoiceAction.whichChoice == 2 ) { bgBack2.set_bind = true ; }
		if ( ChoiceAction.whichChoice == 3 ) { bgBack3.set_bind = true ; }
	}" 
	]  
} # End Control_Filter Script 

 } # end PROTO Background_Switcher  

# =========================================================================
# Prototype for anchor control button item 
# BUTTON SHAPE 
PROTO CONTROL_ANCHOR_ITEM [ 
	exposedField	SFVec3f 		translate_Ctrl	0 0 0 	 	#  Placement of control in control panel 
	exposedField	SFColor		ctrlColor		0.6 0.6 1.0 		#  Color of control 
	exposedField 	MFString		strLabel		["Label item"]	#  display text label for control 
	exposedField	MFString           	urlName		["WorldInfo.htm"]	#  name for url to execute onClick; default is in new window
#										#  There is no need to specify the url description; same as label name
] # end PROTO Fields
# Begin PROTO OBJECT
{

# Transform repositions entire object - a sphere and text label 
	DEF CONTROL_ITEM Transform { 
		translation IS translate_Ctrl  #  0 0 0 
		children [ 
# Control item button 
		DEF CI_Anchor Anchor {
#	Anchor sensor responds to both button and text 
		url IS urlName
#  Pop-up display disabled 		parameter [ "target='_blank'" ]
#		parameter [ "target='_blank'" ]
		description ""

		children [

			DEF Control_Button_Sphere Shape {   
              	  		appearance Appearance {
                          		material Material { 
				    			diffuseColor IS ctrlColor # .6 .6 1
							transparency .7
						} # end Material
	              	  	} # end Appearance 
		                	geometry Sphere { radius .2  } 
			} # end Shape Control_Button_Sphere
# Control item button sensor 

# Control item label 
			DEF CONTROL_LABEL Transform { 
#   nudged down to button baseline 
				translation 0.3 -0.35 0 
				children [

	            	  		Shape {
            				appearance Appearance {
							material Material {
				   				diffuseColor IS ctrlColor # 0.6 0.6 0.6 
								} # end Material
		                            }    # end Appearance 
              		              geometry Text {
							string IS strLabel   # "Label text" 
							fontStyle FontStyle {
	             					justify "FIRST"  
								family "SANS"
								style "BOLD"  
								size 1.0 
                          		  	} # end FontStyle  
						} # end Geometry 
					} # end Shape Text Control item label 
				] # end children CONTROL_LABEL text
			} # end Transform CONTROL_LABEL text

		] # end children CI_Anchor
		} # end Anchor CI_Anchor

		] # end children Transform CONTROL_ITEM
	} # end children Transform CONTROL_ITEM

 } # end PROTO OBJECT CONTROL_ANCHOR_ITEM  


# =========================================================================
# Template for control button with memory and initial on state and memory
# BUTTON SHAPE 
PROTO Control_Button_Sphere_ON_MEM [ 
	exposedField 	SFFloat		ctrlTransparency	0.7			#  transparency of control 
	exposedField	SFInt32		ctrlChoiceAction	1			#  sets which control choice will be sent onlclick 
	eventIn		SFBool		set_boolean					#  on click in signal 
	eventOut	SFInt32		Control_choice 					#  on click choice out signal 
] # end PROTO Fields
# Begin PROTO OBJECT
{


# Control item button 
			DEF Control_Button_Sphere Shape {   
	              	  		appearance Appearance {
                     			     		material DEF Control_Button_Material Material { 
						diffuseColor 1.0 1.0 0.0 
						transparency .7
					} # end Material
					} # end Appearance 
			                	geometry Sphere { radius 0.2 } 
			} # end Shape Control_Button_Sphere
# Color switcher
			DEF ColorPath ColorInterpolator {
				key [ 0.0 1.0 ]
				keyValue [ 
					1.0 1.0 0.0, 
					0.6 0.6 1.0, ]
			}

# PASS DATA FROM EXPOSED FIELDS IN PROTOTYPE TO OBJECT INSTANCE 
DEF tmp_ctrlChoiceAction Switch { whichChoice IS ctrlChoiceAction }			# Pass SFInt32 to script 

# Control item button sensor 
			DEF Control_Filter Script { # On/Off toggle switch with memory
			field SFNode ChoiceAction USE tmp_ctrlChoiceAction
			field SFBool value TRUE 
			eventIn SFBool set_boolean IS set_boolean
			url [ "javascript: 
				function set_boolean ( bool, eventTime ) {
				if ( bool == false ) { return; } 
				if ( value == true ) { value = false; } 
				else { value = true; } 
				value_changed = value; 
				if ( value == false ) { 
					Control_choice = ChoiceAction.whichChoice ; 
					set_fraction = 1.0; 
				}
				if ( value == true ) { 
					Control_choice = 0; 
					set_fraction = 0.0; 
				}
				}" 
			] 
			eventOut SFBool value_changed  
			eventOut SFInt32 Control_choice IS Control_choice 
			eventOut SFFloat set_fraction 
			} # End Control_Filter Script 

# Filter script routers are outside end children for Cosmoplayer 2.1 compatability 
#			ROUTE Control_Button.isActive TO Control_Filter.set_boolean 
			ROUTE Control_Filter.set_fraction TO ColorPath.set_fraction 
			ROUTE ColorPath.value_changed TO Control_Button_Material.set_diffuseColor 

} # end PROTO Control_Button_Sphere_ON_MEM

# =========================================================================
# Template for control button with memory and initial off state 
# BUTTON SHAPE 
#    Unique settings are intial diffuse color and size and initial "value" in control filter script 
PROTO Control_Button_Sphere_OFF_MEM [ 
	exposedField 	SFFloat		ctrlTransparency	0.7			#  transparency of control 
	exposedField	SFInt32		ctrlChoiceAction	1			#  sets which control choice will be sent onlclick 
	eventIn		SFBool		set_boolean					#  on click in signal 
	eventOut	SFInt32		Control_choice 					#  on click choice out signal 
] # end PROTO Fields
# Begin PROTO OBJECT
{


# Control item button 
			DEF Control_Button_Sphere Shape {   
	              	  		appearance Appearance {
                     			     		material DEF Control_Button_Material Material { 
# SPECIAL DERIVATION FOR INITIALIZATION STATE  - initial color is off state
						diffuseColor 0.6 0.6 1.0
						transparency .7
					} # end Material
					} # end Appearance 
			                	geometry Sphere { radius 0.2 } 
			} # end Shape Control_Button_Sphere
# Color switcher
			DEF ColorPath ColorInterpolator {
				key [ 0.0 1.0 ]
				keyValue [ 
					1.0 1.0 0.0, 
					0.6 0.6 1.0, ]
			}

# PASS DATA FROM EXPOSED FIELDS IN PROTOTYPE TO OBJECT INSTANCE 
DEF tmp_ctrlChoiceAction Switch { whichChoice IS ctrlChoiceAction }			# Pass SFInt32 to script 

# Control item button sensor 
			DEF Control_Filter Script { # On/Off toggle switch with memory
			field SFNode ChoiceAction USE tmp_ctrlChoiceAction
# SPECIAL DERIVATION FOR INITIALIZATION STATE  - FALSE instead of normal TRUE
			field SFBool value FALSE 
			eventIn SFBool set_boolean IS set_boolean
			url [ "javascript: 
				function set_boolean ( bool, eventTime ) {
				if ( bool == false ) { return; } 
				if ( value == true ) { value = false; } 
				else { value = true; } 
				value_changed = value; 
				if ( value == false ) { 
					Control_choice = ChoiceAction.whichChoice ; 
					set_fraction = 1.0; 
				}
				if ( value == true ) { 
					Control_choice = 0; 
					set_fraction = 0.0; 
				}
				}" 
			] 
			eventOut SFBool value_changed  
			eventOut SFInt32 Control_choice IS Control_choice 
			eventOut SFFloat set_fraction 
			} # End Control_Filter Script 

# Filter script routers are outside end children for Cosmoplayer 2.1 compatability 
#			ROUTE Control_Button.isActive TO Control_Filter.set_boolean 
			ROUTE Control_Filter.set_fraction TO ColorPath.set_fraction 
			ROUTE ColorPath.value_changed TO Control_Button_Material.set_diffuseColor 

} # end PROTO Control_Button_Sphere_OFF_MEM

# =========================================================================
# Template for control button with memory and initial on state and memory
# BOX SHAPE 
PROTO Control_Button_Box_ON_MEM [ 
	exposedField 	SFFloat		ctrlTransparency	0.7			#  transparency of control 
	exposedField	SFInt32		ctrlChoiceAction	1			#  sets which control choice will be sent onlclick 
	eventIn		SFBool		set_boolean				#  on click in signal 
	eventOut	SFInt32		Control_choice 					#  on click choice out signal 
] # end PROTO Fields
# Begin PROTO OBJECT
{


# Control item button 
			DEF Control_Button_Sphere Shape {   
	              	  		appearance Appearance {
                     			     		material DEF Control_Button_Material Material { 
						diffuseColor 1.0 1.0 0.0 
						transparency .7
					} # end Material
					} # end Appearance 
			                	geometry Box { size 0.3 0.3 0.3 } 
			} # end Shape Control_Button_Sphere
# Color switcher
			DEF ColorPath ColorInterpolator {
				key [ 0.0 1.0 ]
				keyValue [ 
					1.0 1.0 0.0, 
					0.6 0.6 1.0, ]
			}

# PASS DATA FROM EXPOSED FIELDS IN PROTOTYPE TO OBJECT INSTANCE 
DEF tmp_ctrlChoiceAction Switch { whichChoice IS ctrlChoiceAction }			# Pass SFInt32 to script 

# Control item button sensor 
			DEF Control_Filter Script { # On/Off toggle switch with memory
			field SFNode ChoiceAction USE tmp_ctrlChoiceAction
			field SFBool value TRUE 
			eventIn SFBool set_boolean IS set_boolean
			url [ "javascript: 
				function set_boolean ( bool, eventTime ) {
				if ( bool == false ) { return; } 
				if ( value == true ) { value = false; } 
				else { value = true; } 
				value_changed = value; 
				if ( value == false ) { 
					Control_choice = ChoiceAction.whichChoice ; 
					set_fraction = 1.0; 
				}
				if ( value == true ) { 
					Control_choice = 0; 
					set_fraction = 0.0; 
				}
				}" 
			] 
			eventOut SFBool value_changed  
			eventOut SFInt32 Control_choice IS Control_choice 
			eventOut SFFloat set_fraction 
			} # End Control_Filter Script 

# Filter script routers are outside end children for Cosmoplayer 2.1 compatability 
#			ROUTE Control_Button.isActive TO Control_Filter.set_boolean 
			ROUTE Control_Filter.set_fraction TO ColorPath.set_fraction 
			ROUTE ColorPath.value_changed TO Control_Button_Material.set_diffuseColor 

} # end PROTO Control_Button_Box_ON_MEM

# =========================================================================
# Template for control button with memory and initial off state 
# BOX SHAPE 
#    Unique settings are intial diffuse color and size and initial "value" in control filter script 
PROTO Control_Button_Box_OFF_MEM [ 
	exposedField 	SFFloat		ctrlTransparency	0.7			#  transparency of control 
	exposedField	SFInt32		ctrlChoiceAction	1			#  sets which control choice will be sent onlclick 
	eventIn		SFBool		set_boolean					#  on click in signal 
	eventOut	SFInt32		Control_choice 					#  on click choice out signal 
] # end PROTO Fields
# Begin PROTO OBJECT
{


# Control item button 
			DEF Control_Button_Sphere Shape {   
	              	  		appearance Appearance {
                     			     		material DEF Control_Button_Material Material { 
# SPECIAL DERIVATION FOR INITIALIZATION STATE  - initial color is off state
						diffuseColor 0.6 0.6 1.0
						transparency .7
					} # end Material
					} # end Appearance 
			                	geometry Box { size 0.3 0.3 0.3 } 
			} # end Shape Control_Button_Sphere
# Color switcher
			DEF ColorPath ColorInterpolator {
				key [ 0.0 1.0 ]
				keyValue [ 
					1.0 1.0 0.0, 
					0.6 0.6 1.0, ]
			}

# PASS DATA FROM EXPOSED FIELDS IN PROTOTYPE TO OBJECT INSTANCE 
DEF tmp_ctrlChoiceAction Switch { whichChoice IS ctrlChoiceAction }			# Pass SFInt32 to script 

# Control item button sensor 
			DEF Control_Filter Script { # On/Off toggle switch with memory
			field SFNode ChoiceAction USE tmp_ctrlChoiceAction
# SPECIAL DERIVATION FOR INITIALIZATION STATE  - FALSE instead of normal TRUE
			field SFBool value FALSE 
			eventIn SFBool set_boolean IS set_boolean
			url [ "javascript: 
				function set_boolean ( bool, eventTime ) {
				if ( bool == false ) { return; } 
				if ( value == true ) { value = false; } 
				else { value = true; } 
				value_changed = value; 
				if ( value == false ) { 
					Control_choice = ChoiceAction.whichChoice ; 
					set_fraction = 1.0; 
				}
				if ( value == true ) { 
					Control_choice = 0; 
					set_fraction = 0.0; 
				}
				}" 
			] 
			eventOut SFBool value_changed  
			eventOut SFInt32 Control_choice IS Control_choice 
			eventOut SFFloat set_fraction 
			} # End Control_Filter Script 

# Filter script routers are outside end children for Cosmoplayer 2.1 compatability 
#			ROUTE Control_Button.isActive TO Control_Filter.set_boolean 
			ROUTE Control_Filter.set_fraction TO ColorPath.set_fraction 
			ROUTE ColorPath.value_changed TO Control_Button_Material.set_diffuseColor 

} # end PROTO Control_Button_Box_OFF_MEM

# =========================================================================
# Template for control label text 
PROTO Control_Label_Text_Format [ 
	exposedField 	MFString 	strLabel		"Label text"		#  text to display in label 
] # end PROTO Fields
# Begin PROTO OBJECT
{


	            	  		Shape {
            					appearance Appearance {
						material Material {
		   					diffuseColor 0.7 0.7 0.7 
						} # end Material
			                     		}    # end Appearance 
              				geometry Text {
					string IS strLabel
					fontStyle FontStyle {
		             				justify "FIRST"  
						family "SANS"
						style "BOLD"  
						size 1.0 
                     		     		  	} # end FontStyle  
				} # end Geometry 
				} # end Shape Text Control item label 

} # end PROTO Control_Label_Text_Format

# =========================================================================
# Template for circular Is Selected indicator on Control Panel  
PROTO Indicator_Clyinder [ 
	exposedField	SFVec3f 	translate_Ctrl		6.5 	0.0 	0.00		#  Placement of control on control panel 
	exposedField	SFRotation 	rotation_Ctrl		1.0 	0.0 	0.0	1.547	#  Rotation of control on control panel 
	exposedField 	SFFloat		ctrlTransparency	0.6				#  transparency of control 
] # end PROTO Fields
# Begin PROTO OBJECT
{
		DEF Indicator_Box Transform { 
			translation IS translate_Ctrl
	 		rotation IS rotation_Ctrl
			children [

					Shape { 
					appearance Appearance { 
						material Material { 
							diffuseColor 1.0 1.0 1.0 
							transparency IS ctrlTransparency 
						} # end Material
					} # end Appearance
					geometry Cylinder { radius 0.5 height 0.2 side TRUE top TRUE bottom FALSE }
				} # end Shape 
			] # end children Indicator_Box
		} # end Transform Indicator_Box

} # end PROTO Indicator_Box 

# =========================================================================
# Template for control button with memory and initial on state 
# CONE SHAPE BUTTON 
PROTO Control_Button_Cone_ON_NOMEM [ 
	exposedField 	SFFloat		ctrlTransparency	0.7			#  transparency of control 
	exposedField	SFInt32		ctrlChoiceAction	1			#  sets which control choice will be sent onlclick 
	eventIn		SFBool		set_boolean					#  on click in signal 
	eventOut	SFInt32		Control_choice 					#  on click choice out signal 
] # end PROTO Fields
# Begin PROTO OBJECT
{


# Control item button 
			DEF Control_Button_Sphere Shape {   
	              	  		appearance Appearance {
                     			     		material DEF Control_Button_Material Material { 
						diffuseColor 1.0 1.0 0.0 
						transparency .7
					} # end Material
					} # end Appearance 
			                	geometry Cone { bottomRadius .3 height 0.7 } 
			} # end Shape Control_Button_Sphere

# PASS DATA FROM EXPOSED FIELDS IN PROTOTYPE TO OBJECT INSTANCE 
DEF tmp_ctrlChoiceAction Switch { whichChoice IS ctrlChoiceAction }			# Pass SFInt32 to script 

# Control item button sensor 
			DEF Control_Filter Script { # On/Off toggle switch without memory
			field SFNode ChoiceAction USE tmp_ctrlChoiceAction
			field SFBool value TRUE 
			eventIn SFBool set_boolean IS set_boolean
			url [ "javascript: 
				function set_boolean ( bool, eventTime ) {
				if ( bool == false ) { return; } 
				if ( bool == true ) { Control_choice = ChoiceAction.whichChoice ; }
				}" 
			] 
			eventOut SFInt32 Control_choice IS Control_choice 
			} # End Control_Filter Script 

# Filter script routers are outside end children for Cosmoplayer 2.1 compatability 
#			ROUTE Control_Button.isActive TO Control_Filter.set_boolean 
# All ROUTEs are external to this script 

} # end PROTO Control_Button_Cone_ON_NOMEM


# =========================================================================
# Template for control button with memory and initial on state 
# CYLINDER SHAPE BUTTON 
PROTO Control_Button_Cylinder_ON_NOMEM [ 
	exposedField 	SFFloat		ctrlTransparency	0.7			#  transparency of control 
	exposedField	SFInt32		ctrlChoiceAction	1			#  sets which control choice will be sent onlclick 
	eventIn		SFBool		set_boolean				#  on click in signal 
	eventOut	SFInt32		Control_choice 					#  on click choice out signal 
] # end PROTO Fields
# Begin PROTO OBJECT
{

# Control item button 
			DEF Control_Button_Sphere Shape {   
	              	  		appearance Appearance {
                     			     		material DEF Control_Button_Material Material { 
						diffuseColor 1.0 1.0 0.0 
						transparency .7
					} # end Material
					} # end Appearance 
			                	geometry Cylinder { radius .3 height 0.7 } 
			} # end Shape Control_Button_Sphere

# PASS DATA FROM EXPOSED FIELDS IN PROTOTYPE TO OBJECT INSTANCE 
DEF tmp_ctrlChoiceAction Switch { whichChoice IS ctrlChoiceAction }			# Pass SFInt32 to script 

# Control item button sensor 
			DEF Control_Filter Script { # On/Off toggle switch without memory
			field SFNode ChoiceAction USE tmp_ctrlChoiceAction
			field SFBool value TRUE 
			eventIn SFBool set_boolean IS set_boolean
			url [ "javascript: 
				function set_boolean ( bool, eventTime ) {
				if ( bool == false ) { return; } 
				if ( bool == true ) { Control_choice = ChoiceAction.whichChoice ; }
				}" 
			] 
			eventOut SFInt32 Control_choice IS Control_choice 
			} # End Control_Filter Script 

# Filter script routers are outside end children for Cosmoplayer 2.1 compatability 
#			ROUTE Control_Button.isActive TO Control_Filter.set_boolean 
# All ROUTEs are external to this script 

} # end PROTO Control_Button_Cylinder_ON_NOMEM

# =========================================================================
# Template for generic on/off toggle with control_choice, no memory, and and initial off state 
#    Returns Control_Choice if true or 1 if false 
PROTO Control_Filter_Toggle_OFF_NOMEM [ 
	exposedField	SFInt32		ctrlChoiceAction	0	#  sets which control choice will be sent onlclick 
	eventIn		SFBool		set_boolean		#  on click in signal 
	eventOut		SFInt32		Control_choice 		#  on click choice out signal 
] # end PROTO Fields
# Begin PROTO OBJECT
{

# PASS DATA FROM EXPOSED FIELDS IN PROTOTYPE TO OBJECT INSTANCE 
DEF tmp_ctrlChoiceAction Switch { whichChoice IS ctrlChoiceAction }			# Pass SFInt32 to script 

# Control filter script - use with sensor 
			DEF Control_Filter Script { # On/Off toggle switch without memory
			field SFNode ChoiceAction USE tmp_ctrlChoiceAction
			field SFBool value TRUE 
			eventIn SFBool set_boolean IS set_boolean
			directOutput TRUE
			url [ "javascript: 
				function set_boolean ( bool, eventTime ) {
				if ( bool == false ) { Control_choice = 1 ; } 
				if ( bool == true ) { Control_choice = ChoiceAction.whichChoice ; }
				}" 
			] 
			eventOut SFInt32 Control_choice IS Control_choice 
			} # End Control_Filter Script 

# Filter script routers are outside end children for Cosmoplayer 2.1 compatability 
#			ROUTE Control_Button.isActive TO Control_Filter.set_boolean 
# All ROUTEs are external to this script 

} # end PROTO Control_Filter_Toggle_OFF_NOMEM 
