X3D Model Documentation: TimeDelaySensorPrototype.x3d

  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='titlecontent='TimeDelaySensorPrototype.x3d'/>
  6            <meta name='descriptioncontent='Time delay sensor design pattern, implemented as a reusable prototype node.'/>
  7            <meta name='creatorcontent='Don Brutzman and MV4204 class'/>
  8            <meta name='createdcontent='29 August 2003'/>
  9            <meta name='modifiedcontent='28 November 2019'/>
 10            <meta name='referencecontent='TimeDelaySensorExample.x3d'/>
 11            <meta name='referencecontent='https://www.web3d.org/technicalinfo/specifications/vrml97/part1/concepts.html#4.6.8'/>
 12            <meta name='referencecontent='https://www.web3d.org/technicalinfo/specifications/vrml97/part1/nodesRef.html#CoordinateInterpolator'/>
 13            <meta name='subjectcontent='TimeDelaySensor'/>
 14            <meta name='identifiercontent='https://savage.nps.edu/Savage/Tools/Animation/TimeDelaySensorPrototype.x3d'/>
 15            <meta name='generatorcontent='X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit'/>
 16            <meta name='licensecontent='../../license.html'/>
 17       </head>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->

<!-- to top Index for DEF nodes: TimeDelayClock, TimeDelayScript

Index for ProtoDeclare definition: TimeDelaySensor
-->
 18       <Scene>
 19            <WorldInfo title='TimeDelaySensorPrototype.x3d'/>
 20            <ProtoDeclare name='TimeDelaySensorappinfo='TimeSensor functionality commences after delayInterval pause'>
 21                 <ProtoInterface>
 22                      <field name='descriptiontype='SFStringaccessType='inputOutput'
                     appinfo='describe the purpose of this sensor'/>
 23                      <field name='enabledtype='SFBoolvalue='trueaccessType='inputOutput'
                     appinfo='whether sensor is active'/>
 24                      <field name='startTimetype='SFTimevalue='0accessType='inputOutput'
                     appinfo='when current time exceeds startTime, isActive becomes true and sensor becomes active'/>
 25                      <field name='delayIntervaltype='SFTimevalue='1accessType='inputOutput'
                     appinfo='seconds'/>
 26                      <field name='delayCompleteTimetype='SFTimeaccessType='outputOnly'/>
 27                      <field name='traceEnabledtype='SFBoolvalue='falseaccessType='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='startTimeprotoField='startTime'/>
 34                                     <connect nodeField='enabledprotoField='enabled'/>
 35                                     <connect nodeField='cycleIntervalprotoField='delayInterval'/>
 36                                </IS>
 37                           </TimeSensor>
 38 
                         <!-- ROUTE information for TimeDelayScript node:  [from TimeDelayClock.fraction_changed to set_fraction ] -->
                         <Script DEF='TimeDelayScriptdirectOutput='true'>
 39                                <field name='descriptiontype='SFStringaccessType='inputOutput'
                               appinfo='describe the purpose of this sensor'/>
 40                                <field name='set_fractiontype='SFFloataccessType='inputOnly'/>
 41                                <field name='delayCompleteTimetype='SFTimeaccessType='outputOnly'/>
 42                                <field name='LocalTimeDelayClocktype='SFNodeaccessType='initializeOnly'>
 43                                     <TimeSensor USE='TimeDelayClock'/>
 44                                </field>
 45                                <field name='priorDelayIntervaltype='SFTimevalue='1accessType='initializeOnly'/>
 46                                <field name='delayStartedtype='SFBoolvalue='falseaccessType='initializeOnly'/>
 47                                <field name='traceEnabledtype='SFBoolaccessType='initializeOnly'/>
 48                                <IS>
 49                                     <connect nodeField='descriptionprotoField='description'/>
 50                                     <connect nodeField='delayCompleteTimeprotoField='delayCompleteTime'/>
 51                                     <connect nodeField='traceEnabledprotoField='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 shows event connections.
-->

<!-- to top Index for DEF nodes: TimeDelayClock, TimeDelayScript

Index for ProtoDeclare definition: TimeDelaySensor
-->
X3D Tooltips element index: Anchor, Appearance, connect, field, FontStyle, Group, head, IS, Material, meta, ProtoBody, ProtoDeclare, ProtoInterface, ROUTE, Scene, Script, Shape, Text, TimeSensor, WorldInfo, X3D, accessType and type, XML data types, field types

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

ROUTE
event to
(1)
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. 


Anchor
description='TimeDelaySensor Example' 
User-interaction hint for this node. 
Additional guidance on X3D animation can be found in the 10-Step Animation Design Process and Event Tracing hint sheets. Have fun with X3D! 😀

-->
<!-- Online at
https://savage.nps.edu/Savage/Tools/Animation/TimeDelaySensorPrototypeIndex.html -->
<!-- Version control at
https://gitlab.nps.edu/Savage/Savage/Tools/Animation/TimeDelaySensorPrototype.x3d -->

<!-- Color legend: X3D terminology <X3dNode  DEF='idNamefield='value'/> matches XML terminology <XmlElement  DEF='idNameattribute='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> -->

to top <!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints. -->