{ "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":"ProjectileSliderBarPrototype.x3d"
          },
          {
            "@name":"description",
            "@content":"A generic slider bar prototype. Colors, size of the bar and name are changable."
          },
          {
            "@name":"creator",
            "@content":"Ozan APAYDIN"
          },
          {
            "@name":"created",
            "@content":"1 December 2001"
          },
          {
            "@name":"modified",
            "@content":"30 November 2024"
          },
          {
            "@name":"identifier",
            "@content":"https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/ProjectileSliderBarPrototype.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../license.html"
          },
          {
            "@name":"translated",
            "@content":"20 April 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":"ProjectileSliderBarPrototype.x3d"
            }
          },
          { "ProtoDeclare":
            {
              "@name":"ProjectileSliderBar",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"name",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Name of the Slider Bar. It appears on the left side of the bar.",
                      "@type":"MFString"
                    },
                    {
                      "@name":"length",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Length of the Slider bar. According to given value bar will arrange itself.",
                      "@type":"SFFloat",
                      "@value":1
                    },
                    {
                      "@name":"width",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Width of the Slider bar. According to given value bar will arrange itself.",
                      "@type":"SFFloat",
                      "@value":1
                    },
                    {
                      "@name":"maxValue",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Max. value of Slider Bar.It can be assigned a positive or a negative value.",
                      "@type":"SFFloat",
                      "@value":1
                    },
                    {
                      "@name":"minValue",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Min. value of Slider Bar. It can be assigned a positive or a negative value.",
                      "@type":"SFFloat",
                      "@value":0
                    },
                    {
                      "@name":"barColor",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Color of Slider Bar.",
                      "@type":"SFColor",
                      "@value":[1,0,0]
                    },
                    {
                      "@name":"pointerColor",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Pointer Color of Slider Bar.",
                      "@type":"SFColor",
                      "@value":[1,1,0]
                    },
                    {
                      "@name":"nameColor",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Slider Bar Name Color.",
                      "@type":"SFColor",
                      "@value":[1,0,1]
                    },
                    {
                      "@name":"currentValueColor",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Color of Current Value text.",
                      "@type":"SFColor",
                      "@value":[0.2,0.8,0.2]
                    },
                    {
                      "@name":"currentValueInt",
                      "@accessType":"outputOnly",
                      "@appinfo":"If the precision is 0 current Value will be output in this eventOut field as Integer else in currentValueFloat eventOut field as Float.",
                      "@type":"SFInt32"
                    },
                    {
                      "@name":"currentValueFloat",
                      "@accessType":"outputOnly",
                      "@appinfo":"If the precision is NOT 0 current Value will be output in this eventOut field as Float else in currentValueInt eventOut field as Integer.",
                      "@type":"SFFloat"
                    },
                    {
                      "@name":"precision",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Count of the numbers after Decimal Point. Example : If precision is 2 1.562777 -> 1.56",
                      "@type":"SFInt32",
                      "@value":2
                    },
                    {
                      "@name":"translation",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Translation values of Slider Bar to define its location on the screen.",
                      "@type":"SFVec3f",
                      "@value":[0,0,0]
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    { "Group":
                      {
                        "@DEF":"HUDGroup",
                        "-children":[
                          { "Collision":
                            {
                              "@enabled":false,
                              "-children":[
                                { "ProximitySensor":
                                  {
                                    "@DEF":"HudProx",
                                    "@size":[1000000,1000000,1000000]
                                  }
                                },
                                { "Transform":
                                  {
                                    "@DEF":"HudTransform",
                                    "-children":[
                                      { "Transform":
                                        {
                                          "@translation":[0,0,-0.2],
                                          "-children":[
                                            { "Transform":
                                              {
                                                "@DEF":"SliderTransform",
                                                "IS": {
                                                    "connect": [
                                                      {
                                                        "@nodeField":"translation",
                                                        "@protoField":"translation"
                                                      }
                                                    ]
                                                },
                                                "-children":[
                                                  { "Group":
                                                    {
                                                      "@DEF":"SliderShape",
                                                      "-children":[
                                                        { "Transform":
                                                          {
                                                            "@DEF":"barTransform",
                                                            "-children":[
                                                              { "Shape":
                                                                {
                                                                  "-appearance":
                                                                    { "Appearance":
                                                                      {
                                                                        "-material":
                                                                          { "Material":
                                                                            {
                                                                              "@DEF":"BarColor",
                                                                              "@diffuseColor":[0,0,1],
                                                                              "IS": {
                                                                                  "connect": [
                                                                                    {
                                                                                      "@nodeField":"diffuseColor",
                                                                                      "@protoField":"barColor"
                                                                                    }
                                                                                  ]
                                                                              }
                                                                            }
                                                                          }
                                                                      }
                                                                    },
                                                                  "-geometry":
                                                                    { "Box":
                                                                      {
                                                                        "@DEF":"bar",
                                                                        "@size":[0.05,0.001,0.000001]
                                                                      }
                                                                    }
                                                                }
                                                              }
                                                            ]
                                                          }
                                                        },
                                                        { "Transform":
                                                          {
                                                            "@DEF":"pointerTransform",
                                                            "-children":[
                                                              { "Shape":
                                                                {
                                                                  "-appearance":
                                                                    { "Appearance":
                                                                      {
                                                                        "-material":
                                                                          { "Material":
                                                                            {
                                                                              "@DEF":"PointerColor",
                                                                              "@diffuseColor":[1,1,0],
                                                                              "IS": {
                                                                                  "connect": [
                                                                                    {
                                                                                      "@nodeField":"diffuseColor",
                                                                                      "@protoField":"pointerColor"
                                                                                    }
                                                                                  ]
                                                                              }
                                                                            }
                                                                          }
                                                                      }
                                                                    },
                                                                  "-geometry":
                                                                    { "Cone":
                                                                      {
                                                                        "@DEF":"pointer",
                                                                        "@bottomRadius":0.0025,
                                                                        "@height":0.005
                                                                      }
                                                                    }
                                                                }
                                                              },
                                                              { "PlaneSensor":
                                                                {
                                                                  "@DEF":"SVPlaneSensor",
                                                                  "@maxPosition":[0.025,0],
                                                                  "@minPosition":[-0.025,0]
                                                                }
                                                              }
                                                            ]
                                                          }
                                                        },
                                                        { "Transform":
                                                          {
                                                            "@DEF":"sliderNameTransform",
                                                            "-children":[
                                                              { "Shape":
                                                                {
                                                                  "-geometry":
                                                                    { "Text":
                                                                      {
                                                                        "@DEF":"SliderName",
                                                                        "IS": {
                                                                            "connect": [
                                                                              {
                                                                                "@nodeField":"string",
                                                                                "@protoField":"name"
                                                                              }
                                                                            ]
                                                                        },
                                                                        "-fontStyle":
                                                                          { "FontStyle":
                                                                            {
                                                                              "@justify":["END"],
                                                                              "@size":0.0085,
                                                                              "@style":"BOLD"
                                                                            }
                                                                          }
                                                                      }
                                                                    },
                                                                  "-appearance":
                                                                    { "Appearance":
                                                                      {
                                                                        "-material":
                                                                          { "Material":
                                                                            {
                                                                              "@DEF":"sliderNameColor",
                                                                              "IS": {
                                                                                  "connect": [
                                                                                    {
                                                                                      "@nodeField":"diffuseColor",
                                                                                      "@protoField":"nameColor"
                                                                                    }
                                                                                  ]
                                                                              }
                                                                            }
                                                                          }
                                                                      }
                                                                    }
                                                                }
                                                              }
                                                            ]
                                                          }
                                                        },
                                                        { "Transform":
                                                          {
                                                            "@DEF":"currentValueTransform",
                                                            "-children":[
                                                              { "Shape":
                                                                {
                                                                  "@DEF":"currentValue",
                                                                  "-geometry":
                                                                    { "Text":
                                                                      {
                                                                        "@DEF":"currentValueText",
                                                                        "-fontStyle":
                                                                          { "FontStyle":
                                                                            {
                                                                              "@DEF":"currentValueFont",
                                                                              "@justify":["BEGIN","MIDDLE"],
                                                                              "@size":0.0085,
                                                                              "@style":"BOLD"
                                                                            }
                                                                          }
                                                                      }
                                                                    },
                                                                  "-appearance":
                                                                    { "Appearance":
                                                                      {
                                                                        "-material":
                                                                          { "Material":
                                                                            {
                                                                              "@DEF":"valueColor",
                                                                              "IS": {
                                                                                  "connect": [
                                                                                    {
                                                                                      "@nodeField":"diffuseColor",
                                                                                      "@protoField":"currentValueColor"
                                                                                    }
                                                                                  ]
                                                                              }
                                                                            }
                                                                          }
                                                                      }
                                                                    }
                                                                }
                                                              }
                                                            ]
                                                          }
                                                        }
                                                      ]
                                                    }
                                                  }
                                                ]
                                              }
                                            }
                                          ]
                                        }
                                      }
                                    ]
                                  }
                                }
                              ]
                            }
                          }
                        ]
                      }
                    },
                    { "Script":
                      {
                        "@DEF":"ShapeOrganizer",
                        "@directOutput":true,
                        "field": [
                          {
                            "@name":"Length",
                            "@accessType":"initializeOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"Width",
                            "@accessType":"initializeOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"SliderNameTransformNode",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode",
                            "-children":[
                              { "Transform":
                                {
                                  "@USE":"sliderNameTransform"
                                }
                              }
                            ]
                          },
                          {
                            "@name":"CurrentValueTransformNode",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode",
                            "-children":[
                              { "Transform":
                                {
                                  "@USE":"currentValueTransform"
                                }
                              }
                            ]
                          },
                          {
                            "@name":"BarTransformNode",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode",
                            "-children":[
                              { "Transform":
                                {
                                  "@USE":"barTransform"
                                }
                              }
                            ]
                          },
                          {
                            "@name":"PointerTransformNode",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode",
                            "-children":[
                              { "Transform":
                                {
                                  "@USE":"pointerTransform"
                                }
                              }
                            ]
                          },
                          {
                            "@name":"CurrentValueText",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode",
                            "-children":[
                              { "Text":
                                {
                                  "@USE":"currentValueText"
                                }
                              }
                            ]
                          },
                          {
                            "@name":"SVPlaneSensorNode",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode",
                            "-children":[
                              { "PlaneSensor":
                                {
                                  "@USE":"SVPlaneSensor"
                                }
                              }
                            ]
                          }
                        ],
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"Length",
                                "@protoField":"length"
                              },
                              {
                                "@nodeField":"Width",
                                "@protoField":"width"
                              }
                            ]
                        },
                        "#sourceCode":[
"",
"",
"ecmascript:",
"function initialize() {",
"",
"   for(i = 0; i < 3; i++) { ",
"      BarTransformNode.scale[i] = 1;",
"      if(i == 2) {",
"         PointerTransformNode.scale[i] = 0.1; ",
"      }",
"      else {",
"         PointerTransformNode.scale[i] = 1;",
"      }",
"   } ",
"   setBarSize();",
"   setPointerSize();",
"   setCurrentValueTransform();",
"   setNameTransform();",
"}",
"",
"function setBarSize() {",
"   BarTransformNode.scale[0] = Length * BarTransformNode.scale[0];",
"   BarTransformNode.scale[1] = Width * BarTransformNode.scale[1];",
"}",
"",
"function setPointerSize() {",
"   PointerTransformNode.scale[0] = Width * PointerTransformNode.scale[0];",
"   PointerTransformNode.scale[1] = Width * PointerTransformNode.scale[1];",
"   SVPlaneSensorNode.minPosition[0] = Length * SVPlaneSensorNode.minPosition[0];",
"   SVPlaneSensorNode.maxPosition[0] = Length * SVPlaneSensorNode.maxPosition[0];",
"}",
"",
"function setCurrentValueTransform() {",
"   CurrentValueTransformNode.translation[0] = (BarTransformNode.scale[0] * 0.05 / 2) + (BarTransformNode.scale[1] * 0.001 * 2);",
"}",
"",
"function setNameTransform() {",
"   SliderNameTransformNode.translation[0] = -((BarTransformNode.scale[0] * 0.05 / 2) + (BarTransformNode.scale[1] * 0.001 * 2));",
"}",
"",
""
]
                      }
                    },
                    { "Script":
                      {
                        "@DEF":"CurrentValueFinder",
                        "@directOutput":true,
                        "field": [
                          {
                            "@name":"SVPlaneSensorNode",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode",
                            "-children":[
                              { "PlaneSensor":
                                {
                                  "@USE":"SVPlaneSensor"
                                }
                              }
                            ]
                          },
                          {
                            "@name":"MaxValue",
                            "@accessType":"initializeOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"MinValue",
                            "@accessType":"initializeOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"CurrentValueTextNode",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode",
                            "-children":[
                              { "Text":
                                {
                                  "@USE":"currentValueText"
                                }
                              }
                            ]
                          },
                          {
                            "@name":"updateCurrentValue",
                            "@accessType":"inputOnly",
                            "@type":"SFVec3f"
                          },
                          {
                            "@name":"CurrentValueInt",
                            "@accessType":"outputOnly",
                            "@type":"SFInt32"
                          },
                          {
                            "@name":"CurrentValueFloat",
                            "@accessType":"outputOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"Precision",
                            "@accessType":"initializeOnly",
                            "@type":"SFInt32"
                          }
                        ],
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"MaxValue",
                                "@protoField":"maxValue"
                              },
                              {
                                "@nodeField":"MinValue",
                                "@protoField":"minValue"
                              },
                              {
                                "@nodeField":"CurrentValueInt",
                                "@protoField":"currentValueInt"
                              },
                              {
                                "@nodeField":"CurrentValueFloat",
                                "@protoField":"currentValueFloat"
                              },
                              {
                                "@nodeField":"Precision",
                                "@protoField":"precision"
                              }
                            ]
                        },
                        "#sourceCode":[
"",
"",
"ecmascript:",
"",
"var totalLength;",
"",
"function initialize() {",
"   realValue = (MaxValue + MinValue) / 2;",
"   realValue = roundOff(realValue, Precision);",
"   CurrentValueFloat = realValue;",
"   CurrentValueInt = Math.round(realValue);",
"   totalLength = SVPlaneSensorNode.maxPosition[0] - SVPlaneSensorNode.minPosition[0];",
"   updateCurrentValueText(realValue.toString()); ",
"}",
"",
"//Map pointer translation value to the real value",
"function updateCurrentValue(translation, timeEvent) {",
"   var displayString;",
"   var curPositionOnBar = translation[0] + totalLength / 2;",
"   var x = (MaxValue - MinValue) * curPositionOnBar / totalLength;",
"",
"   var realValue = MinValue + x;",
"",
"   if(Precision == 0) { //If ",
"      CurrentValueInt = Math.round(realValue);",
"      displayString = CurrentValueInt.toString();",
"   }",
"   else {",
"      CurrentValueFloat = roundOff(realValue, Precision);       ",
"      displayString = CurrentValueFloat.toString();",
"   } ",
"",
"   updateCurrentValueText(displayString);",
"}",
"",
"",
"function updateCurrentValueText(dispStr) {",
"   CurrentValueTextNode.string[0] = dispStr;",
"}",
"",
"//A function to round the values regarding to given precision.",
"function roundOff(value, precision) {",
"",
"   var result;",
"   var isNegative = false;",
"   var wholeInt = Math.round(value * Math.pow(10, precision));",
"",
"   //Negative numbers creates exceptional condition, therefor they are converted",
"   //to positive values.",
"   if(wholeInt < 0) {",
"      wholeInt = -wholeInt;",
"      isNegative = true;",
"   }",
"",
"   var whole = wholeInt.toString();",
"",
"   var decPoint = whole.length - precision;",
"",
"   //Exception when precision is bigger than the string length   ",
"   if(decPoint < 0) {",
"      i = -decPoint;",
"      for(i; i > 0; i--) {  ",
"         whole ='0' + whole;",
"      }",
"",
"      //Calculate decPoint according to new string expanded with 0s      ",
"      decPoint = whole.length - precision;",
"   }",
"",
"   if(whole !='0') {",
"      //Put the decimal point on the appropriate place",
"      result = whole.substring(0, decPoint);",
"      result +='.';",
"      result += whole.substring(decPoint, whole.length);",
"   }",
"   else { //If the string is'0', then result is'0'",
"      result = whole;",
"   }",
"",
"   //Negative numbers are altered.",
"   if(isNegative) {",
"      result ='-' + result;",
"   }",
"   //Convert the String value to Float.",
"   resultFloat = parseFloat(result); ",
"",
"",
"   return resultFloat;",
"",
"}",
"",
""
]
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"position_changed",
                        "@fromNode":"HudProx",
                        "@toField":"set_translation",
                        "@toNode":"HudTransform"
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"orientation_changed",
                        "@fromNode":"HudProx",
                        "@toField":"set_rotation",
                        "@toNode":"HudTransform"
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"position_changed",
                        "@fromNode":"HudProx",
                        "@toField":"center",
                        "@toNode":"HudProx"
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"translation_changed",
                        "@fromNode":"SVPlaneSensor",
                        "@toField":"set_translation",
                        "@toNode":"pointerTransform"
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"translation_changed",
                        "@fromNode":"SVPlaneSensor",
                        "@toField":"updateCurrentValue",
                        "@toNode":"CurrentValueFinder"
                      }
                    }
                  ]
              }
            }
          },
          { "Viewpoint":
            {
              "@description":"Slider bar",
              "@position":[0,0,5]
            }
          },
          { "ProtoInstance":
            {
              "@name":"ProjectileSliderBar",
              "fieldValue": [
                {
                  "@name":"name",
                  "@value":["AFAA"]
                },
                {
                  "@name":"length",
                  "@value":1.5
                },
                {
                  "@name":"width",
                  "@value":1
                },
                {
                  "@name":"maxValue",
                  "@value":10
                },
                {
                  "@name":"minValue",
                  "@value":-2
                }
              ]
            }
          }
        ]
    }
  }
}