#VRML V2.0 utf8 # # An example showing the functionality of Pilot Shared Events # # Protos needed for multi-user connections # PROTO BlaxxunZone [ exposedField MFNode events [] ] { } PROTO SharedEvent [ exposedField SFString name "event" eventIn SFString stringFromServer eventOut SFString stringToServer eventIn SFString set_string eventOut SFString string_changed eventOut SFBool initialized ] { Script { eventIn SFString stringFromServer IS stringFromServer eventOut SFString stringToServer IS stringToServer eventIn SFString set_string IS set_string eventOut SFString string_changed IS string_changed eventOut SFBool initialized IS initialized url "vrmlscript: function initialize( time ) { initialized = TRUE;} function stringFromServer (value, time) { string_changed = value; } function set_string (value, time) { stringToServer = value; } " } } # If the name of a shared event contains the substring "_S_PILOT_" # the shared event is treated as a pilot event. # # Setting the event to '' releases the lock # Setting it to any other string requests the lock # If the value of the event sent by the server equals the avatar name # the lock is granted to this client by the server. # DEF SharedZone BlaxxunZone { events [ DEF LockEvent SharedEvent{ name "P_S_PILOT_TEST" } ] } # Some background for the scene # Background { groundAngle 1.5708 groundColor [0.1 0.5 0.1,0.1 0.5 0.1] skyAngle 1.5708 skyColor [0.46 0.38 0.88,0.8 0.7 0.94] } NavigationInfo { headlight TRUE type "WALK" avatarSize [ 0.25 1.6 1 ] } Group { children Shape { appearance Appearance { material Material { diffuseColor 0.2 1 0.2 emissiveColor 0.1 0.5 0.1 } } geometry IndexedFaceSet { coord Coordinate { point [ -32 0 -32,32 0 -32,32 0 32,-32 0 32 ] } ccw FALSE coordIndex [ 0,1,2,3, -1] normalPerVertex FALSE } } } Viewpoint { fieldOfView 0.8 orientation 0 1 0 0 position 0 1.6 4 description "Front" } # A time that makes sure we request the Pilot lock initially # DEF TimeLock TimeSensor { cycleInterval 1 loop TRUE enabled FALSE } # A group around everything # Group{ children[ # The green button to release the lock # Transform { translation 1 1.6 0 children [ DEF clearButton TouchSensor{} Shape { appearance Appearance { material Material { diffuseColor 0 1 0 }} geometry Sphere{ radius .25 } } ] } # The display of the lock # Transform{ translation 0 1.6 0 children[ Shape{ appearance Appearance{ material Material{ diffuseColor 1 1 1 }} geometry DEF thisText Text { string ["_"]fontStyle FontStyle { family "SANS" horizontal TRUE justify "MIDDLE" leftToRight TRUE size 0.125 spacing 1.0 style "BOLD" topToBottom TRUE } } } ] } DEF s Script{ eventIn SFTime set_lock eventIn SFTime clear_lock eventIn SFString set_text eventOut SFString lock_set eventOut MFString text_changed field SFString lock ''; field SFNode TimeLock USE TimeLock url"vrmlscript: function initialize() { // make sure the timer gets run // TimeLock.set_enabled = TRUE; Browser.print( 'Init: TimeLock enabled' ); // set the lock to an empty string // lock = ''; Browser.print( 'Init: lock to |' + lock + '|' ); // clear the text that is displayed // text_changed = new MFString( lock ); Browser.print( 'Init: text_changed to |' + text_changed + '|' ); } // the set_lock function is called by the TimeLock timer // function set_lock( v, t ) { Browser.print( 'set_lock: lock is |' + lock + '|' ); // if the lock is not set currently // if( lock == '' ) { // the lock is not set currently, // we try to release the lock, // the server will assign it to somebody // lock_set = ''; Browser.print( 'set_lock: lock_set to |' + lock_set + '|' ); } else { // as the lock is set we can disable the timer // TimeLock.set_enabled = FALSE; Browser.print( 'set_lock: TimeLock disabled' ); } } // In a real application there should be no reason to clear a pilot // lock at all, this function is just here to show what happens when // the Pilot lock is given up by a user // function clear_lock( v, t ) { Browser.print( 'clear_lock: lock is |' + lock + '|' ); // the lock can only be cleared if it is set by us // if( lock == Browser.myAvatarName ) { // clear the lock // lock_set = ''; Browser.print( 'clear_lock: lock_set to |' + lock_set + '|' ); } } function set_text( v ,t ) { // we received a new lock value from the net, set it localy // lock = v; Browser.print( 'set_text: lock to |' + lock + '|' ); // set the display as well // text_changed = new MFString( lock ); Browser.print( 'set_text: text_changed to |' + text_changed + '|' ); } " } ]}#END main group # This tries to release the lock until it is set # ROUTE TimeLock.cycleTime TO s.set_lock # This allows to clear the lock # ROUTE clearButton.touchTime TO s.clear_lock # Send the lock value to the network # ROUTE s.lock_set TO LockEvent.set_string # Receive the lock's value from the net # ROUTE LockEvent.string_changed TO s.set_text # Display the current lock # ROUTE s.text_changed TO thisText.set_string