From da09d950aa1e09e39c4a6a87f17f4aaa6346f092 Mon Sep 17 00:00:00 2001 From: Haowei Wen Date: Thu, 10 Sep 2020 00:23:32 +0800 Subject: [PATCH] add 'renderPaused' option to SkinViewerOptions --- src/fxaa.ts | 2 +- src/viewer.ts | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/fxaa.ts b/src/fxaa.ts index 8717c5c..30fc2c0 100644 --- a/src/fxaa.ts +++ b/src/fxaa.ts @@ -39,7 +39,7 @@ export class FXAASkinViewer extends SkinViewer { this.fxaaPass.material.uniforms["resolution"].value.y = 1 / (this.height * pixelRatio); } - protected doRender(): void { + render(): void { this.composer.render(); } } diff --git a/src/viewer.ts b/src/viewer.ts index b86bcd4..2595050 100644 --- a/src/viewer.ts +++ b/src/viewer.ts @@ -32,6 +32,12 @@ export type SkinViewerOptions = { * Whether to preserve the buffers until manually cleared or overwritten. Default is false. */ preserveDrawingBuffer?: boolean; + + /** + * The initial value of `SkinViewer.renderPaused`. Default is false. + * If this option is true, rendering and animation loops will not start. + */ + renderPaused?: boolean; } function toMakeVisible(options?: LoadOptions): boolean { @@ -92,8 +98,6 @@ class SkinViewer { this.playerObject.cape.visible = false; this.scene.add(this.playerObject); - window.requestAnimationFrame(() => this.draw()); - if (options.skin !== undefined) { this.loadSkin(options.skin); } @@ -106,6 +110,12 @@ class SkinViewer { if (options.height !== undefined) { this.height = options.height; } + + if (options.renderPaused === true) { + this._renderPaused = true; + } else { + window.requestAnimationFrame(() => this.draw()); + } } protected skinLoaded(model: ModelType, options?: LoadOptions): void { @@ -136,11 +146,15 @@ class SkinViewer { return; } this.animations.runAnimationLoop(this.playerObject); - this.doRender(); + this.render(); window.requestAnimationFrame(() => this.draw()); } - protected doRender(): void { + /** + * Renders the scene to the canvas. + * This method does not change the animation progress. + */ + render(): void { this.renderer.render(this.scene, this.camera); } @@ -161,6 +175,11 @@ class SkinViewer { return this._disposed; } + /** + * Whether rendering and animations are paused. + * Setting this property to true will stop both rendering and animation loops. + * Setting it back to false will resume them. + */ get renderPaused(): boolean { return this._renderPaused; }