[x3d-public] announce: updated encoding, X3D to JSON Stylesheet Converter: string arrays, whitespace, UTF-8, Script #source

John Carlson yottzumm at gmail.com
Sun Nov 15 23:11:19 PST 2015


It’s likely that you have to convert end-of-line to “\n”  see JSON spec.

John

> 
> The result below looks good to me, according to the JSON specification.  However jslint balks... is it really an error, perhaps an overzealous jslint configuration setting controls this?
> 
> Console:
>> C:\x3d-code\www.web3d.org\x3d\content\examples\X3dForAdvancedModeling/GeometricShapes//ParallelepipedPrototype.x3d processing with X3dToJson stylesheet
>> Script ParallelepipedScript contains CDATA source-code text, copied as "#source"
>> C:\x3d-code\www.web3d.org\x3d\content\examples\X3dForAdvancedModeling/GeometricShapes//ParallelepipedPrototype.json processing with jslint
>> jslint:C:\x3d-code\www.web3d.org\x3d\content\examples\X3dForAdvancedModeling/GeometricShapes//ParallelepipedPrototype.json:279:29:JavaScript URL.
>> jslint:C:\x3d-code\www.web3d.org\x3d\content\examples\X3dForAdvancedModeling/GeometricShapes//ParallelepipedPrototype.json:284:10:Unexpected character '(space)'.
> 
> Excerpt:
> http://X3dGraphics.com/examples/X3dForAdvancedModeling/GeometricShapes/ParallelepipedPrototype.x3d
> http://X3dGraphics.com/examples/X3dForAdvancedModeling/GeometricShapes/ParallelepipedPrototype.json
> 
>            "-children":[
>              { "Script":
>                {
>                  "@DEF":"ParallelepipedScript",
>                  "field": [
>                    {
>                      "@name":"point",
>                      "@accessType":"inputOutput",
>                      "@type":"MFVec3f"
>                    }
>                  ],
>                  "IS": {
>                    "connect": [
>                      {
>                        "@nodeField":"point",
>                        "@protoField":"point"
>                      }
>                    ]
>                  },
>                  "#source":"
> ecmascript:
> function initialize ()
> {
>    checkCoordinatePoints ();
> }
> function checkCoordinatePoints ()
> {
>    // A parallelepiped has three sets of four parallel edges; the edges within each set are of equal length.
>    // Quality assurance: check that lengths of corresponding sides match.
>        edge01 = length2(point[0], point[1]); // top
>    edge12 = length2(point[1], point[2]);
>    edge23 = length2(point[2], point[3]);
>    edge30 = length2(point[3], point[0]);
>    edge45 = length2(point[4], point[5]); // bottom
>    edge56 = length2(point[5], point[6]);
>    edge67 = length2(point[6], point[7]);
>    edge74 = length2(point[7], point[4]);
>    edge04 = length2(point[0], point[4]); // sides
>    edge15 = length2(point[1], point[5]);
>    edge26 = length2(point[2], point[6]);
>    edge37 = length2(point[3], point[7]);
>        epsilon = edge01 * 0.001;
>        if      ((Math.abs(edge01 - edge23) > epsilon) ||
>             (Math.abs(edge23 - edge67) > epsilon) ||
>             (Math.abs(edge67 - edge45) > epsilon) ||
>             (Math.abs(edge45 - edge01) > epsilon))
>         Browser.println ('Warning, mismatched parallelopiped sides 02/33/45/67');
>    else if ((Math.abs(edge30 - edge12) > epsilon) ||
>             (Math.abs(edge12 - edge56) > epsilon) ||
>             (Math.abs(edge56 - edge74) > epsilon) ||
>             (Math.abs(edge74 - edge30) > epsilon))
>         Browser.println ('Warning, mismatched parallelopiped sides 30/12/56/74');
>    else if ((Math.abs(edge04 - edge15) > epsilon) ||
>             (Math.abs(edge15 - edge26) > epsilon) ||
>             (Math.abs(edge26 - edge37) > epsilon) ||
>             (Math.abs(edge37 - edge04) > epsilon))
>         Browser.println ('Warning, mismatched parallelopiped sides 04/15/26/37');
> }
> function length2 (pointA, pointB)
> {
>    return Math.sqrt((pointA.x - pointB.x)*(pointA.x - pointB.x) +
>                     (pointA.y - pointB.y)*(pointA.y - pointB.y) +
>                     (pointA.z - pointB.z)*(pointA.z - pointB.z));
> }
> function set_point (eventValue)
> {
>   // input eventValue received for inputOutput field
>    point = eventValue;
>    checkCoordinatePoints ();
> }
> "
>                }
>              }
>            ]
> 
> How does it look?  I believe that this is the last major language feature to include, further work will be tuning/improving what is there.
> 
> =================================================
> 
> I was able to reduce some of the recursion in the stylesheet, and tried to nudge the memory settings in multiple ways, but the large scenes provoking out-of-memory errors were unimpressed and continue to explode in the same amount of time as before... will continue looking at those configurations.
> 
> =================================================
> 
> Closer and closer... comments and improvements remain appreciated and welcome.
> 
> 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




More information about the x3d-public mailing list