Skip to content

Commit 3555e73

Browse files
committed
Autofocus story
1 parent 6a20ac6 commit 3555e73

22 files changed

+118
-536
lines changed

β€Ž.storybook/Setup.tsxβ€Ž

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as React from 'react'
2+
import { Vector3 } from 'three'
3+
import { Canvas, Props as CanvasProps } from '@react-three/fiber'
4+
5+
// import { OrbitControls } from '../src'
6+
7+
type Props = React.PropsWithChildren<
8+
CanvasProps & {
9+
cameraFov?: number
10+
cameraPosition?: Vector3
11+
controls?: boolean
12+
lights?: boolean
13+
}
14+
>
15+
16+
export const Setup = ({
17+
children,
18+
cameraFov = 75,
19+
cameraPosition = new Vector3(-5, 5, 5),
20+
controls = true,
21+
lights = true,
22+
...restProps
23+
}: Props) => (
24+
<div style={{ height: '100vh' }}>
25+
<Canvas shadows camera={{ position: cameraPosition, fov: cameraFov }} {...restProps}>
26+
{children}
27+
{lights && (
28+
<>
29+
<ambientLight intensity={0.8} />
30+
<pointLight intensity={1} position={[0, 6, 0]} />
31+
</>
32+
)}
33+
{/* {controls && <OrbitControls makeDefault />} */}
34+
</Canvas>
35+
</div>
36+
)

β€Ž.storybook/preview.tsβ€Ž

Lines changed: 0 additions & 15 deletions
This file was deleted.

β€Ž.storybook/preview.tsxβ€Ž

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react'
2+
import type { Preview } from '@storybook/react'
3+
4+
const preview: Preview = {
5+
parameters: {
6+
// actions: { argTypesRegex: '^on[A-Z].*' },
7+
// controls: {
8+
// matchers: {
9+
// color: /(background|color)$/i,
10+
// date: /Date$/,
11+
// },
12+
// },
13+
layout: 'fullscreen',
14+
},
15+
decorators: [
16+
(Story) => (
17+
<React.Suspense fallback={null}>
18+
<Story />
19+
</React.Suspense>
20+
),
21+
],
22+
}
23+
24+
export default preview

β€Žsrc/Autofocus.stories.tsxβ€Ž

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as THREE from 'three'
2+
import type { Meta, StoryObj } from '@storybook/react'
3+
import { Setup } from '../.storybook/Setup'
4+
5+
import { EffectComposer } from './EffectComposer'
6+
7+
import { Autofocus } from './Autofocus'
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: [(Story) => <Setup cameraPosition={new THREE.Vector3(1, 1, 2)}>{Story()}</Setup>],
14+
tags: ['autodocs'],
15+
// argTypes: {
16+
// debug: {
17+
// control: { type: 'range', min: 0, max: 1, step: 0.01 },
18+
// },
19+
// },
20+
} satisfies Meta<typeof Autofocus>
21+
22+
export default meta
23+
type Story = StoryObj<typeof meta>
24+
25+
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
26+
export const Primary: Story = {
27+
render: (args) => (
28+
<>
29+
<mesh castShadow>
30+
<sphereGeometry args={[0.5, 64, 64]} />
31+
<meshStandardMaterial color="#9d4b4b" />
32+
</mesh>
33+
<mesh castShadow position={[1, 0, -5]}>
34+
<boxGeometry args={[1, 1, 1]} />
35+
<meshStandardMaterial color="#9d4b4b" />
36+
</mesh>
37+
38+
<gridHelper />
39+
40+
<EffectComposer>
41+
<Autofocus {...args} focusRange={0.001} bokehScale={18} />
42+
</EffectComposer>
43+
</>
44+
),
45+
args: {
46+
mouse: true,
47+
debug: 0.04,
48+
bokehScale: 8,
49+
},
50+
}

β€Žsrc/Autofocus.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { CopyPass, DepthPickingPass, DepthOfFieldEffect } from 'postprocessing'
1414
import { DepthOfField, EffectComposerContext } from './index'
1515
import { easing } from 'maath'
1616

17-
export type AutofocusProps = typeof DepthOfField & {
17+
export type AutofocusProps = React.ComponentProps<typeof DepthOfField> & {
1818
target?: [number, number, number]
1919
mouse?: boolean
2020
debug?: number

β€Žsrc/stories/Button.stories.tsβ€Ž

Lines changed: 0 additions & 44 deletions
This file was deleted.

β€Žsrc/stories/Button.tsxβ€Ž

Lines changed: 0 additions & 48 deletions
This file was deleted.

β€Žsrc/stories/Header.stories.tsβ€Ž

Lines changed: 0 additions & 26 deletions
This file was deleted.

β€Žsrc/stories/Header.tsxβ€Ž

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
Β (0)