#X3D V3.0 utf8 PROFILE Immersive # [X3D] version=3.0 # [X3D] noNamespaceSchemaLocation=https://www.web3d.org/specifications/x3d-3.0.xsd # X3D-to-ClassicVRML XSL translation autogenerated by X3dToClassicVrmlEncoding.xslt and X3dToVrml97.xslt # https://www.web3d.org/x3d/content/X3dToClassicVrmlEncoding.xslt # https://www.web3d.org/x3d/content/X3dToVrml97.xslt # Transformation using XSLT processor: Saxonica # head META "title" "TimeDelaySensorPrototype.x3d" META "description" "Time delay sensor design pattern, implemented as a reusable prototype node." META "creator" "Don Brutzman and MV4204 class" META "created" "29 August 2003" META "modified" "28 November 2019" META "reference" "TimeDelaySensorExample.x3d" META "reference" "https://www.web3d.org/technicalinfo/specifications/vrml97/part1/concepts.html#4.6.8" META "reference" "https://www.web3d.org/technicalinfo/specifications/vrml97/part1/nodesRef.html#CoordinateInterpolator" META "subject" "TimeDelaySensor" META "identifier" "https://savage.nps.edu/Savage/Tools/Animation/TimeDelaySensorPrototype.x3d" META "generator" "X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit" META "license" "../../license.html" # [Scene] ========== ========== ========== WorldInfo { title "TimeDelaySensorPrototype.x3d" } PROTO TimeDelaySensor [ # [appinfo] TimeSensor functionality commences after delayInterval pause inputOutput SFString description "" # [appinfo] describe the purpose of this sensor inputOutput SFBool enabled TRUE # [appinfo] whether sensor is active inputOutput SFTime startTime 0 # [appinfo] when current time exceeds startTime, isActive becomes true and sensor becomes active inputOutput SFTime delayInterval 1 # [appinfo] seconds outputOnly SFTime delayCompleteTime initializeOnly SFBool traceEnabled FALSE ] { Group { children [ DEF TimeDelayClock TimeSensor { startTime IS startTime enabled IS enabled cycleInterval IS delayInterval } DEF TimeDelayScript Script { inputOutput SFString description IS description # [appinfo] describe the purpose of this sensor inputOnly SFFloat set_fraction outputOnly SFTime delayCompleteTime IS delayCompleteTime initializeOnly SFNode LocalTimeDelayClock USE TimeDelayClock initializeOnly SFTime priorDelayInterval 1 initializeOnly SFBool delayStarted FALSE 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 handled by setting values function initialize () { priorDelayInterval = LocalTimeDelayClock.cycleInterval; tracePrint ('initial delayInterval=' + priorDelayInterval + ' seconds'); } function tracePrint (outputString) { if (traceEnabled) Browser.println ('[TimeDelaySensor] ' + outputString); } function set_description (newDescription) { description = newDescription; } function set_fraction (currentFraction, timestamp) // from LocalTimeDelayClock { if (priorDelayInterval != LocalTimeDelayClock.cycleInterval) { priorDelayInterval = LocalTimeDelayClock.cycleInterval; tracePrint ('changed delayInterval=' + priorDelayInterval + ' seconds'); } if (!delayStarted) { delayStarted = true; tracePrint ('delay start time=' + timestamp); } tracePrint ('set_fraction=' + currentFraction); if (currentFraction >= 1.0) { delayCompleteTime = timestamp; // send output event tracePrint ('delayCompleteTime=' + delayCompleteTime); delayStarted = false; } } " ] } ] ROUTE TimeDelayClock.fraction_changed TO TimeDelayScript.set_fraction } } # ====================================== # Example use Anchor { description "TimeDelaySensor Example" url [ "TimeDelaySensorExample.x3d" "https://savage.nps.edu/Savage/Tools/Animation/TimeDelaySensorExample.x3d" "TimeDelaySensorExample.wrl" "https://savage.nps.edu/Savage/Tools/Animation/TimeDelaySensorExample.wrl" ] children [ Shape { geometry Text { string [ "TimeDelaySensorPrototype" "defines a prototype" "" "Click text to see" "TimeDelaySensorExample scene" ] fontStyle FontStyle { justify [ "MIDDLE" "MIDDLE" ] size 0.7 } } appearance Appearance { material Material { diffuseColor 1 1 0.2 } } } ] }