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='titlecontent=' BathymetryGeneratorPrototype.x3d '/>
  6            <meta name='descriptioncontent='This prototype generates bathymetry based on the input data using IndexedFaceSet.'/>
  7            <meta name='creatorcontent='Don Brutzman, Jane Wu'/>
  8            <meta name='createdcontent='8 February 2002'/>
  9            <meta name='modifiedcontent='28 November 2019'/>
 10            <meta name='subjectcontent='bathymetry'/>
 11            <meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/BathymetryGeneratorPrototype.x3d '/>
 12            <meta name='generatorcontent='X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit'/>
 13            <meta name='licensecontent='../../license.html'/>
 14       </head>
<!--

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

Index for ProtoDeclare definition: BathymetryGenerator
-->
 15       <Scene>
 16            <WorldInfo title='BathymetryGeneratorPrototype.x3d'/>
 17            <ProtoDeclare name='BathymetryGeneratorappinfo='BathymetryGenerator creates bottom topography'>
 18                 <ProtoInterface>
 19                      <field name='positionArraytype='MFVec3fvalue='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 70accessType='initializeOnly'/>
 20                      <field name='colorSchemeDepthRangeArraytype='MFVec2fvalue='0 -10 -10 -20 -20 -30 -30 -40 -40 -50 -50 -60 -60 -70 -70 -999999accessType='initializeOnly'/>
 21                      <field name='colorSchemeColorArraytype='MFColorvalue='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 1accessType='initializeOnly'/>
 22                      <field name='beamWidthtype='SFFloatvalue='2accessType='initializeOnly'/>
 23                      <field name='traceEnabledtype='SFBoolvalue='falseaccessType='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='BathymetryFaceSetccw='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='positionArraytype='MFVec3faccessType='initializeOnly'/>
 36                                     <field name='depthRangeArraytype='MFVec2faccessType='initializeOnly'/>
 37                                     <field name='depthColorArraytype='MFColoraccessType='initializeOnly'/>
 38                                     <field name='beamWidthtype='SFFloataccessType='initializeOnly'/>
 39                                     <field name='bathyFaceCoordPointstype='MFVec3faccessType='outputOnly'/>
 40                                     <field name='bathyCoordIndextype='MFInt32accessType='outputOnly'/>
 41                                     <field name='bathyFaceColorArraytype='MFColoraccessType='outputOnly'/>
 42                                     <field name='bathyColorIndextype='MFInt32accessType='outputOnly'/>
 43                                     <field name='traceEnabledtype='SFBoolaccessType='initializeOnly'/>
 44                                     <field name='dataValidtype='SFBoolvalue='falseaccessType='initializeOnly'
                                    appinfo='local variable'/>
 45                                     <field name='colortype='SFColorvalue='1 1 1accessType='initializeOnly'
                                    appinfo='local variable'/>
 46                                     <field name='leftPointtype='SFVec3fvalue='0 0 0accessType='initializeOnly'
                                    appinfo='local variable'/>
 47                                     <field name='rightPointtype='SFVec3fvalue='0 0 0accessType='initializeOnly'
                                    appinfo='local variable'/>
 48                                     <IS>
 49                                          <connect nodeField='positionArrayprotoField='positionArray'/>
 50                                          <connect nodeField='depthRangeArrayprotoField='colorSchemeDepthRangeArray'/>
 51                                          <connect nodeField='depthColorArrayprotoField='colorSchemeColorArray'/>
 52                                          <connect nodeField='beamWidthprotoField='beamWidth'/>
 53                                          <connect nodeField='traceEnabledprotoField='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='BathymetryGeneratorExampleparameter='"target=_blank"'   url=' "BathymetryGeneratorExample.x3d" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/BathymetryGeneratorExample.x3d" "BathymetryGeneratorExample.wrl" "https://www.web3d.org/x3d/content/examples/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 DEF nodes index: 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://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/BathymetryGeneratorPrototypeIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Savage/Tools/Animation/BathymetryGeneratorPrototype.x3d -->

<!-- Color-coding 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. -->