#VRML V2.0 utf8
# X3D-to-VRML-97 XSL translation autogenerated by X3dToVrml97.xslt
# http://www.web3d.org/x3d/content/X3dToVrml97.xslt
# Generated using XSLT processor: SAXON 9.1.0.6 from Saxonica

# [X3D] VRML V3.2 utf8
# PROFILE Immersive
# [X3D] version=3.2
# [X3D] noNamespaceSchemaLocation=http://www.web3d.org/specifications/x3d-3.2.xsd
# [head]

# META "title" "CADGeometryPrototypes.x3d"
# META "description" "X3D Amendment 1 CAD Component node prototypes for backwards compatibility with VRML97 and X3D 2004."
# META "creator" "Travis Rauch, Alan Shaffer, Mounir Sidhom, Patrick Sullivan and Don Brutzman"
# META "created" "28 April 2005"
# META "modified" "28 November 2008"
# META "warning" "need example scene"
# META "warning" "Example scenes using these prototypes do not get support for making embdedded metadata values visible at run time, though metadata can certainly be saved in the scene file OK."
# META "reference" "CADGeometryExternPrototypes.x3d"
# META "reference" "http://www.web3d.org/x3d/specifications/ISO-IEC-FDIS-19775-1.2-X3D-AbstractSpecification/Part01/components/CADGeometry.html"
# META "reference" "http://www.web3d.org/x3d/specifications/ISO-IEC-FDIS-19775-1.2-X3D-AbstractSpecification/Part01/CADInterchange.html"
# META "subject" "CADAssembly CADFace CADLayer CADPart IndexedQuadSet QuadSet"
# META "identifier" "http://www.web3d.org/x3d/content/examples/Basic/CAD/CADGeometryPrototypes.x3d"
# META "generator" "X3D-Edit, https://savage.nps.edu/X3D-Edit"
# META "license" "../license.html"
#    Copyright (c) 1995-2009 held by the author(s). All rights reserved.
# 
#    Redistribution and use in source and binary forms, with or without
#    modification, are permitted provided that the following conditions are
#    met:
#      * Redistributions of source code must retain the above copyright
#        notice, this list of conditions and the following disclaimer.
#      * Redistributions in binary form must reproduce the above copyright
#        notice, this list of conditions and the following disclaimer in the
#        documentation and/or other materials provided with the
#        distribution.
#      * Neither the names of the [1]Naval Postgraduate School (NPS)
#        [2]Modeling Virtual Environments and Simulation (MOVES) Institute
#        nor the names of its contributors may be used to endorse or promote
#        products derived from this software without specific prior written
#        permission.
# 
#    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
#    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
#    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
#    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
#    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
#    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# 
# References
# 
#    1. http://www.nps.edu/
#    2. http://www.MovesInstitute.org/

EXTERNPROTO MetadataString [
  # [appinfo] MetadataString contains a set of strings in the value field.
  exposedField SFString name
  exposedField MFString value
  exposedField SFString reference
  exposedField SFNode metadata # [appinfo] Metadata node only
][
  "MetadataPrototypes.wrl#MetadataString"
  "http://www.web3d.org/x3d/content/examples/Basic/development/MetadataPrototypes.wrl#MetadataString"
  "MetadataPrototypes.x3d#MetadataString"
  "http://www.web3d.org/x3d/content/examples/Basic/development/MetadataPrototypes.x3d#MetadataString"
 ]

    
# [Scene] ========== ========== ==========

NavigationInfo { type [ "EXAMINE" "ANY" ] } ###  Default X3D NavigationInfo

# ===========================================
PROTO IndexedQuadSet [
  # [appinfo] The IndexedQuadSet node represents a 3D shape composed of a collection of individual quadrilaterals (quads). IndexedQuadSet uses the indices in its index field to specify the vertices of each quad from the coord field. Each quad is formed from a set of four vertices of the Coordinate node identified by four consecutive indices from the index field If the index field does not contain a multiple of four coordinate values the remaining vertices shall be ignored.


 # documentation: http://www.web3d.org/x3d/specifications/ISO-IEC-19775-Amendment1-PDAM-X3DAbstractSpecification/Part01/components/CADGeometry.html#IndexedQuadSet

  eventIn      MFInt32	set_index    # [appinfo] range [0..∞) or -1

    # No specific initialization value

  exposedField MFNode	attrib [ ]    # [appinfo] [X3DVertexAttributeNode]

    # Specification initialization: NULL node

  exposedField SFNode      color NULL    # [appinfo] [X3DColorNode]

    # Specification initialization: NULL node

  exposedField SFNode      coord NULL    # [appinfo] [X3DCoordinateNode]

    # Specification initialization: NULL node

  exposedField SFNode      fogCoord NULL    # [appinfo] [FogCoordinate]

    # Specification initialization: NULL node

  exposedField SFNode      normal NULL    # [appinfo] [X3DNormalNode]

    # Specification initialization: NULL node

  exposedField SFNode      texCoord NULL    # [appinfo] [X3DTextureCoordinateNode]

    # Specification initialization: NULL node

  field        SFBool	ccw TRUE
  field        SFBool	colorPerVertex TRUE    # [appinfo] colorPerVertex ignored in IndexedQuadSet. and always treated as true

  field        SFBool	normalPerVertex TRUE
  field        SFBool	solid TRUE
  field        MFInt32	index [ ]    # [appinfo] range [0..∞) or -1

    # No specific initialization value

  exposedField SFNode      metadata NULL    # [appinfo] [X3DMetadataObject]

    # Specification initialization: NULL node

] {
 ### Warning:  <ProtoDeclare name='IndexedQuadSet'/> ProtoBody child following first child will not be rendered, since the first child determines node type. (Authors can silence this warning by placing a comment as second child.)
  DEF RenderedIQS IndexedFaceSet {
          attrib IS attrib
      color IS color
      colorPerVertex IS colorPerVertex
      coord IS coord
      fogCoord IS fogCoord
      normal IS normal
      texCoord IS texCoord
      ccw IS ccw
      normalPerVertex IS normalPerVertex
      solid IS solid
  }
  DEF UnrenderedIQS Group {
    children [
        DEF IndexedQuadSetToIndexedFaceSet Script {
          field        MFInt32	index IS index
          eventIn      MFInt32	set_index IS set_index
          field        SFNode      renderedIQS             USE RenderedIQS
          field        SFBool	localTraceEnabled TRUE
          field        MFInt32	coordIndexNew [ ]
            # constructed during initialization

          directOutput TRUE
                                  
	url [ "javascript:
// ### X3D Browser.print() not supported by all VRML97 viewers, instead simply use print()


function initialize()
{
	//colorPerVertex ignored in IndexedQuadSet, and always treated as "true"
	RenderedIQS.colorPerVertex = true;

	// index is an array of quad indices. The ordering of
	// the vertices is ccw (counter-clockwise).

	// ensure legal index values
	for (ii=0; ii <= index.length-1; ii++)
	{
	  if (index[ii] < -1)
	  {
		forcePrint ('error, index[' + ii + ']=' + index[ii] + ' is illegal value');
		return;
	  }
	}
	tracePrint ('index.length=' + index.length);
	tracePrint ('index=' + index);

	if (index.length < 4)
	{
		forcePrint ('warning, index.length=' + index.length + ' insufficient to construct a quad, IQS ignored');
		return;
	}

	coordIndexNew = new MFInt32 ();

	// ii walks through index array,
	// goal is to initialize coordIndexNew list to match quads
	for (ii=0; ii <= index.length-1; ii+=4)
	{
		if ((index[ii]   == index[ii+1]) || (index[ii]   == index[ii+2]) || (index[ii] == index[ii+3]) ||
		    (index[ii+1] == index[ii+2]) || (index[ii+1] == index[ii+3]) ||
		    (index[ii+2] == index[ii+3]))
		{
			forcePrint ('index=' + index);
			forcePrint ('error, pair of equal indices in quad');
			return;
		}

		if (index[ii] >= 0)
		{
			// add another quad from latest 4 points of fan set to IQS
			// order is ccw, i.e. in correct halfplane direction
			// note: there is an implicit "malloc" here for the'length' element of the array
			coordIndexNew [coordIndexNew.length] = index[ii];
			coordIndexNew [coordIndexNew.length] = index[ii+1];
			coordIndexNew [coordIndexNew.length] = index[ii+2];
			coordIndexNew [coordIndexNew.length] = index[ii+3];
			coordIndexNew [coordIndexNew.length] = -1;
		}

		if (index.length % 4 != 0) {
			forcePrint ('error, index field does not contain a multiple of four coordinate values.');
			forcePrint ('The remaining vertices shall be ignored');
			return;
		}

	  // incremental trace of array being built
	  tracePrint ('coordIndexNew=' + coordIndexNew);
	}
	renderedIQS.set_coordIndex = coordIndexNew;
	tracePrint ('renderedIQS.coordIndex=' + renderedIQS.coordIndex);
	// match colorIndex if any Color node exists
//	if (nodesHolder.color)
//	{
//	  if (nodesHolder.color.color.length > 0)
//	  {
		//  Could implement color count check here
//	  }
//	}

	// no need to set colorIndex since indexedFaceSet semantics handles this
}
function set_index (value, timestamp)
{
	index = value;
	initialize ();
}
function tracePrint(outputString)
{
    if (localTraceEnabled)
	  print ('[IndexedQuadSet]' + outputString);
}
function forcePrint(outputString)
{
	print ('[IndexedQuadSet]' + outputString);
}

          
" ]
        }
        Group {
          children [
              # metadata holder
              # metadata
              MetadataString {
                                  metadata IS metadata
              }
          ]
        }
    ]
  }
}
# ===========================================
PROTO QuadSet [
  # [appinfo] The QuadSet node represents a 3D shape that represents a collection of individual planar quadrilaterals. The coord field contains a Coordinate node that defines the 3D vertices that define the quad. Each quad is formed from a consecutive set of four vertices of the coordinate node. If the coordinate node does not contain a multiple of four coordinate values the remaining vertices shall be ignored.


 # documentation: http://www.web3d.org/x3d/specifications/ISO-IEC-19775-Amendment1-PDAM-X3DAbstractSpecification/Part01/components/CADGeometry.html#QuadSet

  exposedField MFNode	attrib [ ]    # [appinfo] [X3DVertexAttributeNode]

    # Specification initialization: NULL node

  exposedField SFNode      color NULL    # [appinfo] [X3DColorNode]

    # Specification initialization: NULL node

  exposedField SFNode      coord NULL    # [appinfo] [X3DCoordinateNode]

    # Specification initialization: NULL node

  exposedField SFNode      fogCoord NULL    # [appinfo] [FogCoordinate]

    # Specification initialization: NULL node

  exposedField SFNode      normal NULL    # [appinfo] [X3DNormalNode]

    # Specification initialization: NULL node

  exposedField SFNode      texCoord NULL    # [appinfo] [X3DTextureCoordinateNode]

    # Specification initialization: NULL node

  field        SFBool	ccw TRUE
  field        SFBool	colorPerVertex TRUE    # [appinfo] colorPerVertex ignored in QuadSet and always treated as true

  field        SFBool	normalPerVertex TRUE
  field        SFBool	solid TRUE
  exposedField SFNode      metadata NULL    # [appinfo] [X3DMetadataObject]

    # Specification initialization: NULL node

] {
 ### Warning:  <ProtoDeclare name='QuadSet'/> ProtoBody child following first child will not be rendered, since the first child determines node type. (Authors can silence this warning by placing a comment as second child.)
  DEF RenderedQS IndexedFaceSet {
          attrib IS attrib
      color IS color
      colorPerVertex IS colorPerVertex
      coord IS coord
      fogCoord IS fogCoord
      normal IS normal
      texCoord IS texCoord
      ccw IS ccw
      normalPerVertex IS normalPerVertex
      solid IS solid
  }
  DEF UnrenderedQS Group {
    children [
        DEF QuadSetToIndexedFaceSet Script {
          field        MFInt32	index [ ]
            # initialized in ecmascript

          eventIn      MFInt32	set_index
          field        SFNode      renderedQS             USE RenderedQS
          field        SFBool	localTraceEnabled TRUE
          field        MFInt32	coordIndexNew [ ]
            # constructed during initialization

          directOutput TRUE

	url [ "javascript:
// ### X3D Browser.print() not supported by all VRML97 viewers, instead simply use print()


function initialize()
{
	//colorPerVertex ignored in QuadSet, and always treated as "true"
	RenderedQS.colorPerVertex = true;

	// calculate index value from QuadSet coord values
	if (renderedQS.coord)
	{
		numberOfCoordinatePoints = renderedQS.coord.point.length;
	}
	else
	{
		tracePrint ('no Coordinate node found');
		return;
	}
	if (numberOfCoordinatePoints < 4)
	{
		forcePrint ('warning, numberOfCoordinatePoints=' + numberOfCoordinatePoints + ' insufficient to construct a quad, QuadSet ignored');
		return;
	}

	coordIndexNew = new MFInt32 ();

	// ii walks through index array,
	// goal is to initialize coordIndexNew list to match quads
	for (ii=0; ii <= numberOfCoordinatePoints-1; ii+=4)
	{
		// check if at least 4 vertices remaining to build a quad
		if ((numberOfCoordinatePoints - ii) < 4)
		{
			forcePrint ('error, index field does not contain a multiple' +
' of four coordinate values.');
			forcePrint ('The remaining vertices shall be ignored');
			return;
		}

		if ((index[ii]   == index[ii+1]) || (index[ii]   == index[ii+2]) || (index[ii] == index[ii+3]) ||
		    (index[ii+1] == index[ii+2]) || (index[ii+1] == index[ii+3]) ||
		    (index[ii+2] == index[ii+3]))
		{
			forcePrint ('index=' + index);
			forcePrint ('error, pair of equal indices in quad');
			return;
		}

		if (index[ii] >= 0)
		{
			// add another quad from latest 4 points of fan set to QS
			// order is ccw, i.e. in correct halfplane direction
			// note: there is an implicit "malloc" here for the'length' element of the array
			coordIndexNew [coordIndexNew.length] = index[ii];
			coordIndexNew [coordIndexNew.length] = index[ii+1];
			coordIndexNew [coordIndexNew.length] = index[ii+2];
			coordIndexNew [coordIndexNew.length] = index[ii+3];
			coordIndexNew [coordIndexNew.length] = -1;
		}

	  // incremental trace of array being built
	  tracePrint ('coordIndexNew=' + coordIndexNew);
	}
	renderedQS.set_coordIndex = coordIndexNew;
	tracePrint ('renderedQS.coordIndex=' + renderedQS.coordIndex);
	// match colorIndex if any Color node exists
//	if (nodesHolder.color)
//	{
//	  if (nodesHolder.color.color.length > 0)
//	  {
		//  Could implement color count check here
//	  }
//	}

	// no need to set colorIndex since indexedFaceSet semantics handles this
}
function set_index (value, timestamp)
{
	index = value;
	initialize ();
}
function tracePrint(outputString)
{
    if (localTraceEnabled)
	  print ('[IndexedQuadSet]' + outputString);
}
function forcePrint(outputString)
{
	print ('[IndexedQuadSet]' + outputString);
}
          
          
" ]
        }
        Group {
          children [
              # metadata holder
              # metadata
              MetadataString {
                                  metadata IS metadata
              }
          ]
        }
    ]
  }
}
# ========================================
PROTO CADAssembly [
  # [appinfo] The CADAssembly node holds a set of assemblies or parts grouped together.

  eventIn      MFNode	addChildren
  eventIn      MFNode	removeChildren
  exposedField MFNode	children [ ]    # [appinfo] The children field can contain X3DProductStructureChildNode types. Each child will be either a sub-assembly or a part.

    # Specification initialization: NULL node

  exposedField SFString	name ""    # [appinfo] The name field documents the name of this CADAssembly.

  field        SFVec3f	bboxCenter 0 0 0    # [appinfo] Bounding box center: position offset from origin of local coordinate system.

  field        SFVec3f	bboxSize -1 -1 -1    # [appinfo] Bounding box size: automatically calculated can be specified as an optimization or constraint.

  exposedField SFNode      metadata NULL    # [appinfo] [X3DMetadataObject]

    # Specification initialization: NULL node

] {
  Group {
          addChildren IS addChildren
      removeChildren IS removeChildren
      children IS children
      bboxCenter IS bboxCenter
      bboxSize IS bboxSize
  }
  Group {
    children [
        # metadata holder
        # metadata
        MetadataString {
                      metadata IS metadata
        }
        # name holder
        Anchor {
          url [ "#hideWarning1" ]
                      description IS name
        }
    ]
  }
}
# ========================================
PROTO ShapeHolder [
  # [appinfo] local dummy node to hold value for CADFace

   ### Info:  SFNode not provided for field 'shape' with @accessType='inputOutput'. (Authors can silence this warning by inserting a comment.)
exposedField SFNode      shape NULL
] {
  Script {
     ### Warning:  field 'shape' has accessType 'inputOutput' (exposedField), which is only allowed in X3D Script node, not VRML97 Script node. Using exposedField anyway, may cause errors.
exposedField  SFNode      shape IS shape      # [appinfo] holder for IS field

      # no initialization node

    directOutput TRUE
          
	url [ "javascript:
// no script code, this node is simply a container

        
" ]
  }
}
# = = = = =
PROTO CADFace [
  # [appinfo] The CADFace node holds the geometry representing a face of a part.


 # documentation: http://www.web3d.org/x3d/specifications/ISO-IEC-19775-Amendment1-PDAM-X3DAbstractSpecification/Part01/components/CADGeometry.html#CADPart

  exposedField SFString	name ""    # [appinfo] The name field documents the name of this CADFace.

  exposedField SFNode      shape NULL    # [appinfo] [X3DShapeNode | LOD]

    # Specification initialization: NULL node

  field        SFVec3f	bboxCenter 0 0 0    # [appinfo] Bounding box center: position offset from origin of local coordinate system.

  field        SFVec3f	bboxSize -1 -1 -1    # [appinfo] Bounding box size: automatically calculated can be specified as an optimization or constraint.

  exposedField SFNode      metadata NULL    # [appinfo] [X3DMetadataObject]

    # Specification initialization: NULL node

] {
   ShapeHolder {
          shape IS shape
  }
  Group {
          bboxCenter IS bboxCenter
      bboxSize IS bboxSize
    # metadata holder
    # name holder
    children [
        # metadata holder
        # metadata
        MetadataString {
                      metadata IS metadata
        }
        # name holder
        Anchor {
          url [ "#hideWarning2" ]
                      description IS name
        }
    ]
  }
}
# ========================================
PROTO CADLayer [
  # [appinfo] The CADLayer node defines a hierarchy of nodes used for showing layer structure.


 # documentation: http://www.web3d.org/x3d/specifications/ISO-IEC-19775-Amendment1-PDAM-X3DAbstractSpecification/Part01/components/CADGeometry.html#CADPart

  eventIn      MFNode	addChildren
  eventIn      MFNode	removeChildren
  exposedField MFNode	children [ ]    # [appinfo] The children field can contain X3DChildNode types.

    # Specification initialization: NULL node

  exposedField SFString	name ""    # [appinfo] The name field documents the name of this CADLayer.

  exposedField SFString	visible "" # type MFBool     # [appinfo] specifies whether a particular child and its subchildren are visible. If the number of values is less than the number of children the remaining children shall be visible.

  field        SFVec3f	bboxCenter 0 0 0    # [appinfo] Bounding box center: position offset from origin of local coordinate system.

  field        SFVec3f	bboxSize -1 -1 -1    # [appinfo] Bounding box size: automatically calculated can be specified as an optimization or constraint.

  exposedField SFNode      metadata NULL    # [appinfo] [X3DMetadataObject]

    # Specification initialization: NULL node

] {
  Group {
          addChildren IS addChildren
      removeChildren IS removeChildren
      children IS children
      bboxCenter IS bboxCenter
      bboxSize IS bboxSize
  }
  Group {
    children [
        # metadata holder
        # metadata
        MetadataString {
                      metadata IS metadata
        }
        # name holder
        Anchor {
          url [ "#hideWarning3" ]
                      description IS name
        }
    ]
  }
  Script {
     ### Warning:  field 'visible' has accessType 'inputOutput' (exposedField), which is only allowed in X3D Script node, not VRML97 Script node. Using exposedField anyway, may cause errors.
exposedField  SFString	visible IS visible # type MFBool 
      # no initialization node

              # no script code, this node is simpply a container
 ### Error:  Script node has neither url nor contained code in CDATA section

	url [  ]
  }
}
# ========================================
PROTO CADPart [
  # [appinfo] Representing the location and faces that constitute apart


 # documentation: http://www.web3d.org/x3d/specifications/ISO-IEC-19775-Amendment1-PDAM-X3DAbstractSpecification/Part01/components/CADGeometry.html#CADPart

  eventIn      MFNode	addChildren
  eventIn      MFNode	removeChildren
  exposedField MFNode	children [ ]    # [appinfo] The children field can only contain CADFace nodes.

    # Specification initialization: NULL node

  exposedField SFString	name ""
  exposedField SFVec3f	translation 0 0 0
  exposedField SFRotation	rotation 0 0 1 0
  exposedField SFVec3f	center 0 0 0
  exposedField SFVec3f	scale 1 1 1
  exposedField SFRotation	scaleOrientation 0 0 1 0
  field        SFVec3f	bboxCenter 0 0 0
  field        SFVec3f	bboxSize -1 -1 -1
  exposedField SFNode      metadata NULL    # [appinfo] [X3DMetadataObject]

    # Specification initialization: NULL node

] {
  Transform {
          children IS children
      addChildren IS addChildren
      removeChildren IS removeChildren
      translation IS translation
      rotation IS rotation
      center IS center
      scale IS scale
      scaleOrientation IS scaleOrientation
      bboxCenter IS bboxCenter
      bboxSize IS bboxSize
  }
  Group {
    children [
        # metadata holder
        # metadata
        MetadataString {
                      metadata IS metadata
        }
        # name holder
        Anchor {
          url [ "#hideWarning4" ]
                      description IS name
        }
    ]
  }
}
# ========================================
Anchor {
  description "CADExamples"
  parameter [ "target=_blank" ]
  url [ "CADExamples.wrl" "http://www.web3d.org/x3d/content/examples/Basic/development/CADExamples.wrl" "CADExamples.x3d" "http://www.web3d.org/x3d/content/examples/Basic/development/CADExamples.x3d" ]
  children [
      Shape {
        geometry Text {
          string [ "CADPrototype" "defines prototypes" "" "Click text to see" "CADExamples" ]
          fontStyle FontStyle {
            justify [ "MIDDLE" "MIDDLE"  ] 
            size 0.9
          }
        }
        appearance Appearance {
          material Material {
            diffuseColor 1 1 0.2
          }
        }
      }
  ]
}
