Difference between revisions of "STEP-NC WebGL Demo"

From Web3D.org
Jump to: navigation, search
Line 6: Line 6:
 
*[https://s3.amazonaws.com/kshell/stepnc_x3d/webgl_demo_checkout/shell55130_tri_nonormal.x3d shell55130_tri_nonormal.x3d] Workpiece rendered through IndexedTriangleSet node, without per-triangle normals included.
 
*[https://s3.amazonaws.com/kshell/stepnc_x3d/webgl_demo_checkout/shell55130_tri_nonormal.x3d shell55130_tri_nonormal.x3d] Workpiece rendered through IndexedTriangleSet node, without per-triangle normals included.
 
*[https://s3.amazonaws.com/kshell/stepnc_x3d/webgl_demo_checkout/shell55130_nurbs_transpose.x3d shell55130_nurbs_transpose.x3d] Workpiece rendered through NurbsTrimmedSurface, with parameters transposed for rendering on InstantReality X3d browser.
 
*[https://s3.amazonaws.com/kshell/stepnc_x3d/webgl_demo_checkout/shell55130_nurbs_transpose.x3d shell55130_nurbs_transpose.x3d] Workpiece rendered through NurbsTrimmedSurface, with parameters transposed for rendering on InstantReality X3d browser.
 +
 +
<pre>
 +
<?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
 +
shell : 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
 +
-->
 +
 +
<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() &lt; 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() &lt; last()">
 +
                <xsl:text>, </xsl:text>
 +
            </xsl:if>
 +
        </xsl:for-each>
 +
        </xsl:attribute>
 +
        </Normal>
 +
    </xsl:if>
 +
   
 +
</IndexedTriangleSet>
 +
</xsl:template>
 +
 +
</xsl:stylesheet>
 +
 +
</pre>

Revision as of 16:15, 14 February 2012

<?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
shell : 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
-->

<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>