Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  JavaScript    Check if animation is running

Moderators: e_phoenix13
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Member
Posted
What is the most efficient way to check if an animation is running or not? I need a way to disable the users ability to call another animation until after the current one is done running; otherwise they can cause view problems.
 
Posts: 48 | Registered: April 17, 2006Reply With QuoteEdit or Delete MessageReport This Post
Avi
AviScript Extraordinaire
Member
Picture of Avi
Posted Hide Post
This can be done in Javascript with a simple variable (let's call it canplay).

Declare the variable and set it's value to 0. 0 means that no animations can play. 1 means that any animation is free to play. If you have an event collection at the beginning of your scene, then after your scene is done downloading, call a javascript function to set canplay to 1 or just set it straight (Func="canplay=1") in the mtx.

If your buttons for animation calls are in HTML, then you'd call the javascript function which would check against the canplay variable to determine if the animation can play or not. If your buttons are inside of Viewpoint, I'd say to call out the Javascript function when the button is clicked and it would do the same as if it were in HTML.

So you'd have something like this in your HTML:

var canplay = 0;

function vwpt_trigger(ani) {
if (canplay == 1) {
canplay = 0;
vmp.TriggerAnim(ani);
}
}

And for your button to play the animation, you would call the vwpt_trigger function and pass it the animation name. This would restrict playing animations if the canplay is set to 0.

Now, the only thing would be to release the canplay variable to 1 when the animation is complete. You can do this in an actionanimator with the last property being a call to the javascript function that sets canplay to 1 or set it straight to a 1 in the mtx.

Does this make sense? There could be other ways, but this is one we usually use.

Avi
 
Posts: 24 | Registered: January 24, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
That sounds like what I need to do... I create and call all of my animations from code... here is an example... could you show me what line of code I should add?

function ZoomToDistance(distance)
{
i++;
var keyframes = "0 1";
var timeline = "* ["+distance+"]";

targ = MTSMarkup("Target", "", "Name", "MTSCamera", "Property", "orbd", "Timeline", "T1");
time = MTSMarkup("Time", keyframes);
tili = MTSMarkup("Timeline", timeline, "Name", "T1", "Type", "1D");
tiEl = MTSMarkup("MTSTimeElem", targ+time+tili, "Type", "Keyframe", "Name", "myCameraAnim"+i, "On", "0");
vmp.Execute(tiEl);
vmp.TriggerAnim("myCameraAnim"+i);
}
 
Posts: 48 | Registered: April 17, 2006Reply With QuoteEdit or Delete MessageReport This Post
Avi
AviScript Extraordinaire
Member
Picture of Avi
Posted Hide Post
Are you creating all your animations like this? If so, then you know each animation is 1 second long, correct? At this point, I would keep it completely in JavaScript using setTimeout routines. Research setTimeout in javascript. What you'd want to do is when you call the function, if canplay is a 1 (meaning you can play it), set canplay to 0. And then in one second (using setTimeout, so 1000 since the function takes in the parameter of milliseconds), set canplay back to a 1.

Avi
 
Posts: 24 | Registered: January 24, 2003Reply With QuoteEdit or Delete MessageReport This Post
  Powered by Eve Community  
 

Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  JavaScript    Check if animation is running