{ "X3D": {
    "encoding":"UTF-8",
    "@profile":"Immersive",
    "@version":"3.3",
    "@xsd:noNamespaceSchemaLocation":"https://www.web3d.org/specifications/x3d-3.3.xsd",
    "JSON schema":"https://www.web3d.org/specifications/x3d-4.0-JSONSchema.autogenerated.json",
    "head": {
        "meta": [
          {
            "@name":"title",
            "@content":"SideScanSonarPrototype.x3d"
          },
          {
            "@name":"description",
            "@content":"Produce wireframe or transparent sidescan sonar beams."
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman"
          },
          {
            "@name":"created",
            "@content":"15 March 2001"
          },
          {
            "@name":"modified",
            "@content":"20 October 2019"
          },
          {
            "@name":"identifier",
            "@content":"https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Sonar/SideScanSonarPrototype.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../../license.html"
          },
          {
            "@name":"translated",
            "@content":"21 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":[
          { "NavigationInfo":
            {
              "@DEF":"LockedDownInterface2D",
              "@type":["NONE"]
            }
          },
          { "Background":
            {
              "@skyColor":[0,0.3,0.5]
            }
          },
          { "WorldInfo":
            {
              "@info":["Produce wireframe or transparent beam cones."],
              "@title":"BeamCone Prototyupe"
            }
          },
          { "Viewpoint":
            {
              "@description":"SideScanSonar Prototype",
              "@position":[0,0,15]
            }
          },
          { "ProtoDeclare":
            {
              "@name":"SideScanSonar",
              "@appinfo":"Produce wireframe or semi-transparent sonar sidescan beams",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"altitude",
                      "@accessType":"inputOnly",
                      "@appinfo":"vertical distance above bottom in meters along y axis",
                      "@type":"SFFloat"
                    },
                    {
                      "@name":"defaultAltitude",
                      "@accessType":"initializeOnly",
                      "@appinfo":"default vertical distance above bottom in meters along y axis",
                      "@type":"SFFloat",
                      "@value":3
                    },
                    {
                      "@name":"maxAltitude",
                      "@accessType":"initializeOnly",
                      "@appinfo":"maximum effective altitude of sidescan sonar above bottom",
                      "@type":"SFFloat",
                      "@value":3
                    },
                    {
                      "@name":"defaultCrossTrackHalfRange",
                      "@accessType":"initializeOnly",
                      "@appinfo":"distance in meters from nadir to rightmost/leftmost edge when operating at defaultAltitude above the bottom",
                      "@type":"SFFloat",
                      "@value":30
                    },
                    {
                      "@name":"defaultTrackWidthMeters",
                      "@accessType":"initializeOnly",
                      "@appinfo":"longitudinal width of a single return",
                      "@type":"SFFloat",
                      "@value":0.30
                    },
                    {
                      "@name":"vehicleWidthMeters",
                      "@accessType":"initializeOnly",
                      "@appinfo":"width (or diameter) of vehicle carrying port/starboard sidescan sonar transducers",
                      "@type":"SFFloat",
                      "@value":0.178
                    },
                    {
                      "@name":"contact",
                      "@accessType":"inputOnly",
                      "@appinfo":"(communications) whether transmitted signal is in contact with receiver or (sensor) is a target return detected?",
                      "@type":"SFBool"
                    },
                    {
                      "@name":"wireframe",
                      "@accessType":"initializeOnly",
                      "@appinfo":"draw lines for tracking shape?",
                      "@type":"SFBool",
                      "@value":true
                    },
                    {
                      "@name":"solid",
                      "@accessType":"initializeOnly",
                      "@appinfo":"draw solid tracking shape?",
                      "@type":"SFBool",
                      "@value":true
                    },
                    {
                      "@name":"contactColor",
                      "@accessType":"initializeOnly",
                      "@appinfo":"rendering color when contact=true",
                      "@type":"SFColor",
                      "@value":[0.8,0.1,0.1]
                    },
                    {
                      "@name":"noContactColor",
                      "@accessType":"initializeOnly",
                      "@appinfo":"rendering color when contact=false",
                      "@type":"SFColor",
                      "@value":[0.3,0.5,0.5]
                    },
                    {
                      "@name":"transparency",
                      "@accessType":"inputOutput",
                      "@appinfo":"1 = fully transparent wireframe only",
                      "@type":"SFFloat",
                      "@value":0
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    {
                      "#comment":"BEAM_CONTROL beam scaling is controlled by range/beamHeightDegrees/beamWidthDegrees/direction inputs"
                    },
                    { "Transform":
                      {
                        "@DEF":"BEAM_CONTROL",
                        "-children":[
                          { "Switch":
                            {
                              "@DEF":"WIREFRAME_SWITCH",
                              "@whichChoice":1,
                              "-children":[
                                {
                                  "#comment":"TODO refactor index values starting from -1, remove WorldInfo"
                                },
                                { "WorldInfo":
                                  {
                                    "@info":["initial choice is null node (WorldInfo), meaning no wireframe beam"]
                                  }
                                },
                                { "Shape":
                                  {
                                    "-appearance":
                                      { "Appearance":
                                        {
                                          "-material":
                                            { "Material":
                                              {
                                                "@DEF":"WireMaterial",
                                                "@diffuseColor":[0.1,0.1,0.1],
                                                "@emissiveColor":[0.1,0.1,0.1],
                                                "IS": {
                                                    "connect": [
                                                      {
                                                        "@nodeField":"transparency",
                                                        "@protoField":"transparency"
                                                      }
                                                    ]
                                                }
                                              }
                                            }
                                        }
                                      },
                                    "-geometry":
                                      { "IndexedLineSet":
                                        {
                                          "@DEF":"ILS",
                                          "@coordIndex":[1,2,3,1,-1,5,3,4,5,-1,6,8,7,6,-1,10,9,8,10,-1,6,7,2,1,6,-1,10,5,4,9,10,-1],
                                          "-coord":
                                            { "Coordinate":
                                              {
                                                "@DEF":"BeamPatternCoordinatePoints",
                                                "@point":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
                                              }
                                            }
                                        }
                                      }
                                  }
                                }
                              ]
                            }
                          },
                          { "Switch":
                            {
                              "@DEF":"SOLID_SWITCH",
                              "@whichChoice":0,
                              "-children":[
                                {
                                  "#comment":"TODO refactor index values starting from -1, remove WorldInfo"
                                },
                                { "WorldInfo":
                                  {
                                    "@info":["initial choice is null node (WorldInfo), meaning no solid beam"]
                                  }
                                },
                                { "Shape":
                                  {
                                    "-appearance":
                                      { "Appearance":
                                        {
                                          "-material":
                                            { "Material":
                                              {
                                                "@DEF":"FaceMaterial",
                                                "@diffuseColor":[0.1,0.1,0.1],
                                                "IS": {
                                                    "connect": [
                                                      {
                                                        "@nodeField":"transparency",
                                                        "@protoField":"transparency"
                                                      }
                                                    ]
                                                }
                                              }
                                            }
                                        }
                                      },
                                    "-geometry":
                                      { "IndexedFaceSet":
                                        {
                                          "@DEF":"IFS",
                                          "@coordIndex":[1,2,3,1,-1,5,3,4,5,-1,6,8,7,6,-1,10,9,8,10,-1,6,7,2,1,6,-1,10,5,4,9,10,-1],
                                          "@solid":false,
                                          "-coord":
                                            { "Coordinate":
                                              {
                                                "@USE":"BeamPatternCoordinatePoints"
                                              }
                                            }
                                        }
                                      }
                                  }
                                }
                              ]
                            }
                          }
                        ]
                      }
                    },
                    {
                      "#comment":"Non-renderable animation controls"
                    },
                    { "Script":
                      {
                        "@DEF":"BEAM_CALCULATE",
                        "field": [
                          {
                            "@name":"altitude",
                            "@accessType":"inputOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"defaultAltitude",
                            "@accessType":"initializeOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"maxAltitude",
                            "@accessType":"initializeOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"defaultCrossTrackHalfRange",
                            "@accessType":"initializeOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"defaultTrackWidthMeters",
                            "@accessType":"initializeOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"vehicleWidthMeters",
                            "@accessType":"initializeOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"beamScale",
                            "@accessType":"outputOnly",
                            "@type":"SFVec3f"
                          },
                          {
                            "@name":"coordinatePoints",
                            "@accessType":"outputOnly",
                            "@type":"MFVec3f"
                          },
                          {
                            "@name":"traceEnabled",
                            "@accessType":"initializeOnly",
                            "@appinfo":"internal flag to turn on Script tracing",
                            "@type":"SFBool",
                            "@value":false
                          }
                        ],
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"altitude",
                                "@protoField":"altitude"
                              },
                              {
                                "@nodeField":"defaultAltitude",
                                "@protoField":"defaultAltitude"
                              },
                              {
                                "@nodeField":"maxAltitude",
                                "@protoField":"maxAltitude"
                              },
                              {
                                "@nodeField":"defaultCrossTrackHalfRange",
                                "@protoField":"defaultCrossTrackHalfRange"
                              },
                              {
                                "@nodeField":"defaultTrackWidthMeters",
                                "@protoField":"defaultTrackWidthMeters"
                              },
                              {
                                "@nodeField":"vehicleWidthMeters",
                                "@protoField":"vehicleWidthMeters"
                              }
                            ]
                        },
                        "#sourceCode":[
"",
"",
"ecmascript:",
"",
"function tracePrint (value)",
"{",
"\tif (traceEnabled) Browser.println ('[SideScanSonar BEAM_CALCULATE] ' + value);",
"}",
"",
"function initialize () {",
" beamScale = new SFVec3f (1, 1, 1);",
" dt2 = defaultTrackWidthMeters/2;",
"",
" origin = new SFVec3f (0, 0, 0);",
" a  = new SFVec3f (-dt2,  0,               -vehicleWidthMeters/2);",
" b  = new SFVec3f (-dt2, -defaultAltitude, -defaultCrossTrackHalfRange);",
" c  = new SFVec3f (-dt2, -defaultAltitude,  0);",
" d  = new SFVec3f (-dt2, -defaultAltitude,  defaultCrossTrackHalfRange);",
" e  = new SFVec3f (-dt2,  0,                vehicleWidthMeters/2);",
" aa = new SFVec3f ( dt2,  0,               -vehicleWidthMeters/2);",
" bb = new SFVec3f ( dt2, -defaultAltitude, -defaultCrossTrackHalfRange);",
" cc = new SFVec3f ( dt2, -defaultAltitude,  0);",
" dd = new SFVec3f ( dt2, -defaultAltitude,  defaultCrossTrackHalfRange);",
" ee = new SFVec3f ( dt2,  0,                vehicleWidthMeters/2);",
"",
" coordinatePoints = new MFVec3f (origin, a, b, c, d, e, aa, bb, cc, dd, ee);",
"",
" tracePrint ('coordinatePoints =' + coordinatePoints);",
"}",
"function altitude (newAltitude, timeStamp) {",
" if (newAltitude <= 0)",
" {",
"   beamHeightFactor= 0.001;",
"   beamScale = new SFVec3f (1, beamHeightFactor, beamHeightFactor);",
" }",
" else if (newAltitude < maxAltitude)",
" {",
"   beamHeightFactor= newAltitude / defaultAltitude;",
"   beamScale = new SFVec3f (1, beamHeightFactor, beamHeightFactor);",
" }",
" else",
" {",
"   beamHeightFactor= maxAltitude / defaultAltitude;",
"   beamScale = new SFVec3f (1, beamHeightFactor, beamHeightFactor);",
" }",
" tracePrint ('newAltitude      =' + newAltitude);",
" tracePrint ('beamHeightFactor =' + beamHeightFactor);",
" tracePrint ('beamScale        =' + beamScale);",
"}",
"",
""
]
                      }
                    },
                    { "Script":
                      {
                        "@DEF":"DETECTION",
                        "@directOutput":true,
                        "field": [
                          {
                            "@name":"contact",
                            "@accessType":"inputOnly",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"wireframe",
                            "@accessType":"initializeOnly",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"solid",
                            "@accessType":"initializeOnly",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"contactColor",
                            "@accessType":"initializeOnly",
                            "@type":"SFColor"
                          },
                          {
                            "@name":"noContactColor",
                            "@accessType":"initializeOnly",
                            "@type":"SFColor"
                          },
                          {
                            "@name":"beamColor",
                            "@accessType":"outputOnly",
                            "@type":"SFColor"
                          },
                          {
                            "@name":"wireframeChoice",
                            "@accessType":"outputOnly",
                            "@type":"SFInt32"
                          },
                          {
                            "@name":"solidChoice",
                            "@accessType":"outputOnly",
                            "@type":"SFInt32"
                          },
                          {
                            "@name":"MaterialNodeHolder",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode",
                            "-children":[
                              { "Material":
                                {
                                  "@USE":"FaceMaterial"
                                }
                              }
                            ]
                          },
                          {
                            "@name":"traceEnabled",
                            "@accessType":"initializeOnly",
                            "@appinfo":"internal flag to turn on Script tracing",
                            "@type":"SFBool",
                            "@value":false
                          }
                        ],
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"contact",
                                "@protoField":"contact"
                              },
                              {
                                "@nodeField":"wireframe",
                                "@protoField":"wireframe"
                              },
                              {
                                "@nodeField":"solid",
                                "@protoField":"solid"
                              },
                              {
                                "@nodeField":"contactColor",
                                "@protoField":"contactColor"
                              },
                              {
                                "@nodeField":"noContactColor",
                                "@protoField":"noContactColor"
                              }
                            ]
                        },
                        "#sourceCode":[
"",
"",
"ecmascript:",
"",
"function tracePrint (value)",
"{",
"\tif (traceEnabled) Browser.println ('[SideScanSonar DETECTION] ' + value);",
"}",
"",
"function initialize ()",
"{",
"\tbeamColor = noContactColor;",
"\tif (wireframe == true) wireframeChoice = 1;",
"\tif (solid     == true) solidChoice     = 1;",
"",
"\t// Debug  statements",
"\ttracePrint ('  wireframe       =' + wireframe);",
"\ttracePrint ('  solid           =' + solid);",
"\ttracePrint ('  contactColor    =' + contactColor);",
"\ttracePrint ('  noContactColor  =' + noContactColor);",
"\ttracePrint ('  beamColor       =' + beamColor);",
"\ttracePrint ('  wireframeChoice =' + wireframeChoice);",
"\ttracePrint ('  solidChoice     =' + solidChoice);",
"\ttracePrint ('  transparency    =' + MaterialNodeHolder.transparency);",
"}",
"function contact (newDetect, timeStamp)",
"{",
"\ttracePrint ('  newDetect       =' + newDetect);",
"\tif (newDetect) beamColor = contactColor;",
"\telse           beamColor = noContactColor;",
"}",
"",
""
]
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"beamScale",
                        "@fromNode":"BEAM_CALCULATE",
                        "@toField":"scale",
                        "@toNode":"BEAM_CONTROL"
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"coordinatePoints",
                        "@fromNode":"BEAM_CALCULATE",
                        "@toField":"point",
                        "@toNode":"BeamPatternCoordinatePoints"
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"beamColor",
                        "@fromNode":"DETECTION",
                        "@toField":"emissiveColor",
                        "@toNode":"WireMaterial"
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"beamColor",
                        "@fromNode":"DETECTION",
                        "@toField":"emissiveColor",
                        "@toNode":"FaceMaterial"
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"wireframeChoice",
                        "@fromNode":"DETECTION",
                        "@toField":"whichChoice",
                        "@toNode":"WIREFRAME_SWITCH"
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"solidChoice",
                        "@fromNode":"DETECTION",
                        "@toField":"whichChoice",
                        "@toNode":"SOLID_SWITCH"
                      }
                    }
                  ]
              }
            }
          },
          {
            "#comment":"Viewable geometry for this scene is anchored text that links to an example showing ExternProtoDeclare usage of BeamCone"
          },
          { "Anchor":
            {
              "@description":"SideScanSonar Example",
              "@parameter":["target=_blank"],
              "@url":["SideScanSonarExample.x3d","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Sonar/SideScanSonarExample.x3d","SideScanSonarExample.wrl","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Sonar/SideScanSonarExample.wrl"],
              "-children":[
                { "Shape":
                  {
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "Material":
                              {
                                "@diffuseColor":[0,1,1],
                                "@emissiveColor":[0,1,1]
                              }
                            }
                        }
                      },
                    "-geometry":
                      { "Text":
                        {
                          "@string":["SideScanSonarPrototype","is a Prototype definition file.","To see an example scene","click this text and view","SideScanSonarExample."],
                          "-fontStyle":
                            { "FontStyle":
                              {
                                "@justify":["MIDDLE","MIDDLE"]
                              }
                            }
                        }
                      }
                  }
                },
                { "Shape":
                  {
                    "-children":[
                      {
                        "#comment":"transparent Box as text-selection assist"
                      }
                    ],
                    "-geometry":
                      { "Box":
                        {
                          "@size":[10.5,6,0.001]
                        }
                      },
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "Material":
                              {
                                "@transparency":1
                              }
                            }
                        }
                      }
                  }
                }
              ]
            }
          }
        ]
    }
  }
}