[x3d-public] Proto expander. Scripts in protobodies without a DEF

Don Brutzman brutzman at nps.edu
Sat Jul 16 14:15:24 PDT 2016


Thanks for this trouble report.

I think the stylesheet is more thorough now about handling things like \n correctly in text blocks.

Updated test case attached.  Does it look OK now?

Updates stylesheet changes visible at

https://sourceforge.net/p/x3d/code/23351/
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/X3dToJson.xslt

Will rebuild all JSON example scenes tonite.


On 7/14/2016 6:24 PM, John Carlson wrote:
> A problem with the X3dToJson.xslt stylesheet, as reported before.  Stylesheet renders it as \\’ in the output JSON.   I am not quite sure what to do, but I should probably convert \\ to \\\\ until we get the newline in place.
>
>
>
> John
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>
>
> *From: *John Carlson <mailto:yottzumm at gmail.com>
> *Sent: *Thursday, July 14, 2016 9:17 PM
> *To: *Don Brutzman <mailto:brutzman at nps.edu>; Roy Walmsley <mailto:roy.walmsley at ntlworld.com>
> *Cc: *X3D Graphics public mailing list <mailto:x3d-public at web3d.org>
> *Subject: *RE: Proto expander. Scripts in protobodies without a DEF
>
>
>
> Yes, the script it broken.  The problem is highlighted in red.  It should be \n’
>
>
>
>                                 Browser.print ('diffuseColor=(' + red +',' + green + ',' + blue + ') newColor=' + newColor.toString() + '\');
>
>
>
>
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>
>
> *From: *John Carlson <mailto:yottzumm at gmail.com>
> *Sent: *Thursday, July 14, 2016 8:57 PM
> *To: *Don Brutzman <mailto:brutzman at nps.edu>; Roy Walmsley <mailto:roy.walmsley at ntlworld.com>
> *Cc: *X3D Graphics public mailing list <mailto:x3d-public at web3d.org>
> *Subject: *RE: Proto expander. Scripts in protobodies without a DEF
>
>
>
> I don’t know if the script is broken or something else.  The expanded version doesn’t work in any browser I tried.  The proto version works in at least octaga.  The original Proto version does not work in X3D JSON Loader (Cobweb).  The original Proto version does work in normal Cobweb.
>
>
>
> X3D JSON -> XML version without Proto Expander is here (broken in Cobweb):
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "http://www.web3d.org/specifications/x3d-3.3.dtd">
>
> <X3D  profile="Immersive" version="3.3" ><head><meta name="title" content="MaterialModulator.x3d"></meta>
>
> <meta name="description" content="Mimic a Material node and modulate fields as an animation effect"></meta>
>
> <meta name="hint" content="try changing the modulation script so that it goes from [0 ... 1] and then [1 ... 0] alternating, rather than abruptly shifting from 1 immediately back to 0."></meta>
>
> <meta name="creator" content="Don Brutzman"></meta>
>
> <meta name="created" content="10 March 2008"></meta>
>
> <meta name="modified" content="28 November 2014"></meta>
>
> <meta name="subject" content="X3D prototype requiring Script inputOutput fields"></meta>
>
> <meta name="Image" content="MaterialModulator.png"></meta>
>
> <meta name="identifier" content="http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter14-Prototypes/MaterialModulator.x3d"></meta>
>
> <meta name="generator" content="X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"></meta>
>
> <meta name="license" content="../license.html"></meta>
>
> </head>
>
> <Scene><ProtoDeclare name="MaterialModulator" appinfo="mimic a Material node and modulate fields as an animation effect"><ProtoInterface><field name="enabled" accessType="inputOutput" type="SFBool" value="true"></field>
>
> <field name="diffuseColor" accessType="inputOutput" type="SFColor" value="0.8 0.8 0.8"></field>
>
> <field name="emissiveColor" accessType="inputOutput" type="SFColor" value="0 0 0"></field>
>
> <field name="specularColor" accessType="inputOutput" type="SFColor" value="0 0 0"></field>
>
> <field name="transparency" accessType="inputOutput" type="SFFloat" value="0"></field>
>
> <field name="shininess" accessType="inputOutput" type="SFFloat" value="0.2"></field>
>
> <field name="ambientIntensity" accessType="inputOutput" type="SFFloat" value="0.2"></field>
>
> </ProtoInterface>
>
> <ProtoBody><Material DEF="MaterialNode"><IS><connect nodeField="diffuseColor" protoField="diffuseColor"></connect>
>
> <connect nodeField="emissiveColor" protoField="emissiveColor"></connect>
>
> <connect nodeField="specularColor" protoField="specularColor"></connect>
>
> <connect nodeField="transparency" protoField="transparency"></connect>
>
> <connect nodeField="shininess" protoField="shininess"></connect>
>
> <connect nodeField="ambientIntensity" protoField="ambientIntensity"></connect>
>
> </IS>
>
> </Material>
>
> <!--Only first node (the node type) is renderable, others are along for the ride--><Script DEF="MaterialModulatorScript"><field name="enabled" accessType="inputOutput" type="SFBool"></field>
>
> <field name="diffuseColor" accessType="inputOutput" type="SFColor"></field>
>
> <field name="newColor" accessType="outputOnly" type="SFColor"></field>
>
> <field name="clockTrigger" accessType="inputOnly" type="SFTime"></field>
>
> <IS><connect nodeField="enabled" protoField="enabled"></connect>
>
> <connect nodeField="diffuseColor" protoField="diffuseColor"></connect>
>
> </IS>
>
> <![CDATA[ecmascript:
>
> function initialize ()
>
> {
>
>     newColor = diffuseColor; // start with correct color
>
> }
>
>
>
> 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);
>
>                 if (enabled)
>
>                 {
>
>                                 Browser.print ('diffuseColor=(' + red +',' + green + ',' + blue + ') newColor=' + newColor.toString() + '\');
>
>                 }
>
> }
>
> ]]></Script>
>
> <!--Clock tickles Script to wake up and compute a new value--><ROUTE fromField="newColor" fromNode="MaterialModulatorScript" toField="diffuseColor" toNode="MaterialNode"></ROUTE>
>
> <TimeSensor DEF="ModulationClock" cycleInterval="0.1" loop="true"><IS><connect nodeField="enabled" protoField="enabled"></connect>
>
> </IS>
>
> </TimeSensor>
>
> <ROUTE fromField="cycleTime" fromNode="ModulationClock" toField="clockTrigger" toNode="MaterialModulatorScript"></ROUTE>
>
> </ProtoBody>
>
> </ProtoDeclare>
>
> <!--Rendered geometry for the ProtoInstance now follows prototype declaration--><Transform translation="0 1 0"><Shape><Sphere containerField="geometry"></Sphere>
>
> <Appearance containerField="appearance"><ProtoInstance containerField="material" name="MaterialModulator" DEF="MaterialModulatorInstance"><fieldValue containerField="material" name="enabled" value="true"></fieldValue>
>
> <fieldValue containerField="material" name="diffuseColor" value="0.5 0.1 0.1"></fieldValue>
>
> </ProtoInstance>
>
> </Appearance>
>
> </Shape>
>
> </Transform>
>
> <!--Selectable Text design pattern has transparent Box and TouchSensor description as a tooltip--><Transform translation="0 -2 0"><Shape><Text containerField="geometry" string=""enable/disable" "MaterialModulator""><FontStyle containerField="fontStyle" family=""SANS"" justify=""MIDDLE" "MIDDLE"" style="BOLD"></FontStyle>
>
> </Text>
>
> <Appearance containerField="appearance"><Material containerField="material" diffuseColor="0.9 0.9 0.9"></Material>
>
> </Appearance>
>
> </Shape>
>
> <Shape><Box containerField="geometry" size="8 2 0.001"></Box>
>
> <Appearance containerField="appearance"><Material containerField="material" transparency="1"></Material>
>
> </Appearance>
>
> </Shape>
>
> <!--Toggle text to enable/disable MaterialModulator--><TouchSensor DEF="TouchTextInterface" description="Select to enable/disable MaterialModulator"></TouchSensor>
>
> <BooleanToggle DEF="EventToggler"></BooleanToggle>
>
> <ROUTE fromField="isActive" fromNode="TouchTextInterface" toField="set_boolean" toNode="EventToggler"></ROUTE>
>
> <ROUTE fromField="toggle" fromNode="EventToggler" toField="enabled" toNode="MaterialModulatorInstance"></ROUTE>
>
> </Transform>
>
> </Scene>
>
> </X3D>
>
>
>
>
>
>
>


all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman
-------------- next part --------------
{ "X3D": {
    "encoding":"UTF-8",
    "@profile":"Immersive",
    "@version":"3.3",
    "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.3.xsd",
    "JSON schema":"http://www.web3d.org/specifications/x3d-3.3-JSONSchema.json",
    "head": {
        "meta": [
          {
            "@name":"title",
            "@content":"MaterialModulator.x3d"
          },
          {
            "@name":"description",
            "@content":"Mimic a Material node and modulate fields as an animation effect"
          },
          {
            "@name":"hint",
            "@content":"try changing the modulation script so that it goes from [0 ... 1] and then [1 ... 0] alternating, rather than abruptly shifting from 1 immediately back to 0."
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman"
          },
          {
            "@name":"created",
            "@content":"10 March 2008"
          },
          {
            "@name":"modified",
            "@content":"28 November 2014"
          },
          {
            "@name":"subject",
            "@content":"X3D prototype requiring Script inputOutput fields"
          },
          {
            "@name":"Image",
            "@content":"MaterialModulator.png"
          },
          {
            "@name":"identifier",
            "@content":"http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter14-Prototypes/MaterialModulator.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../license.html"
          },
          {
            "@name":"translated",
            "@content":"16 July 2016"
          },
          {
            "@name":"generator",
            "@content":"X3dToJson.xslt, http://www.web3d.org/x3d/stylesheets/X3dToJson.html"
          },
          {
            "@name":"warning",
            "@content":"An experimental version of X3D JSON encoding is used for this scene.  Status online at http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding"
          }
        ]
    },
    "Scene": {
        "-children":[
          { "ProtoDeclare":
            {
              "@name":"MaterialModulator",
              "@appinfo":"mimic a Material node and modulate fields as an animation effect",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"enabled",
                      "@accessType":"inputOutput",
                      "@type":"SFBool",
                      "@value":true
                    },
                    {
                      "@name":"diffuseColor",
                      "@accessType":"inputOutput",
                      "@type":"SFColor",
                      "@value":[0.8,0.8,0.8]
                    },
                    {
                      "@name":"emissiveColor",
                      "@accessType":"inputOutput",
                      "@type":"SFColor",
                      "@value":[0,0,0]
                    },
                    {
                      "@name":"specularColor",
                      "@accessType":"inputOutput",
                      "@type":"SFColor",
                      "@value":[0,0,0]
                    },
                    {
                      "@name":"transparency",
                      "@accessType":"inputOutput",
                      "@type":"SFFloat",
                      "@value":0.0
                    },
                    {
                      "@name":"shininess",
                      "@accessType":"inputOutput",
                      "@type":"SFFloat",
                      "@value":0.2
                    },
                    {
                      "@name":"ambientIntensity",
                      "@accessType":"inputOutput",
                      "@type":"SFFloat",
                      "@value":0.2
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    { "Material":
                      {
                        "@DEF":"MaterialNode",
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"diffuseColor",
                                "@protoField":"diffuseColor"
                              },
                              {
                                "@nodeField":"emissiveColor",
                                "@protoField":"emissiveColor"
                              },
                              {
                                "@nodeField":"specularColor",
                                "@protoField":"specularColor"
                              },
                              {
                                "@nodeField":"transparency",
                                "@protoField":"transparency"
                              },
                              {
                                "@nodeField":"shininess",
                                "@protoField":"shininess"
                              },
                              {
                                "@nodeField":"ambientIntensity",
                                "@protoField":"ambientIntensity"
                              }
                            ]
                        }
                      }
                    },
                    { "#comment":"Only first node (the node type) is renderable, others are along for the ride"
                    },
                    { "Script":
                      {
                        "@DEF":"MaterialModulatorScript",
                        "field": [
                          {
                            "@name":"enabled",
                            "@accessType":"inputOutput",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"diffuseColor",
                            "@accessType":"inputOutput",
                            "@type":"SFColor"
                          },
                          {
                            "@name":"newColor",
                            "@accessType":"outputOnly",
                            "@type":"SFColor"
                          },
                          {
                            "@name":"clockTrigger",
                            "@accessType":"inputOnly",
                            "@type":"SFTime"
                          }
                        ],
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"enabled",
                                "@protoField":"enabled"
                              },
                              {
                                "@nodeField":"diffuseColor",
                                "@protoField":"diffuseColor"
                              }
                            ]
                        },
                        "#sourceText":[
"ecmascript:",
"function initialize ()",
"{",
"    newColor = diffuseColor; // start with correct color",
"}",
"",
"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);",
"\tif (enabled)",
"\t{",
"\t\tBrowser.print ('diffuseColor=(' + red +',' + green + ',' + blue + ') newColor=' + newColor.toString() + '\n');",
"\t}",
"}"
]
                      }
                    },
                    { "#comment":"Clock tickles Script to wake up and compute a new value"
                    },
                    { "ROUTE":
                      {
                        "@fromField":"newColor",
                        "@fromNode":"MaterialModulatorScript",
                        "@toField":"diffuseColor",
                        "@toNode":"MaterialNode"
                      }
                    },
                    { "TimeSensor":
                      {
                        "@DEF":"ModulationClock",
                        "@cycleInterval":0.1,
                        "@loop":true,
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"enabled",
                                "@protoField":"enabled"
                              }
                            ]
                        }
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"cycleTime",
                        "@fromNode":"ModulationClock",
                        "@toField":"clockTrigger",
                        "@toNode":"MaterialModulatorScript"
                      }
                    }
                  ]
              }
            }
          },
          { "#comment":"Rendered geometry for the ProtoInstance now follows prototype declaration"
          },
          { "Transform":
            {
              "@translation":[0,1,0],
              "-children":[
                { "Shape":
                  {
                    "-geometry":
                      { "Sphere":
                        {
                        }
                      },
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "ProtoInstance":
                              {
                                "@name":"MaterialModulator",
                                "@DEF":"MaterialModulatorInstance",
                                "fieldValue": [
                                  {
                                    "@name":"enabled",
                                    "@value":true
                                  },
                                  {
                                    "@name":"diffuseColor",
                                    "@value":[0.5,0.1,0.1]
                                  }
                                ]
                              }
                            }
                        }
                      }
                  }
                }
              ]
            }
          },
          { "#comment":"Selectable Text design pattern has transparent Box and TouchSensor description as a tooltip"
          },
          { "Transform":
            {
              "@translation":[0,-2,0],
              "-children":[
                { "Shape":
                  {
                    "-geometry":
                      { "Text":
                        {
                          "@string":["enable/disable","MaterialModulator"],
                          "-fontStyle":
                            { "FontStyle":
                              {
                                "@family":["SANS"],
                                "@justify":["MIDDLE","MIDDLE"],
                                "@style":"BOLD"
                              }
                            }
                        }
                      },
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "Material":
                              {
                                "@diffuseColor":[0.9,0.9,0.9]
                              }
                            }
                        }
                      }
                  }
                },
                { "Shape":
                  {
                    "-geometry":
                      { "Box":
                        {
                          "@size":[8,2,0.001]
                        }
                      },
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "Material":
                              {
                                "@transparency":1
                              }
                            }
                        }
                      }
                  }
                },
                { "#comment":"Toggle text to enable/disable MaterialModulator"
                },
                { "TouchSensor":
                  {
                    "@DEF":"TouchTextInterface",
                    "@description":"Select to enable/disable MaterialModulator"
                  }
                },
                { "BooleanToggle":
                  {
                    "@DEF":"EventToggler"
                  }
                },
                { "ROUTE":
                  {
                    "@fromField":"isActive",
                    "@fromNode":"TouchTextInterface",
                    "@toField":"set_boolean",
                    "@toNode":"EventToggler"
                  }
                },
                { "ROUTE":
                  {
                    "@fromField":"toggle",
                    "@fromNode":"EventToggler",
                    "@toField":"enabled",
                    "@toNode":"MaterialModulatorInstance"
                  }
                }
              ]
            }
          }
        ]
    }
  }
}


More information about the x3d-public mailing list