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

Andreas Plesch andreasplesch at gmail.com
Sun Apr 12 03:39:04 PDT 2020


Yes, I believe createX3DFromString is the only way to create a
ProtoDeclaration. The abstract SAI spec. mentions an example. It then may
have to be added to the ProtoDeclarationArray of the scene before a new
instance can be created, with createProto () .

The easter bunny.


---on the phone---

On Sun, Apr 12, 2020, 12:04 AM John Carlson <yottzumm at gmail.com> wrote:

> Still haven't found a way to create PROTOs with SAI
> (createVrmlFromString?).
>
> Here's the examples, if someone wants an online version:
>
>
> https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/vrmlscript/examples/
>
>
> (paste file into dev tools console)
>
> This is kind of how I'm learning SAI!
>
> On Sat, Apr 11, 2020 at 10:49 PM John Carlson <yottzumm at gmail.com> wrote:
>
>> Okay, figured a bit out.  Next question: How do you create a PROTO
>> with SAI?
>>
>> Thanks, here's the latest version of my abox.xhtml example (smaller than
>> Hello World):
>>
>> I'm going to set it aside for tonight, I think.
>>
>> John
>> var browser = X3D.getBrowser();
>> var X3D0 = {}; // not really used.
>> X3D0.profile = "Immersive";
>> X3D0.version = "3.3";
>> ProtoDeclare2 = browser.currentScene.createNode("ProtoDeclare");
>> ProtoDeclare2.name = "anyShape";
>> ProtoInterface3 = browser.currentScene.createNode("ProtoInterface");
>> field4 = browser.currentScene.createNode("field");
>> field4.name = "myShape";
>> field4.accessType = "inputOutput";
>> field4.type = "MFNode";
>> Shape5 = browser.currentScene.createNode("Shape");
>> Sphere6 = browser.currentScene.createNode("Sphere");
>> Shape5.geometry = Sphere6;
>>
>> field4.children[0] = Shape5;
>>
>> ProtoInterface3.field[0] = field4;
>>
>> ProtoDeclare2.protoInterface = ProtoInterface3;
>>
>> ProtoBody7 = browser.currentScene.createNode("ProtoBody");
>> Transform8 = browser.currentScene.createNode("Transform");
>> IS9 = browser.currentScene.createNode("IS");
>> connect10 = browser.currentScene.createNode("connect");
>> connect10.nodeField = "children";
>> connect10.protoField = "myShape";
>> IS9.connect[0] = connect10;
>>
>> Transform8.iS = IS9;
>>
>> ProtoBody7.children[0] = Transform8;
>>
>> ProtoDeclare2.protoBody = ProtoBody7;
>>
>> browser.currentScene.children[0] = ProtoDeclare2;
>>
>> ProtoDeclare11 = browser.currentScene.createNode("ProtoDeclare");
>> ProtoDeclare11.name = "one";
>> ProtoInterface12 = browser.currentScene.createNode("ProtoInterface");
>> field13 = browser.currentScene.createNode("field");
>> field13.name = "myShape";
>> field13.accessType = "inputOutput";
>> field13.type = "MFNode";
>> Shape14 = browser.currentScene.createNode("Shape");
>> Cylinder15 = browser.currentScene.createNode("Cylinder");
>> Shape14.geometry = Cylinder15;
>>
>> field13.children[0] = Shape14;
>>
>> ProtoInterface12.field[0] = field13;
>>
>> ProtoDeclare11.protoInterface = ProtoInterface12;
>>
>> ProtoBody16 = browser.currentScene.createNode("ProtoBody");
>> Transform17 = browser.currentScene.createNode("Transform");
>> ProtoInstance18 = browser.currentScene.createNode("ProtoInstance");
>> ProtoInstance18.name = "anyShape";
>> IS19 = browser.currentScene.createNode("IS");
>> connect20 = browser.currentScene.createNode("connect");
>> connect20.nodeField = "myShape";
>> connect20.protoField = "myShape";
>> IS19.connect[0] = connect20;
>>
>> ProtoInstance18.iS = IS19;
>>
>> Transform17.children[0] = ProtoInstance18;
>>
>> ProtoBody16.children[0] = Transform17;
>>
>> ProtoDeclare11.protoBody = ProtoBody16;
>>
>> browser.currentScene.children[1] = ProtoDeclare11;
>>
>> ProtoInstance21 = browser.currentScene.createNode("ProtoInstance");
>> ProtoInstance21.name = "one";
>> fieldValue22 = browser.currentScene.createNode("fieldValue");
>> fieldValue22.name = "myShape";
>> Shape23 = browser.currentScene.createNode("Shape");
>> Box24 = browser.currentScene.createNode("Box");
>> Box24.size = [140,140,140];
>> Shape23.geometry = Box24;
>>
>> fieldValue22.children[0] = Shape23;
>>
>> ProtoInstance21.fieldValue[0] = fieldValue22;
>>
>> browser.currentScene.children[2] = ProtoInstance21;
>>
>>
>> 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/20200412/ccad9ce2/attachment-0001.html>


More information about the x3d-public mailing list