<head>
<meta name='title' content='MaterialModulator.x3d'/>
<meta name='description' content='Mimic a Material node and modulate the diffuseColor field as an animation effect, provided as a prototype for reusability.'/>
<meta name='hint' content='Learning suggestion for authors: try changing the modulation script so that it goes from [0 ... 1] and then [1 ... 0] alternating, rather than abruptly shifting from 1 immediately back to 0.'/>
<meta name='creator' content='Don Brutzman'/>
<meta name='created' content='10 March 2008'/>
<meta name='modified' content='20 October 2019'/>
<meta name='subject' content='X3D prototype requiring Script inputOutput fields'/>
<meta name='Image' content='MaterialModulator.png'/>
<meta name='identifier' content='
https://X3dGraphics.com/examples/X3dForWebAuthors/Chapter14Prototypes/MaterialModulator.x3d
'/>
<meta name='generator' content='X3D-Edit 3.3,
https://savage.nps.edu/X3D-Edit'/>
<meta name='license' content='
../license.html'/>
</head>
<!--
-->
<Scene>
<WorldInfo title='MaterialModulator.x3d'/>
<ProtoDeclare name='MaterialModulator' appinfo='mimic a Material node and modulate the diffuseColor field as an animation effect' documentation='
https://x3dgraphics.com/examples/X3dForWebAuthors/Chapter14Prototypes/MaterialModulatorIndex.html
'>
<ProtoInterface>
<field name='enabled' type='SFBool' value='true' accessType='inputOutput'
appinfo='default value true'/>
<field name='diffuseColor' type='SFColor' value='0.8 0.8 0.8' accessType='inputOutput'
appinfo='default value 0.8 0.8 0.8'/>
<field name='emissiveColor' type='SFColor' value='0 0 0' accessType='inputOutput'
appinfo='default value 0 0 0'/>
<field name='specularColor' type='SFColor' value='0 0 0' accessType='inputOutput'
appinfo='default value 0 0 0'/>
<field name='transparency' type='SFFloat' value='0.0' accessType='inputOutput'
appinfo='default value 0.0'/>
<field name='shininess' type='SFFloat' value='0.2' accessType='inputOutput'
appinfo='default value 0.2'/>
<field name='ambientIntensity' type='SFFloat' value='0.2' accessType='inputOutput'
appinfo='default value 0.2'/>
</ProtoInterface>
<ProtoBody>
<![CDATA[
ecmascript:
function initialize ()
{
newColor = diffuseColor; // start with original 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);
if (enabled)
{
Browser.print ('diffuseColor=(' + red +',' + green + ',' + blue + ') newColor=' + newColor.toString() + '\n');
}
}
function set_enabled (newValue)
{
enabled = newValue;
}
]]>
</ProtoDeclare>
<!-- Rendered geometry for the ProtoInstance now follows prototype declaration -->
<Transform translation='0 1 0'>
<Shape>
<Sphere/>
<Appearance>
<!-- ROUTE information for MaterialModulatorInstance node:
[from EventToggler.toggle to enabled
]
-->
<ProtoInstance name='MaterialModulator' DEF='MaterialModulatorInstance' containerField='material'>
<fieldValue name='enabled' value='true'/>
<fieldValue name='diffuseColor' value='0.5 0.1 0.1'/>
<!-- fieldValue declarations for other Material attributes can appear here -->
</ProtoInstance>
</Appearance>
</Shape>
</Transform>
<!-- Selectable Text design pattern has transparent Box and TouchSensor description as a tooltip -->
<Transform translation='0 -2 0'>
</Transform>
</Scene>