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=' SliderIntegerPrototype.x3d '/> |
6 | <meta name='description' content='A Slider prototype enabling mouse input where integer output values are needed. Size, min/max values and color are defined by the author.'/> |
7 | <meta name='creator' content='Mike Hunsberger, Jane Wu'/> |
8 | <meta name='created' content='3 August 2001'/> |
9 | <meta name='modified' content='28 November 2019'/> |
10 | <meta name='subject' content='animation slider'/> |
11 | <meta name='identifier' content=' https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/SliderIntegerPrototype.x3d '/> |
12 | <meta name='generator' content='X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit'/> |
13 | <meta name='license' content='../../license.html'/> |
14 | </head> |
15 | <Scene> |
16 | <WorldInfo title='SliderIntegerPrototype.x3d'/> |
17 | <ProtoDeclare name='SliderInteger' appinfo='Slider user-interface widget that produces integer output values'> |
18 | <ProtoInterface> |
19 |
<field name='layoutDirection' type='SFString' value='vertical' accessType='initializeOnly'
appinfo='Allowed values: vertical, horizontal'/> |
20 |
<field name='height' type='SFFloat' value='1.0' accessType='initializeOnly'
appinfo='default value 1.0'/> |
21 |
<field name='radius' type='SFFloat' value='0.1' accessType='initializeOnly'
appinfo='default value 0.1'/> |
22 |
<field name='barRadius' type='SFFloat' value='0.02' accessType='initializeOnly'
appinfo='default value 0.02'/> |
23 |
<field name='sliderBarColor' type='SFColor' value='.8 .4 .8' accessType='initializeOnly'
appinfo='default value .8 .4 .8'/> |
24 |
<field name='sliderBallColor' type='SFColor' value='.3 .4 .8' accessType='initializeOnly'
appinfo='default value .3 .4 .8'/> |
25 |
<field name='sliderEndColor' type='SFColor' value='.2 .3 .9' accessType='initializeOnly'
appinfo='default value .2 .3 .9'/> |
26 |
<field name='min' type='SFInt32' value='0' accessType='initializeOnly'
appinfo='default value 0'/> |
27 |
<field name='max' type='SFInt32' value='10' accessType='initializeOnly'
appinfo='default value 10'/> |
28 |
<field name='value' type='SFInt32' value='0' accessType='initializeOnly'
appinfo='default value 0'/> |
29 |
<field name='setMin' type='SFInt32' accessType='inputOnly'
appinfo='set minimum value for slider bar'/> |
30 |
<field name='setMax' type='SFInt32' accessType='inputOnly'
appinfo='set maximum value for slider bar'/> |
31 |
<field name='setValue' type='SFInt32' accessType='inputOnly'
appinfo='set value for slider bar'/> |
32 |
<field name='valueChanged' type='SFInt32' accessType='outputOnly'
appinfo='output value for slider bar'/> |
33 |
<field name='traceEnabled' type='SFBool' value='false' accessType='initializeOnly'
appinfo='Enable/disable console output for troubleshooting'/> |
34 | </ProtoInterface> |
35 | <ProtoBody> |
36 | <Group> |
37 |
<!-- ROUTE information for LayoutDirectionTransform node:
[from LayoutDirectionScript.directionRotation to set_rotation
]
-->
<Transform DEF='LayoutDirectionTransform'> |
38 | <Transform DEF='SliderBarTransform'> |
39 | <Shape> |
40 | <Appearance> |
41 | <Material DEF='SliderBarMaterial'> |
42 | <IS> |
43 | <connect nodeField='diffuseColor' protoField='sliderBarColor'/> |
44 | <connect nodeField='emissiveColor' protoField='sliderBarColor'/> |
45 | </IS> |
46 | </Material> |
47 | </Appearance> |
48 | <Cylinder DEF='SliderBar'> |
49 | <IS> |
50 | <connect nodeField='height' protoField='height'/> |
51 | <connect nodeField='radius' protoField='barRadius'/> |
52 | </IS> |
53 | </Cylinder> |
54 | </Shape> |
55 | </Transform> |
56 |
<!-- ROUTE information for SliderBallTransform node:
[from SliderScript.ballPositionChanged to set_translation
]
-->
<Transform DEF='SliderBallTransform'> |
57 |
<!-- ROUTE information for SliderBallPlaneSensor node:
[from SliderScript.minBallPositionChanged to set_minPosition
]
[from SliderScript.maxBallPositionChanged to set_maxPosition
]
[from isActive to SliderScript.setDragActive
]
[from translation_changed to SliderScript.setBallPosition
]
-->
<PlaneSensor DEF='SliderBallPlaneSensor' description='select and drag to change values'/> |
58 | <Shape> |
59 | <Appearance> |
60 | <Material DEF='SliderBallMaterial'> |
61 | <IS> |
62 | <connect nodeField='diffuseColor' protoField='sliderBallColor'/> |
63 | </IS> |
64 | </Material> |
65 | </Appearance> |
66 | <Sphere DEF='SliderBall'> |
67 | <IS> |
68 | <connect nodeField='radius' protoField='radius'/> |
69 | </IS> |
70 | </Sphere> |
71 | </Shape> |
72 | </Transform> |
73 |
<!-- ROUTE information for BottomEndTransform node:
[from SliderScript.bottomEndPositionChanged to set_translation
]
-->
<Transform DEF='BottomEndTransform'> |
74 |
<!-- ROUTE information for BottomEndSensor node:
[from isActive to SliderScript.bottomEndTouched
]
-->
<TouchSensor DEF='BottomEndSensor' description='touch bottom end to decrement'/> |
75 | |
76 | <Appearance> |
77 | <Material DEF='EndMaterial'> |
78 | <IS> |
79 | <connect nodeField='diffuseColor' protoField='sliderEndColor'/> |
80 | </IS> |
81 | </Material> |
82 | </Appearance> |
83 | <Cylinder height='.05' radius='.1'/> |
84 | </Shape> |
85 | <Transform translation='0 -0.1 0'> |
86 |
<!-- Shape
TransparentEndShape is a DEF node that has 1 USE node: USE_1 -->
<Shape DEF='TransparentEndShape'> |
87 | <Appearance> |
88 | <Material transparency='1'/> |
89 | </Appearance> |
90 | <Box size='0.2 0.2 0.01'/> |
91 | </Shape> |
92 | </Transform> |
93 | </Transform> |
94 |
<!-- ROUTE information for TopEndTransform node:
[from SliderScript.topEndPositionChanged to set_translation
]
-->
<Transform DEF='TopEndTransform'> |
95 |
<!-- ROUTE information for TopEndSensor node:
[from isActive to SliderScript.topEndTouched
]
-->
<TouchSensor DEF='TopEndSensor' description='touch top end to increment'/> |
96 | <Shape USE='EndShape'/> |
97 | <Transform translation='0 0.1 0'> |
98 | <Shape USE='TransparentEndShape'/> |
99 | </Transform> |
100 | </Transform> |
101 |
<!-- ROUTE information for SliderScript node:
[from SliderBallPlaneSensor.isActive to setDragActive
]
[from SliderBallPlaneSensor.translation_changed to setBallPosition
]
[from BottomEndSensor.isActive to bottomEndTouched
]
[from TopEndSensor.isActive to topEndTouched
]
[from minBallPositionChanged to SliderBallPlaneSensor.set_minPosition
]
[from maxBallPositionChanged to SliderBallPlaneSensor.set_maxPosition
]
[from bottomEndPositionChanged to BottomEndTransform.set_translation
]
[from topEndPositionChanged to TopEndTransform.set_translation
]
[from ballPositionChanged to SliderBallTransform.set_translation
]
-->
<Script DEF='SliderScript'> |
102 | <field name='height' type='SFFloat' accessType='initializeOnly'/> |
103 | <field name='radius' type='SFFloat' accessType='initializeOnly'/> |
104 | <field name='min' type='SFInt32' accessType='initializeOnly'/> |
105 | <field name='max' type='SFInt32' accessType='initializeOnly'/> |
106 | <field name='value' type='SFInt32' accessType='initializeOnly'/> |
107 | <field name='dragActive' type='SFBool' value='false' accessType='initializeOnly'/> |
108 | <field name='lastBallPosition' type='SFVec3f' value='0 0 0' accessType='initializeOnly'/> |
109 | <field name='beginPosition' type='SFVec3f' value='0 0 0' accessType='initializeOnly'/> |
110 | <field name='endPosition' type='SFVec3f' value='0 0 0' accessType='initializeOnly'/> |
111 | <field name='incrementInterval' type='SFFloat' value='1' accessType='initializeOnly'/> |
112 | <field name='setMin' type='SFInt32' accessType='inputOnly'/> |
113 | <field name='setMax' type='SFInt32' accessType='inputOnly'/> |
114 | <field name='setValue' type='SFInt32' accessType='inputOnly'/> |
115 | <field name='valueChanged' type='SFInt32' accessType='outputOnly'/> |
116 | <field name='bottomEndTouched' type='SFBool' accessType='inputOnly'/> |
117 | <field name='topEndTouched' type='SFBool' accessType='inputOnly'/> |
118 | <field name='setBallPosition' type='SFVec3f' accessType='inputOnly'/> |
119 | <field name='setDragActive' type='SFBool' accessType='inputOnly'/> |
120 | <field name='bottomEndPositionChanged' type='SFVec3f' accessType='outputOnly'/> |
121 | <field name='topEndPositionChanged' type='SFVec3f' accessType='outputOnly'/> |
122 | <field name='ballPositionChanged' type='SFVec3f' accessType='outputOnly'/> |
123 | <field name='minBallPositionChanged' type='SFVec2f' accessType='outputOnly'/> |
124 | <field name='maxBallPositionChanged' type='SFVec2f' accessType='outputOnly'/> |
125 | <field name='traceEnabled' type='SFBool' accessType='initializeOnly'/> |
126 | <IS> |
127 | <connect nodeField='height' protoField='height'/> |
128 | <connect nodeField='radius' protoField='radius'/> |
129 | <connect nodeField='min' protoField='min'/> |
130 | <connect nodeField='max' protoField='max'/> |
131 | <connect nodeField='value' protoField='value'/> |
132 | <connect nodeField='setMin' protoField='setMin'/> |
133 | <connect nodeField='setMax' protoField='setMax'/> |
134 | <connect nodeField='setValue' protoField='setValue'/> |
135 | <connect nodeField='valueChanged' protoField='valueChanged'/> |
136 | <connect nodeField='traceEnabled' protoField='traceEnabled'/> |
137 | </IS> |
<![CDATA[
ecmascript: function initialize() { tracePrint('initialize() commenced...'); beginPosition = new SFVec3f(0, (height/2) * (-1) + radius, 0); endPosition = new SFVec3f(0, (height/2) - radius, 0); tracePrint('beginPosition=' + beginPosition.toString() + ', endPosition=' + endPosition.toString()); incrementInterval = (height - (2 * radius)) / (max - min); tracePrint('incrementInterval=' + incrementInterval.toString()); bottomEndPositionChanged = new SFVec3f(0, (height/2) * (-1), 0); topEndPositionChanged = new SFVec3f(0, (height/2), 0); tracePrint('bottomEndPositionChanged=' + bottomEndPositionChanged.toString() + ', topEndPositionChanged=' + topEndPositionChanged.toString()); minBallPositionChanged = new SFVec2f(0, bottomEndPositionChanged.y + radius); maxBallPositionChanged = new SFVec2f(0, topEndPositionChanged.y - radius); tracePrint('minBallPositionChanged=' + minBallPositionChanged.toString() + ', maxBallPositionChanged=' + maxBallPositionChanged.toString()); ballPositionChanged = new SFVec3f(0, beginPosition.y + (incrementInterval * (value - min)), 0); lastBallPosition = ballPositionChanged; if (value < min) value = min; if (value > max) value = max; valueChanged = value; tracePrint('value=' + value.toString()); tracePrint('...initialize() complete'); } function setDragActive(inputValue, timeStamp) { dragActive = inputValue; } function setMin(inputValue, timeStamp) { min = inputValue; if (value < min) value = min; incrementInterval = (height - (2 * radius)) / (max - min); tracePrint('incrementInterval=' + incrementInterval.toString()); ballPositionChanged = new SFVec3f(0, beginPosition.y + (incrementInterval * (value - min)), 0); lastBallPosition = ballPositionChanged; valueChanged = value; tracePrint('min=' + min + ', valueChanged=' + valueChanged); } function setMax(inputValue, timeStamp) { max = inputValue; if (value > max) value = max; incrementInterval = (height - (2 * radius)) / (max - min); ballPositionChanged = new SFVec3f(0, beginPosition.y + (incrementInterval * (value - min)), 0); lastBallPosition = ballPositionChanged; valueChanged = value; tracePrint('max=' + max + ', valueChanged=' + valueChanged); } function setValue(inputValue, timeStamp) { if (inputValue <= min) { valueChanged = value = min; ballPositionChanged = beginPosition; lastBallPosition = ballPositionChanged; } else if (inputValue >= max) { valueChanged = value = max; ballPositionChanged = endPosition; lastBallPosition = ballPositionChanged; } else { if (inputValue > value) //getting bigger { ballPositionChanged = new SFVec3f(0, lastBallPosition.y + (incrementInterval * (inputValue - value)), 0); lastBallPosition = ballPositionChanged; } else if (inputValue < value) //getting smaller { ballPositionChanged = new SFVec3f(0, lastBallPosition.y - (incrementInterval * (value - inputValue)), 0); lastBallPosition = ballPositionChanged; } valueChanged = value = inputValue; } } function bottomEndTouched(inputValue, timeStamp) { tracePrint('bottomEndTouched(' + inputValue.toString() + ')'); if (inputValue == false) return; // ignore deselection if (value > min) { valueChanged = --value; ballPositionChanged = new SFVec3f(0, lastBallPosition.y - incrementInterval, 0); lastBallPosition = ballPositionChanged; } } function topEndTouched(inputValue, timeStamp) { tracePrint('topEndTouched(' + inputValue.toString() + ')'); if (inputValue == false) return; // ignore deselection if (value < max) { valueChanged = ++value; ballPositionChanged = new SFVec3f(0, lastBallPosition.y + incrementInterval, 0); lastBallPosition = ballPositionChanged; } } function setBallPosition(inputValue, timeStamp) { tracePrint('setBallPosition(' + inputValue.toString() + '), dragActive=' + dragActive); // if (!dragActive) // return; if (inputValue.y > lastBallPosition.y) // moving upwards { if (inputValue.y >= (beginPosition.y + (incrementInterval * ((value + 1) - min)))) { if (value == max - 1) { value = max; lastBallPosition = endPosition; } else { value = value + 1; lastBallPosition = new SFVec3f(0, beginPosition.y + (incrementInterval * (value - min)), 0); } valueChanged = value; ballPositionChanged = lastBallPosition; } } else if (inputValue.y < lastBallPosition.y) // moving downwards { if (inputValue.y <= (endPosition.y - (incrementInterval * (max - (value - 1))))) { if (value == (min + 1)) { value = min; lastBallPosition = beginPosition; } else { value = value - 1; lastBallPosition = new SFVec3f(0, endPosition.y - (incrementInterval * (max - value)), 0); } valueChanged = value; ballPositionChanged = lastBallPosition; } } } function tracePrint (text) { if (traceEnabled) Browser.println ('[SliderFloat SliderScript] ' + text); }
]]>
|
|
139 | </Script> |
140 | < ROUTE fromNode='SliderBallPlaneSensor' fromField='isActive' toNode='SliderScript' toField='setDragActive'/> |
141 | < ROUTE fromNode='SliderBallPlaneSensor' fromField='translation_changed' toNode='SliderScript' toField='setBallPosition'/> |
142 | < ROUTE fromNode='BottomEndSensor' fromField='isActive' toNode='SliderScript' toField='bottomEndTouched'/> |
143 | < ROUTE fromNode='TopEndSensor' fromField='isActive' toNode='SliderScript' toField='topEndTouched'/> |
144 | < ROUTE fromNode='SliderScript' fromField='minBallPositionChanged' toNode='SliderBallPlaneSensor' toField='set_minPosition'/> |
145 | < ROUTE fromNode='SliderScript' fromField='maxBallPositionChanged' toNode='SliderBallPlaneSensor' toField='set_maxPosition'/> |
146 | < ROUTE fromNode='SliderScript' fromField='bottomEndPositionChanged' toNode='BottomEndTransform' toField='set_translation'/> |
147 | < ROUTE fromNode='SliderScript' fromField='topEndPositionChanged' toNode='TopEndTransform' toField='set_translation'/> |
148 | < ROUTE fromNode='SliderScript' fromField='ballPositionChanged' toNode='SliderBallTransform' toField='set_translation'/> |
149 | </Transform> |
150 |
<!-- ROUTE information for LayoutDirectionScript node:
[from directionRotation to LayoutDirectionTransform.set_rotation
]
-->
<Script DEF='LayoutDirectionScript'> |
151 | <field name='direction' type='SFString' accessType='initializeOnly'/> |
152 | <field name='directionRotation' type='SFRotation' accessType='outputOnly'/> |
153 | <field name='traceEnabled' type='SFBool' accessType='initializeOnly'/> |
154 | <IS> |
155 | <connect nodeField='direction' protoField='layoutDirection'/> |
156 | <connect nodeField='traceEnabled' protoField='traceEnabled'/> |
157 | </IS> |
<![CDATA[
ecmascript: function initialize () { if ((direction=='vertical') || (direction=='Vertical') || (direction=='VERTICAL')) { directionRotation = new SFRotation(0, 0, 1, 0); } else if ((direction=='horizontal') || (direction=='Horizontal') || (direction=='HORIZONTAL')) { directionRotation = new SFRotation(0, 0, 1, -1.57); } else { Browser.println ('[SliderFloat LayoutDirectionScript] unrecognized direction: ' + direction + ', using vertical'); directionRotation = new SFRotation(0, 0, 1, 0); } tracePrint ('direction=' + direction); } function tracePrint (text) { if (traceEnabled) Browser.println ('[SliderFloat LayoutDirectionScript] ' + text); }
]]>
|
|
159 | </Script> |
160 | < ROUTE fromNode='LayoutDirectionScript' fromField='directionRotation' toNode='LayoutDirectionTransform' toField='set_rotation'/> |
161 | </Group> |
162 | </ProtoBody> |
163 | </ProtoDeclare> |
164 | <Anchor description='SliderIntegerExample' parameter='"target=_blank"' url=' "SliderIntegerExample.x3d" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/SliderIntegerExample.x3d" "SliderIntegerExample.wrl" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/SliderIntegerExample.wrl" '> |
165 | <Shape> |
166 | <Appearance> |
167 | <Material diffuseColor='0 1 1' emissiveColor='0 1 1'/> |
168 | </Appearance> |
169 | <Text string='"SliderIntegerPrototype is a" "Prototype definition file." "" "To see an example scene" "using this new node" "click this text and view" "SliderIntegerExample.x3d"'> |
170 | <FontStyle justify='"MIDDLE" "MIDDLE"' size='0.8'/> |
171 | </Text> |
172 | </Shape> |
173 | </Anchor> |
174 | </Scene> |
175 | </X3D> |
Event Graph ROUTE Table entries with 10 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.
LayoutDirectionScript
Script directionRotation SFRotation |
LayoutDirectionTransform
Transform set_rotation SFRotation |
line 164
Anchor |
description='SliderIntegerExample' 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.
-->