Difference between revisions of "STEP-NC WebGL Demo"

From Web3D.org
Jump to: navigation, search
Line 6: Line 6:
 
*[http://www.steptools.com/demos/boxy.xml boxy.xml] '''Warning''' 39 MB XML file.
 
*[http://www.steptools.com/demos/boxy.xml boxy.xml] '''Warning''' 39 MB XML file.
  
[[Image:STEPNC webgl screenshot.jpg|600px]]
+
[[Image:STEPNC webgl screenshot.jpg|800px]]
  
 
This is a screenshot of the WebGL demonstration (running on Safari v5.1.2); the red highlight box shows the 'selected' workingstep. The geometry for the workpiece at this stage of machining was identified as being in XML node id="id55130" of the boxy.xml file. The triangle data in the boxy.xml was reformatted into a X3D format file by an XSLT script (see below).
 
This is a screenshot of the WebGL demonstration (running on Safari v5.1.2); the red highlight box shows the 'selected' workingstep. The geometry for the workpiece at this stage of machining was identified as being in XML node id="id55130" of the boxy.xml file. The triangle data in the boxy.xml was reformatted into a X3D format file by an XSLT script (see below).

Revision as of 13:16, 15 February 2012

STEPTools Inc (Troy, NY) has developed a WebGL demonstration of standards-based display of CAD/CAM content over the web. The starting point is a STEP-NC file, conforming to Application Protocol 238 of the STEP standard for manufacturing data. A STEP-NC file contains information for computer aided manufacturing and may contain geometry for the workpiece at stages of the manufacture as well as geometry of the cutting tools, toolpaths, fixtures and machine centers, as well as process data.

The files on this wiki page are taken or derived from the boxy demonstation.

The geometry displayed in the webgl demo is delivered in an XML file -- it is not a standard schema but is a readily understood encoded collection of triangles. This file is downloaded and interpreted by Javascript functions embedded or included in the underlying HTML 5 source. The single boxy.xml file is large and contains all the geometry for the workpieces, cutting tools and fixtures, as well as toolpaths for animated movements of the cutting tools.

Error creating thumbnail: File missing

This is a screenshot of the WebGL demonstration (running on Safari v5.1.2); the red highlight box shows the 'selected' workingstep. The geometry for the workpiece at this stage of machining was identified as being in XML node id="id55130" of the boxy.xml file. The triangle data in the boxy.xml was reformatted into a X3D format file by an XSLT script (see below).

  • shell55130_tri.x3d Workpiece rendered through IndexedTriangleSet node , with per-triangle normals provided
  • shell55130_tri_nonormal.x3d Workpiece rendered through IndexedTriangleSet node, without per-triangle normals included.

The geometry in the boxy.xml file includes specification of the normal vectors; however it appears that the normals do not consistently point "out" of the solid body of the workpiece, which causes unsatisfactory rendering on some X3D browsers. For this reason, the conversion to X3D can be done optionally without including the "normal" geometry data.


  • STEP-NC file This is a Zip archive of a STEP Part 28 (XML encoding) file.
  • shell55130_nurbs_transpose.x3d Workpiece rendered through NurbsTrimmedSurface, with parameters transposed for rendering on InstantReality X3d browser.

Webgl Information flow.001.png

An XSLT script can generate an X3D file from the triangle data in WebGL data. The script used takes two parameters. Using the xsltproc XSLT command line tool, the invocation looks like:

xsltproc  -param "shape" "//shell[@id='id55130']" -param "include-normal" "false()"   convert_to_x3d.xsl boxy.xml > boxy_shell.x3d

XSLT script: convert_to_x3d.xsl

<?xml version="1.0" encoding="utf-8"?>


<!-- 
XSL transformation to generate an X3D file from the xml data used for 
the STEPTools WebGL demo (http://www.steptools.com/demos)

This transformation takes two parameters
shape : an XPath expression identifying the nodes in the source XML file which contains
geometry to be converted to X3D

include-normal : enter as true() or false()  whether normal geometry data taken from
source file should be included in X3D geometry

Copyright 2012 Vincent Marchetti

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


-->



 
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:str="http://exslt.org/strings"
                extension-element-prefixes="str">

<xsl:output method="xml" encoding="utf-8"/>


<xsl:param name="shape"/>
<xsl:param name="include-normal" select="0"/>

<xsl:template match="/">
<X3D xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" 
    xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.2.xsd" 
    version="3.2" 
    profile="Interchange">
  <head/>
  <Scene>
    <Background skyColor="0.2 0.5 0.2"/>
    <Shape>
    <xsl:apply-templates select="$shape"/>
    <Appearance>
        <Material containerField="material" diffuseColor="1.000000 1.000000 1.000000"/>
    </Appearance>
    </Shape>
</Scene>
</X3D>
</xsl:template>

<xsl:template match="shell">
<IndexedTriangleSet containerField="geometry" solid="FALSE">
    <xsl:attribute name="index">
    <xsl:for-each select="facets/f/@v">
        <xsl:for-each select="str:split(normalize-space(.))">
            <xsl:value-of select="number(./text())+0"/><xsl:text> </xsl:text>
        </xsl:for-each>
    </xsl:for-each>
    </xsl:attribute>
    <Coordinate containerField="coord">
    <xsl:attribute name="point">
    <xsl:for-each select="./verts/v/@p">
        <xsl:for-each select="str:split(normalize-space(.))">
            <xsl:value-of select="format-number(number(./text()),'###.####')"/><xsl:text> </xsl:text>
        </xsl:for-each>

        <xsl:if test="position() < last()">
            <xsl:text>, </xsl:text>
        </xsl:if>
    </xsl:for-each>
    </xsl:attribute>
    </Coordinate>
    
    <xsl:if test="$include-normal"> 
        <Normal containerField="normal">
        <xsl:attribute name="vector">
        <xsl:for-each select="facets/f/@fn">
            <xsl:for-each select="str:split(normalize-space(.))">
                <xsl:value-of select="format-number(number(./text()),'###.####')"/><xsl:text> </xsl:text>
            </xsl:for-each>
    
            <xsl:if test="position() < last()">
                <xsl:text>, </xsl:text>
            </xsl:if>
        </xsl:for-each>
        </xsl:attribute>
        </Normal>
    </xsl:if>
    
</IndexedTriangleSet>
</xsl:template>

</xsl:stylesheet>