X3D Model Documentation: MaterialTogglePrototype.x3d

  1  <?xml version="1.0" encoding="UTF-8"?>
  2 
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
  3  <X3D profile='Immersive' version='3.0 xmlns:xsd='https://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.0.xsd'>
  4       <head>
  5            <meta name='titlecontent=' MaterialTogglePrototype.x3d '/>
  6            <meta name='descriptioncontent='Prototype definition for toggle-able Material node that can switch between 2 sets of material values, selectable at run time. This prototype also demonstrates why it is important that only the first node in a ProtoBody can render: so that it can serve as a special node type (such as Material).'/>
  7            <meta name='creatorcontent='Don Brutzman and MV4205 class'/>
  8            <meta name='createdcontent='29 April 2004'/>
  9            <meta name='modifiedcontent='28 November 2019'/>
 10            <meta name='referencecontent=' MaterialToggleExample.x3d '/>
 11            <meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialTogglePrototype.x3d '/>
 12            <meta name='generatorcontent='X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit'/>
 13            <meta name='licensecontent='../../license.html'/>
 14       </head>
<!--

Event Graph ROUTE Table shows event connections.

--> <!-- to top DEF nodes index: MaterialAnimationScript, ViewedMaterialNode

Index for ProtoDeclare definition: MaterialToggle

-->
 15       <Scene>
 16            <WorldInfo title='MaterialTogglePrototype.x3d'/>
 17            <ProtoDeclare name='MaterialToggleappinfo='MaterialToggle selects one of two different Material values'>
 18                 <ProtoInterface>
 19                      <field name='set_toggletype='SFBoolaccessType='inputOnly'/>
 20                      <field name='toggletype='SFBoolvalue='falseaccessType='initializeOnlyappinfo='whether to use DefaultMaterial or ToggleMaterial'/>
 21                      <field name='toggle_changedtype='SFBoolaccessType='outputOnly'/>
 22                      <field name='defaultMaterialtype='SFNodeaccessType='initializeOnlyappinfo='Material node that is enabled when toggle=false'>
 23                           <!-- no default initialization node since it crashes Xj3D -->
 24                      </field>
 25                      <field name='toggleMaterialtype='SFNodeaccessType='initializeOnlyappinfo='Material node that is enabled when toggle=true'>
 26                           <!-- no default initialization node since it crashes Xj3D -->
 27                      </field>
 28                      <field name='set_defaultMaterialtype='SFNodeaccessType='inputOnlyappinfo='provide replacement default Material node'/>
 29                      <field name='set_toggleMaterialtype='SFNodeaccessType='inputOnlyappinfo='provide replacement toggle Material node'/>
 30                 </ProtoInterface>
 31                 <ProtoBody>
 32                      <!-- first node is node type for this prototype, other nodes are active but do not render -->
 33 
                    <!-- Material ViewedMaterialNode is a DEF node that has 1 USE node: USE_1 -->
                    <Material DEF='ViewedMaterialNode'/>
 34                      <Script DEF='MaterialAnimationScriptdirectOutput='true'>
 35                           <field name='traceEnabledtype='SFBoolvalue='falseaccessType='initializeOnly'/>
 36                           <field name='set_toggletype='SFBoolaccessType='inputOnly'/>
 37                           <field name='toggletype='SFBoolaccessType='initializeOnlyappinfo='whether to use DefaultMaterial or ToggleMaterial'/>
 38                           <field name='toggle_changedtype='SFBoolaccessType='outputOnly'/>
 39                           <field name='defaultMaterialtype='SFNodeaccessType='initializeOnly'/>
 40                           <field name='toggleMaterialtype='SFNodeaccessType='initializeOnly'/>
 41                           <field name='set_defaultMaterialtype='SFNodeaccessType='inputOnlyappinfo='provide replacement Material node'/>
 42                           <field name='set_toggleMaterialtype='SFNodeaccessType='inputOnlyappinfo='provide replacement Material node'/>
 43                           <field name='viewedMaterialtype='SFNodeaccessType='initializeOnly'>
 44                                <Material USE='ViewedMaterialNode'/>
 45                           </field>
 46                           <IS>
 47                                <connect nodeField='set_toggleprotoField='set_toggle'/>
 48                                <connect nodeField='toggleprotoField='toggle'/>
 49                                <connect nodeField='toggle_changedprotoField='toggle_changed'/>
 50                                <connect nodeField='defaultMaterialprotoField='defaultMaterial'/>
 51                                <connect nodeField='toggleMaterialprotoField='toggleMaterial'/>
 52                                <connect nodeField='set_defaultMaterialprotoField='set_defaultMaterial'/>
 53                                <connect nodeField='set_toggleMaterialprotoField='set_toggleMaterial'/>
 54                           </IS>
  <![CDATA[
          
ecmascript:

function initialize ()
{

   tracePrint ('initialize() begin...');
   if (defaultMaterial != null)
   {
	tracePrint ('defaultMaterial.diffuseColor=' + defaultMaterial.diffuseColor.toString());
	viewedMaterial.diffuseColor     = defaultMaterial.diffuseColor;
	viewedMaterial.emissiveColor    = defaultMaterial.emissiveColor;
	viewedMaterial.specularColor    = defaultMaterial.specularColor;
	viewedMaterial.shininess        = defaultMaterial.shininess;
	viewedMaterial.ambientIntensity = defaultMaterial.ambientIntensity;
	viewedMaterial.transparency     = defaultMaterial.transparency;
	tracePrint ('toggleMaterial.diffuseColor=' + toggleMaterial.diffuseColor.toString());
   }
   else alwaysPrint ('warning: no initialization Material node provided for defaultMaterial');
   if  (toggleMaterial == null)
        alwaysPrint ('warning: no initialization Material node provided for toggleMaterial');

   tracePrint ('initialize() complete');
}

function set_toggle (value, timestamp)
{
   if ((value == true) && (toggleMaterial != null))
   {
	tracePrint ('set_toggle true, toggleMaterial.diffuseColor=' + toggleMaterial.diffuseColor.toString());
	viewedMaterial.diffuseColor     = toggleMaterial.diffuseColor;
	viewedMaterial.emissiveColor    = toggleMaterial.emissiveColor;
	viewedMaterial.specularColor    = toggleMaterial.specularColor;
	viewedMaterial.shininess        = toggleMaterial.shininess;
	viewedMaterial.ambientIntensity = toggleMaterial.ambientIntensity;
	viewedMaterial.transparency     = toggleMaterial.transparency;
   }
   else if (defaultMaterial != null)
   {
	tracePrint ('set_toggle false, defaultMaterial.diffuseColor=' + defaultMaterial.diffuseColor.toString());
	viewedMaterial.diffuseColor     = defaultMaterial.diffuseColor;
	viewedMaterial.emissiveColor    = defaultMaterial.emissiveColor;
	viewedMaterial.specularColor    = defaultMaterial.specularColor;
	viewedMaterial.shininess        = defaultMaterial.shininess;
	viewedMaterial.ambientIntensity = defaultMaterial.ambientIntensity;
	viewedMaterial.transparency     = defaultMaterial.transparency;
   }
   toggle         = value; // remember state
   toggle_changed = value; // chain input boolean event to output event
   tracePrint ('set_toggle(' + value + ') complete');
}

function set_defaultMaterial(newMaterial)
{
	defaultMaterial = newMaterial;
	tracePrint('set_defaultMaterial = ' + newMaterial);
}

function set_toggleMaterial(newMaterial)
{
	toggleMaterial = newMaterial;
	tracePrint('set_toggleMaterial = ' + newMaterial);
}

function tracePrint(outputString)
{
	if (traceEnabled) Browser.println ('[MaterialToggle] ' + outputString);
}
function alwaysPrint(outputString)
{
	Browser.println ('[MaterialToggle] ' + outputString);
}

        
]]>
 56                      </Script>
 57                 </ProtoBody>
 58            </ProtoDeclare>
 59            <!-- ==================== -->
 60            <Anchor description='MaterialToggleExampleparameter='"target=_blank"'   url=' "MaterialToggleExample.x3d" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialToggleExample.x3d" "MaterialToggleExample.wrl" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialToggleExample.wrl" '>
 61                 <Shape>
 62                      <Text string='"MaterialTogglePrototype" "defines a prototype" "" "Click text to see example scene" "MaterialToggleExample"'>
 63                           <FontStyle justify='"MIDDLE" "MIDDLE"size='0.9'/>
 64                      </Text>
 65                      <Appearance>
 66                           <Material diffuseColor='1 1 0.2'/>
 67                      </Appearance>
 68                 </Shape>
 69            </Anchor>
 70       </Scene>
 71  </X3D>
<!--

Event Graph ROUTE Table shows event connections.

--> <!-- to top DEF nodes index: MaterialAnimationScript, ViewedMaterialNode

Index for ProtoDeclare definition: MaterialToggle

-->
X3D Tooltips element index: to top Anchor, Appearance, connect, field, FontStyle, head, IS, Material, meta, ProtoBody, ProtoDeclare, ProtoInterface, Scene, Script, Shape, Text, WorldInfo, X3D,
plus documentation for accessType definitions, type definitions, XML data types, and field types

🔖   Event Graph ROUTE Table with 0 ROUTE connections1 Anchor hover hint, showing X3D event-model relationships for this scene.

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

MaterialAnimationScript
Script
No direct ROUTE connection found for events to/from this node.
This node is part of the MaterialToggle ProtoDeclare prototype declaration.
Contains IS/connect fields directly connected to MaterialToggle ProtoInterface fields.
Contains SFNode fields with direct access to another node. 

line 60
Anchor
description='MaterialToggleExample' 
No direct ROUTE connection found for events to/from this node. 

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/Savage/Tools/Animation/MaterialTogglePrototypeIndex.html -->
<!-- SourceForge version control Version control at    
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialTogglePrototype.x3d -->

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

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