#X3D V3.0 utf8 # X3D-to-ClassicVRML XSL translation autogenerated by X3dToVrml97.xslt # https://www.web3d.org/x3d/content/X3dToVrml97.xslt # Generated using XSLT processor: Saxonica PROFILE Immersive # [X3D] version=3.0 # [X3D] noNamespaceSchemaLocation=https://www.web3d.org/specifications/x3d-3.0.xsd # [head] META "title" "DoubleClickTouchSensorPrototype.x3d" META "description" "Double-click TouchSensor design pattern, implemented as a reusable prototype node." META "creator" "Don Brutzman" META "created" "26 May 2004" META "modified" "6 June 2020" META "reference" "DoubleClickTouchSensorExample.x3d" META "reference" "https://www.web3d.org/x3d/specifications/ISO-IEC-19775-FDIS-X3dAbstractSpecification/Part01/components/pointingsensor.html#TouchSensor" META "subject" "DoubleClickTouchSensor" META "identifier" "https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototype.x3d" META "generator" "X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit" META "license" "../../license.html" # [Scene] ========== ========== ========== NavigationInfo { type [ "EXAMINE" "ANY" ] } ### Default X3D NavigationInfo WorldInfo { title "DoubleClickTouchSensorPrototype.x3d" } PROTO DoubleClickTouchSensor [ # [appinfo] DoubleClickTouchSensor functionality activates when user double clicks (or double selects) within maxDelayInterval inputOutput SFString description "" # [appinfo] describe the purpose of this sensor initializeOnly SFTime maxDelayInterval 0.5 # [appinfo] seconds inputOutput SFBool enabled TRUE outputOnly SFBool isActive outputOnly SFBool isOver outputOnly SFTime touchTime # [appinfo] seconds outputOnly SFVec3f hitPoint_changed outputOnly SFVec3f hitNormal_changed outputOnly SFVec2f hitTexCoord_changed initializeOnly SFNode metadata NULL # [appinfo] can contain one of Metadata nodes # initialization node (if any) goes here initializeOnly SFBool traceEnabled FALSE ] { DEF TouchSensorNode TouchSensor { ### Warning: IS/connect ignored for nodeField='description' since not a supported field in VRML97 for parent TouchSensor ### description IS description enabled IS enabled isOver IS isOver } Group { children [ DEF DoubleClickTouchScript Script { inputOutput SFString description IS description inputOnly SFBool checkClicks initializeOnly SFTime maxDelayInterval IS maxDelayInterval # [appinfo] seconds initializeOnly SFTime priorTouchTime -1 initializeOnly SFTime currentTouchTime -1 initializeOnly SFNode touchSensor USE TouchSensorNode # [appinfo] permits controlled access to various TouchSensorNode fields outputOnly SFBool isActive IS isActive outputOnly SFTime touchTime IS touchTime # [appinfo] seconds outputOnly SFVec3f hitPoint_changed IS hitPoint_changed outputOnly SFVec3f hitNormal_changed IS hitNormal_changed outputOnly SFVec2f hitTexCoord_changed IS hitTexCoord_changed initializeOnly SFBool traceEnabled IS traceEnabled directOutput TRUE url [ "ecmascript: // ### X3D Browser.print() not supported by all VRML97 viewers, instead simply using print() // inputOnly events are handled by functions, // initializeOnly fields are variable objects, // outputOnly events are sent by setting values function initialize () { tracePrint ('initialize (); enabled=' + touchSensor.enabled); } // trigger on isActive to filter touchTime events when unclicking function checkClicks (value, timestamp) // activated from TouchSensorNode.isActive { if (value == false) // doubleClick isActive=false events { if (isActive == true) // need to unclick { isActive = false; // send output events touchTime = timestamp; tracePrint ('DoubleClick isActive=false;'); } return; } priorTouchTime = currentTouchTime; currentTouchTime = timestamp; computedDelay = (currentTouchTime - priorTouchTime); if (priorTouchTime == -1) { tracePrint ('priorTouchTime == -1, return;'); return; } else if (computedDelay <= maxDelayInterval) { tracePrint ('computedDelay=' + computedDelay + ', DoubleClick isActive=true;'); isActive = true; // send output events touchTime = timestamp; hitPoint_changed = touchSensor.hitPoint_changed; hitNormal_changed = touchSensor.hitNormal_changed; hitTexCoord_changed = touchSensor.hitTexCoord_changed; } else { tracePrint ('computedDelay=' + computedDelay + ', single click'); return; } } function set_description (newDescription) { description = newDescription; } function tracePrint (outputString) { if (traceEnabled) Browser.println ('[DoubleClickTouchSensor] ' + outputString); } " ] } DEF MetadataHolder Collision { enabled FALSE proxy IS metadata } ] ROUTE TouchSensorNode.isActive TO DoubleClickTouchScript.checkClicks } } # ====================================== # Example use Anchor { description "DoubleClickTouchSensor Example" parameter [ "target=_blank" ] url [ "DoubleClickTouchSensorExample.x3d" "https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorExample.x3d" "DoubleClickTouchSensorExample.wrl" "https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorExample.wrl" ] children [ Shape { geometry Text { string [ "DoubleClickTouchSensorPrototype" "defines a prototype" "" "Click text to see" "DoubleClickTouchSensorExample scene" ] fontStyle FontStyle { justify [ "MIDDLE" "MIDDLE" ] size 0.7 } } appearance Appearance { material Material { diffuseColor 1 1 0.2 } } } ] }