Replace animationPaused with animationSpeed

This commit is contained in:
yushijinhun 2019-04-20 23:54:04 +08:00
parent 0c8a8b627a
commit 5992d3e68d
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
3 changed files with 10 additions and 11 deletions

View File

@ -58,7 +58,7 @@ Three.js powered Minecraft skin viewer.
// Pause single animation
run.paused = true;
// Pause all animations!
skinViewer.animationPaused = true;
skinViewer.animationSpeed = 0;
</script>
```

View File

@ -36,10 +36,8 @@
// skinViewer.playerObject.skin.slim = true;
let control = new skinview3d.createOrbitControls(skinViewer);
skinViewer.animation = new skinview3d.CompositeAnimation();
let walk = skinViewer.animation.add(skinview3d.WalkingAnimation);
walk.speed = 1.5;
skinViewer.animation = skinview3d.WalkingAnimation;
skinViewer.animationSpeed = 1.5;
</script>

View File

@ -18,7 +18,7 @@ export class SkinViewer {
public readonly domElement: Node;
public animation: Animation | null;
public detectModel: boolean = true;
public animationPaused: boolean = false;
public animationSpeed: number = 1;
public animationTime: number = 0;
public disposed: boolean = false;
@ -40,6 +40,8 @@ export class SkinViewer {
public readonly playerObject: PlayerObject;
private readonly clock: THREE.Clock;
constructor(options: SkinViewerOptions) {
this.domElement = options.domElement;
this.animation = options.animation || null;
@ -114,14 +116,13 @@ export class SkinViewer {
if (options.width) this.width = options.width;
if (options.height) this.height = options.height;
this.clock = new THREE.Clock(true);
const draw = () => {
if (this.disposed) return;
window.requestAnimationFrame(draw);
if (!this.animationPaused) {
this.animationTime++;
if (this.animation) {
invokeAnimation(this.animation, this.playerObject, this.animationTime / 100.0);
}
this.animationTime += this.clock.getDelta() * this.animationSpeed;
if (this.animation) {
invokeAnimation(this.animation, this.playerObject, this.animationTime);
}
this.renderer.render(this.scene, this.camera);
};