<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "https://www.web3d.org/specifications/x3d-3.3.dtd">
<X3D profile='Immersive' version='3.3 xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation =' https://www.web3d.org/specifications/x3d-3.3.xsd '>
<head>
<meta name='titlecontent='ParallelepipedPrototype.x3d'/>
<meta name='descriptioncontent='Reusable prototype for creating a Parallelepiped, which is a 3D figure formed by six parallelograms; also sometimes referred to as a rhomboid.'/>
<meta name='creatorcontent='Don Brutzman'/>
<meta name='createdcontent='25 November 2011'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='referencecontent='ParallelepipedExamples.x3d'/>
<meta name='Imagecontent='ParallelepipedVertexIndices.png'/>
<meta name='drawingcontent='GeometricShapes.vsd'/>
<meta name='referencecontent=' https://en.wikipedia.org/wiki/Parallelepiped '/>
<meta name='referencecontent=' http://upload.wikimedia.org/wikipedia/commons/f/f6/Parallelepiped.svg '/>
<meta name='referencecontent=' http://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Parallelepiped.svg/500px-Parallelepiped.svg.png '/>
<meta name='subjectcontent='parallelopiped rhomboid geometry polyhedron'/>
<meta name='identifiercontent=' https://x3dgraphics.com/examples/X3dForAdvancedModeling/GeometricShapes/ParallelepipedPrototype.x3d '/>
<meta name='referencecontent=' https://www.web3d.org/x3d/content/examples/X3dResources.html '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../license.html'/>
</head>
<!--

Index for ProtoDeclare definition : Parallelepiped

Index for DEF nodes : BlueAppearance, IFS, ParallelepipedScript, TransparentBox
-->
<Scene>
<WorldInfo title='ParallelepipedPrototype.x3d'/>
<ProtoDeclare name='Parallelepipedappinfo='Parallelepiped is a 3D figure formed by six parallelograms; also sometimes referred to as a rhomboid'>
<ProtoInterface>
<field name='pointtype='MFVec3fvalue='0 1 0 1 1 0 1 1 1 0 1 1 0 0 0 1 0 0 1 0 1 0 0 1accessType='inputOutput'/>
<field name='colorPerVertextype='SFBoolvalue='trueaccessType='initializeOnly'/>
<field name='normalPerVertextype='SFBoolvalue='trueaccessType='initializeOnly'/>
<field name='colorIndextype='MFInt32accessType='initializeOnly'/>
<field name='normalIndextype='MFInt32accessType='initializeOnly'/>
<field name='texCoordIndextype='MFInt32accessType='initializeOnly'/>
<field name='colortype='SFNodeaccessType='inputOutput'>
<!-- initialization node (if any) goes here -->
</field>
<field name='normaltype='SFNodeaccessType='inputOutput'>
<!-- initialization node (if any) goes here -->
</field>
<field name='texCoordtype='SFNodeaccessType='inputOutput'>
<!-- initialization node (if any) goes here -->
</field>
</ProtoInterface>
<ProtoBody>
<!-- First node determines node type of this prototype -->
<IndexedFaceSet DEF='IFSconvex='falsesolid='falsecoordIndex='0 3 2 1 -1 4 5 6 7 -1 0 1 5 4 -1 1 2 6 5 -1 2 3 7 6 -1 3 0 4 7 -1'>
<IS>
<connect nodeField='colorPerVertexprotoField='colorPerVertex'/>
<connect nodeField='normalPerVertexprotoField='normalPerVertex'/>
<connect nodeField='colorIndexprotoField='colorIndex'/>
<connect nodeField='normalIndexprotoField='normalIndex'/>
<connect nodeField='texCoordIndexprotoField='texCoordIndex'/>
<connect nodeField='colorprotoField='color'/>
<connect nodeField='normalprotoField='normal'/>
<connect nodeField='texCoordprotoField='texCoord'/>
</IS>
<Coordinate>
<IS>
<connect nodeField='pointprotoField='point'/>
</IS>
</Coordinate>
</IndexedFaceSet>
<!-- This embedded Script provides the X3D author with additional visibility and control over prototype inputs and outputs -->
<Script DEF='ParallelepipedScript'>
<field name='pointtype='MFVec3faccessType='inputOutput'/>
<IS>
<connect nodeField='pointprotoField='point'/>
</IS>
<![CDATA[
          
ecmascript:
function initialize ()
{
    checkCoordinatePoints ();
}
function checkCoordinatePoints ()
{
    // A parallelepiped has three sets of four parallel edges; the edges within each set are of equal length.
    // Quality assurance: check that lengths of corresponding sides match.
    
    edge01 = length2(point[0], point[1]); // top
    edge12 = length2(point[1], point[2]);
    edge23 = length2(point[2], point[3]);
    edge30 = length2(point[3], point[0]);
    edge45 = length2(point[4], point[5]); // bottom
    edge56 = length2(point[5], point[6]);
    edge67 = length2(point[6], point[7]);
    edge74 = length2(point[7], point[4]);
    edge04 = length2(point[0], point[4]); // sides
    edge15 = length2(point[1], point[5]);
    edge26 = length2(point[2], point[6]);
    edge37 = length2(point[3], point[7]);
    
    epsilon = edge01 * 0.001;
    
    if      ((Math.abs(edge01 - edge23) > epsilon) ||
             (Math.abs(edge23 - edge67) > epsilon) ||
             (Math.abs(edge67 - edge45) > epsilon) ||
             (Math.abs(edge45 - edge01) > epsilon))
         Browser.println ('Warning, mismatched parallelopiped sides 02/33/45/67');
    else if ((Math.abs(edge30 - edge12) > epsilon) ||
             (Math.abs(edge12 - edge56) > epsilon) ||
             (Math.abs(edge56 - edge74) > epsilon) ||
             (Math.abs(edge74 - edge30) > epsilon))
         Browser.println ('Warning, mismatched parallelopiped sides 30/12/56/74');
    else if ((Math.abs(edge04 - edge15) > epsilon) ||
             (Math.abs(edge15 - edge26) > epsilon) ||
             (Math.abs(edge26 - edge37) > epsilon) ||
             (Math.abs(edge37 - edge04) > epsilon))
         Browser.println ('Warning, mismatched parallelopiped sides 04/15/26/37');
}
function length2 (pointA, pointB)
{    
    return Math.sqrt((pointA.x - pointB.x)*(pointA.x - pointB.x) +
                     (pointA.y - pointB.y)*(pointA.y - pointB.y) +
                     (pointA.z - pointB.z)*(pointA.z - pointB.z));
}
function set_point (eventValue)
{
   // input eventValue received for inputOutput field
    point = eventValue;
    checkCoordinatePoints ();
}

        
]]>
</Script>
</ProtoBody>
</ProtoDeclare>
<!-- ================================================================================ -->
<Background skyColor='0.905882 1 0.858824'/>
<Anchor description='Open ParallelepipedExamples scene'
  url=' "ParallelepipedExamples.x3d" "https://x3dgraphics.com/examples/X3dForAdvancedModeling/GeometricShapes/ParallelepipedExamples.x3d" "ParallelepipedExamples.wrl" "https://x3dgraphics.com/examples/X3dForAdvancedModeling/GeometricShapes/ParallelepipedExamples.wrl" '>
<Shape>
<Text string='"This scene defines a" "Parallelepiped prototype" "" "Select this text to open" "ParallelepipedExamples scene"'>
<FontStyle justify='"MIDDLE" "MIDDLE"'/>
</Text>
<Appearance DEF='BlueAppearance'>
<Material diffuseColor='0 0.698039 1'/>
</Appearance>
</Shape>
<Shape DEF='TransparentBox'>
<Box size='11 5 0.1'/>
<Appearance>
<Material transparency='1'/>
</Appearance>
</Shape>
</Anchor>
</Scene>
</X3D>
<!--

Index for ProtoDeclare definition : Parallelepiped

Index for DEF nodes : BlueAppearance, IFS, ParallelepipedScript, TransparentBox
-->

<!-- Color key: <X3dNode DEF='idName' field='value'/> matches <XmlElement DEF='idName' attribute='value'/>
(Light blue background: behavior node) (Grey background: inserted documentation) (Magenta background: X3D Extensibility)
    <Prototype name='ProtoName'> <field name='fieldName'/> </Prototype> -->

<!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources and X3D Scene Authoring Hints. -->