[X3D-Public] initial X3D JSON conversion support using X3dToJson.xslt
Don Brutzman
brutzman at nps.edu
Wed Oct 8 09:28:33 PDT 2014
Initial construction of X3D to JSON stylesheet is working. Examples attached.
Working:
- elements, attributes, comments
- Square and squiggly brackets, commas
- escaping quotation marks
TODO
- handling special characters
- elimination of default X3D attribute values
- CDATA text (for example, Script content)
- round-trip testing using a JSON-to-XML converter
- embedded support in X3D-Edit
What X3D JSON specification will need to specify:
- @attributeName
- "#comment"
- "#CDATA'
Not possible:
- differentiate typing of string versus number values
- embedded JSON comments
Example invocation from build.xml:
<target name="test.X3dToJson.xslt" depends="test.mkdir"
description="Test X3dToJson.xslt stylesheet using default Ant xslt task" >
<xslt style="X3dToJson.xslt" in="${examples.dir}/HelloWorld.x3d" out="test/HelloWorld.json"/>
<echo message="converted test/HelloWorld.json"/>
<xslt style="X3dToJson.xslt" in="${examples.dir}/HelloWorld.x3d" out="test/HelloWorld.scene.json">
<param name="sceneGraphOnly" expression="true"/>
</xslt>
<echo message="converted test/HelloWorld.scene.json"/>
</target>
p.s. once a web3d.org website problem is sorted out, these assets will reappear at
http://www.web3d.org/stylesheets
Source updates remain are currently accessible via sourceforge at
http://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/
http://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/test
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": [
{
"@bboxCenter": "0 0 0",
"@bboxSize": "-1 -1 -1",
"@containerField": "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",
"@retainUserOffsets": "false",
"@containerField": "children"
},
"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",
"@containerField": "children"
, "Shape": [
{
"@containerField": "children",
"@bboxCenter": "0 0 0",
"@bboxSize": "-1 -1 -1"
, "Sphere": {
"@radius": "1",
"@solid": "true",
"@containerField": "geometry"
},
"Appearance": [
{
"@containerField": "appearance"
, "Material": {
"@DEF": "MaterialLightBlue",
"@diffuseColor": "0.1 0.5 1",
"@ambientIntensity": "0.2",
"@emissiveColor": "0 0 0",
"@shininess": "0.2",
"@specularColor": "0 0 0",
"@transparency": "0",
"@containerField": "material"
},
"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",
"@containerField": "texture"
}
}
]
}
]
}
],
"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",
"@containerField": "children"
, "Shape": [
{
"@containerField": "children",
"@bboxCenter": "0 0 0",
"@bboxSize": "-1 -1 -1"
, "Text": [
{
"@DEF": "TextMessage",
"@string": "\"Hello\" \"world!\"",
"@maxExtent": "0.0",
"@solid": "false",
"@containerField": "geometry"
, "FontStyle": {
"@justify": "\"MIDDLE\" \"MIDDLE\"",
"@family": "\"SERIF\"",
"@horizontal": "true",
"@leftToRight": "true",
"@size": "1.0",
"@spacing": "1.0",
"@style": "PLAIN",
"@topToBottom": "true",
"@containerField": "fontStyle"
}
}
],
"Appearance": [
{
"@containerField": "appearance"
, "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",
"@containerField": "material"
}
}
]
}
]
}
]
}
]
}
-------------- next part --------------
{
"#comment": "Example scene to illustrate X3D nodes and fields (XML elements and attributes)",
"Group": [
{
"@bboxCenter": "0 0 0",
"@bboxSize": "-1 -1 -1",
"@containerField": "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",
"@retainUserOffsets": "false",
"@containerField": "children"
},
"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",
"@containerField": "children"
, "Shape": [
{
"@containerField": "children",
"@bboxCenter": "0 0 0",
"@bboxSize": "-1 -1 -1"
, "Sphere": {
"@radius": "1",
"@solid": "true",
"@containerField": "geometry"
},
"Appearance": [
{
"@containerField": "appearance"
, "Material": {
"@DEF": "MaterialLightBlue",
"@diffuseColor": "0.1 0.5 1",
"@ambientIntensity": "0.2",
"@emissiveColor": "0 0 0",
"@shininess": "0.2",
"@specularColor": "0 0 0",
"@transparency": "0",
"@containerField": "material"
},
"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",
"@containerField": "texture"
}
}
]
}
]
}
],
"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",
"@containerField": "children"
, "Shape": [
{
"@containerField": "children",
"@bboxCenter": "0 0 0",
"@bboxSize": "-1 -1 -1"
, "Text": [
{
"@DEF": "TextMessage",
"@string": "\"Hello\" \"world!\"",
"@maxExtent": "0.0",
"@solid": "false",
"@containerField": "geometry"
, "FontStyle": {
"@justify": "\"MIDDLE\" \"MIDDLE\"",
"@family": "\"SERIF\"",
"@horizontal": "true",
"@leftToRight": "true",
"@size": "1.0",
"@spacing": "1.0",
"@style": "PLAIN",
"@topToBottom": "true",
"@containerField": "fontStyle"
}
}
],
"Appearance": [
{
"@containerField": "appearance"
, "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",
"@containerField": "material"
}
}
]
}
]
}
]
}
]
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: X3dToJson.xslt
Type: text/xml
Size: 12306 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20141008/ac2db48f/attachment-0001.xml>
More information about the X3D-Public
mailing list