{ "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":"MaterialModulatorPrototypeExpanded.x3d"
          },
          {
            "@name":"description",
            "@content":"Provide example for expansion of a MaterialModulator as regular X3D nodes, rather than a ProtoDeclare/ProtoInstance combination. MaterialModulator mimics a Material node and modulates diffuseColor field as an animation effect."
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman, John Carlson, Roy Walmsley"
          },
          {
            "@name":"created",
            "@content":"2 July 2016"
          },
          {
            "@name":"modified",
            "@content":"15 July 2025"
          },
          {
            "@name":"subject",
            "@content":"X3D prototype expander, IS/connect, Script inputOutput field"
          },
          {
            "@name":"Image",
            "@content":"MaterialModulator.png"
          },
          {
            "@name":"reference",
            "@content":"MaterialModulator.x3d"
          },
          {
            "@name":"reference",
            "@content":"JSON prototype expander https://github.com/coderextreme/X3DJSONLD"
          },
          {
            "@name":"TODO",
            "@content":"Create corresponding web page describing Prototype Expander design."
          },
          {
            "@name":"TODO",
            "@content":"Create stylesheet converter matching this Prototype Expander design pattern."
          },
          {
            "@name":"TODO",
            "@content":"Add external ROUTEs to original example as a further test case for Prototype Expander design."
          },
          {
            "@name":"reference",
            "@content":"https://github.com/coderextreme/X3DJSONLD/blob/master/PrototypeExpander.js"
          },
          {
            "@name":"reference",
            "@content":"https://github.com/coderextreme/X3DJSONLD/blob/master/ServerPrototypeExpander.js"
          },
          {
            "@name":"reference",
            "@content":"X3D Tooltips: ProtoBody https://www.web3d.org/x3d/content/X3dTooltips.html#ProtoBody"
          },
          {
            "@name":"reference",
            "@content":"4.4.4.3 PROTO definition semantics https://www.web3d.org/specifications/X3Dv4/ISO-IEC19775-1v4-IS/Part01/concepts.html#PROTOdefinitionsemantics"
          },
          {
            "@name":"reference",
            "@content":"[x3d-public] Prototype Expander, Question on design of instance expansions: http://web3d.org/pipermail/x3d-public_web3d.org/2016-July/004982.html"
          },
          {
            "@name":"identifier",
            "@content":"https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter14Prototypes/MaterialModulatorPrototypeExpanded.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../license.html"
          },
          {
            "@name":"translated",
            "@content":"17 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":"MaterialModulatorPrototypeExpanded.x3d"
            }
          },
          { "Shape":
            {
              "-geometry":
                { "Sphere":
                  {
                  }
                },
              "-appearance":
                { "Appearance":
                  {
                    "-children":[
                      {
                        "#comment":"Prototype Expander design note: only first node (the node type) of the prototype is substituted here."
                      }
                    ],
                    "-material":
                      { "Material":
                        {
                          "@DEF":"MaterialModulatorNodeExpanded1",
                          "@diffuseColor":[0.5,0.1,0.1],
                          "-children":[
                            {
                              "#comment":"Prototype Expander design note: no children nodes found in originally defined initial ProtoBody node, so no contained child nodes appear here"
                            }
                          ]
                        }
                      }
                  }
                }
            }
          },
          {
            "#comment":"Prototype Expander design note: only first node (the node type) of the prototype is renderable above. when Switch is first allowed"
          },
          { "Switch":
            {
              "@DEF":"HideAdditionalPrototypeBodyNodesExpanded1",
              "@whichChoice":-1,
              "-children":[
                {
                  "#comment":"Prototype Expander design note: all children inside a Switch continue to receive/send events."
                },
                { "Group":
                  {
                    "-children":[
                      {
                        "#comment":"Prototype Expander design note: additional follow-on nodes from the original ProtoBody are placed here."
                      },
                      { "Script":
                        {
                          "@DEF":"MaterialModulatorScriptExpanded1",
                          "field": [
                            {
                              "@name":"enabled",
                              "@accessType":"inputOutput",
                              "@type":"SFBool",
                              "@value":true
                            },
                            {
                              "@name":"diffuseColor",
                              "@accessType":"inputOutput",
                              "@type":"SFColor",
                              "@value":[0.5,0.1,0.1]
                            },
                            {
                              "@name":"newColor",
                              "@accessType":"outputOnly",
                              "@type":"SFColor"
                            },
                            {
                              "@name":"clockTrigger",
                              "@accessType":"inputOnly",
                              "@type":"SFTime"
                            }
                          ],
                          "#sourceCode":[
"",
"",
"ecmascript:",
"function initialize ()",
"{",
"    newColor     = diffuseColor; // start with original color",
"//  diffuseColor = diffuseColor; // retain original color, silence warning",
"}",
"function clockTrigger (timeValue)",
"{",
"    if (!enabled) return;",
"    red   = newColor.r;",
"    green = newColor.g;",
"    blue  = newColor.b;",
"",
"    // note different modulation rates for each color component, % is modulus operator",
"    newColor = new SFColor ((red + 0.02) % 1, (green + 0.03) % 1, (blue + 0.04) % 1);   ",
"    Browser.println ('diffuseColor=(' + red +',' + green + ',' + blue + ') newColor=' + newColor.toString());",
"}",
"function set_enabled (newValue)",
"{",
"\tenabled = newValue;",
"}",
"function set_diffuseColor (newValue)",
"{",
"    newColor = newValue;",
"}",
"",
""
]
                        }
                      },
                      {
                        "#comment":"Clock tickles Script to wake up and compute a new value"
                      },
                      { "ROUTE":
                        {
                          "@fromField":"newColor",
                          "@fromNode":"MaterialModulatorScriptExpanded1",
                          "@toField":"diffuseColor",
                          "@toNode":"MaterialModulatorNodeExpanded1"
                        }
                      },
                      { "TimeSensor":
                        {
                          "@DEF":"ModulationClockExpanded1",
                          "@cycleInterval":0.1,
                          "@loop":true
                        }
                      },
                      { "ROUTE":
                        {
                          "@fromField":"cycleTime",
                          "@fromNode":"ModulationClockExpanded1",
                          "@toField":"clockTrigger",
                          "@toNode":"MaterialModulatorScriptExpanded1"
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
    }
  }
}