Difference between revisions of "X3DOM CAD"

From Web3D.org
Jump to: navigation, search
m
 
(19 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
Nearby:  [[X3D CAD]] Working Group
 +
 +
== Overview:  X3DOM and CAD support ==
 
Resources and Issues related to using the CADGeometry component in models incorporated into HTML5 web pages and rendered in a browser pages using X3DOM implemented with Javascript+WebGL or Flash Player
 
Resources and Issues related to using the CADGeometry component in models incorporated into HTML5 web pages and rendered in a browser pages using X3DOM implemented with Javascript+WebGL or Flash Player
  
[http://www.x3dom.org X3DOM] is one way to integrate an X3D model into into an HTML5 web document. ( see [[X3D_and_HTML5]] ). The X3DOM implementation is a library of Javascript classes and functions which, after an HTML5 document is loaded, search the Document Object Model tree of the document for X3D elements and renders the content in an HTML5 canvas element using WebGL calls or Flash Player, on browsers that do not suport WebGL. The Javascript code is open source and available  in a [http://github.com/x3dom/x3dom  Github project]. The Javascript code can also be loaded from a singe minimized script at URL http://www.x3dom.org/x3dom/example/x3dom.js . X3DOM offers a partial but expanding coverage of X3D nodes; the nodes which can be rendered using X3DOM in an HTML5 page is documented in the [http://x3dom.org/x3dom/test/functional/dumpNodeTypeTree.html Node Type Tree]. The X3DOM classes do not implement any of the nodes in the CADGeometry component. (As of version 1.4; March 2013)
+
[http://www.x3dom.org X3DOM] is one way to integrate an X3D model into into an HTML5 web document (see [[X3D_and_HTML5]] ). The X3DOM implementation is a library of Javascript classes and functions which, after an HTML5 document is loaded, search the Document Object Model (DOM) tree of the document for X3D elements and renders the content in an HTML5 canvas element using WebGL calls or else Flash Player, on browsers that do not suport WebGL. The Javascript code is open source and available  in a [http://github.com/x3dom/x3dom  Github project]. The Javascript code can also be loaded from a single minimized script at URL http://www.x3dom.org/x3dom/example/x3dom.js . X3DOM offers a partial but expanding coverage of X3D nodes; the nodes which can be rendered using X3DOM in an HTML5 page is documented in the [http://x3dom.org/x3dom/test/functional/dumpNodeTypeTree.html Node Type Tree]. The X3DOM classes themselves do not implement any of the nodes in the CADGeometry component. (As of version 1.4; March 2013)
 
The coverage of X3D nodes can be extended through additional Javascript code which extends the X3DOM classes (see [http://x3dom.org/docs/dev/components.html X3DOM Components])
 
The coverage of X3D nodes can be extended through additional Javascript code which extends the X3DOM classes (see [http://x3dom.org/docs/dev/components.html X3DOM Components])
  
[http://www.web3d.org/x3d/stylesheets/X3dToX3dom.xslt X3dToX3dom.xslt] is an XSLT 2 stylesheet which will generate an HTML5 document embedding an X3D input model. This stylesheet can be run using a stand-alone XSLT2 engine or from within the [https://savage.nps.edu/X3D-Edit/ X3D-Edit] tool.
+
[http://www.web3d.org/x3d/stylesheets/X3dToX3dom.xslt X3dToX3dom.xslt] is an XSLT 2 stylesheet which will generate an HTML5 document embedding an X3D input model. This stylesheet can be run using a stand-alone XSLT2 engine or from within the [https://savage.nps.eduX3D-Edit/ X3D-Edit] tool.
 
+
  
 
[http://www.kshell.com/pages/x3dom/x3dom_cad/scripts/CADGeometry.js CADGeometry.js] Javascript code implementing the CADLayer, CADAssembly, CADFace, and CADPart nodes of the X3D [http://www.web3d.org/files/specifications/19775-1/V3.2/Part01/components/CADGeometry.html CADGeometry] component. This Javascript should be loaded by a webpage '''''after''''' the core components of the X3DOM Javascript have been loaded. Example:
 
[http://www.kshell.com/pages/x3dom/x3dom_cad/scripts/CADGeometry.js CADGeometry.js] Javascript code implementing the CADLayer, CADAssembly, CADFace, and CADPart nodes of the X3D [http://www.web3d.org/files/specifications/19775-1/V3.2/Part01/components/CADGeometry.html CADGeometry] component. This Javascript should be loaded by a webpage '''''after''''' the core components of the X3DOM Javascript have been loaded. Example:
Line 13: Line 15:
 
</code>
 
</code>
  
===X3D Models===
+
==X3D Models==
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/laser_assembly.x3d laser_assembly] Converted from a [http://gicl.cs.drexel.edu/repository/data/Assemblies/laser__top.stp STEP file] in the [http://www.designrepository.org/ National Design Repository].
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/laser_assembly.x3d laser_assembly] Converted from a [http://gicl.cs.drexel.edu/repository/data/Assemblies/laser__top.stp STEP file] in the [http://www.designrepository.org/ National Design Repository].
 
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/CadTeapot.x3d CadTeapot] Copied from the Web3D Basic Examples [http://www.web3d.org/x3d/content/examples/Basic/CAD/_pages/page08.html CadTeapot] model but modified so that each of the Appearance nodes for the 4 parts of the teapot is independently defined.
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/CadTeapot.x3d CadTeapot] Copied from the Web3D Basic Examples [http://www.web3d.org/x3d/content/examples/Basic/CAD/_pages/page08.html CadTeapot] model but modified so that each of the Appearance nodes for the 4 parts of the teapot is independently defined.
  
===X3DOM Pages===
+
==X3DOM Pages==
 
These pages were generated using a modification of the X3dToX3dom.xslt script (modified XSLT stylesheet [http://www.kshell.com/pages/x3dom/x3dom_cad/X3dToX3dom.xslt here]). These pages load the CADGeometry extension to X3DOM after loading the X3DOM core classes.
 
These pages were generated using a modification of the X3dToX3dom.xslt script (modified XSLT stylesheet [http://www.kshell.com/pages/x3dom/x3dom_cad/X3dToX3dom.xslt here]). These pages load the CADGeometry extension to X3DOM after loading the X3DOM core classes.
 
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/no_cad/laser_assembly.xhtml laser_assembly page] The laser_assembly model embedded in a web page rendered with X3DOM.
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/no_cad/laser_assembly.xhtml laser_assembly page] The laser_assembly model embedded in a web page rendered with X3DOM.
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/no_cad/CadTeapot.xhtml CadTeapot page] The CadTeapot model embedded in a web page rendered with X3DOM.
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/no_cad/CadTeapot.xhtml CadTeapot page] The CadTeapot model embedded in a web page rendered with X3DOM.
  
===X3DOM -- Product structure pages===
+
==X3DOM -- Product structure pages==
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/transparency/laser_assembly.xhtml laser_assembly product structure] The laser_assembly model in a page, with additional linked HTML/Javascript elements to display the assembly tree.
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/transparency/laser_assembly.xhtml laser_assembly product structure] The laser_assembly model in a page, with additional linked HTML/Javascript elements to display the assembly tree.
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/transparency/CadTeapot.xhtml CadTeapot product structure] The laser_assembly model in a page, with additional linked HTML/Javascript elements to display the assembly tree.
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/transparency/CadTeapot.xhtml CadTeapot product structure] The laser_assembly model in a page, with additional linked HTML/Javascript elements to display the assembly tree.
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/transparency/retention_clip.xhtml retention_clip] A product structure containing nested assemblies.
 
* [http://www.kshell.com/pages/x3dom/x3dom_cad/transparency/retention_clip.xhtml retention_clip] A product structure containing nested assemblies.
 +
 +
==DOM/X3DOM -- Javascript programming==
 +
The loaded X3D model is part of the document DOM (Document Object Model) and can be searched and manipulated by Javascript code. To ensure that the X3D model is completely loaded and initialized, the X3DOM framework allows the page script to assign a function to the variable x3dom.runtime.ready. This function will be run after the X3DOM code has resolved all external URL's in the X3D model and the rendering objects have been initialized.
 +
 +
For example, the following javascript defines a function which searches the DOM tree for CADPart nodes and prints the X3D field 'name' to the browser console.
 +
 +
<code language="javascript">
 +
<pre>
 +
<nowiki>
 +
/*
 +
Javascript code to implement manipulating the DOM elements which
 +
are associated with the CADGeometry component implementation of x3dom.
 +
 +
Vincent Marchetti 2012
 +
Licensed in same way as X3DOM release 1.5 : http://x3dom.org
 +
 +
Dual licensed under the MIT and GPL.
 +
http://x3dom.org/download/dev/docs/html/license.html
 +
*/
 +
 +
(function(){
 +
    // save any existing value of the
 +
    // x3dom.runtime.ready, so it can
 +
    // be executed along with our code
 +
    var existing_ready = x3dom.runtime.ready;
 +
   
 +
    function print_part_names(){
 +
        // locate X3D nodes in the DOM tree with standard
 +
        // Javascript DOM API
 +
        var parts=x3dElem.getElementsByTagName("CADPart");
 +
        for (var j=0; j<parts.length; ++j)
 +
            // get the X3D field value from the CADPart
 +
            // node using the .getattribute member function
 +
            console.log( parts[j].getAttribute('name'));
 +
    }
 +
     
 +
    // according to X3DOM documentation, setting or overriding
 +
    // this function is how you perform a desired action just before
 +
    // the X3D scene to to be rendered, so the X3DOM objects have all been
 +
    // constructed
 +
    x3dom.runtime.ready=function(){
 +
        // Be courteous, let any previously existing function
 +
        // go first
 +
        if (existing_ready !== undefined) existing_ready(); 
 +
        // then run our code
 +
        print_part_names();
 +
    }
 +
})();
 +
</nowiki>
 +
</pre>
 +
</code>
 +
 +
This excerpt illustrates the method used to create the HTML part-structure tool in the XHTML examples for product structure that appear above.  Those examples are created when exporting the original X3D model (containing CAD nodes) to the HTML+X3D .xhtml product structure node.
 +
 +
Future work:  the DOM lets you save new attributes without difficult.  Therefore, original values for transparency might be retained in memory while the widget changes other transparency values from 1.0 to 0.2 (or whatever) for visualization, then allows restoration of original values (perhaps by another button or link).
 +
 +
==To Do==
 +
* Incorporate the product structure display (on the HTML page) as an option in the X3dToX3dom stylesheet.
 +
* Setup a SourceForge project for ProductStructure, other scripts useful
 +
* Prepare a x3dom folder with examples and scripts to be included ( with local URL references from .xhtml to .js scripts) to be placed in the http://www.web3d.org/x3d/content/examples/Basic/CAD/x3dom folder
 +
* The product-structure functionality will be integrated into the X3dToX3dom.xslt stylesheet so that the HTML widget can be available for any X3D export.
 +
* Implement the other CAD-related nodes needed for addtion to the [http://x3dom.org/docs/dev/nodes/index.html X3DOM nodes list]:
 +
** QuadSet, IndexedQuadSet, ClipPlane, [http://www.web3d.org/files/specifications/19775-1/V3.3/Part01/components/nurbs.html NURBS Component] nodes

Latest revision as of 03:11, 18 April 2013

Nearby: X3D CAD Working Group

Overview: X3DOM and CAD support

Resources and Issues related to using the CADGeometry component in models incorporated into HTML5 web pages and rendered in a browser pages using X3DOM implemented with Javascript+WebGL or Flash Player

X3DOM is one way to integrate an X3D model into into an HTML5 web document (see X3D_and_HTML5 ). The X3DOM implementation is a library of Javascript classes and functions which, after an HTML5 document is loaded, search the Document Object Model (DOM) tree of the document for X3D elements and renders the content in an HTML5 canvas element using WebGL calls or else Flash Player, on browsers that do not suport WebGL. The Javascript code is open source and available in a Github project. The Javascript code can also be loaded from a single minimized script at URL http://www.x3dom.org/x3dom/example/x3dom.js . X3DOM offers a partial but expanding coverage of X3D nodes; the nodes which can be rendered using X3DOM in an HTML5 page is documented in the Node Type Tree. The X3DOM classes themselves do not implement any of the nodes in the CADGeometry component. (As of version 1.4; March 2013) The coverage of X3D nodes can be extended through additional Javascript code which extends the X3DOM classes (see X3DOM Components)

X3dToX3dom.xslt is an XSLT 2 stylesheet which will generate an HTML5 document embedding an X3D input model. This stylesheet can be run using a stand-alone XSLT2 engine or from within the X3D-Edit tool.

CADGeometry.js Javascript code implementing the CADLayer, CADAssembly, CADFace, and CADPart nodes of the X3D CADGeometry component. This Javascript should be loaded by a webpage after the core components of the X3DOM Javascript have been loaded. Example:

   <script type="text/javascript" src="http://www.x3dom.org/x3dom/example/x3dom.js"/>
   <script type="text/javascript" src="http://www.kshell.com/pages/x3dom/x3dom_cad/scripts/CADGeometry.js"/>

X3D Models

X3DOM Pages

These pages were generated using a modification of the X3dToX3dom.xslt script (modified XSLT stylesheet here). These pages load the CADGeometry extension to X3DOM after loading the X3DOM core classes.

  • laser_assembly page The laser_assembly model embedded in a web page rendered with X3DOM.
  • CadTeapot page The CadTeapot model embedded in a web page rendered with X3DOM.

X3DOM -- Product structure pages

DOM/X3DOM -- Javascript programming

The loaded X3D model is part of the document DOM (Document Object Model) and can be searched and manipulated by Javascript code. To ensure that the X3D model is completely loaded and initialized, the X3DOM framework allows the page script to assign a function to the variable x3dom.runtime.ready. This function will be run after the X3DOM code has resolved all external URL's in the X3D model and the rendering objects have been initialized.

For example, the following javascript defines a function which searches the DOM tree for CADPart nodes and prints the X3D field 'name' to the browser console.


/*
Javascript code to implement manipulating the DOM elements which
are associated with the CADGeometry component implementation of x3dom.

Vincent Marchetti 2012
Licensed in same way as X3DOM release 1.5 : http://x3dom.org

Dual licensed under the MIT and GPL.
http://x3dom.org/download/dev/docs/html/license.html
*/

(function(){
    // save any existing value of the
    // x3dom.runtime.ready, so it can
    // be executed along with our code
    var existing_ready = x3dom.runtime.ready;
    
    function print_part_names(){
        // locate X3D nodes in the DOM tree with standard
        // Javascript DOM API
        var parts=x3dElem.getElementsByTagName("CADPart");
        for (var j=0; j<parts.length; ++j)
            // get the X3D field value from the CADPart
            // node using the .getattribute member function
            console.log( parts[j].getAttribute('name'));
    }
       
    // according to X3DOM documentation, setting or overriding
    // this function is how you perform a desired action just before
    // the X3D scene to to be rendered, so the X3DOM objects have all been 
    // constructed
    x3dom.runtime.ready=function(){
        // Be courteous, let any previously existing function
        // go first
        if (existing_ready !== undefined) existing_ready();   
        // then run our code
        print_part_names();
    }
})();

This excerpt illustrates the method used to create the HTML part-structure tool in the XHTML examples for product structure that appear above. Those examples are created when exporting the original X3D model (containing CAD nodes) to the HTML+X3D .xhtml product structure node.

Future work: the DOM lets you save new attributes without difficult. Therefore, original values for transparency might be retained in memory while the widget changes other transparency values from 1.0 to 0.2 (or whatever) for visualization, then allows restoration of original values (perhaps by another button or link).

To Do

  • Incorporate the product structure display (on the HTML page) as an option in the X3dToX3dom stylesheet.
  • Setup a SourceForge project for ProductStructure, other scripts useful
  • Prepare a x3dom folder with examples and scripts to be included ( with local URL references from .xhtml to .js scripts) to be placed in the http://www.web3d.org/x3d/content/examples/Basic/CAD/x3dom folder
  • The product-structure functionality will be integrated into the X3dToX3dom.xslt stylesheet so that the HTML widget can be available for any X3D export.
  • Implement the other CAD-related nodes needed for addtion to the X3DOM nodes list: