Hi want to get the smoothest animations possible.
So far, even with a single box spinning, it isn’t as smooth as I think it can be (60 fps).
Sometimes it feels like there are micro lags.
I made two boxes and I think one is animated on a frame basis while the other is animated on a time basis.
Is this done right?
If so, is the animation of box2 the smoothest animation I can get or is it still not optimal?
As I said, it seems like both are the same when previewing. Being smooth but not perfectly.
function engine(){
const engine = new BABYLON.Engine(canvas);
engine.setSize(canvasWidth,canvasHeight);
engine.runRenderLoop(renderLoop);
const scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color3(0.95, 0.95, 0.95);
new BABYLON.Layer('back','../assets/images/background.jpg', scene, true);
const camera = new BABYLON.FreeCamera("camera",new BABYLON.Vector3(0, 0, -10),scene);
camera.attachControl(canvas, true, true)
camera.setTarget(new BABYLON.Vector3(0, 0, 0));
const light = new BABYLON.HemisphericLight("Light", new BABYLON.Vector3(0, 1, 0), scene);
light.diffuse = new BABYLON.Color3(1, 1, 1);
light.specular = new BABYLON.Color3(1, 1, 1);
light.intensity = 2;
const box1 = new BABYLON.MeshBuilder.CreateBox("box", { width:2, height:2, depth:2 }, scene);
box1.material = new BABYLON.StandardMaterial("material", scene);;
box1.material.diffuseColor = new BABYLON.Color3.FromHexString("#494e5d");
box1.position.x = -3
box1.position.y = 0
box1.position.a = -3
box1.rotation.x = 0
box1.rotation.y = 0
box1.rotation.z = 0
const box2 = new BABYLON.MeshBuilder.CreateBox("box", { width:2, height:2, depth:2 }, scene);
box2.material = new BABYLON.StandardMaterial("material", scene);
box2.material.diffuseColor = new BABYLON.Color3.FromHexString("#494e5d");
box2.position.x = 3
box2.position.y = 0
box2.position.a = 3
box2.rotation.x = 0
box2.rotation.y = 0
box2.rotation.z = 0
function renderLoop() {
scene.render();
// frame-based => relative to frame rate => less smooth, can lag?
box1.rotation.x += 0.027;
box1.rotation.y += 0.027;
// time based => relative to delta time => smoother, steadier?
let delta = engine.getDeltaTime()
box2.rotation.x += 0.0015*delta;
box2.rotation.y += 0.0015*delta;
}
}
Moreover, I’m astonished that I had to change the base value of the rotation so that the two boxes seem to move at the same speed. (0.027 had to become 0.0015 to match).
Something feels odd and I want to be sure that I’m using delta time correctly.
Thanks for your help