[x3d-public] Trying to use X3dToJson.xslt in web page to produce JSON.

John Carlson yottzumm at gmail.com
Sun Nov 29 14:24:32 PST 2015


Okay, I have another one for you Don.  It has to do with MFRotation.  Apparently MFRotations in JSON output aren’t quoted or made into an array.  See attached JSON and X3D.  I am not sure if you’ve caught this yet, and I am on the track of something else, so here it is.

John

{ "X3D": {
    "@profile":"Full",
    "@version":3.3,
    "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.3.xsd",
    "Scene": {
        "-children":[
          { "NavigationInfo":
            {
            }
          },
          { "Viewpoint":
            {
              "@DEF":"Tour",
              "@description":"Tour Views"
            }
          },
          { "Viewpoint":
            {
              "@position":[0,0,4],
              "@description":"sphere in road"
            }
          },
          { "Background":
            {
              "@backUrl":"\"cubemap/BK.png\" \"http://coderextreme.net/X3DJSONLD/cubemap/BK.png\"",
              "@bottomUrl":"\"cubemap/BT.png\" \"http://coderextreme.net/X3DJSONLD/cubemap/BT.png\"",
              "@frontUrl":"\"cubemap/FR.png\" \"http://coderextreme.net/X3DJSONLD/cubemap/FR.png\"",
              "@leftUrl":"\"cubemap/LF.png\" \"http://coderextreme.net/X3DJSONLD/cubemap/LF.png\"",
              "@rightUrl":"\"cubemap/RT.png\" \"http://coderextreme.net/X3DJSONLD/cubemap/RT.png\"",
              "@topUrl":"\"cubemap/TP.png\" \"http://coderextreme.net/X3DJSONLD/cubemap/TP.png\""
            }
          },
          { "Transform":
            {
              "@DEF":"Rose01",
              "-children":[
                { "Shape":
                  {
                    "-geometry":[
                      { "Sphere":
                        {
                        }
                      }
                    ],
                    "-appearance":[
                      { "Appearance":
                        {
                          "@DEF":"_01_-_Default",
                          "-material":[
                            { "Material":
                              {
                                "@diffuseColor":[0.7,0.7,0.7],
                                "@specularColor":[0.5,0.5,0.5]
                              }
                            }
                          ],
                          "-texture":[
                            { "ComposedCubeMapTexture":
                              {
                                "@containerField":"texture",
                                "-back":[
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/BK.png","http://coderextreme.net/X3DJSONLD/cubemap/BK.png"],
                                      "@containerField":"back"
                                    }
                                  }
                                ],
                                "-bottom":[
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/BT.png","http://coderextreme.net/X3DJSONLD/cubemap/BT.png"],
                                      "@containerField":"bottom"
                                    }
                                  }
                                ],
                                "-front":[
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/FR.png","http://coderextreme.net/X3DJSONLD/cubemap/FR.png"],
                                      "@containerField":"front"
                                    }
                                  }
                                ],
                                "-left":[
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/LF.png","http://coderextreme.net/X3DJSONLD/cubemap/LF.png"],
                                      "@containerField":"left"
                                    }
                                  }
                                ],
                                "-right":[
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/RT.png","http://coderextreme.net/X3DJSONLD/cubemap/RT.png"],
                                      "@containerField":"right"
                                    }
                                  }
                                ],
                                "-top":[
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/TP.png","http://coderextreme.net/X3DJSONLD/cubemap/TP.png"],
                                      "@containerField":"top"
                                    }
                                  }
                                ]
                              }
                            }
                          ],
                          "-shaders":[
                            { "ComposedShader":
                              {
                                "@DEF":"ComposedShader",
                                "@containerField":"shaders",
                                "@language":"GLSL",
                                "field": [
                                  {
                                    "@name":"cube",
                                    "@accessType":"inputOutput",
                                    "@type":"SFInt32",
                                    "@value":0
                                  },
                                  {
                                    "@name":"chromaticDispertion",
                                    "@accessType":"inputOutput",
                                    "@type":"SFVec3f",
                                    "@value":[0.98,1,1.033]
                                  },
                                  {
                                    "@name":"bias",
                                    "@accessType":"inputOutput",
                                    "@type":"SFFloat",
                                    "@value":0.5
                                  },
                                  {
                                    "@name":"scale",
                                    "@accessType":"inputOutput",
                                    "@type":"SFFloat",
                                    "@value":0.5
                                  },
                                  {
                                    "@name":"power",
                                    "@accessType":"inputOutput",
                                    "@type":"SFFloat",
                                    "@value":2
                                  }
                                ],
                                "-parts":[
                                  { "ShaderPart":
                                    {
                                      "@url":["bubbles.vs","http://coderextreme.net/X3DJSONLD/bubbles.vs"],
                                      "@containerField":"parts"
                                    }
                                  },
                                  { "ShaderPart":
                                    {
                                      "@url":["bubbles.fs","http://coderextreme.net/X3DJSONLD/bubbles.fs"],
                                      "@containerField":"parts",
                                      "@type":"FRAGMENT"
                                    }
                                  }
                                ]
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                }
              ]
            }
          },
          { "TimeSensor":
            {
              "@DEF":"TourTime",
              "@cycleInterval":5,
              "@loop":true
            }
          },
          { "PositionInterpolator":
            {
              "@DEF":"TourPosition",
              "@key":[0,1],
              "@keyValue":[0,0,10,0,0,-10]
            }
          },
          { "OrientationInterpolator":
            {
              "@DEF":"TourOrientation",
              "@key":[0,1],
              "@keyValue":[0,1,0,0,0,1,0,3.1416]
            }
          },
          { "Script":
            {
              "@DEF":"RandomTourTime",
              "field": [
                {
                  "@name":"set_fraction",
                  "@accessType":"inputOnly",
                  "@type":"SFFloat"
                },
                {
                  "@name":"value_changed",
                  "@accessType":"inputOutput",
                  "@type":"SFFloat",
                  "@value":0
                },
                {
                  "@name":"orientations",
                  "@accessType":"inputOutput",
                  "@type":"MFRotation",
                  "@value":0 1 0 0 0 1 0 -1.57 0 1 0 3.14 0 1 0 1.57 0 1 0 0 1 0 0 -1.57 0 1 0 0 1 0 0 1.57 0 1 0 0
                },
                {
                  "@name":"positions",
                  "@accessType":"inputOutput",
                  "@type":"MFVec3f",
                  "@value":[0,0,10,-10,0,0,0,0,-10,10,0,0,0,0,10,0,10,0,0,0,10,0,-10,0,0,0,10]
                },
                {
                  "@name":"position_changed",
                  "@accessType":"outputOnly",
                  "@type":"MFVec3d"
                },
                {
                  "@name":"orientation_changed",
                  "@accessType":"outputOnly",
                  "@type":"MFRotation"
                }
              ],
              "#sourceText":[
"ecmascript:",
"            ",
"         ",
"               function set_fraction(value) {",
"                        //var positions = [[0, 0, 10], [-10, 0, 0], [0, 0, -10], [10, 0, 0], [0, 0, 10], [0, 10, 0], [0, 0, 10], [0, -10, 0], [0, 0, 10]];",
"                        //var orientations = [[0, 1, 0, 0], [0, 1, 0, -1.57], [0, 1, 0, 3.14], [0, 1, 0, 1.57], [0, 1, 0, 0] [1, 0, 0, -1.57], [0, 1, 0, 0], [1, 0, 0, 1.57], [0, 1, 0, 0]];",
"                    //Browser.println(value);",
"                        var ov = value_changed;",
"                        Browser.println(ov);      ",
"                        //Browser.println(positions.length);                  ",
"\t\t\tdo {",
"\t\t\t\tvalue_changed = Math.round(Math.random()*positions.length);",
"\t\t\t} while (value_changed === ov);",
"                        Browser.println(value_changed);",
"                        var vc = value_changed;",
"                        ",
"                        Browser.println(orientations[ov]);",
"                        Browser.println(orientations[vc]);",
"                        orientation_changed[0] = new SFRotation(orientations[ov][0], orientations[ov][1], orientations[ov][2], orientations[ov][3]);",
"                        orientation_changed[1] = new SFRotation(orientations[vc][0], orientations[vc][1], orientations[vc][2], orientations[vc][3]);",
"                        Browser.println(positions[ov]);",
"                        Browser.println(positions[vc]);",
"\t\t\tposition_changed = new MFVec3f();",
"                        position_changed[0] = new SFVec3f(positions[ov][0],positions[ov][1],positions[ov][2]);",
"                        position_changed[1] = new SFVec3f(positions[vc][0],positions[vc][1],positions[vc][2]);",
"                    // }",
"               }"
]
            }
          }
        ],
        "ROUTE": [
          {
            "@fromNode":"TourTime",
            "@fromField":"cycleTime",
            "@toNode":"RandomTourTime",
            "@toField":"set_fraction"
          },
          {
            "@fromNode":"RandomTourTime",
            "@fromField":"orientation_changed",
            "@toNode":"TourOrientation",
            "@toField":"keyValue"
          },
          {
            "@fromNode":"RandomTourTime",
            "@fromField":"position_changed",
            "@toNode":"TourPosition",
            "@toField":"keyValue"
          },
          {
            "@fromNode":"TourTime",
            "@fromField":"fraction_changed",
            "@toNode":"TourOrientation",
            "@toField":"set_fraction"
          },
          {
            "@fromNode":"TourOrientation",
            "@fromField":"value_changed",
            "@toNode":"Tour",
            "@toField":"set_orientation"
          },
          {
            "@fromNode":"TourTime",
            "@fromField":"fraction_changed",
            "@toNode":"TourPosition",
            "@toField":"set_fraction"
          },
          {
            "@fromNode":"TourPosition",
            "@fromField":"value_changed",
            "@toNode":"Tour",
            "@toField":"set_position"
          }
        ]
    }
  }
}

<?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='Full' version='3.3' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.3.xsd' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance'>
    <Scene>
	<NavigationInfo></NavigationInfo>
        <Viewpoint DEF='Tour' description='Tour Views'/>
        <Viewpoint position='0 0 4' description='sphere in road'/>
        <Background backUrl='"cubemap/BK.png" "http://coderextreme.net/X3DJSONLD/cubemap/BK.png"' bottomUrl='"cubemap/BT.png" "http://coderextreme.net/X3DJSONLD/cubemap/BT.png"' frontUrl='"cubemap/FR.png" "http://coderextreme.net/X3DJSONLD/cubemap/FR.png"' leftUrl='"cubemap/LF.png" "http://coderextreme.net/X3DJSONLD/cubemap/LF.png"' rightUrl='"cubemap/RT.png" "http://coderextreme.net/X3DJSONLD/cubemap/RT.png"' topUrl='"cubemap/TP.png" "http://coderextreme.net/X3DJSONLD/cubemap/TP.png"'/>
        <Transform DEF='Rose01'>
            <Shape>
                <Sphere/>
                <Appearance DEF='_01_-_Default'>
                    <Material diffuseColor='0.7 0.7 0.7' specularColor='0.5 0.5 0.5'/>
                    <ComposedCubeMapTexture containerField='texture'>
                        <ImageTexture url='"cubemap/BK.png" "http://coderextreme.net/X3DJSONLD/cubemap/BK.png"' containerField='back'/>
                        <ImageTexture url='"cubemap/BT.png" "http://coderextreme.net/X3DJSONLD/cubemap/BT.png"' containerField='bottom'/>
                        <ImageTexture url='"cubemap/FR.png" "http://coderextreme.net/X3DJSONLD/cubemap/FR.png"' containerField='front'/>
                        <ImageTexture url='"cubemap/LF.png" "http://coderextreme.net/X3DJSONLD/cubemap/LF.png"' containerField='left'/>
                        <ImageTexture url='"cubemap/RT.png" "http://coderextreme.net/X3DJSONLD/cubemap/RT.png"' containerField='right'/>
                        <ImageTexture url='"cubemap/TP.png" "http://coderextreme.net/X3DJSONLD/cubemap/TP.png"' containerField='top'/>
                    </ComposedCubeMapTexture>
                    <ComposedShader DEF='ComposedShader' containerField='shaders' language='GLSL'>
                        <field name='cube' accessType='inputOutput' type='SFInt32' value='0'/>
                        <field name='chromaticDispertion' accessType='inputOutput' type='SFVec3f' value='0.98 1 1.033'/>
                        <field name='bias' accessType='inputOutput' type='SFFloat' value='0.5'/>
                        <field name='scale' accessType='inputOutput' type='SFFloat' value='0.5'/>
                        <field name='power' accessType='inputOutput' type='SFFloat' value='2'/>
                        <ShaderPart url='"bubbles.vs" "http://coderextreme.net/X3DJSONLD/bubbles.vs"' containerField='parts'/>
                        <ShaderPart url='"bubbles.fs" "http://coderextreme.net/X3DJSONLD/bubbles.fs"' containerField='parts' type='FRAGMENT'/>
                    </ComposedShader>
                </Appearance>
            </Shape>
        </Transform>
        <TimeSensor DEF='TourTime' cycleInterval='5' loop='true'/>
        <PositionInterpolator DEF='TourPosition' key='0 1' keyValue='0 0 10 0 0 -10'/>
        <OrientationInterpolator DEF='TourOrientation' key='0 1' keyValue='0 1 0 0 0 1 0 3.1416'/>
        <Script DEF='RandomTourTime'>
            <field accessType='inputOnly' name='set_fraction' type='SFFloat'/>
            <field name='value_changed' accessType='inputOutput' type='SFFloat' value='0'/>
	    <field name='orientations' accessType='inputOutput' type='MFRotation' value='0,1,0,0,0,1,0,-1.57,0,1,0,3.14,0,1,0,1.57,0,1,0,0,1,0,0,-1.57,0,1,0,0,1,0,0,1.57,0,1,0,0'/>
            <field name='positions' accessType='inputOutput' type='MFVec3f' value='0,0,10,-10,0,0,0,0,-10,10,0,0,0,0,10,0,10,0,0,0,10,0,-10,0,0,0,10'/>
            <field name='position_changed' accessType='outputOnly' type='MFVec3d'/>
            <field name='orientation_changed' accessType='outputOnly' type='MFRotation'/>
            ecmascript:
            
         
               function set_fraction(value) {
                        //var positions = [[0, 0, 10], [-10, 0, 0], [0, 0, -10], [10, 0, 0], [0, 0, 10], [0, 10, 0], [0, 0, 10], [0, -10, 0], [0, 0, 10]];
                        //var orientations = [[0, 1, 0, 0], [0, 1, 0, -1.57], [0, 1, 0, 3.14], [0, 1, 0, 1.57], [0, 1, 0, 0] [1, 0, 0, -1.57], [0, 1, 0, 0], [1, 0, 0, 1.57], [0, 1, 0, 0]];
                    //Browser.println(value);
                        var ov = value_changed;
                        Browser.println(ov);      
                        //Browser.println(positions.length);                  
			do {
				value_changed = Math.round(Math.random()*positions.length);
			} while (value_changed === ov);
                        Browser.println(value_changed);
                        var vc = value_changed;
                        
                        Browser.println(orientations[ov]);
                        Browser.println(orientations[vc]);
                        orientation_changed[0] = new SFRotation(orientations[ov][0], orientations[ov][1], orientations[ov][2], orientations[ov][3]);
                        orientation_changed[1] = new SFRotation(orientations[vc][0], orientations[vc][1], orientations[vc][2], orientations[vc][3]);
                        Browser.println(positions[ov]);
                        Browser.println(positions[vc]);
			position_changed = new MFVec3f();
                        position_changed[0] = new SFVec3f(positions[ov][0],positions[ov][1],positions[ov][2]);
                        position_changed[1] = new SFVec3f(positions[vc][0],positions[vc][1],positions[vc][2]);
                    // }
               }
        </Script>
        <ROUTE fromNode='TourTime' fromField='cycleTime' toNode='RandomTourTime' toField='set_fraction'/>
        <ROUTE fromNode='RandomTourTime' fromField='orientation_changed' toNode='TourOrientation' toField='keyValue'/>
        <ROUTE fromNode='RandomTourTime' fromField='position_changed' toNode='TourPosition' toField='keyValue'/>
        <ROUTE fromNode='TourTime' fromField='fraction_changed' toNode='TourOrientation' toField='set_fraction'/>
        <ROUTE fromNode='TourOrientation' fromField='value_changed' toNode='Tour' toField='set_orientation'/>
        <ROUTE fromNode='TourTime' fromField='fraction_changed' toNode='TourPosition' toField='set_fraction'/>
        <ROUTE fromNode='TourPosition' fromField='value_changed' toNode='Tour' toField='set_position'/>
    </Scene>
</X3D>




More information about the x3d-public mailing list