Execute function based on animation timeline with API

api
animation

(Pierre Savoie) #1

Basically, I want to be able to change my camera position at specific moment in my animation. For now it work kind-ish but I can't get the specific time to work because the time is not rounded.

Any clues as to how to proceed?

var GetTime = function () {
setInterval(
function() {
			sketchfabAPIUtility.api.getCurrentTime( function( err, time ){
			Math.round( time );
			console.log( time );
				if (time == 18) {
				sketchfabAPIUtility.api.lookat(
				// eye position
				[ 1, 1, 0],
				// target to lookat
				target,
				// duration of the animation in seconds
				5
				);
				} else if (time == 24) {
				sketchfabAPIUtility.api.lookat(
				// eye position
				[ 0, -1, 1],
				// target to lookat
				target,
				// duration of the animation in seconds
				5
				);
				}
			} );
			
}, 500);
}

#2

Hmm, maybe it could work better if we had a way to switch to frames instead of time?


(Pierre Savoie) #3

I managed to make it work with a condition that look like this :

if (time < 18 && time > 16)

It's not optimal but it works for now.


(Pierre Savoie) #4

I mentioned it in a mail, but I can't access it right now.
There is a big difference in how the animation look in frame mode vs timeStamp mode.

Here's an example:

In frame mode, the animation is somewhat jagged but each frame appear as they were in my 3ds max.
The animation feels smoother in timestamp but I can see in-between two frame. Look at timestamp 4:81, you can see the Christmas balls scaling down.


Animating objects on and off via scale
(Shaderbytes) #5

this is a known issue even with regular frame based single scene animations. Sketchfab will inject/ create their own frames of interpolation.For example if you have an object at scale 1 on one frame and the very next frame it is scale 0 . In the authoring software it will immediately disappear. In Sketchfab they will generate there owns frames which will normally inject frames in between such frames so that you notice the interpolation from 1 to 0 over several frames.

Kinda sucks but it has been like this for long. Lets hope they have a fix in the pipeline :wink:


(Stephomi) #6

@shaderbytes That's not entirely correct (as of today at least).

We do rebake animations in a regular basis (30fps), but we still allow duplicates frames (at exact sames timestamp).
So it's perfectly possible to animation a scale 0->1 without interpolation in sketchfab.

Of course there are different ways for a software to handle this transitions:
- step/nearest interpolation
- manually move 2 keyframes on the same timestamp
- other variants... it depends of the authoring tool

I'll let @waleguene investigate this particular file. Depending of the software and method used, we might have a bug.


(Shaderbytes) #7

Thanks for the update, i will have to test it again and see i know using blender myself and others using maya had this injected interpolation previously.where frames adjacent to each other with scale 1 then 0 was an issue. I will target 30fps and check if it has been fixed.:wink:


(Waleguene) #8

Hi @pierre.savoie

I took a look at your model and it seems that it has none of the two mentionned solutions for sharp keyframe interpolations.
Example:

That's why frame by frame is fine.
You will get the expected result by changing the tangent mode to "Stepped".

This is how it should look:

I hope it helps.

@shaderbytes it's still an issue for Blender.


(Shaderbytes) #9

thanks @waleguene

I wont test it then :slight_smile: I know from a coding point of view in blender animations are if fact made up of IPO curves and time. The curves are smooth bezier by default. Even when changing this to say linear and the adjacent frames each represent a curve node , this is still and issue in blender. the time step for keyframe generation/sampling rate is the default 1. I know the default FPS is 24, not 30 like you guys have it, so this is probably causing issues as is. but most people wont even touch the curves interpolation curves and just use the default. Which is smooth bezier as mentioned.


(Pierre Savoie) #10

Thanks for all the answers,
I will update my animation transition with stepped and see if it works better.