[x3d-public] JSON encoding for SFNode: no [array brackets]

Don Brutzman brutzman at nps.edu
Fri Feb 19 00:16:57 PST 2016


John, during today's X3D Schema/DTD teleconference Roy observed that our SFNode child nodes were always wrapped in [array brackets] even though there is not an array there.

This is contrary to our declared design principle that SFNode is always a JSON object.

	http://www.web3d.org/x3d/stylesheets/X3dToJson.html#values

That definitely appears to be what we want.  No desire to mislead JSON authors into thinking that another node might appear.

Fortunately this implementation wasn't too difficult.  Here is the list of SFNode types that I constructed from AllX3dElementsAttributes.3.3.xml

<xsl:variable name="SFNodeType" select="
	($fieldName = 'back')               or ($fieldName = 'bottom')            or ($fieldName = 'front')              or
	($fieldName = 'left')               or ($fieldName = 'right')             or ($fieldName = 'top')                or
	($fieldName = 'backTexture')        or ($fieldName = 'bottomTexture')     or ($fieldName = 'frontTexture')       or
	($fieldName = 'leftTexture')        or ($fieldName = 'rightTexture')      or ($fieldName = 'topTexture')         or
	($fieldName = 'appearance')         or ($fieldName = 'body1')             or ($fieldName = 'body2')              or
	($fieldName = 'collidable')         or ($fieldName = 'collider')          or
	($fieldName = 'color')              or ($fieldName = 'colorRamp')         or ($fieldName = 'coord')              or
	($fieldName = 'controlPoint')       or ($fieldName = 'controlPoints')     or ($fieldName = 'crossSectionCurve')  or
	($fieldName = 'emitter')            or ($fieldName = 'fillProperties')    or
	($fieldName = 'fogCoord')           or ($fieldName = 'fontStyle')         or ($fieldName = 'geoOrigin')          or
	($fieldName = 'geometry')           or ($fieldName = 'geometry1')         or ($fieldName = 'geometry2')          or
	($fieldName = 'gradients')          or ($fieldName = 'layout')            or ($fieldName = 'lineProperties')     or
	($fieldName = 'massDensityModel')   or
	($fieldName = 'metadata')           or ($fieldName = 'normal')            or ($fieldName = 'pickingGeometry')    or
	($fieldName = 'profileCurve')       or ($fieldName = 'proxy')             or
	($fieldName = 'renderStyle')        or ($fieldName = 'source')            or
	($fieldName = 'segmentIdentifiers') or ($fieldName = 'surface')           or ($fieldName = 'surfaceNormals')     or
	($fieldName = 'targetObject')       or ($fieldName = 'texCoord')          or ($fieldName = 'texCoordRamp')       or
	($fieldName = 'texture')            or ($fieldName = 'textureProperties') or ($fieldName = 'textureTransform')   or
	($fieldName = 'trajectoryCurve')    or ($fieldName = 'transferFunction')  or
	($fieldName = 'viewpoint')          or ($fieldName = 'voxels')            or
	($fieldName = 'weightTransferFunction1') or ($fieldName = 'weightTransferFunction2') or
	($parentName='CADFace'         and $fieldName = 'shape') or
	($parentName='CollidableShape' and $fieldName = 'shape')" />

So anyway it appears to be working on the first handful of test examples used during development.

HelloWorld.json example attached, check out SFNode fields -appearance -geometry -material etc.  Output is slightly terser as well.

No doubt this affects your implementation to but it appears to be an important change.

Hope this sounds good to you too.  Chalk another win up for Roy's JSON schema!

Stylesheet modifications checked in.  I'm running the JSON Examples build overnight, should be ready for you and Roy in the morning.

http://www.web3d.org/x3d/content/examples/X3dResources.html#Examples
"Special testing distribution. A comprehensive collection of all JSON example scenes is available at X3dExampleArchivesJsonScenes.zip (MD5 checksum) plus current output from the X3D JSON build process at build.json.out."

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":"HelloWorld.x3d"
          },
          {
            "@name":"description",
            "@content":"Simple X3D scene example: Hello World!"
          },
          {
            "@name":"created",
            "@content":"30 October 2000"
          },
          {
            "@name":"modified",
            "@content":"23 November 2014"
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman"
          },
          {
            "@name":"Image",
            "@content":"HelloWorld.tall.png"
          },
          {
            "@name":"reference",
            "@content":"http://en.wikipedia.org/wiki/Hello_world"
          },
          {
            "@name":"reference",
            "@content":"en.wikipedia.org/wiki/Hello#\"Hello,_World\"_computer_program"
          },
          {
            "@name":"reference",
            "@content":"http://en.wikibooks.org/w/index.php?title=Computer_Programming/Hello_world"
          },
          {
            "@name":"reference",
            "@content":"http://www.HelloWorldExample.net"
          },
          {
            "@name":"reference",
            "@content":"http://www.web3D.org"
          },
          {
            "@name":"reference",
            "@content":"http://www.web3d.org/realtime-3d/news/internationalization-x3d"
          },
          {
            "@name":"reference",
            "@content":"http://www.web3d.org/x3d/content/examples/HelloWorld.x3d"
          },
          {
            "@name":"reference",
            "@content":"http://X3dGraphics.com/examples/X3dForAdvancedModeling/HelloWorldScenes"
          },
          {
            "@name":"identifier",
            "@content":"http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter01-TechnicalOverview/HelloWorld.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"
          },
          {
            "@name":"reference",
            "@content":"HelloWorld.wrl"
          },
          {
            "@name":"reference",
            "@content":"HelloWorld.x3dv"
          },
          {
            "@name":"reference",
            "@content":"HelloWorld.x3db"
          },
          {
            "@name":"reference",
            "@content":"HelloWorld.xhtml"
          },
          {
            "@name":"reference",
            "@content":"HelloWorld.json"
          }
        ],
        "-children":[
          { "#comment":"Alternate encodings: VRML97, X3D ClassicVRML Encoding, X3D Compressed Binary Encoding (CBE), X3DOM, JSON"
          }
        ]
    },
    "Scene": {
        "-children":[
          { "#comment":"Example scene to illustrate X3D nodes and fields (XML elements and attributes)"
          },
          { "Group":
            {
              "-children":[
                { "Viewpoint":
                  {
                    "@DEF":"ViewUpClose",
                    "@centerOfRotation":[0,-1,0],
                    "@description":"Hello world!",
                    "@position":[0,-1,7]
                  }
                },
                { "Transform":
                  {
                    "@rotation":[0,1,0,3],
                    "-children":[
                      { "Shape":
                        {
                          "-geometry":
                            { "Sphere":
                              {
                              }
                            },
                          "-appearance":
                            { "Appearance":
                              {
                                "-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"]
                                    }
                                  }
                              }
                            }
                        }
                      }
                    ]
                  }
                },
                { "Transform":
                  {
                    "@translation":[0,-2,0],
                    "-children":[
                      { "Shape":
                        {
                          "-geometry":
                            { "Text":
                              {
                                "@DEF":"TextMessage",
                                "@string":["Hello","world!"],
                                "-fontStyle":
                                  { "FontStyle":
                                    {
                                      "@justify":["MIDDLE","MIDDLE"]
                                    }
                                  }
                              }
                            },
                          "-appearance":
                            { "Appearance":
                              {
                                "-material":[
                                  { "Material":
                                    {
                                      "@USE":"MaterialLightBlue"
                                    }
                                  }
                                ]
                              }
                            }
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
    }
  }
}


More information about the x3d-public mailing list