[x3d-public] resolution of dangling comma in JSON conversion, including ShaderPart type="VERTEX" value, VR Hackathon preps

Don Brutzman brutzman at nps.edu
Sun Feb 21 18:13:39 PST 2016


OK the example was again a big help John.

1. The comma is OK...  As you indicated, an attribute type="VERTEX" was being omitted.  That occurred because it is a default value in the Schema, confusing the comma-inclusion logic.  Now fixed.

I think that this problem wasn't detected in the previous tests because the VERTEX shader wasn't a test case.

Am thinking that this information is so important that the ShaderPart type attribute should always be included...  In other words, author assumptions or misunderstandings on Shaders ought to be avoided if possible given their potential for security issues.

Corrected output attached, converter stylesheet changes checked in.  Have also modified similar code in other stylesheets to always show type="VERTEX" in output.

2. Cool shader-program scene!  For me it worked in Octaga, and briefly worked in FreeWrl, but then errors or no response in anything else.

Once again, we need open-source shader examples in the X3D Examples Archive.  I hope that some can be added at some point when ready.

A collection of several would likely have revealed the full scope of problems earlier, instead of piecemeal fixes.  The first ones will likely be somewhat influential since they will encourage satisfactory capabilities in several X3D players.

3.Roy: in the X3D Schema definitions for ShaderPart and ShaderProgram, we have the following definition:

	<xs:attribute name="type" type="shaderPartTypeValues"/>

This doesn't list the default value.  If nothing else we need to add that.  Modification for schema draft:

	<xs:attribute name="type" type="shaderPartTypeValues" default="VERTEX"/>

We also might consider making this REQUIRED.  This should do it:

	<xs:attribute name="type" type="shaderPartTypeValues" default="VERTEX" use="required"/>

We can also require it in DTD - made it so.

Also added a rule to X3D Schematron to nag if the type attribute is not found so that there is some explanation available if this gets confusing someday.

... or not required, like other attributes?  This is a design-pattern issue.  Good topic for confirmation during next weekly teleconference.

On 2/21/2016 3:22 PM, John Carlson wrote:
> I see no change to the stylesheet on my end from version control to the version on the web3d website.  Here’s the actual area where it’s failing:
>
>
>   "-parts":[
> { "ShaderPart":
> {,
> "#sourceText":[
> "/*",
>
> "The MIT License (MIT)”,
>
> Source:
>
>                  <ShaderPart type='VERTEX'>
> /*
> The MIT License (MIT)

gosh.  once you see type='VERTEX' missing above, it sure looks obvious...   :0

> Attached is a full X3D file.  I have at least 4 of them which fail this way.  As far as I can tell, it’s the first ShaderPart or the VERTEX shader which has the issue.  The type attribute is elided.   That may be my issue.  I get no errors when running the stylesheet.
>
>
> Don, maybe consider a vacation, or a break over the weekend?  Does the Navy offer free flights to Hawaii?
>
> John

3. Thanks for the kind thoughts.  Uhh, I thought this effort was my break!  Carpe weekend...  8)

Web3D Consortium is sponsoring a VR Hackathon in two and a half weeks, March 11-13 in San Francisco.

	http://www.web3d.org/event/virtual-reality-hackathon-san-francisco-0

	http://vrhackathon.com/sanfrancisco.html

Wondering, might we have demo-able work using X3D JSON by then?  Sure would be cool.  Your D3 efforts perhaps?

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",
    "Scene": {
        "-children":[
          { "NavigationInfo":
            {
            }
          },
          { "Background":
            {
              "@backUrl":["cubemap/BK.png"],
              "@bottomUrl":["cubemap/BT.png"],
              "@frontUrl":["cubemap/FR.png"],
              "@leftUrl":["cubemap/LF.png"],
              "@rightUrl":["cubemap/RT.png"],
              "@topUrl":["cubemap/TP.png"]
            }
          },
          { "Viewpoint":
            {
              "@position":[0,0,40],
              "@description":"Transparent rose"
            }
          },
          { "Transform":
            {
              "@DEF":"Rose01",
              "-children":[
                { "Shape":
                  {
                    "-appearance":
                      { "Appearance":
                        {
                          "@DEF":"_01_-_Default",
                          "-material":
                            { "Material":
                              {
                                "@diffuseColor":[0.7,0.7,0.7],
                                "@specularColor":[0.5,0.5,0.5]
                              }
                            },
                          "-texture":
                            { "ComposedCubeMapTexture":
                              {
                                "-back":
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/BK.png","http://coderextreme.net/cubemap/BK.png"]
                                    }
                                  },
                                "-bottom":
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/BT.png","http://coderextreme.net/cubemap/BT.png"]
                                    }
                                  },
                                "-front":
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/FR.png","http://coderextreme.net/cubemap/FR.png"]
                                    }
                                  },
                                "-left":
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/LF.png","http://coderextreme.net/cubemap/LF.png"]
                                    }
                                  },
                                "-right":
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/RT.png","http://coderextreme.net/cubemap/RT.png"]
                                    }
                                  },
                                "-top":
                                  { "ImageTexture":
                                    {
                                      "@url":["cubemap/TP.png","http://coderextreme.net/cubemap/TP.png"]
                                    }
                                  }
                              }
                            },
                          "-shaders":[
                            { "ComposedShader":
                              {
                                "@DEF":"ComposedShader",
                                "@language":"GLSL",
                                "field": [
                                  {
                                    "@name":"cube",
                                    "@type":"SFInt32",
                                    "@accessType":"inputOutput",
                                    "@value":0
                                  },
                                  {
                                    "@name":"chromaticDispertion",
                                    "@accessType":"inputOutput",
                                    "@type":"SFVec3f",
                                    "@value":[0.98,1.0,1.033]
                                  },
                                  {
                                    "@name":"bias",
                                    "@type":"SFFloat",
                                    "@accessType":"inputOutput",
                                    "@value":0.5
                                  },
                                  {
                                    "@name":"scale",
                                    "@type":"SFFloat",
                                    "@accessType":"inputOutput",
                                    "@value":0.5
                                  },
                                  {
                                    "@name":"power",
                                    "@type":"SFFloat",
                                    "@accessType":"inputOutput",
                                    "@value":2
                                  }
                                ],
                                "-parts":[
                                  { "ShaderPart":
                                    {
                                      "@type":"VERTEX",
                                      "#sourceText":[
"/*",
"The MIT License (MIT)",
"Copyright (c) 2011 Authors of J3D. All rights reserved.",
"",
"Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:",
"",
"The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.",
"",
"THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"*/",
"attribute vec3 position;",
"attribute vec3 normal;",
"attribute vec2 texcoord;",
"",
"uniform mat4 modelViewProjectionMatrix;",
"uniform mat4 modelViewMatrix;",
"uniform mat4 modelViewMatrixInverse;",
"uniform mat4 normalMatrix;",
"",
"uniform vec3 chromaticDispertion;",
"uniform float bias;",
"uniform float scale;",
"uniform float power;",
"",
"varying vec3 t;",
"varying vec3 tr;",
"varying vec3 tg;",
"varying vec3 tb;",
"varying float rfac;",
"",
"void main()",
"{",
"    mat3 mvm3=mat3(",
"                modelViewMatrix[0].x,",
"                modelViewMatrix[0].y,",
"                modelViewMatrix[0].z,",
"                modelViewMatrix[1].x,",
"                modelViewMatrix[1].y,",
"                modelViewMatrix[1].z,",
"                modelViewMatrix[2].x,",
"                modelViewMatrix[2].y,",
"                modelViewMatrix[2].z",
"    );",
"    vec3 fragNormal = mvm3*normal;",
"    gl_Position = modelViewProjectionMatrix*vec4(position, 1.0);",
"    vec3 incident = normalize((modelViewMatrix * vec4(position, 1.0)).xyz);",
"",
"    t = reflect(incident, fragNormal)*mvm3;",
"    tr = refract(incident, fragNormal, chromaticDispertion.x)*mvm3;",
"    tg = refract(incident, fragNormal, chromaticDispertion.y)*mvm3;",
"    tb = refract(incident, fragNormal, chromaticDispertion.z)*mvm3;",
"",
"    rfac = bias + scale * pow(0.5+0.5*dot(incident, fragNormal), power);",
"}"
]
                                    }
                                  },
                                  { "ShaderPart":
                                    {
                                      "@type":"FRAGMENT",
                                      "#sourceText":[
"/*",
"The MIT License (MIT)",
"Copyright (c) 2011 Authors of J3D. All rights reserved.",
"",
"Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:",
"",
"The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.",
"",
"THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"*/",
"#ifdef GL_ES",
"  precision highp float;",
"#endif",
"",
"uniform samplerCube cube;",
"",
"varying vec3 t;",
"varying vec3 tr;",
"varying vec3 tg;",
"varying vec3 tb;",
"varying float rfac;",
"",
"void main()",
"{",
"    vec4 ref = textureCube(cube, t);",
"    vec4 ret = vec4(1.0);",
"",
"    ret.r = textureCube(cube, tr).r;",
"    ret.g = textureCube(cube, tg).g;",
"    ret.b = textureCube(cube, tb).b;",
"",
"    gl_FragColor = ret * rfac + ref * (1.0 - rfac);",
"}"
]
                                    }
                                  }
                                ]
                              }
                            }
                          ]
                        }
                      },
                    "-children":[
                      { "#comment":"Sphere/"
                      }
                    ],
                    "-geometry":
                      { "IndexedFaceSet":
                        {
                          "@DEF":"Orbit",
                          "@creaseAngle":1.57,
                          "-coord":
                            { "Coordinate":
                              {
                                "@DEF":"OrbitCoordinates"
                              }
                            }
                        }
                      }
                  }
                }
              ]
            }
          },
          { "Script":
            {
              "@DEF":"OrbitScript",
              "field": [
                {
                  "@name":"set_fraction",
                  "@accessType":"inputOnly",
                  "@type":"SFFloat"
                },
                {
                  "@name":"coordinates",
                  "@accessType":"inputOutput",
                  "@type":"MFVec3f"
                },
                {
                  "@name":"coordIndexes",
                  "@accessType":"inputOutput",
                  "@type":"MFInt32"
                }
              ],
              "#sourceText":[
"ecmascript:",
"",
"var e = 5;",
"var f = 5;",
"var g = 5;",
"var h = 5;",
"",
"function initialize() {",
"     resolution = 100;",
"     updateCoordinates(resolution);",
"     if (typeof coordIndexes == 'undefined' || coordIndexes == null) {",
"     \tcoordIndexes = new MFInt32();",
"     }",
"     ci = 0;",
"     for ( i = 0; i < resolution-1; i++) {",
"     \tfor ( j = 0; j < resolution-1; j++) {",
"\t     coordIndexes[ci] = i*resolution+j;",
"\t     coordIndexes[ci+1] = i*resolution+j+1;",
"\t     coordIndexes[ci+2] = (i+1)*resolution+j+1;",
"\t     coordIndexes[ci+3] = (i+1)*resolution+j;",
"\t     coordIndexes[ci+4] = -1;",
"\t     ci += 5;",
"\t}",
"    }",
"}",
"",
"function updateCoordinates(resolution) {",
"     theta = 0.0;",
"     phi = 0.0;",
"     delta = (2 * 3.141592653) / (resolution-1);",
"     if (typeof coordinates == 'undefined' || coordinates == null) {",
"     \tcoordinates = new MFVec3f();",
"     }",
"     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\tcoordinates[i*resolution+j][0] = rho * Math.cos(phi) * Math.cos(theta);",
"\t\tcoordinates[i*resolution+j][1] = rho * Math.cos(phi) * Math.sin(theta);",
"\t\tcoordinates[i*resolution+j][2] = rho * Math.sin(phi);",
"\t\ttheta += delta;",
"\t}",
"\tphi += delta;",
"     }",
"}",
"",
"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,
              "@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