X3D Model Documentation: DoubleClickTouchSensorPrototype.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='DoubleClickTouchSensorPrototype.x3d'/>
  6            <meta name='descriptioncontent='Double-click TouchSensor design pattern, implemented as a reusable prototype node.'/>
  7            <meta name='creatorcontent='Don Brutzman'/>
  8            <meta name='createdcontent='26 May 2004'/>
  9            <meta name='modifiedcontent='6 June 2020'/>
 10            <meta name='referencecontent='DoubleClickTouchSensorExample.x3d'/>
 11            <meta name='referencecontent='https://www.web3d.org/x3d/specifications/ISO-IEC-19775-FDIS-X3dAbstractSpecification/Part01/components/pointingsensor.html#TouchSensor'/>
 12            <meta name='subjectcontent='DoubleClickTouchSensor'/>
 13            <meta name='identifiercontent='https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototype.x3d'/>
 14            <meta name='generatorcontent='X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit'/>
 15            <meta name='licensecontent='../../license.html'/>
 16       </head>
<!--

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

<!-- to top Index for DEF nodes: DoubleClickTouchScript, MetadataHolder, TouchSensorNode

Index for ProtoDeclare definition: DoubleClickTouchSensor
-->
 17       <Scene>
 18            <WorldInfo title='DoubleClickTouchSensorPrototype.x3d'/>
 19            <ProtoDeclare name='DoubleClickTouchSensorappinfo='DoubleClickTouchSensor functionality activates when user double clicks (or double selects) within maxDelayInterval'>
 20                 <ProtoInterface>
 21                      <field name='descriptiontype='SFStringaccessType='inputOutput'
                     appinfo='describe the purpose of this sensor'/>
 22                      <field name='maxDelayIntervaltype='SFTimevalue='0.5accessType='initializeOnly'
                     appinfo='seconds'/>
 23                      <field name='enabledtype='SFBoolvalue='trueaccessType='inputOutput'/>
 24                      <field name='isActivetype='SFBoolaccessType='outputOnly'/>
 25                      <field name='isOvertype='SFBoolaccessType='outputOnly'/>
 26                      <field name='touchTimetype='SFTimeaccessType='outputOnly'
                     appinfo='seconds'/>
 27                      <field name='hitPoint_changedtype='SFVec3faccessType='outputOnly'/>
 28                      <field name='hitNormal_changedtype='SFVec3faccessType='outputOnly'/>
 29                      <field name='hitTexCoord_changedtype='SFVec2faccessType='outputOnly'/>
 30                      <field name='metadatatype='SFNodeaccessType='initializeOnly'
                     appinfo='can contain one of Metadata nodes'>
 31                           <!-- initialization node (if any) goes here -->
 32                      </field>
 33                      <field name='traceEnabledtype='SFBoolvalue='falseaccessType='initializeOnly'/>
 34                 </ProtoInterface>
 35                 <ProtoBody>
 36 
                    <!-- TouchSensor TouchSensorNode is a DEF node that has 1 USE node: USE_1
                    <!-- ROUTE information for TouchSensorNode node:  [from isActive to DoubleClickTouchScript.checkClicks ] -->
                    <TouchSensor DEF='TouchSensorNode'>
 37                           <IS>
 38                                <connect nodeField='descriptionprotoField='description'/>
 39                                <connect nodeField='enabledprotoField='enabled'/>
 40                                <connect nodeField='isOverprotoField='isOver'/>
 41                           </IS>
 42                      </TouchSensor>
 43                      <!-- Only first node inside a ProtoBody is rendered. TouchSensor must remain outside Group to be externally active. -->
 44                      <Group>
 45 
                         <!-- ROUTE information for DoubleClickTouchScript node:  [from TouchSensorNode.isActive to checkClicks ] -->
                         <Script DEF='DoubleClickTouchScriptdirectOutput='true'>
 46                                <field name='descriptiontype='SFStringaccessType='inputOutput'/>
 47                                <field name='checkClickstype='SFBoolaccessType='inputOnly'/>
 48                                <field name='maxDelayIntervaltype='SFTimeaccessType='initializeOnly'
                               appinfo='seconds'/>
 49                                <field name='priorTouchTimetype='SFTimevalue='-1accessType='initializeOnly'/>
 50                                <field name='currentTouchTimetype='SFTimevalue='-1accessType='initializeOnly'/>
 51                                <field name='touchSensortype='SFNodeaccessType='initializeOnly'
                               appinfo='permits controlled access to various TouchSensorNode fields'>
 52                                     <TouchSensor USE='TouchSensorNode'/>
 53                                </field>
 54                                <field name='isActivetype='SFBoolaccessType='outputOnly'/>
 55                                <field name='touchTimetype='SFTimeaccessType='outputOnly'
                               appinfo='seconds'/>
 56                                <field name='hitPoint_changedtype='SFVec3faccessType='outputOnly'/>
 57                                <field name='hitNormal_changedtype='SFVec3faccessType='outputOnly'/>
 58                                <field name='hitTexCoord_changedtype='SFVec2faccessType='outputOnly'/>
 59                                <field name='traceEnabledtype='SFBoolaccessType='initializeOnly'/>
 60                                <IS>
 61                                     <connect nodeField='descriptionprotoField='description'/>
 62                                     <connect nodeField='maxDelayIntervalprotoField='maxDelayInterval'/>
 63                                     <connect nodeField='isActiveprotoField='isActive'/>
 64                                     <connect nodeField='touchTimeprotoField='touchTime'/>
 65                                     <connect nodeField='hitPoint_changedprotoField='hitPoint_changed'/>
 66                                     <connect nodeField='hitNormal_changedprotoField='hitNormal_changed'/>
 67                                     <connect nodeField='hitTexCoord_changedprotoField='hitTexCoord_changed'/>
 68                                     <connect nodeField='traceEnabledprotoField='traceEnabled'/>
 69                                </IS>
  <![CDATA[
            
ecmascript:

//  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);
}

          
]]>
 71                           </Script>
 72                           < ROUTE  fromNode='TouchSensorNode' fromField='isActive' toNode='DoubleClickTouchScript' toField='checkClicks'/>
 73                           <Collision DEF='MetadataHolderenabled='false'>
 74                                <IS>
 75                                     <connect nodeField='proxyprotoField='metadata'/>
 76                                </IS>
 77                           </Collision>
 78                      </Group>
 79                 </ProtoBody>
 80            </ProtoDeclare>
 81            <!-- ====================================== -->
 82            <!-- Example use -->
 83            <Anchor description='DoubleClickTouchSensor Exampleparameter='"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" '>
 84                 <Shape>
 85                      <Text string='"DoubleClickTouchSensorPrototype" "defines a prototype" "" "Click text to see" "DoubleClickTouchSensorExample scene"'>
 86                           <FontStyle justify='"MIDDLE" "MIDDLE"size='0.7'/>
 87                      </Text>
 88                      <Appearance>
 89                           <Material diffuseColor='1 1 0.2'/>
 90                      </Appearance>
 91                 </Shape>
 92            </Anchor>
 93       </Scene>
 94  </X3D>
<!--

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

<!-- to top Index for DEF nodes: DoubleClickTouchScript, MetadataHolder, TouchSensorNode

Index for ProtoDeclare definition: DoubleClickTouchSensor
-->
X3D Tooltips element index: Anchor, Appearance, Collision, connect, field, FontStyle, Group, head, IS, Material, meta, ProtoBody, ProtoDeclare, ProtoInterface, ROUTE, Scene, Script, Shape, Text, TouchSensor, 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.

TouchSensorNode
TouchSensor
isActive
SFBool

ROUTE
event to
(1)
DoubleClickTouchScript
Script
checkClicks
SFBool

      DoubleClickTouchScript
Script
No ROUTE connection found for output events from this node.
Contains SFNode field with direct access to another node. 


Anchor
description='DoubleClickTouchSensor 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/DoubleClickTouchSensorPrototypeIndex.html -->
<!-- Version control at
https://gitlab.nps.edu/Savage/Savage/Tools/Animation/DoubleClickTouchSensorPrototype.x3d -->

<!-- Color 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> -->

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