[x3d-public] Help with IndexedFaceSet and initialization. X3DJSAIL corrections

Don Brutzman brutzman at nps.edu
Sun Apr 1 20:31:37 PDT 2018


New release available:

	X3D Java Scene Access Interface Library (X3DJSAIL)
	which  supports programmers with standards-based X3D Java interfaces and objects, all as open source.
	http://www.web3d.org/specifications/java/X3DJSAIL.html

1. The flowers4.x3d scene (attached) is another tough but excellent test.  Thanks for persisting on that one John.

The first problem was in the reflection-based DOM loader, disambiguating a texture node's parent when the parent is ComposedCubeMapTextureObject and child is a Texture node.  Also found erroneous containerField default for (ComposedCubeMapTextureObject, GeneratedCubeMapTextureObject, ImageCubeMapTextureObject) in X3D Tooltips.

	http://www.web3d.org/x3d/tooltips/X3dTooltips.html#ComposedCubeMapTexture
	http://www.web3d.org/x3d/tooltips/X3dTooltips.html#GeneratedCubeMapTextureObject
	http://www.web3d.org/x3d/tooltips/X3dTooltips.html#ImageCubeMapTextureObject

This example scene also exposed omissions in handling parent/child combinations ComposedShader/ShaderPart and ProgramShader/ShaderProgram, now remedied (for concrete nodes at least).

2. Next, something else you have reported before:

"org.web3d.x3d.sai.InvalidFieldException: IndexedFaceSet containing Coordinate node must also include coordIndex field"

Looks like you are setting values independently via Script - a pretty common authoring technique, starting out with unadorned IndexedFaceSet/Coordinate.  So this run-time validation error indeed seems overly assertive.

Thinking it would be OK if I relaxed this validation rule slightly to allow no coordIndex field if the Coordinate node had no point values.  Would similarly modify a series of other error checks... turned out to be another nontrivial block of work, because there might be a CoordinateDouble or even contained ProtoInstance node instead of a Coordinate node.  And so on and so on for Color/ColorRGBA, Normal and TextureCoordinate.

So I added some utility methods for all this housekeeping to IndexedFaceSet and (when appropriate) IndexedLineSet.  Then was able to make the exceptions less interruptive when no values are present in the child node.  They only holler if values are found in the contained node but the corresponding index is empty, thus flagging an otherwise-silent failure to render.

http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Geometry3D/IndexedFaceSetObject.html#getCoordCount--
http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Geometry3D/IndexedFaceSetObject.html#getColorCount--
http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Geometry3D/IndexedFaceSetObject.html#getNormalCount--
http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Geometry3D/IndexedFaceSetObject.html#getTexCoordCount--


3. Now your flowers4.x3d test finally passes Java loading and scene validation prior to JSON conversion.  Have added it to X3DJSAIL examples.
===========================================
org.web3d.x3d.jsail.CommandLine java/examples/flowers4.x3d -toJSON -toFile java/examples/flowers4.json
parameter: source file flowers4.x3d filesize 7176 bytes
parameter: "-toJSON" for conversion to JSON encoding
parameter: "-toFile" "java/examples/flowers4.json" for result file name root java/examples/flowers4
convert to JSON:
Warning: java/examples/flowers4.json does not meet suggested X3D naming conventions. Output serialization allowed to continue, file may be editable...
Script DEF=OrbitScript contains CDATA source-code text, copied as "#sourceText" using "strings" mode
file conversion successful: flowers4.json (12543 bytes)
===========================================

4. I also added some further conversions last week: toFileX3dTidy/toStringX3dTidy and toFileHtmlDocumentation (refactor/rename)


http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3DObject.html#toFileX3dTidy-java.lang.String-
http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3DObject.html#toStringX3dTidy--

http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3DObject.html#toFileHtmlDocumentation-java.lang.String-
http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3DObject.html#toStringHtmlDocumentation-java.lang.String-

These many fixes are checked in, jars uploaded, file deployment in progress (takes about 2 hours from home).



On 3/7/2018 3:31 AM, John Carlson wrote:
> This may be a better example. Attached. Note:  it works in X_ITE 4.1.3 under firefox, last time I tried.
> 
> John
> 
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
> 
> *From: *John Carlson <mailto:yottzumm at gmail.com>
> *Sent: *Wednesday, March 7, 2018 6:02 AM
> *To: *x3d-public at web3d.org <mailto:x3d-public at web3d.org>
> *Subject: *Help with IndexedFaceSet and initialization. X3DJSAIL
> 
> I would like to initialize an IndexedFaceSet in a script.  However, if I don’t provide coordinates, coordIndex in the XML, X3DJSAIL complains!  I could enable output on invalid scenegraph but is there another alternative?  I am generating the X3DJSAIL files, and I only have a  few invalid ones.
> 
> John
> 
> org.web3d.x3d.sai.InvalidFieldException: IndexedFaceSet containing Coordinate node must also include coordIndex field
> 
> org.web3d.x3d.sai.InvalidFieldException: IndexedFaceSet containing Coordinate node must also include coordIndex field
> 
>          at org.web3d.x3d.jsail.Geometry3D.IndexedFaceSetObject.validate(IndexedFaceSetObject.java:3007)
> 
>          at org.web3d.x3d.jsail.Shape.ShapeObject.validate(ShapeObject.java:1404)
> 
>          at org.web3d.x3d.jsail.Grouping.TransformObject.validate(TransformObject.java:1818)
> 
>          at org.web3d.x3d.jsail.Core.ProtoBodyObject.validate(ProtoBodyObject.java:641)
> 
>          at org.web3d.x3d.jsail.Core.ProtoDeclareObject.validate(ProtoDeclareObject.java:875)
> 
>          at org.web3d.x3d.jsail.Core.SceneObject.validate(SceneObject.java:651)
> 
>          at org.web3d.x3d.jsail.Core.X3DObject.validate(X3DObject.java:3309)
> 
>          at org.web3d.x3d.jsail.Core.X3DObject.toFileX3D(X3DObject.java:648)
> 
>          at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$548$flowers_sail$cu1$restOf.:program(../nashorn/net/coderextreme/data/flowers.sail.js:202)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:652)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:517)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.apply(Shell.java:519)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.runScripts(Shell.java:448)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.run(Shell.java:186)
> 
>          at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:104)
> 
>          at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:80)
> 
> Exception in thread "main" org.web3d.x3d.sai.InvalidFieldException: IndexedFaceSet containing Coordinate node must also include coordIndex field
> 
>          at org.web3d.x3d.jsail.Geometry3D.IndexedFaceSetObject.validate(IndexedFaceSetObject.java:3007)
> 
>          at org.web3d.x3d.jsail.Shape.ShapeObject.validate(ShapeObject.java:1404)
> 
>          at org.web3d.x3d.jsail.Grouping.TransformObject.validate(TransformObject.java:1818)
> 
>          at org.web3d.x3d.jsail.Core.ProtoBodyObject.validate(ProtoBodyObject.java:641)
> 
>          at org.web3d.x3d.jsail.Core.ProtoDeclareObject.validate(ProtoDeclareObject.java:875)
> 
>          at org.web3d.x3d.jsail.Core.SceneObject.validate(SceneObject.java:651)
> 
>          at org.web3d.x3d.jsail.Core.X3DObject.validate(X3DObject.java:3309)
> 
>          at org.web3d.x3d.jsail.Core.X3DObject.toFileX3D(X3DObject.java:648)
> 
>          at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$548$flowers_sail$cu1$restOf.:program(../nashorn/net/coderextreme/data/flowers.sail.js:202)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:652)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:517)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.apply(Shell.java:519)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.runScripts(Shell.java:448)
> 
>          at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.run(Shell.java:186)
> 
>          at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:104)
> 
>          at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:80)
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org


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 --------------
A non-text attachment was scrubbed...
Name: flowers4.x3d
Type: model/x3d+xml
Size: 7034 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20180401/ef55a007/attachment-0001.x3d>
-------------- 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",
    "head": {
        "component": [
          {
            "@name":"Shaders",
            "@level":1
          },
          {
            "@name":"CubeMapTexturing",
            "@level":1
          }
        ],
        "meta": [
          {
            "@name":"title",
            "@content":"flowers4.x3d"
          },
          {
            "@name":"creator",
            "@content":"John Carlson"
          },
          {
            "@name":"generator",
            "@content":"manual"
          },
          {
            "@name":"identifier",
            "@content":"https://coderextreme.net/X3DJSONLD/flowers4.x3d"
          },
          {
            "@name":"description",
            "@content":"an animated flower"
          },
          {
            "@name":"translated",
            "@content":"01 April 2018"
          },
          {
            "@name":"generator",
            "@content":"X3dToJson.xslt, http://www.web3d.org/x3d/stylesheets/X3dToJson.html"
          },
          {
            "@name":"reference",
            "@content":"X3D JSON encoding: http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding"
          }
        ]
    },
    "Scene": {
        "-children":[
          { "NavigationInfo":
            {
            }
          },
          { "Background":
            {
              "@backUrl":["../resources/images/all_probes/stpeters_cross/stpeters_back.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_back.png"],
              "@bottomUrl":["../resources/images/all_probes/stpeters_cross/stpeters_bottom.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_bottom.png"],
              "@frontUrl":["../resources/images/all_probes/stpeters_cross/stpeters_front.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_front.png"],
              "@leftUrl":["../resources/images/all_probes/stpeters_cross/stpeters_left.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_left.png"],
              "@rightUrl":["../resources/images/all_probes/stpeters_cross/stpeters_right.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_right.png"],
              "@topUrl":["../resources/images/all_probes/stpeters_cross/stpeters_top.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_top.png"]
            }
          },
          { "Transform":
            {
              "@DEF":"transform",
              "-children":[
                { "Shape":
                  {
                    "-children":[
                      {
                        "#comment":"<Sphere>"
                      }
                    ],
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "Material":
                              {
                                "@diffuseColor":[0.7,0.7,0.7],
                                "@specularColor":[0.5,0.5,0.5]
                              }
                            },
                          "-shaders":[
                            { "ComposedShader":
                              {
                                "@DEF":"shader",
                                "@language":"GLSL",
                                "-parts":[
                                  { "ShaderPart":
                                    {
                                      "@type":"VERTEX",
                                      "@url":["../shaders/x3dom.vs","https://coderextreme.net/X3DJSONLD/shaders/x3dom.vs"]
                                    }
                                  },
                                  { "ShaderPart":
                                    {
                                      "@type":"FRAGMENT",
                                      "@url":["../shaders/pc_bubbles.fs","https://coderextreme.net/X3DJSONLD/shaders/pc_bubbles.fs"]
                                    }
                                  }
                                ],
                                "field": [
                                  {
                                    "@name":"cube",
                                    "@accessType":"inputOutput",
                                    "@type":"SFInt32",
                                    "@value":0
                                  },
                                  {
                                    "@name":"chromaticDispertion",
                                    "@accessType":"inputOutput",
                                    "@type":"SFVec3f",
                                    "@value":[0.98,1,1.033]
                                  },
                                  {
                                    "@name":"bias",
                                    "@accessType":"inputOutput",
                                    "@type":"SFFloat",
                                    "@value":0.5
                                  },
                                  {
                                    "@name":"scale",
                                    "@accessType":"inputOutput",
                                    "@type":"SFFloat",
                                    "@value":0.5
                                  },
                                  {
                                    "@name":"power",
                                    "@accessType":"inputOutput",
                                    "@type":"SFFloat",
                                    "@value":2.0
                                  }
                                ]
                              }
                            }
                          ],
                          "-texture":
                            { "ComposedCubeMapTexture":
                              {
                                "-back":
                                  { "ImageTexture":
                                    {
                                      "@url":["../resources/images/all_probes/stpeters_cross/stpeters_back.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_back.png"]
                                    }
                                  },
                                "-bottom":
                                  { "ImageTexture":
                                    {
                                      "@url":["../resources/images/all_probes/stpeters_cross/stpeters_bottom.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_bottom.png"]
                                    }
                                  },
                                "-front":
                                  { "ImageTexture":
                                    {
                                      "@url":["../resources/images/all_probes/stpeters_cross/stpeters_front.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_front.png"]
                                    }
                                  },
                                "-left":
                                  { "ImageTexture":
                                    {
                                      "@url":["../resources/images/all_probes/stpeters_cross/stpeters_left.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_left.png"]
                                    }
                                  },
                                "-right":
                                  { "ImageTexture":
                                    {
                                      "@url":["../resources/images/all_probes/stpeters_cross/stpeters_right.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_right.png"]
                                    }
                                  },
                                "-top":
                                  { "ImageTexture":
                                    {
                                      "@url":["../resources/images/all_probes/stpeters_cross/stpeters_top.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_top.png"]
                                    }
                                  }
                              }
                            }
                        }
                      },
                    "-geometry":
                      { "IndexedFaceSet":
                        {
                          "@DEF":"Orbit",
                          "@convex":false,
                          "-coord":
                            { "Coordinate":
                              {
                                "@DEF":"OrbitCoordinates"
                              }
                            }
                        }
                      }
                  }
                }
              ]
            }
          },
          { "Script":
            {
              "@DEF":"OrbitScript",
              "field": [
                {
                  "@name":"set_fraction",
                  "@accessType":"inputOnly",
                  "@type":"SFFloat"
                },
                {
                  "@name":"coordinates",
                  "@accessType":"inputOutput",
                  "@type":"MFVec3f"
                },
                {
                  "@name":"coordIndexes",
                  "@accessType":"outputOnly",
                  "@type":"MFInt32"
                }
              ],
              "#sourceText":[
"",
"",
"ecmascript:",
"",
"var e = 5;",
"var f = 5;",
"var g = 5;",
"var h = 5;",
"",
"function initialize() {",
"     resolution = 100;",
"     updateCoordinates(resolution);",
"     var cis = [];",
"     for ( i = 0; i < resolution-1; i++) {",
"     \tfor ( j = 0; j < resolution-1; j++) {",
"\t     cis.push(i*resolution+j);",
"\t     cis.push(i*resolution+j+1);",
"\t     cis.push((i+1)*resolution+j+1);",
"\t     cis.push((i+1)*resolution+j);",
"\t     cis.push(-1);",
"\t}",
"    }",
"    coordIndexes = new MFInt32(cis);",
"}",
"",
"function updateCoordinates(resolution) {",
"     theta = 0.0;",
"     phi = 0.0;",
"     delta = (2 * 3.141592653) / (resolution-1);",
"     var crds = [];",
"     for ( i = 0; i < resolution; i++) {",
"     \tfor ( j = 0; j < resolution; j++) {",
"\t\trho = e + f * Math.cos(g * theta) * Math.cos(h * phi);",
"\t\tcrds.push(new SFVec3f(",
"\t\t\trho * Math.cos(phi) * Math.cos(theta),",
"\t\t\trho * Math.cos(phi) * Math.sin(theta),",
"\t\t\trho * Math.sin(phi)",
"\t\t));",
"\t\ttheta += delta;",
"\t}",
"\tphi += delta;",
"     }",
"     coordinates = new MFVec3f(crds);",
"}",
"",
"function set_fraction(fraction, eventTime) {",
"\tchoice = Math.floor(Math.random() * 4);",
"\tswitch (choice) {",
"\tcase 0:",
"\t\te += Math.floor(Math.random() * 2) * 2 - 1;",
"\t\tbreak;",
"\tcase 1:",
"\t\tf += Math.floor(Math.random() * 2) * 2 - 1;",
"\t\tbreak;",
"\tcase 2:",
"\t\tg += Math.floor(Math.random() * 2) * 2 - 1;",
"\t\tbreak;",
"\tcase 3:",
"\t\th += Math.floor(Math.random() * 2) * 2 - 1;",
"\t\tbreak;",
"\t}",
"\tif (f < 1) {",
"\t\tf = 10;",
"\t}",
"\tif (g < 1) {",
"\t\tg = 4;",
"\t}",
"\tif (h < 1) {",
"\t\th = 4;",
"\t}",
"\tresolution = 100;",
"\tupdateCoordinates(resolution);",
"}",
"",
""
]
            }
          },
          { "TimeSensor":
            {
              "@DEF":"Clock",
              "@cycleInterval":16.0,
              "@loop":true
            }
          },
          { "ROUTE":
            {
              "@fromField":"coordIndexes",
              "@fromNode":"OrbitScript",
              "@toField":"set_coordIndex",
              "@toNode":"Orbit"
            }
          },
          { "ROUTE":
            {
              "@fromField":"coordinates",
              "@fromNode":"OrbitScript",
              "@toField":"set_point",
              "@toNode":"OrbitCoordinates"
            }
          },
          { "ROUTE":
            {
              "@fromField":"fraction_changed",
              "@fromNode":"Clock",
              "@toField":"set_fraction",
              "@toNode":"OrbitScript"
            }
          }
        ]
    }
  }
}


More information about the x3d-public mailing list