Skip to content

Commit 58ca1a0

Browse files
committed
docs: docs folder
1 parent de3b074 commit 58ca1a0

File tree

130 files changed

+5281
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+5281
-0
lines changed

docs/abstractions/ascii-renderer.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: AsciiRenderer
3+
---
4+
5+
<Grid cols={4}>
6+
<li>
7+
<Codesandbox id="vq9wsl" />
8+
</li>
9+
</Grid>
10+
11+
Abstraction of three's [AsciiEffect](https://threejs.org/examples/?q=as#webgl_effects_ascii). It creates a DOM layer on top of the canvas and renders the scene as ascii characters.
12+
13+
```tsx
14+
type AsciiRendererProps = {
15+
/** Render index, default: 1 */
16+
renderIndex?: number
17+
/** CSS background color (can be "transparent"), default: black */
18+
bgColor?: string
19+
/** CSS character color, default: white */
20+
fgColor?: string
21+
/** Characters, default: ' .:-+*=%@#' */
22+
characters?: string
23+
/** Invert character, default: true */
24+
invert?: boolean
25+
/** Colorize output (very expensive!), default: false */
26+
color?: boolean
27+
/** Level of detail, default: 0.15 */
28+
resolution?: number
29+
}
30+
```
31+
32+
```jsx
33+
<Canvas>
34+
<AsciiRenderer />
35+
```

docs/abstractions/billboard.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Billboard
3+
---
4+
5+
[![](https://img.shields.io/badge/-storybook-%23ff69b4)](https://drei.pmnd.rs/?path=/story/abstractions-billboard--billboard-st)
6+
7+
Adds a `<group />` that always faces the camera.
8+
9+
```jsx
10+
<Billboard
11+
follow={true}
12+
lockX={false}
13+
lockY={false}
14+
lockZ={false} // Lock the rotation on the z axis (default=false)
15+
>
16+
<Text fontSize={1}>I'm a billboard</Text>
17+
</Billboard>
18+
```

docs/abstractions/clone.mdx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: Clone
3+
---
4+
5+
<Grid cols={4}>
6+
<li>
7+
<Codesandbox id="42glz0" />
8+
</li>
9+
</Grid>
10+
11+
Declarative abstraction around THREE.Object3D.clone. This is useful when you want to create a shallow copy of an existing fragment (and Object3D, Groups, etc) into your scene, for instance a group from a loaded GLTF. This clone is now re-usable, but it will still refer to the original geometries and materials.
12+
13+
```ts
14+
<Clone
15+
/** Any pre-existing THREE.Object3D (groups, meshes, ...), or an array of objects */
16+
object: THREE.Object3D | THREE.Object3D[]
17+
/** Children will be placed within the object, or within the group that holds arrayed objects */
18+
children?: React.ReactNode
19+
/** Can clone materials and/or geometries deeply (default: false) */
20+
deep?: boolean | 'materialsOnly' | 'geometriesOnly'
21+
/** The property keys it will shallow-clone (material, geometry, visible, ...) */
22+
keys?: string[]
23+
/** Can either spread over props or fill in JSX children, applies to every mesh within */
24+
inject?: MeshProps | React.ReactNode | ((object: THREE.Object3D) => React.ReactNode)
25+
/** Short access castShadow, applied to every mesh within */
26+
castShadow?: boolean
27+
/** Short access receiveShadow, applied to every mesh within */
28+
receiveShadow?: boolean
29+
/>
30+
```
31+
32+
You create a shallow clone by passing a pre-existing object to the `object` prop.
33+
34+
```jsx
35+
const { nodes } = useGLTF(url)
36+
return (
37+
<Clone object={nodes.table} />
38+
```
39+
40+
Or, multiple objects:
41+
42+
```jsx
43+
<Clone object={[nodes.foo, nodes.bar]} />
44+
```
45+
46+
You can dynamically insert objects, these will apply to anything that isn't a group or a plain object3d (meshes, lines, etc):
47+
48+
```jsx
49+
<Clone object={nodes.table} inject={<meshStandardMaterial color="green" />} />
50+
```
51+
52+
Or make inserts conditional:
53+
54+
```jsx
55+
<Clone object={nodes.table} inject={
56+
{(object) => (object.name === 'table' ? <meshStandardMaterial color="green" /> : null)}
57+
} />
58+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: ComputedAttribute
3+
---
4+
5+
[![](https://img.shields.io/badge/-storybook-%23ff69b4)](https://drei.vercel.app/?path=/story/misc-sampler--sampler-weight-st)
6+
7+
Create and attach an attribute declaratively.
8+
9+
```tsx
10+
<sphereGeometry>
11+
<ComputedAttribute
12+
// attribute will be added to the geometry with this name
13+
name="my-attribute-name"
14+
compute={(geometry) => {
15+
// ...someLogic;
16+
return new THREE.BufferAttribute([1, 2, 3], 1)
17+
}}
18+
// you can pass any BufferAttribute prop to this component, eg.
19+
usage={THREE.StaticReadUsage}
20+
/>
21+
</sphereGeometry>
22+
```

docs/abstractions/decal.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: Decal
3+
---
4+
5+
[![](https://img.shields.io/badge/-storybook-%23ff69b4)](https://drei.pmnd.rs/?path=/story/misc-decal--decal-st)
6+
7+
<Grid cols={4}>
8+
<li>
9+
<Codesandbox id="ymb5d9" />
10+
</li>
11+
</Grid>
12+
13+
Abstraction around Three's `DecalGeometry`. It will use the its parent `mesh` as the decal surface by default.
14+
15+
The decal box has to intersect the surface, otherwise it will not be visible. if you do not specifiy a rotation it will look at the parents center point. You can also pass a single number as the rotation which allows you to spin it.
16+
17+
```js
18+
<mesh>
19+
<sphereGeometry />
20+
<meshBasicMaterial />
21+
<Decal
22+
debug // Makes "bounding box" of the decal visible
23+
position={[0, 0, 0]} // Position of the decal
24+
rotation={[0, 0, 0]} // Rotation of the decal (can be a vector or a degree in radians)
25+
scale={1} // Scale of the decal
26+
>
27+
<meshBasicMaterial
28+
map={texture}
29+
polygonOffset
30+
polygonOffsetFactor={-1} // The material should take precedence over the original
31+
/>
32+
</Decal>
33+
</mesh>
34+
```
35+
36+
If you do not specify a material it will create a transparent meshBasicMaterial with a polygonOffsetFactor of -10.
37+
38+
```jsx
39+
<mesh>
40+
<sphereGeometry />
41+
<meshBasicMaterial />
42+
<Decal map={texture} />
43+
</mesh>
44+
```
45+
46+
If declarative composition is not possible, use the `mesh` prop to define the surface the decal must attach to.
47+
48+
```js
49+
<Decal mesh={ref}>
50+
<meshBasicMaterial map={texture} polygonOffset polygonOffsetFactor={-1} />
51+
</Decal>
52+
```

docs/abstractions/edges.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Edges
3+
---
4+
5+
<Grid cols={4}>
6+
<li>
7+
<Codesandbox id="ny3p4" />
8+
</li>
9+
</Grid>
10+
11+
Abstracts [THREE.EdgesGeometry](https://threejs.org/docs/#api/en/geometries/EdgesGeometry). It pulls the geometry automatically from its parent, optionally you can ungroup it and give it a `geometry` prop. You can give it children, for instance a custom material. Edges is based on `<Line>` and supports all of its props.
12+
13+
```jsx
14+
<mesh>
15+
<boxGeometry />
16+
<meshBasicMaterial />
17+
<Edges
18+
linewidth={4}
19+
scale={1.1}
20+
threshold={15} // Display edges only when the angle between two faces exceeds this value (default=15 degrees)
21+
color="white"
22+
/>
23+
</mesh>
24+
```

docs/abstractions/effects.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Effects
3+
---
4+
5+
Abstraction around threes own [EffectComposer](https://threejs.org/docs/#examples/en/postprocessing/EffectComposer). By default it will prepend a render-pass and a gammacorrection-pass. Children are cloned, `attach` is given to them automatically. You can only use passes or effects in there.
6+
7+
By default it creates a render target with HalfFloatType, RGBAFormat. You can change all of this to your liking, inspect the types.
8+
9+
```jsx
10+
import { SSAOPass } from "three-stdlib"
11+
12+
extend({ SSAOPass })
13+
14+
<Effects multisamping={8} renderIndex={1} disableGamma={false} disableRenderPass={false} disableRender={false}>
15+
<sSAOPass args={[scene, camera, 100, 100]} kernelRadius={1.2} kernelSize={0} />
16+
</Effects>
17+
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: GradientTexture
3+
---
4+
5+
<Grid cols={4}>
6+
<li>
7+
<Codesandbox id="l03yb" />
8+
</li>
9+
</Grid>
10+
11+
A declarative THREE.Texture which attaches to "map" by default. You can use this to create gradient backgrounds.
12+
13+
```jsx
14+
<mesh>
15+
<planeGeometry />
16+
<meshBasicMaterial>
17+
<GradientTexture
18+
stops={[0, 1]} // As many stops as you want
19+
colors={['aquamarine', 'hotpink']} // Colors need to match the number of stops
20+
size={1024} // Size is optional, default = 1024
21+
/>
22+
</meshBasicMaterial>
23+
</mesh>
24+
```
25+
26+
Radial gradient.
27+
28+
```jsx
29+
import { GradientTexture, GradientType } from './GradientTexture'
30+
;<mesh>
31+
<planeGeometry />
32+
<meshBasicMaterial>
33+
<GradientTexture
34+
stops={[0, 0.5, 1]} // As many stops as you want
35+
colors={['aquamarine', 'hotpink', 'yellow']} // Colors need to match the number of stops
36+
size={1024} // Size (height) is optional, default = 1024
37+
width={1024} // Width of the canvas producing the texture, default = 16
38+
type={GradientType.Radial} // The type of the gradient, default = GradientType.Linear
39+
innerCircleRadius={0} // Optional, the radius of the inner circle of the gradient, default = 0
40+
outerCircleRadius={'auto'} // Optional, the radius of the outer circle of the gradient, default = auto
41+
/>
42+
</meshBasicMaterial>
43+
</mesh>
44+
```

docs/abstractions/image.mdx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: Image
3+
---
4+
5+
<Grid cols={4}>
6+
<li>
7+
<Codesandbox id="9s2wd9" />
8+
</li>
9+
<li>
10+
<Codesandbox id="l4klb" />
11+
</li>
12+
<li>
13+
<Codesandbox id="gsm1y" />
14+
</li>
15+
<li>
16+
<Codesandbox id="x8gvs" />
17+
</li>
18+
<li>
19+
<Codesandbox id="yjhzv" />
20+
</li>
21+
</Grid>
22+
23+
A shader-based image component with auto-cover (similar to css/background: cover).
24+
25+
```tsx
26+
export type ImageProps = Omit<JSX.IntrinsicElements['mesh'], 'scale'> & {
27+
segments?: number
28+
scale?: number | [number, number]
29+
color?: Color
30+
zoom?: number
31+
radius?: number
32+
grayscale?: number
33+
toneMapped?: boolean
34+
transparent?: boolean
35+
opacity?: number
36+
side?: THREE.Side
37+
}
38+
```
39+
40+
```jsx
41+
function Foo() {
42+
const ref = useRef()
43+
useFrame(() => {
44+
ref.current.material.radius = ... // between 0 and 1
45+
ref.current.material.zoom = ... // 1 and higher
46+
ref.current.material.grayscale = ... // between 0 and 1
47+
ref.current.material.color.set(...) // mix-in color
48+
})
49+
return <Image ref={ref} url="/file.jpg" />
50+
}
51+
```
52+
53+
To make the material transparent:
54+
55+
```jsx
56+
<Image url="/file.jpg" transparent opacity={0.5} />
57+
```
58+
59+
You can have custom planes, for instance a rounded-corner plane.
60+
61+
```jsx
62+
import { extend } from '@react-three/fiber'
63+
import { Image } from '@react-three/drei'
64+
import { easing, geometry } from 'maath'
65+
66+
extend({ RoundedPlaneGeometry: geometry.RoundedPlaneGeometry })
67+
68+
<Image url="/file.jpg">
69+
<roundedPlaneGeometry args={[1, 2, 0.15]} />
70+
</Image>
71+
```

docs/abstractions/marching-cubes.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: MarchingCubes
3+
---
4+
5+
[![](https://img.shields.io/badge/-storybook-%23ff69b4)](https://drei.pmnd.rs/?path=/story/abstractions-marchingcubes--marching-cubes-story)
6+
7+
An abstraction for threes [MarchingCubes](https://threejs.org/examples/#webgl_marchingcubes)
8+
9+
```jsx
10+
<MarchingCubes resolution={50} maxPolyCount={20000} enableUvs={false} enableColors={true}>
11+
<MarchingCube strength={0.5} subtract={12} color={new Color('#f0f')} position={[0.5, 0.5, 0.5]} />
12+
13+
<MarchingPlane planeType="y" strength={0.5} subtract={12} />
14+
</MarchingCubes>
15+
```

0 commit comments

Comments
 (0)