X3D Model Documentation: SingleTypeConversionPrototype.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=' SingleTypeConversionPrototype.x3d '/>
  6            <meta name='descriptioncontent='Converts from a single typed value to various other types of values.'/>
  7            <meta name='creatorcontent='Don Brutzman, Mike Hunsberger, Jane Wu'/>
  8            <meta name='createdcontent='15 June 2001'/>
  9            <meta name='modifiedcontent='15 October 2023'/>
 10            <meta name='subjectcontent='type conversion'/>
 11            <meta name='referencecontent=' http://www.cs.brown.edu/~gss/VRML98/paper.rev.html '/>
 12            <meta name='referencecontent='http://www.cs.brown.edu/~gss/vrml/hprotos.wrl'/>
 13            <meta name='referencecontent='http://www.cs.brown.edu/~gss/vrml/hotpot.zip'/>
 14            <meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/SingleTypeConversionPrototype.x3d '/>
 15            <meta name='generatorcontent='X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit'/>
 16            <meta name='licensecontent='../../license.html'/>
 17       </head>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->
<!-- to top DEF node index: ConversionScript

Index for ProtoDeclare definition: SingleTypeConversion
-->
 18       <Scene>
 19            <WorldInfo title='SingleTypeConversionPrototype.x3d'/>
 20            <ProtoDeclare name='SingleTypeConversionappinfo='SingleTypeConversion converts from a single typed value to various other types of values'>
 21                 <ProtoInterface>
 22                      <field name='decimalPlacestype='SFInt32value='-1accessType='initializeOnly'
                     appinfo='decimalPlaces is the number of significant digits after the decimal point, use -1 to indicate no round off'/>
 23                      <field name='setDecimalPlacestype='SFInt32accessType='inputOnly'/>
 24                      <field name='BooleanValuetype='SFBoolaccessType='inputOnly'/>
 25                      <field name='FloatValuetype='SFFloataccessType='inputOnly'/>
 26                      <field name='IntegerValuetype='SFInt32accessType='inputOnly'/>
 27                      <field name='TimeValuetype='SFTimeaccessType='inputOnly'/>
 28                      <field name='BooleanResulttype='SFBoolaccessType='outputOnly'/>
 29                      <field name='FloatResulttype='SFFloataccessType='outputOnly'/>
 30                      <field name='IntegerResulttype='SFInt32accessType='outputOnly'/>
 31                      <field name='TimeResulttype='SFTimeaccessType='outputOnly'/>
 32                      <field name='StringResulttype='SFStringaccessType='outputOnly'/>
 33                      <field name='StringsResulttype='MFStringaccessType='outputOnly'/>
 34                 </ProtoInterface>
 35                 <ProtoBody>
 36                      <Script DEF='ConversionScript'>
 37                           <field name='decimalPlacestype='SFInt32accessType='initializeOnly'/>
 38                           <field name='setDecimalPlacestype='SFInt32accessType='inputOnly'/>
 39                           <field name='SFBoolValuetype='SFBoolaccessType='inputOnly'/>
 40                           <field name='SFFloatValuetype='SFFloataccessType='inputOnly'/>
 41                           <field name='SFInt32Valuetype='SFInt32accessType='inputOnly'/>
 42                           <field name='SFTimeValuetype='SFTimeaccessType='inputOnly'/>
 43                           <field name='SFBoolResulttype='SFBoolaccessType='outputOnly'/>
 44                           <field name='SFInt32Resulttype='SFInt32accessType='outputOnly'/>
 45                           <field name='SFFloatResulttype='SFFloataccessType='outputOnly'/>
 46                           <field name='SFTimeResulttype='SFTimeaccessType='outputOnly'/>
 47                           <field name='SFStringResulttype='SFStringaccessType='outputOnly'/>
 48                           <field name='MFStringResulttype='MFStringaccessType='outputOnly'/>
 49                           <field name='newIntegerValuetype='SFInt32value='0accessType='initializeOnly'
                          appinfo='local temporary variable'/>
 50                           <field name='newFloatValuetype='SFFloatvalue='0.0accessType='initializeOnly'
                          appinfo='local temporary variable'/>
 51                           <field name='newTimeValuetype='SFFloatvalue='0.0accessType='initializeOnly'
                          appinfo='local temporary variable'/>
 52                           <field name='roundOffFactortype='SFFloatvalue='1accessType='initializeOnly'
                          appinfo='local variable defined as field for persistence'/>
 53                           <IS>
 54                                <connect nodeField='decimalPlacesprotoField='decimalPlaces'/>
 55                                <connect nodeField='setDecimalPlacesprotoField='setDecimalPlaces'/>
 56                                <connect nodeField='SFBoolValueprotoField='BooleanValue'/>
 57                                <connect nodeField='SFFloatValueprotoField='FloatValue'/>
 58                                <connect nodeField='SFInt32ValueprotoField='IntegerValue'/>
 59                                <connect nodeField='SFTimeValueprotoField='TimeValue'/>
 60                                <connect nodeField='SFBoolResultprotoField='BooleanResult'/>
 61                                <connect nodeField='SFInt32ResultprotoField='IntegerResult'/>
 62                                <connect nodeField='SFFloatResultprotoField='FloatResult'/>
 63                                <connect nodeField='SFTimeResultprotoField='TimeResult'/>
 64                                <connect nodeField='SFStringResultprotoField='StringResult'/>
 65                                <connect nodeField='MFStringResultprotoField='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 1emissiveColor='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 shows event connections.
-->
<!-- to top DEF node index: ConversionScript

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

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. 

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://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/SingleTypeConversionPrototypeIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/SingleTypeConversionPrototype.x3d -->

<!-- Color-coding legend: X3D terminology <X3dNode  DEF='idNamefield='value'/> matches XML terminology <XmlElement  DEF='idNameattribute='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. -->