I run on macOS 10.15 Catalina.
I reloaded the HTML page with the animation on Google Chrome Version 88.0.4324.96 (Official Build) (x86_64) and it played flawlessly 8 times on 10.
On Safari Version 13.1.3 (15609.4.1) it played fluently just 6 times on 10. If I clean the cash then quit then relaunch, it plays the same way.
But those numbers are random. I can’t say it’s always 8/10 on Chrome and 5/10 on Safari.
This is my animation function
/////////////////////////////////////////////////////
function PlayAnimation(objects, absFrame)
/////////////////////////////////////////////////////
{
var i, totObjs = objects.length;
for(i = 0; i < totObjs; i++)
{
// obj is a json containing a mesh, positions, rotations… if obj is a group (a folder), it contains its children
var obj = objects[i];
// if the object on the timeline should be rendered
if(absFrame >= obj.start && absFrame <= obj.end)
{
// The obj.mesh is the one we added to the scene with scene.add(obj.mesh);
// We created with: mesh = new THREE.Mesh(mergedGeometry, materials);
obj.mesh.visible = true;
// obj.mDynamic is an array containing *only* the parameters we have to animate,
// so maybe just one parameter as kPosX or e.g. six parameters as kPosX, kPosY, kPosZ, kRotX, kRotY, kRotZ…
// We previously did set the object static parameters just once, when we loaded the object.
var dynParams = obj.mDynamic;
if(dynParams) // if the object contains dynamic parameters as e.g. positions and rotations, we have to animate it
{
// the obj's frame (objFrame) is the absolute current frame (absFrame) - the obj's start time on the timeline
var objFrame = absFrame - obj.start;
for(const [key, dynParam] of Object.entries(dynParams))
{
switch(key)
{
case kPosX:
obj.mesh.position.x = dynParam[objFrame];
break;
case kPosY:
obj.mesh.position.y = dynParam[objFrame];
break;
case kPosZ:
obj.mesh.position.z = dynParam[objFrame];
break;
// and so on…
}
}
}
if(obj.children) // in case of group we iterate its children
{
PlayAnimation(obj.children, absFrame);
}
}
// if the object on the timeline should not be rendered
else{
obj.mesh.visible = false;
}
}
}
And this is my animate() function:
const fps = 60.0;
const fpsInterval = 1000 / fps;
var now, elapsed;
var then = Date.now();
var startTime = then;
var mAnimationFrame = 0;
var mObjects = []; // an array containing all the objects (json) loaded.
////////////////////////////////////////////////////////////////
function animate()
////////////////////////////////////////////////////////////////
{
requestAnimationFrame(animate);
now = Date.now();
elapsed = now - then;
// if enough time has elapsed, draw the next frame
if(elapsed > fpsInterval)
{
then = now - (elapsed % fpsInterval);
PlayAnimation(mObjects, mAnimationFrame);
mAnimationFrame +=1;
renderer.render(scene, camera);
}
}