<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D profile='Immersive' version='3.0 xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation =' http://www.web3d.org/specifications/x3d-3.0.xsd '>
<head>
<meta name='titlecontent='MaterialChoiceExample.x3d'/>
<meta name='descriptioncontent='Example for toggle-able Material node that can choose among an array of material nodes, and is switchable at run time.'/>
<meta name='creatorcontent='Don Brutzman and MV4205 class'/>
<meta name='createdcontent='2 May 2004'/>
<meta name='modifiedcontent='14 January 2014'/>
<meta name='referencecontent='MaterialChoicePrototype.x3d'/>
<meta name='identifiercontent=' https://savage.nps.edu/Savage/Tools/Animation/MaterialChoiceExample.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../../license.html'/>
</head>
<!-- -->
<Scene>
<ExternProtoDeclare name='MaterialChoice'
  url=' "MaterialChoicePrototype.x3d#MaterialChoice" "https://savage.nps.edu/Savage/Tools/Animation/MaterialChoicePrototype.x3d#MaterialChoice" "MaterialChoicePrototype.wrl#MaterialChoice" "https://savage.nps.edu/Savage/Tools/Animation/MaterialChoicePrototype.wrl#MaterialChoice" '>
<field name='set_indextype='SFInt32accessType='inputOnly'/>
<field name='indextype='SFInt32accessType='initializeOnly'
 appinfo='which Material node is chosen, with array index starting at 0'/>

<field name='index_changedtype='SFInt32accessType='outputOnly'/>
<field name='set_fractiontype='SFFloataccessType='inputOnly'/>
<field name='fractiontype='SFFloataccessType='initializeOnly'
 appinfo='fraction to interpolate between current and next Material node (if any) across all field values.'/>

<field name='nexttype='SFBoolaccessType='inputOnly'/>
<field name='previoustype='SFBoolaccessType='inputOnly'/>
<field name='materialstype='MFNodeaccessType='initializeOnly'
 appinfo='array of available Material nodes defaults to zeroth Material'/>

<field name='appendMaterialtype='SFNodeaccessType='inputOnly'
 appinfo='append another Material node to materials array'/>

<field name='deleteMaterialtype='SFInt32accessType='inputOnly'
 appinfo='delete Material node indicated by input index value'/>

<field name='deleteAllMaterialstype='SFBoolaccessType='inputOnly'
 appinfo='deletes all Material nodes resets scene to default Material values defined in X3D Specification'/>
</ExternProtoDeclare>
<!-- ==================== -->
<Viewpoint description='MaterialChoice index is sequenced to change selected Material valueposition='0 0 6'/>
<Transform DEF='RotateBoxrotation='1 0 0 0.79'>
<Transform rotation='0 1 0 0.79'>
<Shape>
<Box/>
<Appearance>
<!-- ROUTE information for MC node:  [from TriggerNext.triggerTrue to next ] [from TouchNext.isActive to next ] [from TouchPrevious.isActive to previous ] [from AddNewMaterialScript.newMaterial to appendMaterial ] [from TouchDelete0Trigger.triggerValue to deleteMaterial ] [from TouchDelete2Trigger.triggerValue to deleteMaterial ] [from TouchDelete1Trigger.triggerValue to deleteMaterial ] [from TouchDeleteAll.isActive to deleteAllMaterials ] -->
<ProtoInstance name='MaterialChoiceDEF='MCcontainerField='material'>
<fieldValue name='indexvalue='0'/>
<fieldValue name='fractionvalue='0.0'/>
<fieldValue name='materials'>
<Material ambientIntensity='0.24diffuseColor='1 0.452381 0.40339shininess='0.9specularColor='0.686486 0.396903 0.419275'>
<!-- Universal Media Library: ArtDeco 3 -->
</Material>
<Material ambientIntensity='0.24diffuseColor='0.330519 0.3389 0.6shininess='0.78specularColor='0.290909 0.290909 0.290909'>
<!-- Universal Media Library: ArtDeco 8 -->
</Material>
<Material ambientIntensity='0.25diffuseColor='0 0.251004 0.239248shininess='0.06specularColor='0.177935 0.249369 0.229278'>
<!-- Universal Media Library: ArtDeco 19 -->
</Material>
</fieldValue>
</ProtoInstance>
</Appearance>
</Shape>
</Transform>
</Transform>
<!-- other tests -->
<Group DEF='AnimationGroup'>
<!-- Animate the MaterialChoice automatically -->
<!-- ROUTE information for Clock node:  [from ClockStopperFilter.inputNegate to enabled ] [from ToggleLoop.toggle_changed to enabled ] [from cycleTime to TriggerNext.set_triggerTime ] -->
<TimeSensor DEF='ClockcycleInterval='2enabled='falseloop='true'/>
<!-- ROUTE information for TriggerNext node:  [from Clock.cycleTime to set_triggerTime ] [from triggerTrue to MC.next ] -->
<BooleanTrigger DEF='TriggerNext'/>
<ROUTE fromNode='ClockfromField='cycleTimetoNode='TriggerNexttoField='set_triggerTime'/>
<ROUTE fromNode='TriggerNextfromField='triggerTruetoNode='MCtoField='next'/>
<!-- iff another action starts (i.e. touch true), then negate value and stop clock -->
<!-- ROUTE information for ClockStopper node:  [from TouchNext.isActive to set_boolean ] [from TouchPrevious.isActive to set_boolean ] [from TouchAppend.isActive to set_boolean ] [from TouchDelete0.isActive to set_boolean ] [from TouchDelete2.isActive to set_boolean ] [from TouchDelete1.isActive to set_boolean ] [from TouchDeleteAll.isActive to set_boolean ] [from inputTrue to ClockStopperFilter.set_boolean ] -->
<BooleanFilter DEF='ClockStopper'/>
<!-- ROUTE information for ClockStopperFilter node:  [from ClockStopper.inputTrue to set_boolean ] [from inputNegate to Clock.enabled ] -->
<BooleanFilter DEF='ClockStopperFilter'/>
<ROUTE fromNode='ClockStopperfromField='inputTruetoNode='ClockStopperFiltertoField='set_boolean'/>
<ROUTE fromNode='ClockStopperFilterfromField='inputNegatetoNode='ClocktoField='enabled'/>
</Group>
<Transform DEF='TestNexttranslation='-2.5 2 0'>
<Billboard axisOfRotation='0 0 0'>
<Shape>
<Text string='"next"'>
<FontStyle DEF='FSsize='0.6'/>
</Text>
<Appearance>
<Material diffuseColor='0 0.9 0'/>
</Appearance>
</Shape>
<!-- ROUTE information for TouchNext node:  [from isActive to ClockStopper.set_boolean ] [from isActive to MC.next ] -->
<TouchSensor DEF='TouchNextdescription='touch for next Material'/>
<ROUTE fromNode='TouchNextfromField='isActivetoNode='ClockStoppertoField='set_boolean'/>
<ROUTE fromNode='TouchNextfromField='isActivetoNode='MCtoField='next'/>
</Billboard>
</Transform>
<Transform DEF='TestPrevioustranslation='1 2 0'>
<Billboard axisOfRotation='0 0 0'>
<Shape>
<Text string='"previous"'>
<FontStyle USE='FS'/>
</Text>
<Appearance>
<Material diffuseColor='0.9 0 0'/>
</Appearance>
</Shape>
<!-- ROUTE information for TouchPrevious node:  [from isActive to ClockStopper.set_boolean ] [from isActive to MC.previous ] -->
<TouchSensor DEF='TouchPreviousdescription='touch for previous Material'/>
<ROUTE fromNode='TouchPreviousfromField='isActivetoNode='ClockStoppertoField='set_boolean'/>
<ROUTE fromNode='TouchPreviousfromField='isActivetoNode='MCtoField='previous'/>
</Billboard>
</Transform>
<Transform DEF='TestLooptranslation='-3 -2 0'>
<Billboard axisOfRotation='0 0 0'>
<Shape>
<Text string='"loop"'>
<FontStyle USE='FS'/>
</Text>
<Appearance>
<Material diffuseColor='0 0 0.9'/>
</Appearance>
</Shape>
<!-- ROUTE information for TouchLoop node:  [from isActive to ToggleLoop.set_boolean ] -->
<TouchSensor DEF='TouchLoopdescription='touch to loop through Materials'/>
<!-- ROUTE information for ToggleLoop node:  [from TouchLoop.isActive to set_boolean ] [from toggle_changed to Clock.enabled ] -->
<BooleanToggle DEF='ToggleLoop'/>
<ROUTE fromNode='TouchLoopfromField='isActivetoNode='ToggleLooptoField='set_boolean'/>
<ROUTE fromNode='ToggleLoopfromField='toggle_changedtoNode='ClocktoField='enabled'/>
</Billboard>
</Transform>
<Transform DEF='TestAppendtranslation='1 -2 0'>
<Billboard axisOfRotation='0 0 0'>
<Shape>
<Text string='"append"'>
<FontStyle USE='FS'/>
</Text>
<Appearance>
<Material diffuseColor='0.6 0.6 0'/>
</Appearance>
</Shape>
<!-- ROUTE information for TouchAppend node:  [from isActive to ClockStopper.set_boolean ] [from isActive to AddNewMaterialScript.generateAndAppendMaterial ] -->
<TouchSensor DEF='TouchAppenddescription='touch to add a new Material'/>
<!-- ROUTE information for AddNewMaterialScript node:  [from TouchAppend.isActive to generateAndAppendMaterial ] [from newMaterial to MC.appendMaterial ] -->
<Script DEF='AddNewMaterialScriptdirectOutput='true'>
<field name='generateAndAppendMaterialtype='SFBoolaccessType='inputOnly'/>
<field name='newMaterialtype='SFNodeaccessType='outputOnly'/>
<field name='defaultMaterialtype='SFNodeaccessType='initializeOnly'>
<Material/>
</field>
<field name='traceEnabledtype='SFBoolvalue='falseaccessType='initializeOnly'/>
<![CDATA[
          
ecmascript:

function initialize ()
{
	if (traceEnabled) Browser.print ('[ MaterialChoiceExample ] AddNewMaterialScript.initialize()');
}

function generateAndAppendMaterial(trigger, timestamp)
{
   if (trigger == true)
   {
	if (traceEnabled) Browser.print ('[MaterialChoiceExample AddNewMaterialScript] generateAndAppendMaterial(' + trigger + ')');
	newColor = new SFColor (Math.random(), Math.random(), Math.random());
	defaultMaterial.diffuseColor = newColor;
	newMaterial = defaultMaterial;
	if (traceEnabled) Browser.print ('[ MaterialChoiceExample AddNewMaterialScript] append Material with diffuseColor (' + newColor + ')');
   }
}

        
]]>
</Script>
<ROUTE fromNode='TouchAppendfromField='isActivetoNode='ClockStoppertoField='set_boolean'/>
<ROUTE fromNode='TouchAppendfromField='isActivetoNode='AddNewMaterialScripttoField='generateAndAppendMaterial'/>
<ROUTE fromNode='AddNewMaterialScriptfromField='newMaterialtoNode='MCtoField='appendMaterial'/>
</Billboard>
</Transform>
<Transform DEF='TestDeleteOnetranslation='-3 0 0'>
<Transform>
<Billboard axisOfRotation='0 0 0'>
<Shape>
<Text string='"delete"'>
<FontStyle USE='FS'/>
</Text>
<Appearance>
<Material/>
</Appearance>
</Shape>
</Billboard>
</Transform>
<Transform DEF='TestDelete0translation='0 -0.5 0'>
<Billboard axisOfRotation='0 0 0'>
<Shape>
<Text string='"0"'>
<FontStyle USE='FS'/>
</Text>
<Appearance>
<Material/>
</Appearance>
</Shape>
</Billboard>
<!-- ROUTE information for TouchDelete0 node:  [from isActive to ClockStopper.set_boolean ] [from isActive to TouchDelete0Trigger.set_boolean ] -->
<TouchSensor DEF='TouchDelete0description='touch to delete Material[0]'/>
<!-- ROUTE information for TouchDelete0Trigger node:  [from TouchDelete0.isActive to set_boolean ] [from triggerValue to MC.deleteMaterial ] -->
<IntegerTrigger DEF='TouchDelete0TriggerintegerKey='0'/>
<ROUTE fromNode='TouchDelete0fromField='isActivetoNode='ClockStoppertoField='set_boolean'/>
<ROUTE fromNode='TouchDelete0fromField='isActivetoNode='TouchDelete0TriggertoField='set_boolean'/>
<ROUTE fromNode='TouchDelete0TriggerfromField='triggerValuetoNode='MCtoField='deleteMaterial'/>
</Transform>
<Transform DEF='TestDelete1translation='0.5 -0.5 0'>
<Billboard axisOfRotation='0 0 0'>
<Shape>
<Text string='"1"'>
<FontStyle USE='FS'/>
</Text>
<Appearance>
<Material/>
</Appearance>
</Shape>
</Billboard>
<!-- ROUTE information for TouchDelete2 node:  [from isActive to ClockStopper.set_boolean ] [from isActive to TouchDelete2Trigger.set_boolean ] -->
<TouchSensor DEF='TouchDelete2description='touch to delete Material[1]'/>
<!-- ROUTE information for TouchDelete2Trigger node:  [from TouchDelete2.isActive to set_boolean ] [from triggerValue to MC.deleteMaterial ] -->
<IntegerTrigger DEF='TouchDelete2TriggerintegerKey='1'/>
<ROUTE fromNode='TouchDelete2fromField='isActivetoNode='ClockStoppertoField='set_boolean'/>
<ROUTE fromNode='TouchDelete2fromField='isActivetoNode='TouchDelete2TriggertoField='set_boolean'/>
<ROUTE fromNode='TouchDelete2TriggerfromField='triggerValuetoNode='MCtoField='deleteMaterial'/>
</Transform>
<Transform DEF='TestDelete2translation='1 -0.5 0'>
<Billboard axisOfRotation='0 0 0'>
<Shape>
<Text string='"2"'>
<FontStyle USE='FS'/>
</Text>
<Appearance>
<Material/>
</Appearance>
</Shape>
</Billboard>
<!-- ROUTE information for TouchDelete1 node:  [from isActive to ClockStopper.set_boolean ] [from isActive to TouchDelete1Trigger.set_boolean ] -->
<TouchSensor DEF='TouchDelete1description='touch to delete Material[2]'/>
<!-- ROUTE information for TouchDelete1Trigger node:  [from TouchDelete1.isActive to set_boolean ] [from triggerValue to MC.deleteMaterial ] -->
<IntegerTrigger DEF='TouchDelete1TriggerintegerKey='1'/>
<ROUTE fromNode='TouchDelete1fromField='isActivetoNode='ClockStoppertoField='set_boolean'/>
<ROUTE fromNode='TouchDelete1fromField='isActivetoNode='TouchDelete1TriggertoField='set_boolean'/>
<ROUTE fromNode='TouchDelete1TriggerfromField='triggerValuetoNode='MCtoField='deleteMaterial'/>
</Transform>
</Transform>
<Transform DEF='TestDeleteAlltranslation='1.8 0 0'>
<Billboard axisOfRotation='0 0 0'>
<Shape>
<Text string='"delete" " all"'>
<FontStyle USE='FS'/>
</Text>
<Appearance>
<Material/>
</Appearance>
</Shape>
<!-- ROUTE information for TouchDeleteAll node:  [from isActive to ClockStopper.set_boolean ] [from isActive to MC.deleteAllMaterials ] -->
<TouchSensor DEF='TouchDeleteAlldescription='touch to delete all Materials'/>
<ROUTE fromNode='TouchDeleteAllfromField='isActivetoNode='ClockStoppertoField='set_boolean'/>
<ROUTE fromNode='TouchDeleteAllfromField='isActivetoNode='MCtoField='deleteAllMaterials'/>
</Billboard>
</Transform>
</Scene>
</X3D>
<!--

Index for ExternProtoDeclare definition : MaterialChoice

Index for DEF nodes : AddNewMaterialScript, AnimationGroup, Clock, ClockStopper, ClockStopperFilter, FS, MC, RotateBox, TestAppend, TestDelete0, TestDelete1, TestDelete2, TestDeleteAll, TestDeleteOne, TestLoop, TestNext, TestPrevious, ToggleLoop, TouchAppend, TouchDelete0, TouchDelete0Trigger, TouchDelete1, TouchDelete1Trigger, TouchDelete2, TouchDelete2Trigger, TouchDeleteAll, TouchLoop, TouchNext, TouchPrevious, TriggerNext

Index for Viewpoint image : Viewpoint_1
-->

<!-- 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)
    <Prototype name='ProtoName'> <field name='fieldName'/> </Prototype> -->

<!-- Additional help information about X3D scenes: X3D Resources, X3D Scene Authoring Hints and X3D Tooltips -->