[x3d-public] JSON Encoding

Don Brutzman brutzman at nps.edu
Mon Dec 21 15:40:52 PST 2015


Thanks Cecile, very interesting.  Additional questions:

1.  Focusing on object-dereferencing accessor syntax is really important and we should probably start doing this in all our syntax examples.

>	"*data.appearance.material.diffuseColor*"

In the proposed alternative example (again attached), what would the full object reference from the top of the scene graph be?  Something like

	data.X3D.Scene['-children'].Group['-children'].Transform[1]['-children'].Shape['appearance'].Appearance['-material'].Material['@diffuseColor']


2.  A code snippet that showed how to test such a reference in node.js console would be helpful...


3.Wondering what is the formal status of JSON5?  Am not finding that it is specified anywhere.

Incidentally the syntax in your JSON5 example looks somewhat reminiscent of jQuery library calls.


On 12/21/2015 2:29 PM, Cecile Muller wrote:
> Good evening
>
>
> Let's take this example from the mailing-list:
>
> { "Shape":
> {
> "-content": [
> { "#comment":"Sphere begin"},
> { "Sphere":
> {
> }
> },
> { "#comment":"Sphere complete, Appearance begin"},
> { "Appearance":
> {
> "-content": [
> { "#comment":"Material begin"},
> { "Material":
> {
> "@DEF":"MaterialLightBlue",
> "@diffuseColor":[0.1,0.5,1]
> }
> },
> { "#comment":"Material complete, ImageTexture begin"},
> { "ImageTexture":
> {
> "@DEF":"ImageCloudlessEarth",
> "@url":["earth-topo.png”]
> }
> },
> { "#comment":"ImageTexture complete"}
> ]
> }
> },
> { "#comment":"Appearance complete"}
> ]
> }
> }
>
> Given a reference "data" to the root of the structure, you would have to use this to access the color:
>   "*data.Shape['-content'][3].Appearance['-content'][1].Material['@diffuseColor']*"
> which is quite a mouthful.
>
>
> Compare to this JSON5 structure instead:
>
> {
> "$": "Shape",
>
> // Sphere begins
> "geometry": {
> "$": "Sphere"
> },
>
> // Sphere complete, Appearance begin
> "appearance": {
> "$": "Appearance",
> "material": {
> "$": "Material",
> "$DEF": "MaterialLightBlue",
> "diffuseColor": [0.1, 0.5, 1]
> },
>
> // Material complete, ImageTexture begin
> "texture": {
> "$": "ImageTexture",
> "$DEF": "ImageCloudlessEarth",
> "url": ["earth-topo.png"]
> }
> // ImageTexture complete
> }
> // Appearance complete
> }
>
> This time, you can access the color simply using: "*data.appearance.material.diffuseColor*".
>
>
> See you,
> Cecile

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": {
    "@profile":"Immersive",
    "@version":3.3,
    "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.3.xsd",
    "head": {
        "meta": [
          {
            "@name":"title",
            "@content":"HelloWorldCommented.x3d"
          },
          {
            "@name":"description",
            "@content":"Numerous comments added to simple X3D scene example for testing JSON encoding alternatives."
          },
          {
            "@name":"created",
            "@content":"19 December 2015"
          },
          {
            "@name":"modified",
            "@content":"19 December 2015"
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman"
          },
          {
            "@name":"reference",
            "@content":"HelloWorldCommentedOriginalEncoding.json"
          },
          {
            "@name":"reference",
            "@content":"HelloWorldCommentedAlternativeEncoding.json"
          },
          {
            "@name":"identifier",
            "@content":"http://X3dGraphics.com/examples/X3dForAdvancedModeling/HelloWorldScenes/HelloWorldCommented.x3d"
          },
          {
            "@name":"license",
            "@content":"http://www.web3d.org/x3d/content/examples/license.html"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"
          }
        ]
    },
    "Scene": {
        "-children":[
          { "#comment":"Example scene to illustrate comments interspersed among X3D nodes and fields (XML elements and attributes)"},
          { "#comment":"WorldInfo begin"},
          { "WorldInfo":
            {
              "@title":"Hello world!"
            }
          },
          { "#comment":"WorldInfo complete, Group begin"},
          { "Group":
            {
              "-children":[
                { "#comment":"Viewpoint begin"},
                { "Viewpoint":
                  {
                    "@DEF":"ViewUpClose",
                    "@centerOfRotation":[0,-1,0],
                    "@description":"Hello world!",
                    "@position":[0,-1,7]
                  }
                },
                { "#comment":"Viewpoint complete, Transform begin"},
                { "Transform":
                  {
                    "@rotation":[0,1,0,3],
                    "-children":[
                      { "#comment":"Shape begin"},
                      { "Shape":
                        {
                          "-children":[
                            { "#comment":"Sphere begin"},
                            { "#comment":"Sphere complete, Appearance begin"},
                            { "#comment":"Appearance complete"}
                          ],
                          "-geometry":[
                            { "Sphere":
                              {
                              }
                            }
                          ],
                          "-appearance":[
                            { "Appearance":
                              {
                                "-children":[
                                 { "#comment":"Material begin"},
                                 { "#comment":"Material complete, ImageTexture begin"},
                                 { "#comment":"ImageTexture complete"}
                                ],
                                "-material":[
                                  { "Material":
                                    {
                                      "@DEF":"MaterialLightBlue",
                                      "@diffuseColor":[0.1,0.5,1]
                                    }
                                  }
                                ],
                                "-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"]
                                    }
                                  }
                                ]
                              }
                            }
                          ]
                        }
                      },
                      { "#comment":"Shape complete"}
                    ]
                  }
                },
                { "#comment":"Transform complete, Transform begin"},
                { "Transform":
                  {
                    "@translation":[0,-2,0],
                    "-children":[
                      { "#comment":"Shape begin"},
                      { "Shape":
                        {
                          "-children":[
                            { "#comment":"Text begin"},
                            { "#comment":"Text complete, Appearance begin"},
                            { "#comment":"Appearance complete"}
                          ],
                          "-geometry":[
                            { "Text":
                              {
                                "@DEF":"TextMessage",
                                "@string":["Hello","world!"],
                                "-children":[
                                  { "#comment":"FontStyle begin"},
                                  { "#comment":"FontStyle complete"}
                                ],
                                "-fontStyle":[
                                  { "FontStyle":
                                    {
                                      "@justify":["MIDDLE","MIDDLE"]
                                    }
                                  }
                                ]
                              }
                            }
                          ],
                          "-appearance":[
                            { "Appearance":
                              {
                                "-children":[
                                  { "#comment":"Material begin"},
                                  { "#comment":"Material complete"}
                                ],
                                "-material":[
                                  { "Material":
                                    {
                                      "@USE":"MaterialLightBlue"
                                    }
                                  }
                                ]
                              }
                            }
                          ]
                        }
                      },
                      { "#comment":"Shape complete"}
                    ]
                  }
                },
                { "#comment":"Transform complete"}
              ]
            }
          },
          { "#comment":"Group complete"}
        ]
    }
  }
}


More information about the x3d-public mailing list