{ "X3D": {
    "encoding":"UTF-8",
    "@profile":"Immersive",
    "@version":"3.0",
    "@xsd:noNamespaceSchemaLocation":"https://www.web3d.org/specifications/x3d-3.0.xsd",
    "JSON schema":"https://www.web3d.org/specifications/x3d-4.0-JSONSchema.autogenerated.json",
    "head": {
        "meta": [
          {
            "@name":"title",
            "@content":"SingleTypeConversionPrototype.x3d"
          },
          {
            "@name":"description",
            "@content":"Converts from a single typed value to various other types of values."
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman, Mike Hunsberger, Jane Wu"
          },
          {
            "@name":"created",
            "@content":"15 June 2001"
          },
          {
            "@name":"modified",
            "@content":"15 October 2023"
          },
          {
            "@name":"subject",
            "@content":"type conversion"
          },
          {
            "@name":"reference",
            "@content":"http://www.cs.brown.edu/~gss/VRML98/paper.rev.html"
          },
          {
            "@name":"reference",
            "@content":"http://www.cs.brown.edu/~gss/vrml/hprotos.wrl"
          },
          {
            "@name":"reference",
            "@content":"http://www.cs.brown.edu/~gss/vrml/hotpot.zip"
          },
          {
            "@name":"identifier",
            "@content":"https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/SingleTypeConversionPrototype.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../../license.html"
          },
          {
            "@name":"translated",
            "@content":"26 March 2026"
          },
          {
            "@name":"generator",
            "@content":"X3dToJson.xslt, https://www.web3d.org/x3d/stylesheets/X3dToJson.html"
          },
          {
            "@name":"reference",
            "@content":"X3D JSON encoding: https://www.web3d.org/wiki/index.php/X3D_JSON_Encoding"
          }
        ]
    },
    "Scene": {
        "-children":[
          { "WorldInfo":
            {
              "@title":"SingleTypeConversionPrototype.x3d"
            }
          },
          { "ProtoDeclare":
            {
              "@name":"SingleTypeConversion",
              "@appinfo":"SingleTypeConversion converts from a single typed value to various other types of values",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"decimalPlaces",
                      "@accessType":"initializeOnly",
                      "@appinfo":"decimalPlaces is the number of significant digits after the decimal point, use -1 to indicate no round off",
                      "@type":"SFInt32",
                      "@value":-1
                    },
                    {
                      "@name":"setDecimalPlaces",
                      "@accessType":"inputOnly",
                      "@type":"SFInt32"
                    },
                    {
                      "@name":"BooleanValue",
                      "@accessType":"inputOnly",
                      "@type":"SFBool"
                    },
                    {
                      "@name":"FloatValue",
                      "@accessType":"inputOnly",
                      "@type":"SFFloat"
                    },
                    {
                      "@name":"IntegerValue",
                      "@accessType":"inputOnly",
                      "@type":"SFInt32"
                    },
                    {
                      "@name":"TimeValue",
                      "@accessType":"inputOnly",
                      "@type":"SFTime"
                    },
                    {
                      "@name":"BooleanResult",
                      "@accessType":"outputOnly",
                      "@type":"SFBool"
                    },
                    {
                      "@name":"FloatResult",
                      "@accessType":"outputOnly",
                      "@type":"SFFloat"
                    },
                    {
                      "@name":"IntegerResult",
                      "@accessType":"outputOnly",
                      "@type":"SFInt32"
                    },
                    {
                      "@name":"TimeResult",
                      "@accessType":"outputOnly",
                      "@type":"SFTime"
                    },
                    {
                      "@name":"StringResult",
                      "@accessType":"outputOnly",
                      "@type":"SFString"
                    },
                    {
                      "@name":"StringsResult",
                      "@accessType":"outputOnly",
                      "@type":"MFString"
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    { "Script":
                      {
                        "@DEF":"ConversionScript",
                        "field": [
                          {
                            "@name":"decimalPlaces",
                            "@accessType":"initializeOnly",
                            "@type":"SFInt32"
                          },
                          {
                            "@name":"setDecimalPlaces",
                            "@accessType":"inputOnly",
                            "@type":"SFInt32"
                          },
                          {
                            "@name":"SFBoolValue",
                            "@accessType":"inputOnly",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"SFFloatValue",
                            "@accessType":"inputOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"SFInt32Value",
                            "@accessType":"inputOnly",
                            "@type":"SFInt32"
                          },
                          {
                            "@name":"SFTimeValue",
                            "@accessType":"inputOnly",
                            "@type":"SFTime"
                          },
                          {
                            "@name":"SFBoolResult",
                            "@accessType":"outputOnly",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"SFInt32Result",
                            "@accessType":"outputOnly",
                            "@type":"SFInt32"
                          },
                          {
                            "@name":"SFFloatResult",
                            "@accessType":"outputOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"SFTimeResult",
                            "@accessType":"outputOnly",
                            "@type":"SFTime"
                          },
                          {
                            "@name":"SFStringResult",
                            "@accessType":"outputOnly",
                            "@type":"SFString"
                          },
                          {
                            "@name":"MFStringResult",
                            "@accessType":"outputOnly",
                            "@type":"MFString"
                          },
                          {
                            "@name":"newIntegerValue",
                            "@accessType":"initializeOnly",
                            "@appinfo":"local temporary variable",
                            "@type":"SFInt32",
                            "@value":0
                          },
                          {
                            "@name":"newFloatValue",
                            "@accessType":"initializeOnly",
                            "@appinfo":"local temporary variable",
                            "@type":"SFFloat",
                            "@value":0.0
                          },
                          {
                            "@name":"newTimeValue",
                            "@accessType":"initializeOnly",
                            "@appinfo":"local temporary variable",
                            "@type":"SFFloat",
                            "@value":0.0
                          },
                          {
                            "@name":"roundOffFactor",
                            "@accessType":"initializeOnly",
                            "@appinfo":"local variable defined as field for persistence",
                            "@type":"SFFloat",
                            "@value":1
                          }
                        ],
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"decimalPlaces",
                                "@protoField":"decimalPlaces"
                              },
                              {
                                "@nodeField":"setDecimalPlaces",
                                "@protoField":"setDecimalPlaces"
                              },
                              {
                                "@nodeField":"SFBoolValue",
                                "@protoField":"BooleanValue"
                              },
                              {
                                "@nodeField":"SFFloatValue",
                                "@protoField":"FloatValue"
                              },
                              {
                                "@nodeField":"SFInt32Value",
                                "@protoField":"IntegerValue"
                              },
                              {
                                "@nodeField":"SFTimeValue",
                                "@protoField":"TimeValue"
                              },
                              {
                                "@nodeField":"SFBoolResult",
                                "@protoField":"BooleanResult"
                              },
                              {
                                "@nodeField":"SFInt32Result",
                                "@protoField":"IntegerResult"
                              },
                              {
                                "@nodeField":"SFFloatResult",
                                "@protoField":"FloatResult"
                              },
                              {
                                "@nodeField":"SFTimeResult",
                                "@protoField":"TimeResult"
                              },
                              {
                                "@nodeField":"SFStringResult",
                                "@protoField":"StringResult"
                              },
                              {
                                "@nodeField":"MFStringResult",
                                "@protoField":"StringsResult"
                              }
                            ]
                        },
                        "#sourceCode":[
"",
"",
"ecmascript:",
"",
"function initialize()",
"{",
"\tif (decimalPlaces <= -1)",
"\t{",
"\t\troundOffFactor = 1;",
"\t}",
"\telse",
"\t{",
"\t\troundOffFactor = Math.pow(10, decimalPlaces);",
"\t}",
"//\tBrowser.println ('[SingleTypeConversion initialize()] decimalPlaces=' + decimalPlaces + ', roundOffFactor=' + roundOffFactor);",
"}",
"function setDecimalPlaces (value, timeStamp)",
"{",
"\tdecimalPlaces = value;",
"\tinitialize ();",
"}",
"function SFBoolValue(value, timeStamp)",
"{",
"\tif (value)",
"\t{",
"\t\tSFBoolResult   = value;",
"\t\tSFInt32Result  = 1;",
"\t\tSFFloatResult  = 1.0;",
"\t\tSFTimeResult   = timeStamp;",
"\t\tSFStringResult = '1';",
"\t\tMFStringResult = new MFString ('1');",
"\t}",
"\telse",
"\t{",
"\t\tSFBoolResult   = value;",
"\t\tSFInt32Result  = 0;",
"\t\tSFFloatResult  = 0.0;",
"\t\tSFTimeResult   = -1;",
"\t\tSFStringResult = '0';",
"\t\tMFStringResult = new MFString ('0');",
"\t}",
"}",
"function SFInt32Value(value, timeStamp)",
"{",
"\tif (value == 0)",
"\t\tSFBoolResult = false;",
"\telse",
"\t\tSFBoolResult = true;",
"",
"\tnewIntegerValue = value;",
"        SFInt32Result   = newIntegerValue;",
"\tSFFloatResult   = newIntegerValue * 1.0;",
"\tSFTimeResult    = newIntegerValue * 1.0;",
"\tSFStringResult  = newIntegerValue.toString(); // per EcmaScript specification",
"        if (SFStringResult == null)",
"        {",
"            SFStringResult = newIntegerValue; // try direct approach",
"        }",
"\tMFStringResult = new MFString(SFStringResult);",
"}",
"function SFFloatValue(value, timeStamp)",
"{",
"\tif (value == 0)",
"\t\tSFBoolResult = false;",
"\telse",
"\t\tSFBoolResult = true;",
"",
"        if (decimalPlaces >= 0)",
"\t     newFloatValue = Math.round(value*roundOffFactor) / roundOffFactor;",
"\telse newFloatValue = value;",
"",
"\tSFInt32Result  = Math.round(newFloatValue);",
"\tSFFloatResult  = newFloatValue;",
"\tSFTimeResult   = newFloatValue;",
"\tSFStringResult = newFloatValue.toString(); // per EcmaScript specification",
"        if (SFStringResult == null)",
"        {",
"          SFStringResult = newFloatValue; // try direct approach",
"        }",
"\tMFStringResult = new MFString(SFStringResult);",
"//      Browser.println ('value=' + value + ', SFFloatResult=' + SFFloatResult);",
"}",
"function SFTimeValue(value, timeStamp)",
"{",
"\tif (value == 0.0)",
"\t\tSFBoolResult = false;",
"\telse",
"\t\tSFBoolResult = true;",
"",
"\tif (decimalPlaces >= 0)",
"\t\tnewTimeValue = Math.round(value*roundOffFactor) / roundOffFactor;",
"\telse\tnewTimeValue = value;",
"",
"\tSFInt32Result  = Math.round(newTimeValue);",
"\tSFFloatResult  = newTimeValue;",
"\tSFTimeResult   = newTimeValue;",
"\tSFStringResult = newTimeValue.toString(); // per EcmaScript specification",
"        if (SFStringResult == null)",
"        {",
"            SFStringResult = newTimeValue; // try direct approach",
"        }",
"\tMFStringResult = new MFString(SFStringResult);",
"}",
"",
""
]
                      }
                    }
                  ]
              }
            }
          },
          {
            "#comment":"===================="
          },
          { "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"],
              "-children":[
                { "Shape":
                  {
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "Material":
                              {
                                "@diffuseColor":[0,1,1],
                                "@emissiveColor":[0,1,1]
                              }
                            }
                        }
                      },
                    "-geometry":
                      { "Text":
                        {
                          "@string":["SingleTypeConversionPrototype","is a Prototype definition file.","To see an example scene","select this text and view","SingleTypeConversionExample"],
                          "-fontStyle":
                            { "FontStyle":
                              {
                                "@justify":["MIDDLE","MIDDLE"],
                                "@size":0.8
                              }
                            }
                        }
                      }
                  }
                }
              ]
            }
          }
        ]
    }
  }
}