[x3d-public] Cobweb_dom...Script Magic? Loading DOM subscenes after parentinX3DOM and Cobweb.

John Carlson yottzumm at gmail.com
Sat May 20 21:17:16 PDT 2017

Yes, there’s a user option in X3DJSONLD to turn off PROTO expansion, but it applys to both Cobweb DOM and X3DOM, and does not apply to EXTERNPROTOs, which are handled on the server—probably why I don’t support EXTERNPROTOs on coderextreme.net, since I have no server side running code there (please someone fix/enable client-side EXTERNPROTOs in X3DJSONLD—If possible!)  The code merely imports the ExternProtoDeclare as a ProtoDeclare for further processing I believe.  I doubt if this simple approach might work in practice (on the client), not sure.  I’ve forgotten what I do with the hastag once I have a ProtoDeclare—there’s no URL in ProtoDeclare that I know of.  Just musing.

I check against the standard JSON schema, so any X3DOM specific things should be caught, and the user is given the option of continuing.  We also have filtering in X3dToJson.xslt now, for X3D, subdivision and id, I believe.

Thanks for the advice on the global Group.  I suspect that X3DOM treats Scenes differently than Cobweb?  What if the original Scene doesn’t have a Group, but rather, a ProtoDeclare? I suspect I need to add a Group between the Scene and the children objects?  It seems like I should have a base <X3D><Scene><Group>…</X3D> and add and remove X3D scene children to/from the Group (no wonder X3DOM is throwing errors).  This might save on WebGL contexts as well?  Why does Cobweb stop showing in X3DJSONLD after several loads?

This is good advice.



Sent from Mail for Windows 10

From: Andreas Plesch
Sent: Saturday, May 20, 2017 11:47 PM
To: John Carlson
Cc: x3dom mlist; X3D Graphics public mailing list; holger.seelig at yahoo.de
Subject: RE: Cobweb_dom...Script Magic? Loading DOM subscenes after parentinX3DOM and Cobweb.

On May 20, 2017 8:46 PM, "John Carlson" <yottzumm at gmail.com> wrote:
I would like to separate the main scene loading from the sub scene loading, so I can load many, many subscenes, plus it will make coding easier.
I am almost able to do that, but I am not sure when the Scene object loads in the main scene.
What wasn’t working before was that the child scene was added before it displayed in Cobweb.  That has been fixed now.
It’s an Inline, but not in typical X3D parlance.  It’s a DOM object added afterwards, by using a selector on the DOM.
I see. In terms of the X3D event model it would be then be safer to have a global Group and add the late content as children to this Group. For cobweb and cobweb_dom, however, this should not be necessary since cobweb treats Scene as a grouping node already.

I can expand prototypes inline, as the example now shows.  That’s not a problem, really.  I just want to make a way NOT to expand PROTOs for Cobweb.
A user option in the JSON loader/expander to not expand ?

Yes, I am loading X3DJSON into Cobweb AND X3DOM, using the same DOM tree (probably not a good idea).
Probably not because X3DOM has quite a few non but almost standard nodes (such as CommonSurfaceShader) which JSON should also support. 
Yes, I am interested in your DOM event which is dispatched when a Scene is fully loaded.  Could you go and check?  Thanks!

Will do.
Sent from Mail for Windows 10
From: Andreas Plesch
Sent: Saturday, May 20, 2017 8:21 PM
To: John Carlson
Cc: holger.seelig at yahoo.de; X3D Graphics public mailing list; x3dom-users at lists.sourceforge.net
Subject: Re: Cobweb_dom...Script Magic? Loading DOM subscenes after parent inX3DOM and Cobweb.
Hi John,
it is difficult for me to see what is not working, in the example. It looks like it is working but only by using callbacks in custom methods and you would rather use Promises in reusable fashion ?
By child DOM scenegraph, do you mean a scene which is added as an Inline to another (parent) scene ? Hm. it looks more like an appended Transform group which would be quite different.
I think for cobweb_dom I added a dom event which is dispatched when an Inline or Scene is fully loaded but I would have to go back and check. Events would be another way to guarantee a sequence of loading.
jquery xhr and regular xhr have mechanisms to allow acting on when a request is fulfilled (which is I think what you are using).
It may be necessary to come up with a minimal, non-working example which shows the issue. Is dealing with expanding prototypes related to sequencing ?
I think you are also trying to show how to load json encoded x3d with x3dom and cobweb ?
Sorry to be of no more constructive help, eg. asking all the returned questions,
On Sat, May 20, 2017 at 5:23 PM, John Carlson <yottzumm at gmail.com> wrote:
Cobweb_dom, X3DOM experts, I need some help adding a child DOM scenegraph with prototypes to a parent DOM scenegraph after the primary scene has been  loaded, and not before. I have an example of loading before the scene is loaded, and in a callback.  If you have an example with Promises instead of callback nesting, that would be more ideal, the second $.getJSON() (child scenegraph) might finish before the first $.getJSON() (parent scenegraph) if I don’t use promises or callback nesting. Also, Promises would allow me to separate the parent loading somewhat from the child loading, and create separate functions.  Also, X3DOM experts can provide an example with Promises as well.  Meanwhile, I will be reading about Promises.
Here is my example so far:

Viewable here:
The white Box is the subscene of the dolphin scene.
The following related code is from https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/loaderJQuery.js
and references code from:
[ actually, I think the last two reference each other – naughty ]
Data is here:
[ child scenegraph ]
[ parent scenegraph ]
Cobweb doesn’t need the prototypeExpander or the flattener (well, it might have with prototypes in cobweb_dom, but I think the last release fixed that…haven’t checked—here is a good test for you!).  This is a dual example, and I haven’t figured out how to conditionally run the prototypeExpander on only X3DOM code.  Please test without the PrototypeExpander.js and Flattener.js included, and remove X3DOM, since it won’t work in that case.  X3DOM folks can include the two JavaScript files which are here:
You may provide your own appendInline (below) which doesn’t call loadSchema.  That may be too complex of a download.  That is, you probably don’t want to do all that JSON schema validation in your example.  Try to keep my code close to what it is otherwise.
And if you start supporting X3D JSON in your viewers, that would be even better!
• Next is passed the element parameter
• */
function appendInline(element, url, next) {
        $.getJSON(url, function(json) {
                if (typeof prototypeExpander === 'function') {
                        json = prototypeExpander(url, json, "");
                } else {
                        console.error("Perhaps you need to include the PrototypeExpander.js?");
                if (typeof flattener === 'function') {
                        json = flattener(json);
                } else {
                        console.error("Perhaps you need to include the Flattener.js?");
                // must validate here because we call an inner method.
                loadSchema(json, url, doValidate, function() {
                        ConvertToX3DOM(json["X3D"]["Scene"], "Scene", element, url);
                }, function(e) {
        }).fail(function(jqXHR, textStatus, errorThrown) { alert('getJSON request failed! ' + textStatus + ' ' + errorThrown); });
• Next is passed the selected element from selector
• Selector is the CSS selector to append inline to.
• */
function loadSubscene(selector, url, next) {
        appendInline(document.querySelector(selector), url, next);

Andreas Plesch
39 Barbara Rd.
Waltham, MA 02453

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170521/4933361a/attachment-0001.html>

More information about the x3d-public mailing list