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=' SingleTypeConversionPrototype.x3d '/> |
6 | <meta name='description' content='Converts from a single typed value to various other types of values.'/> |
7 | <meta name='creator' content='Don Brutzman, Mike Hunsberger, Jane Wu'/> |
8 | <meta name='created' content='15 June 2001'/> |
9 | <meta name='modified' content='15 October 2023'/> |
10 | <meta name='subject' content='type conversion'/> |
11 | <meta name='reference' content=' http://www.cs.brown.edu/~gss/VRML98/paper.rev.html '/> |
12 | <meta name='reference' content='http://www.cs.brown.edu/~gss/vrml/hprotos.wrl'/> |
13 | <meta name='reference' content='http://www.cs.brown.edu/~gss/vrml/hotpot.zip'/> |
14 | <meta name='identifier' content=' https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/SingleTypeConversionPrototype.x3d '/> |
15 | <meta name='generator' content='X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit'/> |
16 | <meta name='license' content='../../license.html'/> |
17 | </head> |
18 | <Scene> |
19 | <WorldInfo title='SingleTypeConversionPrototype.x3d'/> |
20 | <ProtoDeclare name='SingleTypeConversion' appinfo='SingleTypeConversion converts from a single typed value to various other types of values'> |
21 | <ProtoInterface> |
22 |
<field name='decimalPlaces' type='SFInt32' value='-1' accessType='initializeOnly'
appinfo='decimalPlaces is the number of significant digits after the decimal point, use -1 to indicate no round off'/> |
23 | <field name='setDecimalPlaces' type='SFInt32' accessType='inputOnly'/> |
24 | <field name='BooleanValue' type='SFBool' accessType='inputOnly'/> |
25 | <field name='FloatValue' type='SFFloat' accessType='inputOnly'/> |
26 | <field name='IntegerValue' type='SFInt32' accessType='inputOnly'/> |
27 | <field name='TimeValue' type='SFTime' accessType='inputOnly'/> |
28 | <field name='BooleanResult' type='SFBool' accessType='outputOnly'/> |
29 | <field name='FloatResult' type='SFFloat' accessType='outputOnly'/> |
30 | <field name='IntegerResult' type='SFInt32' accessType='outputOnly'/> |
31 | <field name='TimeResult' type='SFTime' accessType='outputOnly'/> |
32 | <field name='StringResult' type='SFString' accessType='outputOnly'/> |
33 | <field name='StringsResult' type='MFString' accessType='outputOnly'/> |
34 | </ProtoInterface> |
35 | <ProtoBody> |
36 | <Script DEF='ConversionScript'> |
37 | <field name='decimalPlaces' type='SFInt32' accessType='initializeOnly'/> |
38 | <field name='setDecimalPlaces' type='SFInt32' accessType='inputOnly'/> |
39 | <field name='SFBoolValue' type='SFBool' accessType='inputOnly'/> |
40 | <field name='SFFloatValue' type='SFFloat' accessType='inputOnly'/> |
41 | <field name='SFInt32Value' type='SFInt32' accessType='inputOnly'/> |
42 | <field name='SFTimeValue' type='SFTime' accessType='inputOnly'/> |
43 | <field name='SFBoolResult' type='SFBool' accessType='outputOnly'/> |
44 | <field name='SFInt32Result' type='SFInt32' accessType='outputOnly'/> |
45 | <field name='SFFloatResult' type='SFFloat' accessType='outputOnly'/> |
46 | <field name='SFTimeResult' type='SFTime' accessType='outputOnly'/> |
47 | <field name='SFStringResult' type='SFString' accessType='outputOnly'/> |
48 | <field name='MFStringResult' type='MFString' accessType='outputOnly'/> |
49 |
<field name='newIntegerValue' type='SFInt32' value='0' accessType='initializeOnly'
appinfo='local temporary variable'/> |
50 |
<field name='newFloatValue' type='SFFloat' value='0.0' accessType='initializeOnly'
appinfo='local temporary variable'/> |
51 |
<field name='newTimeValue' type='SFFloat' value='0.0' accessType='initializeOnly'
appinfo='local temporary variable'/> |
52 |
<field name='roundOffFactor' type='SFFloat' value='1' accessType='initializeOnly'
appinfo='local variable defined as field for persistence'/> |
53 | <IS> |
54 | <connect nodeField='decimalPlaces' protoField='decimalPlaces'/> |
55 | <connect nodeField='setDecimalPlaces' protoField='setDecimalPlaces'/> |
56 | <connect nodeField='SFBoolValue' protoField='BooleanValue'/> |
57 | <connect nodeField='SFFloatValue' protoField='FloatValue'/> |
58 | <connect nodeField='SFInt32Value' protoField='IntegerValue'/> |
59 | <connect nodeField='SFTimeValue' protoField='TimeValue'/> |
60 | <connect nodeField='SFBoolResult' protoField='BooleanResult'/> |
61 | <connect nodeField='SFInt32Result' protoField='IntegerResult'/> |
62 | <connect nodeField='SFFloatResult' protoField='FloatResult'/> |
63 | <connect nodeField='SFTimeResult' protoField='TimeResult'/> |
64 | <connect nodeField='SFStringResult' protoField='StringResult'/> |
65 | <connect nodeField='MFStringResult' protoField='StringsResult'/> |
66 | </IS> |
<![CDATA[
ecmascript: function initialize() { if (decimalPlaces <= -1) { roundOffFactor = 1; } else { roundOffFactor = Math.pow(10, decimalPlaces); } // Browser.println ('[SingleTypeConversion initialize()] decimalPlaces=' + decimalPlaces + ', roundOffFactor=' + roundOffFactor); } function setDecimalPlaces (value, timeStamp) { decimalPlaces = value; initialize (); } function SFBoolValue(value, timeStamp) { if (value) { SFBoolResult = value; SFInt32Result = 1; SFFloatResult = 1.0; SFTimeResult = timeStamp; SFStringResult = '1'; MFStringResult = new MFString ('1'); } else { SFBoolResult = value; SFInt32Result = 0; SFFloatResult = 0.0; SFTimeResult = -1; SFStringResult = '0'; MFStringResult = new MFString ('0'); } } function SFInt32Value(value, timeStamp) { if (value == 0) SFBoolResult = false; else SFBoolResult = true; newIntegerValue = value; SFInt32Result = newIntegerValue; SFFloatResult = newIntegerValue * 1.0; SFTimeResult = newIntegerValue * 1.0; SFStringResult = newIntegerValue.toString(); // per EcmaScript specification if (SFStringResult == null) { SFStringResult = newIntegerValue; // try direct approach } MFStringResult = new MFString(SFStringResult); } function SFFloatValue(value, timeStamp) { if (value == 0) SFBoolResult = false; else SFBoolResult = true; if (decimalPlaces >= 0) newFloatValue = Math.round(value*roundOffFactor) / roundOffFactor; else newFloatValue = value; SFInt32Result = Math.round(newFloatValue); SFFloatResult = newFloatValue; SFTimeResult = newFloatValue; SFStringResult = newFloatValue.toString(); // per EcmaScript specification if (SFStringResult == null) { SFStringResult = newFloatValue; // try direct approach } MFStringResult = new MFString(SFStringResult); // Browser.println ('value=' + value + ', SFFloatResult=' + SFFloatResult); } function SFTimeValue(value, timeStamp) { if (value == 0.0) SFBoolResult = false; else SFBoolResult = true; if (decimalPlaces >= 0) newTimeValue = Math.round(value*roundOffFactor) / roundOffFactor; else newTimeValue = value; SFInt32Result = Math.round(newTimeValue); SFFloatResult = newTimeValue; SFTimeResult = newTimeValue; SFStringResult = newTimeValue.toString(); // per EcmaScript specification if (SFStringResult == null) { SFStringResult = newTimeValue; // try direct approach } MFStringResult = new MFString(SFStringResult); }
]]>
|
|
68 | </Script> |
69 | </ProtoBody> |
70 | </ProtoDeclare> |
71 | <!-- ==================== --> |
72 | <Anchor description='SingleTypeConversion Example' url=' "SingleTypeConversionExample.x3d" "../../../Savage/Tools/Authoring/SingleTypeConversionExample.x3d" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/SingleTypeConversionExample.x3d" "SingleTypeConversionExample.wrl" "../../../Savage/Tools/Authoring/SingleTypeConversionExample.wrl" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/SingleTypeConversionExample.wrl" '> |
73 | <Shape> |
74 | <Appearance> |
75 | <Material diffuseColor='0 1 1' emissiveColor='0 1 1'/> |
76 | </Appearance> |
77 | <Text string='"SingleTypeConversionPrototype" "is a Prototype definition file." "" "To see an example scene" "select this text and view" "SingleTypeConversionExample"'> |
78 | <FontStyle justify='"MIDDLE" "MIDDLE"' size='0.8'/> |
79 | </Text> |
80 | </Shape> |
81 | </Anchor> |
82 | </Scene> |
83 | </X3D> |
Event Graph ROUTE Table with 0 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.
ConversionScript
Script |
No direct ROUTE connection found for events to/from this node. This Script has no direct access to other nodes. |
line 72
Anchor |
description='SingleTypeConversion 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.
-->