skinview3d/examples/index.html

428 lines
14 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
2020-08-23 22:32:43 +02:00
<meta http-equiv="x-ua-compatible" content="ie=edge">
2020-08-23 22:38:54 +02:00
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>skinview3d</title>
<style>
body {
font-family: "Helvetica Neue", "Helvetica", "Arial", "sans-serif";
2020-08-23 22:32:43 +02:00
margin: 5px;
}
h1 {
font-size: 1.25em;
}
h2 {
font-size: 1em;
}
h1,
h2 {
margin-bottom: 0;
}
input[type="number"] {
2020-08-23 22:32:43 +02:00
max-width: 60px;
}
input[type="text"] {
box-sizing: border-box;
max-width: 250px;
width: calc(100% - 100px);
}
.control {
2020-08-23 22:32:43 +02:00
display: inline;
}
.control + .control {
margin-left: 10px;
}
.control-section {
margin-left: 10px;
}
.control-section>h1,
.control-section>h2 {
margin-left: -10px;
}
table {
border-collapse: collapse;
}
table td,
table th {
border: 1px black dashed;
text-align: left;
}
thead th {
border-top: unset;
}
tbody tr:last-child td,
tbody tr:last-child th {
border-bottom: unset;
}
table th:first-child,
table td:first-child {
border-left: unset;
}
table th:last-child,
table td:last-child {
border-right: unset;
}
table td input[type="checkbox"] {
vertical-align: middle;
margin: 0;
width: 100%;
}
2020-08-17 16:17:21 +02:00
footer {
margin-top: 10px;
padding-top: 10px;
border-top: 1px grey solid;
}
2020-08-23 22:32:43 +02:00
label {
white-space: nowrap;
}
.control-section ul {
margin-top: 0;
padding-left: 20px;
}
</style>
</head>
<body>
<canvas id="skin_container"></canvas>
2020-08-17 16:17:21 +02:00
<div class="controls">
<button id="reset_all" type="button" class="control">Reset All</button>
<div class="control-section">
<h1>Canvas Size</h1>
2020-08-23 22:32:43 +02:00
<label class="control">Width: <input id="canvas_width" type="number" value="300"></label>
<label class="control">Height: <input id="canvas_height" type="number" value="300"></label>
</div>
<div class="control-section">
<h1>Animation</h1>
2020-08-23 22:32:43 +02:00
<label class="control">Global Speed: <input id="global_animation_speed" type="number" value="1" step="0.1"></label>
<button id="animation_pause_resume" type="button" class="control">Pause / Resume</button>
<div>
<h2>Rotate</h2>
2020-08-23 22:32:43 +02:00
<label class="control"><input id="rotate_animation" type="checkbox"> Enable</label>
<label class="control">Speed: <input id="rotate_animation_speed" type="number" value="1" step="0.1"></label>
</div>
<div>
<h2>Walk / Run</h2>
<div class="control">
2020-08-23 22:32:43 +02:00
<label><input type="radio" id="primary_animation_none" name="primary_animation" value="" checked> None</label>
<label><input type="radio" id="primary_animation_walk" name="primary_animation" value="walk"> Walk</label>
<label><input type="radio" id="primary_animation_run" name="primary_animation" value="run"> Run</label>
</div>
2020-08-23 22:32:43 +02:00
<label class="control">Speed: <input id="primary_animation_speed" type="number" value="1" step="0.1"></label>
</div>
</div>
<div class="control-section">
<h1>Mouse Control</h1>
<div class="control">
2020-08-23 22:32:43 +02:00
<label><input type="checkbox" id="control_rotate" checked> Enable Rotate</label>
<label><input type="checkbox" id="control_zoom" checked> Enable Zoom</label>
<label><input type="checkbox" id="control_pan"> Enable Pan</label>
</div>
</div>
<div class="control-section">
<h1>Skin Layers</h1>
2020-08-23 22:32:43 +02:00
<table id="layers_table">
<thead>
<tr>
<th></th>
<th>head</th>
<th>body</th>
<th>right arm</th>
<th>left arm</th>
<th>right leg</th>
<th>left leg</th>
</tr>
</thead>
<tbody>
<tr>
<th>inner</th>
<td><input type="checkbox" data-layer="innerLayer" data-part="head" checked></td>
<td><input type="checkbox" data-layer="innerLayer" data-part="body" checked></td>
<td><input type="checkbox" data-layer="innerLayer" data-part="rightArm" checked></td>
<td><input type="checkbox" data-layer="innerLayer" data-part="leftArm" checked></td>
<td><input type="checkbox" data-layer="innerLayer" data-part="rightLeg" checked></td>
<td><input type="checkbox" data-layer="innerLayer" data-part="leftLeg" checked></td>
</tr>
<tr>
<th>outer</th>
<td><input type="checkbox" data-layer="outerLayer" data-part="head" checked></td>
<td><input type="checkbox" data-layer="outerLayer" data-part="body" checked></td>
<td><input type="checkbox" data-layer="outerLayer" data-part="rightArm" checked></td>
<td><input type="checkbox" data-layer="outerLayer" data-part="leftArm" checked></td>
<td><input type="checkbox" data-layer="outerLayer" data-part="rightLeg" checked></td>
<td><input type="checkbox" data-layer="outerLayer" data-part="leftLeg" checked></td>
</tr>
</tbody>
</table>
</div>
<div class="control-section">
<h1>Textures</h1>
<div>
<div class="control">
2020-08-23 22:32:43 +02:00
<label>Skin URL: <input id="skin_url" type="text" value="img/1_8_texturemap_redux.png" placeholder="none" list="default_skins"></label>
<datalist id="default_skins">
<option value="img/1_8_texturemap_redux.png">
<option value="img/hacksore.png">
<option value="img/haka.png">
<option value="img/hatsune_miku.png">
<option value="img/ironman_hd.png">
<option value="img/sethbling.png">
</datalist>
<input id="skin_url_upload" type="file" accept="image/*" style="display: none;">
<button type="button" class="control"
onclick="document.getElementById('skin_url_upload').click();">Browse...</button>
</div>
2020-08-23 22:32:43 +02:00
<label class="control">Model:
<select id="skin_model" value="auto-detect">
<option value="auto-detect">Auto detect</option>
<option value="default">Default</option>
<option value="slim">Slim</option>
</select>
2020-08-23 22:32:43 +02:00
</label>
</div>
<div>
<div class="control">
2020-08-23 22:32:43 +02:00
<label>Cape URL: <input id="cape_url" type="text" value="" placeholder="none" list="default_capes"></label>
<datalist id="default_capes">
<option value="">
<option value="img/mojang_cape.png">
<option value="img/legacy_cape.png">
<option value="img/hd_cape.png">
</datalist>
<input id="cape_url_upload" type="file" accept="image/*" style="display: none;">
<button type="button" class="control"
onclick="document.getElementById('cape_url_upload').click();">Browse...</button>
</div>
</div>
</div>
<div class="control-section">
<h1>Other examples</h1>
<ul>
<li><a href="offscreen-render.html">offscreen-render</a></li>
</ul>
</div>
</div>
2020-08-17 16:17:21 +02:00
<footer>
<div>
GitHub: <a href="https://github.com/bs-community/skinview3d">bs-community/skinview3d</a>
</div>
<!--%%deploy_only%%
<div>
Built from
commit <a href="https://github.com/bs-community/skinview3d/commit/{{build_commit}}">{{build_commit}}</a>
at <time datetime="{{build_time}}">{{build_time}}</time>
</div>
-->
</footer>
<script src="../bundles/skinview3d.bundle.js"></script>
<script>
const skinParts = ["head", "body", "rightArm", "leftArm", "rightLeg", "leftLeg"];
const skinLayers = ["innerLayer", "outerLayer"];
const availableAnimations = {
walk: skinview3d.WalkingAnimation,
run: skinview3d.RunningAnimation
};
let skinViewer;
let oribitControl;
let rotateAnimation;
let primaryAnimation;
function reloadSkin() {
const input = document.getElementById("skin_url");
const url = input.value;
if (url === "") {
skinViewer.loadSkin(null);
input.setCustomValidity("");
} else {
skinViewer.loadSkin(url, document.getElementById("skin_model").value)
.then(() => input.setCustomValidity(""))
.catch(e => {
input.setCustomValidity("Image can't be loaded.");
console.error(e);
});
}
}
function reloadCape() {
const input = document.getElementById("cape_url");
const url = input.value;
if (url === "") {
skinViewer.loadCape(null);
input.setCustomValidity("");
} else {
skinViewer.loadCape(url)
.then(() => input.setCustomValidity(""))
.catch(e => {
input.setCustomValidity("Image can't be loaded.");
console.error(e);
});
}
}
function initializeControls() {
document.getElementById("canvas_width").addEventListener("change", e => skinViewer.width = e.target.value);
document.getElementById("canvas_height").addEventListener("change", e => skinViewer.height = e.target.value);
document.getElementById("global_animation_speed").addEventListener("change", e => skinViewer.animations.speed = e.target.value);
document.getElementById("animation_pause_resume").addEventListener("click", () => skinViewer.animations.paused = !skinViewer.animations.paused);
document.getElementById("rotate_animation").addEventListener("change", e => {
if (e.target.checked && rotateAnimation === null) {
rotateAnimation = skinViewer.animations.add(skinview3d.RotatingAnimation);
rotateAnimation.speed = document.getElementById("rotate_animation_speed").value;
} else if (!e.target.checked && rotateAnimation !== null) {
rotateAnimation.resetAndRemove();
rotateAnimation = null;
}
});
document.getElementById("rotate_animation_speed").addEventListener("change", e => {
if (rotateAnimation !== null) {
rotateAnimation.speed = e.target.value;
}
});
for (const el of document.querySelectorAll('input[type="radio"][name="primary_animation"]')) {
el.addEventListener("change", e => {
if (primaryAnimation !== null) {
primaryAnimation.resetAndRemove();
primaryAnimation = null;
}
if (e.target.value !== "") {
primaryAnimation = skinViewer.animations.add(availableAnimations[e.target.value]);
primaryAnimation.speed = document.getElementById("primary_animation_speed").value;
}
});
}
document.getElementById("primary_animation_speed").addEventListener("change", e => {
if (primaryAnimation !== null) {
primaryAnimation.speed = e.target.value;
}
});
document.getElementById("control_rotate").addEventListener("change", e => oribitControl.enableRotate = e.target.checked);
document.getElementById("control_zoom").addEventListener("change", e => oribitControl.enableZoom = e.target.checked);
document.getElementById("control_pan").addEventListener("change", e => oribitControl.enablePan = e.target.checked);
for (const part of skinParts) {
for (const layer of skinLayers) {
document.querySelector(`#layers_table input[type="checkbox"][data-part="${part}"][data-layer="${layer}"]`)
.addEventListener("change", e => skinViewer.playerObject.skin[part][layer].visible = e.target.checked);
}
}
const skinReader = new FileReader();
skinReader.addEventListener("load", e => {
document.getElementById("skin_url").value = skinReader.result;
reloadSkin();
});
document.getElementById("skin_url_upload").addEventListener("change", e => {
const file = e.target.files[0];
if (file !== undefined) {
skinReader.readAsDataURL(file);
}
});
const capeReader = new FileReader();
capeReader.addEventListener("load", e => {
document.getElementById("cape_url").value = capeReader.result;
reloadCape();
});
document.getElementById("cape_url_upload").addEventListener("change", e => {
const file = e.target.files[0];
if (file !== undefined) {
capeReader.readAsDataURL(file);
}
});
document.getElementById("skin_url").addEventListener("change", () => reloadSkin());
document.getElementById("skin_model").addEventListener("change", () => reloadSkin());
document.getElementById("cape_url").addEventListener("change", () => reloadCape());
document.getElementById("reset_all").addEventListener("click", () => {
skinViewer.dispose();
initializeViewer();
});
}
function initializeViewer() {
skinViewer = new skinview3d.FXAASkinViewer({
canvas: document.getElementById("skin_container"),
2020-08-23 17:29:40 +02:00
alpha: false
});
skinViewer.renderer.setClearColor(0x5a76f3);
oribitControl = skinview3d.createOrbitControls(skinViewer);
rotateAnimation = null;
primaryAnimation = null;
skinViewer.width = document.getElementById("canvas_width").value;
skinViewer.height = document.getElementById("canvas_height").value;
skinViewer.animations.speed = document.getElementById("global_animation_speed").value;
if (document.getElementById("rotate_animation").checked) {
rotateAnimation = skinViewer.animations.add(skinview3d.RotatingAnimation);
rotateAnimation.speed = document.getElementById("rotate_animation_speed").value;
}
const primaryAnimationName = document.querySelector('input[type="radio"][name="primary_animation"]:checked').value;
if (primaryAnimationName !== "") {
primaryAnimation = skinViewer.animations.add(availableAnimations[primaryAnimationName]);
primaryAnimation.speed = document.getElementById("primary_animation_speed").value;
}
oribitControl.enableRotate = document.getElementById("control_rotate").checked;
oribitControl.enableZoom = document.getElementById("control_zoom").checked;
oribitControl.enablePan = document.getElementById("control_pan").checked;
for (const part of skinParts) {
for (const layer of skinLayers) {
skinViewer.playerObject.skin[part][layer].visible =
document.querySelector(`#layers_table input[type="checkbox"][data-part="${part}"][data-layer="${layer}"]`).checked;
}
}
reloadSkin();
reloadCape();
}
initializeControls();
initializeViewer();
</script>
</body>
2020-08-23 20:26:33 +02:00
<script type="module" src="https://unpkg.com/stats.js@0.17.0/src/Stats.js" integrity="sha384-W71K+d2HbqXqQWSj3Vj4RDsIVvIV7lR8O6RArKAiqB39ntwLci0W08qOn4Z1n8sM" crossorigin="anonymous" async></script>
<script type="module" async>
import Stats from "https://unpkg.com/stats.js@0.17.0/src/Stats.js";
const stats = new Stats();
stats.dom.style.left = "";
stats.dom.style.right = "0";
document.body.appendChild(stats.dom);
function loop() {
stats.update();
requestAnimationFrame(loop)
}
requestAnimationFrame(loop);
</script>
</html>