From 61aa9753af614ae65ad9b58528a28e6b180e3b69 Mon Sep 17 00:00:00 2001 From: Haowei Wen Date: Sat, 10 Oct 2020 10:22:17 +0800 Subject: [PATCH] Add PlayerObject.backEquipment property --- README.md | 6 +++++- examples/index.html | 22 +++++++++++++++++++++- examples/offscreen-render.html | 14 +++++++++----- src/model.ts | 17 +++++++++++++++++ src/viewer.ts | 31 ++++++++++++++++--------------- 5 files changed, 68 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 09176db..a467084 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Three.js powered Minecraft skin viewer. * 1.8 Skins * HD Skins * Capes +* Elytras * Slim Arms * Automatic model detection (Slim / Default) @@ -37,7 +38,10 @@ Three.js powered Minecraft skin viewer. // Load a cape skinViewer.loadCape("img/cape.png"); - // Unload(hide) the cape + // Load a elytra (from a cape texture) + skinViewer.loadCape("img/cape.png", { backEquipment: "elytra" }); + + // Unload(hide) the cape / elytra skinViewer.loadCape(null); // Control objects with your mouse! diff --git a/examples/index.html b/examples/index.html index dcd8b41..0e0e12e 100644 --- a/examples/index.html +++ b/examples/index.html @@ -182,6 +182,13 @@ +
+

Back Equipment

+
+ + +
+
@@ -284,7 +291,8 @@ skinViewer.loadCape(null); input.setCustomValidity(""); } else { - skinViewer.loadCape(url) + const selectedBackEquipment = document.querySelector('input[type="radio"][name="back_equipment"]:checked'); + skinViewer.loadCape(url, { backEquipment: selectedBackEquipment.value }) .then(() => input.setCustomValidity("")) .catch(e => { input.setCustomValidity("Image can't be loaded."); @@ -363,6 +371,18 @@ document.getElementById("skin_url").addEventListener("change", () => reloadSkin()); document.getElementById("skin_model").addEventListener("change", () => reloadSkin()); document.getElementById("cape_url").addEventListener("change", () => reloadCape()); + + for (const el of document.querySelectorAll('input[type="radio"][name="back_equipment"]')) { + el.addEventListener("change", e => { + if (skinViewer.playerObject.backEquipment === null) { + // cape texture hasn't been loaded yet + // this option will be processed on texture loading + } else { + skinViewer.playerObject.backEquipment = e.target.value; + } + }); + } + document.getElementById("reset_all").addEventListener("click", () => { skinViewer.dispose(); orbitControl.dispose(); diff --git a/examples/offscreen-render.html b/examples/offscreen-render.html index 5ebbfb2..662c209 100644 --- a/examples/offscreen-render.html +++ b/examples/offscreen-render.html @@ -12,7 +12,7 @@