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='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.0.xsd'> |
4 | <head> |
5 | <meta name='title' content=' MaterialTogglePrototype.x3d '/> |
6 | <meta name='description' content='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='creator' content='Don Brutzman and MV4205 class'/> |
8 | <meta name='created' content='29 April 2004'/> |
9 | <meta name='modified' content='28 November 2019'/> |
10 | <meta name='reference' content=' MaterialToggleExample.x3d '/> |
11 | <meta name='identifier' content=' https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialTogglePrototype.x3d '/> |
12 | <meta name='generator' content='X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit'/> |
13 | <meta name='license' content='../../license.html'/> |
14 | </head> |
15 | <Scene> |
16 | <WorldInfo title='MaterialTogglePrototype.x3d'/> |
17 | <ProtoDeclare name='MaterialToggle' appinfo='MaterialToggle selects one of two different Material values'> |
18 | <ProtoInterface> |
19 | <field name='set_toggle' type='SFBool' accessType='inputOnly'/> |
20 |
<field name='toggle' type='SFBool' value='false' accessType='initializeOnly'
appinfo='whether to use DefaultMaterial or ToggleMaterial'/> |
21 | <field name='toggle_changed' type='SFBool' accessType='outputOnly'/> |
22 |
<field name='defaultMaterial' type='SFNode' accessType='initializeOnly'
appinfo='Material node that is enabled when toggle=false'> |
23 | <!-- no default initialization node since it crashes Xj3D --> |
24 | </field> |
25 |
<field name='toggleMaterial' type='SFNode' accessType='initializeOnly'
appinfo='Material node that is enabled when toggle=true'> |
26 | <!-- no default initialization node since it crashes Xj3D --> |
27 | </field> |
28 |
<field name='set_defaultMaterial' type='SFNode' accessType='inputOnly'
appinfo='provide replacement default Material node'/> |
29 |
<field name='set_toggleMaterial' type='SFNode' accessType='inputOnly'
appinfo='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='MaterialAnimationScript' directOutput='true'> |
35 | <field name='traceEnabled' type='SFBool' value='false' accessType='initializeOnly'/> |
36 | <field name='set_toggle' type='SFBool' accessType='inputOnly'/> |
37 |
<field name='toggle' type='SFBool' accessType='initializeOnly'
appinfo='whether to use DefaultMaterial or ToggleMaterial'/> |
38 | <field name='toggle_changed' type='SFBool' accessType='outputOnly'/> |
39 | <field name='defaultMaterial' type='SFNode' accessType='initializeOnly'/> |
40 | <field name='toggleMaterial' type='SFNode' accessType='initializeOnly'/> |
41 |
<field name='set_defaultMaterial' type='SFNode' accessType='inputOnly'
appinfo='provide replacement Material node'/> |
42 |
<field name='set_toggleMaterial' type='SFNode' accessType='inputOnly'
appinfo='provide replacement Material node'/> |
43 | <field name='viewedMaterial' type='SFNode' accessType='initializeOnly'> |
44 | <Material USE='ViewedMaterialNode'/> |
45 | </field> |
46 | <IS> |
47 | <connect nodeField='set_toggle' protoField='set_toggle'/> |
48 | <connect nodeField='toggle' protoField='toggle'/> |
49 | <connect nodeField='toggle_changed' protoField='toggle_changed'/> |
50 | <connect nodeField='defaultMaterial' protoField='defaultMaterial'/> |
51 | <connect nodeField='toggleMaterial' protoField='toggleMaterial'/> |
52 | <connect nodeField='set_defaultMaterial' protoField='set_defaultMaterial'/> |
53 | <connect nodeField='set_toggleMaterial' protoField='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='MaterialToggleExample' parameter='"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 with 0 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.
MaterialAnimationScript
Script |
No direct ROUTE connection found for events to/from this node. Contains SFNode fields with direct access to another node. |
line 60
Anchor |
description='MaterialToggleExample' User-interaction hint for this node. |
<!--
Color-coding 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)
<ProtoDeclare name='ProtoName'>
<field
name='fieldName'/> </ProtoDeclare>
-->
<!--
For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints.
-->