<?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='SphericalMinePrototype.x3d' name='title'/>
    <meta content='Underwater mine prototype SphericalMine. Note level of detail (LOD) transitions when seen at transition ranges.' name='description'/>
    <meta content='Don Brutzman' name='creator'/>
    <meta content='26 June 2000' name='created'/>
    <meta content='2 September 2024' name='modified'/>
    <meta content='https://www.web3d.org/x3d/content/examples/Savage/Weapons/UnderwaterMines/SphericalMinePrototype.x3d' name='identifier'/>
    <meta content='X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit' name='generator'/>
    <meta content='../../license.html' name='license'/>
  </head>
  <Scene>
    <!-- SphericalMine is a simple notional mine -->
    <WorldInfo title='SphericalMinePrototype.x3d'/>
    <ProtoDeclare appinfo='Spherical floating mine moored to bottom' name='SphericalMine'>
      <ProtoInterface>
        <field accessType='initializeOnly' appinfo='Description for each mine contact.' name='description' type='SFString' value='10 m: Spherical Mine'/>
        <field accessType='inputOutput' appinfo='Mine color can be used to indicate status (found/unknown/disabled/) tactic etc.' name='color' type='SFColor' value='.8 .8 .8'/>
        <field accessType='inputOutput' appinfo='Location of mine center in local world coordinates.' name='translation' type='SFVec3f' value='0 0 0'/>
        <field accessType='inputOutput' appinfo='Scale factor to change spherical mine size default diameter = 1m.' name='scale' type='SFVec3f' value='1 1 1'/>
        <field accessType='initializeOnly' appinfo='Bounding box for collision detection of mine.' name='bboxCenter' type='SFVec3f' value='0 0 0'/>
        <field accessType='inputOutput' appinfo='Top and bottom endpoints of line tether that anchors this mine to the bottom.' name='tetherPoints' type='MFVec3f' value='0 0 0 0 -10 0'/>
        <field accessType='outputOnly' appinfo='proximityIsActive can be used to activate information or interaction when the viewer nears the mine.' name='proximityIsActive' type='SFBool'/>
        <field accessType='inputOutput' appinfo='proximitySize provides overall box dimensions for proximity; thus (10 10 10) yields approximate radius 5 to 7 meters.' name='proximitySize' type='SFVec3f' value='10 10 10'/>
      </ProtoInterface>
      <ProtoBody>
        <Transform DEF='LOCATOR'>
          <IS>
            <connect nodeField='translation' protoField='translation'/>
            <connect nodeField='scale' protoField='scale'/>
            <connect nodeField='bboxCenter' protoField='bboxCenter'/>
          </IS>
          <LOD range='100 500 5000'>
            <!-- High resolution -->
            <Group>
              <Viewpoint DEF='UW_MINE_VIEWPOINT'>
                <IS>
                  <connect nodeField='description' protoField='description'/>
                </IS>
              </Viewpoint>
              <ProximitySensor DEF='UW_MINE_PROXIMITY'>
                <IS>
                  <connect nodeField='isActive' protoField='proximityIsActive'/>
                  <connect nodeField='size' protoField='proximitySize'/>
                </IS>
              </ProximitySensor>
              <Shape DEF='UW_MINE_SPHERE'>
                <Sphere radius='.5'/>
                <Appearance DEF='UW_MINE_APPEARANCE'>
                  <Material DEF='UW_MINE_MATERIAL' shininess='.5'>
                    <IS>
                      <connect nodeField='diffuseColor' protoField='color'/>
                    </IS>
                  </Material>
                </Appearance>
              </Shape>
              <Transform translation='0 .49 0'>
                <Transform DEF='SPIKE' center='0 -.1 0' translation='0 .1 0'>
                  <Shape>
                    <Cone bottom='false' bottomRadius='.05' height='.2'/>
                    <Appearance>
                      <Material diffuseColor='.8 .8 .8' shininess='.5' specularColor='.2 .2 .2'/>
                    </Appearance>
                  </Shape>
                </Transform>
              </Transform>
              <Transform rotation='0 0 1 3.1416' translation='0 -.49 0'>
                <Transform USE='SPIKE'/>
              </Transform>
              <Transform rotation='0 0 1 -1.57079' translation='.49 0 0'>
                <Transform USE='SPIKE'/>
              </Transform>
              <Transform rotation='0 0 1 1.57079' translation='-.49 0 0'>
                <Transform USE='SPIKE'/>
              </Transform>
              <Transform rotation='1 0 0 1.57079' translation='0 0 .49'>
                <Transform USE='SPIKE'/>
              </Transform>
              <Transform rotation='1 0 0 -1.57079' translation='0 0 -.49'>
                <Transform USE='SPIKE'/>
              </Transform>
              <Shape>
                <IndexedLineSet coordIndex='0 1 -1'>
                  <Coordinate DEF='UW_MINE_TETHER'>
                    <IS>
                      <connect nodeField='point' protoField='tetherPoints'/>
                    </IS>
                  </Coordinate>
                </IndexedLineSet>
              </Shape>
            </Group>
            <!-- Medium resolution -->
            <Group>
              <Viewpoint DEF='UW_MINE_VIEWPOINT_MEDIUM'>
                <IS>
                  <connect nodeField='description' protoField='description'/>
                </IS>
              </Viewpoint>
              <Shape USE='UW_MINE_SPHERE'/>
            </Group>
            <!-- Low resolution -->
            <Shape>
              <Box size='12 12 12'/>
              <Appearance USE='UW_MINE_APPEARANCE'/>
            </Shape>
            <!-- No resolution -->
            <WorldInfo info='"null geometry"'/>
          </LOD>
        </Transform>
      </ProtoBody>
    </ProtoDeclare>
    <!-- Show default geometry, in case this Prototype library is viewed directly as a scene -->
    <Group DEF='ShowSphericalMines'>
      <ProtoInstance DEF='BLUE_SPHERICAL_MINE' name='SphericalMine'>
        <fieldValue name='description' value='10 m: blue SphericalMine default viewpoint'/>
        <fieldValue name='color' value='0 0 .8'/>
        <fieldValue name='translation' value='0 -10 0'/>
        <fieldValue name='bboxCenter' value='1 1 1'/>
        <fieldValue name='tetherPoints' value='0 0 0 0 -10.0 0'/>
      </ProtoInstance>
      <ProtoInstance DEF='GREEN_SPHERICAL_MINE' name='SphericalMine'>
        <fieldValue name='description' value='10 m: green SphericalMine default viewpoint'/>
        <fieldValue name='color' value='0 .8 0'/>
        <fieldValue name='translation' value='10 -10 0'/>
        <fieldValue name='bboxCenter' value='2 2 2'/>
        <fieldValue name='tetherPoints' value='0 0 0 0 -10.0 0'/>
      </ProtoInstance>
      <Background groundColor='0 .2 .2' skyColor='0 .3 .3'/>
      <Viewpoint description='1 m: one closeup SphericalMine' position='10 -10 2'/>
      <Viewpoint description='10 m: two pointy SphericalMines' position='5 -10 10'/>
      <Viewpoint description='100+ m: two round SphericalMines' position='5 -10 105'/>
      <Viewpoint description='500+ m: two boxy SphericalMines' position='5 -10 510'/>
      <Viewpoint description='5000+ m: two invisible SphericalMines' position='5 -10 5010'/>
    </Group>
    <!-- Proximity activation triggers switch in NavigationInfo mode between EXAMINE and WALK - pretty cool! -->
    <NavigationInfo DEF='NAVIGATION' speed='20' type='"WALK" "EXAMINE" "ANY"'/>
    <Script DEF='NAVIGATION_MODE'>
      <field accessType='inputOnly' name='inProximity' type='SFBool'/>
      <field accessType='outputOnly' name='type' type='MFString'/>
      <![CDATA[
ecmascript:

function inProximity ( value, eventTime )
{
 if ( value == true )
 {
	type[0] = 'EXAMINE';
	type[1] = 'WALK';
	type[2] = 'ANY';
 }
 else
 {
	type[0] = 'WALK';
	type[1] = 'EXAMINE';
	type[2] = 'ANY';
 }
 // Browser.println ('inProximity=' + value + ', type=' + type);
}
]]>
    </Script>
    <ROUTE fromField='proximityIsActive' fromNode='BLUE_SPHERICAL_MINE' toField='inProximity' toNode='NAVIGATION_MODE'/>
    <ROUTE fromField='proximityIsActive' fromNode='GREEN_SPHERICAL_MINE' toField='inProximity' toNode='NAVIGATION_MODE'/>
    <!-- TODO match field name in Script exactly -->
    <ROUTE fromField='type' fromNode='NAVIGATION_MODE' toField='set_type' toNode='NAVIGATION'/>
  </Scene>
</X3D>