<?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 name='titlecontent='BindingOperations.x3d'/>
<meta name='descriptioncontent='Illustrate Viewpoint binding operations (in gory detail!) as described in Chapter 4 concepts. Scene design: a TimeSensor clock drives and IntegerSequencer for each t0/t1/etc. event, and a customized Script node sends bind/unbind events to the correct Viewpoint. Display the browser console to see occurrence of each event.'/>
<meta name='creatorcontent='Don Brutzman'/>
<meta name='createdcontent='5 January 2008'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='referencecontent='BindingOperations.console.txt'/>
<meta name='referencecontent='BindingStackOperations.png'/>
<meta name='referencecontent='X3D for Web Authors, Section 2.5.1, Figure 4.1'/>
<meta name='referencecontent=' https://X3dGraphics.com '/>
<meta name='referencecontent=' https://www.web3d.org/x3d/content/examples/X3dResources.html '/>
<meta name='rightscontent='Copyright Don Brutzman and Leonard Daly 2007'/>
<meta name='subjectcontent=' X3D book, X3D graphics, X3D-Edit, http://www.x3dGraphics.com '/>
<meta name='identifiercontent=' https://X3dGraphics.com/examples/X3dForWebAuthors/Chapter04ViewingNavigation/BindingOperations.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../license.html'/>
</head>
<!-- -->
<Scene>
<WorldInfo title='BindingOperations.x3d'/>
<!-- ROUTE information for View1 node:  [from BindingSequencerEngine.bindView1 to set_bind ] [from isBound to BindingSequencerEngine.view1Bound ] -->
<Viewpoint DEF='View1centerOfRotation='-6 0 0description='Viewpoint 1position='-6 0 5'/>
<!-- ROUTE information for View2 node:  [from BindingSequencerEngine.bindView2 to set_bind ] [from isBound to BindingSequencerEngine.view2Bound ] -->
<Viewpoint DEF='View2centerOfRotation='-2 0 0description='Viewpoint 2position='-2 0 5'/>
<!-- ROUTE information for View3 node:  [from BindingSequencerEngine.bindView3 to set_bind ] [from isBound to BindingSequencerEngine.view3Bound ] -->
<Viewpoint DEF='View3centerOfRotation='2 0 0description='Viewpoint 3position='2 0 5'/>
<!-- ROUTE information for View4 node:  [from BindingSequencerEngine.bindView4 to set_bind ] [from isBound to BindingSequencerEngine.view4Bound ] -->
<Viewpoint DEF='View4centerOfRotation='6 0 0description='Viewpoint 4position='6 0 5'/>
<!-- Script initialization ought to first bind view5 below. -->
<Group>
<Transform DEF='Text1translation='-6 0 0'>
<Shape>
<Text string='"View" "# 1"'>
<FontStyle DEF='CenterJustifyjustify='"MIDDLE" "MIDDLE"'/>
</Text>
<Appearance>
<Material diffuseColor='1 0 0'/>
</Appearance>
</Shape>
</Transform>
<Transform DEF='Text2translation='-2 0 0'>
<Shape>
<Text string='"View" "# 2"'>
<FontStyle USE='CenterJustify'/>
</Text>
<Appearance>
<Material diffuseColor='0 1 0'/>
</Appearance>
</Shape>
</Transform>
<Transform DEF='Text3translation='2 0 0'>
<Shape>
<Text string='"View" "# 3"'>
<FontStyle USE='CenterJustify'/>
</Text>
<Appearance>
<Material diffuseColor='0 0 1'/>
</Appearance>
</Shape>
</Transform>
<Transform DEF='Text4translation='6 0 0'>
<Shape>
<Text string='"View" "# 4"'>
<FontStyle USE='CenterJustify'/>
</Text>
<Appearance>
<Material/>
</Appearance>
</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. it is called view5 in the Script. -->
<!-- ROUTE information for ClickToAnimateView node:  [from BindingSequencerEngine.bindView5 to set_bind ] -->
<Viewpoint DEF='ClickToAnimateViewdescription='Select animation sequenceposition='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>
<!-- ROUTE information for TextTouchSensor node:  [from touchTime to Clock.set_startTime ] -->
<TouchSensor DEF='TextTouchSensordescription='Click to begin animating viewpoint selections'/>
<!-- ROUTE information for Clock node:  [from TextTouchSensor.touchTime to set_startTime ] [from fraction_changed to TimingSequencer.set_fraction ] -->
<TimeSensor DEF='ClockcycleInterval='10'/>
<ROUTE fromNode='TextTouchSensorfromField='touchTimetoNode='ClocktoField='set_startTime'/>
<!-- ROUTE information for TimingSequencer node:  [from Clock.fraction_changed to set_fraction ] [from value_changed to BindingSequencerEngine.set_timeEvent ] -->
<IntegerSequencer DEF='TimingSequencerkey='0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 1.0keyValue='0 1 2 3 4 5 6 7 8 10'/>
<ROUTE fromNode='ClockfromField='fraction_changedtoNode='TimingSequencertoField='set_fraction'/>
<!-- ROUTE information for BindingSequencerEngine node:  [from TimingSequencer.value_changed to set_timeEvent ] [from View1.isBound to view1Bound ] [from View2.isBound to view2Bound ] [from View3.isBound to view3Bound ] [from View4.isBound to view4Bound ] [from bindView1 to View1.set_bind ] [from bindView2 to View2.set_bind ] [from bindView3 to View3.set_bind ] [from bindView4 to View4.set_bind ] [from bindView5 to ClickToAnimateView.set_bind ] -->
<Script DEF='BindingSequencerEngine'>
<field name='set_timeEventtype='SFInt32accessType='inputOnly'/>
<field name='bindView1type='SFBoolaccessType='outputOnly'/>
<field name='bindView2type='SFBoolaccessType='outputOnly'/>
<field name='bindView3type='SFBoolaccessType='outputOnly'/>
<field name='bindView4type='SFBoolaccessType='outputOnly'/>
<field name='bindView5type='SFBoolaccessType='outputOnly'/>
<field name='view1Boundtype='SFBoolaccessType='inputOnly'/>
<field name='view2Boundtype='SFBoolaccessType='inputOnly'/>
<field name='view3Boundtype='SFBoolaccessType='inputOnly'/>
<field name='view4Boundtype='SFBoolaccessType='inputOnly'/>
<field name='priorInputvaluetype='SFInt32value='-1accessType='initializeOnly'/>
<![CDATA[
        
ecmascript:

function initialize ()
{
    bindView5 = true;
    Browser.print ('Timing script 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
    if (inputValue == 0)
    {
        Browser.print ('\n===========\n time t0');
        bindView1 = true;
    }
    else if (inputValue == 1)
    {
        Browser.print ('\n===========\n time t1');
        bindView2 = true;
    }
    else if (inputValue == 2)
    {
        Browser.print ('\n===========\n time t2');
        bindView3 = true;
    }
    else if (inputValue == 3)
    {
        Browser.print ('\n===========\n time t3');
        bindView3 = false;
    }
    else if (inputValue == 4)
    {
        Browser.print ('\n===========\n time t4');
        bindView1 = true;
    }
    else if (inputValue == 5)
    {
        Browser.print ('\n===========\n time t5');
        bindView2 = false;
    }
    else if (inputValue == 6)
    {
        Browser.print ('\n===========\n time t6');
        bindView1 = false;
    }
    else if (inputValue == 7)
    {
        Browser.print ('\n===========\n time t7');
        bindView4 = true;

    }
    else if (inputValue == 8)
    {
        Browser.print ('\n===========\n time t8');
        Browser.print (', no action, all done');
        Browser.print ('\n\n');
    }
}

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 fromNode='TimingSequencerfromField='value_changedtoNode='BindingSequencerEnginetoField='set_timeEvent'/>
<!-- Script will bind and unbind Viewpoint nodes -->
<ROUTE fromNode='BindingSequencerEnginefromField='bindView1toNode='View1toField='set_bind'/>
<ROUTE fromNode='BindingSequencerEnginefromField='bindView2toNode='View2toField='set_bind'/>
<ROUTE fromNode='BindingSequencerEnginefromField='bindView3toNode='View3toField='set_bind'/>
<ROUTE fromNode='BindingSequencerEnginefromField='bindView4toNode='View4toField='set_bind'/>
<ROUTE fromNode='BindingSequencerEnginefromField='bindView5toNode='ClickToAnimateViewtoField='set_bind'/>
<!-- Viewpoint nodes report bind and unbind events -->
<ROUTE fromNode='View1fromField='isBoundtoNode='BindingSequencerEnginetoField='view1Bound'/>
<ROUTE fromNode='View2fromField='isBoundtoNode='BindingSequencerEnginetoField='view2Bound'/>
<ROUTE fromNode='View3fromField='isBoundtoNode='BindingSequencerEnginetoField='view3Bound'/>
<ROUTE fromNode='View4fromField='isBoundtoNode='BindingSequencerEnginetoField='view4Bound'/>
</Transform>
</Scene>
</X3D>
<!--

Index for DEF nodes : BindingSequencerEngine, CenterJustify, ClickToAnimateView, Clock, Text1, Text2, Text3, Text4, TextTouchSensor, TimingSequencer, View1, View2, View3, View4

Index for Viewpoint images : ClickToAnimateView, View1, View2, View3, View4
-->

<!-- Color key: <X3dNode DEF='idName' field='value'/> matches <XmlElement DEF='idName' attribute='value'/>
(Light blue background: behavior node) (Grey background: inserted documentation) (Magenta background: X3D Extensibility)
-->

<!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources and X3D Scene Authoring Hints. -->