[x3d-public] Proto expander. Scripts in protobodies without a DEF

John Carlson yottzumm at gmail.com
Thu Jul 14 17:41:45 PDT 2016


Here’s the MaterialModulatorPrototypeExpanded.x3d from my code.  Please try in all browsers.  I think there’s  a problem with the BooleanToggle—there’s no toggle in X3DOM or Cobweb.  I wll test in some browsers.

John

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "http://www.web3d.org/specifications/x3d-3.3.dtd">
<X3D  profile="Immersive" version="3.3" ><head><meta name="title" content="MaterialModulator.x3d"></meta>
<meta name="description" content="Mimic a Material node and modulate fields as an animation effect"></meta>
<meta name="hint" content="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>
<meta name="creator" content="Don Brutzman"></meta>
<meta name="created" content="10 March 2008"></meta>
<meta name="modified" content="28 November 2014"></meta>
<meta name="subject" content="X3D prototype requiring Script inputOutput fields"></meta>
<meta name="Image" content="MaterialModulator.png"></meta>
<meta name="identifier" content="http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter14-Prototypes/MaterialModulator.x3d"></meta>
<meta name="generator" content="X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"></meta>
<meta name="license" content="../license.html"></meta>
</head>
<Scene><!--Rendered geometry for the ProtoInstance now follows prototype declaration--><Transform translation="0 1 0"><Shape><Sphere containerField="geometry"></Sphere>
<Appearance containerField="appearance"><Material containerField="material" DEF="DECLMaterialModulator_MaterialModulatorInstance_MaterialNode" diffuseColor="0.5 0.1 0.1" emissiveColor="0 0 0" specularColor="0 0 0" transparency="0" shininess="0.2" ambientIntensity="0.2"></Material>
</Appearance>
</Shape>
<Switch whichChoice="-1"><Group><!--Only first node (the node type) is renderable, others are along for the ride--><Script DEF="DECLMaterialModulator_MaterialModulatorInstance_MaterialModulatorScript"><field name="enabled" accessType="inputOutput" type="SFBool" value="true"></field>
<field name="diffuseColor" accessType="inputOutput" type="SFColor" value="0.5 0.1 0.1"></field>
<field name="newColor" accessType="outputOnly" type="SFColor"></field>
<field name="clockTrigger" accessType="inputOnly" type="SFTime"></field>
<![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);
	if (enabled)
	{
		Browser.print ('diffuseColor=(' + red +',' + green + ',' + blue + ') newColor=' + newColor.toString() + '\');
	}
}
]]></Script>
<!--Clock tickles Script to wake up and compute a new value--><ROUTE fromNode="DECLMaterialModulator_MaterialModulatorInstance_MaterialModulatorScript" fromField="newColor" toNode="DECLMaterialModulator_MaterialModulatorInstance_MaterialNode" toField="diffuseColor"></ROUTE>
<TimeSensor DEF="DECLMaterialModulator_MaterialModulatorInstance_ModulationClock" cycleInterval="0.1" loop="true" enabled="true"></TimeSensor>
<ROUTE fromNode="DECLMaterialModulator_MaterialModulatorInstance_ModulationClock" fromField="cycleTime" toNode="DECLMaterialModulator_MaterialModulatorInstance_MaterialModulatorScript" toField="clockTrigger"></ROUTE>
</Group>
</Switch>
</Transform>
<!--Selectable Text design pattern has transparent Box and TouchSensor description as a tooltip--><Transform translation="0 -2 0"><Shape><Text containerField="geometry" string=""enable/disable" "MaterialModulator""><FontStyle containerField="fontStyle" family=""SANS"" justify=""MIDDLE" "MIDDLE"" style="BOLD"></FontStyle>
</Text>
<Appearance containerField="appearance"><Material containerField="material" diffuseColor="0.9 0.9 0.9"></Material>
</Appearance>
</Shape>
<Shape><Box containerField="geometry" size="8 2 0.001"></Box>
<Appearance containerField="appearance"><Material containerField="material" transparency="1"></Material>
</Appearance>
</Shape>
<!--Toggle text to enable/disable MaterialModulator--><TouchSensor DEF="TouchTextInterface" description="Select to enable/disable MaterialModulator"></TouchSensor>
<BooleanToggle DEF="EventToggler"></BooleanToggle>
<ROUTE fromNode="TouchTextInterface" fromField="isActive" toNode="EventToggler" toField="set_boolean"></ROUTE>
<ROUTE fromNode="EventToggler" fromField="toggle" toNode="DECLMaterialModulator_MaterialModulatorInstance_MaterialModulatorScript" toField="enabled"></ROUTE>
</Transform>
</Scene>
</X3D>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20160714/e596b480/attachment.html>


More information about the x3d-public mailing list