<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.1//EN" "http://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='http://www.web3d.org/specifications/x3d-3.1.xsd'>
  <head>
    <meta content='BindingOperations.x3d' name='title'/>
    <meta content='Illustrate Viewpoint binding operations as described in Chapter 4 concepts. Display the browser console to see an event' name='description'/>
    <meta content='Don Brutzman' name='creator'/>
    <meta content='5 January 2008' name='created'/>
    <meta content='16 February 2008' name='modified'/>
    <meta content='BindingOperations.console.txt' name='reference'/>
    <meta content='BindingStackOperations.png' name='reference'/>
    <meta content='X3D for Web Authors, Section 2.5.1, Figure 4.1' name='reference'/>
    <meta content='http://X3dGraphics.com' name='reference'/>
    <meta content='http://www.web3d.org/x3d/content/examples/X3dResources.html' name='reference'/>
    <meta content='Copyright Don Brutzman and Leonard Daly 2007' name='rights'/>
    <meta content='X3D book, X3D graphics, X3D-Edit, http://www.x3dGraphics.com' name='subject'/>
    <meta content='http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter04-ViewingNavigation/BindingOperations.x3d' name='identifier'/>
    <meta content='X3D-Edit, https://savage.nps.edu/X3D-Edit' name='generator'/>
    <meta content='../license.html' name='license'/>
  </head>
  <Scene>
    <Viewpoint DEF='View1' centerOfRotation='-6 0 0' description='Viewpoint 1' position='-6 0 5'/>
    <Viewpoint DEF='View2' centerOfRotation='-2 0 0' description='Viewpoint 2' position='-2 0 5'/>
    <Viewpoint DEF='View3' centerOfRotation='2 0 0' description='Viewpoint 3' position='2 0 5'/>
    <Viewpoint DEF='View4' centerOfRotation='6 0 0' description='Viewpoint 4' position='6 0 5'/>
    <Group>
      <Transform DEF='Text1' translation='-6 0 0'>
        <Shape>
          <Text string='"View" "# 1"'>
            <FontStyle DEF='CenterJustify' justify='"MIDDLE" "MIDDLE"'/>
          </Text>
          <Appearance>
            <Material diffuseColor='1 0 0'/>
          </Appearance>
        </Shape>
      </Transform>
      <Transform DEF='Text2' translation='-2 0 0'>
        <Shape>
          <Text string='"View" "# 2"'>
            <FontStyle USE='CenterJustify'/>
          </Text>
          <Appearance>
            <Material diffuseColor='0 1 0'/>
          </Appearance>
        </Shape>
      </Transform>
      <Transform DEF='Text3' translation='2 0 0'>
        <Shape>
          <Text string='"View" "# 3"'>
            <FontStyle USE='CenterJustify'/>
          </Text>
          <Appearance>
            <Material diffuseColor='0 0 1'/>
          </Appearance>
        </Shape>
      </Transform>
      <Transform DEF='Text4' translation='6 0 0'>
        <Shape>
          <Text string='"View" "# 4"'>
            <FontStyle USE='CenterJustify'/>
          </Text>
        </Shape>
      </Transform>
    </Group>
    <!-- The following advanced animation sequence uses nodes covered in Chapters 7, 8 and 9. -->
    <!-- It does not need to be studied in this chapter. -->
    <Transform translation='0 -3 8'>
      <!-- notice this next Viewpoint has been transformed with the text, so its position is relative -->
      <Viewpoint DEF='ClickToAnimateView' description='Select animation sequence' fieldOfView='0.785' position='0 0 7'/>
      <Shape>
        <Text string='"Click here to animate"'>
          <FontStyle justify='"MIDDLE" "BEGIN"'/>
        </Text>
        <Appearance>
          <Material diffuseColor='0.8 0.4 0'/>
        </Appearance>
      </Shape>
      <Shape>
        <Box size='7 1 0.02'/>
        <Appearance>
          <Material transparency='1'/>
        </Appearance>
      </Shape>
      <TouchSensor DEF='TextTouchSensor' description='Click to begin animating viewpoint selections'/>
      <TimeSensor DEF='Clock' cycleInterval='10'/>
      <ROUTE fromField='touchTime' fromNode='TextTouchSensor' toField='set_startTime' toNode='Clock'/>
      <IntegerSequencer DEF='TimingSequencer' key='0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 1.0' keyValue='0 1 2 3 4 5 6 7 8 10'/>
      <ROUTE fromField='fraction_changed' fromNode='Clock' toField='set_fraction' toNode='TimingSequencer'/>
      <Script DEF='BindingSequencerEngine'>
        <field accessType='inputOnly' name='set_timeEvent' type='SFInt32'/>
        <field accessType='outputOnly' name='bindView1' type='SFBool'/>
        <field accessType='outputOnly' name='bindView2' type='SFBool'/>
        <field accessType='outputOnly' name='bindView3' type='SFBool'/>
        <field accessType='outputOnly' name='bindView4' type='SFBool'/>
        <field accessType='outputOnly' name='bindView5' type='SFBool'/>
        <field accessType='inputOnly' name='view1Bound' type='SFBool'/>
        <field accessType='inputOnly' name='view2Bound' type='SFBool'/>
        <field accessType='inputOnly' name='view3Bound' type='SFBool'/>
        <field accessType='inputOnly' name='view4Bound' type='SFBool'/>
        <field accessType='initializeOnly' name='priorInputvalue' type='SFInt32' value='-1'/>
        <![CDATA[
ecmascript:

function initialize ()
{
    bindView5 = true;
    Browser.print ('initialized and ready for activation');
}
function set_timeEvent (inputValue)
{
    if (inputValue == priorInputvalue)
    {
        return; // ignore repeated inputs
    }
    // new value provided
    priorInputvalue = inputValue;
    // Browser.print ('\ntimeEvent inputValue=' + inputValue);
        
    // mimics user execution of Figure 4.1 steps t_0 through t_8
    switch (inputValue) 
    {
        case 0:
        {
            Browser.print ('\n===========\n time t0');
            bindView1 = true;
            break;
        }
        case 1:
        {
            Browser.print ('\n===========\n time t1');
            bindView2 = true;
            break;
        }
        case 2:
        {
            Browser.print ('\n===========\n time t2');
            bindView3 = true;
            break;
        }
        case 3:
        {
            Browser.print ('\n===========\n time t3');
            bindView3 = false;
            break;
        }
        case 4:
        {
            Browser.print ('\n===========\n time t4');
            bindView1 = true;
            break;
        }
        case 5:
        {
            Browser.print ('\n===========\n time t5');
            bindView2 = false;
            break;
        }
        case 6:
        {
            Browser.print ('\n===========\n time t6');
            bindView1 = false;
            break;
        }
        case 7:
        {
            Browser.print ('\n===========\n time t7');
            bindView4 = true;
            break;

        }
        case 8:
        {
            Browser.print ('\n===========\n time t8');
            Browser.print (', no action, all done');
            Browser.print ('\n\n');
            break;
        }
    }
}

function view1Bound (inputValue)
{
    Browser.print (', view1Bound ' + (inputValue));
    if (priorInputvalue == -1) Browser.print ('\n');
}
function view2Bound (inputValue)
{
    Browser.print (', view2Bound ' + (inputValue));
}
function view3Bound (inputValue)
{
    Browser.print (', view3Bound ' + (inputValue));
}
function view4Bound (inputValue)
{
    Browser.print (', view4Bound ' + (inputValue));
}
function view5Bound (inputValue)
{
    Browser.print (', view5Bound ' + (inputValue));
}
]]>
      </Script>
      <!-- drive Script with TimeSensor clock -->
      <ROUTE fromField='value_changed' fromNode='TimingSequencer' toField='set_timeEvent' toNode='BindingSequencerEngine'/>
      <!-- Script will bind and unbind Viewpoint nodes -->
      <ROUTE fromField='bindView1' fromNode='BindingSequencerEngine' toField='set_bind' toNode='View1'/>
      <ROUTE fromField='bindView2' fromNode='BindingSequencerEngine' toField='set_bind' toNode='View2'/>
      <ROUTE fromField='bindView3' fromNode='BindingSequencerEngine' toField='set_bind' toNode='View3'/>
      <ROUTE fromField='bindView4' fromNode='BindingSequencerEngine' toField='set_bind' toNode='View4'/>
      <ROUTE fromField='bindView5' fromNode='BindingSequencerEngine' toField='set_bind' toNode='ClickToAnimateView'/>
      <!-- Viewpoint nodes report bind and unbind events -->
      <ROUTE fromField='isBound' fromNode='View1' toField='view1Bound' toNode='BindingSequencerEngine'/>
      <ROUTE fromField='isBound' fromNode='View2' toField='view2Bound' toNode='BindingSequencerEngine'/>
      <ROUTE fromField='isBound' fromNode='View3' toField='view3Bound' toNode='BindingSequencerEngine'/>
      <ROUTE fromField='isBound' fromNode='View4' toField='view4Bound' toNode='BindingSequencerEngine'/>
    </Transform>
  </Scene>
</X3D>