[x3d-public] X3D JSON X_ITE scene loading. As well as XMLorDOM(oneortheotheror both) loading.

John Carlson yottzumm at gmail.com
Mon Mar 5 07:59:32 PST 2018


Oh, that resources folder!

There was only one problem with that gears.json, namely, it had an embedded .x3d URL instead of a .json URL.   But I replaced .x3d with .json and it worked.  Woohoo!  I am happy.

The folders are quite different, see below.   The main differences are the vrmlscript, though.  Don, can you ASAP revert X3dToJson.xslt back so that VRMLScript/ECMAScript is no longer scrunched together on a single line?  I think that might be causing issues. I don’t want to have to set a parameter to get old behavior.

Thank goodness I kept that around in the resources folder!

John

diff -wr Gears/gears.json Gears.old/gears.json
39c39
<             "@content":"02 May 2017"
---
>             "@content":"30 January 2018"
250,463c250
< "vrmlscript:",
< "",
< "function initialize ()",
< "{",
< "\teventsProcessed ();",
< "}",
< "",
< "function eventsProcessed ()",
< "{",
< "\tprint ('### Generating gear ...');",
< "",
< "\tvar indices = new MFInt32 ();",
< "\tvar points  = new MFVec3f ();",
< "",
< "\tvar cos = Math .cos;",
< "\tvar sin = Math .sin;",
< "",
< "\t// Radien and tooth angle",
< "",
< "\tvar radius0 = innerRadius;",
< "\tvar radius1 = outerRadius - toothDepth / 2;",
< "\tvar radius2 = outerRadius + toothDepth / 2;",
< "\tvar da = 2 * Math .PI / teeth / 4;",
< "",
< "\t// Front vectors",
< "",
< "\tvar vectorf0 = new SFVec3f (radius0, 0, width * 0.5);",
< "\tvar vectorf1 = new SFVec3f (radius1, 0, width * 0.5);",
< "\tvar vectorf2 = new SFVec3f (radius2, 0, width * 0.5);",
< "",
< "\t// Back vectors",
< "",
< "\tvar vectorb0 = new SFVec3f (radius0, 0, -width * 0.5);",
< "\tvar vectorb1 = new SFVec3f (radius1, 0, -width * 0.5);",
< "\tvar vectorb2 = new SFVec3f (radius2, 0, -width * 0.5);",
< "",
< "\t// Generate front face indices",
< "",
< "\tfor (var i = 0; i < teeth; ++ i)",
< "\t{",
< "\t\tvar index = i * 3;",
< "",
< "\t\tindices [indices .length] = index;",
< "\t\tindices [indices .length] = index + 1;",
< "\t\tindices [indices .length] = index + 2;",
< "\t\tindices [indices .length] = index + 4;",
< "\t\tindices [indices .length] = index + 3;",
< "\t\tindices [indices .length] = -1;",
< "\t}",
< "",
< "\t// Generate front face points",
< "",
< "\tfor (var i = 0; i < teeth + 1; ++ i)",
< "\t{",
< "\t\tvar angle = i * 2 * Math .PI / teeth;",
< "",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle)          .multVec (vectorf0);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle)          .multVec (vectorf1);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorf1);",
< "\t}",
< "",
< "\tpoints .length = points .length - 1;",
< "",
< "\tpoints [points .length] = new SFVec3f ();",
< "\tpoints [points .length] = new SFVec3f ();",
< "\tpoints [points .length] = new SFVec3f ();",
< "",
< "",
< "\t// Generate front sides of teeth indices",
< "",
< "\tfor (var i = 0; i < teeth; ++ i)",
< "\t{",
< "\t\tvar index = i * 4;",
< "",
< "\t\tindices [indices .length] = points .length + index;",
< "\t\tindices [indices .length] = points .length + index + 1;",
< "\t\tindices [indices .length] = points .length + index + 2;",
< "\t\tindices [indices .length] = points .length + index + 3;",
< "\t\tindices [indices .length] = -1;",
< "\t}",
< "",
< "\t// Generate front sides of teeth points",
< "",
< "\tfor (var i = 0; i < teeth; ++ i)",
< "\t{",
< "\t\tvar angle = i * 2 * Math .PI / teeth;",
< "",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle)          .multVec (vectorf1);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + da)     .multVec (vectorf2);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + 2 * da) .multVec (vectorf2);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorf1);",
< "\t}",
< "",
< "",
< "\t// Generate back face indices",
< "",
< "\tfor (var i = 0; i < teeth; ++ i)",
< "\t{",
< "\t\tvar index = i * 3;",
< "",
< "\t\tindices [indices .length] = points .length + index;",
< "\t\tindices [indices .length] = points .length + index + 3;",
< "\t\tindices [indices .length] = points .length + index + 4;",
< "\t\tindices [indices .length] = points .length + index + 2;",
< "\t\tindices [indices .length] = points .length + index + 1;",
< "\t\tindices [indices .length] = -1;",
< "\t}",
< "",
< "\t// Generate back face points",
< "",
< "\tfor (var i = 0; i < teeth + 1; ++ i)",
< "\t{",
< "\t\tvar angle = i * 2 * Math .PI / teeth;",
< "",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle)          .multVec (vectorb0);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle)          .multVec (vectorb1);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorb1);",
< "\t}",
< "",
< "\tpoints .length = points .length - 1;",
< "",
< "",
< "\t// Generate back sides of teeth indices",
< "",
< "\tfor (var i = 0; i < teeth; ++ i)",
< "\t{",
< "\t\tvar index = i * 4;",
< "",
< "\t\tindices [indices .length] = points .length + index;",
< "\t\tindices [indices .length] = points .length + index + 1;",
< "\t\tindices [indices .length] = points .length + index + 2;",
< "\t\tindices [indices .length] = points .length + index + 3;",
< "\t\tindices [indices .length] = -1;",
< "\t}",
< "",
< "\t// Generate front sides of teeth points",
< "",
< "\tfor (var i = 0; i < teeth; ++ i)",
< "\t{",
< "\t\tvar angle = i * 2 * Math .PI / teeth;",
< "",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorb1);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + 2 * da) .multVec (vectorb2);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + da)     .multVec (vectorb2);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle)          .multVec (vectorb1);",
< "\t}",
< "",
< "",
< "\t// Generate outward faces of teeth indices",
< "",
< "\tfor (var i = 0; i < teeth * 4; ++ i)",
< "\t{",
< "\t\tvar index = i * 2;",
< "",
< "\t\tindices [indices .length] = points .length + index;",
< "\t\tindices [indices .length] = points .length + index + 1;",
< "\t\tindices [indices .length] = points .length + index + 3;",
< "\t\tindices [indices .length] = points .length + index + 2;",
< "\t\tindices [indices .length] = -1;",
< "\t}",
< "",
< "\tindices [indices .length - 3] = points .length + 1;",
< "\tindices [indices .length - 2] = points .length;",
< "",
< "\t// Generate outward faces of teeth points",
< "",
< "\tfor (var i = 0; i < teeth; ++ i)",
< "\t{",
< "\t   var angle = i * 2 * Math .PI / teeth;",
< "",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorf1);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorb1);",
< "",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + da) .multVec (vectorf2);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + da) .multVec (vectorb2);",
< "",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + 2 * da) .multVec (vectorf2);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + 2 * da) .multVec (vectorb2);",
< "",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorf1);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorb1);",
< "\t}",
< "",
< "",
< "\t// Generate inside radius cylinder points",
< "",
< "\tfor (var i = 0; i < teeth; ++ i)",
< "\t{",
< "\t\tvar index = i * 2;",
< "",
< "\t\tindices [indices .length] = points .length + index;",
< "\t\tindices [indices .length] = points .length + index + 1;",
< "\t\tindices [indices .length] = points .length + index + 3;",
< "\t\tindices [indices .length] = points .length + index + 2;",
< "\t\tindices [indices .length] = -1;",
< "\t}",
< "",
< "\tindices [indices .length - 3] = points .length + 1;",
< "\tindices [indices .length - 2] = points .length;",
< "",
< "\t// Generate inside radius cylinder indices",
< "",
< "\tfor (var i = 0; i < teeth + 1; ++ i)",
< "\t{",
< "\t\tvar angle = i * 2 * Math .PI / teeth;",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorb0);",
< "\t\tpoints [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorf0);",
< "\t}",
< "",
< "\tprint ('### Generating gear done.');",
< "",
< "\tgear .coord .point   = points;",
< "\tgear .set_coordIndex = indices;",
< "}"
---
> "vrmlscript: function initialize () { eventsProcessed (); } function eventsProcessed () { print ('### Generating gear ...'); var indices = new MFInt32 (); var points = new MFVec3f (); var cos = Math .cos; var sin = Math .sin; // Radien and tooth angle var radius0 = innerRadius; var radius1 = outerRadius - toothDepth / 2; var radius2 = outerRadius + toothDepth / 2; var da = 2 * Math .PI / teeth / 4; // Front vectors var vectorf0 = new SFVec3f (radius0, 0, width * 0.5); var vectorf1 = new SFVec3f (radius1, 0, width * 0.5); var vectorf2 = new SFVec3f (radius2, 0, width * 0.5); // Back vectors var vectorb0 = new SFVec3f (radius0, 0, -width * 0.5); var vectorb1 = new SFVec3f (radius1, 0, -width * 0.5); var vectorb2 = new SFVec3f (radius2, 0, -width * 0.5); // Generate front face indices for (var i = 0; i < teeth; ++ i) { var index = i * 3; indices [indices .length] = index; indices [indices .length] = index + 1; indices [indices .length] = index + 2; indices [indices .length] = index + 4; indices [indices .length] = index + 3; indices [indices .length] = -1; } // Generate front face points for (var i = 0; i < teeth + 1; ++ i) { var angle = i * 2 * Math .PI / teeth; points [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorf0); points [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorf1); points [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorf1); } points .length = points .length - 1; points [points .length] = new SFVec3f (); points [points .length] = new SFVec3f (); points [points .length] = new SFVec3f (); // Generate front sides of teeth indices for (var i = 0; i < teeth; ++ i) { var index = i * 4; indices [indices .length] = points .length + index; indices [indices .length] = points .length + index + 1; indices [indices .length] = points .length + index + 2; indices [indices .length] = points .length + index + 3; indices [indices .length] = -1; } // Generate front sides of teeth points for (var i = 0; i < teeth; ++ i) { var angle = i * 2 * Math .PI / teeth; points [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorf1); points [points .length] = new SFRotation (0, 0, 1, angle + da) .multVec (vectorf2); points [points .length] = new SFRotation (0, 0, 1, angle + 2 * da) .multVec (vectorf2); points [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorf1); } // Generate back face indices for (var i = 0; i < teeth; ++ i) { var index = i * 3; indices [indices .length] = points .length + index; indices [indices .length] = points .length + index + 3; indices [indices .length] = points .length + index + 4; indices [indices .length] = points .length + index + 2; indices [indices .length] = points .length + index + 1; indices [indices .length] = -1; } // Generate back face points for (var i = 0; i < teeth + 1; ++ i) { var angle = i * 2 * Math .PI / teeth; points [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorb0); points [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorb1); points [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorb1); } points .length = points .length - 1; // Generate back sides of teeth indices for (var i = 0; i < teeth; ++ i) { var index = i * 4; indices [indices .length] = points .length + index; indices [indices .length] = points .length + index + 1; indices [indices .length] = points .length + index + 2; indices [indices .length] = points .length + index + 3; indices [indices .length] = -1; } // Generate front sides of teeth points for (var i = 0; i < teeth; ++ i) { var angle = i * 2 * Math .PI / teeth; points [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorb1); points [points .length] = new SFRotation (0, 0, 1, angle + 2 * da) .multVec (vectorb2); points [points .length] = new SFRotation (0, 0, 1, angle + da) .multVec (vectorb2); points [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorb1); } // Generate outward faces of teeth indices for (var i = 0; i < teeth * 4; ++ i) { var index = i * 2; indices [indices .length] = points .length + index; indices [indices .length] = points .length + index + 1; indices [indices .length] = points .length + index + 3; indices [indices .length] = points .length + index + 2; indices [indices .length] = -1; } indices [indices .length - 3] = points .length + 1; indices [indices .length - 2] = points .length; // Generate outward faces of teeth points for (var i = 0; i < teeth; ++ i) { var angle = i * 2 * Math .PI / teeth; points [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorf1); points [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorb1); points [points .length] = new SFRotation (0, 0, 1, angle + da) .multVec (vectorf2); points [points .length] = new SFRotation (0, 0, 1, angle + da) .multVec (vectorb2); points [points .length] = new SFRotation (0, 0, 1, angle + 2 * da) .multVec (vectorf2); points [points .length] = new SFRotation (0, 0, 1, angle + 2 * da) .multVec (vectorb2); points [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorf1); points [points .length] = new SFRotation (0, 0, 1, angle + 3 * da) .multVec (vectorb1); } // Generate inside radius cylinder points for (var i = 0; i < teeth; ++ i) { var index = i * 2; indices [indices .length] = points .length + index; indices [indices .length] = points .length + index + 1; indices [indices .length] = points .length + index + 3; indices [indices .length] = points .length + index + 2; indices [indices .length] = -1; } indices [indices .length - 3] = points .length + 1; indices [indices .length - 2] = points .length; // Generate inside radius cylinder indices for (var i = 0; i < teeth + 1; ++ i) { var angle = i * 2 * Math .PI / teeth; points [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorb0); points [points .length] = new SFRotation (0, 0, 1, angle) .multVec (vectorf0); } print ('### Generating gear done.'); gear .coord .point = points; gear .set_coordIndex = indices; }"
Only in Gears.old: gears.x3dv
diff -wr Gears/Rotor.json Gears.old/Rotor.json
31c31
<             "@content":"02 May 2017"
---
>             "@content":"30 January 2018"
227,248c227
< "vrmlscript:",
< "",
< "function initialize ()",
< "{",
< "\teventsProcessed ();",
< "}",
< "",
< "function set_axis ()",
< "{ }",
< "",
< "function set_angle ()",
< "{ }",
< "",
< "function eventsProcessed ()",
< "{",
< "\tvar keyValue = interpolator .keyValue;",
< "",
< "\tfor (var i = 0; i < 4; ++ i)",
< "\t\tkeyValue [i] = new SFRotation (axis, angle + 2 * Math .PI / 4 * i);",
< "\t",
< "\tkeyValue [4] = keyValue [0];",
< "}"
---
> "vrmlscript: function initialize () { eventsProcessed (); } function set_axis () { } function set_angle () { } function eventsProcessed () { var keyValue = interpolator .keyValue; for (var i = 0; i < 4; ++ i) keyValue [i] = new SFRotation (axis, angle + 2 * Math .PI / 4 * i); keyValue [4] = keyValue [0]; }"
Only in Gears.old: Rotor.x3dv
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20180305/787a669e/attachment-0001.html>


More information about the x3d-public mailing list