<?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='MaterialModulatorPrototypeExpanded.x3d'/>
<meta name='descriptioncontent='Provide example for expansion of a MaterialModulator as regular X3D nodes, rather than a ProtoDeclare/ProtoInstance combination. MaterialModulator mimics a Material node and modulates diffuseColor field as an animation effect.'/>
<meta name='creatorcontent='Don Brutzman, John Carlson, Roy Walmsley'/>
<meta name='createdcontent='2 July 2016'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='subjectcontent='X3D prototype expander, IS/connect, Script inputOutput field'/>
<meta name='Imagecontent='MaterialModulator.png'/>
<meta name='referencecontent='MaterialModulator.x3d'/>
<meta name='referencecontent=' JSON prototype expander https://github.com/coderextreme/X3DJSONLD '/>
<meta name=' TODO content=' Create corresponding web page describing Prototype Expander design. '/>
<meta name=' TODO content=' Create stylesheet converter matching this Prototype Expander design pattern. '/>
<meta name=' TODO content=' Add external ROUTEs to original example as a further test case for Prototype Expander design. '/>
<meta name='referencecontent=' https://github.com/coderextreme/X3DJSONLD/blob/master/PrototypeExpander.js '/>
<meta name='referencecontent=' https://github.com/coderextreme/X3DJSONLD/blob/master/ServerPrototypeExpander.js '/>
<meta name='referencecontent=' X3D Tooltips: ProtoBody https://www.web3d.org/x3d/content/X3dTooltips.html#ProtoBody '/>
<meta name='referencecontent=' 4.4.4.3 PROTO definition semantics https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19775-1v4-IS.proof/Part01/concepts.html#PROTOdefinitionsemantics '/>
<meta name='referencecontent=' [x3d-public] Prototype Expander, Question on design of instance expansions: http://web3d.org/pipermail/x3d-public_web3d.org/2016-July/004982.html '/>
<meta name='identifiercontent=' https://X3dGraphics.com/examples/X3dForWebAuthors/Chapter14Prototypes/MaterialModulatorPrototypeExpanded.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../license.html'/>
</head>
<!-- -->
<Scene>
<WorldInfo title='MaterialModulatorPrototypeExpanded.x3d'/>
<Shape>
<Sphere/>
<Appearance>
<!-- Prototype Expander design note: only first node (the node type) of the prototype is substituted here. -->
<!-- ROUTE information for MaterialModulatorNodeExpanded1 node:  [from MaterialModulatorScriptExpanded1.newColor to diffuseColor ] -->
<Material DEF='MaterialModulatorNodeExpanded1diffuseColor='0.5 0.1 0.1'>
<!-- Prototype Expander design note: no children nodes found in originally defined initial ProtoBody node, so no contained child nodes appear here -->
</Material>
</Appearance>
</Shape>
<!-- Prototype Expander design note: only first node (the node type) of the prototype is renderable above. when Switch is first allowed -->
<Switch DEF='HideAdditionalPrototypeBodyNodesExpanded1whichChoice='-1'>
<!-- Prototype Expander design note: all children inside a Switch continue to receive/send events. -->
<Group>
<!-- Prototype Expander design note: additional follow-on nodes from the original ProtoBody are placed here. -->
<!-- ROUTE information for MaterialModulatorScriptExpanded1 node:  [from ModulationClockExpanded1.cycleTime to clockTrigger ] [from newColor to MaterialModulatorNodeExpanded1.diffuseColor ] -->
<Script DEF='MaterialModulatorScriptExpanded1'>
<field name='enabledtype='SFBoolvalue='trueaccessType='inputOutput'/>
<field name='diffuseColortype='SFColorvalue='0.5 0.1 0.1accessType='inputOutput'/>
<field name='newColortype='SFColoraccessType='outputOnly'/>
<field name='clockTriggertype='SFTimeaccessType='inputOnly'/>
<![CDATA[
          
ecmascript:
function initialize ()
{
    newColor = diffuseColor; // start with correct color
}
function clockTrigger (timeValue)
{
    if (!enabled) return;
    red   = newColor.r;
    green = newColor.g;
    blue  = newColor.b;
    
    // note different modulation rates for each color component, % is modulus operator
    newColor = new SFColor ((red + 0.02) % 1, (green + 0.03) % 1, (blue + 0.04) % 1);   
    Browser.print ('diffuseColor=(' + red +',' + green + ',' + blue + ') newColor=' + newColor.toString() + '\n');
}

        
]]>
</Script>
<!-- Clock tickles Script to wake up and compute a new value -->
<ROUTE fromNode='MaterialModulatorScriptExpanded1fromField='newColortoNode='MaterialModulatorNodeExpanded1toField='diffuseColor'/>
<!-- ROUTE information for ModulationClockExpanded1 node:  [from cycleTime to MaterialModulatorScriptExpanded1.clockTrigger ] -->
<TimeSensor DEF='ModulationClockExpanded1cycleInterval='0.1loop='true'/>
<ROUTE fromNode='ModulationClockExpanded1fromField='cycleTimetoNode='MaterialModulatorScriptExpanded1toField='clockTrigger'/>
</Group>
</Switch>
</Scene>
</X3D>
<!--

Index for DEF nodes : HideAdditionalPrototypeBodyNodesExpanded1, MaterialModulatorNodeExpanded1, MaterialModulatorScriptExpanded1, ModulationClockExpanded1
-->

<!-- 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. -->