X3D Model Documentation: ArbitraryAxisCylinderSensorPrototype.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='title' content='ArbitraryAxisCylinderSensorPrototype.x3d'/>
  6            <meta name='description' content="Modified CylinderSensor oriented about an arbitrary axis, relative to peer/child geometry that remains oriented to its original axis. Originally authored by Don Brutzman's MV4204 class, with modifications by Maj James Breitinger USMC to include min/max angles of rotation and object center. Motivation: Modify example shown by Chapter 9 Figure 7 to build a PROTO for a CylinderSensor oriented about an arbitrary axis."/>
  7            <meta name='info' content='ArbitraryAxisCylinderSensor operates on its children, NOT on its peers. This variation is necessary in order to accomplish the desired Transform rotation to a new orientation axis.'/>
  8            <meta name='creator' content='Don Brutzman'/>
  9            <meta name='created' content='1 October 1998'/>
 10            <meta name='modified' content='28 November 2019'/>
 11            <meta name='reference' content='ArbitraryAxisCylinderSensorExamples.x3d'/>
 12            <meta name='reference' content='ArbitraryAxisCylinderSensorPrototypeOriginal.wrl'/>
 13            <meta name='identifier' content='https://savage.nps.edu/Savage/Tools/Animation/ArbitraryAxisCylinderSensorPrototype.x3d'/>
 14            <meta name='reference' content='The VRML 2.0 Sourcebook (Copyright 1997 By Andrea L. Ames, David R. Nadeau, and John L. Moreland)'/>
 15            <meta name='generator' content='X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit'/>
 16            <meta name='license' content='../../license.html'/>
 17       </head>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->
<!-- to top Index for DEF nodes: ArbitraryAxisTransform, CylinderSensorRotationTransform, HideSensorShapeScript, NegationScript, RestorationTransform, RotatedCylinderSensor, ScaleSensorShape, ScaleSensorSwitch, SelectionAssist, SensorShapeAppearance, SensorShapeMaterial

Index for Viewpoint node: Viewpoint_1

Index for ProtoDeclare definition: ArbitraryAxisCylinderSensor
-->
 18       <Scene>
 19            <WorldInfo title='ArbitraryAxisCylinderSensorPrototype.x3d'/>
 20            <ProtoDeclare name='ArbitraryAxisCylinderSensor' appinfo='Modified CylinderSensor with children nodes oriented about an arbitrary axis. Warning: ArbitraryAxisCylinderSensor affects children, not peers.'>
 21                 <ProtoInterface>
 22                      <!-- All default fields and events of a regular CylinderSensor are exposed without modification. -->
 23                      <!-- Transparent viewing-assist geometry shows orientation and cylindrical mapping of mouse movements by sensor. Since viewCylinderSensorShape connects to a Script, it is a initialize-time field instead of a run-time exposedField. -->
 24                      <field name='shiftRotationAxis' type='SFRotation' value='1 0 0 0' accessType='initializeOnly'
                     appinfo='shifted axis of rotation from local vertical, default 1 0 0 0'/>
 25                      <field name='center' type='SFVec3f' value='0 0 0' accessType='initializeOnly'
                     appinfo='local center for axis of rotation, default 0 0 0'/>
 26                      <field name='showCylinderSensorShape' type='SFBool' value='true' accessType='initializeOnly'
                     appinfo='whether to show visualization shape to show orientation and cylindrical mapping of mouse movements by sensor, default true'/>
 27                      <field name='scaleCylinderSensorShape' type='SFVec3f' value='1 1 1' accessType='inputOutput'
                     appinfo='scale for visualization shape, default 1 1 1'/>
 28                      <field name='colorCylinderSensorShape' type='SFColor' value='0.9 0.9 0.4' accessType='inputOutput'
                     appinfo='color for visualization shape, default 0.9 0.9 0.4'/>
 29                      <field name='transparencyCylinderSensorShape' type='SFFloat' value='0.8' accessType='inputOutput'
                     appinfo='transparency for visualization shape'/>
 30                      <field name='children' type='MFNode' accessType='inputOutput'
                     appinfo='children nodes affected by ArbitraryAxisCylinderSensor'>
 31                           <!-- initialization nodes (if any) go here -->
 32                      </field>
 33                      <field name='autoOffset' type='SFBool' value='true' accessType='inputOutput'
                     appinfo='determines whether previous offset values are remembered/accumulated, default true'/>
 34                      <field name='description' type='SFString' value='Select and drag to rotate ArbitraryAxisCylinderSensor' accessType='inputOutput'
                     appinfo='Text tooltip displayed for user interaction'/>
 35                      <field name='diskAngle' type='SFFloat' value='0.262' accessType='inputOutput'
                     appinfo='diskAngle 0 forces disk-like behavior, diskAngle 1.57 (90 degrees) forces cylinder-like behavior, default 0.262, range [0,pi/2]'/>
 36                      <field name='enabled' type='SFBool' value='true' accessType='inputOutput'
                     appinfo='enables/disables node operation, default true'/>
 37                      <field name='minAngle' type='SFFloat' value='0' accessType='inputOutput'
                     appinfo='clamps rotation_changed events, default 0, range [-2pi,2pi]'/>
 38                      <field name='maxAngle' type='SFFloat' value='-1' accessType='inputOutput'
                     appinfo='clamps rotation_changed events, default -1, range [-2pi,2pi]'/>
 39                      <field name='offset' type='SFFloat' value='0' accessType='initializeOnly'
                     appinfo='sends event and remembers last value sensed, default 0, range (-infinity,infinity)'/>
 40                      <field name='isActive' type='SFBool' accessType='outputOnly'
                     appinfo='output event isActive=true when primary mouse button is pressed, output event isActive=false when released.'/>
 41                      <field name='rotation_changed' type='SFRotation' accessType='outputOnly'
                     appinfo='rotation_changed events equal sum of relative bearing changes plus offset value about Y-axis in local coordinate system'/>
 42                      <field name='trackPoint_changed' type='SFVec3f' accessType='outputOnly'
                     appinfo="trackPoint_changed events give intersection point of bearing with sensor's virtual geometry"/>
 43                 </ProtoInterface>
 44                 <ProtoBody>
 45                      <!-- Prototype body follows. First rotate local frame about center to axis of interest, then perform the rotation about the desired center. -->
 46                      <Transform DEF='ArbitraryAxisTransform'>
 47                           <IS>
 48                                <connect nodeField='rotation' protoField='shiftRotationAxis'/>
 49                                <connect nodeField='center' protoField='center'/>
 50                           </IS>
 51 
                         <!-- ROUTE information for RotatedCylinderSensor node:  [from rotation_changed to CylinderSensorRotationTransform.set_rotation ] -->
                         <CylinderSensor DEF='RotatedCylinderSensor'>
 52                                <IS>
 53                                     <connect nodeField='autoOffset' protoField='autoOffset'/>
 54                                     <connect nodeField='description' protoField='description'/>
 55                                     <connect nodeField='diskAngle' protoField='diskAngle'/>
 56                                     <connect nodeField='enabled' protoField='enabled'/>
 57                                     <connect nodeField='minAngle' protoField='minAngle'/>
 58                                     <connect nodeField='maxAngle' protoField='maxAngle'/>
 59                                     <connect nodeField='offset' protoField='offset'/>
 60                                     <connect nodeField='isActive' protoField='isActive'/>
 61                                     <connect nodeField='rotation_changed' protoField='rotation_changed'/>
 62                                     <connect nodeField='trackPoint_changed' protoField='trackPoint_changed'/>
 63                                </IS>
 64                           </CylinderSensor>
 65                           <!-- CylinderSensorRotationTransform rotation value is overridden by RotatedCylinderSensor, so leave it alone! -->
 66 
                         <!-- Transform CylinderSensorRotationTransform is a DEF node that has 1 USE node: USE_1
                         <!-- ROUTE information for CylinderSensorRotationTransform node:  [from RotatedCylinderSensor.rotation_changed to set_rotation ] -->
                         <Transform DEF='CylinderSensorRotationTransform'>
 67                                <!-- ROUTEd rotation to RestorationTransform negates (and offsets) arbitrary-axis rotation in RestorationTransform, so children geometry is returned to original orientation. -->
 68                                <!-- Perform the rotation about the same center. -->
 69 
                              <!-- ROUTE information for RestorationTransform node:  [from NegationScript.rotationRestore to rotation ] -->
                              <Transform DEF='RestorationTransform'>
 70                                     <IS>
 71                                          <connect nodeField='center' protoField='center'/>
 72                                          <connect nodeField='children' protoField='children'/>
 73                                     </IS>
 74                                </Transform>
 75                                <!-- Prototype children field finally appears above... -->
 76 
                              <!-- ROUTE information for ScaleSensorSwitch node:  [from HideSensorShapeScript.choiceScaleSensor to whichChoice ] -->
                              <Switch DEF='ScaleSensorSwitch' whichChoice='0'>
 77                                     <Transform DEF='ScaleSensorShape'>
 78                                          <IS>
 79                                               <connect nodeField='scale' protoField='scaleCylinderSensorShape'/>
 80                                          </IS>
 81                                          <Shape>
 82                                               <Cylinder height='2.5' radius='0.1'/>
 83 
                                             <!-- Appearance SensorShapeAppearance is a DEF node that has 1 USE node: USE_1 -->
                                             <Appearance DEF='SensorShapeAppearance'>
 84                                                    <Material DEF='SensorShapeMaterial'>
 85                                                         <IS>
 86                                                              <connect nodeField='diffuseColor' protoField='colorCylinderSensorShape'/>
 87                                                              <connect nodeField='transparency' protoField='transparencyCylinderSensorShape'/>
 88                                                         </IS>
 89                                                    </Material>
 90                                               </Appearance>
 91                                          </Shape>
 92                                          <Shape>
 93                                               <Cylinder height='0.2' radius='1.5'/>
 94                                               <Appearance USE='SensorShapeAppearance'/>
 95                                          </Shape>
 96                                     </Transform>
 97                                </Switch>
 98                           </Transform>
 99 
                         <!-- ROUTE information for NegationScript node:  [from rotationRestore to RestorationTransform.rotation ] -->
                         <Script DEF='NegationScript' directOutput='true'>
100                                <field name='shiftRotationAxis' type='SFRotation' accessType='initializeOnly'/>
101                                <field name='offset' type='SFFloat' accessType='initializeOnly'/>
102                                <field name='rotationRestore' type='SFRotation' accessType='outputOnly'/>
103                                <field name='CylinderSensorRotationTransform' type='SFNode' accessType='initializeOnly'>
104                                     <Transform USE='CylinderSensorRotationTransform'/>
105                                </field>
106                                <!-- local variables -->
107                                <field name='rotationOffset' type='SFRotation' value='0 1 0 0' accessType='initializeOnly'/>
108                                <field name='rotationIntermediate' type='SFRotation' value='0 1 0 0' accessType='initializeOnly'/>
109                                <IS>
110                                     <connect nodeField='offset' protoField='offset'/>
111                                     <connect nodeField='shiftRotationAxis' protoField='shiftRotationAxis'/>
112                                </IS>
  <![CDATA[
            
ecmascript:

function initialize () {
	rotationOffset = new SFRotation (0, 1, 0, offset);  // establish initial angle
	CylinderSensorRotationTransform.rotation =
	   CylinderSensorRotationTransform.rotation.multiply (rotationOffset);
	rotationIntermediate = shiftRotationAxis;
	rotationIntermediate = rotationIntermediate.inverse ();
	rotationRestore = rotationIntermediate;
	Browser.println ('   rotationOffset=' +    rotationOffset.toString());
	Browser.println ('shiftRotationAxis=' + shiftRotationAxis.toString());
	Browser.println ('  rotationRestore=' +   rotationRestore.toString());
}

          
]]>
114                           </Script>
115 
                         <!-- ROUTE information for HideSensorShapeScript node:  [from choiceScaleSensor to ScaleSensorSwitch.whichChoice ] -->
                         <Script DEF='HideSensorShapeScript'>
116                                <field name='showCylinderSensorShape' type='SFBool' accessType='initializeOnly'/>
117                                <field name='choiceScaleSensor' type='SFInt32' accessType='outputOnly'/>
118                                <IS>
119                                     <connect nodeField='showCylinderSensorShape' protoField='showCylinderSensorShape'/>
120                                </IS>
  <![CDATA[
            
ecmascript:

function initialize () {
	if (showCylinderSensorShape == true)
		choiceScaleSensor =  0;
	else	choiceScaleSensor = -1;
}

          
]]>
122                           </Script>
123                      </Transform>
124                      < ROUTE  fromNode='RotatedCylinderSensor' fromField='rotation_changed' toNode='CylinderSensorRotationTransform' toField='set_rotation'/>
125                      < ROUTE  fromNode='NegationScript' fromField='rotationRestore' toNode='RestorationTransform' toField='rotation'/>
126                      < ROUTE  fromNode='HideSensorShapeScript' fromField='choiceScaleSensor' toNode='ScaleSensorSwitch' toField='whichChoice'/>
127                      <!-- Add any ROUTEs here, going from Script to other nodes in ProtoBody -->
128                 </ProtoBody>
129            </ProtoDeclare>
130            <!-- Example use of this prototype is in ArbitraryAxisCylinderSensorExample.x3d, .wrl -->
131            <Viewpoint description='click message to view example' position='0 0 8'/>
132            <!-- Redirection text in case a user examines this PROTO file via a 3D browser: -->
133            <Anchor description='Touch text for example'   url=' "ArbitraryAxisCylinderSensorExamples.x3d" "https://savage.nps.edu/Savage/Tools/Animation/ArbitraryAxisCylinderSensorExamples.x3d" "ArbitraryAxisCylinderSensorExamples.wrl" "https://savage.nps.edu/Savage/Tools/Animation/ArbitraryAxisCylinderSensorExamples.wrl" '>
134                 <Shape>
135                      <Appearance>
136                           <Material diffuseColor='0 1 1' emissiveColor='0 1 1'/>
137                      </Appearance>
138                      <Text string='"ArbitraryAxisCylinderSensorPrototype" "is a Prototype (PROTO) definition file." "" "To see an example scene using this new node" "click this text and view" "ArbitraryAxisCylinderSensorExample"'>
139                           <FontStyle justify='"MIDDLE" "MIDDLE"' size='0.5'/>
140                      </Text>
141                 </Shape>
142                 <Shape DEF='SelectionAssist'>
143                      <Box size='9 4 .001'/>
144                      <Appearance>
145                           <Material transparency='0.9'/>
146                      </Appearance>
147                 </Shape>
148            </Anchor>
149       </Scene>
150  </X3D>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->
<!-- to top Index for DEF nodes: ArbitraryAxisTransform, CylinderSensorRotationTransform, HideSensorShapeScript, NegationScript, RestorationTransform, RotatedCylinderSensor, ScaleSensorShape, ScaleSensorSwitch, SelectionAssist, SensorShapeAppearance, SensorShapeMaterial

Index for Viewpoint node: Viewpoint_1

Index for ProtoDeclare definition: ArbitraryAxisCylinderSensor
-->
X3D Tooltips element index: Anchor, Appearance, Box, connect, Cylinder, CylinderSensor, field, FontStyle, head, IS, Material, meta, ProtoBody, ProtoDeclare, ProtoInterface, ROUTE, Scene, Script, Shape, Switch, Text, Transform, Viewpoint, WorldInfo, X3D, plus documentation for accessType definitions, type definitions, XML data types, and field types

Event Graph ROUTE Table entries with 3 ROUTE connections 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.

HideSensorShapeScript
Script
choiceScaleSensor
SFInt32
→
ROUTE
event to
(1)
ScaleSensorSwitch
Switch
whichChoice
SFInt32

NegationScript
Script
rotationRestore
SFRotation
→
ROUTE
event to
(1)
RestorationTransform
Transform
rotation
SFRotation

RotatedCylinderSensor
CylinderSensor
rotation_changed
SFRotation
→
ROUTE
event to
(1)
CylinderSensorRotationTransform
Transform
set_rotation
SFRotation

line 133
Anchor
description='Touch text for 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/ArbitraryAxisCylinderSensorPrototypeIndex.html -->
<!-- Version control at
https://gitlab.nps.edu/Savage/Savage/Tools/Animation/ArbitraryAxisCylinderSensorPrototype.x3d -->

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

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