<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.1//EN" "https://www.web3d.org/specifications/x3d-3.1.dtd">
<X3D profile='Immersive' version='3.1' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.1.xsd'>
  <head>
    <meta content='PixelTextureInterpolatorPrototype.x3d' name='title'/>
    <meta content='Create Script prototype to modify a PixelTexture as an image morph' name='description'/>
    <meta content='Don Brutzman' name='creator'/>
    <meta content='14 April 2008' name='created'/>
    <meta content='20 October 2019' name='modified'/>
    <meta content='under development' name='warning'/>
    <meta content='2D image PixelTexture morph' name='subject'/>
    <meta content='https://savage.nps.edu/Savage/Tools/Authoring/PixelTextureInterpolatorPrototype.x3d' name='identifier'/>
    <meta content='X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit' name='generator'/>
    <meta content='../license.html' name='license'/>
  </head>
  <Scene>
    <WorldInfo title='PixelTextureInterpolatorPrototype.x3d'/>
    <ProtoDeclare name='PixelTextureInterpolator'>
      <ProtoInterface>
        <field accessType='inputOnly' name='set_fraction' type='SFFloat'/>
        <field accessType='initializeOnly' name='key' type='MFFloat'/>
        <field accessType='initializeOnly' name='keyValue' type='MFNode'/>
        <field accessType='outputOnly' name='value_changed' type='SFImage'/>
        <field accessType='initializeOnly' appinfo='enable console output to trace script computations and prototype progress' name='traceEnabled' type='SFBool' value='true'/>
      </ProtoInterface>
      <ProtoBody>
        <!-- First node determines node type of prototype -->
        <Script DEF='ImageInterpolatorScript' url='"PixelTextureInterpolator.js" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/PixelTextureInterpolator.js"'>
          <field accessType='inputOnly' name='set_fraction' type='SFFloat'/>
          <field accessType='initializeOnly' name='key' type='MFFloat'/>
          <field accessType='initializeOnly' name='keyValue' type='MFNode'>
            <!-- initialization nodes (if any) go here -->
          </field>
          <field accessType='outputOnly' name='value_changed' type='SFImage'/>
          <field accessType='initializeOnly' name='traceEnabled' type='SFBool'/>
          <IS>
            <connect nodeField='set_fraction' protoField='set_fraction'/>
            <connect nodeField='key' protoField='key'/>
            <connect nodeField='keyValue' protoField='keyValue'/>
            <connect nodeField='value_changed' protoField='value_changed'/>
            <connect nodeField='traceEnabled' protoField='traceEnabled'/>
          </IS>
        </Script>
        <!-- Subsequent nodes do not render, but still must be a valid X3D subgraph -->
      </ProtoBody>
    </ProtoDeclare>
    <!-- renderable scene graph begins here -->
    <Shape>
      <Box/>
      <Appearance>
        <PixelTexture DEF='PixelColors' image='2 4 3 0xff0000 0xffff00 0x007700 0xff0077 0x0000ff 0xff7700 0x00ff77 0x888888'/>
      </Appearance>
    </Shape>
    <!-- set of images, interpolated as a 2D morph -->
    <ProtoInstance DEF='PixelTextureInterpolatorExample' name='PixelTextureInterpolator'>
      <fieldValue name='key' value='0 0.25 0.5 0.75 1'/>
      <fieldValue name='keyValue'>
        <!-- rotate two image values in each PixelTexture -->
        <PixelTexture image='2 4 3 0xff0000 0xffff00 0x007700 0xff0077 0x0000ff 0xff7700 0x00ff77 0x888888'/>
        <PixelTexture image='2 4 3 0x007700 0xff0077 0x0000ff 0xff7700 0x00ff77 0x888888 0xff0000 0xffff00'/>
        <PixelTexture image='2 4 3 0x0000ff 0xff7700 0x00ff77 0x888888 0xff0000 0xffff00 0x007700 0xff0077'/>
        <PixelTexture image='2 4 3 0x00ff77 0x888888 0xff0000 0xffff00 0x007700 0xff0077 0x0000ff 0xff7700'/>
        <!-- last PixelTexture matches first, would like to DEF and USE within a fieldValue initialization -->
        <PixelTexture image='2 4 3 0xff0000 0xffff00 0x007700 0xff0077 0x0000ff 0xff7700 0x00ff77 0x888888'/>
      </fieldValue>
      <fieldValue name='traceEnabled' value='true'/>
    </ProtoInstance>
    <TimeSensor DEF='Time' cycleInterval='4'/>
    <ROUTE fromField='value_changed' fromNode='PixelTextureInterpolatorExample' toField='image' toNode='PixelColors'/>
    <ROUTE fromField='fraction_changed' fromNode='Time' toField='set_fraction' toNode='PixelTextureInterpolatorExample'/>
  </Scene>
</X3D>