From d583b6d4f209620053029fc4c5a88e653a8f91dc Mon Sep 17 00:00:00 2001 From: Sean Boult <996134+Hacksore@users.noreply.github.com> Date: Tue, 28 Jul 2020 19:08:07 -0500 Subject: [PATCH] Refactor into a single story --- examples/stories/animation.story.js | 49 --------------- examples/stories/basic.story.js | 19 ------ .../{textures.story.js => demo.story.js} | 60 ++++++++++++++++++- examples/stories/util.js | 2 +- 4 files changed, 58 insertions(+), 72 deletions(-) delete mode 100644 examples/stories/animation.story.js delete mode 100644 examples/stories/basic.story.js rename examples/stories/{textures.story.js => demo.story.js} (64%) diff --git a/examples/stories/animation.story.js b/examples/stories/animation.story.js deleted file mode 100644 index 27d659b..0000000 --- a/examples/stories/animation.story.js +++ /dev/null @@ -1,49 +0,0 @@ -/* eslint-disable */ -import { createViewer } from "./util"; -import { withKnobs, number } from "@storybook/addon-knobs"; -import * as skinview3d from "../.."; -import { radios } from "@storybook/addon-knobs"; - -let { viewer, element, defaultAnimation } = createViewer(); -let currentAnimation = defaultAnimation; - -export default { - title: "Skinview3d", - name: "Animation", - decorators: [withKnobs], -}; - -export const Animation = () => { - if (currentAnimation) { - currentAnimation.remove(); - } - - const animationMap = { - Walk: skinview3d.WalkingAnimation, - Run: skinview3d.RunningAnimation, - Rotate: skinview3d.RotatingAnimation, - }; - - const animationKey = radios("Animations", Object.keys(animationMap), "Run"); - - if (currentAnimation) { - currentAnimation.resetAndRemove(); - } - - currentAnimation = viewer.animations.add(animationMap[animationKey]); - - const label = "Speed"; - - const defaultValue = 0.5; - const options = { - range: true, - min: 0.1, - max: 2, - step: 0.01, - }; - const value = number(label, defaultValue, options); - - currentAnimation.speed = value; - - return element; -}; diff --git a/examples/stories/basic.story.js b/examples/stories/basic.story.js deleted file mode 100644 index b74f2c5..0000000 --- a/examples/stories/basic.story.js +++ /dev/null @@ -1,19 +0,0 @@ -/* eslint-disable */ -import { createViewer } from "./util"; -import { withKnobs, number } from "@storybook/addon-knobs"; -let { viewer, element } = createViewer(); - -export default { - title: "Skinview3d", - name: "Basic", - decorators: [withKnobs], -}; - -export const Basic = () => { - const width = number("Canvas Width", 300); - const height = number("Canvas Height", 400); - - viewer.setSize(width, height); - - return element; -}; diff --git a/examples/stories/textures.story.js b/examples/stories/demo.story.js similarity index 64% rename from examples/stories/textures.story.js rename to examples/stories/demo.story.js index 4b460fa..c0b4fdb 100644 --- a/examples/stories/textures.story.js +++ b/examples/stories/demo.story.js @@ -1,8 +1,11 @@ /* eslint-disable */ +import * as skinview3d from "../../libs/skinview3d"; import { createViewer } from "./util"; -import { radios, withKnobs, optionsKnob } from "@storybook/addon-knobs"; +import { radios, withKnobs, optionsKnob, number } from "@storybook/addon-knobs"; let { viewer, element } = createViewer(); +let currentAnimation; + const bodyParts = viewer.playerObject.skin; const skinParts = {}; @@ -24,11 +27,17 @@ skinParts.rightLeg2 = bodyParts.rightLeg.outerLayer; export default { title: "Skinview3d", - name: "Textures", decorators: [withKnobs], }; -export const Textures = () => { +const handleSizeControl = () => { + const width = number("Canvas Width", 300); + const height = number("Canvas Height", 400); + + viewer.setSize(width, height); +}; + +const handleTextureControl = () => { const skinOptions = { "1.8 Skin": "1_8_texturemap_redux", "Classic Skin": "Hacksore", @@ -98,6 +107,51 @@ export const Textures = () => { skinParts[partName].visible = visible; } +}; + +const handleAnimationControl = () => { + if (currentAnimation) { + currentAnimation.remove(); + } + + const animationMap = { + None: null, + Walk: skinview3d.WalkingAnimation, + Run: skinview3d.RunningAnimation, + Rotate: skinview3d.RotatingAnimation, + }; + + const animationKey = radios("Animations", Object.keys(animationMap), "Run"); + + console.log("animationKey", animationKey); + if (currentAnimation || animationKey === "None") { + currentAnimation.resetAndRemove(); + } + + currentAnimation = viewer.animations.add(animationMap[animationKey]); + + const label = "Speed"; + + const defaultValue = 0.5; + const options = { + range: true, + min: 0.1, + max: 2, + step: 0.01, + }; + const value = number(label, defaultValue, options); + + currentAnimation.speed = value; +}; + +export const Component = () => { + handleSizeControl(); + handleTextureControl(); + handleAnimationControl(); return element; }; + +Component.story = { + name: "Demo", +}; diff --git a/examples/stories/util.js b/examples/stories/util.js index 44f52bc..d5cb5b0 100644 --- a/examples/stories/util.js +++ b/examples/stories/util.js @@ -17,5 +17,5 @@ export const createViewer = (config) => { control.enableZoom = true; control.enablePan = true; - return { viewer, element }; + return { viewer, element: viewer.domElement }; };