Skip to content

Commit c2c8515

Browse files
author
Michalis Dobekidis
committed
fix: merge conflicts for sprite-animator
2 parents a8d7c5d + 583564f commit c2c8515

File tree

111 files changed

+3097
-1776
lines changed

Some content is hidden

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

111 files changed

+3097
-1776
lines changed

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"singleQuote": true,
55
"tabWidth": 2,
66
"printWidth": 120,
7-
"useTabs": false
7+
"useTabs": false,
8+
"endOfLine": "auto"
89
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as React from 'react'
2+
3+
import { Setup } from '../Setup'
4+
5+
import { useFrame } from '@react-three/fiber'
6+
import { BufferGeometry, MeshStandardMaterial, type Mesh } from 'three'
7+
import { Icosahedron, Plane, ShadowAlpha } from '../../src'
8+
9+
export default {
10+
title: 'Misc/ShadowAlpha',
11+
component: ShadowAlpha,
12+
decorators: [(storyFn) => <Setup lights={false}> {storyFn()}</Setup>],
13+
}
14+
15+
function ShadowAlphaScene() {
16+
const mesh = React.useRef<Mesh<BufferGeometry, MeshStandardMaterial>>(null!)
17+
18+
useFrame(({ clock }) => {
19+
const time = clock.elapsedTime
20+
mesh.current.material.opacity = Math.sin(time * 2) * 0.5 + 0.5
21+
})
22+
23+
return (
24+
<>
25+
<Icosahedron castShadow ref={mesh} args={[1, 2]} position-y={2}>
26+
<meshStandardMaterial color="lightblue" transparent />
27+
<ShadowAlpha />
28+
</Icosahedron>
29+
30+
<Plane receiveShadow args={[4, 4]} rotation={[-Math.PI / 2, 0, 0]}>
31+
<meshStandardMaterial color="white" />
32+
</Plane>
33+
34+
<directionalLight castShadow position={[10, 40, 10]} />
35+
<ambientLight intensity={0.5} />
36+
</>
37+
)
38+
}
39+
40+
export const ShadowAlphaSt = () => <ShadowAlphaScene />
41+
ShadowAlphaSt.storyName = 'Default'

README.md

Lines changed: 159 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
7777
<li><a href="#outlines">Outlines</a></li>
7878
<li><a href="#trail">Trail</a></li>
7979
<li><a href="#sampler">Sampler</a></li>
80-
<li><a href="#computedattribute">Computed Attribute</a></li>
80+
<li><a href="#computedattribute">ComputedAttribute</a></li>
8181
<li><a href="#clone">Clone</a></li>
8282
<li><a href="#useanimations">useAnimations</a></li>
8383
<li><a href="#marchingcubes">MarchingCubes</a></li>
8484
<li><a href="#decal">Decal</a></li>
8585
<li><a href="#svg">Svg</a></li>
8686
<li><a href="#gltf">Gltf</a></li>
8787
<li><a href="#asciirenderer">AsciiRenderer</a></li>
88+
<li><a href="#splat">Splat</a></li>
8889
</ul>
8990
<li><a href="#shaders">Shaders</a></li>
9091
<ul>
@@ -160,7 +161,8 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
160161
<li><a href="#view">View</a></li>
161162
<li><a href="#rendertexture">RenderTexture</a></li>
162163
<li><a href="#rendercubetexture">RenderCubeTexture</a></li>
163-
<li><a href="#mask">Mask</a></li>
164+
<li><a href="#fisheye">Fisheye</a></li>
165+
<li><a href="#mask">Mask</a></li>
164166
<li><a href="#meshportalmaterial">MeshPortalMaterial</a></li>
165167
</ul>
166168
<li><a href="#modifiers">Modifiers</a></li>
@@ -225,6 +227,7 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
225227
<li><a href="#useenvironment">useEnvironment</a></li>
226228
<li><a href="#usematcaptexture">useMatcapTexture</a></li>
227229
<li><a href="#usenormaltexture">useNormalTexture</a></li>
230+
<li><a href="#shadowalpha">ShadowAlpha</a></li>
228231
</ul>
229232
</ul>
230233
</td>
@@ -855,7 +858,7 @@ function Loop() {
855858
// Set the current position along the curve, you can increment indiscriminately for a loop
856859
motion.current += delta
857860
// Look ahead on the curve
858-
motion.object.lookAt(motion.next)
861+
motion.object.current.lookAt(motion.next)
859862
})
860863
}
861864

@@ -1325,6 +1328,20 @@ To make the material transparent:
13251328
<Image url="/file.jpg" transparent opacity={0.5} />
13261329
```
13271330

1331+
You can have custom planes, for instance a rounded-corner plane.
1332+
1333+
```jsx
1334+
import { extend } from '@react-three/fiber'
1335+
import { Image } from '@react-three/drei'
1336+
import { easing, geometry } from 'maath'
1337+
1338+
extend({ RoundedPlaneGeometry: geometry.RoundedPlaneGeometry })
1339+
1340+
<Image url="/file.jpg">
1341+
<roundedPlaneGeometry args={[1, 2, 0.15]} />
1342+
</Image>
1343+
```
1344+
13281345
#### Text
13291346

13301347
[![](https://img.shields.io/badge/-storybook-%23ff69b4)](https://drei.vercel.app/?path=/story/abstractions-text--text-st) ![](https://img.shields.io/badge/-suspense-brightgreen)
@@ -1768,10 +1785,12 @@ The decal box has to intersect the surface, otherwise it will not be visible. if
17681785
position={[0, 0, 0]} // Position of the decal
17691786
rotation={[0, 0, 0]} // Rotation of the decal (can be a vector or a degree in radians)
17701787
scale={1} // Scale of the decal
1771-
polygonOffset
1772-
polygonOffsetFactor={-1} // The mesh should take precedence over the original
17731788
>
1774-
<meshBasicMaterial map={texture} />
1789+
<meshBasicMaterial
1790+
map={texture}
1791+
polygonOffset
1792+
polygonOffsetFactor={-1} // The material should take precedence over the original
1793+
/>
17751794
</Decal>
17761795
</mesh>
17771796
```
@@ -1846,6 +1865,46 @@ type AsciiRendererProps = {
18461865
<AsciiRenderer />
18471866
```
18481867

1868+
#### Splat
1869+
1870+
<p>
1871+
<a href="https://codesandbox.io/s/qp4jmf"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/qp4jmf/screenshot.png" alt="Demo"/></a>
1872+
</p>
1873+
1874+
A declarative abstraction around [antimatter15/splat](https://github.com/antimatter15/splat). It supports re-use, multiple splats with correct depth sorting, splats can move and behave as a regular object3d's, supports alphahash & alphatest, and stream-loading.
1875+
1876+
```tsx
1877+
type SplatProps = {
1878+
/** Url towards a *.splat file, no support for *.ply */
1879+
src: string
1880+
/** Whether to use tone mapping, default: false */
1881+
toneMapped?: boolean
1882+
/** Alpha test value, , default: 0 */
1883+
alphaTest?: number
1884+
/** Whether to use alpha hashing, default: false */
1885+
alphaHash?: boolean
1886+
/** Chunk size for lazy loading, prevents chokings the worker, default: 25000 (25kb) */
1887+
chunkSize?: number
1888+
} & JSX.IntrinsicElements['mesh']
1889+
```
1890+
1891+
```jsx
1892+
<Splat src="https://huggingface.co/cakewalk/splat-data/resolve/main/nike.splat" />
1893+
```
1894+
1895+
In order to depth sort multiple splats correectly you can either use alphaTest, for instance with a low value. But keep in mind that this can show a slight outline under some viewing conditions.
1896+
1897+
```jsx
1898+
<Splat alphaTest={0.1} src="foo.splat" />
1899+
<Splat alphaTest={0.1} src="bar.splat" />
1900+
```
1901+
1902+
You can also use alphaHash, but this can be slower and create some noise, you would typically get rid of the noise in postprocessing with a TAA pass. You don't have to use alphaHash on all splats.
1903+
1904+
```jsx
1905+
<Splat alphaHash src="foo.splat" />
1906+
```
1907+
18491908
# Shaders
18501909

18511910
#### MeshReflectorMaterial
@@ -2368,6 +2427,16 @@ Enable shadows using the `castShadow` and `recieveShadow` prop.
23682427

23692428
> Note: Html 'blending' mode only correctly occludes rectangular HTML elements by default. Use the `geometry` prop to swap the backing geometry to a custom one if your Html has a different shape.
23702429

2430+
If transform mode is enabled, the dimensions of the rendered html will depend on the position relative to the camera, the camera fov and the distanceFactor. For example, an Html component placed at (0,0,0) and with a distanceFactor of 10, rendered inside a scene with a perspective camera positioned at (0,0,2.45) and a FOV of 75, will have the same dimensions as a "plain" html element like in [this example](https://codesandbox.io/s/drei-html-magic-number-6mzt6m).
2431+
2432+
A caveat of transform mode is that on some devices and browsers, the rendered html may appear blurry, as discussed in [#859](https://github.com/pmndrs/drei/issues/859). The issue can be at least mitigated by scaling down the Html parent and scaling up the html children:
2433+
2434+
```jsx
2435+
<Html transform scale={0.5}>
2436+
<div style={{ transform: 'scale(2)' }}>Some text</div>
2437+
</Html>
2438+
```
2439+
23712440
#### CycleRaycast
23722441

23732442
![](https://img.shields.io/badge/-Dom only-red)
@@ -2466,7 +2535,7 @@ type Props = {
24662535
onLoopEnd?: Function
24672536
/** Event callback when each frame changes */
24682537
onFrame?: Function
2469-
/** Control when the animation runs */
2538+
/** @deprecated Control when the animation runs*/
24702539
play?: boolean
24712540
/** Control when the animation pauses */
24722541
pause?: boolean
@@ -2480,6 +2549,8 @@ type Props = {
24802549
offset?: number
24812550
/** Allows the sprite animation to start from the end towards the start */
24822551
playBackwards: boolean
2552+
/** Allows the animation to be paused after it ended so it can be restarted on demand via auto */
2553+
resetOnEnd?: boolean
24832554
}
24842555
```
24852556
@@ -3266,7 +3337,12 @@ A wrapper around [THREE.LineSegments](https://threejs.org/docs/#api/en/objects/L
32663337
##### Prop based:
32673338

32683339
```jsx
3269-
<Segments limit={1000} lineWidth={1.0}>
3340+
<Segments
3341+
limit={1000}
3342+
lineWidth={1.0}
3343+
// All THREE.LineMaterial props are valid
3344+
{...materialProps}
3345+
>
32703346
<Segment start={[0, 0, 0]} end={[0, 10, 0]} color="red" />
32713347
<Segment start={[0, 0, 0]} end={[0, 10, 10]} color={[1, 0, 1]} />
32723348
</Segments>
@@ -3378,6 +3454,14 @@ export interface BVHOptions {
33783454
maxDepth?: number
33793455
/** The number of triangles to aim for in a leaf node, default: 10 */
33803456
maxLeafTris?: number
3457+
/** If false then an index buffer is created if it does not exist and is rearranged */
3458+
/** to hold the bvh structure. If false then a separate buffer is created to store the */
3459+
/** structure and the index buffer (or lack thereof) is retained. This can be used */
3460+
/** when the existing index layout is important or groups are being used so a */
3461+
/** single BVH hierarchy can be created to improve performance. */
3462+
/** default: false */
3463+
/** Note: This setting is experimental */
3464+
indirect?: boolean
33813465
}
33823466

33833467
export type BvhProps = BVHOptions &
@@ -3621,10 +3705,6 @@ type Props = JSX.IntrinsicElements['texture'] & {
36213705

36223706
#### RenderCubeTexture
36233707

3624-
<p>
3625-
<a href="https://codesandbox.io/s/7qytdw"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/7qytdw/screenshot.png" alt="Demo"/></a>
3626-
</p>
3627-
36283708
This component allows you to render a live scene into a cubetexture which you can then apply to a material, for instance as an environment map (via the envMap property). The contents of it run inside a portal and are separate from the rest of the canvas, therefore you can have events in there, environment maps, etc.
36293709

36303710
```tsx
@@ -3642,7 +3722,7 @@ export type RenderCubeTextureProps = Omit<JSX.IntrinsicElements['texture'], 'rot
36423722
/** Optional frame count, defaults to Infinity. If you set it to 1, it would only render a single frame, etc */
36433723
frames?: number
36443724
/** Optional event compute, defaults to undefined */
3645-
compute?: (event: any, state: any, previous: any) => false | undefined
3725+
compute?: ComputeFunction
36463726
/** Flip cubemap, see https://github.com/mrdoob/three.js/blob/master/src/renderers/WebGLCubeRenderTarget.js */
36473727
flip?: boolean
36483728
/** Cubemap resolution (for each of the 6 takes), null === full screen resolution, default: 896 */
@@ -3676,6 +3756,37 @@ const api = useRef<RenderCubeTextureApi>(null!)
36763756
<mesh />
36773757
```
36783758

3759+
### Fisheye
3760+
3761+
<p>
3762+
<a href="https://codesandbox.io/s/7qytdw"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/7qytdw/screenshot.png" alt="Demo"/></a>
3763+
</p>
3764+
3765+
```tsx
3766+
export type FisheyeProps = JSX.IntrinsicElements['mesh'] & {
3767+
/** Zoom factor, 0..1, 0 */
3768+
zoom?: number
3769+
/** Number of segments, 64 */
3770+
segments?: number
3771+
/** Cubemap resolution (for each of the 6 takes), null === full screen resolution, default: 896 */
3772+
resolution?: number
3773+
/** Children will be projected into the fisheye */
3774+
children: React.ReactNode
3775+
/** Optional render priority, defaults to 1 */
3776+
renderPriority?: number
3777+
}
3778+
```
3779+
3780+
This component will take over system rendering. It portals its children into a cubemap which is then projected onto a sphere. The sphere is rendered out on the screen, filling it. You can lower the resolution to increase performance. Six renders per frame are necessary to construct a full fisheye view, and since each facet of the cubemap only takes a portion of the screen full resolution is not necessary. You can also reduce the amount of segments (resulting in edgier rounds).
3781+
3782+
```jsx
3783+
<Canvas camera={{ position: [0, 0, 5] }}>
3784+
<Fisheye>
3785+
<YourScene />
3786+
</Fisheye>
3787+
<OrbitControls />
3788+
```
3789+
36793790
#### Mask
36803791

36813792
<p>
@@ -3936,15 +4047,19 @@ For instance, one could want the Html component to be pinned to `positive x`, `p
39364047
<a href="https://codesandbox.io/s/42glz0"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/42glz0/screenshot.png" alt="Demo"/></a>
39374048
</p>
39384049

3939-
Calculates a boundary box and centers the camera accordingly. If you are using camera controls, make sure to pass them the `makeDefault` prop. `fit` fits the current view on first render. `clip` sets the cameras near/far planes. `observe` will trigger on window resize.
4050+
Calculates a boundary box and centers the camera accordingly. If you are using camera controls, make sure to pass them the `makeDefault` prop. `fit` fits the current view on first render. `clip` sets the cameras near/far planes. `observe` will trigger on window resize. To control the damping animation, use `maxDuration` to set the animation length in seconds, and `interpolateFunc` to define how the animation changes over time (should be an increasing function in [0, 1] interval, `interpolateFunc(0) === 0`, `interpolateFunc(1) === 1`).
39404051

39414052
```jsx
3942-
<Bounds fit clip observe damping={6} margin={1.2}>
4053+
const interpolateFunc = (t: number) => 1 - Math.exp(-5 * t) + 0.007 * t // Matches the default Bounds behavior
4054+
const interpolateFunc1 = (t: number) => -t * t * t + 2 * t * t // Start smoothly, finish linearly
4055+
const interpolateFunc2 = (t: number) => -t * t * t + t * t + t // Start linearly, finish smoothly
4056+
4057+
<Bounds fit clip observe margin={1.2} maxDuration={1} interpolateFunc={interpolateFunc}>
39434058
<mesh />
39444059
</Bounds>
39454060
```
39464061

3947-
The Bounds component also acts as a context provider, use the `useBounds` hook to refresh the bounds, fit the camera, clip near/far planes, go to camera orientations or focus objects. `refresh(object?: THREE.Object3D | THREE.Box3)` will recalculate bounds, since this can be expensive only call it when you know the view has changed. `clip` sets the cameras near/far planes. `to` sets a position and target for the camera. `fit` zooms and centers the view.
4062+
The Bounds component also acts as a context provider, use the `useBounds` hook to refresh the bounds, fit the camera, clip near/far planes, go to camera orientations or focus objects. `refresh(object?: THREE.Object3D | THREE.Box3)` will recalculate bounds, since this can be expensive only call it when you know the view has changed. `reset` centers the view. `moveTo` changes the camera position. `lookAt` changes the camera orientation, with the respect to up-vector, if specified. `clip` sets the cameras near/far planes. `fit` centers the view for non-orthographic cameras (same as reset) or zooms the view for orthographic cameras.
39484063

39494064
```jsx
39504065
function Foo() {
@@ -3957,10 +4072,17 @@ function Foo() {
39574072
// bounds.refresh(ref.current).clip().fit()
39584073
// bounds.refresh(new THREE.Box3()).clip().fit()
39594074

3960-
// Or, send the camera to a specific orientatin
3961-
// bounds.to({position: [0, 10, 10], target: {[5, 5, 0]}})
4075+
// Or, move the camera to a specific position, and change its orientation
4076+
// bounds.moveTo([0, 10, 10]).lookAt({ target: [5, 5, 0], up: [0, -1, 0] })
4077+
4078+
// For orthographic cameras, reset has to be used to center the view (fit would only change its zoom to match the bounding box)
4079+
// bounds.refresh().reset().clip().fit()
4080+
}, [...])
4081+
}
4082+
39624083
<Bounds>
39634084
<Foo />
4085+
</Bounds>
39644086
```
39654087

39664088
#### CameraShake
@@ -4078,7 +4200,7 @@ For a little more realistic results enable accumulative shadows, which requires
40784200
```jsx
40794201
<Canvas shadows>
40804202
<Stage shadows="accumulative">
4081-
<mesh castShadows />
4203+
<mesh castShadow />
40824204
</Stage>
40834205
</Canvas>
40844206
```
@@ -4706,3 +4828,21 @@ return (
47064828
...
47074829
)
47084830
```
4831+
4832+
#### ShadowAlpha
4833+
4834+
Makes an object's shadow respect its opacity and alphaMap.
4835+
4836+
```jsx
4837+
<mesh>
4838+
<geometry />
4839+
<material transparent opacity={0.5} />
4840+
4841+
<ShadowAlpha
4842+
opacity={undefined} // number. Override the opacity of the shadow.
4843+
alphaMap={undefined} // THREE.Texture. Override the alphaMap of the shadow
4844+
/>
4845+
</mesh>
4846+
```
4847+
4848+
> Note: This component uses Screendoor transparency using a dither pattern. This pattern is notacible when the camera gets close to the shadow.

0 commit comments

Comments
 (0)