Closed andreasplesch closed 7 years ago
https://andreasplesch.github.io/cobweb_dom/tests/importDoc.xhtml
uses a workaround. It parses the dom into a new scene and then replaces the world with the new scene.
A shorter workaround also works: first save the scene after importDocument(), and then replaceWorld(savedScene) to effectively reload. Replacing the world with itself is strange but triggers the correct binding of bindable nodes.
updated the importDocument examples to 2.0
Browser .importDocument should work as expected. It parses the XML fragment into the current scene. If a X3DBindableNode should be bound, then an set_bind TRUE event must be send to this nodes. If this does not work let me know.
The question is does a set_bind TRUE work if not I must do a traverse (CAMERA). Please let me know.
The following code should now work just fine.
var numRootNodes = Browser .currentScene .rootNodes .length;
Browser .importDocument ($.parseXML ("<Viewpoint position='1 0 10'/>"));
Browser .currentScene .rootNodes [numRootNodes + 1] .set_bind = true;
Thanks for looking into this. I will test when latest/cobweb.js is updated.
I believe the spec. has the browser importDocument service defined in a slightly different way:
http://www.web3d.org/documents/specifications/19775-2/V3.3/Part02/servRef.html#importDocument
According to it, it should be possible to do this:
newScene = Browser .importDocument(dom);
Browser.replaceWorld(newScene);
import in importDocument refers to the browser, not the current scene in this definition.
The code does work now:
var newScene = Browser .importDocument (dom);
Browser .replaceWorld (newScene);
Sorry for the inconvenience.
Not an inconvenience at all. To confirm let me ask on x3d-public if this is the correct or accepted interpretation of the importDocument browser service.
I updated the tests/importDocument example to use the latest cobweb.uncompressed.js and replaceWorld(). It works fine.
https://andreasplesch.github.io/cobweb_dom/tests/importDocument.xhtml
uses the importDocument(dom) SAI function to parse a Scene DOM fragment into an empty initial scene.
It works fine for most nodes but bindable nodes such as Background or Viewpoint do not get bound after they are added to the scene.
I think it may have somehow to do how Layers are handled, since the active Layer does have a bound Background node which is black and probably the default if no other backgrounds are available.
It is possible to use the set_bind field to bind the new bindable nodes. But is there a way to 'finish' the importDocument() to bind all new bindable nodes ? I tried scene.setup() and world.setup() and a few other things but could not find a correct way to do this.
[As an aside, the spec. says that browser.importDocument() should not modify the current scene and just return a new scene which then can be used in replaceWorld(newscene): http://www.web3d.org/documents/specifications/19775-2/V3.3/Part02/servRef.html#importDocument]