Search code examples
javascriptxmlxml3d

XML3D API methods and scene hierarchy


I'm using XML3D library to make a simple 3D editor. I wonder if the users of this library are supposed to use its API too or just treat this lib as a tool that renders scene from XML scene definition.

First thing i need would be to create some js scene representation. There is a plenty of tool for XML->JSON conversion but maybe accessing the XML3D internal scene representation would be the better way to handle scene modification.

Could you please give me any advices on scene manipulation with this library?


Solution

  • The idea of XML3D is to use the DOM API to modify the 3D scene representation. Thus, manipulating the scene is as simple as modifying a web page. For instance, if you have a mesh:

    <mesh id="teapot" src="teapot.json"></mesh>
    

    you can add an event listener like this:

    document.querySelector("#teapot").addEventListener("click", function() {
       alert("Hallo");
    });
    

    or with jQuery, removing the mesh from the scene:

    $("#teapot").remove();
    

    Some more examples can also be found in the xml3d.js wiki.