@react-three/drei 9.38.2 → 9.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -23
- package/core/CatmullRomLine.d.ts +1 -1
- package/core/CubicBezierLine.d.ts +1 -1
- package/core/QuadraticBezierLine.d.ts +1 -1
- package/package.json +1 -1
- package/web/KeyboardControls.d.ts +11 -6
package/README.md
CHANGED
|
@@ -353,7 +353,7 @@ Scroll controls create a HTML scroll container in front of the canvas. Everythin
|
|
|
353
353
|
You can listen and react to scroll with the `useScroll` hook which gives you useful data like the current scroll `offset`, `delta` and functions for range finding: `range`, `curve` and `visible`. The latter functions are especially useful if you want to react to the scroll offset, for instance if you wanted to fade things in and out if they are in or out of view.
|
|
354
354
|
|
|
355
355
|
```jsx
|
|
356
|
-
|
|
356
|
+
;<ScrollControls
|
|
357
357
|
pages={3} // Each page takes 100% of the height of the canvas
|
|
358
358
|
distance={1} // A factor that increases scroll bar travel (default: 1)
|
|
359
359
|
damping={4} // Friction, higher is faster (default: 4)
|
|
@@ -387,18 +387,19 @@ function Foo(props) {
|
|
|
387
387
|
// Will start increasing when 1 / 3 of the scroll distance is reached,
|
|
388
388
|
// and reach 1 when it reaches 2 / 3rds.
|
|
389
389
|
const b = data.range(1 / 3, 1 / 3)
|
|
390
|
-
|
|
390
|
+
// Same as above but with a margin of 0.1 on both ends
|
|
391
391
|
const c = data.range(1 / 3, 1 / 3, 0.1)
|
|
392
392
|
// Will move between 0-1-0 for the selected range
|
|
393
393
|
const d = data.curve(1 / 3, 1 / 3)
|
|
394
394
|
// Same as above, but with a margin of 0.1 on both ends
|
|
395
|
-
const
|
|
395
|
+
const e = data.curve(1 / 3, 1 / 3, 0.1)
|
|
396
396
|
// Returns true if the offset is in range and false if it isn't
|
|
397
|
-
const
|
|
397
|
+
const f = data.visible(2 / 3, 1 / 3)
|
|
398
398
|
// The visible function can also receive a margin
|
|
399
|
-
const
|
|
399
|
+
const g = data.visible(2 / 3, 1 / 3, 0.1)
|
|
400
400
|
})
|
|
401
401
|
return <mesh ref={ref} {...props} />
|
|
402
|
+
}
|
|
402
403
|
```
|
|
403
404
|
|
|
404
405
|
#### PresentationControls
|
|
@@ -436,11 +437,11 @@ Semi-OrbitControls with spring-physics, polar zoom and snap-back, for presentati
|
|
|
436
437
|
A rudimentary keyboard controller which distributes your defined data-model to the `useKeyboard` hook. It's a rather simple way to get started with keyboard input.
|
|
437
438
|
|
|
438
439
|
```tsx
|
|
439
|
-
type KeyboardControlsState = { [
|
|
440
|
+
type KeyboardControlsState<T extends string = string> = { [K in T]: boolean }
|
|
440
441
|
|
|
441
|
-
type KeyboardControlsEntry = {
|
|
442
|
+
type KeyboardControlsEntry<T extends string = string> = {
|
|
442
443
|
/** Name of the action */
|
|
443
|
-
name:
|
|
444
|
+
name: T
|
|
444
445
|
/** The keys that define it, you can use either event.key, or event.code */
|
|
445
446
|
keys: string[]
|
|
446
447
|
/** If the event receives the keyup event, true by default */
|
|
@@ -461,33 +462,40 @@ type KeyboardControlsProps = {
|
|
|
461
462
|
|
|
462
463
|
You start by wrapping your app, or scene, into `<KeyboardControls>`.
|
|
463
464
|
|
|
464
|
-
```
|
|
465
|
+
```tsx
|
|
466
|
+
enum Controls {
|
|
467
|
+
forward = 'forward',
|
|
468
|
+
back = 'back',
|
|
469
|
+
left = 'left',
|
|
470
|
+
right = 'right',
|
|
471
|
+
jump = 'jump',
|
|
472
|
+
}
|
|
465
473
|
function App() {
|
|
474
|
+
const map = useMemo<KeyboardControlsEntry<Controls>>(()=>[
|
|
475
|
+
{ name: Controls.forward, keys: ['ArrowUp', 'w', 'W'] },
|
|
476
|
+
{ name: Controls.back, keys: ['ArrowDown', 's', 'S'] },
|
|
477
|
+
{ name: Controls.left, keys: ['ArrowLeft', 'a', 'A'] },
|
|
478
|
+
{ name: Controls.right, keys: ['ArrowRight', 'd', 'D'] },
|
|
479
|
+
{ name: Controls.jump, keys: ['Space'] },
|
|
480
|
+
], [])
|
|
466
481
|
return (
|
|
467
|
-
<KeyboardControls
|
|
468
|
-
map={[
|
|
469
|
-
{ name: 'forward', keys: ['ArrowUp', 'w', 'W'] },
|
|
470
|
-
{ name: 'backward', keys: ['ArrowDown', 's', 'S'] },
|
|
471
|
-
{ name: 'leftward', keys: ['ArrowLeft', 'a', 'A'] },
|
|
472
|
-
{ name: 'rightward', keys: ['ArrowRight', 'd', 'D'] },
|
|
473
|
-
{ name: 'jump', keys: ['Space'] },
|
|
474
|
-
]}>
|
|
482
|
+
<KeyboardControls map={map}>
|
|
475
483
|
<App />
|
|
476
484
|
</KeyboardControls>
|
|
477
485
|
```
|
|
478
486
|
|
|
479
487
|
You can either respond to input reactively, it uses zustand (with the `subscribeWithSelector` middleware) so all the rules apply:
|
|
480
488
|
|
|
481
|
-
```
|
|
489
|
+
```tsx
|
|
482
490
|
function Foo() {
|
|
483
|
-
const
|
|
491
|
+
const forwardPressed = useKeyboardControls<Controls>(state => state.forward)
|
|
484
492
|
```
|
|
485
493
|
|
|
486
494
|
Or transiently, either by `subscribe`, which is a function which returns a function to unsubscribe, so you can pair it with useEffect for cleanup, or `get`, which fetches fresh state non-reactively.
|
|
487
495
|
|
|
488
|
-
```
|
|
496
|
+
```tsx
|
|
489
497
|
function Foo() {
|
|
490
|
-
const [sub, get] = useKeyboardControls()
|
|
498
|
+
const [sub, get] = useKeyboardControls<Controls>()
|
|
491
499
|
|
|
492
500
|
useEffect(() => {
|
|
493
501
|
return sub(
|
|
@@ -500,7 +508,7 @@ function Foo() {
|
|
|
500
508
|
|
|
501
509
|
useFrame(() => {
|
|
502
510
|
// Fetch fresh data from store
|
|
503
|
-
const pressed = get().
|
|
511
|
+
const pressed = get().back
|
|
504
512
|
})
|
|
505
513
|
}
|
|
506
514
|
```
|
|
@@ -2398,7 +2406,7 @@ Now refer to it with the `useMask` hook and the same id, your content will now b
|
|
|
2398
2406
|
const stencil = useMask(1)
|
|
2399
2407
|
return (
|
|
2400
2408
|
<mesh>
|
|
2401
|
-
<
|
|
2409
|
+
<torusKnotGeometry />
|
|
2402
2410
|
<meshStandardMaterial {...stencil} />
|
|
2403
2411
|
```
|
|
2404
2412
|
|
package/core/CatmullRomLine.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Line2 } from 'three
|
|
2
|
+
import { Line2 } from 'three-stdlib';
|
|
3
3
|
import { LineProps } from './Line';
|
|
4
4
|
export declare const CatmullRomLine: React.ForwardRefExoticComponent<Omit<LineProps, "ref"> & {
|
|
5
5
|
closed?: boolean | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Vector3 } from 'three';
|
|
3
|
-
import { Line2 } from 'three
|
|
3
|
+
import { Line2 } from 'three-stdlib';
|
|
4
4
|
import { LineProps } from './Line';
|
|
5
5
|
export declare const CubicBezierLine: React.ForwardRefExoticComponent<Omit<LineProps, "ref" | "points"> & {
|
|
6
6
|
start: Vector3 | [number, number, number];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Vector3 } from 'three';
|
|
3
|
-
import { Line2 } from 'three
|
|
3
|
+
import { Line2 } from 'three-stdlib';
|
|
4
4
|
import { LineProps } from './Line';
|
|
5
5
|
import { Object3DNode } from '@react-three/fiber';
|
|
6
6
|
declare type Line2Props = Object3DNode<Line2, typeof Line2> & {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
declare type KeyboardControlsState = {
|
|
4
|
-
[
|
|
2
|
+
import { GetState, Subscribe } from 'zustand';
|
|
3
|
+
declare type KeyboardControlsState<T extends string = string> = {
|
|
4
|
+
[K in T]: boolean;
|
|
5
5
|
};
|
|
6
|
-
declare type KeyboardControlsEntry = {
|
|
7
|
-
name:
|
|
6
|
+
export declare type KeyboardControlsEntry<T extends string = string> = {
|
|
7
|
+
name: T;
|
|
8
8
|
keys: string[];
|
|
9
9
|
up?: boolean;
|
|
10
10
|
};
|
|
@@ -15,5 +15,10 @@ declare type KeyboardControlsProps = {
|
|
|
15
15
|
domElement?: HTMLElement;
|
|
16
16
|
};
|
|
17
17
|
export declare function KeyboardControls({ map, children, onChange, domElement }: KeyboardControlsProps): JSX.Element;
|
|
18
|
-
|
|
18
|
+
declare type Selector<T extends string = string> = (state: KeyboardControlsState<T>) => boolean;
|
|
19
|
+
export declare function useKeyboardControls<T extends string = string>(): [
|
|
20
|
+
Subscribe<KeyboardControlsState<T>>,
|
|
21
|
+
GetState<KeyboardControlsState<T>>
|
|
22
|
+
];
|
|
23
|
+
export declare function useKeyboardControls<T extends string = string>(sel: Selector<T>): ReturnType<Selector<T>>;
|
|
19
24
|
export {};
|