X3D Model Documentation: BathymetryGeneratorPrototype.x3d

  1  <?xml version="1.0" encoding="UTF-8"?>
  2 
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
  3  <X3D profile='Immersive' version='3.0'  xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.0.xsd'>
  4       <head>
  5            <meta name='title' content='BathymetryGeneratorPrototype.x3d'/>
  6            <meta name='description' content='This prototype generates bathymetry based on the input data using IndexedFaceSet.'/>
  7            <meta name='creator' content='Don Brutzman, Jane Wu'/>
  8            <meta name='created' content='8 February 2002'/>
  9            <meta name='modified' content='28 November 2019'/>
 10            <meta name='subject' content='bathymetry'/>
 11            <meta name='identifier' content='https://savage.nps.edu/Savage/Tools/Animation/BathymetryGeneratorPrototype.x3d'/>
 12            <meta name='generator' content='X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit'/>
 13            <meta name='license' content='../../license.html'/>
 14       </head>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->
<!-- to top Index for DEF nodes: Bathymetry, BathymetryFaceColor, BathymetryFaceCoord, BathymetryFaceSet, BathymetryScript

Index for ProtoDeclare definition: BathymetryGenerator
-->
 15       <Scene>
 16            <WorldInfo title='BathymetryGeneratorPrototype.x3d'/>
 17            <ProtoDeclare name='BathymetryGenerator' appinfo='BathymetryGenerator creates bottom topography'>
 18                 <ProtoInterface>
 19                      <field name='positionArray' type='MFVec3f' value='0.0 0 0 10 -4 0 25 -6 0 30 -8 5 38 -15 5 45 -18 5 55 -22 5 60 -25 15 60 -27 22 55 -30 35 48 -35 35 35 -35 35 25 -45 35 20 -55 35 15 -70 35 3 -70 35 -5 -72 40 -5 -75 50 0 -80 55 15 -75 55 30 -70 55 35 -60 55 40 -50 55 50 -34 55 65 -23 70' accessType='initializeOnly'/>
 20                      <field name='colorSchemeDepthRangeArray' type='MFVec2f' value='0 -10 -10 -20 -20 -30 -30 -40 -40 -50 -50 -60 -60 -70 -70 -999999' accessType='initializeOnly'/>
 21                      <field name='colorSchemeColorArray' type='MFColor' value='1 1 0.2 0.6 1 1 0 1 1 0.2 0.6 0.2 1 0 1 0.56 0 0.32 0.2 0.3 0.7 0 0 1' accessType='initializeOnly'/>
 22                      <field name='beamWidth' type='SFFloat' value='2' accessType='initializeOnly'/>
 23                      <field name='traceEnabled' type='SFBool' value='false' accessType='initializeOnly'/>
 24                 </ProtoInterface>
 25                 <ProtoBody>
 26                      <Group>
 27                           <Transform DEF='Bathymetry'>
 28                                <Shape>
 29 
                                   <!-- ROUTE information for BathymetryFaceSet node:  [from BathymetryScript.bathyCoordIndex to set_coordIndex ] [from BathymetryScript.bathyColorIndex to set_colorIndex ] -->
                                   <IndexedFaceSet DEF='BathymetryFaceSet' ccw='false'>
 30 
                                        <!-- ROUTE information for BathymetryFaceColor node:  [from BathymetryScript.bathyFaceColorArray to color ] -->
                                        <Color DEF='BathymetryFaceColor'/>
 31 
                                        <!-- ROUTE information for BathymetryFaceCoord node:  [from BathymetryScript.bathyFaceCoordPoints to point ] -->
                                        <Coordinate DEF='BathymetryFaceCoord'/>
 32                                     </IndexedFaceSet>
 33                                </Shape>
 34 
                              <!-- ROUTE information for BathymetryScript node:  [from bathyFaceCoordPoints to BathymetryFaceCoord.point ] [from bathyCoordIndex to BathymetryFaceSet.set_coordIndex ] [from bathyFaceColorArray to BathymetryFaceColor.color ] [from bathyColorIndex to BathymetryFaceSet.set_colorIndex ] -->
                              <Script DEF='BathymetryScript'>
 35                                     <field name='positionArray' type='MFVec3f' accessType='initializeOnly'/>
 36                                     <field name='depthRangeArray' type='MFVec2f' accessType='initializeOnly'/>
 37                                     <field name='depthColorArray' type='MFColor' accessType='initializeOnly'/>
 38                                     <field name='beamWidth' type='SFFloat' accessType='initializeOnly'/>
 39                                     <field name='bathyFaceCoordPoints' type='MFVec3f' accessType='outputOnly'/>
 40                                     <field name='bathyCoordIndex' type='MFInt32' accessType='outputOnly'/>
 41                                     <field name='bathyFaceColorArray' type='MFColor' accessType='outputOnly'/>
 42                                     <field name='bathyColorIndex' type='MFInt32' accessType='outputOnly'/>
 43                                     <field name='traceEnabled' type='SFBool' accessType='initializeOnly'/>
 44                                     <field name='dataValid' type='SFBool' value='false' accessType='initializeOnly'
                                    appinfo='local variable'/>
 45                                     <field name='color' type='SFColor' value='1 1 1' accessType='initializeOnly'
                                    appinfo='local variable'/>
 46                                     <field name='leftPoint' type='SFVec3f' value='0 0 0' accessType='initializeOnly'
                                    appinfo='local variable'/>
 47                                     <field name='rightPoint' type='SFVec3f' value='0 0 0' accessType='initializeOnly'
                                    appinfo='local variable'/>
 48                                     <IS>
 49                                          <connect nodeField='positionArray' protoField='positionArray'/>
 50                                          <connect nodeField='depthRangeArray' protoField='colorSchemeDepthRangeArray'/>
 51                                          <connect nodeField='depthColorArray' protoField='colorSchemeColorArray'/>
 52                                          <connect nodeField='beamWidth' protoField='beamWidth'/>
 53                                          <connect nodeField='traceEnabled' protoField='traceEnabled'/>
 54                                     </IS>
  <![CDATA[
              
ecmascript:

function initialize()
{
	dataValid = true;
	checkDataValidity();
	if (!dataValid)
		return;

	tracePrint('positionArray.length = ' + positionArray.length);

	coordIndex = 0;
	colorIndex = 0;
	for (i = 0; i < positionArray.length; i++)
	{
		//determine the color for every position
		determineFaceColor(positionArray[i].y)
		bathyFaceColorArray[colorIndex++] = color;

		//determine the 'leftPoint' for every poistion -- For the first
		//position, use the first and second position.
		if (i == 0)
		{
			determineLeftPoint(positionArray[0], positionArray[1]);
			bathyFaceCoordPoints[coordIndex++] = leftPoint;
			determineRightPoint(positionArray[0], positionArray[1]);
			bathyFaceCoordPoints[coordIndex++] = rightPoint;
		}
		else
		{
			determineLeftPoint(positionArray[i], positionArray[i-1]);
			bathyFaceCoordPoints[coordIndex++] = leftPoint;
			determineRightPoint(positionArray[i], positionArray[i-1]);
			bathyFaceCoordPoints[coordIndex++] = rightPoint;
		}
	}

	tracePrint('bathyFaceCoordPoints = ' + bathyFaceCoordPoints);

	j = 0;
	for (i = 0; i < (positionArray.length - 1); i++)
	{
		bathyCoordIndex[j++] = i * 2;
		bathyCoordIndex[j++] = i * 2 + 1;
		bathyCoordIndex[j++] = i * 2 + 2;
		bathyCoordIndex[j++] = i * 2 + 3;
		bathyCoordIndex[j++] = -1;

		bathyCoordIndex[j++] = i * 2 + 3;
		bathyCoordIndex[j++] = i * 2 + 2;
		bathyCoordIndex[j++] = i * 2 + 1;
		bathyCoordIndex[j++] = i * 2;
		bathyCoordIndex[j++] = -1;
	}

	tracePrint('bathyCoordIndex = ' + bathyCoordIndex);
}

function checkDataValidity()
{
	if (depthRangeArray.length != depthColorArray.length)
	{
		alwaysPrint('<Error> colorSchemeDepthRangeArray must be the same length as colorSchemeColorArray');
		dataValid = false;
		return;
	}
}

function determineFaceColor(depth)
{
	for (j = 0; j < depthColorArray.length; j++)
        {
		if (depth <= depthRangeArray[j].x && depth >= depthRangeArray[j].y)
		{
			color = depthColorArray[j]
			return;
		}
        }
	color = null;
	return;
}

function determineLeftPoint(currPosition, prevPosition)
{
	deltaX = currPosition.x - prevPosition.x;
	deltaZ = currPosition.z - prevPosition.z;

	theta = Math.atan2(deltaX, deltaZ);
	tracePrint('theta = ' + theta);

	leftPoint = new SFVec3f(currPosition.x + Math.cos(theta),
	                        currPosition.y,
	                        currPosition.z - Math.sin(theta) * (beamWidth / 2));
}

function determineRightPoint(currPosition, prevPosition)
{
	deltaX = currPosition.x - prevPosition.x;
	deltaZ = currPosition.z - prevPosition.z;

	theta = Math.atan2(deltaX, deltaZ);

	rightPoint = new SFVec3f(currPosition.x - Math.cos(theta),
	                         currPosition.y,
	                         currPosition.z + Math.sin(theta) * (beamWidth / 2));
}

function alwaysPrint(string)
{
	Browser.println ('[BathymetryGeneratorPrototype] ' + string);
}

function tracePrint(string)
{
	if (traceEnabled)
		Browser.println ('[BathymetryGeneratorPrototype] ' + string);
}

            
]]>
 56                                </Script>
 57                                < ROUTE  fromNode='BathymetryScript' fromField='bathyFaceCoordPoints' toNode='BathymetryFaceCoord' toField='point'/>
 58                                < ROUTE  fromNode='BathymetryScript' fromField='bathyCoordIndex' toNode='BathymetryFaceSet' toField='set_coordIndex'/>
 59                                < ROUTE  fromNode='BathymetryScript' fromField='bathyFaceColorArray' toNode='BathymetryFaceColor' toField='color'/>
 60                                < ROUTE  fromNode='BathymetryScript' fromField='bathyColorIndex' toNode='BathymetryFaceSet' toField='set_colorIndex'/>
 61                           </Transform>
 62                      </Group>
 63                 </ProtoBody>
 64            </ProtoDeclare>
 65            <!-- ==================== -->
 66            <!-- Example scene starts here, in case this prototype is examined. -->
 67            <Anchor description='BathymetryGeneratorExample' parameter='"target=_blank"'   url=' "BathymetryGeneratorExample.x3d" "https://savage.nps.edu/Savage/Tools/Animation/BathymetryGeneratorExample.x3d" "BathymetryGeneratorExample.wrl" "https://savage.nps.edu/Savage/Tools/Animation/BathymetryGeneratorExample.wrl" '>
 68                 <Shape>
 69                      <Text string='"BathymetryGeneratorPrototype" "is a prototype definition file" "" "Click this text to see" "BathymetryGeneratorExample"'>
 70                           <FontStyle justify='"MIDDLE" "MIDDLE"'/>
 71                      </Text>
 72                      <Appearance>
 73                           <Material diffuseColor='0.6 0.8 0.4'/>
 74                      </Appearance>
 75                 </Shape>
 76            </Anchor>
 77       </Scene>
 78  </X3D>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->
<!-- to top Index for DEF nodes: Bathymetry, BathymetryFaceColor, BathymetryFaceCoord, BathymetryFaceSet, BathymetryScript

Index for ProtoDeclare definition: BathymetryGenerator
-->
X3D Tooltips element index: Anchor, Appearance, Color, connect, Coordinate, field, FontStyle, Group, head, IndexedFaceSet, IS, Material, meta, ProtoBody, ProtoDeclare, ProtoInterface, ROUTE, Scene, Script, Shape, Text, Transform, WorldInfo, X3D, plus documentation for accessType definitions, type definitions, XML data types, and field types

Event Graph ROUTE Table entries with 4 ROUTE connections total, showing X3D event-model relationships for this scene.

Each row shows an event cascade that may occur during a single timestamp interval between frame renderings, as part of the X3D execution model.

BathymetryScript
Script
bathyFaceCoordPoints
MFVec3f
→
ROUTE
event to
(1)
BathymetryFaceCoord
Coordinate
point
MFVec3f
BathymetryScript
Script
bathyCoordIndex
MFInt32
→
ROUTE
event to
(1)
BathymetryFaceSet
IndexedFaceSet
set_coordIndex
MFInt32
BathymetryScript
Script
bathyFaceColorArray
MFColor
→
ROUTE
event to
(1)
BathymetryFaceColor
Color
color
MFColor
BathymetryScript
Script
bathyColorIndex
MFInt32
→
ROUTE
event to
(1)
BathymetryFaceSet
IndexedFaceSet
set_colorIndex
MFInt32

line 67
Anchor
description='BathymetryGeneratorExample' 
User-interaction hint for this node. 

Additional guidance on X3D animation can be found in the 10-Step Animation Design Process and Event Tracing hint sheets. Have fun with X3D! 😀

-->
<!-- Online at
https://savage.nps.edu/Savage/Tools/Animation/BathymetryGeneratorPrototypeIndex.html -->
<!-- Version control at
https://gitlab.nps.edu/Savage/Savage/Tools/Animation/BathymetryGeneratorPrototype.x3d -->

<!-- Color-coding legend: X3D terminology <X3dNode  DEF='idName' field='value'/> matches XML terminology <XmlElement  DEF='idName' attribute='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. -->