@react-three/fiber 8.0.7 → 8.0.8
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/CHANGELOG.md +7 -1
- package/dist/declarations/src/core/events.d.ts +69 -69
- package/dist/declarations/src/core/hooks.d.ts +21 -25
- package/dist/declarations/src/core/index.d.ts +56 -42
- package/dist/declarations/src/core/loop.d.ts +13 -13
- package/dist/declarations/src/core/renderer.d.ts +51 -51
- package/dist/declarations/src/core/store.d.ts +91 -109
- package/dist/declarations/src/core/utils.d.ts +83 -57
- package/dist/declarations/src/index.d.ts +10 -10
- package/dist/declarations/src/native/Canvas.d.ts +8 -13
- package/dist/declarations/src/native/events.d.ts +4 -5
- package/dist/declarations/src/native.d.ts +10 -10
- package/dist/declarations/src/three-types.d.ts +327 -326
- package/dist/declarations/src/web/Canvas.d.ts +9 -13
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/{index-e42f8ac9.esm.js → index-548cf96a.esm.js} +101 -16
- package/dist/{index-75d39ab1.cjs.dev.js → index-b8ee55f0.cjs.dev.js} +103 -15
- package/dist/{index-4fb4daff.cjs.prod.js → index-c4e0ac66.cjs.prod.js} +103 -15
- package/dist/react-three-fiber.cjs.dev.js +25 -49
- package/dist/react-three-fiber.cjs.prod.js +25 -49
- package/dist/react-three-fiber.esm.js +24 -47
- package/native/dist/react-three-fiber-native.cjs.dev.js +21 -45
- package/native/dist/react-three-fiber-native.cjs.prod.js +21 -45
- package/native/dist/react-three-fiber-native.esm.js +20 -43
- package/package.json +1 -1
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import type { Options as ResizeOptions } from 'react-use-measure';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
resize?: ResizeOptions;
|
|
11
|
-
events?: (store: UseBoundStore<RootState>) => EventManager<any>;
|
|
12
|
-
}
|
|
13
|
-
export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Options as ResizeOptions } from 'react-use-measure';
|
|
3
|
+
import { RenderProps } from '../core';
|
|
4
|
+
export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size'>, React.HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
fallback?: React.ReactNode;
|
|
7
|
+
resize?: ResizeOptions;
|
|
8
|
+
}
|
|
9
|
+
export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UseBoundStore } from 'zustand';
|
|
2
|
-
import { RootState } from '../core/store';
|
|
3
|
-
import { EventManager } from '../core/events';
|
|
4
|
-
export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
|
|
1
|
+
import { UseBoundStore } from 'zustand';
|
|
2
|
+
import { RootState } from '../core/store';
|
|
3
|
+
import { EventManager } from '../core/events';
|
|
4
|
+
export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
|
|
@@ -10,6 +10,47 @@ var threeTypes = /*#__PURE__*/Object.freeze({
|
|
|
10
10
|
__proto__: null
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
+
// React currently throws a warning when using useLayoutEffect on the server.
|
|
14
|
+
// To get around it, we can conditionally useEffect on the server (no-op) and
|
|
15
|
+
// useLayoutEffect on the client.
|
|
16
|
+
const isSSR = typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
|
|
17
|
+
const useIsomorphicLayoutEffect = isSSR ? React.useEffect : React.useLayoutEffect;
|
|
18
|
+
function Block({
|
|
19
|
+
set
|
|
20
|
+
}) {
|
|
21
|
+
useIsomorphicLayoutEffect(() => {
|
|
22
|
+
set(new Promise(() => null));
|
|
23
|
+
return () => set(false);
|
|
24
|
+
}, [set]);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
class ErrorBoundary extends React.Component {
|
|
28
|
+
constructor(...args) {
|
|
29
|
+
super(...args);
|
|
30
|
+
this.state = {
|
|
31
|
+
error: false
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
componentDidCatch(error) {
|
|
36
|
+
this.props.set(error);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
render() {
|
|
40
|
+
return this.state.error ? null : this.props.children;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
46
|
+
error: true
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
function useMemoizedFn(fn) {
|
|
50
|
+
const fnRef = React.useRef(fn);
|
|
51
|
+
useIsomorphicLayoutEffect(() => void (fnRef.current = fn), [fn]);
|
|
52
|
+
return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
|
|
53
|
+
}
|
|
13
54
|
const DEFAULT = '__default';
|
|
14
55
|
const isDiffSet = def => def && !!def.memoized && !!def.changes;
|
|
15
56
|
function calculateDpr(dpr) {
|
|
@@ -182,10 +223,7 @@ function detach(parent, child, type) {
|
|
|
182
223
|
target,
|
|
183
224
|
key
|
|
184
225
|
} = resolve(parent, type);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (previous === undefined) delete target[key]; // Otherwise set the previous value
|
|
188
|
-
else target[key] = previous;
|
|
226
|
+
target[key] = child.__r3f.previousAttach;
|
|
189
227
|
} else (_child$__r3f = child.__r3f) == null ? void 0 : _child$__r3f.previousAttach == null ? void 0 : _child$__r3f.previousAttach(parent, child);
|
|
190
228
|
|
|
191
229
|
(_child$__r3f2 = child.__r3f) == null ? true : delete _child$__r3f2.previousAttach;
|
|
@@ -278,11 +316,9 @@ function applyProps$1(instance, data) {
|
|
|
278
316
|
// use the prop constructor to find the default it should be
|
|
279
317
|
value = new targetProp.constructor(...memoized.args);
|
|
280
318
|
} else if (currentInstance.constructor) {
|
|
281
|
-
var _currentInstance$__r, _currentInstance$__r2;
|
|
282
|
-
|
|
283
319
|
// create a blank slate of the instance and copy the particular parameter.
|
|
284
320
|
// @ts-ignore
|
|
285
|
-
const defaultClassCall = new currentInstance.constructor(...
|
|
321
|
+
const defaultClassCall = new currentInstance.constructor(...currentInstance.__r3f.memoizedProps.args);
|
|
286
322
|
value = defaultClassCall[targetProp]; // destory the instance
|
|
287
323
|
|
|
288
324
|
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
@@ -1372,8 +1408,23 @@ let i;
|
|
|
1372
1408
|
let globalEffects = [];
|
|
1373
1409
|
let globalAfterEffects = [];
|
|
1374
1410
|
let globalTailEffects = [];
|
|
1411
|
+
/**
|
|
1412
|
+
* Adds a global render callback which is called each frame.
|
|
1413
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
1414
|
+
*/
|
|
1415
|
+
|
|
1375
1416
|
const addEffect = callback => createSubs(callback, globalEffects);
|
|
1417
|
+
/**
|
|
1418
|
+
* Adds a global after-render callback which is called each frame.
|
|
1419
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
|
|
1420
|
+
*/
|
|
1421
|
+
|
|
1376
1422
|
const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
|
|
1423
|
+
/**
|
|
1424
|
+
* Adds a global callback which is called when rendering stops.
|
|
1425
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
|
|
1426
|
+
*/
|
|
1427
|
+
|
|
1377
1428
|
const addTail = callback => createSubs(callback, globalTailEffects);
|
|
1378
1429
|
|
|
1379
1430
|
function run(effects, timestamp) {
|
|
@@ -1382,11 +1433,10 @@ function run(effects, timestamp) {
|
|
|
1382
1433
|
|
|
1383
1434
|
let subscribers;
|
|
1384
1435
|
let subscription;
|
|
1385
|
-
let delta;
|
|
1386
1436
|
|
|
1387
1437
|
function render$1(timestamp, state, frame) {
|
|
1388
1438
|
// Run local effects
|
|
1389
|
-
delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1439
|
+
let delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1390
1440
|
|
|
1391
1441
|
if (state.frameloop === 'never' && typeof timestamp === 'number') {
|
|
1392
1442
|
delta = timestamp - state.clock.elapsedTime;
|
|
@@ -1465,7 +1515,17 @@ function createLoop(roots) {
|
|
|
1465
1515
|
|
|
1466
1516
|
return {
|
|
1467
1517
|
loop,
|
|
1518
|
+
|
|
1519
|
+
/**
|
|
1520
|
+
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
1521
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
1522
|
+
*/
|
|
1468
1523
|
invalidate,
|
|
1524
|
+
|
|
1525
|
+
/**
|
|
1526
|
+
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
1527
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
1528
|
+
*/
|
|
1469
1529
|
advance
|
|
1470
1530
|
};
|
|
1471
1531
|
}
|
|
@@ -1475,9 +1535,20 @@ function useStore() {
|
|
|
1475
1535
|
if (!store) throw `R3F hooks can only be used within the Canvas component!`;
|
|
1476
1536
|
return store;
|
|
1477
1537
|
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Accesses R3F's internal state, containing renderer, canvas, scene, etc.
|
|
1540
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
|
|
1541
|
+
*/
|
|
1542
|
+
|
|
1478
1543
|
function useThree(selector = state => state, equalityFn) {
|
|
1479
1544
|
return useStore()(selector, equalityFn);
|
|
1480
1545
|
}
|
|
1546
|
+
/**
|
|
1547
|
+
* Executes a callback before render in a shared frame loop.
|
|
1548
|
+
* Can order effects with render priority or manually render with a positive priority.
|
|
1549
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
|
|
1550
|
+
*/
|
|
1551
|
+
|
|
1481
1552
|
function useFrame(callback, renderPriority = 0) {
|
|
1482
1553
|
const store = useStore();
|
|
1483
1554
|
const subscribe = store.getState().internal.subscribe; // Update ref
|
|
@@ -1488,6 +1559,11 @@ function useFrame(callback, renderPriority = 0) {
|
|
|
1488
1559
|
React.useLayoutEffect(() => subscribe(ref, renderPriority, store), [renderPriority, subscribe, store]);
|
|
1489
1560
|
return null;
|
|
1490
1561
|
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Returns a node graph of an object with named nodes & materials.
|
|
1564
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
|
|
1565
|
+
*/
|
|
1566
|
+
|
|
1491
1567
|
function useGraph(object) {
|
|
1492
1568
|
return React.useMemo(() => buildGraph(object), [object]);
|
|
1493
1569
|
}
|
|
@@ -1504,12 +1580,14 @@ function loadingFn(extensions, onProgress) {
|
|
|
1504
1580
|
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1505
1581
|
};
|
|
1506
1582
|
}
|
|
1583
|
+
/**
|
|
1584
|
+
* Synchronously loads and caches assets with a three loader.
|
|
1585
|
+
*
|
|
1586
|
+
* Note: this hook's caller must be wrapped with `React.Suspense`
|
|
1587
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
|
|
1588
|
+
*/
|
|
1589
|
+
|
|
1507
1590
|
|
|
1508
|
-
function useMemoizedFn(fn) {
|
|
1509
|
-
const fnRef = React.useRef(fn);
|
|
1510
|
-
React.useLayoutEffect(() => void (fnRef.current = fn), [fn]);
|
|
1511
|
-
return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
|
|
1512
|
-
}
|
|
1513
1591
|
function useLoader(Proto, input, extensions, onProgress) {
|
|
1514
1592
|
// Use suspense to load async assets
|
|
1515
1593
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1519,11 +1597,18 @@ function useLoader(Proto, input, extensions, onProgress) {
|
|
|
1519
1597
|
|
|
1520
1598
|
return Array.isArray(input) ? results : results[0];
|
|
1521
1599
|
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Preloads an asset into cache as a side-effect.
|
|
1602
|
+
*/
|
|
1522
1603
|
|
|
1523
1604
|
useLoader.preload = function (Proto, input, extensions) {
|
|
1524
1605
|
const keys = Array.isArray(input) ? input : [input];
|
|
1525
1606
|
return preload(loadingFn(extensions), [Proto, ...keys]);
|
|
1526
1607
|
};
|
|
1608
|
+
/**
|
|
1609
|
+
* Removes a loaded asset from cache.
|
|
1610
|
+
*/
|
|
1611
|
+
|
|
1527
1612
|
|
|
1528
1613
|
useLoader.clear = function (Proto, input) {
|
|
1529
1614
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1770,7 +1855,7 @@ function Provider({
|
|
|
1770
1855
|
onCreated,
|
|
1771
1856
|
rootElement
|
|
1772
1857
|
}) {
|
|
1773
|
-
|
|
1858
|
+
useIsomorphicLayoutEffect(() => {
|
|
1774
1859
|
const state = store.getState(); // Flag the canvas active, rendering will now begin
|
|
1775
1860
|
|
|
1776
1861
|
state.set(state => ({
|
|
@@ -1898,4 +1983,4 @@ reconciler.injectIntoDevTools({
|
|
|
1898
1983
|
});
|
|
1899
1984
|
const act = React.unstable_act;
|
|
1900
1985
|
|
|
1901
|
-
export {
|
|
1986
|
+
export { useGraph as A, Block as B, useLoader as C, ErrorBoundary as E, createRoot as a, useIsomorphicLayoutEffect as b, createEvents as c, unmountComponentAtNode as d, extend as e, context as f, createPortal as g, reconciler as h, applyProps as i, dispose as j, invalidate as k, advance as l, addEffect as m, addAfterEffect as n, omit as o, pick as p, addTail as q, render as r, getRootState as s, threeTypes as t, useMemoizedFn as u, act as v, roots as w, useStore as x, useThree as y, useFrame as z };
|
|
@@ -39,6 +39,47 @@ var threeTypes = /*#__PURE__*/Object.freeze({
|
|
|
39
39
|
__proto__: null
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
+
// React currently throws a warning when using useLayoutEffect on the server.
|
|
43
|
+
// To get around it, we can conditionally useEffect on the server (no-op) and
|
|
44
|
+
// useLayoutEffect on the client.
|
|
45
|
+
const isSSR = typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
|
|
46
|
+
const useIsomorphicLayoutEffect = isSSR ? React__namespace.useEffect : React__namespace.useLayoutEffect;
|
|
47
|
+
function Block({
|
|
48
|
+
set
|
|
49
|
+
}) {
|
|
50
|
+
useIsomorphicLayoutEffect(() => {
|
|
51
|
+
set(new Promise(() => null));
|
|
52
|
+
return () => set(false);
|
|
53
|
+
}, [set]);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
class ErrorBoundary extends React__namespace.Component {
|
|
57
|
+
constructor(...args) {
|
|
58
|
+
super(...args);
|
|
59
|
+
this.state = {
|
|
60
|
+
error: false
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
componentDidCatch(error) {
|
|
65
|
+
this.props.set(error);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
render() {
|
|
69
|
+
return this.state.error ? null : this.props.children;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
75
|
+
error: true
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
function useMemoizedFn(fn) {
|
|
79
|
+
const fnRef = React__namespace.useRef(fn);
|
|
80
|
+
useIsomorphicLayoutEffect(() => void (fnRef.current = fn), [fn]);
|
|
81
|
+
return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
|
|
82
|
+
}
|
|
42
83
|
const DEFAULT = '__default';
|
|
43
84
|
const isDiffSet = def => def && !!def.memoized && !!def.changes;
|
|
44
85
|
function calculateDpr(dpr) {
|
|
@@ -211,10 +252,7 @@ function detach(parent, child, type) {
|
|
|
211
252
|
target,
|
|
212
253
|
key
|
|
213
254
|
} = resolve(parent, type);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (previous === undefined) delete target[key]; // Otherwise set the previous value
|
|
217
|
-
else target[key] = previous;
|
|
255
|
+
target[key] = child.__r3f.previousAttach;
|
|
218
256
|
} else (_child$__r3f = child.__r3f) == null ? void 0 : _child$__r3f.previousAttach == null ? void 0 : _child$__r3f.previousAttach(parent, child);
|
|
219
257
|
|
|
220
258
|
(_child$__r3f2 = child.__r3f) == null ? true : delete _child$__r3f2.previousAttach;
|
|
@@ -307,11 +345,9 @@ function applyProps$1(instance, data) {
|
|
|
307
345
|
// use the prop constructor to find the default it should be
|
|
308
346
|
value = new targetProp.constructor(...memoized.args);
|
|
309
347
|
} else if (currentInstance.constructor) {
|
|
310
|
-
var _currentInstance$__r, _currentInstance$__r2;
|
|
311
|
-
|
|
312
348
|
// create a blank slate of the instance and copy the particular parameter.
|
|
313
349
|
// @ts-ignore
|
|
314
|
-
const defaultClassCall = new currentInstance.constructor(...
|
|
350
|
+
const defaultClassCall = new currentInstance.constructor(...currentInstance.__r3f.memoizedProps.args);
|
|
315
351
|
value = defaultClassCall[targetProp]; // destory the instance
|
|
316
352
|
|
|
317
353
|
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
@@ -1401,8 +1437,23 @@ let i;
|
|
|
1401
1437
|
let globalEffects = [];
|
|
1402
1438
|
let globalAfterEffects = [];
|
|
1403
1439
|
let globalTailEffects = [];
|
|
1440
|
+
/**
|
|
1441
|
+
* Adds a global render callback which is called each frame.
|
|
1442
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
1443
|
+
*/
|
|
1444
|
+
|
|
1404
1445
|
const addEffect = callback => createSubs(callback, globalEffects);
|
|
1446
|
+
/**
|
|
1447
|
+
* Adds a global after-render callback which is called each frame.
|
|
1448
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
|
|
1449
|
+
*/
|
|
1450
|
+
|
|
1405
1451
|
const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
|
|
1452
|
+
/**
|
|
1453
|
+
* Adds a global callback which is called when rendering stops.
|
|
1454
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
|
|
1455
|
+
*/
|
|
1456
|
+
|
|
1406
1457
|
const addTail = callback => createSubs(callback, globalTailEffects);
|
|
1407
1458
|
|
|
1408
1459
|
function run(effects, timestamp) {
|
|
@@ -1411,11 +1462,10 @@ function run(effects, timestamp) {
|
|
|
1411
1462
|
|
|
1412
1463
|
let subscribers;
|
|
1413
1464
|
let subscription;
|
|
1414
|
-
let delta;
|
|
1415
1465
|
|
|
1416
1466
|
function render$1(timestamp, state, frame) {
|
|
1417
1467
|
// Run local effects
|
|
1418
|
-
delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1468
|
+
let delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1419
1469
|
|
|
1420
1470
|
if (state.frameloop === 'never' && typeof timestamp === 'number') {
|
|
1421
1471
|
delta = timestamp - state.clock.elapsedTime;
|
|
@@ -1494,7 +1544,17 @@ function createLoop(roots) {
|
|
|
1494
1544
|
|
|
1495
1545
|
return {
|
|
1496
1546
|
loop,
|
|
1547
|
+
|
|
1548
|
+
/**
|
|
1549
|
+
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
1550
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
1551
|
+
*/
|
|
1497
1552
|
invalidate,
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
1556
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
1557
|
+
*/
|
|
1498
1558
|
advance
|
|
1499
1559
|
};
|
|
1500
1560
|
}
|
|
@@ -1504,9 +1564,20 @@ function useStore() {
|
|
|
1504
1564
|
if (!store) throw `R3F hooks can only be used within the Canvas component!`;
|
|
1505
1565
|
return store;
|
|
1506
1566
|
}
|
|
1567
|
+
/**
|
|
1568
|
+
* Accesses R3F's internal state, containing renderer, canvas, scene, etc.
|
|
1569
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
|
|
1570
|
+
*/
|
|
1571
|
+
|
|
1507
1572
|
function useThree(selector = state => state, equalityFn) {
|
|
1508
1573
|
return useStore()(selector, equalityFn);
|
|
1509
1574
|
}
|
|
1575
|
+
/**
|
|
1576
|
+
* Executes a callback before render in a shared frame loop.
|
|
1577
|
+
* Can order effects with render priority or manually render with a positive priority.
|
|
1578
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
|
|
1579
|
+
*/
|
|
1580
|
+
|
|
1510
1581
|
function useFrame(callback, renderPriority = 0) {
|
|
1511
1582
|
const store = useStore();
|
|
1512
1583
|
const subscribe = store.getState().internal.subscribe; // Update ref
|
|
@@ -1517,6 +1588,11 @@ function useFrame(callback, renderPriority = 0) {
|
|
|
1517
1588
|
React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority, store), [renderPriority, subscribe, store]);
|
|
1518
1589
|
return null;
|
|
1519
1590
|
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Returns a node graph of an object with named nodes & materials.
|
|
1593
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
|
|
1594
|
+
*/
|
|
1595
|
+
|
|
1520
1596
|
function useGraph(object) {
|
|
1521
1597
|
return React__namespace.useMemo(() => buildGraph(object), [object]);
|
|
1522
1598
|
}
|
|
@@ -1533,12 +1609,14 @@ function loadingFn(extensions, onProgress) {
|
|
|
1533
1609
|
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1534
1610
|
};
|
|
1535
1611
|
}
|
|
1612
|
+
/**
|
|
1613
|
+
* Synchronously loads and caches assets with a three loader.
|
|
1614
|
+
*
|
|
1615
|
+
* Note: this hook's caller must be wrapped with `React.Suspense`
|
|
1616
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
|
|
1617
|
+
*/
|
|
1618
|
+
|
|
1536
1619
|
|
|
1537
|
-
function useMemoizedFn(fn) {
|
|
1538
|
-
const fnRef = React__namespace.useRef(fn);
|
|
1539
|
-
React__namespace.useLayoutEffect(() => void (fnRef.current = fn), [fn]);
|
|
1540
|
-
return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
|
|
1541
|
-
}
|
|
1542
1620
|
function useLoader(Proto, input, extensions, onProgress) {
|
|
1543
1621
|
// Use suspense to load async assets
|
|
1544
1622
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1548,11 +1626,18 @@ function useLoader(Proto, input, extensions, onProgress) {
|
|
|
1548
1626
|
|
|
1549
1627
|
return Array.isArray(input) ? results : results[0];
|
|
1550
1628
|
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Preloads an asset into cache as a side-effect.
|
|
1631
|
+
*/
|
|
1551
1632
|
|
|
1552
1633
|
useLoader.preload = function (Proto, input, extensions) {
|
|
1553
1634
|
const keys = Array.isArray(input) ? input : [input];
|
|
1554
1635
|
return suspendReact.preload(loadingFn(extensions), [Proto, ...keys]);
|
|
1555
1636
|
};
|
|
1637
|
+
/**
|
|
1638
|
+
* Removes a loaded asset from cache.
|
|
1639
|
+
*/
|
|
1640
|
+
|
|
1556
1641
|
|
|
1557
1642
|
useLoader.clear = function (Proto, input) {
|
|
1558
1643
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1799,7 +1884,7 @@ function Provider({
|
|
|
1799
1884
|
onCreated,
|
|
1800
1885
|
rootElement
|
|
1801
1886
|
}) {
|
|
1802
|
-
|
|
1887
|
+
useIsomorphicLayoutEffect(() => {
|
|
1803
1888
|
const state = store.getState(); // Flag the canvas active, rendering will now begin
|
|
1804
1889
|
|
|
1805
1890
|
state.set(state => ({
|
|
@@ -1927,6 +2012,8 @@ reconciler.injectIntoDevTools({
|
|
|
1927
2012
|
});
|
|
1928
2013
|
const act = React__namespace.unstable_act;
|
|
1929
2014
|
|
|
2015
|
+
exports.Block = Block;
|
|
2016
|
+
exports.ErrorBoundary = ErrorBoundary;
|
|
1930
2017
|
exports.act = act;
|
|
1931
2018
|
exports.addAfterEffect = addAfterEffect;
|
|
1932
2019
|
exports.addEffect = addEffect;
|
|
@@ -1950,6 +2037,7 @@ exports.threeTypes = threeTypes;
|
|
|
1950
2037
|
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
1951
2038
|
exports.useFrame = useFrame;
|
|
1952
2039
|
exports.useGraph = useGraph;
|
|
2040
|
+
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
1953
2041
|
exports.useLoader = useLoader;
|
|
1954
2042
|
exports.useMemoizedFn = useMemoizedFn;
|
|
1955
2043
|
exports.useStore = useStore;
|
|
@@ -39,6 +39,47 @@ var threeTypes = /*#__PURE__*/Object.freeze({
|
|
|
39
39
|
__proto__: null
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
+
// React currently throws a warning when using useLayoutEffect on the server.
|
|
43
|
+
// To get around it, we can conditionally useEffect on the server (no-op) and
|
|
44
|
+
// useLayoutEffect on the client.
|
|
45
|
+
const isSSR = typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
|
|
46
|
+
const useIsomorphicLayoutEffect = isSSR ? React__namespace.useEffect : React__namespace.useLayoutEffect;
|
|
47
|
+
function Block({
|
|
48
|
+
set
|
|
49
|
+
}) {
|
|
50
|
+
useIsomorphicLayoutEffect(() => {
|
|
51
|
+
set(new Promise(() => null));
|
|
52
|
+
return () => set(false);
|
|
53
|
+
}, [set]);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
class ErrorBoundary extends React__namespace.Component {
|
|
57
|
+
constructor(...args) {
|
|
58
|
+
super(...args);
|
|
59
|
+
this.state = {
|
|
60
|
+
error: false
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
componentDidCatch(error) {
|
|
65
|
+
this.props.set(error);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
render() {
|
|
69
|
+
return this.state.error ? null : this.props.children;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
75
|
+
error: true
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
function useMemoizedFn(fn) {
|
|
79
|
+
const fnRef = React__namespace.useRef(fn);
|
|
80
|
+
useIsomorphicLayoutEffect(() => void (fnRef.current = fn), [fn]);
|
|
81
|
+
return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
|
|
82
|
+
}
|
|
42
83
|
const DEFAULT = '__default';
|
|
43
84
|
const isDiffSet = def => def && !!def.memoized && !!def.changes;
|
|
44
85
|
function calculateDpr(dpr) {
|
|
@@ -211,10 +252,7 @@ function detach(parent, child, type) {
|
|
|
211
252
|
target,
|
|
212
253
|
key
|
|
213
254
|
} = resolve(parent, type);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (previous === undefined) delete target[key]; // Otherwise set the previous value
|
|
217
|
-
else target[key] = previous;
|
|
255
|
+
target[key] = child.__r3f.previousAttach;
|
|
218
256
|
} else (_child$__r3f = child.__r3f) == null ? void 0 : _child$__r3f.previousAttach == null ? void 0 : _child$__r3f.previousAttach(parent, child);
|
|
219
257
|
|
|
220
258
|
(_child$__r3f2 = child.__r3f) == null ? true : delete _child$__r3f2.previousAttach;
|
|
@@ -307,11 +345,9 @@ function applyProps$1(instance, data) {
|
|
|
307
345
|
// use the prop constructor to find the default it should be
|
|
308
346
|
value = new targetProp.constructor(...memoized.args);
|
|
309
347
|
} else if (currentInstance.constructor) {
|
|
310
|
-
var _currentInstance$__r, _currentInstance$__r2;
|
|
311
|
-
|
|
312
348
|
// create a blank slate of the instance and copy the particular parameter.
|
|
313
349
|
// @ts-ignore
|
|
314
|
-
const defaultClassCall = new currentInstance.constructor(...
|
|
350
|
+
const defaultClassCall = new currentInstance.constructor(...currentInstance.__r3f.memoizedProps.args);
|
|
315
351
|
value = defaultClassCall[targetProp]; // destory the instance
|
|
316
352
|
|
|
317
353
|
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
@@ -1401,8 +1437,23 @@ let i;
|
|
|
1401
1437
|
let globalEffects = [];
|
|
1402
1438
|
let globalAfterEffects = [];
|
|
1403
1439
|
let globalTailEffects = [];
|
|
1440
|
+
/**
|
|
1441
|
+
* Adds a global render callback which is called each frame.
|
|
1442
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
1443
|
+
*/
|
|
1444
|
+
|
|
1404
1445
|
const addEffect = callback => createSubs(callback, globalEffects);
|
|
1446
|
+
/**
|
|
1447
|
+
* Adds a global after-render callback which is called each frame.
|
|
1448
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
|
|
1449
|
+
*/
|
|
1450
|
+
|
|
1405
1451
|
const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
|
|
1452
|
+
/**
|
|
1453
|
+
* Adds a global callback which is called when rendering stops.
|
|
1454
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
|
|
1455
|
+
*/
|
|
1456
|
+
|
|
1406
1457
|
const addTail = callback => createSubs(callback, globalTailEffects);
|
|
1407
1458
|
|
|
1408
1459
|
function run(effects, timestamp) {
|
|
@@ -1411,11 +1462,10 @@ function run(effects, timestamp) {
|
|
|
1411
1462
|
|
|
1412
1463
|
let subscribers;
|
|
1413
1464
|
let subscription;
|
|
1414
|
-
let delta;
|
|
1415
1465
|
|
|
1416
1466
|
function render$1(timestamp, state, frame) {
|
|
1417
1467
|
// Run local effects
|
|
1418
|
-
delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1468
|
+
let delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1419
1469
|
|
|
1420
1470
|
if (state.frameloop === 'never' && typeof timestamp === 'number') {
|
|
1421
1471
|
delta = timestamp - state.clock.elapsedTime;
|
|
@@ -1494,7 +1544,17 @@ function createLoop(roots) {
|
|
|
1494
1544
|
|
|
1495
1545
|
return {
|
|
1496
1546
|
loop,
|
|
1547
|
+
|
|
1548
|
+
/**
|
|
1549
|
+
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
1550
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
1551
|
+
*/
|
|
1497
1552
|
invalidate,
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
1556
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
1557
|
+
*/
|
|
1498
1558
|
advance
|
|
1499
1559
|
};
|
|
1500
1560
|
}
|
|
@@ -1504,9 +1564,20 @@ function useStore() {
|
|
|
1504
1564
|
if (!store) throw `R3F hooks can only be used within the Canvas component!`;
|
|
1505
1565
|
return store;
|
|
1506
1566
|
}
|
|
1567
|
+
/**
|
|
1568
|
+
* Accesses R3F's internal state, containing renderer, canvas, scene, etc.
|
|
1569
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
|
|
1570
|
+
*/
|
|
1571
|
+
|
|
1507
1572
|
function useThree(selector = state => state, equalityFn) {
|
|
1508
1573
|
return useStore()(selector, equalityFn);
|
|
1509
1574
|
}
|
|
1575
|
+
/**
|
|
1576
|
+
* Executes a callback before render in a shared frame loop.
|
|
1577
|
+
* Can order effects with render priority or manually render with a positive priority.
|
|
1578
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
|
|
1579
|
+
*/
|
|
1580
|
+
|
|
1510
1581
|
function useFrame(callback, renderPriority = 0) {
|
|
1511
1582
|
const store = useStore();
|
|
1512
1583
|
const subscribe = store.getState().internal.subscribe; // Update ref
|
|
@@ -1517,6 +1588,11 @@ function useFrame(callback, renderPriority = 0) {
|
|
|
1517
1588
|
React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority, store), [renderPriority, subscribe, store]);
|
|
1518
1589
|
return null;
|
|
1519
1590
|
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Returns a node graph of an object with named nodes & materials.
|
|
1593
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
|
|
1594
|
+
*/
|
|
1595
|
+
|
|
1520
1596
|
function useGraph(object) {
|
|
1521
1597
|
return React__namespace.useMemo(() => buildGraph(object), [object]);
|
|
1522
1598
|
}
|
|
@@ -1533,12 +1609,14 @@ function loadingFn(extensions, onProgress) {
|
|
|
1533
1609
|
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1534
1610
|
};
|
|
1535
1611
|
}
|
|
1612
|
+
/**
|
|
1613
|
+
* Synchronously loads and caches assets with a three loader.
|
|
1614
|
+
*
|
|
1615
|
+
* Note: this hook's caller must be wrapped with `React.Suspense`
|
|
1616
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
|
|
1617
|
+
*/
|
|
1618
|
+
|
|
1536
1619
|
|
|
1537
|
-
function useMemoizedFn(fn) {
|
|
1538
|
-
const fnRef = React__namespace.useRef(fn);
|
|
1539
|
-
React__namespace.useLayoutEffect(() => void (fnRef.current = fn), [fn]);
|
|
1540
|
-
return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
|
|
1541
|
-
}
|
|
1542
1620
|
function useLoader(Proto, input, extensions, onProgress) {
|
|
1543
1621
|
// Use suspense to load async assets
|
|
1544
1622
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1548,11 +1626,18 @@ function useLoader(Proto, input, extensions, onProgress) {
|
|
|
1548
1626
|
|
|
1549
1627
|
return Array.isArray(input) ? results : results[0];
|
|
1550
1628
|
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Preloads an asset into cache as a side-effect.
|
|
1631
|
+
*/
|
|
1551
1632
|
|
|
1552
1633
|
useLoader.preload = function (Proto, input, extensions) {
|
|
1553
1634
|
const keys = Array.isArray(input) ? input : [input];
|
|
1554
1635
|
return suspendReact.preload(loadingFn(extensions), [Proto, ...keys]);
|
|
1555
1636
|
};
|
|
1637
|
+
/**
|
|
1638
|
+
* Removes a loaded asset from cache.
|
|
1639
|
+
*/
|
|
1640
|
+
|
|
1556
1641
|
|
|
1557
1642
|
useLoader.clear = function (Proto, input) {
|
|
1558
1643
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1799,7 +1884,7 @@ function Provider({
|
|
|
1799
1884
|
onCreated,
|
|
1800
1885
|
rootElement
|
|
1801
1886
|
}) {
|
|
1802
|
-
|
|
1887
|
+
useIsomorphicLayoutEffect(() => {
|
|
1803
1888
|
const state = store.getState(); // Flag the canvas active, rendering will now begin
|
|
1804
1889
|
|
|
1805
1890
|
state.set(state => ({
|
|
@@ -1927,6 +2012,8 @@ reconciler.injectIntoDevTools({
|
|
|
1927
2012
|
});
|
|
1928
2013
|
const act = React__namespace.unstable_act;
|
|
1929
2014
|
|
|
2015
|
+
exports.Block = Block;
|
|
2016
|
+
exports.ErrorBoundary = ErrorBoundary;
|
|
1930
2017
|
exports.act = act;
|
|
1931
2018
|
exports.addAfterEffect = addAfterEffect;
|
|
1932
2019
|
exports.addEffect = addEffect;
|
|
@@ -1950,6 +2037,7 @@ exports.threeTypes = threeTypes;
|
|
|
1950
2037
|
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
1951
2038
|
exports.useFrame = useFrame;
|
|
1952
2039
|
exports.useGraph = useGraph;
|
|
2040
|
+
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
1953
2041
|
exports.useLoader = useLoader;
|
|
1954
2042
|
exports.useMemoizedFn = useMemoizedFn;
|
|
1955
2043
|
exports.useStore = useStore;
|