update `MouseControl` and remove event listener

This commit is contained in:
printempw 2018-02-11 18:43:54 +08:00
parent 79167ab0f8
commit 2725925fe4
2 changed files with 14 additions and 13 deletions

View File

@ -227,9 +227,9 @@ class SkinViewer {
}
}
class SkinControl {
class MouseControl {
constructor(skinViewer) {
this.enableAnimationControl = true;
this.enableMouseControl = true;
this.skinViewer = skinViewer;
this.orbitControls = new OrbitControls(skinViewer.camera, skinViewer.renderer.domElement);
@ -238,20 +238,19 @@ class SkinControl {
this.orbitControls.minDistance = 10;
this.orbitControls.maxDistance = 256;
this.orbitControls.update();
this.animationPauseListener = e => {
if (this.enableAnimationControl) {
e.preventDefault();
this.skinViewer.animationPaused = !this.skinViewer.animationPaused;
}
};
this.skinViewer.domElement.addEventListener("contextmenu", this.animationPauseListener, false);
enable() {
this.enableMouseControl = this.orbitControls.enableRotate = this.orbitControls.enableZoom = true;
}
disable() {
this.enableMouseControl = this.orbitControls.enableRotate = this.orbitControls.enableZoom = false;
}
dispose() {
this.skinViewer.domElement.removeEventListener("contextmenu", this.animationPauseListener, false);
this.orbitControls.dispose();
}
}
export { SkinViewer, SkinControl };
export { SkinViewer, MouseControl };

6
types/viewer.d.ts vendored
View File

@ -34,11 +34,13 @@ export class SkinViewer {
public dispose(): void;
}
export class SkinControl {
public enableAnimationControl: boolean;
export class MouseControl {
public enableMouseControl: boolean;
public readonly skinViewer: SkinViewer;
constructor(skinViewer: SkinViewer);
public enable(): void;
public disable(): void;
public dispose(): void;
}