| 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=' DoubleClickTouchSensorPrototype.x3d '/> |
| 6 | <meta name='description' content='Double-click TouchSensor design pattern, implemented as a reusable prototype node.'/> |
| 7 | <meta name='creator' content='Don Brutzman'/> |
| 8 | <meta name='created' content='26 May 2004'/> |
| 9 | <meta name='modified' content='6 June 2020'/> |
| 10 | <meta name='reference' content=' DoubleClickTouchSensorExample.x3d '/> |
| 11 | <meta name='reference' content='https://www.web3d.org/x3d/specifications/ISO-IEC-19775-FDIS-X3dAbstractSpecification/Part01/components/pointingsensor.html#TouchSensor'/> |
| 12 | <meta name='subject' content='DoubleClickTouchSensor'/> |
| 13 | <meta name='identifier' content=' https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/DoubleClickTouchSensorPrototype.x3d '/> |
| 14 | <meta name='generator' content='X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit'/> |
| 15 | <meta name='license' content='../../license.html'/> |
| 16 | </head> |
| 17 | <Scene> |
| 18 | <WorldInfo title='DoubleClickTouchSensorPrototype.x3d'/> |
| 19 | <ProtoDeclare name='DoubleClickTouchSensor' appinfo='DoubleClickTouchSensor functionality activates when user double clicks (or double selects) within maxDelayInterval'> |
| 20 | <ProtoInterface> |
| 21 |
<field name='description' type='SFString' accessType='inputOutput'
appinfo='describe the purpose of this sensor'/> |
| 22 |
<field name='maxDelayInterval' type='SFTime' value='0.5' accessType='initializeOnly'
appinfo='seconds'/> |
| 23 | <field name='enabled' type='SFBool' value='true' accessType='inputOutput'/> |
| 24 | <field name='isActive' type='SFBool' accessType='outputOnly'/> |
| 25 | <field name='isOver' type='SFBool' accessType='outputOnly'/> |
| 26 |
<field name='touchTime' type='SFTime' accessType='outputOnly'
appinfo='seconds'/> |
| 27 | <field name='hitPoint_changed' type='SFVec3f' accessType='outputOnly'/> |
| 28 | <field name='hitNormal_changed' type='SFVec3f' accessType='outputOnly'/> |
| 29 | <field name='hitTexCoord_changed' type='SFVec2f' accessType='outputOnly'/> |
| 30 |
<field name='metadata' type='SFNode' accessType='initializeOnly'
appinfo='can contain one of Metadata nodes'> |
| 31 | <!-- initialization node (if any) goes here --> |
| 32 | </field> |
| 33 | <field name='traceEnabled' type='SFBool' value='false' accessType='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='description' protoField='description'/> |
| 39 | <connect nodeField='enabled' protoField='enabled'/> |
| 40 | <connect nodeField='isOver' protoField='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='DoubleClickTouchScript' directOutput='true'> |
| 46 | <field name='description' type='SFString' accessType='inputOutput'/> |
| 47 | <field name='checkClicks' type='SFBool' accessType='inputOnly'/> |
| 48 |
<field name='maxDelayInterval' type='SFTime' accessType='initializeOnly'
appinfo='seconds'/> |
| 49 | <field name='priorTouchTime' type='SFTime' value='-1' accessType='initializeOnly'/> |
| 50 | <field name='currentTouchTime' type='SFTime' value='-1' accessType='initializeOnly'/> |
| 51 |
<field name='touchSensor' type='SFNode' accessType='initializeOnly'
appinfo='permits controlled access to various TouchSensorNode fields'> |
| 52 | <TouchSensor USE='TouchSensorNode'/> |
| 53 | </field> |
| 54 | <field name='isActive' type='SFBool' accessType='outputOnly'/> |
| 55 |
<field name='touchTime' type='SFTime' accessType='outputOnly'
appinfo='seconds'/> |
| 56 | <field name='hitPoint_changed' type='SFVec3f' accessType='outputOnly'/> |
| 57 | <field name='hitNormal_changed' type='SFVec3f' accessType='outputOnly'/> |
| 58 | <field name='hitTexCoord_changed' type='SFVec2f' accessType='outputOnly'/> |
| 59 | <field name='traceEnabled' type='SFBool' accessType='initializeOnly'/> |
| 60 | <IS> |
| 61 | <connect nodeField='description' protoField='description'/> |
| 62 | <connect nodeField='maxDelayInterval' protoField='maxDelayInterval'/> |
| 63 | <connect nodeField='isActive' protoField='isActive'/> |
| 64 | <connect nodeField='touchTime' protoField='touchTime'/> |
| 65 | <connect nodeField='hitPoint_changed' protoField='hitPoint_changed'/> |
| 66 | <connect nodeField='hitNormal_changed' protoField='hitNormal_changed'/> |
| 67 | <connect nodeField='hitTexCoord_changed' protoField='hitTexCoord_changed'/> |
| 68 | <connect nodeField='traceEnabled' protoField='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='MetadataHolder' enabled='false'> |
| 74 | <IS> |
| 75 | <connect nodeField='proxy' protoField='metadata'/> |
| 76 | </IS> |
| 77 | </Collision> |
| 78 | </Group> |
| 79 | </ProtoBody> |
| 80 | </ProtoDeclare> |
| 81 | <!-- ====================================== --> |
| 82 | <!-- Example use --> |
| 83 | <Anchor description='DoubleClickTouchSensor Example' parameter='"target=_blank"' url=' "DoubleClickTouchSensorExample.x3d" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/DoubleClickTouchSensorExample.x3d" "DoubleClickTouchSensorExample.wrl" "https://www.web3d.org/x3d/content/examples/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 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 |
DoubleClickTouchScript
Script checkClicks SFBool |
|
DoubleClickTouchScript
Script |
No direct ROUTE connection found for events to/from this node. Contains SFNode field with direct access to another node. |
| line 83
Anchor |
description='DoubleClickTouchSensor 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.
-->