This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > VRML > September 2004 > trigger script's eventIn (function) at a certain time





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author trigger script's eventIn (function) at a certain time
Robert Ludig

2004-08-26, 12:28 pm

Hello, I have a function (set_altitude) within a scriptnode that can
set the altitude of a certain point in the ElevationGrid. As Paramter
(val) it gets the index of the point (val[0]) and the height it shall
be set so (val[1]). It works fine.
My only problem is:
I want this function get called at certain time. The goal is to change
altitudes at a specific time ...
How could I call the function after lets say (10 seconds) ???

Here is the code :

-------------- vrmlcode ----------------

#VRML V2.0 utf8

Shape
{
geometry DEF MyIFS ElevationGrid
{
xDimension 5
zDimension 5
zSpacing 0.05
xSpacing 0.05
colorPerVertex TRUE
creaseAngle 0
color Color
{
color
[
1 0 0, 1 0 0, 1 0 0, 1 0 0, 1 0 0,
1 0 0, 1 0 0, 1 0 0, 1 0 0, 1 0 0,
1 0 0, 1 0 0, 1 0 0, 1 0 0, 1 0 0,
1 0 0, 1 0 0, 1 0 0, 1 0 0, 1 0 0,
1 0 0, 1 0 0, 1 0 0, 1 0 0, 1 0 0
]
}
height
[
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0
]
}
appearance Appearance
{
material Material
{
specularColor 1 1 1
}
}
}
DEF DeformerScript Script
{
field SFNode MyIFS USE MyIFS
eventIn SFVec3f set_altitude
url "vrmlscript:
function set_altitude (val,time)
{
MyIFS.height[val[0]] = val[1];
MyIFS.color.color[val[0]] = new SFColor(0, 1, 0);
}
"
}

# the following changes the point with the index 12 to the height of
0.04
# but I want that to happen at a secific time (for example 10 seconds
after
# the timer started)
DEF PosIntpl PositionInterpolator
{
key [0, 1]
keyValue [12 0.04 0,12 0.04 0]
}

DEF Timer TimeSensor
{
cycleInterval 10
loop TRUE
}

ROUTE Timer.fraction_changed TO PosIntpl.set_fraction
ROUTE PosIntpl.value_changed TO DeformerScript.set_altitude

Holger Grahn

2004-08-26, 7:17 pm


Hi

TimeSensor has an eventOut cycleTime which triggers every cycle.

-- Holger

"Robert Ludig" <schwertfischtrombose@gmx.de> schrieb im Newsbeitrag
news:cgkum9$oer@odah37.prod.google.com...
> Hello, I have a function (set_altitude) within a scriptnode that can
> set the altitude of a certain point in the ElevationGrid. As Paramter
> (val) it gets the index of the point (val[0]) and the height it shall
> be set so (val[1]). It works fine.
> My only problem is:
> I want this function get called at certain time. The goal is to change
> altitudes at a specific time ...
> How could I call the function after lets say (10 seconds) ???
>
> Here is the code :
>
> -------------- vrmlcode ----------------
>
> #VRML V2.0 utf8
>
> Shape
> {
> geometry DEF MyIFS ElevationGrid
> {
> xDimension 5
> zDimension 5
> zSpacing 0.05
> xSpacing 0.05
> colorPerVertex TRUE
> creaseAngle 0
> color Color
> {
> color
> [
> 1 0 0, 1 0 0, 1 0 0, 1 0 0, 1 0 0,
> 1 0 0, 1 0 0, 1 0 0, 1 0 0, 1 0 0,
> 1 0 0, 1 0 0, 1 0 0, 1 0 0, 1 0 0,
> 1 0 0, 1 0 0, 1 0 0, 1 0 0, 1 0 0,
> 1 0 0, 1 0 0, 1 0 0, 1 0 0, 1 0 0
> ]
> }
> height
> [
> 0,0,0,0,0,
> 0,0,0,0,0,
> 0,0,0,0,0,
> 0,0,0,0,0,
> 0,0,0,0,0
> ]
> }
> appearance Appearance
> {
> material Material
> {
> specularColor 1 1 1
> }
> }
> }
> DEF DeformerScript Script
> {
> field SFNode MyIFS USE MyIFS
> eventIn SFVec3f set_altitude
> url "vrmlscript:
> function set_altitude (val,time)
> {
> MyIFS.height[val[0]] = val[1];
> MyIFS.color.color[val[0]] = new SFColor(0, 1, 0);
> }
> "
> }
>
> # the following changes the point with the index 12 to the height of
> 0.04
> # but I want that to happen at a secific time (for example 10 seconds
> after
> # the timer started)
> DEF PosIntpl PositionInterpolator
> {
> key [0, 1]
> keyValue [12 0.04 0,12 0.04 0]
> }
>
> DEF Timer TimeSensor
> {
> cycleInterval 10
> loop TRUE
> }
>
> ROUTE Timer.fraction_changed TO PosIntpl.set_fraction
> ROUTE PosIntpl.value_changed TO DeformerScript.set_altitude
>



Robert Ludewig

2004-08-27, 7:15 am

But then I could only call thet function at multiples of cycleinterval.
Also ther would be no way to only call that function ofter 10 secounds and
after 30 secounds.
(if I would chose a cycleinterval of 10 secs, the function would also get
called at 20 secs)


Cecile Muller

2004-08-29, 7:16 pm

>you have a couple of problems,
>you can't, shouldn't, modify height directly, not an exposed field

you
>see, below is simple work round, what you did worked in blaxxun, but
>not in cortona.


The "set_height" eventIn is there for that (spec-compliant), which is
funny because the spec guys thought about putting an eventIn for
modifying, but didn't think of adding an MFFloat interpolator, tsk
tsk.


>I need to be able to specify any time I want for triggering the

function.
>Not just multiples of cuclyinterval:


You could change the interval of the TimeSensor with the script and
trigger the function when the clock stops (using isActive).


> At time:
> 0.1 sec
> Move the heights of the following coords (index):
> 1,3,6,0,12,34,55,234,556,33,12,78,90,23,221,3000,100,29,921
> To:
> 5.4


Below is a complete (spec-compliant) solution, turned into a proto
because i love protos/it's easier to write and re-use. For each
movement, specify at what moment, what indexes of the point(s) to move
and to what height.
It's only one movement at the time (aka it can be several points, but
they go to the same height), but you can easily modify the proto to
have several movements (such as the first point goes to height 1 while
point 2 goes to height -1) by adding a duration field to each info
node, and creating the matching timesensors and routes using the
script.


You can also grab it there:
http://www.wildpeaks.com/vrml/help/move_some_coords.wrl

-----[code]------
#VRML V2.0 utf8

PROTO MovePoints[
exposedField MFInt32 indexes []
exposedField SFTime atTime 0
exposedField SFFloat toHeight 0
]{Group{}}

PROTO MovingGrid[
field SFInt32 xDimension 0
field SFInt32 zDimension 0
field MFFloat height []
field MFNode move_infos []
field SFBool loop FALSE
exposedField MFColor color []
]{
PROTO SimpleMFFloatInterpolator[
exposedField MFFloat values []
eventIn SFFloat set_fraction
eventOut MFFloat value_changed
]{
PROTO Dummy [exposedField MFFloat values[]]{}
DEF dummy Dummy{values IS values}
DEF brain Script{
field SFFloat currentFraction 0
field SFNode dummy USE dummy
eventIn MFFloat values_in
eventIn SFFloat set_fraction IS set_fraction
eventOut MFFloat value_changed IS value_changed
directOutput TRUE
url "java script:
function update(){
l = Math.floor(dummy.values.length / 2);
if (l < 1) return;
values = dummy.values;
lastKey = 0;
lastIndex = 0;
result = new MFFloat();
for (i = 0; i < l; i++){result[i] = values[i] + (values[l + i] -
values[i]) * currentFraction;}
value_changed = result;
}
function values_in(v){currentFraction = 0; update();}
function set_fraction(v){
currentFraction = v;
if (currentFraction < 0) currentFraction = 0;
if (currentFraction > 1) currentFraction = 1;
update();
}
function initialize(){update();}
"
}
ROUTE dummy.values TO brain.values_in
}
Group{
children[
Shape {
appearance Appearance {material Material{specularColor 1 1 1}}
geometry DEF grid ElevationGrid {
xDimension IS xDimension
zDimension IS zDimension
color Color {color IS color}
height IS height
}
}
DEF timer_initialize TimeSensor{loop TRUE}
DEF timer TimeSensor{}
DEF interp SimpleMFFloatInterpolator{}
DEF brain Script{
field MFNode move_infos IS move_infos
field MFFloat height IS height
field SFBool loop IS loop
field SFNode grid USE grid
field SFNode timer USE timer
field MFFloat currentHeights []
field SFInt32 lastInfo 0
field SFTime lastTime 0
eventIn SFBool timer_isActive
eventIn SFTime doInitialize
eventOut MFFloat heights
url "java script:
function float_merge(arr1, arr2){
var tmpArr = new MFFloat();
var l = arr1.length;
var l2 = arr2.length;
for (var i = 0; i < l; i++){tmpArr[i] = arr1[i];}
for (var i = 0; i < l2; i++){tmpArr[l + i] = arr2[i];}
return tmpArr;
}
function float_copy(arr){
var tmpArr = new MFFloat();
var l = arr.length;
for (var i = 0; i < l; i++){tmpArr[i] = arr[i];}
return tmpArr;
}
function update(t){
if ((lastInfo >= move_infos.length) || (lastInfo < 0)) {
if (!loop) {return;} else {lastInfo = 0; lastTime = 0;}
}
var h = move_infos[lastInfo].toHeight;
var indexes = move_infos[lastInfo].indexes;
var time = move_infos[lastInfo].atTime;
timer.cycleInterval = time - lastTime;
lastTime = time;
var lHeight = height.length;
var lIndexes = indexes.length;
if (lHeight == 0) return;
newHeights = float_copy(currentHeights);
for (var i = 0; i < lIndexes; i++){newHeights[indexes[i]] = h;}
heights = float_merge(currentHeights,newHeights);
currentHeights = newHeights;
timer.startTime = t;
lastInfo++;
}
function timer_isActive(v,t){
if (v) return;
timer.stopTime = t - 1;
update(t);
}
function doInitialize(v,t){
if (move_infos.length == 0) return;
currentHeights = float_copy(height);
update(t);
}
"
}
]
ROUTE timer_initialize.time TO brain.doInitialize
ROUTE timer_initialize.time TO timer_initialize.stopTime

ROUTE timer.isActive TO brain.timer_isActive
ROUTE brain.heights TO interp.values

ROUTE timer.fraction_changed TO interp.set_fraction
ROUTE interp.value_changed TO grid.set_height
}
}


#Example of use
MovingGrid{
loop TRUE
xDimension 2
zDimension 2
color [1 0 0, 0 1 0, 1 1 0, 0 0 1]
height [0, 0, 0, 0]
move_infos [
MovePoints{atTime 1 toHeight 1 indexes [0]}
MovePoints{atTime 1.5 toHeight 1 indexes [1]}
MovePoints{atTime 2.009 toHeight 1 indexes [2]}
MovePoints{atTime 2.789 toHeight 1 indexes [3]}
MovePoints{atTime 4 toHeight 0 indexes [0, 1, 2, 3]}
]
}
Background{skyColor 0.5 0.5 1}
Viewpoint {
position 1.347 2.152 2.321
orientation -0.890 0.456 0.023 0.758
fieldOfView 0.844
}
-----[/code]------



>I lamost tned to think that vrml is not the right man for the job.


Now, how about actually learning the language before complaining ?
simon

2004-08-29, 11:15 pm

"Robert Ludewig" <schwertfischtrombose@gmx.de> wrote in message news:<2pc60bFjcljsU1@uni-berlin.de>...
> Thamks for the hint with cortona (but it ONLY has to work in balxxun ...)


but what you've got isn't vrml, it happens to work in one browser by
ACCIDENT, no reason for it to work even in a later version of blaxxun!
and the solution i posted is so simple!

> But still, my problem is not solved. I lamost tned to think that vrml is not
> the right man for the job.


sorry but given your example i still tend to think it is solved, i was
leaving it to you to change from single to multiple value types and
wrap the whole thing in a proto, which allows any number of changes at
any number of times, a proto for each time because each needs a
separate timeSensor.
Robert Ludewig

2004-08-29, 11:15 pm

Thank you for you time, solving the problem that I should have solved by
what simon gave me as hints. .
I am rather new to vrml, and have to admit it is not that easy for me to
familiarize with the vrml programming principles since I come form the plain
OO-corner wich requires a completely different way of thinking ....
As we germans say:
"Shooting from behind through the chest into the eye ...."



Cecile Muller

2004-08-30, 7:15 am

> Thank you for you time, solving the problem that I should have solved by
> what simon gave me as hints. .
> I am rather new to vrml, and have to admit it is not that easy for me to
> familiarize with the vrml programming principles since I come form the plain
> OO-corner wich requires a completely different way of thinking ....
> As we germans say:
> "Shooting from behind through the chest into the eye ...."


With strong wind too :-p
Ah don't worry, when you understand the structure, it will come easy.
The thing to remember is that the scene is mainly composed of
separated elements that communicate thru events instead of being one
script executed one line after the other (which is a bit like OO
actually imho).
Robert Ludewig

2004-08-30, 12:16 pm

I need to be able to specify any time I want for triggering the function.
Not just multiples of cuclyinterval:

12,3 sec 24,456 sec 200,1 sec

Also I need to be able to call the function several times at the same time:
Because I need to be bale to move more than one coord at the same time.


Robert Ludewig

2004-08-30, 12:16 pm

Errm, the coords to change will be PASSED to the function. So I can not use
a forloop since I need to pass the params from out side (wich coord, wich
new psoitzion)
"sam" <sam3dus@yahoo.com> schrieb im Newsbeitrag
news:JtOXc.457$w%6.24@newsread1.news.pas.earthlink.net...
>
>
>
> "Robert Ludewig" <schwertfischtrombose@gmx.de> wrote in message
> news:2p9pr2Fiig9aU1@uni-berlin.de...
>
>
> Set cycleInterval to 0.1 or use the fraction_changed or time event outs.
>
>
> time:
>
> Use a for loop and change as many coords as you like.
>
>
>
>



Joerg Scheurich aka MUFTI

2004-08-30, 7:17 pm

> I am rather new to vrml, and have to admit it is not that easy for me to
> familiarize with the vrml programming principles since I come form the plain
> OO-corner wich requires a completely different way of thinking ....


The basic idea behind the field/eventIn restrictions of fields in shapes like
ElevationGrid is optimization.
Using a type of shape without buildin optimization can make things more
easy for complicated tasks.

so long
MUFTI
--
Eine Unter-Speisekarte wird erscheinen, in der Sie waehlen koennen,
entweder zu spielen, oder das Video zu schlingen.
(aus einem Software-Handbuch, Stichworte: menu und loop)
simon

2004-08-30, 7:17 pm

spam@wildpeaks.com (Cecile Muller) wrote in message news:<aff31ac6.0408292317.9f7c74b@posting.google.com>...

> With strong wind too :-p
> Ah don't worry, when you understand the structure, it will come easy.
> The thing to remember is that the scene is mainly composed of
> separated elements that communicate thru events instead of being one
> script executed one line after the other (which is a bit like OO
> actually imho).


sure, protos are just classes, and then protos make nodes ( instances
) and a lot of the time the objects can be real? virtual objects!
rather than conceptual ones.

but i find the event passing more interesting, because a browser could
avoid executing whole blocks of code, if no events from that code are
routed to an object in the field of view! ( or within sound range.)
BTW this also means that dynamics have to be absolute, so that things
appear to continue when you don't look at them, which is why you need
interpolators and an unintuitive timeSensor!

this also means that multiprocessor execution could be efficient,
which i'm guessing was the original idea, when a world gets really big
and highly multiuser then its the only way to go, ( a user could be
processing things that they alone see.)
Robert Ludewig

2004-09-01, 4:16 am

But then I could only call thet function at multiples of cycleinterval.
Also ther would be no way to only call that function ofter 10 secounds and
after 30 secounds.
(if I would chose a cycleinterval of 10 secs, the function would also get
called at 20 secs)


Robert Ludewig

2004-09-01, 11:17 pm

Thank you for you time, solving the problem that I should have solved by
what simon gave me as hints. .
I am rather new to vrml, and have to admit it is not that easy for me to
familiarize with the vrml programming principles since I come form the plain
OO-corner wich requires a completely different way of thinking ....
As we germans say:
"Shooting from behind through the chest into the eye ...."



Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews