| 1 |
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
|
| 3 | <X3D profile='Immersive' version='3.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.0.xsd'> |
| 4 | <head> |
| 5 | <meta name='title' content='TimeDelaySensorPrototype.x3d'/> |
| 6 | <meta name='description' content='Time delay sensor design pattern, implemented as a reusable prototype node.'/> |
| 7 | <meta name='creator' content='Don Brutzman and MV4204 class'/> |
| 8 | <meta name='created' content='29 August 2003'/> |
| 9 | <meta name='modified' content='28 November 2019'/> |
| 10 | <meta name='reference' content='TimeDelaySensorExample.x3d'/> |
| 11 | <meta name='reference' content='https://www.web3d.org/technicalinfo/specifications/vrml97/part1/concepts.html#4.6.8'/> |
| 12 | <meta name='reference' content='https://www.web3d.org/technicalinfo/specifications/vrml97/part1/nodesRef.html#CoordinateInterpolator'/> |
| 13 | <meta name='subject' content='TimeDelaySensor'/> |
| 14 | <meta name='identifier' content='https://savage.nps.edu/Savage/Tools/Animation/TimeDelaySensorPrototype.x3d'/> |
| 15 | <meta name='generator' content='X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit'/> |
| 16 | <meta name='license' content='../../license.html'/> |
| 17 | </head> |
| 18 | <Scene> |
| 19 | <WorldInfo title='TimeDelaySensorPrototype.x3d'/> |
| 20 | <ProtoDeclare name='TimeDelaySensor' appinfo='TimeSensor functionality commences after delayInterval pause'> |
| 21 | <ProtoInterface> |
| 22 |
<field name='description' type='SFString' accessType='inputOutput'
appinfo='describe the purpose of this sensor'/> |
| 23 |
<field name='enabled' type='SFBool' value='true' accessType='inputOutput'
appinfo='whether sensor is active'/> |
| 24 |
<field name='startTime' type='SFTime' value='0' accessType='inputOutput'
appinfo='when current time exceeds startTime, isActive becomes true and sensor becomes active'/> |
| 25 |
<field name='delayInterval' type='SFTime' value='1' accessType='inputOutput'
appinfo='seconds'/> |
| 26 | <field name='delayCompleteTime' type='SFTime' accessType='outputOnly'/> |
| 27 | <field name='traceEnabled' type='SFBool' value='false' accessType='initializeOnly'/> |
| 28 | </ProtoInterface> |
| 29 | <ProtoBody> |
| 30 | <Group> |
| 31 |
<!-- TimeSensor
TimeDelayClock is a DEF node that has 1 USE node: USE_1
<!-- ROUTE information for TimeDelayClock node: [from fraction_changed to TimeDelayScript.set_fraction ] --> <TimeSensor DEF='TimeDelayClock'> |
| 32 | <IS> |
| 33 | <connect nodeField='startTime' protoField='startTime'/> |
| 34 | <connect nodeField='enabled' protoField='enabled'/> |
| 35 | <connect nodeField='cycleInterval' protoField='delayInterval'/> |
| 36 | </IS> |
| 37 | </TimeSensor> |
| 38 |
<!-- ROUTE information for TimeDelayScript node:
[from TimeDelayClock.fraction_changed to set_fraction
]
-->
<Script DEF='TimeDelayScript' directOutput='true'> |
| 39 |
<field name='description' type='SFString' accessType='inputOutput'
appinfo='describe the purpose of this sensor'/> |
| 40 | <field name='set_fraction' type='SFFloat' accessType='inputOnly'/> |
| 41 | <field name='delayCompleteTime' type='SFTime' accessType='outputOnly'/> |
| 42 | <field name='LocalTimeDelayClock' type='SFNode' accessType='initializeOnly'> |
| 43 | <TimeSensor USE='TimeDelayClock'/> |
| 44 | </field> |
| 45 | <field name='priorDelayInterval' type='SFTime' value='1' accessType='initializeOnly'/> |
| 46 | <field name='delayStarted' type='SFBool' value='false' accessType='initializeOnly'/> |
| 47 | <field name='traceEnabled' type='SFBool' accessType='initializeOnly'/> |
| 48 | <IS> |
| 49 | <connect nodeField='description' protoField='description'/> |
| 50 | <connect nodeField='delayCompleteTime' protoField='delayCompleteTime'/> |
| 51 | <connect nodeField='traceEnabled' protoField='traceEnabled'/> |
| 52 | </IS> |
<![CDATA[
ecmascript:
// 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;
}
}
]]>
|
|
| 54 | </Script> |
| 55 | < ROUTE fromNode='TimeDelayClock' fromField='fraction_changed' toNode='TimeDelayScript' toField='set_fraction'/> |
| 56 | </Group> |
| 57 | </ProtoBody> |
| 58 | </ProtoDeclare> |
| 59 | <!-- ====================================== --> |
| 60 | <!-- Example use --> |
| 61 | <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" '> |
| 62 | <Shape> |
| 63 | <Text string='"TimeDelaySensorPrototype" "defines a prototype" "" "Click text to see" "TimeDelaySensorExample scene"'> |
| 64 | <FontStyle justify='"MIDDLE" "MIDDLE"' size='0.7'/> |
| 65 | </Text> |
| 66 | <Appearance> |
| 67 | <Material diffuseColor='1 1 0.2'/> |
| 68 | </Appearance> |
| 69 | </Shape> |
| 70 | </Anchor> |
| 71 | </Scene> |
| 72 | </X3D> |
Event Graph ROUTE Table with 1 ROUTE connection total, showing X3D event-model relationships for this scene.
Each row shows an event cascade that may occur during a single timestamp interval between frame renderings, as part of the X3D execution model.
|
TimeDelayClock
TimeSensor fraction_changed SFFloat |
TimeDelayScript
Script set_fraction SFFloat |
|
TimeDelayScript
Script |
No ROUTE connection found for output events from this node. Contains SFNode field with direct access to another node. |
| line 61
Anchor |
description='TimeDelaySensor Example' User-interaction hint for this node. |
<!--
Color-coding legend: X3D terminology
<X3dNode
DEF='idName' field='value'/>
matches XML terminology
<XmlElement
DEF='idName' attribute='value'/>
(Light-blue background: event-based behavior node or statement)
(Grey background inside box: inserted documentation)
(Magenta background: X3D Extensibility)
<ProtoDeclare name='ProtoName'>
<field
name='fieldName'/> </ProtoDeclare>
-->
<!--
For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints.
-->