[x3d-public] JSON Encoding
Cecile Muller
newsletter at wildpeaks.fr
Mon Dec 21 14:29:33 PST 2015
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/e7e0f2d7/attachment.html>
More information about the x3d-public
mailing list