[x3d-public] node-java X3DJSAIL and 1 example that works, and one that doesn't

John Carlson yottzumm at gmail.com
Sat Apr 11 19:54:31 PDT 2020


Please test/review this HelloWorld example code in your ECMAScript SAI
environments.  I know it's not perfect yet, but much improved after taking
that nodejs detour.  I will continue revising as we find problems! I know
that embedded scripts are not treated properly yet! Discussion on how to
embed a script in a script is welcome! There's also multiline comments that
are not handled properly, it looks like!

Thanks,

John

var browser = X3D.getBrowser();
var scene = browser.currentScene;
X3D0 = scene.createNode("X3D"); // suggest using
document.querySelector("X3D");
X3D0.profile = "Immersive";
X3D0.version = "3.3";
// x3dVersionComparisonTest for this model:
supportsX3dVersion(X3DObject.VERSION_3_0)=true
head1 = scene.createNode("head");
// comment #1
// comment #2
// comment #3
// comment #4
component2 = scene.createNode("component");
component2.name = "Navigation";
component2.level = 3;
head1.component[0] = component2;

component3 = scene.createNode("component");
component3.name = "Shaders";
component3.level = 1;
head1.component[1] = component3;

component4 = scene.createNode("component");
component4.name = "CADGeometry";
component4.level = 2;
head1.component[2] = component4;

component5 = scene.createNode("component");
component5.name = "DIS";
component5.level = 2;
head1.component[3] = component5;

component6 = scene.createNode("component");
component6.name = "H-Anim";
component6.level = 1;
head1.component[4] = component6;

component7 = scene.createNode("component");
component7.name = "Grouping";
component7.level = 1;
head1.component[5] = component7;

component8 = scene.createNode("component");
component8.name = "Layering";
component8.level = 1;
head1.component[6] = component8;

unit9 = scene.createNode("unit");
unit9.name = "AngleUnitConversion";
unit9.category = "angle";
unit9.conversionFactor = 1.0;
head1.unit[7] = unit9;

unit10 = scene.createNode("unit");
unit10.name = "LengthUnitConversion";
unit10.category = "length";
unit10.conversionFactor = 1.0;
head1.unit[8] = unit10;

unit11 = scene.createNode("unit");
unit11.name = "ForceFromPoundsToNewtons";
unit11.category = "force";
unit11.conversionFactor = 4.4482;
head1.unit[9] = unit11;

meta12 = scene.createNode("meta");
meta12.content = "HelloWorldProgramOutput.x3d";
meta12.name = "title";
head1.meta[10] = meta12;

meta13 = scene.createNode("meta");
meta13.content = "continued development and testing in progress";
meta13.name = "info";
head1.meta[11] = meta13;

meta14 = scene.createNode("meta");
meta14.content = "Example HelloWorldProgram creates an X3D model using the
X3D Java Scene Access Interface Library (X3DJSAIL)";
meta14.name = "description";
head1.meta[12] = meta14;

meta15 = scene.createNode("meta");
meta15.content = "https://www.web3d.org/specifications/java/X3DJSAIL.html";
meta15.name = "reference";
head1.meta[13] = meta15;

meta16 = scene.createNode("meta");
meta16.content = "HelloWorldProgramOutput.java";
meta16.name = "generator";
head1.meta[14] = meta16;

meta17 = scene.createNode("meta");
meta17.content = "6 September 2016";
meta17.name = "created";
head1.meta[15] = meta17;

meta18 = scene.createNode("meta");
meta18.content = "12 January 2020";
meta18.name = "modified";
head1.meta[16] = meta18;

meta19 = scene.createNode("meta");
meta19.content = "X3D Java Scene Access Interface Library (X3DJSAIL)";
meta19.name = "generator";
head1.meta[17] = meta19;

meta20 = scene.createNode("meta");
meta20.content = "
https://www.web3d.org/specifications/java/examples/HelloWorldProgram.java";
meta20.name = "generator";
head1.meta[18] = meta20;

meta21 = scene.createNode("meta");
meta21.content = "Netbeans http://www.netbeans.org";
meta21.name = "generator";
head1.meta[19] = meta21;

meta22 = scene.createNode("meta");
meta22.content = "Don Brutzman";
meta22.name = "creator";
head1.meta[20] = meta22;

meta23 = scene.createNode("meta");
meta23.content = "
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/java/examples/HelloWorldProgramOutput.x3d
";
meta23.name = "reference";
head1.meta[21] = meta23;

meta24 = scene.createNode("meta");
meta24.content = "Console output, ClassicVRML encoding, VRML97 encoding and
pretty-print documentation:";
meta24.name = "reference";
head1.meta[22] = meta24;

meta25 = scene.createNode("meta");
meta25.content = "HelloWorldProgramOutput.txt";
meta25.name = "reference";
head1.meta[23] = meta25;

meta26 = scene.createNode("meta");
meta26.content = "HelloWorldProgramOutput.x3dv";
meta26.name = "reference";
head1.meta[24] = meta26;

meta27 = scene.createNode("meta");
meta27.content = "HelloWorldProgramOutput.wrl";
meta27.name = "reference";
head1.meta[25] = meta27;

meta28 = scene.createNode("meta");
meta28.content = "HelloWorldProgramOutput.html";
meta28.name = "reference";
head1.meta[26] = meta28;

meta29 = scene.createNode("meta");
meta29.content = "
https://savage.nps.edu/X3dValidator?url=https://www.web3d.org/specifications/java/examples/HelloWorldProgramOutput.x3d
";
meta29.name = "reference";
head1.meta[27] = meta29;

meta30 = scene.createNode("meta");
meta30.content = "
https://www.web3d.org/specifications/java/examples/HelloWorldProgramOutput.x3d
";
meta30.name = "identifier";
head1.meta[28] = meta30;

meta31 = scene.createNode("meta");
meta31.content = "../license.html";
meta31.name = "license";
head1.meta[29] = meta31;

X3D0.head = head1;

Scene32 = scene.createNode("Scene");
ViewpointGroup33 = scene.createNode("ViewpointGroup");
ViewpointGroup33.description = "Available viewpoints";
Viewpoint34 = scene.createNode("Viewpoint");
Viewpoint34.DEF = "DefaultView";
Viewpoint34.description = "Hello X3DJSAIL";
ViewpointGroup33.children[0] = Viewpoint34;

Viewpoint35 = scene.createNode("Viewpoint");
Viewpoint35.DEF = "TopDownView";
Viewpoint35.description = "top-down view from above";
Viewpoint35.orientation = [1,0,0,-1.570796];
Viewpoint35.position = [0,100,0];
ViewpointGroup33.children[1] = Viewpoint35;

Scene32.children[0] = ViewpointGroup33;

NavigationInfo36 = scene.createNode("NavigationInfo");
NavigationInfo36.avatarSize = [0.25,1.6,0.75];
NavigationInfo36.transitionType = ["LINEAR"];
NavigationInfo36.type = ["EXAMINE","FLY","ANY"];
Scene32.children[1] = NavigationInfo36;

WorldInfo37 = scene.createNode("WorldInfo");
WorldInfo37.DEF = "WorldInfoDEF";
WorldInfo37.title = "HelloWorldProgram produced by X3D Java SAI Library
(X3DJSAIL)";
Scene32.children[2] = WorldInfo37;

WorldInfo38 = scene.createNode("WorldInfo");
WorldInfo38.USE = "WorldInfoDEF";
Scene32.children[3] = WorldInfo38;

WorldInfo39 = scene.createNode("WorldInfo");
WorldInfo39.USE = "WorldInfoDEF";
Scene32.children[4] = WorldInfo39;

MetadataString40 = scene.createNode("MetadataString");
MetadataString40.DEF = "scene.addChildMetadata";
MetadataString40.name = "test";
MetadataString40.value = ["Top-level root Metadata node beneath Scene needs
to be one of '-children' in JSON encoding"];
Scene32.metadata[5] = MetadataString40;

LayerSet41 = scene.createNode("LayerSet");
LayerSet41.DEF = "scene.addChildLayerSetTest";
LayerSet41.order = [0];
Scene32.layerSet[6] = LayerSet41;

Transform42 = scene.createNode("Transform");
Transform42.DEF = "LogoGeometryTransform";
Transform42.translation = [0,1.5,0];
Anchor43 = scene.createNode("Anchor");
Anchor43.description = "select for X3D Java SAI Library (X3DJSAIL)
description";
Anchor43.url = ["../X3DJSAIL.html","
https://www.web3d.org/specifications/java/X3DJSAIL.html"];
Shape44 = scene.createNode("Shape");
Shape44.DEF = "BoxShape";
Appearance45 = scene.createNode("Appearance");
Material46 = scene.createNode("Material");
Material46.DEF = "GreenMaterial";
Material46.diffuseColor = [0,1,1];
Material46.emissiveColor = [0.8,0,0];
Material46.transparency = 0.1;
Appearance45.material = Material46;

ImageTexture47 = scene.createNode("ImageTexture");
ImageTexture47.url = ["images/X3dJavaSceneAccessInterfaceSaiLibrary.png","
https://www.web3d.org/specifications/java/examples/images/X3dJavaSceneAccessInterfaceSaiLibrary.png
"];
Appearance45.texture = ImageTexture47;

Shape44.appearance = Appearance45;

Box48 = scene.createNode("Box");
Box48.DEF = "test-NMTOKEN_regex.0123456789";
Box48.CssClass = "untextured";
Shape44.geometry = Box48;

Anchor43.children[0] = Shape44;

Transform42.children[0] = Anchor43;

Scene32.children[7] = Transform42;

Shape49 = scene.createNode("Shape");
Shape49.DEF = "LineShape";
Appearance50 = scene.createNode("Appearance");
Material51 = scene.createNode("Material");
Material51.emissiveColor = [0.6,0.19607843,0.8];
Appearance50.material = Material51;

Shape49.appearance = Appearance50;

IndexedLineSet52 = scene.createNode("IndexedLineSet");
IndexedLineSet52.coordIndex = [0,1,2,3,4,0];
// Coordinate 3-tuple point count: 6
Coordinate53 = scene.createNode("Coordinate");
Coordinate53.point = [0,1.5,0,2,1.5,0,2,1.5,-2,-2,1.5,-2,-2,1.5,0,0,1.5,0];
IndexedLineSet52.coord = Coordinate53;

Shape49.geometry = IndexedLineSet52;

Scene32.children[8] = Shape49;

PositionInterpolator54 = scene.createNode("PositionInterpolator");
PositionInterpolator54.DEF = "BoxPathAnimator";
PositionInterpolator54.key = [0,0.125,0.375,0.625,0.875,1];
PositionInterpolator54.keyValue =
[0,1.5,0,2,1.5,0,2,1.5,-2,-2,1.5,-2,-2,1.5,0,0,1.5,0];
Scene32.children[9] = PositionInterpolator54;

TimeSensor55 = scene.createNode("TimeSensor");
TimeSensor55.DEF = "OrbitClock";
TimeSensor55.cycleInterval = 8.0;
TimeSensor55.loop = True;
Scene32.children[10] = TimeSensor55;

ROUTE56 = scene.createNode("ROUTE");
ROUTE56.fromField = "fraction_changed";
ROUTE56.fromNode = "OrbitClock";
ROUTE56.toField = "set_fraction";
ROUTE56.toNode = "BoxPathAnimator";
Scene32.children[11] = ROUTE56;

ROUTE57 = scene.createNode("ROUTE");
ROUTE57.fromField = "value_changed";
ROUTE57.fromNode = "BoxPathAnimator";
ROUTE57.toField = "set_translation";
ROUTE57.toNode = "LogoGeometryTransform";
Scene32.children[12] = ROUTE57;

Transform58 = scene.createNode("Transform");
Transform58.DEF = "TextTransform";
Transform58.translation = [0,-1.5,0];
Shape59 = scene.createNode("Shape");
Appearance60 = scene.createNode("Appearance");
Material61 = scene.createNode("Material");
Material61.USE = "GreenMaterial";
Appearance60.material = Material61;

Shape59.appearance = Appearance60;

Text62 = scene.createNode("Text");
Text62.string = ["X3D Java","SAI Library","X3DJSAIL"];
// Comment example A, plain quotation marks: He said, \"Immel did it!\"
// Comment example B, XML character entities: He said, "Immel did
it!"
MetadataSet63 = scene.createNode("MetadataSet");
MetadataSet63.name = "EscapedQuotationMarksMetadataSet";
MetadataString64 = scene.createNode("MetadataString");
MetadataString64.name = "quotesTestC";
MetadataString64.value = ["MFString example C, backslash-escaped quotes: He
said, \"Immel did it!\""];
MetadataSet63.e[0] = MetadataString64;

MetadataString65 = scene.createNode("MetadataString");
MetadataString65.name = "extraChildTest";
MetadataString65.value = ["checks MetadataSetObject addValue() method"];
MetadataSet63.e[1] = MetadataString65;

Text62.metadata = MetadataSet63;

FontStyle66 = scene.createNode("FontStyle");
FontStyle66.family = ["SERIF"];
FontStyle66.justify = ["MIDDLE","MIDDLE"];
Text62.fontStyle = FontStyle66;

Shape59.geometry = Text62;

Transform58.children[0] = Shape59;

Collision67 = scene.createNode("Collision");
// test containerField='proxy'
Shape68 = scene.createNode("Shape");
Shape68.DEF = "ProxyShape";
// alternative XML encoding: Text string='\"One, Two, Comment\" \"\" \"He
said, \\"Immel did it!\\"\"'
// alternative XML encoding: Text string='\"One, Two, Comment\" \"\" \"He
said, \\"Immel did it!\\"\" \"\"'
// alternative Java source: .setString(new String [] {\"One, Two,
Comment\", \"\", \"He said, \\\"Immel did it!\\\"\"})
// reference:
https://www.web3d.org/x3d/content/examples/Basic/X3dSpecifications/StringArrayEncodingExamplesIndex.html
Text69 = scene.createNode("Text");
Text69.string = ["One, Two, Text","","He said, \"Immel did it!\" \"\""];
Shape68.geometry = Text69;

Collision67.proxy = Shape68;

Transform58.children[1] = Collision67;

// It's a beautiful world
// ... for you!
// https://en.wikipedia.org/wiki/Beautiful_World_(Devo_song)
Scene32.children[13] = Transform58;

// repeatedly spin 180 degrees as a readable special effect
OrientationInterpolator70 = scene.createNode("OrientationInterpolator");
OrientationInterpolator70.DEF = "SpinInterpolator";
OrientationInterpolator70.key = [0,0.5,1];
OrientationInterpolator70.keyValue =
[0,1,0,4.712389,0,1,0,0,0,1,0,1.5707964];
Scene32.children[14] = OrientationInterpolator70;

TimeSensor71 = scene.createNode("TimeSensor");
TimeSensor71.DEF = "SpinClock";
TimeSensor71.cycleInterval = 5.0;
TimeSensor71.loop = True;
Scene32.children[15] = TimeSensor71;

ROUTE72 = scene.createNode("ROUTE");
ROUTE72.fromField = "fraction_changed";
ROUTE72.fromNode = "SpinClock";
ROUTE72.toField = "set_fraction";
ROUTE72.toNode = "SpinInterpolator";
Scene32.children[16] = ROUTE72;

ROUTE73 = scene.createNode("ROUTE");
ROUTE73.fromField = "value_changed";
ROUTE73.fromNode = "SpinInterpolator";
ROUTE73.toField = "rotation";
ROUTE73.toNode = "TextTransform";
Scene32.children[17] = ROUTE73;

Group74 = scene.createNode("Group");
Group74.DEF = "BackgroundGroup";
Background75 = scene.createNode("Background");
Background75.DEF = "GradualBackground";
Group74.children[0] = Background75;

Script76 = scene.createNode("Script");
Script76.DEF = "colorTypeConversionScript";
field77 = scene.createNode("field");
field77.name = "colorInput";
field77.accessType = "inputOnly";
field77.type = "SFColor";
Script76.field[0] = field77;

field78 = scene.createNode("field");
field78.name = "colorsOutput";
field78.accessType = "outputOnly";
field78.type = "MFColor";
Script76.field[1] = field78;


Script76.setSourceCode(`\n"+
"ecmascript:\n"+
"\n"+
"function colorInput (eventValue) // Example source code\n"+
"{\n"+
"   colorsOutput = new MFColor(eventValue); // assigning value sends output
event\n"+
"// Browser.print('colorInput=' + eventValue + ', colorsOutput=' +
colorsOutput + '\\n');\n"+
"}\n"+
"`)
Group74.children[1] = Script76;

ColorInterpolator79 = scene.createNode("ColorInterpolator");
ColorInterpolator79.DEF = "ColorAnimator";
ColorInterpolator79.key = [0,0.5,1];
ColorInterpolator79.keyValue =
[0.9411765,1,1,0.29411766,0,0.50980395,0.9411765,1,1];
// AZURE to INDIGO and back again
Group74.children[2] = ColorInterpolator79;

TimeSensor80 = scene.createNode("TimeSensor");
TimeSensor80.DEF = "ColorClock";
TimeSensor80.cycleInterval = 60.0;
TimeSensor80.loop = True;
Group74.children[3] = TimeSensor80;

ROUTE81 = scene.createNode("ROUTE");
ROUTE81.fromField = "colorsOutput";
ROUTE81.fromNode = "colorTypeConversionScript";
ROUTE81.toField = "skyColor";
ROUTE81.toNode = "GradualBackground";
Group74.children[4] = ROUTE81;

ROUTE82 = scene.createNode("ROUTE");
ROUTE82.fromField = "value_changed";
ROUTE82.fromNode = "ColorAnimator";
ROUTE82.toField = "colorInput";
ROUTE82.toNode = "colorTypeConversionScript";
Group74.children[5] = ROUTE82;

ROUTE83 = scene.createNode("ROUTE");
ROUTE83.fromField = "fraction_changed";
ROUTE83.fromNode = "ColorClock";
ROUTE83.toField = "set_fraction";
ROUTE83.toNode = "ColorAnimator";
Group74.children[6] = ROUTE83;

Scene32.children[18] = Group74;

ProtoDeclare84 = scene.createNode("ProtoDeclare");
ProtoDeclare84.name = "ArtDeco01Material";
ProtoDeclare84.appinfo = "tooltip: ArtDeco01Material prototype is a
Material node";
ProtoInterface85 = scene.createNode("ProtoInterface");
field86 = scene.createNode("field");
field86.name = "description";
field86.accessType = "inputOutput";
field86.appinfo = "tooltip for descriptionField";
field86.type = "SFString";
field86.value = "ArtDeco01Material prototype is a Material node";
ProtoInterface85.field[0] = field86;

field87 = scene.createNode("field");
field87.name = "enabled";
field87.accessType = "inputOutput";
field87.type = "SFBool";
field87.value = "true";
ProtoInterface85.field[1] = field87;

ProtoDeclare84.protoInterface = ProtoInterface85;

ProtoBody88 = scene.createNode("ProtoBody");
// Initial node of ProtoBody determines prototype node type
Material89 = scene.createNode("Material");
Material89.ambientIntensity = 0.25;
Material89.diffuseColor = [0.282435,0.085159,0.134462];
Material89.shininess = 0.127273;
Material89.specularColor = [0.276305,0.11431,0.139857];
ProtoBody88.children[0] = Material89;

// [HelloWorldProgram diagnostic] should be connected to scene graph:
artDeco01ProtoDeclare.getNodeType()=\"Material\"
// presence of follow-on TouchSensor shows that additional nodes are
allowed in ProtoBody after initial node, regardless of node types
TouchSensor90 = scene.createNode("TouchSensor");
TouchSensor90.description = "within ProtoBody";
IS91 = scene.createNode("IS");
connect92 = scene.createNode("connect");
connect92.nodeField = "description";
connect92.protoField = "description";
IS91.connect[0] = connect92;

connect93 = scene.createNode("connect");
connect93.nodeField = "enabled";
connect93.protoField = "enabled";
IS91.connect[1] = connect93;

TouchSensor90.iS = IS91;

ProtoBody88.children[1] = TouchSensor90;

ProtoDeclare84.protoBody = ProtoBody88;

Scene32.children[19] = ProtoDeclare84;

ExternProtoDeclare94 = scene.createNode("ExternProtoDeclare");
ExternProtoDeclare94.name = "ArtDeco02Material";
ExternProtoDeclare94.appinfo = "this is a different Material node";
ExternProtoDeclare94.url = ["
http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter14Prototypes/ArtDecoPrototypesExcerpt.x3d#ArtDeco02Material
","
http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter14Prototypes/ArtDecoPrototypesExcerpt.x3dv#ArtDeco02Material
"];
// [HelloWorldProgram diagnostic]
artDeco02ExternProtoDeclare.getNodeType()=\"ERROR_UNKNOWN_EXTERNPROTODECLARE_NODE_TYPE:
ExternProtoDeclare name='ArtDeco02Material' type cannot be remotely
accessed at run time. TODO X3DJSAIL needs to add further capability that
retrieves the ExternProtoDeclare file.\"
field95 = scene.createNode("field");
field95.name = "description";
field95.accessType = "inputOutput";
field95.appinfo = "tooltip for descriptionField";
field95.type = "SFString";
ExternProtoDeclare94.field[0] = field95;

Scene32.children[20] = ExternProtoDeclare94;

// Tested ArtDeco01ProtoInstance, ArtDeco02ProtoInstance for improper node
type when ProtoInstance is added in wrong place
Shape96 = scene.createNode("Shape");
Shape96.DEF = "TestShape1";
Appearance97 = scene.createNode("Appearance");
Appearance97.DEF = "TestAppearance1";
// ArtDeco01Material prototype goes here... TODO ensure setContainerField
is handled in exported Java
ProtoInstance98 = scene.createNode("ProtoInstance");
ProtoInstance98.name = "ArtDeco01Material";
// [HelloWorldProgram diagnostic]
ArtDeco01ProtoInstance.getNodeType()=\"Material\"
fieldValue99 = scene.createNode("fieldValue");
fieldValue99.name = "description";
fieldValue99.value = "ArtDeco01Material can substitute for a Material node";
ProtoInstance98.fieldValue[0] = fieldValue99;

Appearance97.material = ProtoInstance98;

Shape96.appearance = Appearance97;

Sphere100 = scene.createNode("Sphere");
Sphere100.radius = 0.001;
Shape96.geometry = Sphere100;

Scene32.children[21] = Shape96;

Shape101 = scene.createNode("Shape");
Shape101.DEF = "TestShape2";
Appearance102 = scene.createNode("Appearance");
Appearance102.DEF = "TestAppearance2";
// ArtDeco02Material prototype goes here... TODO ensure setContainerField
is handled in exported Java
ProtoInstance103 = scene.createNode("ProtoInstance");
ProtoInstance103.DEF = "ArtDeco02MaterialDEF";
ProtoInstance103.name = "ArtDeco02Material";
// [HelloWorldProgram diagnostic]
ArtDeco02ProtoInstance.getNodeType()=\"ERROR_UNKNOWN_EXTERNPROTODECLARE_NODE_TYPE:
ExternProtoDeclare name='ArtDeco02Material' type cannot be remotely
accessed at run time. TODO X3DJSAIL needs to add further capability that
retrieves the ExternProtoDeclare file.\"
fieldValue104 = scene.createNode("fieldValue");
fieldValue104.name = "description";
fieldValue104.value = "ArtDeco02Material can substitute for another
Material node";
ProtoInstance103.fieldValue[0] = fieldValue104;

Appearance102.material = ProtoInstance103;

Shape101.appearance = Appearance102;

Cone105 = scene.createNode("Cone");
Cone105.bottomRadius = 0.001;
Cone105.height = 0.001;
Shape101.geometry = Cone105;

Scene32.children[22] = Shape101;

Shape106 = scene.createNode("Shape");
Shape106.DEF = "TestShape3";
Appearance107 = scene.createNode("Appearance");
Appearance107.DEF = "TestAppearance3";
// ArtDeco02Material ProtoInstance USE goes here. Note that name field is
NOT defined as part of ProtoInstance USE.
ProtoInstance108 = scene.createNode("ProtoInstance");
ProtoInstance108.USE = "ArtDeco02MaterialDEF";
Appearance107.material = ProtoInstance108;

Shape106.appearance = Appearance107;

Cylinder109 = scene.createNode("Cylinder");
Cylinder109.height = 0.001;
Cylinder109.radius = 0.001;
Shape106.geometry = Cylinder109;

Scene32.children[23] = Shape106;

Inline110 = scene.createNode("Inline");
Inline110.DEF = "inlineSceneDef";
Inline110.url = ["someOtherScene.x3d","
https://www.web3d.org/specifications/java/examples/someOtherScene.x3d"];
Scene32.children[24] = Inline110;

IMPORT111 = scene.createNode("IMPORT");
IMPORT111.AS = "WorldInfoDEF2";
IMPORT111.importedDEF = "WorldInfoDEF";
IMPORT111.inlineDEF = "inlineSceneDef";
Scene32.children[25] = IMPORT111;

EXPORT112 = scene.createNode("EXPORT");
EXPORT112.AS = "WorldInfoDEF3";
EXPORT112.localDEF = "WorldInfoDEF";
Scene32.children[26] = EXPORT112;

ProtoDeclare113 = scene.createNode("ProtoDeclare");
ProtoDeclare113.name = "MaterialModulator";
ProtoDeclare113.appinfo = "mimic a Material node and modulate fields as an
animation effect";
ProtoDeclare113.documentation = "
http://x3dgraphics.com/examples/X3dForWebAuthors/Chapter14Prototypes/MaterialModulatorIndex.html
";
ProtoInterface114 = scene.createNode("ProtoInterface");
field115 = scene.createNode("field");
field115.name = "enabled";
field115.accessType = "inputOutput";
field115.type = "SFBool";
field115.value = "true";
ProtoInterface114.field[0] = field115;

field116 = scene.createNode("field");
field116.name = "diffuseColor";
field116.accessType = "inputOutput";
field116.type = "SFColor";
field116.value = "0 0 0";
ProtoInterface114.field[1] = field116;

field117 = scene.createNode("field");
field117.name = "emissiveColor";
field117.accessType = "inputOutput";
field117.type = "SFColor";
field117.value = "0.05 0.05 0.5";
ProtoInterface114.field[2] = field117;

field118 = scene.createNode("field");
field118.name = "specularColor";
field118.accessType = "inputOutput";
field118.type = "SFColor";
field118.value = "0 0 0";
ProtoInterface114.field[3] = field118;

field119 = scene.createNode("field");
field119.name = "transparency";
field119.accessType = "inputOutput";
field119.type = "SFFloat";
field119.value = "0.0";
ProtoInterface114.field[4] = field119;

field120 = scene.createNode("field");
field120.name = "shininess";
field120.accessType = "inputOutput";
field120.type = "SFFloat";
field120.value = "0.0";
ProtoInterface114.field[5] = field120;

field121 = scene.createNode("field");
field121.name = "ambientIntensity";
field121.accessType = "inputOutput";
field121.type = "SFFloat";
field121.value = "0.0";
ProtoInterface114.field[6] = field121;

ProtoDeclare113.protoInterface = ProtoInterface114;

ProtoBody122 = scene.createNode("ProtoBody");
Material123 = scene.createNode("Material");
Material123.DEF = "MaterialNode";
IS124 = scene.createNode("IS");
connect125 = scene.createNode("connect");
connect125.nodeField = "diffuseColor";
connect125.protoField = "diffuseColor";
IS124.connect[0] = connect125;

connect126 = scene.createNode("connect");
connect126.nodeField = "emissiveColor";
connect126.protoField = "emissiveColor";
IS124.connect[1] = connect126;

connect127 = scene.createNode("connect");
connect127.nodeField = "specularColor";
connect127.protoField = "specularColor";
IS124.connect[2] = connect127;

connect128 = scene.createNode("connect");
connect128.nodeField = "transparency";
connect128.protoField = "transparency";
IS124.connect[3] = connect128;

connect129 = scene.createNode("connect");
connect129.nodeField = "shininess";
connect129.protoField = "shininess";
IS124.connect[4] = connect129;

connect130 = scene.createNode("connect");
connect130.nodeField = "ambientIntensity";
connect130.protoField = "ambientIntensity";
IS124.connect[5] = connect130;

Material123.iS = IS124;

ProtoBody122.children[0] = Material123;

// Only first node (the node type) is renderable, others are along for the
ride
Script131 = scene.createNode("Script");
Script131.DEF = "MaterialModulatorScript";
field132 = scene.createNode("field");
field132.name = "enabled";
field132.accessType = "inputOutput";
field132.type = "SFBool";
Script131.field[0] = field132;

field133 = scene.createNode("field");
field133.name = "diffuseColor";
field133.accessType = "inputOutput";
field133.type = "SFColor";
Script131.field[1] = field133;

field134 = scene.createNode("field");
field134.name = "newColor";
field134.accessType = "outputOnly";
field134.type = "SFColor";
Script131.field[2] = field134;

field135 = scene.createNode("field");
field135.name = "clockTrigger";
field135.accessType = "inputOnly";
field135.type = "SFTime";
Script131.field[3] = field135;

IS136 = scene.createNode("IS");
connect137 = scene.createNode("connect");
connect137.nodeField = "enabled";
connect137.protoField = "enabled";
IS136.connect[0] = connect137;

connect138 = scene.createNode("connect");
connect138.nodeField = "diffuseColor";
connect138.protoField = "diffuseColor";
IS136.connect[1] = connect138;

Script131.iS = IS136;


Script131.setSourceCode(`\n"+
"ecmascript:\n"+
"function initialize ()\n"+
"{\n"+
"    newColor = diffuseColor; // start with correct color\n"+
"}\n"+
"function set_enabled (newValue)\n"+
"{\n"+
" enabled = newValue;\n"+
"}\n"+
"function clockTrigger (timeValue)\n"+
"{\n"+
"    if (!enabled) return;\n"+
"    red   = newColor.r;\n"+
"    green = newColor.g;\n"+
"    blue  = newColor.b;\n"+
"    \n"+
"    // note different modulation rates for each color component, % is
modulus operator\n"+
"    newColor = new SFColor ((red + 0.02) % 1, (green + 0.03) % 1, (blue +
0.04) % 1);\n"+
" if (enabled)\n"+
" {\n"+
" Browser.print ('diffuseColor=(' + red + ',' + green + ',' + blue + ')
newColor=' + newColor.toString() + '\\n');\n"+
" }\n"+
"}\n"+
"`)
ProtoBody122.children[1] = Script131;

ProtoDeclare113.protoBody = ProtoBody122;

Scene32.children[27] = ProtoDeclare113;

// Test success: declarative statement createDeclarativeShapeTests()
Group139 = scene.createNode("Group");
Group139.DEF = "DeclarativeGroupExample";
Shape140 = scene.createNode("Shape");
MetadataString141 = scene.createNode("MetadataString");
MetadataString141.DEF = "FindableMetadataStringTest";
MetadataString141.name = "findThisNameValue";
MetadataString141.value = ["test case"];
Shape140.metadata = MetadataString141;

Appearance142 = scene.createNode("Appearance");
Appearance142.DEF = "DeclarativeAppearanceExample";
// DeclarativeMaterialExample gets overridden by subsequently added
MaterialModulator ProtoInstance
ProtoInstance143 = scene.createNode("ProtoInstance");
ProtoInstance143.DEF = "MyMaterialModulator";
ProtoInstance143.name = "MaterialModulator";
Appearance142.material = ProtoInstance143;

Shape140.appearance = Appearance142;

Cone144 = scene.createNode("Cone");
Cone144.bottom = False;
Cone144.bottomRadius = 0.05;
Cone144.height = 0.1;
Shape140.geometry = Cone144;

Group139.children[0] = Shape140;

// Test success: declarativeGroup.addChild() singleton pipeline method
Scene32.children[28] = Group139;

// Test success: declarative statement addChild()
// Test success: x3dModel.findNodeByDEF(DeclarativeAppearanceExample) =
<Appearance DEF='DeclarativeAppearanceExample'/> i.e. <Appearance
DEF='DeclarativeAppearanceExample'> <!- - DeclarativeMaterialExample gets
overridden by subsequently added MaterialModulator ProtoInstance - ->
<ProtoInstance DEF='MyMaterialModulator' name='MaterialModulator'
containerField='material'/> </Appearance>
// Test success: x3dModel.findElementByNameValue(findThisNameValue) =
<MetadataString DEF='FindableMetadataStringTest' name='findThisNameValue'
value='\"test case\"'/>
// Test success: x3dModel.findElementByNameValue(\"ArtDeco01Material\",
\"ProtoDeclare\") found
// Test success: x3dModel.findElementByNameValue(\"MaterialModulator\",
\"ProtoDeclare\") found
// Test success: x3dModel.findElementByNameValue(\"MaterialModulator\",
\"ProtoInstance\") found
Group145 = scene.createNode("Group");
Group145.DEF = "TestFieldObjectsGroup";
// testFieldObjects() results
// SFBool default=true, true=true, false=false, negate()=true
// MFBool default=, initial=true false true, negate()=false true false
// SFFloat default=0.0, initial=1.0, setValue(2)=2.0, setValue(3.0f)=3.0,
setValue(4.0)=4.0
// MFFloat default=, initial=1 2 3, append(5)=1 2 3 5, inserts(3,4)(0,0)=0
1 2 3 4 5, append(6)=0 1 2 3 4 5 6, size()=7
// ... get1Value[3]=3.0, remove[1]=0 2 3 4 5 6, set1Value(0,10)=10 2 3 4 5
6, multiply(2)=20 4 6 8 10 12, clear=
// SFVec3f default=0 0 0, initial=1 2 3, setValue=4 5 6, multiply(2)=8 10
12, normalize()=0.45584232 0.5698029 0.68376344, regex matches()=true
// regex test SFVec3f().matches(\"1 2 3\")=true, regex test
SFVec3f().matches(\"1 2 3 4\")=false, regex test
(SFRotationObject.matches(\"0 0 0 0\")=true, failure detecting illegal
(zero axis) rotation value
Scene32.children[29] = Group145;

Sound146 = scene.createNode("Sound");
Sound146.location = [0,1.6,0];
// set sound-ellipsoid location height at 1.6m to match typical avatar
height
AudioClip147 = scene.createNode("AudioClip");
AudioClip147.description = "chimes";
AudioClip147.url = ["chimes.wav","
https://www.web3d.org/x3d/content/examples/ConformanceNist/Sounds/AudioClip/chimes.wav
"];
// Scene example fragment from
https://www.web3d.org/x3d/content/examples/ConformanceNist/Sounds/AudioClip/default.x3d
Sound146.source = AudioClip147;

Scene32.children[30] = Sound146;

Sound148 = scene.createNode("Sound");
Sound148.location = [0,1.6,0];
// set sound-ellipsoid location height at 1.6m to match typical avatar
height
MovieTexture149 = scene.createNode("MovieTexture");
MovieTexture149.description = "mpgsys.mpg from ConformanceNist suite";
MovieTexture149.url = ["mpgsys.mpg","
https://www.web3d.org/x3d/content/examples/ConformanceNist/Appearance/MovieTexture/mpgsys.mpg
"];
// Scene example fragment from
https://www.web3d.org/x3d/content/examples/ConformanceNist/Appearance/MovieTexture/mpeg1-systems.x3d
// Expected containerField='source', allowed containerField
values=\"texture\" \"source\" \"back\" \"bottom\" \"front\" \"left\"
\"right\" \"top\" \"backTexture\" \"bottomTexture\" \"frontTexture\"
\"leftTexture\" \"rightTexture\" \"topTexture\" \"watchList\"
Sound148.source = MovieTexture149;

Scene32.children[31] = Sound148;

// Test success: AnchorObject.isNode()=true, siteAnchor.isNode()=true
// Test success: AnchorObject.isStatement()=false,
siteAnchor.isStatement()=false
// Test success: ROUTEObject.isNode()=false,
orbitPositionROUTE.isNode()=false
// Test success: ROUTEObject.isStatement()=true,
orbitPositionROUTE.isStatement()=true
// Test success: CommentsBlock.isNode()=false, testComments.isNode()=false
// Test failure: CommentsBlock.isStatement()=true,
testComments.isStatement()=true
Shape150 = scene.createNode("Shape");
Shape150.DEF = "ExtrusionShape";
// ExampleExtrusion isCrossSectionClosed()=true, crossSection='[1.0, 1.0,
1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0]'
// ExampleExtrusion isSpineClosed()=false, spine='[0.0, 0.0, 0.0, 0.0, 1.0,
0.0]'
Appearance151 = scene.createNode("Appearance");
Appearance151.DEF = "TransparentAppearance";
Material152 = scene.createNode("Material");
Material152.transparency = 1.0;
Appearance151.material = Material152;

Shape150.appearance = Appearance151;

Extrusion153 = scene.createNode("Extrusion");
Extrusion153.DEF = "ExampleExtrusion";
Shape150.geometry = Extrusion153;

Scene32.children[32] = Shape150;

Group154 = scene.createNode("Group");
// Test MFNode children array as an ordered list consisting of comments,
statements, ProtoInstance and nodes
ProtoDeclare155 = scene.createNode("ProtoDeclare");
ProtoDeclare155.name = "NewWorldInfo";
ProtoInterface156 = scene.createNode("ProtoInterface");
field157 = scene.createNode("field");
field157.name = "description";
field157.accessType = "initializeOnly";
field157.type = "SFString";
ProtoInterface156.field[0] = field157;

ProtoDeclare155.protoInterface = ProtoInterface156;

ProtoBody158 = scene.createNode("ProtoBody");
WorldInfo159 = scene.createNode("WorldInfo");
ProtoBody158.children[0] = WorldInfo159;

ProtoDeclare155.protoBody = ProtoBody158;

Group154.children[0] = ProtoDeclare155;

ProtoInstance160 = scene.createNode("ProtoInstance");
ProtoInstance160.DEF = "Proto1";
ProtoInstance160.name = "NewWorldInfo";
fieldValue161 = scene.createNode("fieldValue");
fieldValue161.name = "description";
fieldValue161.value = "testing 1 2 3";
ProtoInstance160.fieldValue[0] = fieldValue161;

Group154.children[1] = ProtoInstance160;

Group162 = scene.createNode("Group");
Group162.DEF = "Node2";
// intentionally empty
Group154.children[2] = Group162;

ProtoInstance163 = scene.createNode("ProtoInstance");
ProtoInstance163.DEF = "Proto3";
ProtoInstance163.name = "NewWorldInfo";
Group154.children[3] = ProtoInstance163;

Transform164 = scene.createNode("Transform");
Transform164.DEF = "Node4";
// intentionally empty
Group154.children[4] = Transform164;

// Test satisfactorily creates MFNode children array as an ordered list
with mixed content
Scene32.children[33] = Group154;

ProtoDeclare165 = scene.createNode("ProtoDeclare");
ProtoDeclare165.name = "ShaderProto";
ProtoBody166 = scene.createNode("ProtoBody");
ProgramShader167 = scene.createNode("ProgramShader");
ProtoBody166.child[0] = ProgramShader167;

ProtoDeclare165.protoBody = ProtoBody166;

Scene32.children[34] = ProtoDeclare165;

Shape168 = scene.createNode("Shape");
Appearance169 = scene.createNode("Appearance");
// Test MFNode shaders array as an ordered list consisting of comments,
ProtoInstance and nodes
// Test satisfactorily creates MFNode shaders array as an ordered list with
mixed content
ProgramShader170 = scene.createNode("ProgramShader");
ProgramShader170.DEF = "TestShader1";
ShaderProgram171 = scene.createNode("ShaderProgram");
ShaderProgram171.DEF = "TestShader2";
ProgramShader170.programs[0] = ShaderProgram171;

Appearance169.shaders[0] = ProgramShader170;

ProtoInstance172 = scene.createNode("ProtoInstance");
ProtoInstance172.DEF = "TestShader3";
ProtoInstance172.name = "ShaderProto";
Appearance169.material = ProtoInstance172;

ComposedShader173 = scene.createNode("ComposedShader");
ComposedShader173.DEF = "TestShader4";
ShaderPart174 = scene.createNode("ShaderPart");
ShaderPart174.DEF = "TestShader5";
ComposedShader173.parts[0] = ShaderPart174;

Appearance169.shaders[1] = ComposedShader173;

Shape168.appearance = Appearance169;

Scene32.children[35] = Shape168;

Transform175 = scene.createNode("Transform");
Transform175.DEF = "SpecialtyNodes";
CADLayer176 = scene.createNode("CADLayer");
CADAssembly177 = scene.createNode("CADAssembly");
CADPart178 = scene.createNode("CADPart");
CADFace179 = scene.createNode("CADFace");
CADPart178.children[0] = CADFace179;

CADAssembly177.children[0] = CADPart178;

CADLayer176.children[0] = CADAssembly177;

Transform175.children[0] = CADLayer176;

EspduTransform180 = scene.createNode("EspduTransform");
EspduTransform180.geoSystem = ["GD","WE"];
Transform175.children[1] = EspduTransform180;

ReceiverPdu181 = scene.createNode("ReceiverPdu");
ReceiverPdu181.geoSystem = ["GD","WE"];
Transform175.children[2] = ReceiverPdu181;

SignalPdu182 = scene.createNode("SignalPdu");
SignalPdu182.geoSystem = ["GD","WE"];
Transform175.children[3] = SignalPdu182;

TransmitterPdu183 = scene.createNode("TransmitterPdu");
TransmitterPdu183.geoSystem = ["GD","WE"];
Transform175.children[4] = TransmitterPdu183;

DISEntityManager184 = scene.createNode("DISEntityManager");
DISEntityTypeMapping185 = scene.createNode("DISEntityTypeMapping");
DISEntityManager184.mapping[0] = DISEntityTypeMapping185;

Transform175.children[5] = DISEntityManager184;

Scene32.children[36] = Transform175;

X3D0.scene = Scene32;



On Sat, Apr 11, 2020 at 8:40 AM Andreas Plesch <andreasplesch at gmail.com>
wrote:

> Hi John,
>
> x_ite just follows standard SAI, internal or external:
>
> //get Browser
> browser=X3D.getBrowser(); //X3D is global defined by x_ite.js
> //get current scene
> scene=browser.currentScene;
> //make shape node
> shape=scene.createNode('Shape');
> //make box node
> box=scene.createNode('Box');
> //set geometry field
> shape.geometry=box;
> //add as root node (for example)
> scene.addRootNode(shape);
>
> For me the easiest way to experiment with scripting like this, is to
> use the Chrome dev tools console with a simple scene like:
>
> https://www.web3d.org/x3d/content/examples/Basic/UniversalMediaPanoramas/desert3X_ITE.html
> Following the steps will give you a white box visible in the active scene.
>
> x3dom uses the DOM as an interface to the scene. So you create DOM
> elements using HTML5 methods and add those to the Scene DOM element.
> There may be a way to avoid using the DOM and use internal, SAI like
> functions. For example, the javascript domNode._x3dom property gives
> you access to fields and methods for a node. But usually it is easiest
> and most interoperable on a HTML5 page to use the DOM.
>
> The field names are the same across browser but the internal
> representation of field values (as a javascript object) is very
> different. So one cannot use the results of SAI x_ite calls directly
> with x3dom, or vice versa. It is necesssary to go through encodings.
>
> I do not think X3DJSAIL deals a lot with Browser or ExecutionContext
> SAI functions since they are tied to the specific browser but I may be
> wrong.
>
> Andreas
>
> On Sat, Apr 11, 2020 at 2:58 AM John Carlson <yottzumm at gmail.com> wrote:
> >
> > Could Andreas explain how to use createNode in the context of X_ITE SAI?
> > I think that createNode may be the one significant thing missing from
> X3DOM SAI.
> > There's an unrelated one in the physics code.
> >
> > That is, you use createNode to createNodes in SAI, then you use the
> fields of the returned object.  Are these the same across browsers?
> >
> > Here's how to get a node from the standard:
> >
> > Browser.currentScene.createNode('Shape');
> >
> > Again, there is no createNode in X3DJSAIL to speak of.
> >
> > Thanks,
> >
> > John
> >
> > On Sat, Apr 11, 2020 at 1:24 AM John Carlson <yottzumm at gmail.com> wrote:
> >>
> >> We have 2 versions of  JavaScript server side API, Nashorn and Node,
> both dependent on X3DJSAIL, and the code looks similar.  However, we do not
> have a JavaScript native version yet, even with JSweet (it's incomplete).
> >>
> >> I believe that we should pursue an external SAI compatible with X_ITE,
> since X3DOM already has an external SAI.
> >>
> >> Below is an example of "External" with X_ITE. Note that X3D is required
> to be defined, and x_ite.js should be loaded before X3D is called.  So how
> do we do that in node?  This is why I've been suggesting headless browsers!
> >>
> >> ...so...I need to figure out an example of Transform in the standard.
> It would seem like the thing to do would be to implement createNode?  Are
> there any examples of createNode?  Yes, in X_ITE at least.  Do we need to
> create an execution context to use it?  Yes!
> >>
> >> Is there an X_ITE example of external createNode?
> >>
> >> Yes!
> >>
> >> As far as I can tell there is not a X3DOM version of ECMAScript SAI's
> createNode.
> >>
> >> So I think we should start with X_ITE as I said before, and try to
> create an External ECMAScript SAI script (not DOM).
> >>
> >> Do people agree that we should try to create an ECMAScript SAI example
> from outside X_ITE?
> >>
> >> It appears that we either have to start from X3D(), below.   Can we
> make X3D() into an external SAI?
> >>
> >> Do we need a browser in nodejs?
> >>
> >> has anyone looked into chrome embedded framework?
> >>
> >> John
> >>
> >>
> >>
> >>
> -----------------------------------------------------------------------------
> >> function load_X_ITE_XML(content, selector) {
> >>         X3D(function() {
> >>                 var browser = X3D.getBrowser(selector);
> >>
>  browser.replaceWorld(browser.createX3DFromString(content));
> >>         }, function() {
> >>                 alert("Failed to render XML to X_ITE");
> >>         });
> >> }
> >>
> >> function load_X_ITE_DOM(element, selector) {
> >>         X3D(function() {
> >>                 if (typeof X3D.getBrowser !== 'undefined') {
> >>                         var browser = X3D.getBrowser(selector);
> >>                         if (typeof browser !== 'undefined' && typeof
> browser.importDocument !== 'undefined') {
> >>                                 var importedScene =
> browser.importDocument(element);
> >>                                 browser.replaceWorld(importedScene);
> >>                         }
> >>                 }
> >>         }, function() {
> >>                 alert("Failed to render DOM to X_ITE");
> >>         });
> >> }
> >>
> >> function load_X_ITE_JS(jsobj, selector) {
> >>         X3D(function() {
> >>                 if (typeof X3D.getBrowser !== 'undefined') {
> >>                         var browser = X3D.getBrowser(selector);
> >>                         if (typeof browser !== 'undefined' && typeof
> browser.importJS !== 'undefined') {
> >>                                 var importedScene =
> browser.importJS(jsobj);
> >>                                 browser.replaceWorld(importedScene);
> >>                         }
> >>                 }
> >>         }, function() {
> >>                 alert("Failed to render JSON to X_ITE");
> >>         });
> >> }
> >>
> -------------------------------------------------------------------------------------------------------------
> >> John
>
>
>
> --
> Andreas Plesch
> Waltham, MA 02453
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20200411/7986a67c/attachment-0001.html>


More information about the x3d-public mailing list