[x3d-public] [x3dom-users] Cobweb_dom...Script Magic? Loading DOM subscenes after parent in X3DOM and Cobweb.

Leonard Daly Leonard.Daly at realism.com
Sat May 20 16:18:01 PDT 2017


John,

> Cobweb_dom, X3DOM experts, I need some help adding a child DOM 
> scenegraph with prototypes to a parent DOM scenegraph after the
>

Not sure how any of this applies to X3DOM as it does not have PROTOs. 
Assuming you mean X3D prototypes via PROTO or EXTERNPROTO. If you mean 
something else, please elaborate.


Leonard Daly



> 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:
>
> https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/html/flipper.html
>
> Viewable here:
>
> https://coderextreme.net/X3DJSONLD/src/main/html/flipper.html
>
> 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:
>
> https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/X3DJSONLD.js
>
> [ actually, I think the last two reference each other – naughty ]
>
> Data is here:
>
> [ child scenegraph ]
>
> https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/data/abox.json
>
> [ parent scenegraph ]
>
> https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/data/flipp.json
>
> 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:
>
> https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/PrototypeExpander.js
>
> https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/Flattener.js
>
> 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!
>
> John
>
> /**
>
>   * 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);
>
>                         next(element);
>
>                 }, function(e) {
>
>                         console.error(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);
>
> }
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>
>
> _______________________________________________
> X3dom-users mailing list
> X3dom-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/x3dom-users


-- 
*Leonard Daly*
3D Systems & Cloud Consultant
LA ACM SIGGRAPH Chair
President, Daly Realism - /Creating the Future/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170520/f5ed1fa4/attachment-0001.html>


More information about the x3d-public mailing list