source

vrml

VRML 2.0 Tutorial--button2.wrl Source

#VRML V2.0 utf8

WorldInfo {
	title "button2: Behavior: Push-Pop"
	info "
		File:          button2.wrl
		Version:       1.1
		Revisions:     1.0 June 22, 1996 -- initial cut
                     	1.1 February 16, 1997 -- updated to Final Spec
		Description:   Button now has a behavior: push-pop
		Requirements:  A VRML2.0 capable browser
		Author:        Matt Leonard
                     mattl@pobox.com
                     http://www.pobox.com/~mattl
		Copyright:     This file is copyright 1996 Matt Leonard
		Tabstop:       4
	" # info
} # WorldInfo

NavigationInfo {
	type "EXAMINE"
} # NavigationInfo

Viewpoint {
	position 0.2 1.0 1
	orientation 1 0 0 -0.6
	description "Entry Viewpoint" 
} # Viewpoint

DEF BASE Transform {
	translation 0 0 0
	scale 2 1 1

	children [
		Shape {
			geometry Cylinder {
				radius 0.1
				height 0.05
			} # Cylinder
		} # Shape
	] # children
} # BASE

DEF BUTTON Transform {
	translation 0 0 0
	scale 2 1 1

	children [
		DEF SWITCH Switch {
			whichChoice 0
			choice [
				DEF POPPED Transform {
					translation 0 0.026 0
					children [
						Shape {
							geometry Cylinder {
								radius 0.07
								height 0.04
							} # Cylinder

							appearance Appearance {
								material Material {
									# green
									diffuseColor 0 255 0
								} # material
							} # appearance
						} # Shape
					] # children
				} # POPPED

				DEF PUSHED Transform {
					translation 0 0.026 0
					children [
						Shape {
							geometry Cylinder {
								radius .07
								height .005
							} # Cylinder

							appearance Appearance {
								material Material {
									# red
									diffuseColor 255 0 0
								} # material
							} # appearance
						} # Shape
					] # children
				} # PUSHED
			] # choice
		} # SWITCH

		DEF ON_OFF TouchSensor {
		} # ON_OFF

	] # children
} # BUTTON

DEF PUSH_SCRIPT Script {
	eventIn SFTime pushButton
	eventOut SFInt32 push_pop
	url "vrmlscript:
	function pushButton() {
		if (push_pop == 1)
			push_pop = 0;
		else
			push_pop = 1;
	}
	" # url
} # PUSH_SCRIPT

ROUTE ON_OFF.touchTime TO PUSH_SCRIPT.pushButton
ROUTE PUSH_SCRIPT.push_pop TO SWITCH.whichChoice

-- Back to Tutorial --

vrml navbar