Merge pull request #43 from yushijinhun/pause-render

Add renderPaused property, close #42
This commit is contained in:
Pig Fang 2019-12-28 09:00:36 +08:00 committed by GitHub
commit de40fa0196
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 11 deletions

View File

@ -40,6 +40,8 @@ export class SkinViewer {
public readonly playerObject: PlayerObject;
private _renderPaused: boolean = false;
constructor(options: SkinViewerOptions) {
this.domElement = options.domElement;
this.animation = options.animation || null;
@ -114,18 +116,21 @@ export class SkinViewer {
if (options.width) this.width = options.width;
if (options.height) this.height = options.height;
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);
}
window.requestAnimationFrame(() => this.draw());
}
private draw() {
if (this.disposed || this._renderPaused) {
return;
}
if (!this.animationPaused) {
this.animationTime++;
if (this.animation) {
invokeAnimation(this.animation, this.playerObject, this.animationTime / 100.0);
}
this.renderer.render(this.scene, this.camera);
};
draw();
}
this.renderer.render(this.scene, this.camera);
window.requestAnimationFrame(() => this.draw());
}
setSize(width, height) {
@ -142,6 +147,18 @@ export class SkinViewer {
this.capeTexture.dispose();
}
get renderPaused() {
return this._renderPaused;
}
set renderPaused(value: boolean) {
const toResume = !this.disposed && !value && this._renderPaused;
this._renderPaused = value;
if (toResume) {
window.requestAnimationFrame(() => this.draw());
}
}
get skinUrl() {
return this.skinImg.src;
}