From 99fc6ee5bc28b9250ac7345970793bb04f37fb42 Mon Sep 17 00:00:00 2001 From: yushijinhun Date: Fri, 9 Feb 2018 10:47:08 +0800 Subject: [PATCH] support 22x17 capes, closing #4 --- src/viewer.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index e0f6018..313ab53 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -132,16 +132,28 @@ class SkinViewer { this.capeImg.crossOrigin = ""; this.capeImg.onerror = () => console.error("Failed loading " + this.capeImg.src); this.capeImg.onload = () => { + let isOldFormat = false; if (this.capeImg.width !== 2 * this.capeImg.height) { - console.error("Bad cape size"); - return; + if (this.capeImg.width * 17 == this.capeImg.height * 22) { + // width/height = 22/17 + isOldFormat = true; + } else { + console.error("Bad cape size"); + return; + } } - this.capeCanvas.width = this.capeImg.width; - this.capeCanvas.height = this.capeImg.height; let capeContext = this.capeCanvas.getContext("2d"); + if (isOldFormat) { + let width = this.capeImg.width * 64 / 22; + this.capeCanvas.width = width; + this.capeCanvas.height = width / 2; + } else { + this.capeCanvas.width = this.capeImg.width; + this.capeCanvas.height = this.capeImg.height; + } capeContext.clearRect(0, 0, this.capeCanvas.width, this.capeCanvas.height); - capeContext.drawImage(this.capeImg, 0, 0, this.capeCanvas.width, this.capeCanvas.height); + capeContext.drawImage(this.capeImg, 0, 0, this.capeImg.width, this.capeImg.height); this.capeTexture.needsUpdate = true; this.capeMaterial.needsUpdate = true;