[x3d-public] bug report X3dToJson.xslt stylesheet. Handling of SFNode as parameter to Proto

Don Brutzman brutzman at nps.edu
Sun Apr 3 09:26:06 PDT 2016


Apologies for delayed reply.

Here is the rule that was decided as most straightforward and consistent (currently last bullet under Completed Work):

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

* field and fieldValue statements containing SFNode/MFNode content use the -children key.

Your scene passes all X3D Validator tests (good job there) and I think the relevant excerpts that you are referring to are

=================================================================
...
<ProtoDeclare name='twentyseven'>
   <ProtoInterface>
	<field accessType='inputOutput' name='ttranslation' type='SFVec3f' value='0.0 0.0 0.0'/>
	<field accessType='inputOutput' name='myShape' type='SFNode'>
	  <Sphere/>
	</field>
   </ProtoInterface>
   <ProtoBody>
	<Transform translation='0 0 0'>
	  <IS>
		<connect nodeField='translation' protoField='ttranslation'/>
	  </IS>
	  <ProtoInstance name='nine'>
		<fieldValue name='ztranslation' value='0 0 0'/>
		<IS>
		  <connect nodeField='myShape' protoField='myShape'/>
		</IS>
	  </ProtoInstance>
	  <ProtoInstance name='nine'>
		<fieldValue name='ztranslation' value='0 0 2'/>
		<IS>
		  <connect nodeField='myShape' protoField='myShape'/>
		</IS>
	  </ProtoInstance>
	  <ProtoInstance name='nine'>
		<fieldValue name='ztranslation' value='0 0 -2'/>
		<IS>
		  <connect nodeField='myShape' protoField='myShape'/>
		</IS>
	  </ProtoInstance>
	</Transform>
   </ProtoBody>
</ProtoDeclare>
<ProtoInstance name='twentyseven'>
   <fieldValue name='ttranslation' value='0 0 0'/>
   <fieldValue name='myShape'>
	<Box size='1 1 1'/>
   </fieldValue>
</ProtoInstance>
=================================================================

So the corresponding conversion of the ProtoInstance to JSON would be

{ "ProtoInstance":
   {
	"@name":"twentyseven",
	"fieldValue": [
	  {
		"@name":"ttranslation",
		"@value":[0,0,0]
	  },
	  {
		"@name":"myShape",
		"-children":[
		  { "Box":
			{
			  "@size":[1,1,1]
			}
		  }
		]
	  }
	]
   }
}

This JSON excerpt above matches the ProtoInstance in "rubikOnFireFlawed.json" file you sent a week ago.

Full result from X3dToJson.xslt stylesheet attached, passes jslint and also passes Roy's X3D JSON Schema validation.

Incidentally, nested prototypes are certainly allowed by X3D Specification but the great majority of my testing to date has not been testing nesting.


On 3/25/2016 11:35 PM, John Carlson wrote:
> So it actually caught it after my PrototypeExpander ran on it.  So there may be a bug with how my PrototypeExpander handles -children which are SFNodes (actually they are MFNodes (arrays) in the JSON code, so I think the JSON is wrong).  You guys may have discussed this, or something like it, and I was ignorant at the time.
>
> John
>> On Mar 26, 2016, at 2:28 AM, John Carlson <yottzumm at gmail.com> wrote:
>>
>> If you pass an SFNode to a Proto, it is treated as an MFNode and given -children, and not -value or -child.  This can create -geometry nodes which are arrays instead of objects.  Here are an X3D example, the converted JSON, and how the JSON should appear (hand edited).  I did not pick -value or -child because I forgot what we chose.  I could probably fix this another way, but i think -children is misleading when it’s an SFNode.<rubikOnFire.json><rubikOnFire.x3d><rubikOnFireFixed.json>You may use my X3D file in your X3D resources examples if you wish.  rubikOnFire.json  does not pass schema. If there’s a problem with my X3D file, then we should fix QA, because it passed the latest X3D-Edit tests. (Perhaps there should be a warning?).  If there is a problem with my X3D file, then JSON should not be produced.
>>
>> So take your pick, fix the stylesheet, or find an error in my X3D file.   Good luck with both.
>>
>> There’s likely more bugs to report.  This is just the first one.  Good catch Roy!
>>
>> Thanks,
>>
>> John

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": {
    "encoding":"UTF-8",
    "@profile":"Immersive",
    "@version":"3.3",
    "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.3.xsd",
    "JSON schema":"http://www.web3d.org/specifications/x3d-3.3-JSONSchema.json",
    "Scene": {
        "-children":[
          { "NavigationInfo":
            {
              "@type":["ANY","WALK","EXAMINE","FLY","LOOKAT"]
            }
          },
          { "Viewpoint":
            {
              "@description":"Rubiks Cube on Fire",
              "@position":[0,0,12]
            }
          },
          { "ProtoDeclare":
            {
              "@name":"anyShape",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"xtranslation",
                      "@accessType":"inputOutput",
                      "@type":"SFVec3f",
                      "@value":[0.0,0.0,0.0]
                    },
                    {
                      "@name":"myShape",
                      "@accessType":"inputOutput",
                      "@type":"SFNode",
                      "-children":[
                        { "Sphere":
                          {
                          }
                        }
                      ]
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    { "Transform":
                      {
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"translation",
                                "@protoField":"xtranslation"
                              }
                            ]
                        },
                        "-children":[
                          { "Shape":
                            {
                              "IS": {
                                  "connect": [
                                    {
                                      "@nodeField":"geometry",
                                      "@protoField":"myShape"
                                    }
                                  ]
                              },
                              "-appearance":
                                { "Appearance":
                                  {
                                    "-material":
                                      { "Material":
                                        {
                                          "@diffuseColor":[1,1,1]
                                        }
                                      }
                                  }
                                }
                            }
                          }
                        ]
                      }
                    }
                  ]
              }
            }
          },
          { "ProtoDeclare":
            {
              "@name":"three",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"ytranslation",
                      "@accessType":"inputOutput",
                      "@type":"SFVec3f",
                      "@value":[0.0,0.0,0.0]
                    },
                    {
                      "@name":"myShape",
                      "@accessType":"inputOutput",
                      "@type":"SFNode",
                      "-children":[
                        { "Sphere":
                          {
                          }
                        }
                      ]
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    { "Transform":
                      {
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"translation",
                                "@protoField":"ytranslation"
                              }
                            ]
                        },
                        "-children":[
                          { "ProtoInstance":
                            {
                              "@name":"anyShape",
                              "fieldValue": [
                                {
                                  "@name":"xtranslation",
                                  "@value":[0,0,0]
                                }
                              ],
                              "IS": {
                                  "connect": [
                                    {
                                      "@nodeField":"myShape",
                                      "@protoField":"myShape"
                                    }
                                  ]
                              }
                            }
                          },
                          { "ProtoInstance":
                            {
                              "@name":"anyShape",
                              "fieldValue": [
                                {
                                  "@name":"xtranslation",
                                  "@value":[2,0,0]
                                }
                              ],
                              "IS": {
                                  "connect": [
                                    {
                                      "@nodeField":"myShape",
                                      "@protoField":"myShape"
                                    }
                                  ]
                              }
                            }
                          },
                          { "ProtoInstance":
                            {
                              "@name":"anyShape",
                              "fieldValue": [
                                {
                                  "@name":"xtranslation",
                                  "@value":[-2,0,0]
                                }
                              ],
                              "IS": {
                                  "connect": [
                                    {
                                      "@nodeField":"myShape",
                                      "@protoField":"myShape"
                                    }
                                  ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  ]
              }
            }
          },
          { "ProtoDeclare":
            {
              "@name":"nine",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"ztranslation",
                      "@accessType":"inputOutput",
                      "@type":"SFVec3f",
                      "@value":[0.0,0.0,0.0]
                    },
                    {
                      "@name":"myShape",
                      "@accessType":"inputOutput",
                      "@type":"SFNode",
                      "-children":[
                        { "Sphere":
                          {
                          }
                        }
                      ]
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    { "Transform":
                      {
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"translation",
                                "@protoField":"ztranslation"
                              }
                            ]
                        },
                        "-children":[
                          { "ProtoInstance":
                            {
                              "@name":"three",
                              "fieldValue": [
                                {
                                  "@name":"ytranslation",
                                  "@value":[0,0,0]
                                }
                              ],
                              "IS": {
                                  "connect": [
                                    {
                                      "@nodeField":"myShape",
                                      "@protoField":"myShape"
                                    }
                                  ]
                              }
                            }
                          },
                          { "ProtoInstance":
                            {
                              "@name":"three",
                              "fieldValue": [
                                {
                                  "@name":"ytranslation",
                                  "@value":[0,2,0]
                                }
                              ],
                              "IS": {
                                  "connect": [
                                    {
                                      "@nodeField":"myShape",
                                      "@protoField":"myShape"
                                    }
                                  ]
                              }
                            }
                          },
                          { "ProtoInstance":
                            {
                              "@name":"three",
                              "fieldValue": [
                                {
                                  "@name":"ytranslation",
                                  "@value":[0,-2,0]
                                }
                              ],
                              "IS": {
                                  "connect": [
                                    {
                                      "@nodeField":"myShape",
                                      "@protoField":"myShape"
                                    }
                                  ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  ]
              }
            }
          },
          { "ProtoDeclare":
            {
              "@name":"twentyseven",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"ttranslation",
                      "@accessType":"inputOutput",
                      "@type":"SFVec3f",
                      "@value":[0.0,0.0,0.0]
                    },
                    {
                      "@name":"myShape",
                      "@accessType":"inputOutput",
                      "@type":"SFNode",
                      "-children":[
                        { "Sphere":
                          {
                          }
                        }
                      ]
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    { "Transform":
                      {
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"translation",
                                "@protoField":"ttranslation"
                              }
                            ]
                        },
                        "-children":[
                          { "ProtoInstance":
                            {
                              "@name":"nine",
                              "fieldValue": [
                                {
                                  "@name":"ztranslation",
                                  "@value":[0,0,0]
                                }
                              ],
                              "IS": {
                                  "connect": [
                                    {
                                      "@nodeField":"myShape",
                                      "@protoField":"myShape"
                                    }
                                  ]
                              }
                            }
                          },
                          { "ProtoInstance":
                            {
                              "@name":"nine",
                              "fieldValue": [
                                {
                                  "@name":"ztranslation",
                                  "@value":[0,0,2]
                                }
                              ],
                              "IS": {
                                  "connect": [
                                    {
                                      "@nodeField":"myShape",
                                      "@protoField":"myShape"
                                    }
                                  ]
                              }
                            }
                          },
                          { "ProtoInstance":
                            {
                              "@name":"nine",
                              "fieldValue": [
                                {
                                  "@name":"ztranslation",
                                  "@value":[0,0,-2]
                                }
                              ],
                              "IS": {
                                  "connect": [
                                    {
                                      "@nodeField":"myShape",
                                      "@protoField":"myShape"
                                    }
                                  ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  ]
              }
            }
          },
          { "ProtoInstance":
            {
              "@name":"twentyseven",
              "fieldValue": [
                {
                  "@name":"ttranslation",
                  "@value":[0,0,0]
                },
                {
                  "@name":"myShape",
                  "-children":[
                    { "Box":
                      {
                        "@size":[1,1,1]
                      }
                    }
                  ]
                }
              ]
            }
          }
        ]
    }
  }
}


More information about the x3d-public mailing list