Skip to content
Snippets Groups Projects
WaypointInterpolatorExample.x3d 12.92 KiB
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.2//EN" "http://www.web3d.org/specifications/x3d-3.2.dtd">
<X3D profile='Immersive' version='3.2' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.2.xsd'>
  <head>
    <meta content='WaypointInterpolatorExample.x3d' name='title'/>
    <meta content='Example set of waypoints, plus either leg durations or speed(s), which demonstrates resulting position/orientation interpolation. Motion can be stopped/started by placing mouse over orange TouchSensor Box. A HiddenViewpoint also exists under the coordinate axes. Trace values are printed in the browser console.' name='description'/>
    <meta content='Don Brutzman, Curtis Blais, Jeff Weekley, Jane Wu' name='creator'/>
    <meta content='6 April 2001' name='created'/>
    <meta content='28 November 2019' name='modified'/>
    <meta content='WaypointInterpolatorExample.png' name='Image'/>
    <meta content='Cortona bug: TimeSensor set_cycleInterval has no effect, effectively ignoring routed totalDuration. Workaround: view calculated value for totalDuration, then set it in TimeSensor manually.' name='warning'/>
    <meta content='https://savage.nps.edu/Savage/Tools/Animation/WaypointInterpolatorExample.x3d' name='identifier'/>
    <meta content='https://savage.nps.edu/Savage/Tools/Animation/WaypointInterpolatorPrototype.x3d' name='reference'/>
    <meta content='X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit' name='generator'/>
    <meta content='../../license.html' name='license'/>
  </head>
  <Scene>
    <!-- ====================================== -->
    <!-- To use WaypointInterpolator in your scene, copy/paste this definition verbatim first. -->
    <WorldInfo title='WaypointInterpolatorExample.x3d'/>
    <ExternProtoDeclare appinfo='Reads waypoints and legSpeeds/legDurations/defaultSpeed to provide a customizable position/orientation interpolator.' name='WaypointInterpolator' url='"../../../Savage/Tools/Animation/WaypointInterpolatorPrototype.x3d#WaypointInterpolator" "https://savage.nps.edu/Savage/Tools/Animation/WaypointInterpolatorPrototype.x3d#WaypointInterpolator" "../../../Savage/Tools/Animation/WaypointInterpolatorPrototype.wrl#WaypointInterpolator" "https://savage.nps.edu/Savage/Tools/Animation/WaypointInterpolatorPrototype.wrl#WaypointInterpolator"'>
      <!-- Priority of use: legSpeeds (m/sec), legDurations (seconds), defaultSpeed (m/sec) -->
      <field accessType='initializeOnly' appinfo='Short description of what is animated by this WaypointInterpolator.' name='description' type='SFString'/>
      <field accessType='initializeOnly' appinfo='Waypoints being traversed with interpolation of intermediate positions and orientations.' name='waypoints' type='MFVec3f'/>
      <field accessType='inputOnly' appinfo='Add another single waypoint to array of waypoints recalculate interpolator values.' name='add_waypoint' type='SFVec3f'/>
      <field accessType='inputOnly' appinfo='Replace all waypoints recalculate interpolator values.' name='set_waypoints' type='MFVec3f'/>
      <field accessType='initializeOnly' appinfo='Whether to pitch child geometry (such as a vehicle) up or down to match vertical slope' name='pitchUpDownForVerticalWaypoints' type='SFBool'/>
      <field accessType='initializeOnly' appinfo='Units m/sec. If used, array lengths for legSpeeds and legDurations must be one less than number of waypoints.' name='legSpeeds' type='MFFloat'/>
      <field accessType='initializeOnly' appinfo='Units in seconds. If used, array lengths for legSpeeds and legDurations must be one less than number of waypoints.' name='legDurations' type='MFFloat'/>
      <field accessType='initializeOnly' appinfo='Units m/sec.' name='defaultSpeed' type='SFFloat'/>
      <field accessType='initializeOnly' appinfo='turningRate (degrees/second) also determines standoff distance prior to waypoint where turn commences. If 0 turns are instantaneous.' name='turningRate' type='SFFloat'/>
      <field accessType='outputOnly' appinfo='Output calculation summing all leg durations, useful for setting TimeSensor cycleInterval. Units in seconds.' name='totalDuration' type='SFTime'/>
      <!-- interpolation fields -->
      <field accessType='inputOnly' appinfo='exposed PositionInterpolator and OrientationInterpolator setting' name='set_fraction' type='SFFloat'/>
      <field accessType='outputOnly' appinfo='exposed PositionInterpolator setting' name='position_changed' type='SFVec3f'/>
      <field accessType='outputOnly' appinfo='exposed OrientationInterpolator setting' name='orientation_changed' type='SFRotation'/>
      <!-- display-related fields -->
      <field accessType='inputOutput' appinfo='default color for non-active line segments' name='lineColor' type='SFColor'/>
      <field accessType='inputOutput' appinfo='active segment highlight color' name='highlightSegmentColor' type='SFColor'/>
      <field accessType='inputOutput' appinfo='1.0 is completely transparent, 0.0 is completely opaque.' name='transparency' type='SFFloat'/>
      <field accessType='initializeOnly' appinfo='allowed values: none; waypoints (produce labels at each waypoint); or interpolation (produce single moving label at interpolator time course speed location)' name='labelDisplayMode' type='SFString'/>
      <field accessType='initializeOnly' appinfo='allowed values: altitude depth (negate Y value) none' name='heightLabel' type='SFString'/>
      <field accessType='initializeOnly' appinfo='heightLabel relative location' name='labelOffset' type='SFVec3f'/>
      <field accessType='initializeOnly' appinfo='heightLabel text size' name='labelFontSize' type='SFFloat'/>
      <field accessType='initializeOnly' appinfo='heightLabel text color' name='labelColor' type='SFColor'/>
      <field accessType='initializeOnly' appinfo='enable console output to trace script computations and prototype progress' name='traceEnabled' type='SFBool'/>
      <field accessType='initializeOnly' appinfo='Output the number of waypoints totalDistance and totalDuration to console upon initialization' name='outputInitializationComputations' type='SFBool'/>
      <field accessType='inputOutput' appinfo='default color for vertical drop-line segments' name='verticalDropLineColor' type='SFColor'/>
      <field accessType='inputOutput' appinfo='1.0 is completely transparent, 0.0 is completely opaque.' name='verticalDropLineTransparency' type='SFFloat'/>
    </ExternProtoDeclare>
    <!-- ====================================== -->
    <!-- Here is another interesting prototype authoring tool. -->
    <ExternProtoDeclare appinfo='Hidden viewpoint becomes active (binds) upon pointer selection to reveal an interesting view with an optionally label' name='HiddenViewpoint' url='"../../../Savage/Tools/Animation/HiddenViewpointPrototype.x3d#HiddenViewpoint" "https://savage.nps.edu/Savage/Tools/Animation/HiddenViewpointPrototype.x3d#HiddenViewpoint" "../../../Savage/Tools/Animation/HiddenViewpointPrototype.wrl#HiddenViewpoint" "https://savage.nps.edu/Savage/Tools/Animation/HiddenViewpointPrototype.wrl#HiddenViewpoint"'>
      <field accessType='inputOutput' name='position' type='SFVec3f'/>
      <field accessType='inputOutput' name='rotation' type='SFRotation'/>
      <field accessType='initializeOnly' name='sensorRadius' type='SFFloat'/>
      <field accessType='inputOnly' name='activate' type='SFBool'/>
      <field accessType='inputOutput' name='label' type='MFString'/>
      <field accessType='inputOutput' name='labelOffset' type='SFVec3f'/>
      <field accessType='initializeOnly' name='labelFontSize' type='SFFloat'/>
      <field accessType='inputOutput' name='labelColor' type='SFColor'/>
    </ExternProtoDeclare>
    <!-- ====================================== -->
    <!-- Example instance follows prototype declaration -->
    <Viewpoint description='WaypointInterpolator example' orientation='1 0 0 -0.3' position='-1 5 13'/>
    <Viewpoint description='Above, looking down' orientation='1 0 0 -1.57' position='0 15 -5'/>
    <Inline DEF='CoordinateAxes' url='"../../../Savage/Tools/Authoring/CoordinateAxes.x3d" "https://x3dgraphics.com/examples/X3dForWebAuthors/Chapter03Grouping/CoordinateAxes.x3d" "https://savage.nps.edu/Savage/Tools/Authoring/CoordinateAxes.x3d" "../../../Savage/Tools/Authoring/CoordinateAxes.wrl" "https://x3dgraphics.com/examples/X3dForWebAuthors/Chapter03Grouping/CoordinateAxes.wrl" "https://savage.nps.edu/Savage/Tools/Authoring/CoordinateAxes.wrl"'/>
    <!-- 10 second default cycleInterval should get overridden by 25.3 second computed totalDuration. -->
    <TimeSensor DEF='Clock' cycleInterval='10.0' loop='true'/>
    <ProtoInstance DEF='TrackBuilder' name='WaypointInterpolator'>
      <fieldValue name='description' value='TrackBuilder'/>
      <!-- Priority of use: legSpeeds (m/sec), legDurations (seconds), defaultSpeed (m/sec) -->
      <fieldValue name='waypoints' value='-5 0 0 5 2 0 5 5 -10 4.9 2 -10 -5 0 -10 -5 0 0 -5.5 0 1.5 -7 0.5 2 -8 0 0 -5 0 0'/>
      <fieldValue name='pitchUpDownForVerticalWaypoints' value='false'/>
      <fieldValue name='legDurations' value='1 2 3 1 2 3 1 2 3'/>
      <fieldValue name='legSpeeds' value='2 4 2 2 4 1 1 1 1'/>
      <fieldValue name='defaultSpeed' value='5'/>
      <fieldValue name='turningRate' value='90'/>
      <fieldValue name='lineColor' value='1 0 0'/>
      <fieldValue name='highlightSegmentColor' value='0.2 0.2 1'/>
      <fieldValue name='transparency' value='0'/>
      <fieldValue name='labelDisplayMode' value='interpolation'/>
      <fieldValue name='heightLabel' value='altitude'/>
      <fieldValue name='labelOffset' value='0 1.2 0'/>
      <fieldValue name='labelFontSize' value='0.5'/>
      <fieldValue name='labelColor' value='0.3 0.9 0.3'/>
      <fieldValue name='traceEnabled' value='false'/>
      <fieldValue name='outputInitializationComputations' value='true'/>
    </ProtoInstance>
    <ROUTE fromField='fraction_changed' fromNode='Clock' toField='set_fraction' toNode='TrackBuilder'/>
    <ROUTE fromField='totalDuration' fromNode='TrackBuilder' toField='set_cycleInterval' toNode='Clock'/>
    <Transform DEF='TrackingTransform'>
      <!-- Always align initial geometry with X axis -->
      <Group>
        <!-- Point cone along X-axis -->
        <Transform rotation='0 0 1 -1.57'>
          <Shape>
            <Cone bottomRadius='0.4'/>
            <Appearance DEF='ConeAppearance'>
              <Material diffuseColor='0.8 0.8 0.2'/>
            </Appearance>
          </Shape>
        </Transform>
        <Transform translation='0 0.1 0'>
          <Shape>
            <Cone bottomRadius='0.1' height='0.8'/>
            <Appearance USE='ConeAppearance'/>
          </Shape>
        </Transform>
        <Viewpoint description='Ride on' orientation='0 1 0 -1.57' position='-4 1 0'/>
        <Viewpoint description='Ride alongside' position='0 0 5'/>
        <Viewpoint description='Ride in front' orientation='0 1 0 1.57' position='4 1 0'/>
      </Group>
    </Transform>
    <ROUTE fromField='position_changed' fromNode='TrackBuilder' toField='translation' toNode='TrackingTransform'/>
    <ROUTE fromField='orientation_changed' fromNode='TrackBuilder' toField='rotation' toNode='TrackingTransform'/>
    <!-- floor employs TouchSensor.isOver to stop/start animation -->
    <Group DEF='FloorAndToggleMarker'>
      <Transform translation='0 -0.1 -5'>
        <Shape>
          <Box size='10 0.1 10'/>
          <Appearance DEF='FloorAppearance'>
            <Material diffuseColor='0.1 0.8 0.9'/>
          </Appearance>
        </Shape>
      </Transform>
      <!-- starting point marker toggles playback -->
      <Transform translation='-5 0 0'>
        <TouchSensor DEF='TouchBox' description='Touch box to toggle playback'/>
        <ROUTE fromField='isOver' fromNode='TouchBox' toField='enabled' toNode='Clock'/>
        <Shape>
          <Box DEF='TogglePlayback' size='0.1 0.8 0.1'/>
          <Appearance DEF='OrangeAppearance'>
            <Material diffuseColor='0.8 0.5 0.2'/>
          </Appearance>
        </Shape>
        <Transform translation='0 1.4 0'>
          <Billboard>
            <Shape>
              <Text string='"isOver" "toggles" "motion" "off/on"'>
                <FontStyle justify='"MIDDLE" "MIDDLE"' size='0.3'/>
              </Text>
              <Appearance USE='OrangeAppearance'/>
            </Shape>
          </Billboard>
        </Transform>
        <!-- Illuminate bottom of floor for HiddenViewpoint clarity -->
        <PointLight location='0 -6 0' radius='10'/>
      </Transform>
    </Group>
    <!-- Example instance of clickable viewpoint prototype -->
    <ProtoInstance DEF='TestHiddenViewpointPrototype' name='HiddenViewpoint'>
      <fieldValue name='position' value='0 -0.5 0'/>
      <fieldValue name='rotation' value='0 1 0 2.5'/>
      <fieldValue name='sensorRadius' value='1'/>
      <fieldValue name='label' value='"HiddenViewpoint" "test works!"'/>
      <fieldValue name='labelOffset' value='1 -1.25 0'/>
      <fieldValue name='labelFontSize' value='0.4'/>
      <fieldValue name='labelColor' value='1 0 0'/>
    </ProtoInstance>
  </Scene>
</X3D>