refactor constructor
This commit is contained in:
parent
de72de69f4
commit
943d1d3c5a
|
|
@ -11,7 +11,6 @@ export type LoadOptions = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SkinViewerOptions = {
|
export type SkinViewerOptions = {
|
||||||
domElement: Node;
|
|
||||||
width?: number;
|
width?: number;
|
||||||
height?: number;
|
height?: number;
|
||||||
skin?: RemoteImage | TextureSource;
|
skin?: RemoteImage | TextureSource;
|
||||||
|
|
@ -41,15 +40,8 @@ class SkinViewer {
|
||||||
private _disposed: boolean = false;
|
private _disposed: boolean = false;
|
||||||
private _renderPaused: boolean = false;
|
private _renderPaused: boolean = false;
|
||||||
|
|
||||||
constructor(domElement: Node);
|
constructor(domElement: Node, options: SkinViewerOptions = {}) {
|
||||||
constructor(options: SkinViewerOptions);
|
this.domElement = domElement;
|
||||||
|
|
||||||
constructor(param: Node | SkinViewerOptions) {
|
|
||||||
if (param instanceof Node) {
|
|
||||||
this.domElement = param;
|
|
||||||
} else {
|
|
||||||
this.domElement = param.domElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
// texture
|
// texture
|
||||||
this.skinCanvas = document.createElement("canvas");
|
this.skinCanvas = document.createElement("canvas");
|
||||||
|
|
@ -80,28 +72,26 @@ class SkinViewer {
|
||||||
|
|
||||||
window.requestAnimationFrame(() => this.draw());
|
window.requestAnimationFrame(() => this.draw());
|
||||||
|
|
||||||
if (!(param instanceof Node)) {
|
if (options.skin !== undefined) {
|
||||||
if (param.skin !== undefined) {
|
if (isTextureSource(options.skin)) {
|
||||||
if (isTextureSource(param.skin)) {
|
this.loadSkin(options.skin);
|
||||||
this.loadSkin(param.skin);
|
} else {
|
||||||
} else {
|
this.loadSkin(options.skin);
|
||||||
this.loadSkin(param.skin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (param.cape !== undefined) {
|
}
|
||||||
if (isTextureSource(param.cape)) {
|
if (options.cape !== undefined) {
|
||||||
this.loadCape(param.cape);
|
if (isTextureSource(options.cape)) {
|
||||||
} else {
|
this.loadCape(options.cape);
|
||||||
this.loadCape(param.cape);
|
} else {
|
||||||
}
|
this.loadCape(options.cape);
|
||||||
}
|
|
||||||
if (param.width !== undefined) {
|
|
||||||
this.width = param.width;
|
|
||||||
}
|
|
||||||
if (param.height !== undefined) {
|
|
||||||
this.height = param.height;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (options.width !== undefined) {
|
||||||
|
this.width = options.width;
|
||||||
|
}
|
||||||
|
if (options.height !== undefined) {
|
||||||
|
this.height = options.height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected skinLoaded(model: ModelType, options?: LoadOptions): void {
|
protected skinLoaded(model: ModelType, options?: LoadOptions): void {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue