<?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/X3Dv4/ISO-IEC19775-1v4-IS/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://www.web3d.org/x3d/content/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. -->
<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.println ('diffuseColor=(' + red +',' + green + ',' + blue + ') newColor=' + newColor.toString());
}

        
]]>
</Script>
<!-- Clock tickles Script to wake up and compute a new value -->
< ROUTE  fromNode=' MaterialModulatorScriptExpanded1' fromField='newColor' toNode=' MaterialModulatorNodeExpanded1' toField='diffuseColor'/>
<!-- ROUTE information for ModulationClockExpanded1 node:  [from cycleTime to MaterialModulatorScriptExpanded1.clockTrigger ] -->
<TimeSensor DEF='ModulationClockExpanded1cycleInterval='0.1loop='true'/>

< ROUTE  fromNode=' ModulationClockExpanded1' fromField='cycleTime' toNode=' MaterialModulatorScriptExpanded1' toField='clockTrigger'/>
</Group>
</Switch>
</Scene>
</X3D>
<!--

to top <!-- Event Graph ROUTE Table shows event connections -->
 
<!-- Index for DEF nodes: HideAdditionalPrototypeBodyNodesExpanded1, MaterialModulatorNodeExpanded1, MaterialModulatorScriptExpanded1, ModulationClockExpanded1
-->

Event Graph ROUTE Table entries with 2 ROUTE connections total, showing X3D event-model relationships for this scene.

Each row shows an event cascade that may occur during a single timestamp interval between frame renderings, as part of the X3D execution model.

ModulationClockExpanded1
TimeSensor
cycleTime
SFTime

ROUTE
event to
(1)
MaterialModulatorScriptExpanded1
Script
clockTrigger
SFTime

 
 
then
MaterialModulatorScriptExpanded1
Script
newColor
SFColor

ROUTE
event to
(2)
MaterialModulatorNodeExpanded1
Material
diffuseColor
SFColor


      MaterialModulatorScriptExpanded1
Script
newColor
SFColor

ROUTE
event to
(1)
MaterialModulatorNodeExpanded1
Material
diffuseColor
SFColor


-->

<!-- Online at
https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter14Prototypes/MaterialModulatorPrototypeExpandedIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter14Prototypes/MaterialModulatorPrototypeExpanded.x3d -->

<!-- Color legend: X3D terminology <X3dNode DEF='idName' field='value'/> matches XML terminology <XmlElement DEF='idName' attribute='value'/>
(Light-blue background: event-based behavior node or statement) (Grey background inside box: inserted documentation) (Magenta background: X3D Extensibility)
-->

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