Skip to content

Commit

Permalink
chore: wip csf3
Browse files Browse the repository at this point in the history
  • Loading branch information
abernier committed Jun 1, 2024
1 parent 965519d commit d6c2140
Show file tree
Hide file tree
Showing 26 changed files with 688 additions and 669 deletions.
8 changes: 8 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const config: StorybookConfig = {

typescript: {
reactDocgen: 'react-docgen-typescript',
reactDocgenTypescriptOptions: {
propFilter: (prop, component) => {
// Only include props that belong to the current component
const fileName = prop.declarations?.at(0)?.fileName // 'drei/src/core/AccumulativeShadows.tsx'
const componentName = fileName?.split('/').at(-1)?.split('.').at(0) // 'AccumulativeShadows'
return component.name === componentName
},
},
},
}

Expand Down
42 changes: 27 additions & 15 deletions .storybook/stories/AccumulativeShadows.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import * as THREE from 'three'
import * as React from 'react'
import { ComponentProps } from 'react'
import { FlakesTexture } from 'three/examples/jsm/textures/FlakesTexture'
import { Meta, StoryObj } from '@storybook/react'

import { Setup } from '../Setup'

import { useGLTF, AccumulativeShadows, RandomizedLight, OrbitControls, Environment } from '../../src'

export default {
title: 'Staging/AccumulativeShadows',
component: AccumulativeShadowScene,
component: AccumulativeShadows,
decorators: [(storyFn) => <Setup> {storyFn()}</Setup>],
}
} satisfies Meta<typeof AccumulativeShadows>

type Story = StoryObj<typeof AccumulativeShadows>

function AccumulativeShadowScene() {
function AccumulativeShadowScene(props: ComponentProps<typeof AccumulativeShadows>) {
return (
<React.Suspense fallback={null}>
<color attach="background" args={['goldenrod']} />

<Suzi rotation={[-0.63, 0, 0]} scale={2} position={[0, -1.175, 0]} />
<AccumulativeShadows
temporal
frames={100}
color="goldenrod"
alphaTest={0.65}
opacity={2}
scale={14}
position={[0, -0.5, 0]}
>

<AccumulativeShadows {...props} position={[0, -0.5, 0]}>
<RandomizedLight amount={8} radius={4} ambient={0.5} bias={0.001} position={[5, 5, -10]} />
</AccumulativeShadows>

<OrbitControls autoRotate={true} />
<Environment preset="city" />
</React.Suspense>
)
}

function Suzi(props) {
function Suzi(props: ComponentProps<'group'>) {
const { scene, materials } = useGLTF('/suzanne-high-poly.gltf')
React.useLayoutEffect(() => {
scene.traverse((obj) => (obj as any).isMesh && (obj.receiveShadow = obj.castShadow = true))
Expand All @@ -55,5 +54,18 @@ function Suzi(props) {
return <primitive object={scene} {...props} />
}

export const AccumulativeShadowSt = () => <AccumulativeShadowScene />
AccumulativeShadowSt.storyName = 'Default'
export const AccumulativeShadowSt = {
name: 'Default',
render: (args) => <AccumulativeShadowScene {...args} />,
args: {
temporal: true,
frames: 100,
color: 'goldenrod',
alphaTest: 0.65,
opacity: 2,
scale: 14,
},
argTypes: {
color: { control: 'color' },
},
} satisfies Story
25 changes: 17 additions & 8 deletions .storybook/stories/Adaptive.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Suspense } from 'react'
import React, { ComponentProps, Suspense } from 'react'
import { Vector3 } from 'three'
import { Meta, StoryObj } from '@storybook/react'

import { Setup } from '../Setup'

Expand All @@ -10,7 +11,7 @@ import type { GLTF } from 'three-stdlib'

export default {
title: 'Performance/Adaptive',
component: useGLTF,
component: AdaptiveDpr,
decorators: [
(storyFn) => (
<Setup
Expand All @@ -25,7 +26,9 @@ export default {
</Setup>
),
],
}
} satisfies Meta<typeof AdaptiveDpr>

type Story = StoryObj<typeof AdaptiveDpr>

interface ArcherGLTF extends GLTF {
materials: { material_0: Material }
Expand All @@ -51,7 +54,7 @@ function Archer() {
)
}

function AdaptiveScene() {
function AdaptiveScene(props: ComponentProps<typeof AdaptiveDpr>) {
return (
<>
<Suspense fallback={null}>
Expand All @@ -65,14 +68,20 @@ function AdaptiveScene() {
castShadow
shadow-bias={-0.001}
/>
<AdaptiveDpr pixelated />
<AdaptiveDpr {...props} />
<AdaptiveEvents />
<OrbitControls regress />
</>
)
}

export const AdaptiveSceneSt = () => <AdaptiveScene />
AdaptiveSceneSt.story = {
export const AdaptiveSceneSt = {
name: 'Default',
}
render: (args) => <AdaptiveScene {...args} />,
args: {
pixelated: true,
},
argTypes: {
pixelated: { control: 'boolean' },
},
} satisfies Story
55 changes: 30 additions & 25 deletions .storybook/stories/ArcballControls.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
import { createPortal, useFrame } from '@react-three/fiber'
import React, { useRef, useState } from 'react'
import React, { ComponentProps, useRef, useState } from 'react'
import { Scene } from 'three'
import { Meta, StoryObj } from '@storybook/react'

import { Setup } from '../Setup'
import { ArcballControls, Box, PerspectiveCamera, Plane, useFBO } from '../../src'

import type { OrthographicCamera, PerspectiveCamera as PerspectiveCameraType } from 'three'
import type { ArcballControlsProps } from '../../src'

const args = {
enablePan: true,
enableRotate: true,
enableZoom: true,
}

export const ArcballControlsStory = (props: ArcballControlsProps) => (
<>
<ArcballControls {...props} />
<Box>
<meshBasicMaterial wireframe />
</Box>
</>
)

ArcballControlsStory.args = args
ArcballControlsStory.storyName = 'Default'

export default {
title: 'Controls/ArcballControls',
component: ArcballControls,
decorators: [(storyFn) => <Setup controls={false}>{storyFn()}</Setup>],
args: {
enablePan: true,
enableRotate: true,
enableZoom: true,
},
} satisfies Meta<typeof ArcballControls>

type Story = StoryObj<typeof ArcballControls>

function DefaultScene(props: ComponentProps<typeof ArcballControls>) {
return (
<>
<ArcballControls {...props} />
<Box>
<meshBasicMaterial wireframe />
</Box>
</>
)
}

const CustomCamera = (props: ArcballControlsProps) => {
export const ArcballControlsSt1 = {
render: (args) => <DefaultScene {...args} />,
name: 'Default',
} satisfies Story

const CustomCamera = ({ ...props }: ComponentProps<typeof ArcballControls>) => {
/**
* we will render our scene in a render target and use it as a map.
*/
Expand Down Expand Up @@ -73,7 +78,7 @@ const CustomCamera = (props: ArcballControlsProps) => {
)
}

export const CustomCameraStory = (props: ArcballControlsProps) => <CustomCamera {...props} />

CustomCameraStory.args = args
CustomCameraStory.storyName = 'Custom Camera'
export const ArcballControlsSt2 = {
render: (args) => <CustomCamera {...args} />,
name: 'Custom Camera',
} satisfies Story
68 changes: 31 additions & 37 deletions .storybook/stories/BBAnchor.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as React from 'react'
import { ComponentProps } from 'react'
import * as THREE from 'three'
import { Meta, StoryObj } from '@storybook/react'

import { Setup } from '../Setup'

Expand All @@ -17,27 +19,19 @@ export default {
</Setup>
),
],
argTypes: {
drawBoundingBox: { control: 'boolean' },
anchorX: { control: { type: 'range', min: -1, max: 1, step: 0.1 } },
anchorY: { control: { type: 'range', min: -1, max: 1, step: 0.1 } },
anchorZ: { control: { type: 'range', min: -1, max: 1, step: 0.1 } },
children: { table: { disable: true } },
},
}
} satisfies Meta<typeof BBAnchor>

type Anchor = THREE.Vector3 | [number, number, number]
type Story = StoryObj<typeof BBAnchor>

function BBAnchorScene({
anchor,
drawBoundingBox,
children,
}: {
anchor: Anchor
...props
}: ComponentProps<typeof BBAnchor> & {
drawBoundingBox: boolean
children?: React.ReactChild
children?: React.ReactNode
}) {
const ref = React.useRef()
const ref = React.useRef(null)

useHelper(drawBoundingBox && ref, BoxHelper, 'cyan')

Expand All @@ -46,16 +40,12 @@ function BBAnchorScene({
<OrbitControls autoRotate />
<Icosahedron ref={ref}>
<meshBasicMaterial color="hotpink" wireframe />
<BBAnchor anchor={anchor}>{children}</BBAnchor>
<BBAnchor {...props}>{children}</BBAnchor>
</Icosahedron>
</>
)
}

const Template = ({ drawBoundingBox, anchorX, anchorY, anchorZ, ...args }) => (
<BBAnchorScene drawBoundingBox={drawBoundingBox} anchor={[anchorX, anchorY, anchorZ]} {...args} />
)

function HtmlComp() {
return (
<Html
Expand All @@ -70,15 +60,17 @@ function HtmlComp() {
)
}

export const BBAnchorWithHtml = Template.bind({})
BBAnchorWithHtml.args = {
drawBoundingBox: true,
anchorX: 1,
anchorY: 1,
anchorZ: 1,
children: <HtmlComp />,
}
BBAnchorWithHtml.storyName = 'With Html component'
export const BBAnchorWithHtml = {
render: (args) => (
<BBAnchorScene {...args} drawBoundingBox={true}>
<HtmlComp />
</BBAnchorScene>
),
args: {
anchor: [1, 1, 1],
},
name: 'With Html component',
} satisfies Story

function MeshComp() {
return (
Expand All @@ -88,12 +80,14 @@ function MeshComp() {
)
}

export const BBAnchorWithMesh = Template.bind({})
BBAnchorWithMesh.args = {
drawBoundingBox: true,
anchorX: 1,
anchorY: 1,
anchorZ: 1,
children: <MeshComp />,
}
BBAnchorWithMesh.storyName = 'With other mesh'
export const BBAnchorWithMesh = {
render: (args) => (
<BBAnchorScene {...args} drawBoundingBox={true}>
<MeshComp />
</BBAnchorScene>
),
args: {
anchor: [1, 1, 1],
},
name: 'With other mesh',
} satisfies Story
Loading

0 comments on commit d6c2140

Please sign in to comment.