[x3d-public] X3D JSON encoding - floats with leading/trailing zeroes by decimal points; comments improved; TestJsonEncoding.x3d

Don Brutzman brutzman at nps.edu
Sun Mar 29 02:39:27 PDT 2015


Thanks for the great diagnoses John.

Several updates in latest stylesheet.
	http://www.web3d.org/x3d/stylesheets/X3dToJson.xslt
	https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/X3dToJson.xslt

a. JSON requires that float values have leading zero prior to decimal point, and trailing zero after decimal point.
b. Comments are each mapped as JSON objects if parent element has no attributes, otherwise mapped as name:value pair.  Examples:

  { "#comment":"excerpted from HelloWorld.x3d" },

or

   "#comment":"Test leading zeroes inserted before (and trailing zeroes inserted after) decimal points",

c. Still TODO: handling multiple comments within a single element.

d. Build scripts applying jslint with each conversion.

e. Created new test scene TestJsonEncoding.x3d, attached.  Will appear at

http://www.web3d.org/x3d/content/examples/Basic/development/TestJsonEncoding.x3d
http://www.web3d.org/x3d/content/examples/Basic/development/TestJsonEncoding.json

f. List of additional TODO items maintained in the stylesheet.


On 3/26/2015 11:24 AM, John Carlson wrote:
> But only if there's just one comment in the object.  More than one would require a #comment key followed by an array of comments
>
> On Thu, Mar 26, 2015 at 1:23 PM, John Carlson <yottzumm at gmail.com <mailto:yottzumm at gmail.com>> wrote:
>
>     There's an error in comments too.  I think this was mentioned before.  The { "#comment here is illegal, because it's the comment object is being used as a key in an object. Key's have "" around them.  It would work without the braces.
>
[...]
>
>     On Thu, Mar 26, 2015 at 1:10 PM, John Carlson <yottzumm at gmail.com <mailto:yottzumm at gmail.com>> wrote:
>
>         I think there's an error in the X3D JSON encoding. Numbers can't start with a leading decimal point.  See http://json.org/number.gif  Also, JQuery's $.getJSON will catch these.  getJSON will fail silently unless you handle the failure and your scene won't load.  More later


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 --------------
A non-text attachment was scrubbed...
Name: TestJsonEncoding.x3d
Type: model/x3d+xml
Size: 2264 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20150329/eca41d17/attachment.x3d>
-------------- next part --------------
[
  { "X3D":
    {
      "@profile":"Immersive",
      "@version":3.0,
      "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.0.xsd",
      "head":[
        { "meta":
          {
            "@content":"TestJsonEncoding.x3d",
            "@name":"title"
          }
        },
        { "meta":
          {
            "@content":"Don Brutzman",
            "@name":"creator"
          }
        },
        { "meta":
          {
            "@content":"29 March 2015",
            "@name":"created"
          }
        },
        { "meta":
          {
            "@content":"29 March 2015",
            "@name":"modified"
          }
        },
        { "meta":
          {
            "@content":"Ensure X3dToJson xslt translator properly converts X3D to JavaScript Object Notation (JSON).",
            "@name":"description"
          }
        },
        { "meta":
          {
            "@content":"http://www.web3d.org/x3d/content/examples/Basic/development/TestJsonEncoding.x3d",
            "@name":"identifier"
          }
        },
        { "meta":
          {
            "@content":"http://www.web3d.org/x3d/stylesheets/X3dToJson.xslt",
            "@name":"reference"
          }
        },
        { "meta":
          {
            "@content":"X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit",
            "@name":"generator"
          }
        },
        { "meta":
          {
            "@content":"../license.html",
            "@name":"license"
          }
        }
      ],
      "Scene":[
        { "#comment":"excerpted from HelloWorld.x3d" },
        { "Group":
          {
            "@bboxCenter":[0, 0, 0],
            "@bboxSize":[-1, -1, -1],
            "-children":[
              { "Viewpoint":
                {
                  "@DEF":"ViewUpClose",
                  "@centerOfRotation":[0, -1, 0],
                  "@description":"Hello world!",
                  "@position":[0, -1, 7],
                  "@fieldOfView":0.7854,
                  "@jump":true,
                  "@orientation":[0, 0, 1, 0]
                }
              },
              { "Transform":
                {
                  "@rotation":[0, 1, 0, 3],
                  "@center":[0, 0, 0],
                  "@scale":[1, 1, 1],
                  "@scaleOrientation":[0, 0, 1, 0],
                  "@translation":[0, 0, 0],
                  "@bboxCenter":[0, 0, 0],
                  "@bboxSize":[-1, -1, -1],
                  "-children":[
                    { "Shape":
                      {
                        "@bboxCenter":[0, 0, 0],
                        "@bboxSize":[-1, -1, -1],
                        "-geometry":[
                          { "Sphere":
                            {
                              "@radius":1,
                              "@solid":true
                            }
                          }
                        ],
                        "-appearance":[
                          { "Appearance":
                            {
                              "#comment":"Test leading zeroes inserted before (and trailing zeroes inserted after) decimal points",
                              "-material":[
                                { "Material":
                                  {
                                    "@DEF":"MaterialLightBlue",
                                    "@diffuseColor":[0.1, 0.5, 1.0],
                                    "@ambientIntensity":0.2,
                                    "@emissiveColor":[0, 0, 0],
                                    "@shininess":0.2,
                                    "@specularColor":[0, 0, 0],
                                    "@transparency":0
                                  }
                                }
                              ],
                              "-texture":[
                                { "ImageTexture":
                                  {
                                    "@DEF":"ImageCloudlessEarth",
                                    "@url":["earth-topo.png", "earth-topo.jpg", "earth-topo-small.gif", "http://www.web3d.org/x3d/content/examples/Basic/earth-topo.png", "http://www.web3d.org/x3d/content/examples/Basic/earth-topo.jpg", "http://www.web3d.org/x3d/content/examples/Basic/earth-topo-small.gif"],
                                    "@repeatS":true,
                                    "@repeatT":true
                                  }
                                }
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              { "Transform":
                {
                  "@translation":[0, -2, 0],
                  "@center":[0, 0, 0],
                  "@rotation":[0, 0, 1, 0],
                  "@scale":[1, 1, 1],
                  "@scaleOrientation":[0, 0, 1, 0],
                  "@bboxCenter":[0, 0, 0],
                  "@bboxSize":[-1, -1, -1],
                  "-children":[
                    { "Shape":
                      {
                        "@bboxCenter":[0, 0, 0],
                        "@bboxSize":[-1, -1, -1],
                        "-geometry":[
                          { "Text":
                            {
                              "@DEF":"TextMessage",
                              "@string":["Hello", "world!"],
                              "@maxExtent":0.0,
                              "@solid":false,
                              "-fontStyle":[
                                { "FontStyle":
                                  {
                                    "@justify":["MIDDLE", "MIDDLE"],
                                    "@family":["SERIF"],
                                    "@horizontal":true,
                                    "@leftToRight":true,
                                    "@size":1.0,
                                    "@spacing":1.0,
                                    "@style":"PLAIN",
                                    "@topToBottom":true
                                  }
                                }
                              ]
                            }
                          }
                        ],
                        "-appearance":[
                          { "Appearance":
                            {
                              "-material":[
                                { "Material":
                                  {
                                    "@USE":"MaterialLightBlue",
                                    "@ambientIntensity":0.2,
                                    "@diffuseColor":[0.8, 0.8, 0.8],
                                    "@emissiveColor":[0, 0, 0],
                                    "@shininess":0.2,
                                    "@specularColor":[0, 0, 0],
                                    "@transparency":0
                                  }
                                }
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
]


More information about the x3d-public mailing list