0

I'm using a library called CCapture to capture equally time-spaced frames. This code seems to be able to hook the clock and control it so that is slows down my rendering loop when it is capturing. My code uses clock.getDelta() to get the time and it uses this time to calculate the positions of moving transit vehicles. When CCapture controls the rendering rate, the vehicles are correctly positioned. I recently started using the TWEEN library in my code.

function animate() {
  renderer.setAnimationLoop( renderFrame );
}

function renderFrame() {
  const delta = clock.getDelta()
  timeSinceStart += delta;
  repositionTransitVehicles(timeSinceStart);

  renderer.render(scene, camera);
  if (capturer) {
    capturer.capture( renderer.domElement );
  }
  orbitControls.enabled = false;
  TWEEN.update();
  orbitControls.enabled = true;
  orbitControls.update();
}, 

With the no-arguments version of TWEEN.update(), tweening works but always proceeds at real time, which is too fast when I'm using CCapture. If I use...

TWEEN.update(timeSinceStart)

...then tweening does not work at all.

Does anyone know the secret to making TWEEN.update() operate using the same clock as the rest of the model?

phil1008
  • 39
  • 4

1 Answers1

0

The timer that TWEEN uses is a millisecond timer, an thus the units of the time that need to be passed into TWEEN.update() need to be in units of milliseconds. The units of THREE.Clock() are seconds. So use...

TWEEN.update(timeSinceStart*1000)

Wherever you use TWEEN's .start() method to initiate your tweens, you will also need to pass in the argument timeSinceStart*1000 as well.

phil1008
  • 39
  • 4