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

John Carlson yottzumm at gmail.com
Thu Jul 14 17:57:33 PDT 2016


I don’t know if the script is broken or something else.  The expanded version doesn’t work in any browser I tried.  The proto version works in at least octaga.  The original Proto version does not work in X3D JSON Loader (Cobweb).  The original Proto version does work in normal Cobweb.

X3D JSON -> XML version without Proto Expander is here (broken in Cobweb):

<?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><ProtoDeclare name="MaterialModulator" appinfo="mimic a Material node and modulate fields as an animation effect"><ProtoInterface><field name="enabled" accessType="inputOutput" type="SFBool" value="true"></field>
<field name="diffuseColor" accessType="inputOutput" type="SFColor" value="0.8 0.8 0.8"></field>
<field name="emissiveColor" accessType="inputOutput" type="SFColor" value="0 0 0"></field>
<field name="specularColor" accessType="inputOutput" type="SFColor" value="0 0 0"></field>
<field name="transparency" accessType="inputOutput" type="SFFloat" value="0"></field>
<field name="shininess" accessType="inputOutput" type="SFFloat" value="0.2"></field>
<field name="ambientIntensity" accessType="inputOutput" type="SFFloat" value="0.2"></field>
</ProtoInterface>
<ProtoBody><Material DEF="MaterialNode"><IS><connect nodeField="diffuseColor" protoField="diffuseColor"></connect>
<connect nodeField="emissiveColor" protoField="emissiveColor"></connect>
<connect nodeField="specularColor" protoField="specularColor"></connect>
<connect nodeField="transparency" protoField="transparency"></connect>
<connect nodeField="shininess" protoField="shininess"></connect>
<connect nodeField="ambientIntensity" protoField="ambientIntensity"></connect>
</IS>
</Material>
<!--Only first node (the node type) is renderable, others are along for the ride--><Script DEF="MaterialModulatorScript"><field name="enabled" accessType="inputOutput" type="SFBool"></field>
<field name="diffuseColor" accessType="inputOutput" type="SFColor"></field>
<field name="newColor" accessType="outputOnly" type="SFColor"></field>
<field name="clockTrigger" accessType="inputOnly" type="SFTime"></field>
<IS><connect nodeField="enabled" protoField="enabled"></connect>
<connect nodeField="diffuseColor" protoField="diffuseColor"></connect>
</IS>
<![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 fromField="newColor" fromNode="MaterialModulatorScript" toField="diffuseColor" toNode="MaterialNode"></ROUTE>
<TimeSensor DEF="ModulationClock" cycleInterval="0.1" loop="true"><IS><connect nodeField="enabled" protoField="enabled"></connect>
</IS>
</TimeSensor>
<ROUTE fromField="cycleTime" fromNode="ModulationClock" toField="clockTrigger" toNode="MaterialModulatorScript"></ROUTE>
</ProtoBody>
</ProtoDeclare>
<!--Rendered geometry for the ProtoInstance now follows prototype declaration--><Transform translation="0 1 0"><Shape><Sphere containerField="geometry"></Sphere>
<Appearance containerField="appearance"><ProtoInstance containerField="material" name="MaterialModulator" DEF="MaterialModulatorInstance"><fieldValue containerField="material" name="enabled" value="true"></fieldValue>
<fieldValue containerField="material" name="diffuseColor" value="0.5 0.1 0.1"></fieldValue>
</ProtoInstance>
</Appearance>
</Shape>
</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 fromField="isActive" fromNode="TouchTextInterface" toField="set_boolean" toNode="EventToggler"></ROUTE>
<ROUTE fromField="toggle" fromNode="EventToggler" toField="enabled" toNode="MaterialModulatorInstance"></ROUTE>
</Transform>
</Scene>
</X3D>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20160714/95188617/attachment-0001.html>


More information about the x3d-public mailing list