skinview3d/examples/stories/index.stories.js

101 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-03-14 03:52:20 +01:00
/* eslint-disable */
2020-07-13 20:53:42 +02:00
import * as skinview3d from "../..";
2020-07-10 15:52:13 +02:00
import { withKnobs, radios, number } from "@storybook/addon-knobs";
2020-03-14 03:52:20 +01:00
export default {
2020-07-10 15:52:13 +02:00
title: "Skinview3d",
decorators: [withKnobs],
2020-03-14 03:52:20 +01:00
};
2020-03-14 05:40:36 +01:00
let currentAnimation;
2020-03-14 03:52:20 +01:00
const createViewer = () => {
2020-07-10 15:52:13 +02:00
const element = document.createElement("div");
const viewer = new skinview3d.SkinViewer(element, {
width: 300,
height: 400,
2020-07-13 20:53:42 +02:00
skin: "textures/1_8_texturemap_redux.png",
2020-03-14 03:52:20 +01:00
});
2020-07-10 15:52:13 +02:00
console.log(viewer);
// Control objects with your mouse!
const control = skinview3d.createOrbitControls(viewer);
2020-03-14 03:52:20 +01:00
control.enableRotate = true;
control.enableZoom = false;
control.enablePan = false;
2020-07-10 15:52:13 +02:00
// Add an animation
currentAnimation = viewer.animations.add(skinview3d.WalkingAnimation);
2020-03-14 03:52:20 +01:00
return { viewer, element };
2020-07-10 15:52:13 +02:00
};
2020-03-14 03:52:20 +01:00
2020-03-14 05:40:36 +01:00
let { viewer, element } = createViewer();
2020-03-14 03:52:20 +01:00
2020-07-10 15:52:13 +02:00
export const Basic = () => {
// reset
let { viewer, element } = createViewer();
2020-03-14 05:40:36 +01:00
if (currentAnimation) {
currentAnimation.remove();
}
2020-03-14 03:52:20 +01:00
return element;
};
2020-07-10 15:52:13 +02:00
export const Animation = () => {
2020-03-14 05:40:36 +01:00
if (currentAnimation) {
currentAnimation.remove();
}
const animationMap = {
2020-07-10 15:52:13 +02:00
Walk: skinview3d.WalkingAnimation,
Run: skinview3d.RunningAnimation,
Rotate: skinview3d.RotatingAnimation,
2020-03-14 05:40:36 +01:00
};
2020-07-10 15:52:13 +02:00
const animationKey = radios("Animations", Object.keys(animationMap), "Run");
2020-03-14 05:40:36 +01:00
currentAnimation = viewer.animations.add(animationMap[animationKey]);
2020-03-14 03:52:20 +01:00
2020-07-10 15:52:13 +02:00
const label = "Speed";
2020-03-14 03:52:20 +01:00
2020-07-10 15:52:13 +02:00
const defaultValue = 0.5;
2020-03-14 03:52:20 +01:00
const options = {
2020-07-10 15:52:13 +02:00
range: true,
min: 0.1,
max: 2,
step: 0.01,
2020-03-14 03:52:20 +01:00
};
2020-03-14 05:40:36 +01:00
const value = number(label, defaultValue, options);
2020-03-14 03:52:20 +01:00
2020-03-14 05:40:36 +01:00
currentAnimation.speed = value;
2020-03-14 03:52:20 +01:00
return element;
};
2020-07-10 15:52:13 +02:00
export const Textures = () => {
2020-03-14 05:40:36 +01:00
const skinOptions = {
2020-07-10 15:52:13 +02:00
"1.8 Skin": "1_8_texturemap_redux",
"Classic Skin": "Hacksore",
"HD Skin": "ironman_hd",
2020-03-14 03:52:20 +01:00
};
2020-07-10 15:52:13 +02:00
const skinUrl = radios("Skin Textures", skinOptions, "1_8_texturemap_redux");
2020-03-14 03:52:20 +01:00
2020-03-14 05:40:36 +01:00
const capeOptions = {
2020-07-10 15:52:13 +02:00
None: "none",
"Classic Cape": "cape",
"HD Cape": "hd_cape",
2020-03-14 05:40:36 +01:00
};
2020-03-14 03:52:20 +01:00
2020-07-10 15:52:13 +02:00
const capeUrl = radios("Cape Textures", capeOptions, "none");
2020-07-13 20:53:42 +02:00
viewer.loadSkin(`textures/${skinUrl}.png`);
2020-07-10 15:52:13 +02:00
if (capeUrl === "none") {
viewer.loadCape(null);
2020-07-13 19:11:34 +02:00
} else {
2020-07-13 20:53:42 +02:00
viewer.loadCape(`textures/${capeUrl}.png`);
2020-07-10 15:52:13 +02:00
}
2020-03-14 03:52:20 +01:00
return element;
};