<?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 content='ParallelepipedPrototype.x3d' name='title'/>
    <meta content='Reusable prototype for creating a Parallelepiped, which is a 3D figure formed by six parallelograms; also sometimes referred to as a rhomboid.' name='description'/>
    <meta content='Don Brutzman' name='creator'/>
    <meta content='25 November 2011' name='created'/>
    <meta content='7 December 2024' name='modified'/>
    <meta content='ParallelepipedExamples.x3d' name='reference'/>
    <meta content='ParallelepipedVertexIndices.png' name='Image'/>
    <meta content='GeometricShapes.vsdx' name='drawing'/>
    <meta content='https://en.wikipedia.org/wiki/Parallelepiped' name='reference'/>
    <meta content='http://upload.wikimedia.org/wikipedia/commons/f/f6/Parallelepiped.svg' name='reference'/>
    <meta content='http://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Parallelepiped.svg/500px-Parallelepiped.svg.png' name='reference'/>
    <meta content='parallelepiped rhomboid geometry polyhedron' name='subject'/>
    <meta content='https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/GeometricShapes/ParallelepipedPrototype.x3d' name='identifier'/>
    <meta content='https://www.web3d.org/x3d/content/examples/X3dResources.html' name='reference'/>
    <meta content='X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit' name='generator'/>
    <meta content='../license.html' name='license'/>
  </head>
  <Scene>
    <WorldInfo title='ParallelepipedPrototype.x3d'/>
    <ProtoDeclare appinfo='Parallelepiped is a 3D figure formed by six parallelograms; also sometimes referred to as a rhomboid' name='Parallelepiped'>
      <ProtoInterface>
        <field accessType='inputOutput' name='point' type='MFVec3f' value='0 1 0 1 1 0 1 1 1 0 1 1 0 0 0 1 0 0 1 0 1 0 0 1'/>
        <field accessType='initializeOnly' name='colorPerVertex' type='SFBool' value='true'/>
        <field accessType='initializeOnly' name='normalPerVertex' type='SFBool' value='true'/>
        <field accessType='initializeOnly' name='colorIndex' type='MFInt32'/>
        <field accessType='initializeOnly' name='normalIndex' type='MFInt32'/>
        <field accessType='initializeOnly' name='texCoordIndex' type='MFInt32'/>
        <field accessType='inputOutput' name='colorNode' type='SFNode'>
          <Color DEF='DefaultColor'/>
        </field>
        <field accessType='inputOutput' name='normalNode' type='SFNode'>
          <Normal DEF='DefaultNormal'/>
        </field>
        <field accessType='inputOutput' name='texCoordNode' type='SFNode'>
          <TextureCoordinate DEF='DefaultTextureCoordinate'/>
        </field>
      </ProtoInterface>
      <ProtoBody>
        <!-- First node determines node type of this prototype -->
        <IndexedFaceSet DEF='IFS' convex='false' coordIndex='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' solid='false'>
          <IS>
            <connect nodeField='colorPerVertex' protoField='colorPerVertex'/>
            <connect nodeField='normalPerVertex' protoField='normalPerVertex'/>
            <connect nodeField='colorIndex' protoField='colorIndex'/>
            <connect nodeField='normalIndex' protoField='normalIndex'/>
            <connect nodeField='texCoordIndex' protoField='texCoordIndex'/>
            <connect nodeField='colorNode' protoField='colorNode'/>
            <connect nodeField='normalNode' protoField='normalNode'/>
            <connect nodeField='texCoordNode' protoField='texCoordNode'/>
          </IS>
          <Coordinate>
            <IS>
              <connect nodeField='point' protoField='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 accessType='inputOutput' name='point' type='MFVec3f'/>
          <IS>
            <connect nodeField='point' protoField='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 parallelepiped 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 parallelepiped 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 parallelepiped 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://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/GeometricShapes/ParallelepipedExamples.x3d" "ParallelepipedExamples.wrl" "https://www.web3d.org/x3d/content/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>