Add SkinViewerOptions

This commit is contained in:
yushijinhun 2018-08-17 12:05:17 +08:00
parent 96286ee9ea
commit 6477c7c707
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
2 changed files with 30 additions and 20 deletions

View File

@ -5,7 +5,8 @@ export {
} from "./model"; } from "./model";
export { export {
SkinViewer SkinViewer,
SkinViewerOptions
} from "./viewer"; } from "./viewer";
export { export {

View File

@ -3,35 +3,44 @@ import { PlayerObject } from "./model";
import { invokeAnimation } from "./animation"; import { invokeAnimation } from "./animation";
import { loadSkinToCanvas, loadCapeToCanvas, isSlimSkin } from "./utils"; import { loadSkinToCanvas, loadCapeToCanvas, isSlimSkin } from "./utils";
export interface SkinViewerOptions {
domElement: Node;
animation?: Animation;
skinUrl?: string;
capeUrl?: string;
width?: number;
height?: number;
detectModel?: boolean;
}
export class SkinViewer { export class SkinViewer {
public domElement: HTMLElement; public readonly domElement: Node;
public animation: Animation; public animation: Animation | null;
public detectModel: boolean = true; public detectModel: boolean = true;
public animationPaused: boolean = false; public animationPaused: boolean = false;
public animationTime: number = 0; public animationTime: number = 0;
public disposed: boolean = false; public disposed: boolean = false;
public skinImg: HTMLImageElement; public readonly skinImg: HTMLImageElement;
public skinCanvas: HTMLCanvasElement; public readonly skinCanvas: HTMLCanvasElement;
public skinTexture: THREE.Texture; public readonly skinTexture: THREE.Texture;
public capeImg: HTMLImageElement; public readonly capeImg: HTMLImageElement;
public capeCanvas: HTMLCanvasElement; public readonly capeCanvas: HTMLCanvasElement;
public capeTexture: THREE.Texture; public readonly capeTexture: THREE.Texture;
public layer1Material: THREE.MeshBasicMaterial; public readonly layer1Material: THREE.MeshBasicMaterial;
public layer2Material: THREE.MeshBasicMaterial; public readonly layer2Material: THREE.MeshBasicMaterial;
public readonly capeMaterial: THREE.MeshBasicMaterial;
public scene: THREE.Scene; public readonly scene: THREE.Scene;
public camera: THREE.PerspectiveCamera; public readonly camera: THREE.PerspectiveCamera;
public readonly renderer: THREE.WebGLRenderer;
public capeMaterial: THREE.MeshBasicMaterial; public readonly playerObject: PlayerObject;
public renderer: THREE.WebGLRenderer;
public playerObject: PlayerObject; constructor(options: SkinViewerOptions) {
constructor(options) {
this.domElement = options.domElement; this.domElement = options.domElement;
this.animation = options.animation || null; this.animation = options.animation || null;
if (options.detectModel === false) { if (options.detectModel === false) {
@ -118,13 +127,13 @@ export class SkinViewer {
draw(); draw();
} }
private setSize(width, height) { setSize(width, height) {
this.camera.aspect = width / height; this.camera.aspect = width / height;
this.camera.updateProjectionMatrix(); this.camera.updateProjectionMatrix();
this.renderer.setSize(width, height); this.renderer.setSize(width, height);
} }
private dispose() { dispose() {
this.disposed = true; this.disposed = true;
this.domElement.removeChild(this.renderer.domElement); this.domElement.removeChild(this.renderer.domElement);
this.renderer.dispose(); this.renderer.dispose();