-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8922673
commit 6e490a8
Showing
83 changed files
with
9,514 additions
and
1,213 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"sandboxes": ["/demos/ssr"], | ||
"packages": ["dist"], | ||
"node": "14" | ||
} |
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
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 |
---|---|---|
|
@@ -46,3 +46,7 @@ jspm_packages/ | |
pnpm-lock.yaml | ||
|
||
dist | ||
.next | ||
|
||
# storybook | ||
storybook-static |
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,2 +1,5 @@ | ||
dist | ||
.github | ||
.github | ||
.next | ||
node_modules | ||
storybook-static |
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 @@ | ||
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; | ||
} | ||
|
||
main { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
canvas { | ||
width: 100%; | ||
height: 100%; | ||
} |
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,4 @@ | ||
module.exports = { | ||
stories: ['./stories/*.stories.@(js|jsx|ts|tsx)'], | ||
addons: ['@storybook/addon-essentials', '@storybook/addon-controls', '@storybook/addon-storysource'], | ||
} |
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,6 @@ | ||
import { addons } from '@storybook/addons' | ||
|
||
addons.setConfig({ | ||
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,7 @@ | ||
import './index.css' | ||
|
||
export const parameters = { | ||
layout: 'fullscreen', | ||
} | ||
|
||
export const decorators = [(story) => `<canvas id="canvas-root"></canvas>${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 { Camera, Scene, PerspectiveCamera, WebGLRenderer, Clock } from 'three' | ||
//@ts-ignore | ||
import { OrbitControls } from '../src' | ||
|
||
interface useThreeReturn { | ||
camera: Camera | ||
scene: Scene | ||
renderer: WebGLRenderer | ||
} | ||
|
||
interface useFrameProps { | ||
clock: Clock | ||
} | ||
|
||
interface useThreeProps { | ||
useFrame?: ({ clock }: useFrameProps, delta: number) => void | ||
} | ||
|
||
export const useThree = ({ useFrame }: useThreeProps = {}): useThreeReturn => { | ||
const container = document.getElementById('canvas-root') as HTMLCanvasElement | ||
|
||
const renderer = new WebGLRenderer({ | ||
antialias: true, | ||
canvas: container, | ||
alpha: true, | ||
powerPreference: 'high-performance', | ||
}) | ||
renderer.setClearAlpha(0) | ||
renderer.setPixelRatio(window.devicePixelRatio) | ||
renderer.setSize(window.innerWidth, window.innerHeight) | ||
|
||
const camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000) | ||
camera.position.set(0, 0, -5) | ||
camera.lookAt(0, 0, 0) | ||
|
||
const scene = new Scene() | ||
|
||
function onWindowResize() { | ||
camera.aspect = window.innerWidth / window.innerHeight | ||
camera.updateProjectionMatrix() | ||
|
||
renderer.setSize(window.innerWidth, window.innerHeight) | ||
} | ||
|
||
const clock = new Clock() | ||
|
||
const controls = new OrbitControls(camera, container) | ||
controls.enableDamping = true | ||
|
||
function animate() { | ||
if (useFrame) { | ||
useFrame( | ||
{ | ||
clock, | ||
}, | ||
clock.getDelta(), | ||
) | ||
} | ||
|
||
controls.update() | ||
|
||
render() | ||
|
||
requestAnimationFrame(animate) | ||
} | ||
|
||
function render() { | ||
renderer.render(scene, camera) | ||
} | ||
|
||
window.addEventListener('resize', onWindowResize) | ||
|
||
animate() | ||
|
||
return { | ||
camera, | ||
scene, | ||
renderer, | ||
} | ||
} |
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,50 @@ | ||
import { | ||
AmbientLight, | ||
DirectionalLight, | ||
PointLight, | ||
SpotLight, | ||
Mesh, | ||
IcosahedronBufferGeometry, | ||
MeshStandardMaterial, | ||
Color, | ||
} from 'three' | ||
import { useEffect } from '@storybook/client-api' | ||
|
||
import { useThree } from '../setup' | ||
|
||
export default { | ||
title: 'Basic/Scene', | ||
} | ||
|
||
export const Default = () => { | ||
// must run in this so the canvas has mounted in the iframe & can be accessed by `three` | ||
useEffect(() => { | ||
const mesh = new Mesh(new IcosahedronBufferGeometry(1), new MeshStandardMaterial({ color: 'pink' })) | ||
|
||
const ambientLight = new AmbientLight('white', 0.2) | ||
const directionalLight = new DirectionalLight('pink', 2) | ||
directionalLight.position.set(0, -5, 0) | ||
const pointLight1 = new PointLight('pink', 0.4) | ||
pointLight1.position.set(-10, -10, 10) | ||
const pointLight2 = new PointLight('white', 0.2) | ||
pointLight2.position.set(-10, -10, 10) | ||
const spotLight = new SpotLight('white', 2, 35, Math.PI / 4, 2, 3.5) | ||
spotLight.position.set(-3, 6, -4) | ||
|
||
const { scene, renderer } = useThree({ | ||
useFrame: (_, delta) => { | ||
mesh.rotation.x += delta | ||
mesh.rotation.y += delta | ||
}, | ||
}) | ||
|
||
scene.background = new Color(0x0000ff).convertSRGBToLinear() | ||
scene.add(ambientLight, directionalLight, pointLight1, pointLight2, spotLight, mesh) | ||
|
||
return () => { | ||
renderer.dispose() | ||
} | ||
}, []) | ||
|
||
return '' | ||
} |
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,5 @@ | ||
{ | ||
"extends": "../tsconfig", | ||
"exclude": [], | ||
"include": ["./stories/*"] | ||
} |
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
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,12 @@ | ||
{ | ||
"presets": ["next/babel"], | ||
"plugins": [ | ||
[ | ||
"styled-components", | ||
{ | ||
"ssr": true, | ||
"preprocess": false | ||
} | ||
] | ||
] | ||
} |
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 { useEffect, useState } from 'react' | ||
// @ts-ignore | ||
import { OrbitControls } from 'three-stdlib' | ||
import { useThree } from 'react-three-fiber' | ||
|
||
export const Controls = (): JSX.Element | null => { | ||
const { camera, gl, invalidate } = useThree() | ||
|
||
const [controls, setControls] = useState<OrbitControls>() | ||
|
||
useEffect(() => { | ||
setControls(new OrbitControls(camera, gl.domElement)) | ||
}, [camera, gl]) | ||
|
||
useEffect(() => { | ||
if (controls) { | ||
controls.addEventListener('change', invalidate) | ||
} | ||
return (): void => { | ||
if (controls) { | ||
controls.removeEventListener('change', invalidate) | ||
} | ||
} | ||
}, [controls, invalidate]) | ||
|
||
return controls ? <primitive dispose={undefined} object={controls} enableDamping /> : null | ||
} |
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 @@ | ||
export const Lights = (): JSX.Element => { | ||
return ( | ||
<group> | ||
<spotLight position={[-3, 6, -4]} intensity={10} angle={Math.PI / 4} decay={3.5} distance={35} penumbra={2} /> | ||
<pointLight position={[-10, -10, 10]} color="pink" intensity={1} /> | ||
<pointLight position={[-5, -5, 5]} intensity={0.2} /> | ||
<directionalLight position={[0, -5, 0]} color="pink" intensity={2} /> | ||
<ambientLight intensity={0.2} color="white" /> | ||
</group> | ||
) | ||
} |
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 { useRef } from 'react' | ||
import { useFrame } from 'react-three-fiber' | ||
import { Mesh } from 'three' | ||
|
||
import { Lights } from './Lights' | ||
import { Controls } from './Controls' | ||
|
||
export const Scene = (): JSX.Element => { | ||
const meshRef = useRef<Mesh>() | ||
|
||
useFrame((_, delta) => { | ||
const { current: mesh } = meshRef | ||
|
||
if (mesh) { | ||
mesh.rotation.x += delta | ||
mesh.rotation.y += delta | ||
} | ||
}) | ||
|
||
return ( | ||
<> | ||
<Controls /> | ||
<Lights /> | ||
<mesh ref={meshRef}> | ||
<icosahedronBufferGeometry args={[1]} /> | ||
<meshStandardMaterial color="pink" roughness={0} /> | ||
</mesh> | ||
</> | ||
) | ||
} |
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,2 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> |
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,3 @@ | ||
module.exports = { | ||
future: { webpack5: true }, | ||
} |
Oops, something went wrong.