[x3d-public] This script worked before adding addRoute/deleteRoute.
John Carlson
yottzumm at gmail.com
Mon Dec 9 09:49:12 PST 2024
Switch JavaScript versions in FreeWRL found the issue. deleteRoute takes
1 parameter.
This script works in Sunrize and FreeWRL:
<Script DEF="Script21">
<field name="inTime" type="SFTime" accessType="inputOnly"/>
<field name="fraction" type="SFFloat" accessType="inputOutput"
value="0"/>
<field name="diffuseColor" type="SFColor" accessType="inputOutput"
value="0 0 1"/>
<field name="checked" type="SFBool" accessType="inputOutput"
value="false"/>
<![CDATA[ecmascript:
var route = null;
function inTime(value) {
// Browser.print("in", diffuseColor.g, diffuseColor.b);
if (value) {
checked = !checked;
}
scene = Browser.currentScene;
if (checked) {
route = scene.addRoute(scene.getNamedNode("Main_Clock"),
'fraction_changed', scene.getNamedNode("AnimationAdapter_JinMouthStretch"),
'set_fraction');
diffuseColor.g = 1;
diffuseColor.b = 0;
fraction = 0;
} else {
if (route != null) {
scene.deleteRoute(route);
// scene.deleteRoute(scene.getNamedNode("Main_Clock"), 'fraction_changed',
scene.getNamedNode("AnimationAdapter_JinMouthStretch"), 'set_fraction');
}
diffuseColor.g = 1;
diffuseColor.g = 0;
diffuseColor.b = 1;
fraction = 0;
}
// Browser.print("out", diffuseColor.g, diffuseColor.b);
}
]]>
</Script>
Question: I'm guessing one can't have X3DRoutes as field types, and I have
to use a global Script variable? I'm hoping this isn't global in all
Scripts. If it is, I will probably implement a PROTO.
Thanks.
On Mon, Dec 9, 2024 at 11:33 AM John Carlson <yottzumm at gmail.com> wrote:
> Apparently there was some kind of caching issue with Sunrize, when I used
> npx sunrize at latest, everything was perfect.
>
> deleteRoute does not work in FreeWRL, and has been reported to Doug.
>
> Thanks,
>
> John
>
> On Mon, Dec 9, 2024 at 11:24 AM John Carlson <yottzumm at gmail.com> wrote:
>
>> Can someone confirm if this script looks like valid SAI?
>>
>> The scene was working great until I added addRoute/deleteRoute.
>>
>> Thanks!
>>
>> John
>>
>> <Script DEF="Script21">
>> <field name="inTime" type="SFTime" accessType="inputOnly"/>
>> <field name="fraction" type="SFFloat" accessType="inputOutput"
>> value="0"/>
>> <field name="diffuseColor" type="SFColor"
>> accessType="inputOutput" value="0 0 1"/>
>> <field name="checked" type="SFBool" accessType="inputOutput"
>> value="false"/>
>> <![CDATA[ecmascript:
>> function inTime(value) {
>> // Browser.print("in", diffuseColor.g, diffuseColor.b);
>> if (value) {
>> checked = !checked;
>> }
>> scene = Browser.currentScene;
>> if (checked) {
>> scene.addRoute(scene.getNamedNode("Main_Clock"),
>> 'fraction_changed', scene.getNamedNode("AnimationAdapter_JinMouthStretch"),
>> 'set_fraction');
>>
>> diffuseColor.g = 1;
>> diffuseColor.b = 0;
>> fraction = 0;
>> } else {
>> scene.deleteRoute(scene.getNamedNode("Main_Clock"),
>> 'fraction_changed', scene.getNamedNode("AnimationAdapter_JinMouthStretch"),
>> 'set_fraction');
>>
>> diffuseColor.g = 1;
>> diffuseColor.g = 0;
>> diffuseColor.b = 1;
>> fraction = 0;
>> }
>> // Browser.print("out", diffuseColor.g, diffuseColor.b);
>> }
>> ]]>
>> </Script>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20241209/76131360/attachment.html>
More information about the x3d-public
mailing list