Position-based control over animations

I have a site where I move an animated model along a predefined path, at a pre-determined (and variable) speed. There are several different models, with very different animations. For each model, I know how far it should move over the ground during a single play through of the animation.

A similar example is described here, but the final solution is to use nodeTransformations - which is somewhat reasonable for a model with 4 wheels that all need to rotate at the same speed. In my case, I may have hundreds of nodes with related (obviously) but different transformations; the animation is supposed to capture all that detail, so that my website doesn’t have to know about it.

Currently, it seems that model animations are entirely time based. I need mine to be distance based; when the model is at a particular distance along the path, I want it to be at a particular “time” in the animation. Specifically, if the model is supposed to move N meters for each full iteration of the animation, the animation duration is D, and the current distance of the model along the path is L, I want to set the local animation time to (L/N - floor(L/N)) * D.

After digging through the code a bit, I’ve found that there are private methods, and an internal animation object that can be used to set an animation to a particular local time. Its pretty straightforward to code it up:

var animation = model._runtime.animations[0];
var duration = animation.stopTime - animation.startTime;
# sim.dist is how far the model is along the path, and sim.category.defaultAnimationSpeed
# is how far the simulation's model should move in a single iteration of the animation.
var delta = sim.dist / sim.category.defaultAnimationSpeed;
delta -= Math.floor(delta);
var localTime = delta * duration + animation.startTime;
if (localTime > animation.stopTime) localTime = animation.stopTime;
# the following should probably be a setLocalTime() method on animations
var channelEvaluators = animation.channelEvaluators;
var length = channelEvaluators.length;
for (var i = 0; i < length; ++i) {

This works perfectly - but of course, it depends on poking around in cesium internals that could change at any time. Would it be reasonable to have a method on ModelAnimation to set its local time directly? If I added such a method, is that something that would be accepted?

FWIW here’s an example of one of the more complex models (the site is a work in progress, and it may take a while for the model to appear the first time you load it).

No takers? :upside_down_face:

I just made a pull request: Add support for explicit control over model animations by markw65 · Pull Request #9339 · CesiumGS/cesium · GitHub