Fix ears and add webgl errors
This commit is contained in:
parent
c0851c2d79
commit
c7e44a78e2
|
|
@ -101,6 +101,15 @@
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
padding-left: 20px;
|
padding-left: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.skin_container_error {
|
||||||
|
padding: 1rem;
|
||||||
|
margin: 1rem;
|
||||||
|
display: inline-block;
|
||||||
|
background: red;
|
||||||
|
color: white;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,13 +96,21 @@ export class SkinViewer {
|
||||||
this.camera.position.y = -8;
|
this.camera.position.y = -8;
|
||||||
this.camera.position.z = 64;
|
this.camera.position.z = 64;
|
||||||
|
|
||||||
this.renderer = new WebGLRenderer({
|
try {
|
||||||
canvas: this.canvas,
|
this.renderer = new WebGLRenderer({
|
||||||
alpha: options.alpha !== false, // default: true
|
canvas: this.canvas,
|
||||||
preserveDrawingBuffer: options.preserveDrawingBuffer === true // default: false
|
alpha: options.alpha !== false, // default: true
|
||||||
|
preserveDrawingBuffer: options.preserveDrawingBuffer === true // default: false
|
||||||
});
|
});
|
||||||
this.renderer.setPixelRatio(window.devicePixelRatio);
|
this.renderer.setPixelRatio(window.devicePixelRatio);
|
||||||
|
} catch(error) {
|
||||||
|
const errorDiv = document.createElement('div');
|
||||||
|
errorDiv.classList.add(`${this.canvas.id}_error`);
|
||||||
|
errorDiv.textContent = "Your browser doesn't support WebGL. You will encounter issues!";
|
||||||
|
document.body.insertBefore(errorDiv, this.canvas.nextSibling)
|
||||||
|
this.canvas.remove();
|
||||||
|
throw "No WebGL Support";
|
||||||
|
}
|
||||||
|
|
||||||
this.playerObject = new PlayerObject(this.skinTexture, this.capeTexture, this.earTexture);
|
this.playerObject = new PlayerObject(this.skinTexture, this.capeTexture, this.earTexture);
|
||||||
this.playerObject.name = "player";
|
this.playerObject.name = "player";
|
||||||
|
|
@ -143,7 +151,6 @@ export class SkinViewer {
|
||||||
model?: ModelType | "auto-detect",
|
model?: ModelType | "auto-detect",
|
||||||
options?: LoadOptions
|
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",
|
model: ModelType | "auto-detect" = "auto-detect",
|
||||||
|
|
@ -172,7 +179,6 @@ export class SkinViewer {
|
||||||
source: S,
|
source: S,
|
||||||
options?: CapeLoadOptions
|
options?: CapeLoadOptions
|
||||||
): S extends TextureSource ? void : Promise<void>;
|
): S extends TextureSource ? void : Promise<void>;
|
||||||
|
|
||||||
loadCape(
|
loadCape(
|
||||||
source: TextureSource | RemoteImage | null,
|
source: TextureSource | RemoteImage | null,
|
||||||
options: CapeLoadOptions = {}
|
options: CapeLoadOptions = {}
|
||||||
|
|
@ -201,7 +207,6 @@ export class SkinViewer {
|
||||||
source: S,
|
source: S,
|
||||||
options?: LoadOptions
|
options?: LoadOptions
|
||||||
): S extends TextureSource ? void : Promise<void>;
|
): S extends TextureSource ? void : Promise<void>;
|
||||||
|
|
||||||
loadEars(
|
loadEars(
|
||||||
source: TextureSource | RemoteImage | null,
|
source: TextureSource | RemoteImage | null,
|
||||||
options: LoadOptions = {}
|
options: LoadOptions = {}
|
||||||
|
|
@ -211,17 +216,12 @@ export class SkinViewer {
|
||||||
} else if (isTextureSource(source)) {
|
} else if (isTextureSource(source)) {
|
||||||
loadEarsToCanvas(this.earsCanvas, source);
|
loadEarsToCanvas(this.earsCanvas, source);
|
||||||
this.earTexture.needsUpdate = true;
|
this.earTexture.needsUpdate = true;
|
||||||
|
this.playerObject.ears.visible = true;
|
||||||
} else {
|
} else {
|
||||||
return loadImage(source).then(image => this.loadEars(image, options));
|
return loadImage(source).then(image => this.loadEars(image, options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected animateCape(options?: LoadOptions): void {
|
|
||||||
if(this.capeImage != undefined) {
|
|
||||||
animateCape(this.capeCanvas, this.capeImage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected resetSkin(): void {
|
protected resetSkin(): void {
|
||||||
this.playerObject.skin.visible = false;
|
this.playerObject.skin.visible = false;
|
||||||
}
|
}
|
||||||
|
|
@ -241,7 +241,9 @@ export class SkinViewer {
|
||||||
this.animations.runAnimationLoop(this.playerObject);
|
this.animations.runAnimationLoop(this.playerObject);
|
||||||
this.render();
|
this.render();
|
||||||
|
|
||||||
this.animateCape({ makeVisible: false })
|
if(this.capeImage != undefined) {
|
||||||
|
this.capeTexture.needsUpdate = animateCape(this.capeCanvas, this.capeImage);
|
||||||
|
}
|
||||||
|
|
||||||
window.requestAnimationFrame(() => this.draw());
|
window.requestAnimationFrame(() => this.draw());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue