add SkinLoadOptions
This commit is contained in:
parent
9f975c3354
commit
47f34b856c
|
@ -328,7 +328,9 @@
|
||||||
skinViewer.loadSkin(null);
|
skinViewer.loadSkin(null);
|
||||||
input.setCustomValidity("");
|
input.setCustomValidity("");
|
||||||
} else {
|
} else {
|
||||||
skinViewer.loadSkin(url, document.getElementById("skin_model").value)
|
skinViewer.loadSkin(url, {
|
||||||
|
model: document.getElementById("skin_model").value
|
||||||
|
})
|
||||||
.then(() => input.setCustomValidity(""))
|
.then(() => input.setCustomValidity(""))
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
input.setCustomValidity("Image can't be loaded.");
|
input.setCustomValidity("Image can't be loaded.");
|
||||||
|
|
|
@ -10,6 +10,13 @@ export interface LoadOptions {
|
||||||
makeVisible?: boolean;
|
makeVisible?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SkinLoadOptions extends LoadOptions {
|
||||||
|
/**
|
||||||
|
* The model type of skin. Default is "auto-detect".
|
||||||
|
*/
|
||||||
|
model?: ModelType | "auto-detect";
|
||||||
|
}
|
||||||
|
|
||||||
export interface CapeLoadOptions extends LoadOptions {
|
export interface CapeLoadOptions extends LoadOptions {
|
||||||
/**
|
/**
|
||||||
* The equipment (cape or elytra) to show, defaults to "cape".
|
* The equipment (cape or elytra) to show, defaults to "cape".
|
||||||
|
@ -135,7 +142,9 @@ export class SkinViewer {
|
||||||
this.scene.add(this.playerWrapper);
|
this.scene.add(this.playerWrapper);
|
||||||
|
|
||||||
if (options.skin !== undefined) {
|
if (options.skin !== undefined) {
|
||||||
this.loadSkin(options.skin, options.model);
|
this.loadSkin(options.skin, {
|
||||||
|
model: options.model
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (options.cape !== undefined) {
|
if (options.cape !== undefined) {
|
||||||
this.loadCape(options.cape);
|
this.loadCape(options.cape);
|
||||||
|
@ -184,27 +193,32 @@ export class SkinViewer {
|
||||||
loadSkin(empty: null): void;
|
loadSkin(empty: null): void;
|
||||||
loadSkin<S extends TextureSource | RemoteImage>(
|
loadSkin<S extends TextureSource | RemoteImage>(
|
||||||
source: S,
|
source: S,
|
||||||
model?: ModelType | "auto-detect",
|
options?: SkinLoadOptions
|
||||||
options?: LoadOptions
|
|
||||||
): S extends TextureSource ? void : Promise<void>;
|
): S extends TextureSource ? void : Promise<void>;
|
||||||
|
|
||||||
loadSkin(
|
loadSkin(
|
||||||
source: TextureSource | RemoteImage | null,
|
source: TextureSource | RemoteImage | null,
|
||||||
model: ModelType | "auto-detect" = "auto-detect",
|
options: SkinLoadOptions = {}
|
||||||
options: LoadOptions = {}
|
|
||||||
): void | Promise<void> {
|
): void | Promise<void> {
|
||||||
if (source === null) {
|
if (source === null) {
|
||||||
this.resetSkin();
|
this.resetSkin();
|
||||||
|
|
||||||
} else if (isTextureSource(source)) {
|
} else if (isTextureSource(source)) {
|
||||||
loadSkinToCanvas(this.skinCanvas, source);
|
loadSkinToCanvas(this.skinCanvas, source);
|
||||||
const actualModel = model === "auto-detect" ? inferModelType(this.skinCanvas) : model;
|
|
||||||
this.skinTexture.needsUpdate = true;
|
this.skinTexture.needsUpdate = true;
|
||||||
this.playerObject.skin.modelType = actualModel;
|
|
||||||
|
if (options.model === undefined || options.model === "auto-detect") {
|
||||||
|
this.playerObject.skin.modelType = inferModelType(this.skinCanvas);
|
||||||
|
} else {
|
||||||
|
this.playerObject.skin.modelType = options.model;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.makeVisible !== false) {
|
if (options.makeVisible !== false) {
|
||||||
this.playerObject.skin.visible = true;
|
this.playerObject.skin.visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return loadImage(source).then(image => this.loadSkin(image, model, options));
|
return loadImage(source).then(image => this.loadSkin(image, options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue