-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from servinlp/feat/storybook
feat: initial storybook setup and shaderMaterial story
- Loading branch information
Showing
12 changed files
with
7,347 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"sandboxes": ["4nc1u", "bfplr", "1wh6f"], | ||
"packages": ["dist"], | ||
"node": "14" | ||
"node": "18" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { PerspectiveCamera, Scene, WebGLRenderer } from 'three' | ||
|
||
export const Setup = () => { | ||
const root = document.querySelector('#root')! | ||
let { width, height } = root?.getBoundingClientRect() | ||
const camera = new PerspectiveCamera(45, width / height, 1, 1000) | ||
camera.position.z = 3 | ||
const renderer = new WebGLRenderer() | ||
const scene = new Scene() | ||
|
||
const resize = () => { | ||
let { width, height } = root?.getBoundingClientRect() | ||
renderer.setSize(width, height) | ||
camera.aspect = width / height | ||
camera.updateProjectionMatrix() | ||
} | ||
|
||
resize() | ||
window.addEventListener('resize', resize) | ||
|
||
const render = (toRender = () => {}) => { | ||
toRender() | ||
|
||
renderer.render(scene, camera) | ||
|
||
requestAnimationFrame(() => render(toRender)) | ||
} | ||
|
||
return { renderer, camera, scene, render } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
html, | ||
body, | ||
#root { | ||
width: 100%; | ||
height: 100%; | ||
margin: 0; | ||
padding: 0; | ||
-webkit-touch-callout: none; | ||
-webkit-user-select: none; | ||
-khtml-user-select: none; | ||
-moz-user-select: none; | ||
-ms-user-select: none; | ||
user-select: none; | ||
overflow: hidden; | ||
background-color: #121212; | ||
} | ||
|
||
#root { | ||
overflow: auto; | ||
} | ||
|
||
.html-story-block { | ||
color: white; | ||
width: 120px; | ||
position: relative; | ||
margin-left: 100px; | ||
} | ||
|
||
.html-story-block.margin300 { | ||
margin-left: 300px; | ||
} | ||
|
||
.html-story-block:before { | ||
content: ''; | ||
display: block; | ||
position: absolute; | ||
|
||
top: 50%; | ||
left: -60px; | ||
|
||
width: 60px; | ||
height: 1px; | ||
background-color: white; | ||
} | ||
|
||
.html-story-label { | ||
background-color: white; | ||
color: black; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 8px; | ||
} | ||
|
||
.html-story-label-B { | ||
font-size: 50px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { resolve } from 'path' | ||
|
||
export default { | ||
staticDirs: ['./public'], | ||
core: { | ||
builder: '@storybook/builder-webpack5', | ||
}, | ||
stories: ['./stories/**/*.stories.{ts,tsx}'], | ||
addons: ['@storybook/addon-controls', '@storybook/addon-actions'], | ||
typescript: { | ||
check: true, | ||
}, | ||
// https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-implicit-postcss-loader | ||
features: { | ||
postcss: false, | ||
}, | ||
webpackFinal: (config) => { | ||
config.module.rules.push({ | ||
test: /\.(glsl|vs|fs|vert|frag)$/, | ||
exclude: /node_modules/, | ||
use: ['raw-loader', 'glslify-loader'], | ||
include: resolve(__dirname, '../'), | ||
}) | ||
|
||
return config | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { addons } from '@storybook/addons' | ||
import theme from './theme' | ||
|
||
addons.setConfig({ | ||
theme, | ||
panelPosition: 'right', | ||
showPanel: true, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import './index.css' | ||
|
||
export const parameters = { | ||
layout: 'fullscreen', | ||
} | ||
|
||
export const decorators = [ | ||
(Story) => { | ||
return Story() | ||
}, | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { BoxGeometry, Mesh, Texture, TextureLoader } from 'three' | ||
import { shaderMaterial } from '../../src/core/shaderMaterial' | ||
import { Setup } from '../Setup' | ||
import { Meta } from '@storybook/html' | ||
import { OrbitControls } from 'three-stdlib' | ||
|
||
export default { | ||
title: 'Shaders/shaderMaterial', | ||
argTypes: { repeats: { control: { type: 'range', min: 1, max: 5, step: 1 } } }, | ||
} as Meta | ||
|
||
const MyMaterial = shaderMaterial( | ||
{ map: new Texture(), repeats: 1 }, | ||
` | ||
varying vec2 vUv; | ||
void main() { | ||
vUv = uv; | ||
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.); | ||
} | ||
`, | ||
` | ||
varying vec2 vUv; | ||
uniform float repeats; | ||
uniform sampler2D map; | ||
float random (vec2 st) { | ||
return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123); | ||
} | ||
void main(){ | ||
vec2 uv = vUv; | ||
uv *= repeats; | ||
uv = fract(uv); | ||
vec3 color = vec3( | ||
texture2D(map, uv).r, | ||
texture2D(map, uv + vec2(0.01,0.01)).g, | ||
texture2D(map, uv - vec2(0.01,0.01)).b | ||
); | ||
gl_FragColor = vec4(color,1.0); | ||
#include <tonemapping_fragment> | ||
#include <encodings_fragment> | ||
} | ||
` | ||
) | ||
|
||
export const ShaderMaterialStory = (args) => { | ||
const { renderer, scene, camera, render } = Setup() | ||
new OrbitControls(camera, renderer.domElement) | ||
|
||
const loader = new TextureLoader() | ||
|
||
loader.load('https://source.unsplash.com/random/400x400', function (texture) { | ||
const geometry = new BoxGeometry(1, 1, 1) | ||
const material = new MyMaterial({ | ||
map: texture, | ||
repeats: args.repeats, | ||
}) | ||
|
||
const mesh = new Mesh(geometry, material) | ||
scene.add(mesh) | ||
|
||
render(() => { | ||
mesh.rotation.x += 0.005 | ||
mesh.rotation.y += 0.01 | ||
}) | ||
}) | ||
|
||
return renderer.domElement | ||
} | ||
|
||
ShaderMaterialStory.storyName = 'Default' | ||
ShaderMaterialStory.args = { | ||
repeats: 2, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { create } from '@storybook/theming/create' | ||
import dreiLogo from '../logo.jpg' | ||
|
||
export default create({ | ||
base: 'light', | ||
brandImage: dreiLogo, | ||
appBg: 'white', | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.