X3D Model Documentation: MaterialModulatorPrototypeExpanded.x3d

  1  <?xml version="1.0" encoding="UTF-8"?>
  2  <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "https://www.web3d.org/specifications/x3d-3.3.dtd">
  3  <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'>
  4       <head>
  5            <meta name='titlecontent='MaterialModulatorPrototypeExpanded.x3d'/>
  6            <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.'/>
  7            <meta name='creatorcontent='Don Brutzman, John Carlson, Roy Walmsley'/>
  8            <meta name='createdcontent='2 July 2016'/>
  9            <meta name='modifiedcontent='20 October 2019'/>
 10            <meta name='subjectcontent='X3D prototype expander, IS/connect, Script inputOutput field'/>
 11            <meta name='Imagecontent='MaterialModulator.png'/>
 12            <meta name='referencecontent='MaterialModulator.x3d'/>
 13            <meta name='referencecontent='JSON prototype expander https://github.com/coderextreme/X3DJSONLD'/>
 14            <meta name=' TODO content=' Create corresponding web page describing Prototype Expander design. '/>
 15            <meta name=' TODO content=' Create stylesheet converter matching this Prototype Expander design pattern. '/>
 16            <meta name=' TODO content=' Add external ROUTEs to original example as a further test case for Prototype Expander design. '/>
 17            <meta name='referencecontent='https://github.com/coderextreme/X3DJSONLD/blob/master/PrototypeExpander.js'/>
 18            <meta name='referencecontent='https://github.com/coderextreme/X3DJSONLD/blob/master/ServerPrototypeExpander.js'/>
 19            <meta name='referencecontent='X3D Tooltips: ProtoBody https://www.web3d.org/x3d/content/X3dTooltips.html#ProtoBody'/>
 20            <meta name='referencecontent='4.4.4.3 PROTO definition semantics https://www.web3d.org/specifications/X3Dv4/ISO-IEC19775-1v4-IS/Part01/concepts.html#PROTOdefinitionsemantics'/>
 21            <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'/>
 22            <meta name='identifiercontent='https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter14Prototypes/MaterialModulatorPrototypeExpanded.x3d'/>
 23            <meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
 24            <meta name='licensecontent='../license.html'/>
 25       </head>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->

<!-- to top Index for DEF nodes: HideAdditionalPrototypeBodyNodesExpanded1, MaterialModulatorNodeExpanded1, MaterialModulatorScriptExpanded1, ModulationClockExpanded1
-->
 26       <Scene>
 27            <WorldInfo title='MaterialModulatorPrototypeExpanded.x3d'/>
 28            <Shape>
 29                 <Sphere/>
 30                 <Appearance>
 31                      <!-- Prototype Expander design note: only first node (the node type) of the prototype is substituted here. -->
 32 
                    <!-- ROUTE information for MaterialModulatorNodeExpanded1 node:  [from MaterialModulatorScriptExpanded1.newColor to diffuseColor ] -->
                    <Material DEF='MaterialModulatorNodeExpanded1diffuseColor='0.5 0.1 0.1'>
 33                           <!-- Prototype Expander design note: no children nodes found in originally defined initial ProtoBody node, so no contained child nodes appear here -->
 34                      </Material>
 35                 </Appearance>
 36            </Shape>
 37            <!-- Prototype Expander design note: only first node (the node type) of the prototype is renderable above. when Switch is first allowed -->
 38            <Switch DEF='HideAdditionalPrototypeBodyNodesExpanded1whichChoice='-1'>
 39                 <!-- Prototype Expander design note: all children inside a Switch continue to receive/send events. -->
 40                 <Group>
 41                      <!-- Prototype Expander design note: additional follow-on nodes from the original ProtoBody are placed here. -->
 42 
                    <!-- ROUTE information for MaterialModulatorScriptExpanded1 node:  [from ModulationClockExpanded1.cycleTime to clockTrigger ] [from newColor to MaterialModulatorNodeExpanded1.diffuseColor ] -->
                    <Script DEF='MaterialModulatorScriptExpanded1'>
 43                           <field name='enabledtype='SFBoolvalue='trueaccessType='inputOutput'/>
 44                           <field name='diffuseColortype='SFColorvalue='0.5 0.1 0.1accessType='inputOutput'/>
 45                           <field name='newColortype='SFColoraccessType='outputOnly'/>
 46                           <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());
}

        
]]>
 48                      </Script>
 49                      <!-- Clock tickles Script to wake up and compute a new value -->
 50                      < ROUTE  fromNode='MaterialModulatorScriptExpanded1' fromField='newColor' toNode='MaterialModulatorNodeExpanded1' toField='diffuseColor'/>
 51 
                    <!-- ROUTE information for ModulationClockExpanded1 node:  [from cycleTime to MaterialModulatorScriptExpanded1.clockTrigger ] -->
                    <TimeSensor DEF='ModulationClockExpanded1cycleInterval='0.1loop='true'/>
 52                      < ROUTE  fromNode='ModulationClockExpanded1' fromField='cycleTime' toNode='MaterialModulatorScriptExpanded1' toField='clockTrigger'/>
 53                 </Group>
 54            </Switch>
 55       </Scene>
 56  </X3D>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->

<!-- to top Index for DEF nodes: HideAdditionalPrototypeBodyNodesExpanded1, MaterialModulatorNodeExpanded1, MaterialModulatorScriptExpanded1, ModulationClockExpanded1
-->
X3D Tooltips element index: Appearance, field, Group, head, Material, meta, ROUTE, Scene, Script, Shape, Sphere, Switch, TimeSensor, WorldInfo, X3D, accessType and type, XML data types, field types

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
Additional guidance on X3D animation can be found in the 10-Step Animation Design Process and Event Tracing hint sheets. Have fun with X3D! 😀

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