Timeline events and controlling animation

viewer-api
animation

(Moochiecricket) #1

I am trying to create a script that will track the animation time and at a specified time execute a function. I was trying to use getCurrentTime but that seems to only get called once rather than continually watching the animation time. I need something that says "at this specific time in the animation, do this"

Also I notice that the seekTo function doesn't update the time slider location unless the animation is paused. If the animation is not paused then the time display gets set to the correct time and the animation jumps to that time, but the time slider does not jump to the correct position on the bar.

Ultimately I am trying to use sketchfab to create step by step animated instructions.


(Mauricesvay) #2

Hello,

I'm not sure to understand exactly what you are trying to achieve, but we just added a new experiment around animation controls: https://labs.sketchfab.com/experiments/custom-animation-controls/

The code is available on github there: https://github.com/sketchfab/experiments/tree/master/custom-animation-controls


(Kmullis) #3

Thanks @mauricesvay

Ultimately what I need is a function that continually returns the time of the animation, so that I can say

at this particular time
do the following

I know that getCurrentTime will do this but I need to assign the return of getCurrentTime to a variable so that I can use the value it's returning.

This is where I am having difficulties. I essentially want to do something like the following

var currentTime = api.getCurrentTime( function (err,time) {
return time;
});

I am still a relative novice when it comes to coding, so I'm not sure if this is how I should be going about it. However, the approach above gives me an undefined for currentTime when I try to do a console log.

If I can just get some help on how to assign the return of api.getCurrentTime to a variable, I think I can figure out the rest from there.


(Kmullis) #4

by the way I am also the person who posted the original question. I didn't realize I was logged into a friends account on the forum. didn't know at first that the sketchfab and forum accounts were not linked.


(Mauricesvay) #5

This part of the code should be what you are looking for:

Everytime the time changes, the onTime callback is executed.


(Kmullis) #6

Thanks @mauricesvay

This is pretty much what I'm looking for. However, this example creates a new timeslider rather than working with the default sketchfab timeslider. Is there a way to do this with the default timeslider?

I think am going to try to use a setTimeout function to continually return the time, as you have in this example.


(Mauricesvay) #7

There is no event to get this information periodically. You need to pull the information. setTimeout or requestAnimationFrame are the way to go for now.


(Kmullis) #8

Thanks again @mauricesvay

I'll let you know how it works out for me.