[X3D-Public] [x3dom-developers] initial X3D JSON conversion support using X3dToJson.xslt
Don Brutzman
brutzman at nps.edu
Sun Oct 12 01:15:44 PDT 2014
More progress, on this version of a candidate encoding at least.
[...]
> To accomplish this means that the converter will need to be type-aware on a field-by-field basis when reading values. When programming this, I'll need to trap booleans and strings first, then treat everything else as number.
>
> Will fix in next revision.
Stylesheet now removes default attribute values. Also deduces typing based on content for boolean, number, number array, string, string array.
Strong typing will be a future modification - still needed since it is possible for numeric strings to sneak through as numbers despite using the prior heuristics.
> JSON question #1, wondering which is correct for a singleton number?
>
> "transparency": [1],
> or
> "transparency": 1,
Using second case.
> There are very few examples in the JSON spec. A strict reading there seems to permit either form: an array with a single value, or else a singleton number with no surrounding brackets.
>
> JSON question #2, wondering which is correct for an MFVec3f value, single array or array of arrays?
>
> "keyValue": [0 0 0 1 1 1 2 2 2],
> or
> "keyValue": [ [0 0 0], [1 1 1], [2 2 2] ],
Revised candidates, with required commas:
"keyValue": [ 0, 0, 0, 1, 1, 1, 2, 2, 2 ],
or
"keyValue": [ [0, 0, 0], [1, 1, 1], [2, 2, 2] ],
Still wondering. This is likely a player question, what form is preferred for efficient operations. Will assume the second form (array of arrays) unless someone argues otherwise.
Latest results maintained at
https://svn.code.sf.net/p/x3d/code/www.web3d.org/x3d/stylesheets/X3dToJson.xslt
https://svn.code.sf.net/p/x3d/code/www.web3d.org/x3d/stylesheets/test/HelloWorld.json
https://svn.code.sf.net/p/x3d/code/www.web3d.org/x3d/stylesheets/test/HelloWorld.scene.json
Still some problems with extra commas in the output, but cleaned-up version is attached to allow testing by anyone who wants to use JSON.parse() to read and generate objects. It passes Netbeans/X3D-Edit JSON syntax testing.
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 --------------
{
"#comment": "Example scene to illustrate X3D nodes and fields (XML elements and attributes)",
"Group": [
{
"Viewpoint": {
"@DEF": "ViewUpClose",
"@centerOfRotation": [ 0, -1, 0 ],
"@description": "Hello world!",
"@position": [ 0, -1, 7 ]
},
"Transform": [
{
"@rotation": [ 0, 1, 0, 3 ],
"Shape": [
{
"Sphere": {
},
"Appearance": [
{
"Material": {
"@DEF": "MaterialLightBlue",
"@diffuseColor": [ 0.1, 0.5, 1 ]
},
"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" ]
}
}
]
}
]
}
],
"Transform": [
{
"@translation": [ 0, -2, 0 ],
"Shape": [
{
"Text": [
{
"@DEF": "TextMessage",
"@string": [ "Hello", "world!" ],
"FontStyle": {
"@justify": [ "MIDDLE", "MIDDLE" ]
}
}
],
"Appearance": [
{
"Material": {
"@USE": "MaterialLightBlue"
}
}
]
}
]
}
]
}
]
}
More information about the X3D-Public
mailing list