{ "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":"MaterialTogglePrototype.x3d"
          },
          {
            "@name":"description",
            "@content":"Prototype definition for toggle-able Material node that can switch between 2 sets of material values, selectable at run time. This prototype also demonstrates why it is important that only the first node in a ProtoBody can render: so that it can serve as a special node type (such as Material)."
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman and MV4205 class"
          },
          {
            "@name":"created",
            "@content":"29 April 2004"
          },
          {
            "@name":"modified",
            "@content":"28 November 2019"
          },
          {
            "@name":"reference",
            "@content":"MaterialToggleExample.x3d"
          },
          {
            "@name":"identifier",
            "@content":"https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialTogglePrototype.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.2, 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":"MaterialTogglePrototype.x3d"
            }
          },
          { "ProtoDeclare":
            {
              "@name":"MaterialToggle",
              "@appinfo":"MaterialToggle selects one of two different Material values",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"set_toggle",
                      "@accessType":"inputOnly",
                      "@type":"SFBool"
                    },
                    {
                      "@name":"toggle",
                      "@accessType":"initializeOnly",
                      "@appinfo":"whether to use DefaultMaterial or ToggleMaterial",
                      "@type":"SFBool",
                      "@value":false
                    },
                    {
                      "@name":"toggle_changed",
                      "@accessType":"outputOnly",
                      "@type":"SFBool"
                    },
                    {
                      "@name":"defaultMaterial",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Material node that is enabled when toggle=false",
                      "@type":"SFNode",
                      "-children":[
                        {
                          "#comment":"no default initialization node since it crashes Xj3D"
                        }
                      ]
                    },
                    {
                      "@name":"toggleMaterial",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Material node that is enabled when toggle=true",
                      "@type":"SFNode",
                      "-children":[
                        {
                          "#comment":"no default initialization node since it crashes Xj3D"
                        }
                      ]
                    },
                    {
                      "@name":"set_defaultMaterial",
                      "@accessType":"inputOnly",
                      "@appinfo":"provide replacement default Material node",
                      "@type":"SFNode"
                    },
                    {
                      "@name":"set_toggleMaterial",
                      "@accessType":"inputOnly",
                      "@appinfo":"provide replacement toggle Material node",
                      "@type":"SFNode"
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    {
                      "#comment":"first node is node type for this prototype, other nodes are active but do not render"
                    },
                    { "Material":
                      {
                        "@DEF":"ViewedMaterialNode"
                      }
                    },
                    { "Script":
                      {
                        "@DEF":"MaterialAnimationScript",
                        "@directOutput":true,
                        "field": [
                          {
                            "@name":"traceEnabled",
                            "@accessType":"initializeOnly",
                            "@type":"SFBool",
                            "@value":false
                          },
                          {
                            "@name":"set_toggle",
                            "@accessType":"inputOnly",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"toggle",
                            "@accessType":"initializeOnly",
                            "@appinfo":"whether to use DefaultMaterial or ToggleMaterial",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"toggle_changed",
                            "@accessType":"outputOnly",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"defaultMaterial",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode"
                          },
                          {
                            "@name":"toggleMaterial",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode"
                          },
                          {
                            "@name":"set_defaultMaterial",
                            "@accessType":"inputOnly",
                            "@appinfo":"provide replacement Material node",
                            "@type":"SFNode"
                          },
                          {
                            "@name":"set_toggleMaterial",
                            "@accessType":"inputOnly",
                            "@appinfo":"provide replacement Material node",
                            "@type":"SFNode"
                          },
                          {
                            "@name":"viewedMaterial",
                            "@accessType":"initializeOnly",
                            "@type":"SFNode",
                            "-children":[
                              { "Material":
                                {
                                  "@USE":"ViewedMaterialNode"
                                }
                              }
                            ]
                          }
                        ],
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"set_toggle",
                                "@protoField":"set_toggle"
                              },
                              {
                                "@nodeField":"toggle",
                                "@protoField":"toggle"
                              },
                              {
                                "@nodeField":"toggle_changed",
                                "@protoField":"toggle_changed"
                              },
                              {
                                "@nodeField":"defaultMaterial",
                                "@protoField":"defaultMaterial"
                              },
                              {
                                "@nodeField":"toggleMaterial",
                                "@protoField":"toggleMaterial"
                              },
                              {
                                "@nodeField":"set_defaultMaterial",
                                "@protoField":"set_defaultMaterial"
                              },
                              {
                                "@nodeField":"set_toggleMaterial",
                                "@protoField":"set_toggleMaterial"
                              }
                            ]
                        },
                        "#sourceCode":[
"",
"",
"ecmascript:",
"",
"function initialize ()",
"{",
"",
"   tracePrint ('initialize() begin...');",
"   if (defaultMaterial != null)",
"   {",
"\ttracePrint ('defaultMaterial.diffuseColor=' + defaultMaterial.diffuseColor.toString());",
"\tviewedMaterial.diffuseColor     = defaultMaterial.diffuseColor;",
"\tviewedMaterial.emissiveColor    = defaultMaterial.emissiveColor;",
"\tviewedMaterial.specularColor    = defaultMaterial.specularColor;",
"\tviewedMaterial.shininess        = defaultMaterial.shininess;",
"\tviewedMaterial.ambientIntensity = defaultMaterial.ambientIntensity;",
"\tviewedMaterial.transparency     = defaultMaterial.transparency;",
"\ttracePrint ('toggleMaterial.diffuseColor=' + toggleMaterial.diffuseColor.toString());",
"   }",
"   else alwaysPrint ('warning: no initialization Material node provided for defaultMaterial');",
"   if  (toggleMaterial == null)",
"        alwaysPrint ('warning: no initialization Material node provided for toggleMaterial');",
"",
"   tracePrint ('initialize() complete');",
"}",
"",
"function set_toggle (value, timestamp)",
"{",
"   if ((value == true) && (toggleMaterial != null))",
"   {",
"\ttracePrint ('set_toggle true, toggleMaterial.diffuseColor=' + toggleMaterial.diffuseColor.toString());",
"\tviewedMaterial.diffuseColor     = toggleMaterial.diffuseColor;",
"\tviewedMaterial.emissiveColor    = toggleMaterial.emissiveColor;",
"\tviewedMaterial.specularColor    = toggleMaterial.specularColor;",
"\tviewedMaterial.shininess        = toggleMaterial.shininess;",
"\tviewedMaterial.ambientIntensity = toggleMaterial.ambientIntensity;",
"\tviewedMaterial.transparency     = toggleMaterial.transparency;",
"   }",
"   else if (defaultMaterial != null)",
"   {",
"\ttracePrint ('set_toggle false, defaultMaterial.diffuseColor=' + defaultMaterial.diffuseColor.toString());",
"\tviewedMaterial.diffuseColor     = defaultMaterial.diffuseColor;",
"\tviewedMaterial.emissiveColor    = defaultMaterial.emissiveColor;",
"\tviewedMaterial.specularColor    = defaultMaterial.specularColor;",
"\tviewedMaterial.shininess        = defaultMaterial.shininess;",
"\tviewedMaterial.ambientIntensity = defaultMaterial.ambientIntensity;",
"\tviewedMaterial.transparency     = defaultMaterial.transparency;",
"   }",
"   toggle         = value; // remember state",
"   toggle_changed = value; // chain input boolean event to output event",
"   tracePrint ('set_toggle(' + value + ') complete');",
"}",
"",
"function set_defaultMaterial(newMaterial)",
"{",
"\tdefaultMaterial = newMaterial;",
"\ttracePrint('set_defaultMaterial = ' + newMaterial);",
"}",
"",
"function set_toggleMaterial(newMaterial)",
"{",
"\ttoggleMaterial = newMaterial;",
"\ttracePrint('set_toggleMaterial = ' + newMaterial);",
"}",
"",
"function tracePrint(outputString)",
"{",
"\tif (traceEnabled) Browser.println ('[MaterialToggle] ' + outputString);",
"}",
"function alwaysPrint(outputString)",
"{",
"\tBrowser.println ('[MaterialToggle] ' + outputString);",
"}",
"",
""
]
                      }
                    }
                  ]
              }
            }
          },
          {
            "#comment":"===================="
          },
          { "Anchor":
            {
              "@description":"MaterialToggleExample",
              "@parameter":["target=_blank"],
              "@url":["MaterialToggleExample.x3d","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialToggleExample.x3d","MaterialToggleExample.wrl","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialToggleExample.wrl"],
              "-children":[
                { "Shape":
                  {
                    "-geometry":
                      { "Text":
                        {
                          "@string":["MaterialTogglePrototype","defines a prototype","Click text to see example scene","MaterialToggleExample"],
                          "-fontStyle":
                            { "FontStyle":
                              {
                                "@justify":["MIDDLE","MIDDLE"],
                                "@size":0.9
                              }
                            }
                        }
                      },
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "Material":
                              {
                                "@diffuseColor":[1,1,0.2]
                              }
                            }
                        }
                      }
                  }
                }
              ]
            }
          }
        ]
    }
  }
}