@react-three/fiber 8.0.5 → 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 +18 -0
- 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 -108
- 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 -327
- package/dist/declarations/src/web/Canvas.d.ts +9 -13
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/{index-635ddfb2.esm.js → index-548cf96a.esm.js} +126 -24
- package/dist/{index-28a77253.cjs.dev.js → index-b8ee55f0.cjs.dev.js} +128 -23
- package/dist/{index-1ff856c3.cjs.prod.js → index-c4e0ac66.cjs.prod.js} +128 -23
- package/dist/react-three-fiber.cjs.dev.js +13 -41
- package/dist/react-three-fiber.cjs.prod.js +13 -41
- package/dist/react-three-fiber.esm.js +12 -39
- package/native/dist/react-three-fiber-native.cjs.dev.js +9 -37
- package/native/dist/react-three-fiber-native.cjs.prod.js +9 -37
- package/native/dist/react-three-fiber-native.esm.js +8 -35
- 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) {
|
|
@@ -831,8 +872,10 @@ function createRenderer(roots, getEventPriority) {
|
|
|
831
872
|
let added = false;
|
|
832
873
|
|
|
833
874
|
if (child) {
|
|
875
|
+
var _child$__r3f, _parentInstance$__r3f;
|
|
876
|
+
|
|
834
877
|
// The attach attribute implies that the object attaches itself on the parent
|
|
835
|
-
if (child.__r3f.attach) {
|
|
878
|
+
if ((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) {
|
|
836
879
|
attach(parentInstance, child, child.__r3f.attach);
|
|
837
880
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
838
881
|
// add in the usual parent-child way
|
|
@@ -842,7 +885,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
842
885
|
// that is, anything that's a child in React but not a child in the scenegraph.
|
|
843
886
|
|
|
844
887
|
|
|
845
|
-
if (!added) parentInstance.__r3f.objects.push(child);
|
|
888
|
+
if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
|
|
846
889
|
if (!child.__r3f) prepare(child, {});
|
|
847
890
|
child.__r3f.parent = parentInstance;
|
|
848
891
|
updateInstance(child);
|
|
@@ -854,7 +897,9 @@ function createRenderer(roots, getEventPriority) {
|
|
|
854
897
|
let added = false;
|
|
855
898
|
|
|
856
899
|
if (child) {
|
|
857
|
-
|
|
900
|
+
var _child$__r3f2, _parentInstance$__r3f2;
|
|
901
|
+
|
|
902
|
+
if ((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) {
|
|
858
903
|
attach(parentInstance, child, child.__r3f.attach);
|
|
859
904
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
860
905
|
child.parent = parentInstance;
|
|
@@ -867,7 +912,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
867
912
|
added = true;
|
|
868
913
|
}
|
|
869
914
|
|
|
870
|
-
if (!added) parentInstance.__r3f.objects.push(child);
|
|
915
|
+
if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
|
|
871
916
|
if (!child.__r3f) prepare(child, {});
|
|
872
917
|
child.__r3f.parent = parentInstance;
|
|
873
918
|
updateInstance(child);
|
|
@@ -881,21 +926,21 @@ function createRenderer(roots, getEventPriority) {
|
|
|
881
926
|
|
|
882
927
|
function removeChild(parentInstance, child, dispose) {
|
|
883
928
|
if (child) {
|
|
884
|
-
var _parentInstance$
|
|
929
|
+
var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
|
|
885
930
|
|
|
886
931
|
// Clear the parent reference
|
|
887
932
|
if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
|
|
888
933
|
|
|
889
|
-
if ((_parentInstance$
|
|
934
|
+
if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
|
|
890
935
|
|
|
891
|
-
if (child.__r3f.attach) {
|
|
936
|
+
if ((_child$__r3f3 = child.__r3f) != null && _child$__r3f3.attach) {
|
|
892
937
|
detach(parentInstance, child, child.__r3f.attach);
|
|
893
938
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
894
|
-
var _child$
|
|
939
|
+
var _child$__r3f4;
|
|
895
940
|
|
|
896
941
|
parentInstance.remove(child); // Remove interactivity
|
|
897
942
|
|
|
898
|
-
if ((_child$
|
|
943
|
+
if ((_child$__r3f4 = child.__r3f) != null && _child$__r3f4.root) {
|
|
899
944
|
removeInteractivity(child.__r3f.root, child);
|
|
900
945
|
}
|
|
901
946
|
} // Allow objects to bail out of recursive dispose alltogether by passing dispose={null}
|
|
@@ -909,14 +954,14 @@ function createRenderer(roots, getEventPriority) {
|
|
|
909
954
|
// when the reconciler calls it, but then carry our own check recursively
|
|
910
955
|
|
|
911
956
|
|
|
912
|
-
const isPrimitive = (_child$
|
|
957
|
+
const isPrimitive = (_child$__r3f5 = child.__r3f) == null ? void 0 : _child$__r3f5.primitive;
|
|
913
958
|
const shouldDispose = dispose === undefined ? child.dispose !== null && !isPrimitive : dispose; // Remove nested child objects. Primitives should not have objects and children that are
|
|
914
959
|
// attached to them declaratively ...
|
|
915
960
|
|
|
916
961
|
if (!isPrimitive) {
|
|
917
|
-
var _child$
|
|
962
|
+
var _child$__r3f6;
|
|
918
963
|
|
|
919
|
-
removeRecursive((_child$
|
|
964
|
+
removeRecursive((_child$__r3f6 = child.__r3f) == null ? void 0 : _child$__r3f6.objects, child, shouldDispose);
|
|
920
965
|
removeRecursive(child.children, child, shouldDispose);
|
|
921
966
|
} // Remove references
|
|
922
967
|
|
|
@@ -1274,7 +1319,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1274
1319
|
initialClick: [0, 0],
|
|
1275
1320
|
initialHits: [],
|
|
1276
1321
|
capturedMap: new Map(),
|
|
1277
|
-
subscribe: (ref, priority
|
|
1322
|
+
subscribe: (ref, priority, store) => {
|
|
1278
1323
|
set(({
|
|
1279
1324
|
internal
|
|
1280
1325
|
}) => ({
|
|
@@ -1288,7 +1333,8 @@ const createStore = (invalidate, advance) => {
|
|
|
1288
1333
|
// highest priority renders last (on top of the other frames)
|
|
1289
1334
|
subscribers: [...internal.subscribers, {
|
|
1290
1335
|
ref,
|
|
1291
|
-
priority
|
|
1336
|
+
priority,
|
|
1337
|
+
store
|
|
1292
1338
|
}].sort((a, b) => a.priority - b.priority)
|
|
1293
1339
|
}
|
|
1294
1340
|
}));
|
|
@@ -1362,8 +1408,23 @@ let i;
|
|
|
1362
1408
|
let globalEffects = [];
|
|
1363
1409
|
let globalAfterEffects = [];
|
|
1364
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
|
+
|
|
1365
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
|
+
|
|
1366
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
|
+
|
|
1367
1428
|
const addTail = callback => createSubs(callback, globalTailEffects);
|
|
1368
1429
|
|
|
1369
1430
|
function run(effects, timestamp) {
|
|
@@ -1371,6 +1432,7 @@ function run(effects, timestamp) {
|
|
|
1371
1432
|
}
|
|
1372
1433
|
|
|
1373
1434
|
let subscribers;
|
|
1435
|
+
let subscription;
|
|
1374
1436
|
|
|
1375
1437
|
function render$1(timestamp, state, frame) {
|
|
1376
1438
|
// Run local effects
|
|
@@ -1385,7 +1447,10 @@ function render$1(timestamp, state, frame) {
|
|
|
1385
1447
|
|
|
1386
1448
|
subscribers = state.internal.subscribers;
|
|
1387
1449
|
|
|
1388
|
-
for (i = 0; i < subscribers.length; i++)
|
|
1450
|
+
for (i = 0; i < subscribers.length; i++) {
|
|
1451
|
+
subscription = subscribers[i];
|
|
1452
|
+
subscription.ref.current(subscription.store.getState(), delta, frame);
|
|
1453
|
+
} // Render content
|
|
1389
1454
|
|
|
1390
1455
|
|
|
1391
1456
|
if (!state.internal.priority && state.gl.render) state.gl.render(state.scene, state.camera); // Decrease frame count
|
|
@@ -1450,7 +1515,17 @@ function createLoop(roots) {
|
|
|
1450
1515
|
|
|
1451
1516
|
return {
|
|
1452
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
|
+
*/
|
|
1453
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
|
+
*/
|
|
1454
1529
|
advance
|
|
1455
1530
|
};
|
|
1456
1531
|
}
|
|
@@ -1460,18 +1535,35 @@ function useStore() {
|
|
|
1460
1535
|
if (!store) throw `R3F hooks can only be used within the Canvas component!`;
|
|
1461
1536
|
return store;
|
|
1462
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
|
+
|
|
1463
1543
|
function useThree(selector = state => state, equalityFn) {
|
|
1464
1544
|
return useStore()(selector, equalityFn);
|
|
1465
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
|
+
|
|
1466
1552
|
function useFrame(callback, renderPriority = 0) {
|
|
1467
|
-
const
|
|
1553
|
+
const store = useStore();
|
|
1554
|
+
const subscribe = store.getState().internal.subscribe; // Update ref
|
|
1468
1555
|
|
|
1469
1556
|
const ref = React.useRef(callback);
|
|
1470
1557
|
React.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
|
|
1471
1558
|
|
|
1472
|
-
React.useLayoutEffect(() => subscribe(ref, renderPriority), [renderPriority, subscribe]);
|
|
1559
|
+
React.useLayoutEffect(() => subscribe(ref, renderPriority, store), [renderPriority, subscribe, store]);
|
|
1473
1560
|
return null;
|
|
1474
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
|
+
|
|
1475
1567
|
function useGraph(object) {
|
|
1476
1568
|
return React.useMemo(() => buildGraph(object), [object]);
|
|
1477
1569
|
}
|
|
@@ -1488,12 +1580,14 @@ function loadingFn(extensions, onProgress) {
|
|
|
1488
1580
|
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1489
1581
|
};
|
|
1490
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
|
+
|
|
1491
1590
|
|
|
1492
|
-
function useMemoizedFn(fn) {
|
|
1493
|
-
const fnRef = React.useRef(fn);
|
|
1494
|
-
React.useLayoutEffect(() => void (fnRef.current = fn), [fn]);
|
|
1495
|
-
return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
|
|
1496
|
-
}
|
|
1497
1591
|
function useLoader(Proto, input, extensions, onProgress) {
|
|
1498
1592
|
// Use suspense to load async assets
|
|
1499
1593
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1503,11 +1597,18 @@ function useLoader(Proto, input, extensions, onProgress) {
|
|
|
1503
1597
|
|
|
1504
1598
|
return Array.isArray(input) ? results : results[0];
|
|
1505
1599
|
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Preloads an asset into cache as a side-effect.
|
|
1602
|
+
*/
|
|
1506
1603
|
|
|
1507
1604
|
useLoader.preload = function (Proto, input, extensions) {
|
|
1508
1605
|
const keys = Array.isArray(input) ? input : [input];
|
|
1509
1606
|
return preload(loadingFn(extensions), [Proto, ...keys]);
|
|
1510
1607
|
};
|
|
1608
|
+
/**
|
|
1609
|
+
* Removes a loaded asset from cache.
|
|
1610
|
+
*/
|
|
1611
|
+
|
|
1511
1612
|
|
|
1512
1613
|
useLoader.clear = function (Proto, input) {
|
|
1513
1614
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1754,7 +1855,7 @@ function Provider({
|
|
|
1754
1855
|
onCreated,
|
|
1755
1856
|
rootElement
|
|
1756
1857
|
}) {
|
|
1757
|
-
|
|
1858
|
+
useIsomorphicLayoutEffect(() => {
|
|
1758
1859
|
const state = store.getState(); // Flag the canvas active, rendering will now begin
|
|
1759
1860
|
|
|
1760
1861
|
state.set(state => ({
|
|
@@ -1804,6 +1905,7 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
1804
1905
|
|
|
1805
1906
|
function createPortal(children, container, state) {
|
|
1806
1907
|
return /*#__PURE__*/React.createElement(Portal, {
|
|
1908
|
+
key: container.uuid,
|
|
1807
1909
|
children: children,
|
|
1808
1910
|
container: container,
|
|
1809
1911
|
state: state
|
|
@@ -1881,4 +1983,4 @@ reconciler.injectIntoDevTools({
|
|
|
1881
1983
|
});
|
|
1882
1984
|
const act = React.unstable_act;
|
|
1883
1985
|
|
|
1884
|
-
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) {
|
|
@@ -860,8 +901,10 @@ function createRenderer(roots, getEventPriority) {
|
|
|
860
901
|
let added = false;
|
|
861
902
|
|
|
862
903
|
if (child) {
|
|
904
|
+
var _child$__r3f, _parentInstance$__r3f;
|
|
905
|
+
|
|
863
906
|
// The attach attribute implies that the object attaches itself on the parent
|
|
864
|
-
if (child.__r3f.attach) {
|
|
907
|
+
if ((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) {
|
|
865
908
|
attach(parentInstance, child, child.__r3f.attach);
|
|
866
909
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
867
910
|
// add in the usual parent-child way
|
|
@@ -871,7 +914,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
871
914
|
// that is, anything that's a child in React but not a child in the scenegraph.
|
|
872
915
|
|
|
873
916
|
|
|
874
|
-
if (!added) parentInstance.__r3f.objects.push(child);
|
|
917
|
+
if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
|
|
875
918
|
if (!child.__r3f) prepare(child, {});
|
|
876
919
|
child.__r3f.parent = parentInstance;
|
|
877
920
|
updateInstance(child);
|
|
@@ -883,7 +926,9 @@ function createRenderer(roots, getEventPriority) {
|
|
|
883
926
|
let added = false;
|
|
884
927
|
|
|
885
928
|
if (child) {
|
|
886
|
-
|
|
929
|
+
var _child$__r3f2, _parentInstance$__r3f2;
|
|
930
|
+
|
|
931
|
+
if ((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) {
|
|
887
932
|
attach(parentInstance, child, child.__r3f.attach);
|
|
888
933
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
889
934
|
child.parent = parentInstance;
|
|
@@ -896,7 +941,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
896
941
|
added = true;
|
|
897
942
|
}
|
|
898
943
|
|
|
899
|
-
if (!added) parentInstance.__r3f.objects.push(child);
|
|
944
|
+
if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
|
|
900
945
|
if (!child.__r3f) prepare(child, {});
|
|
901
946
|
child.__r3f.parent = parentInstance;
|
|
902
947
|
updateInstance(child);
|
|
@@ -910,21 +955,21 @@ function createRenderer(roots, getEventPriority) {
|
|
|
910
955
|
|
|
911
956
|
function removeChild(parentInstance, child, dispose) {
|
|
912
957
|
if (child) {
|
|
913
|
-
var _parentInstance$
|
|
958
|
+
var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
|
|
914
959
|
|
|
915
960
|
// Clear the parent reference
|
|
916
961
|
if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
|
|
917
962
|
|
|
918
|
-
if ((_parentInstance$
|
|
963
|
+
if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
|
|
919
964
|
|
|
920
|
-
if (child.__r3f.attach) {
|
|
965
|
+
if ((_child$__r3f3 = child.__r3f) != null && _child$__r3f3.attach) {
|
|
921
966
|
detach(parentInstance, child, child.__r3f.attach);
|
|
922
967
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
923
|
-
var _child$
|
|
968
|
+
var _child$__r3f4;
|
|
924
969
|
|
|
925
970
|
parentInstance.remove(child); // Remove interactivity
|
|
926
971
|
|
|
927
|
-
if ((_child$
|
|
972
|
+
if ((_child$__r3f4 = child.__r3f) != null && _child$__r3f4.root) {
|
|
928
973
|
removeInteractivity(child.__r3f.root, child);
|
|
929
974
|
}
|
|
930
975
|
} // Allow objects to bail out of recursive dispose alltogether by passing dispose={null}
|
|
@@ -938,14 +983,14 @@ function createRenderer(roots, getEventPriority) {
|
|
|
938
983
|
// when the reconciler calls it, but then carry our own check recursively
|
|
939
984
|
|
|
940
985
|
|
|
941
|
-
const isPrimitive = (_child$
|
|
986
|
+
const isPrimitive = (_child$__r3f5 = child.__r3f) == null ? void 0 : _child$__r3f5.primitive;
|
|
942
987
|
const shouldDispose = dispose === undefined ? child.dispose !== null && !isPrimitive : dispose; // Remove nested child objects. Primitives should not have objects and children that are
|
|
943
988
|
// attached to them declaratively ...
|
|
944
989
|
|
|
945
990
|
if (!isPrimitive) {
|
|
946
|
-
var _child$
|
|
991
|
+
var _child$__r3f6;
|
|
947
992
|
|
|
948
|
-
removeRecursive((_child$
|
|
993
|
+
removeRecursive((_child$__r3f6 = child.__r3f) == null ? void 0 : _child$__r3f6.objects, child, shouldDispose);
|
|
949
994
|
removeRecursive(child.children, child, shouldDispose);
|
|
950
995
|
} // Remove references
|
|
951
996
|
|
|
@@ -1303,7 +1348,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1303
1348
|
initialClick: [0, 0],
|
|
1304
1349
|
initialHits: [],
|
|
1305
1350
|
capturedMap: new Map(),
|
|
1306
|
-
subscribe: (ref, priority
|
|
1351
|
+
subscribe: (ref, priority, store) => {
|
|
1307
1352
|
set(({
|
|
1308
1353
|
internal
|
|
1309
1354
|
}) => ({
|
|
@@ -1317,7 +1362,8 @@ const createStore = (invalidate, advance) => {
|
|
|
1317
1362
|
// highest priority renders last (on top of the other frames)
|
|
1318
1363
|
subscribers: [...internal.subscribers, {
|
|
1319
1364
|
ref,
|
|
1320
|
-
priority
|
|
1365
|
+
priority,
|
|
1366
|
+
store
|
|
1321
1367
|
}].sort((a, b) => a.priority - b.priority)
|
|
1322
1368
|
}
|
|
1323
1369
|
}));
|
|
@@ -1391,8 +1437,23 @@ let i;
|
|
|
1391
1437
|
let globalEffects = [];
|
|
1392
1438
|
let globalAfterEffects = [];
|
|
1393
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
|
+
|
|
1394
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
|
+
|
|
1395
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
|
+
|
|
1396
1457
|
const addTail = callback => createSubs(callback, globalTailEffects);
|
|
1397
1458
|
|
|
1398
1459
|
function run(effects, timestamp) {
|
|
@@ -1400,6 +1461,7 @@ function run(effects, timestamp) {
|
|
|
1400
1461
|
}
|
|
1401
1462
|
|
|
1402
1463
|
let subscribers;
|
|
1464
|
+
let subscription;
|
|
1403
1465
|
|
|
1404
1466
|
function render$1(timestamp, state, frame) {
|
|
1405
1467
|
// Run local effects
|
|
@@ -1414,7 +1476,10 @@ function render$1(timestamp, state, frame) {
|
|
|
1414
1476
|
|
|
1415
1477
|
subscribers = state.internal.subscribers;
|
|
1416
1478
|
|
|
1417
|
-
for (i = 0; i < subscribers.length; i++)
|
|
1479
|
+
for (i = 0; i < subscribers.length; i++) {
|
|
1480
|
+
subscription = subscribers[i];
|
|
1481
|
+
subscription.ref.current(subscription.store.getState(), delta, frame);
|
|
1482
|
+
} // Render content
|
|
1418
1483
|
|
|
1419
1484
|
|
|
1420
1485
|
if (!state.internal.priority && state.gl.render) state.gl.render(state.scene, state.camera); // Decrease frame count
|
|
@@ -1479,7 +1544,17 @@ function createLoop(roots) {
|
|
|
1479
1544
|
|
|
1480
1545
|
return {
|
|
1481
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
|
+
*/
|
|
1482
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
|
+
*/
|
|
1483
1558
|
advance
|
|
1484
1559
|
};
|
|
1485
1560
|
}
|
|
@@ -1489,18 +1564,35 @@ function useStore() {
|
|
|
1489
1564
|
if (!store) throw `R3F hooks can only be used within the Canvas component!`;
|
|
1490
1565
|
return store;
|
|
1491
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
|
+
|
|
1492
1572
|
function useThree(selector = state => state, equalityFn) {
|
|
1493
1573
|
return useStore()(selector, equalityFn);
|
|
1494
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
|
+
|
|
1495
1581
|
function useFrame(callback, renderPriority = 0) {
|
|
1496
|
-
const
|
|
1582
|
+
const store = useStore();
|
|
1583
|
+
const subscribe = store.getState().internal.subscribe; // Update ref
|
|
1497
1584
|
|
|
1498
1585
|
const ref = React__namespace.useRef(callback);
|
|
1499
1586
|
React__namespace.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
|
|
1500
1587
|
|
|
1501
|
-
React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority), [renderPriority, subscribe]);
|
|
1588
|
+
React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority, store), [renderPriority, subscribe, store]);
|
|
1502
1589
|
return null;
|
|
1503
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
|
+
|
|
1504
1596
|
function useGraph(object) {
|
|
1505
1597
|
return React__namespace.useMemo(() => buildGraph(object), [object]);
|
|
1506
1598
|
}
|
|
@@ -1517,12 +1609,14 @@ function loadingFn(extensions, onProgress) {
|
|
|
1517
1609
|
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1518
1610
|
};
|
|
1519
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
|
+
|
|
1520
1619
|
|
|
1521
|
-
function useMemoizedFn(fn) {
|
|
1522
|
-
const fnRef = React__namespace.useRef(fn);
|
|
1523
|
-
React__namespace.useLayoutEffect(() => void (fnRef.current = fn), [fn]);
|
|
1524
|
-
return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
|
|
1525
|
-
}
|
|
1526
1620
|
function useLoader(Proto, input, extensions, onProgress) {
|
|
1527
1621
|
// Use suspense to load async assets
|
|
1528
1622
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1532,11 +1626,18 @@ function useLoader(Proto, input, extensions, onProgress) {
|
|
|
1532
1626
|
|
|
1533
1627
|
return Array.isArray(input) ? results : results[0];
|
|
1534
1628
|
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Preloads an asset into cache as a side-effect.
|
|
1631
|
+
*/
|
|
1535
1632
|
|
|
1536
1633
|
useLoader.preload = function (Proto, input, extensions) {
|
|
1537
1634
|
const keys = Array.isArray(input) ? input : [input];
|
|
1538
1635
|
return suspendReact.preload(loadingFn(extensions), [Proto, ...keys]);
|
|
1539
1636
|
};
|
|
1637
|
+
/**
|
|
1638
|
+
* Removes a loaded asset from cache.
|
|
1639
|
+
*/
|
|
1640
|
+
|
|
1540
1641
|
|
|
1541
1642
|
useLoader.clear = function (Proto, input) {
|
|
1542
1643
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1783,7 +1884,7 @@ function Provider({
|
|
|
1783
1884
|
onCreated,
|
|
1784
1885
|
rootElement
|
|
1785
1886
|
}) {
|
|
1786
|
-
|
|
1887
|
+
useIsomorphicLayoutEffect(() => {
|
|
1787
1888
|
const state = store.getState(); // Flag the canvas active, rendering will now begin
|
|
1788
1889
|
|
|
1789
1890
|
state.set(state => ({
|
|
@@ -1833,6 +1934,7 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
1833
1934
|
|
|
1834
1935
|
function createPortal(children, container, state) {
|
|
1835
1936
|
return /*#__PURE__*/React__namespace.createElement(Portal, {
|
|
1937
|
+
key: container.uuid,
|
|
1836
1938
|
children: children,
|
|
1837
1939
|
container: container,
|
|
1838
1940
|
state: state
|
|
@@ -1910,6 +2012,8 @@ reconciler.injectIntoDevTools({
|
|
|
1910
2012
|
});
|
|
1911
2013
|
const act = React__namespace.unstable_act;
|
|
1912
2014
|
|
|
2015
|
+
exports.Block = Block;
|
|
2016
|
+
exports.ErrorBoundary = ErrorBoundary;
|
|
1913
2017
|
exports.act = act;
|
|
1914
2018
|
exports.addAfterEffect = addAfterEffect;
|
|
1915
2019
|
exports.addEffect = addEffect;
|
|
@@ -1933,6 +2037,7 @@ exports.threeTypes = threeTypes;
|
|
|
1933
2037
|
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
1934
2038
|
exports.useFrame = useFrame;
|
|
1935
2039
|
exports.useGraph = useGraph;
|
|
2040
|
+
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
1936
2041
|
exports.useLoader = useLoader;
|
|
1937
2042
|
exports.useMemoizedFn = useMemoizedFn;
|
|
1938
2043
|
exports.useStore = useStore;
|