X3D Model Documentation: ParallelepipedPrototype.x3d

  1  <?xml version="1.0" encoding="UTF-8"?>
  2  <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "https://www.web3d.org/specifications/x3d-3.3.dtd">
  3  <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'>
  4       <head>
  5            <meta name='titlecontent='ParallelepipedPrototype.x3d'/>
  6            <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.'/>
  7            <meta name='creatorcontent='Don Brutzman'/>
  8            <meta name='createdcontent='25 November 2011'/>
  9            <meta name='modifiedcontent='7 December 2024'/>
 10            <meta name='referencecontent='ParallelepipedExamples.x3d'/>
 11            <meta name='Imagecontent='ParallelepipedVertexIndices.png'/>
 12            <meta name='drawingcontent='GeometricShapes.vsdx'/>
 13            <meta name='referencecontent='https://en.wikipedia.org/wiki/Parallelepiped'/>
 14            <meta name='referencecontent='http://upload.wikimedia.org/wikipedia/commons/f/f6/Parallelepiped.svg'/>
 15            <meta name='referencecontent='http://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Parallelepiped.svg/500px-Parallelepiped.svg.png'/>
 16            <meta name='subjectcontent='parallelepiped rhomboid geometry polyhedron'/>
 17            <meta name='identifiercontent='https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/GeometricShapes/ParallelepipedPrototype.x3d'/>
 18            <meta name='referencecontent='https://www.web3d.org/x3d/content/examples/X3dResources.html'/>
 19            <meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
 20            <meta name='licensecontent='../license.html'/>
 21       </head>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->

<!-- to top Index for DEF nodes: BlueAppearance, DefaultColor, DefaultNormal, DefaultTextureCoordinate, IFS, ParallelepipedScript, TransparentBox

Index for ProtoDeclare definition: Parallelepiped
-->
 22       <Scene>
 23            <WorldInfo title='ParallelepipedPrototype.x3d'/>
 24            <ProtoDeclare name='Parallelepipedappinfo='Parallelepiped is a 3D figure formed by six parallelograms; also sometimes referred to as a rhomboid'>
 25                 <ProtoInterface>
 26                      <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'/>
 27                      <field name='colorPerVertextype='SFBoolvalue='trueaccessType='initializeOnly'/>
 28                      <field name='normalPerVertextype='SFBoolvalue='trueaccessType='initializeOnly'/>
 29                      <field name='colorIndextype='MFInt32accessType='initializeOnly'/>
 30                      <field name='normalIndextype='MFInt32accessType='initializeOnly'/>
 31                      <field name='texCoordIndextype='MFInt32accessType='initializeOnly'/>
 32                      <field name='colorNodetype='SFNodeaccessType='inputOutput'>
 33                           <Color DEF='DefaultColor'/>
 34                      </field>
 35                      <field name='normalNodetype='SFNodeaccessType='inputOutput'>
 36                           <Normal DEF='DefaultNormal'/>
 37                      </field>
 38                      <field name='texCoordNodetype='SFNodeaccessType='inputOutput'>
 39                           <TextureCoordinate DEF='DefaultTextureCoordinate'/>
 40                      </field>
 41                 </ProtoInterface>
 42                 <ProtoBody>
 43                      <!-- First node determines node type of this prototype -->
 44                      <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'>
 45                           <IS>
 46                                <connect nodeField='colorPerVertexprotoField='colorPerVertex'/>
 47                                <connect nodeField='normalPerVertexprotoField='normalPerVertex'/>
 48                                <connect nodeField='colorIndexprotoField='colorIndex'/>
 49                                <connect nodeField='normalIndexprotoField='normalIndex'/>
 50                                <connect nodeField='texCoordIndexprotoField='texCoordIndex'/>
 51                                <connect nodeField='colorNodeprotoField='colorNode'/>
 52                                <connect nodeField='normalNodeprotoField='normalNode'/>
 53                                <connect nodeField='texCoordNodeprotoField='texCoordNode'/>
 54                           </IS>
 55                           <Coordinate>
 56                                <IS>
 57                                     <connect nodeField='pointprotoField='point'/>
 58                                </IS>
 59                           </Coordinate>
 60                      </IndexedFaceSet>
 61                      <!-- This embedded Script provides the X3D author with additional visibility and control over prototype inputs and outputs -->
 62                      <Script DEF='ParallelepipedScript'>
 63                           <field name='pointtype='MFVec3faccessType='inputOutput'/>
 64                           <IS>
 65                                <connect nodeField='pointprotoField='point'/>
 66                           </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 ();
}

        
]]>
 68                      </Script>
 69                 </ProtoBody>
 70            </ProtoDeclare>
 71            <!-- ================================================================================ -->
 72            <Background skyColor='0.905882 1 0.858824'/>
 73            <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" '>
 74                 <Shape>
 75                      <Text string='"This scene defines a" "Parallelepiped prototype" "" "Select this text to open" "ParallelepipedExamples scene"'>
 76                           <FontStyle justify='"MIDDLE" "MIDDLE"'/>
 77                      </Text>
 78                      <Appearance DEF='BlueAppearance'>
 79                           <Material diffuseColor='0 0.698039 1'/>
 80                      </Appearance>
 81                 </Shape>
 82                 <Shape DEF='TransparentBox'>
 83                      <Box size='11 5 0.1'/>
 84                      <Appearance>
 85                           <Material transparency='1'/>
 86                      </Appearance>
 87                 </Shape>
 88            </Anchor>
 89       </Scene>
 90  </X3D>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->

<!-- to top Index for DEF nodes: BlueAppearance, DefaultColor, DefaultNormal, DefaultTextureCoordinate, IFS, ParallelepipedScript, TransparentBox

Index for ProtoDeclare definition: Parallelepiped
-->
X3D Tooltips element index: Anchor, Appearance, Background, Box, Color, connect, Coordinate, field, FontStyle, head, IndexedFaceSet, IS, Material, meta, Normal, ProtoBody, ProtoDeclare, ProtoInterface, Scene, Script, Shape, Text, TextureCoordinate, WorldInfo, X3D, accessType and type, XML data types, field types

-->
<!-- Online at
https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/GeometricShapes/ParallelepipedPrototypeIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/GeometricShapes/ParallelepipedPrototype.x3d -->

<!-- Color legend: X3D terminology <X3dNode  DEF='idNamefield='value'/> matches XML terminology <XmlElement  DEF='idNameattribute='value'/>
(Light-blue background: event-based behavior node or statement) (Grey background inside box: inserted documentation) (Magenta background: X3D Extensibility)
    <ProtoDeclare name='ProtoName'> <field name='fieldName'/> ProtoDeclare> -->

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