You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
594 B
33 lines
594 B
import { Clock } from "three";
|
|
|
|
const clock = new Clock();
|
|
|
|
class Loop {
|
|
constructor(camera, scene, renderer) {
|
|
this.camera = camera;
|
|
this.scene = scene;
|
|
this.renderer = renderer;
|
|
this.updatables = [];
|
|
}
|
|
|
|
start() {
|
|
this.renderer.setAnimationLoop(() => {
|
|
this.tick();
|
|
// render a frame
|
|
this.renderer.render(this.scene, this.camera);
|
|
});
|
|
}
|
|
|
|
stop() {
|
|
this.renderer.setAnimationLoop(null);
|
|
}
|
|
|
|
tick() {
|
|
const delta = clock.getDelta();
|
|
for (const object of this.updatables) {
|
|
object.tick(delta);
|
|
}
|
|
}
|
|
}
|
|
|
|
export { Loop };
|
|
|