skinview3d/stories/index.stories.js

97 lines
2.0 KiB
JavaScript
Raw Normal View History

2020-03-14 03:52:20 +01:00
/* eslint-disable */
import * as skinview3d from '../libs/skinview3d';
2020-03-14 05:40:36 +01:00
import { withKnobs, radios, number } from '@storybook/addon-knobs';
2020-03-14 03:52:20 +01:00
export default {
title: 'Skinview3d',
decorators: [withKnobs]
};
2020-03-14 05:40:36 +01:00
let currentAnimation;
2020-03-14 03:52:20 +01:00
const createViewer = () => {
const element = document.createElement('div');
element.style.width = '400px';
element.style.height = '500px';
let viewer = new skinview3d.SkinViewer({
domElement: element,
width: 600,
height: 600,
2020-03-14 05:40:36 +01:00
skinUrl: 'texture/1_8_texturemap_redux.png',
2020-03-14 03:52:20 +01:00
});
let control = skinview3d.createOrbitControls(viewer);
control.enableRotate = true;
control.enableZoom = false;
control.enablePan = false;
return { viewer, element };
}
2020-03-14 05:40:36 +01:00
let { viewer, element } = createViewer();
2020-03-14 03:52:20 +01:00
export const NoAnimation = () => {
2020-03-14 05:40:36 +01:00
if (currentAnimation) {
currentAnimation.remove();
}
2020-03-14 03:52:20 +01:00
return element;
};
export const WithAnimation = () => {
2020-03-14 05:40:36 +01:00
if (currentAnimation) {
currentAnimation.remove();
}
const animationMap = {
'Walk': skinview3d.WalkingAnimation,
'Run': skinview3d.RunningAnimation,
'Rotate': skinview3d.RotatingAnimation,
};
const animationKey = radios('Animations', Object.keys(animationMap), 'Run');
currentAnimation = viewer.animations.add(animationMap[animationKey]);
2020-03-14 03:52:20 +01:00
const label = 'Speed';
2020-03-14 05:40:36 +01:00
2020-03-14 03:52:20 +01:00
const defaultValue = 1;
const options = {
range: true,
min: 0.1,
max: 3,
step: 0.01,
};
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-03-14 05:40:36 +01:00
export const TestTextures = () => {
2020-03-14 03:52:20 +01:00
2020-03-14 05:40:36 +01:00
const skinOptions = {
2020-03-14 03:52:20 +01:00
'1.8 Skin': '1_8_texturemap_redux',
'Classic Skin': 'Hacksore',
'HD Skin': 'ironman_hd',
};
2020-03-14 05:40:36 +01: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 = {
'None': 'none',
'Classic Cape': 'cape',
'HD Cape': 'hd_cape',
};
2020-03-14 03:52:20 +01:00
2020-03-14 05:40:36 +01:00
const capeUrl = radios('Cape Textures', capeOptions, 'none');
2020-03-14 03:52:20 +01:00
viewer.skinUrl = `texture/${skinUrl}.png`;
2020-03-14 05:40:36 +01:00
// Will fix with #48
viewer.capeUrl = capeUrl !== 'none' ? `texture/${capeUrl}.png` : null;
2020-03-14 03:52:20 +01:00
return element;
};