[x3d-public] JSON Encoding

Roy Walmsley roy.walmsley at ntlworld.com
Mon Dec 21 15:00:46 PST 2015


Cecile,

 

Thanks. An interesting comparison, which I hadn’t considered.

 

But then, I wonder, where would you be calling up such a path? Surely, this would be in some form of programmatic access, such as with the SAI or DOM, for example. This is just an encoding, for storage in an external file. Whichever form happened to be used the content when loaded into an application/web browser would be identical. So the form of the encoding would be irrelevant …

 

The point of my effort was to find a way to keep the comments and ROUTEs within a scene maintained identically, so that lossless round tripping can occur from one encoding to another, e.g. XML to JSON to XML. Your listing removes the comments from the scene and incorporates them externally to the structured JSON. While that may be possible with comments it is surely not possible with ROUTEs.

 

Regards,

 

Roy

 

From: x3d-public [mailto:x3d-public-bounces at web3d.org] On Behalf Of Cecile Muller
Sent: 21 December 2015 22:30
To: X3D Graphics public mailing list
Subject: Re: [x3d-public] JSON Encoding

 

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20151221/437c8bda/attachment-0001.html>


More information about the x3d-public mailing list