|
| 1 | +import React, { memo } from 'react' |
| 2 | +import * as THREE from 'three' |
| 3 | +import type { Meta, StoryObj } from '@storybook/react' |
| 4 | +import { useGLTF, Center, Resize, AccumulativeShadows, RandomizedLight, Environment, Stats } from '@react-three/drei' |
| 5 | + |
| 6 | +import { Setup } from '../Setup' |
| 7 | +import { EffectComposer, Autofocus } from '../../src' |
| 8 | + |
| 9 | +// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction |
| 10 | +const meta = { |
| 11 | + title: 'Effect/Autofocus', |
| 12 | + component: Autofocus, |
| 13 | + decorators: [ |
| 14 | + (Story) => ( |
| 15 | + <Setup cameraPosition={new THREE.Vector3(-17, 1.5, 13)} cameraFov={20} lights={false}> |
| 16 | + {Story()} |
| 17 | + </Setup> |
| 18 | + ), |
| 19 | + ], |
| 20 | + tags: ['autodocs'], |
| 21 | + // argTypes: { |
| 22 | + // debug: { |
| 23 | + // control: { type: 'range', min: 0, max: 1, step: 0.01 }, |
| 24 | + // }, |
| 25 | + // }, |
| 26 | +} satisfies Meta<typeof Autofocus> |
| 27 | + |
| 28 | +export default meta |
| 29 | +type Story = StoryObj<typeof meta> |
| 30 | + |
| 31 | +// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args |
| 32 | +export const Primary: Story = { |
| 33 | + render: (args) => ( |
| 34 | + <> |
| 35 | + <color attach="background" args={['#303035']} /> |
| 36 | + |
| 37 | + <group position-y={-0.5} position-x={-1}> |
| 38 | + <Center top> |
| 39 | + <Resize scale={3.5}> |
| 40 | + <Suzi rotation={[-0.63, 0, 0]}> |
| 41 | + <meshStandardMaterial color="#9d4b4b" /> |
| 42 | + </Suzi> |
| 43 | + </Resize> |
| 44 | + </Center> |
| 45 | + <Center top position={[-2, 0, 2]}> |
| 46 | + <mesh castShadow> |
| 47 | + <sphereGeometry args={[0.5, 64, 64]} /> |
| 48 | + <meshStandardMaterial color="#9d4b4b" /> |
| 49 | + </mesh> |
| 50 | + </Center> |
| 51 | + <Center top position={[2.5, 0, 1]}> |
| 52 | + <mesh castShadow rotation={[0, Math.PI / 4, 0]}> |
| 53 | + <boxGeometry args={[0.7, 0.7, 0.7]} /> |
| 54 | + <meshStandardMaterial color="#9d4b4b" /> |
| 55 | + </mesh> |
| 56 | + </Center> |
| 57 | + |
| 58 | + <Shadows /> |
| 59 | + <Environment preset="city" /> |
| 60 | + <Stats /> |
| 61 | + </group> |
| 62 | + |
| 63 | + <EffectComposer> |
| 64 | + <Autofocus {...args} /> |
| 65 | + </EffectComposer> |
| 66 | + </> |
| 67 | + ), |
| 68 | + args: { |
| 69 | + mouse: true, |
| 70 | + debug: 0.04, |
| 71 | + bokehScale: 8, |
| 72 | + focusRange: 0.001, |
| 73 | + }, |
| 74 | +} |
| 75 | + |
| 76 | +const Suzi = ({ children, ...props }) => { |
| 77 | + console.log(import.meta.url) |
| 78 | + const { nodes } = useGLTF('/suzi.gltf') as any |
| 79 | + return ( |
| 80 | + <> |
| 81 | + <mesh castShadow receiveShadow geometry={nodes.Suzanne.geometry} {...props}> |
| 82 | + {children} |
| 83 | + </mesh> |
| 84 | + </> |
| 85 | + ) |
| 86 | +} |
| 87 | + |
| 88 | +const Shadows = memo(() => ( |
| 89 | + <AccumulativeShadows temporal frames={100} color="#9d4b4b" colorBlend={0.5} alphaTest={0.9} scale={20}> |
| 90 | + <RandomizedLight amount={8} radius={4} position={[5, 5, -10]} /> |
| 91 | + </AccumulativeShadows> |
| 92 | +)) |
0 commit comments