@react-three/fiber 8.0.4 → 8.0.7
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 +25 -25
- package/dist/declarations/src/core/index.d.ts +42 -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 +109 -108
- package/dist/declarations/src/core/utils.d.ts +57 -57
- package/dist/declarations/src/index.d.ts +10 -10
- package/dist/declarations/src/native/Canvas.d.ts +13 -13
- package/dist/declarations/src/native/events.d.ts +5 -5
- package/dist/declarations/src/native.d.ts +10 -10
- package/dist/declarations/src/three-types.d.ts +326 -326
- package/dist/declarations/src/web/Canvas.d.ts +13 -13
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/{index-227921b7.cjs.prod.js → index-4fb4daff.cjs.prod.js} +47 -21
- package/dist/{index-6cf8dd4b.cjs.dev.js → index-75d39ab1.cjs.dev.js} +47 -21
- package/dist/{index-de9e845e.esm.js → index-e42f8ac9.esm.js} +47 -21
- package/dist/react-three-fiber.cjs.dev.js +9 -13
- package/dist/react-three-fiber.cjs.prod.js +9 -13
- package/dist/react-three-fiber.esm.js +10 -14
- package/native/dist/react-three-fiber-native.cjs.dev.js +9 -13
- package/native/dist/react-three-fiber-native.cjs.prod.js +9 -13
- package/native/dist/react-three-fiber-native.esm.js +10 -14
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import type { Options as ResizeOptions } from 'react-use-measure';
|
|
3
|
-
import { UseBoundStore } from 'zustand';
|
|
4
|
-
import { RenderProps } from '../core';
|
|
5
|
-
import { RootState } from '../core/store';
|
|
6
|
-
import { EventManager } from '../core/events';
|
|
7
|
-
export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size' | 'events'>, React.HTMLAttributes<HTMLDivElement> {
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
fallback?: React.ReactNode;
|
|
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 { UseBoundStore } from 'zustand';
|
|
4
|
+
import { RenderProps } from '../core';
|
|
5
|
+
import { RootState } from '../core/store';
|
|
6
|
+
import { EventManager } from '../core/events';
|
|
7
|
+
export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size' | 'events'>, React.HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
fallback?: React.ReactNode;
|
|
10
|
+
resize?: ResizeOptions;
|
|
11
|
+
events?: (store: UseBoundStore<RootState>) => EventManager<any>;
|
|
12
|
+
}
|
|
13
|
+
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>;
|
|
@@ -211,7 +211,10 @@ function detach(parent, child, type) {
|
|
|
211
211
|
target,
|
|
212
212
|
key
|
|
213
213
|
} = resolve(parent, type);
|
|
214
|
-
|
|
214
|
+
const previous = child.__r3f.previousAttach; // When the previous value was undefined, it means the value was never set to begin with
|
|
215
|
+
|
|
216
|
+
if (previous === undefined) delete target[key]; // Otherwise set the previous value
|
|
217
|
+
else target[key] = previous;
|
|
215
218
|
} else (_child$__r3f = child.__r3f) == null ? void 0 : _child$__r3f.previousAttach == null ? void 0 : _child$__r3f.previousAttach(parent, child);
|
|
216
219
|
|
|
217
220
|
(_child$__r3f2 = child.__r3f) == null ? true : delete _child$__r3f2.previousAttach;
|
|
@@ -304,9 +307,11 @@ function applyProps$1(instance, data) {
|
|
|
304
307
|
// use the prop constructor to find the default it should be
|
|
305
308
|
value = new targetProp.constructor(...memoized.args);
|
|
306
309
|
} else if (currentInstance.constructor) {
|
|
310
|
+
var _currentInstance$__r, _currentInstance$__r2;
|
|
311
|
+
|
|
307
312
|
// create a blank slate of the instance and copy the particular parameter.
|
|
308
313
|
// @ts-ignore
|
|
309
|
-
const defaultClassCall = new currentInstance.constructor(...currentInstance.__r3f.memoizedProps.args);
|
|
314
|
+
const defaultClassCall = new currentInstance.constructor(...((_currentInstance$__r = (_currentInstance$__r2 = currentInstance.__r3f) == null ? void 0 : _currentInstance$__r2.memoizedProps.args) != null ? _currentInstance$__r : []));
|
|
310
315
|
value = defaultClassCall[targetProp]; // destory the instance
|
|
311
316
|
|
|
312
317
|
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
@@ -480,7 +485,13 @@ function createEvents(store) {
|
|
|
480
485
|
if (state) {
|
|
481
486
|
state.raycaster.camera = undefined;
|
|
482
487
|
}
|
|
483
|
-
});
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
if (!state.previousRoot) {
|
|
491
|
+
// Make sure root-level pointer and ray are set up
|
|
492
|
+
state.events.compute == null ? void 0 : state.events.compute(event, state);
|
|
493
|
+
} // Collect events
|
|
494
|
+
|
|
484
495
|
|
|
485
496
|
let hits = eventsObjects // Intersect objects
|
|
486
497
|
.flatMap(obj => {
|
|
@@ -854,8 +865,10 @@ function createRenderer(roots, getEventPriority) {
|
|
|
854
865
|
let added = false;
|
|
855
866
|
|
|
856
867
|
if (child) {
|
|
868
|
+
var _child$__r3f, _parentInstance$__r3f;
|
|
869
|
+
|
|
857
870
|
// The attach attribute implies that the object attaches itself on the parent
|
|
858
|
-
if (child.__r3f.attach) {
|
|
871
|
+
if ((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) {
|
|
859
872
|
attach(parentInstance, child, child.__r3f.attach);
|
|
860
873
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
861
874
|
// add in the usual parent-child way
|
|
@@ -865,7 +878,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
865
878
|
// that is, anything that's a child in React but not a child in the scenegraph.
|
|
866
879
|
|
|
867
880
|
|
|
868
|
-
if (!added) parentInstance.__r3f.objects.push(child);
|
|
881
|
+
if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
|
|
869
882
|
if (!child.__r3f) prepare(child, {});
|
|
870
883
|
child.__r3f.parent = parentInstance;
|
|
871
884
|
updateInstance(child);
|
|
@@ -877,7 +890,9 @@ function createRenderer(roots, getEventPriority) {
|
|
|
877
890
|
let added = false;
|
|
878
891
|
|
|
879
892
|
if (child) {
|
|
880
|
-
|
|
893
|
+
var _child$__r3f2, _parentInstance$__r3f2;
|
|
894
|
+
|
|
895
|
+
if ((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) {
|
|
881
896
|
attach(parentInstance, child, child.__r3f.attach);
|
|
882
897
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
883
898
|
child.parent = parentInstance;
|
|
@@ -890,7 +905,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
890
905
|
added = true;
|
|
891
906
|
}
|
|
892
907
|
|
|
893
|
-
if (!added) parentInstance.__r3f.objects.push(child);
|
|
908
|
+
if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
|
|
894
909
|
if (!child.__r3f) prepare(child, {});
|
|
895
910
|
child.__r3f.parent = parentInstance;
|
|
896
911
|
updateInstance(child);
|
|
@@ -904,21 +919,21 @@ function createRenderer(roots, getEventPriority) {
|
|
|
904
919
|
|
|
905
920
|
function removeChild(parentInstance, child, dispose) {
|
|
906
921
|
if (child) {
|
|
907
|
-
var _parentInstance$
|
|
922
|
+
var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
|
|
908
923
|
|
|
909
924
|
// Clear the parent reference
|
|
910
925
|
if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
|
|
911
926
|
|
|
912
|
-
if ((_parentInstance$
|
|
927
|
+
if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
|
|
913
928
|
|
|
914
|
-
if (child.__r3f.attach) {
|
|
929
|
+
if ((_child$__r3f3 = child.__r3f) != null && _child$__r3f3.attach) {
|
|
915
930
|
detach(parentInstance, child, child.__r3f.attach);
|
|
916
931
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
917
|
-
var _child$
|
|
932
|
+
var _child$__r3f4;
|
|
918
933
|
|
|
919
934
|
parentInstance.remove(child); // Remove interactivity
|
|
920
935
|
|
|
921
|
-
if ((_child$
|
|
936
|
+
if ((_child$__r3f4 = child.__r3f) != null && _child$__r3f4.root) {
|
|
922
937
|
removeInteractivity(child.__r3f.root, child);
|
|
923
938
|
}
|
|
924
939
|
} // Allow objects to bail out of recursive dispose alltogether by passing dispose={null}
|
|
@@ -932,14 +947,14 @@ function createRenderer(roots, getEventPriority) {
|
|
|
932
947
|
// when the reconciler calls it, but then carry our own check recursively
|
|
933
948
|
|
|
934
949
|
|
|
935
|
-
const isPrimitive = (_child$
|
|
950
|
+
const isPrimitive = (_child$__r3f5 = child.__r3f) == null ? void 0 : _child$__r3f5.primitive;
|
|
936
951
|
const shouldDispose = dispose === undefined ? child.dispose !== null && !isPrimitive : dispose; // Remove nested child objects. Primitives should not have objects and children that are
|
|
937
952
|
// attached to them declaratively ...
|
|
938
953
|
|
|
939
954
|
if (!isPrimitive) {
|
|
940
|
-
var _child$
|
|
955
|
+
var _child$__r3f6;
|
|
941
956
|
|
|
942
|
-
removeRecursive((_child$
|
|
957
|
+
removeRecursive((_child$__r3f6 = child.__r3f) == null ? void 0 : _child$__r3f6.objects, child, shouldDispose);
|
|
943
958
|
removeRecursive(child.children, child, shouldDispose);
|
|
944
959
|
} // Remove references
|
|
945
960
|
|
|
@@ -1297,7 +1312,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1297
1312
|
initialClick: [0, 0],
|
|
1298
1313
|
initialHits: [],
|
|
1299
1314
|
capturedMap: new Map(),
|
|
1300
|
-
subscribe: (ref, priority
|
|
1315
|
+
subscribe: (ref, priority, store) => {
|
|
1301
1316
|
set(({
|
|
1302
1317
|
internal
|
|
1303
1318
|
}) => ({
|
|
@@ -1311,7 +1326,8 @@ const createStore = (invalidate, advance) => {
|
|
|
1311
1326
|
// highest priority renders last (on top of the other frames)
|
|
1312
1327
|
subscribers: [...internal.subscribers, {
|
|
1313
1328
|
ref,
|
|
1314
|
-
priority
|
|
1329
|
+
priority,
|
|
1330
|
+
store
|
|
1315
1331
|
}].sort((a, b) => a.priority - b.priority)
|
|
1316
1332
|
}
|
|
1317
1333
|
}));
|
|
@@ -1394,10 +1410,12 @@ function run(effects, timestamp) {
|
|
|
1394
1410
|
}
|
|
1395
1411
|
|
|
1396
1412
|
let subscribers;
|
|
1413
|
+
let subscription;
|
|
1414
|
+
let delta;
|
|
1397
1415
|
|
|
1398
1416
|
function render$1(timestamp, state, frame) {
|
|
1399
1417
|
// Run local effects
|
|
1400
|
-
|
|
1418
|
+
delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1401
1419
|
|
|
1402
1420
|
if (state.frameloop === 'never' && typeof timestamp === 'number') {
|
|
1403
1421
|
delta = timestamp - state.clock.elapsedTime;
|
|
@@ -1408,7 +1426,10 @@ function render$1(timestamp, state, frame) {
|
|
|
1408
1426
|
|
|
1409
1427
|
subscribers = state.internal.subscribers;
|
|
1410
1428
|
|
|
1411
|
-
for (i = 0; i < subscribers.length; i++)
|
|
1429
|
+
for (i = 0; i < subscribers.length; i++) {
|
|
1430
|
+
subscription = subscribers[i];
|
|
1431
|
+
subscription.ref.current(subscription.store.getState(), delta, frame);
|
|
1432
|
+
} // Render content
|
|
1412
1433
|
|
|
1413
1434
|
|
|
1414
1435
|
if (!state.internal.priority && state.gl.render) state.gl.render(state.scene, state.camera); // Decrease frame count
|
|
@@ -1487,12 +1508,13 @@ function useThree(selector = state => state, equalityFn) {
|
|
|
1487
1508
|
return useStore()(selector, equalityFn);
|
|
1488
1509
|
}
|
|
1489
1510
|
function useFrame(callback, renderPriority = 0) {
|
|
1490
|
-
const
|
|
1511
|
+
const store = useStore();
|
|
1512
|
+
const subscribe = store.getState().internal.subscribe; // Update ref
|
|
1491
1513
|
|
|
1492
1514
|
const ref = React__namespace.useRef(callback);
|
|
1493
1515
|
React__namespace.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
|
|
1494
1516
|
|
|
1495
|
-
React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority), [renderPriority, subscribe]);
|
|
1517
|
+
React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority, store), [renderPriority, subscribe, store]);
|
|
1496
1518
|
return null;
|
|
1497
1519
|
}
|
|
1498
1520
|
function useGraph(object) {
|
|
@@ -1827,6 +1849,7 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
1827
1849
|
|
|
1828
1850
|
function createPortal(children, container, state) {
|
|
1829
1851
|
return /*#__PURE__*/React__namespace.createElement(Portal, {
|
|
1852
|
+
key: container.uuid,
|
|
1830
1853
|
children: children,
|
|
1831
1854
|
container: container,
|
|
1832
1855
|
state: state
|
|
@@ -1849,6 +1872,7 @@ function Portal({
|
|
|
1849
1872
|
} = state;
|
|
1850
1873
|
const previousRoot = useStore();
|
|
1851
1874
|
const [raycaster] = React__namespace.useState(() => new THREE__namespace.Raycaster());
|
|
1875
|
+
const [pointer] = React__namespace.useState(() => new THREE__namespace.Vector2());
|
|
1852
1876
|
const inject = React__namespace.useCallback((state, injectState) => {
|
|
1853
1877
|
const intersect = { ...state
|
|
1854
1878
|
};
|
|
@@ -1868,6 +1892,8 @@ function Portal({
|
|
|
1868
1892
|
raycaster,
|
|
1869
1893
|
events: { ...state.events,
|
|
1870
1894
|
...(injectState == null ? void 0 : injectState.events),
|
|
1895
|
+
pointer,
|
|
1896
|
+
mouse: pointer,
|
|
1871
1897
|
...events
|
|
1872
1898
|
},
|
|
1873
1899
|
...rest
|
|
@@ -211,7 +211,10 @@ function detach(parent, child, type) {
|
|
|
211
211
|
target,
|
|
212
212
|
key
|
|
213
213
|
} = resolve(parent, type);
|
|
214
|
-
|
|
214
|
+
const previous = child.__r3f.previousAttach; // When the previous value was undefined, it means the value was never set to begin with
|
|
215
|
+
|
|
216
|
+
if (previous === undefined) delete target[key]; // Otherwise set the previous value
|
|
217
|
+
else target[key] = previous;
|
|
215
218
|
} else (_child$__r3f = child.__r3f) == null ? void 0 : _child$__r3f.previousAttach == null ? void 0 : _child$__r3f.previousAttach(parent, child);
|
|
216
219
|
|
|
217
220
|
(_child$__r3f2 = child.__r3f) == null ? true : delete _child$__r3f2.previousAttach;
|
|
@@ -304,9 +307,11 @@ function applyProps$1(instance, data) {
|
|
|
304
307
|
// use the prop constructor to find the default it should be
|
|
305
308
|
value = new targetProp.constructor(...memoized.args);
|
|
306
309
|
} else if (currentInstance.constructor) {
|
|
310
|
+
var _currentInstance$__r, _currentInstance$__r2;
|
|
311
|
+
|
|
307
312
|
// create a blank slate of the instance and copy the particular parameter.
|
|
308
313
|
// @ts-ignore
|
|
309
|
-
const defaultClassCall = new currentInstance.constructor(...currentInstance.__r3f.memoizedProps.args);
|
|
314
|
+
const defaultClassCall = new currentInstance.constructor(...((_currentInstance$__r = (_currentInstance$__r2 = currentInstance.__r3f) == null ? void 0 : _currentInstance$__r2.memoizedProps.args) != null ? _currentInstance$__r : []));
|
|
310
315
|
value = defaultClassCall[targetProp]; // destory the instance
|
|
311
316
|
|
|
312
317
|
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
@@ -480,7 +485,13 @@ function createEvents(store) {
|
|
|
480
485
|
if (state) {
|
|
481
486
|
state.raycaster.camera = undefined;
|
|
482
487
|
}
|
|
483
|
-
});
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
if (!state.previousRoot) {
|
|
491
|
+
// Make sure root-level pointer and ray are set up
|
|
492
|
+
state.events.compute == null ? void 0 : state.events.compute(event, state);
|
|
493
|
+
} // Collect events
|
|
494
|
+
|
|
484
495
|
|
|
485
496
|
let hits = eventsObjects // Intersect objects
|
|
486
497
|
.flatMap(obj => {
|
|
@@ -854,8 +865,10 @@ function createRenderer(roots, getEventPriority) {
|
|
|
854
865
|
let added = false;
|
|
855
866
|
|
|
856
867
|
if (child) {
|
|
868
|
+
var _child$__r3f, _parentInstance$__r3f;
|
|
869
|
+
|
|
857
870
|
// The attach attribute implies that the object attaches itself on the parent
|
|
858
|
-
if (child.__r3f.attach) {
|
|
871
|
+
if ((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) {
|
|
859
872
|
attach(parentInstance, child, child.__r3f.attach);
|
|
860
873
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
861
874
|
// add in the usual parent-child way
|
|
@@ -865,7 +878,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
865
878
|
// that is, anything that's a child in React but not a child in the scenegraph.
|
|
866
879
|
|
|
867
880
|
|
|
868
|
-
if (!added) parentInstance.__r3f.objects.push(child);
|
|
881
|
+
if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
|
|
869
882
|
if (!child.__r3f) prepare(child, {});
|
|
870
883
|
child.__r3f.parent = parentInstance;
|
|
871
884
|
updateInstance(child);
|
|
@@ -877,7 +890,9 @@ function createRenderer(roots, getEventPriority) {
|
|
|
877
890
|
let added = false;
|
|
878
891
|
|
|
879
892
|
if (child) {
|
|
880
|
-
|
|
893
|
+
var _child$__r3f2, _parentInstance$__r3f2;
|
|
894
|
+
|
|
895
|
+
if ((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) {
|
|
881
896
|
attach(parentInstance, child, child.__r3f.attach);
|
|
882
897
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
883
898
|
child.parent = parentInstance;
|
|
@@ -890,7 +905,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
890
905
|
added = true;
|
|
891
906
|
}
|
|
892
907
|
|
|
893
|
-
if (!added) parentInstance.__r3f.objects.push(child);
|
|
908
|
+
if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
|
|
894
909
|
if (!child.__r3f) prepare(child, {});
|
|
895
910
|
child.__r3f.parent = parentInstance;
|
|
896
911
|
updateInstance(child);
|
|
@@ -904,21 +919,21 @@ function createRenderer(roots, getEventPriority) {
|
|
|
904
919
|
|
|
905
920
|
function removeChild(parentInstance, child, dispose) {
|
|
906
921
|
if (child) {
|
|
907
|
-
var _parentInstance$
|
|
922
|
+
var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
|
|
908
923
|
|
|
909
924
|
// Clear the parent reference
|
|
910
925
|
if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
|
|
911
926
|
|
|
912
|
-
if ((_parentInstance$
|
|
927
|
+
if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
|
|
913
928
|
|
|
914
|
-
if (child.__r3f.attach) {
|
|
929
|
+
if ((_child$__r3f3 = child.__r3f) != null && _child$__r3f3.attach) {
|
|
915
930
|
detach(parentInstance, child, child.__r3f.attach);
|
|
916
931
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
917
|
-
var _child$
|
|
932
|
+
var _child$__r3f4;
|
|
918
933
|
|
|
919
934
|
parentInstance.remove(child); // Remove interactivity
|
|
920
935
|
|
|
921
|
-
if ((_child$
|
|
936
|
+
if ((_child$__r3f4 = child.__r3f) != null && _child$__r3f4.root) {
|
|
922
937
|
removeInteractivity(child.__r3f.root, child);
|
|
923
938
|
}
|
|
924
939
|
} // Allow objects to bail out of recursive dispose alltogether by passing dispose={null}
|
|
@@ -932,14 +947,14 @@ function createRenderer(roots, getEventPriority) {
|
|
|
932
947
|
// when the reconciler calls it, but then carry our own check recursively
|
|
933
948
|
|
|
934
949
|
|
|
935
|
-
const isPrimitive = (_child$
|
|
950
|
+
const isPrimitive = (_child$__r3f5 = child.__r3f) == null ? void 0 : _child$__r3f5.primitive;
|
|
936
951
|
const shouldDispose = dispose === undefined ? child.dispose !== null && !isPrimitive : dispose; // Remove nested child objects. Primitives should not have objects and children that are
|
|
937
952
|
// attached to them declaratively ...
|
|
938
953
|
|
|
939
954
|
if (!isPrimitive) {
|
|
940
|
-
var _child$
|
|
955
|
+
var _child$__r3f6;
|
|
941
956
|
|
|
942
|
-
removeRecursive((_child$
|
|
957
|
+
removeRecursive((_child$__r3f6 = child.__r3f) == null ? void 0 : _child$__r3f6.objects, child, shouldDispose);
|
|
943
958
|
removeRecursive(child.children, child, shouldDispose);
|
|
944
959
|
} // Remove references
|
|
945
960
|
|
|
@@ -1297,7 +1312,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1297
1312
|
initialClick: [0, 0],
|
|
1298
1313
|
initialHits: [],
|
|
1299
1314
|
capturedMap: new Map(),
|
|
1300
|
-
subscribe: (ref, priority
|
|
1315
|
+
subscribe: (ref, priority, store) => {
|
|
1301
1316
|
set(({
|
|
1302
1317
|
internal
|
|
1303
1318
|
}) => ({
|
|
@@ -1311,7 +1326,8 @@ const createStore = (invalidate, advance) => {
|
|
|
1311
1326
|
// highest priority renders last (on top of the other frames)
|
|
1312
1327
|
subscribers: [...internal.subscribers, {
|
|
1313
1328
|
ref,
|
|
1314
|
-
priority
|
|
1329
|
+
priority,
|
|
1330
|
+
store
|
|
1315
1331
|
}].sort((a, b) => a.priority - b.priority)
|
|
1316
1332
|
}
|
|
1317
1333
|
}));
|
|
@@ -1394,10 +1410,12 @@ function run(effects, timestamp) {
|
|
|
1394
1410
|
}
|
|
1395
1411
|
|
|
1396
1412
|
let subscribers;
|
|
1413
|
+
let subscription;
|
|
1414
|
+
let delta;
|
|
1397
1415
|
|
|
1398
1416
|
function render$1(timestamp, state, frame) {
|
|
1399
1417
|
// Run local effects
|
|
1400
|
-
|
|
1418
|
+
delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1401
1419
|
|
|
1402
1420
|
if (state.frameloop === 'never' && typeof timestamp === 'number') {
|
|
1403
1421
|
delta = timestamp - state.clock.elapsedTime;
|
|
@@ -1408,7 +1426,10 @@ function render$1(timestamp, state, frame) {
|
|
|
1408
1426
|
|
|
1409
1427
|
subscribers = state.internal.subscribers;
|
|
1410
1428
|
|
|
1411
|
-
for (i = 0; i < subscribers.length; i++)
|
|
1429
|
+
for (i = 0; i < subscribers.length; i++) {
|
|
1430
|
+
subscription = subscribers[i];
|
|
1431
|
+
subscription.ref.current(subscription.store.getState(), delta, frame);
|
|
1432
|
+
} // Render content
|
|
1412
1433
|
|
|
1413
1434
|
|
|
1414
1435
|
if (!state.internal.priority && state.gl.render) state.gl.render(state.scene, state.camera); // Decrease frame count
|
|
@@ -1487,12 +1508,13 @@ function useThree(selector = state => state, equalityFn) {
|
|
|
1487
1508
|
return useStore()(selector, equalityFn);
|
|
1488
1509
|
}
|
|
1489
1510
|
function useFrame(callback, renderPriority = 0) {
|
|
1490
|
-
const
|
|
1511
|
+
const store = useStore();
|
|
1512
|
+
const subscribe = store.getState().internal.subscribe; // Update ref
|
|
1491
1513
|
|
|
1492
1514
|
const ref = React__namespace.useRef(callback);
|
|
1493
1515
|
React__namespace.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
|
|
1494
1516
|
|
|
1495
|
-
React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority), [renderPriority, subscribe]);
|
|
1517
|
+
React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority, store), [renderPriority, subscribe, store]);
|
|
1496
1518
|
return null;
|
|
1497
1519
|
}
|
|
1498
1520
|
function useGraph(object) {
|
|
@@ -1827,6 +1849,7 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
1827
1849
|
|
|
1828
1850
|
function createPortal(children, container, state) {
|
|
1829
1851
|
return /*#__PURE__*/React__namespace.createElement(Portal, {
|
|
1852
|
+
key: container.uuid,
|
|
1830
1853
|
children: children,
|
|
1831
1854
|
container: container,
|
|
1832
1855
|
state: state
|
|
@@ -1849,6 +1872,7 @@ function Portal({
|
|
|
1849
1872
|
} = state;
|
|
1850
1873
|
const previousRoot = useStore();
|
|
1851
1874
|
const [raycaster] = React__namespace.useState(() => new THREE__namespace.Raycaster());
|
|
1875
|
+
const [pointer] = React__namespace.useState(() => new THREE__namespace.Vector2());
|
|
1852
1876
|
const inject = React__namespace.useCallback((state, injectState) => {
|
|
1853
1877
|
const intersect = { ...state
|
|
1854
1878
|
};
|
|
@@ -1868,6 +1892,8 @@ function Portal({
|
|
|
1868
1892
|
raycaster,
|
|
1869
1893
|
events: { ...state.events,
|
|
1870
1894
|
...(injectState == null ? void 0 : injectState.events),
|
|
1895
|
+
pointer,
|
|
1896
|
+
mouse: pointer,
|
|
1871
1897
|
...events
|
|
1872
1898
|
},
|
|
1873
1899
|
...rest
|
|
@@ -182,7 +182,10 @@ function detach(parent, child, type) {
|
|
|
182
182
|
target,
|
|
183
183
|
key
|
|
184
184
|
} = resolve(parent, type);
|
|
185
|
-
|
|
185
|
+
const previous = child.__r3f.previousAttach; // When the previous value was undefined, it means the value was never set to begin with
|
|
186
|
+
|
|
187
|
+
if (previous === undefined) delete target[key]; // Otherwise set the previous value
|
|
188
|
+
else target[key] = previous;
|
|
186
189
|
} else (_child$__r3f = child.__r3f) == null ? void 0 : _child$__r3f.previousAttach == null ? void 0 : _child$__r3f.previousAttach(parent, child);
|
|
187
190
|
|
|
188
191
|
(_child$__r3f2 = child.__r3f) == null ? true : delete _child$__r3f2.previousAttach;
|
|
@@ -275,9 +278,11 @@ function applyProps$1(instance, data) {
|
|
|
275
278
|
// use the prop constructor to find the default it should be
|
|
276
279
|
value = new targetProp.constructor(...memoized.args);
|
|
277
280
|
} else if (currentInstance.constructor) {
|
|
281
|
+
var _currentInstance$__r, _currentInstance$__r2;
|
|
282
|
+
|
|
278
283
|
// create a blank slate of the instance and copy the particular parameter.
|
|
279
284
|
// @ts-ignore
|
|
280
|
-
const defaultClassCall = new currentInstance.constructor(...currentInstance.__r3f.memoizedProps.args);
|
|
285
|
+
const defaultClassCall = new currentInstance.constructor(...((_currentInstance$__r = (_currentInstance$__r2 = currentInstance.__r3f) == null ? void 0 : _currentInstance$__r2.memoizedProps.args) != null ? _currentInstance$__r : []));
|
|
281
286
|
value = defaultClassCall[targetProp]; // destory the instance
|
|
282
287
|
|
|
283
288
|
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
@@ -451,7 +456,13 @@ function createEvents(store) {
|
|
|
451
456
|
if (state) {
|
|
452
457
|
state.raycaster.camera = undefined;
|
|
453
458
|
}
|
|
454
|
-
});
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
if (!state.previousRoot) {
|
|
462
|
+
// Make sure root-level pointer and ray are set up
|
|
463
|
+
state.events.compute == null ? void 0 : state.events.compute(event, state);
|
|
464
|
+
} // Collect events
|
|
465
|
+
|
|
455
466
|
|
|
456
467
|
let hits = eventsObjects // Intersect objects
|
|
457
468
|
.flatMap(obj => {
|
|
@@ -825,8 +836,10 @@ function createRenderer(roots, getEventPriority) {
|
|
|
825
836
|
let added = false;
|
|
826
837
|
|
|
827
838
|
if (child) {
|
|
839
|
+
var _child$__r3f, _parentInstance$__r3f;
|
|
840
|
+
|
|
828
841
|
// The attach attribute implies that the object attaches itself on the parent
|
|
829
|
-
if (child.__r3f.attach) {
|
|
842
|
+
if ((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) {
|
|
830
843
|
attach(parentInstance, child, child.__r3f.attach);
|
|
831
844
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
832
845
|
// add in the usual parent-child way
|
|
@@ -836,7 +849,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
836
849
|
// that is, anything that's a child in React but not a child in the scenegraph.
|
|
837
850
|
|
|
838
851
|
|
|
839
|
-
if (!added) parentInstance.__r3f.objects.push(child);
|
|
852
|
+
if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
|
|
840
853
|
if (!child.__r3f) prepare(child, {});
|
|
841
854
|
child.__r3f.parent = parentInstance;
|
|
842
855
|
updateInstance(child);
|
|
@@ -848,7 +861,9 @@ function createRenderer(roots, getEventPriority) {
|
|
|
848
861
|
let added = false;
|
|
849
862
|
|
|
850
863
|
if (child) {
|
|
851
|
-
|
|
864
|
+
var _child$__r3f2, _parentInstance$__r3f2;
|
|
865
|
+
|
|
866
|
+
if ((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) {
|
|
852
867
|
attach(parentInstance, child, child.__r3f.attach);
|
|
853
868
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
854
869
|
child.parent = parentInstance;
|
|
@@ -861,7 +876,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
861
876
|
added = true;
|
|
862
877
|
}
|
|
863
878
|
|
|
864
|
-
if (!added) parentInstance.__r3f.objects.push(child);
|
|
879
|
+
if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
|
|
865
880
|
if (!child.__r3f) prepare(child, {});
|
|
866
881
|
child.__r3f.parent = parentInstance;
|
|
867
882
|
updateInstance(child);
|
|
@@ -875,21 +890,21 @@ function createRenderer(roots, getEventPriority) {
|
|
|
875
890
|
|
|
876
891
|
function removeChild(parentInstance, child, dispose) {
|
|
877
892
|
if (child) {
|
|
878
|
-
var _parentInstance$
|
|
893
|
+
var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
|
|
879
894
|
|
|
880
895
|
// Clear the parent reference
|
|
881
896
|
if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
|
|
882
897
|
|
|
883
|
-
if ((_parentInstance$
|
|
898
|
+
if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
|
|
884
899
|
|
|
885
|
-
if (child.__r3f.attach) {
|
|
900
|
+
if ((_child$__r3f3 = child.__r3f) != null && _child$__r3f3.attach) {
|
|
886
901
|
detach(parentInstance, child, child.__r3f.attach);
|
|
887
902
|
} else if (child.isObject3D && parentInstance.isObject3D) {
|
|
888
|
-
var _child$
|
|
903
|
+
var _child$__r3f4;
|
|
889
904
|
|
|
890
905
|
parentInstance.remove(child); // Remove interactivity
|
|
891
906
|
|
|
892
|
-
if ((_child$
|
|
907
|
+
if ((_child$__r3f4 = child.__r3f) != null && _child$__r3f4.root) {
|
|
893
908
|
removeInteractivity(child.__r3f.root, child);
|
|
894
909
|
}
|
|
895
910
|
} // Allow objects to bail out of recursive dispose alltogether by passing dispose={null}
|
|
@@ -903,14 +918,14 @@ function createRenderer(roots, getEventPriority) {
|
|
|
903
918
|
// when the reconciler calls it, but then carry our own check recursively
|
|
904
919
|
|
|
905
920
|
|
|
906
|
-
const isPrimitive = (_child$
|
|
921
|
+
const isPrimitive = (_child$__r3f5 = child.__r3f) == null ? void 0 : _child$__r3f5.primitive;
|
|
907
922
|
const shouldDispose = dispose === undefined ? child.dispose !== null && !isPrimitive : dispose; // Remove nested child objects. Primitives should not have objects and children that are
|
|
908
923
|
// attached to them declaratively ...
|
|
909
924
|
|
|
910
925
|
if (!isPrimitive) {
|
|
911
|
-
var _child$
|
|
926
|
+
var _child$__r3f6;
|
|
912
927
|
|
|
913
|
-
removeRecursive((_child$
|
|
928
|
+
removeRecursive((_child$__r3f6 = child.__r3f) == null ? void 0 : _child$__r3f6.objects, child, shouldDispose);
|
|
914
929
|
removeRecursive(child.children, child, shouldDispose);
|
|
915
930
|
} // Remove references
|
|
916
931
|
|
|
@@ -1268,7 +1283,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1268
1283
|
initialClick: [0, 0],
|
|
1269
1284
|
initialHits: [],
|
|
1270
1285
|
capturedMap: new Map(),
|
|
1271
|
-
subscribe: (ref, priority
|
|
1286
|
+
subscribe: (ref, priority, store) => {
|
|
1272
1287
|
set(({
|
|
1273
1288
|
internal
|
|
1274
1289
|
}) => ({
|
|
@@ -1282,7 +1297,8 @@ const createStore = (invalidate, advance) => {
|
|
|
1282
1297
|
// highest priority renders last (on top of the other frames)
|
|
1283
1298
|
subscribers: [...internal.subscribers, {
|
|
1284
1299
|
ref,
|
|
1285
|
-
priority
|
|
1300
|
+
priority,
|
|
1301
|
+
store
|
|
1286
1302
|
}].sort((a, b) => a.priority - b.priority)
|
|
1287
1303
|
}
|
|
1288
1304
|
}));
|
|
@@ -1365,10 +1381,12 @@ function run(effects, timestamp) {
|
|
|
1365
1381
|
}
|
|
1366
1382
|
|
|
1367
1383
|
let subscribers;
|
|
1384
|
+
let subscription;
|
|
1385
|
+
let delta;
|
|
1368
1386
|
|
|
1369
1387
|
function render$1(timestamp, state, frame) {
|
|
1370
1388
|
// Run local effects
|
|
1371
|
-
|
|
1389
|
+
delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1372
1390
|
|
|
1373
1391
|
if (state.frameloop === 'never' && typeof timestamp === 'number') {
|
|
1374
1392
|
delta = timestamp - state.clock.elapsedTime;
|
|
@@ -1379,7 +1397,10 @@ function render$1(timestamp, state, frame) {
|
|
|
1379
1397
|
|
|
1380
1398
|
subscribers = state.internal.subscribers;
|
|
1381
1399
|
|
|
1382
|
-
for (i = 0; i < subscribers.length; i++)
|
|
1400
|
+
for (i = 0; i < subscribers.length; i++) {
|
|
1401
|
+
subscription = subscribers[i];
|
|
1402
|
+
subscription.ref.current(subscription.store.getState(), delta, frame);
|
|
1403
|
+
} // Render content
|
|
1383
1404
|
|
|
1384
1405
|
|
|
1385
1406
|
if (!state.internal.priority && state.gl.render) state.gl.render(state.scene, state.camera); // Decrease frame count
|
|
@@ -1458,12 +1479,13 @@ function useThree(selector = state => state, equalityFn) {
|
|
|
1458
1479
|
return useStore()(selector, equalityFn);
|
|
1459
1480
|
}
|
|
1460
1481
|
function useFrame(callback, renderPriority = 0) {
|
|
1461
|
-
const
|
|
1482
|
+
const store = useStore();
|
|
1483
|
+
const subscribe = store.getState().internal.subscribe; // Update ref
|
|
1462
1484
|
|
|
1463
1485
|
const ref = React.useRef(callback);
|
|
1464
1486
|
React.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
|
|
1465
1487
|
|
|
1466
|
-
React.useLayoutEffect(() => subscribe(ref, renderPriority), [renderPriority, subscribe]);
|
|
1488
|
+
React.useLayoutEffect(() => subscribe(ref, renderPriority, store), [renderPriority, subscribe, store]);
|
|
1467
1489
|
return null;
|
|
1468
1490
|
}
|
|
1469
1491
|
function useGraph(object) {
|
|
@@ -1798,6 +1820,7 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
1798
1820
|
|
|
1799
1821
|
function createPortal(children, container, state) {
|
|
1800
1822
|
return /*#__PURE__*/React.createElement(Portal, {
|
|
1823
|
+
key: container.uuid,
|
|
1801
1824
|
children: children,
|
|
1802
1825
|
container: container,
|
|
1803
1826
|
state: state
|
|
@@ -1820,6 +1843,7 @@ function Portal({
|
|
|
1820
1843
|
} = state;
|
|
1821
1844
|
const previousRoot = useStore();
|
|
1822
1845
|
const [raycaster] = React.useState(() => new THREE.Raycaster());
|
|
1846
|
+
const [pointer] = React.useState(() => new THREE.Vector2());
|
|
1823
1847
|
const inject = React.useCallback((state, injectState) => {
|
|
1824
1848
|
const intersect = { ...state
|
|
1825
1849
|
};
|
|
@@ -1839,6 +1863,8 @@ function Portal({
|
|
|
1839
1863
|
raycaster,
|
|
1840
1864
|
events: { ...state.events,
|
|
1841
1865
|
...(injectState == null ? void 0 : injectState.events),
|
|
1866
|
+
pointer,
|
|
1867
|
+
mouse: pointer,
|
|
1842
1868
|
...events
|
|
1843
1869
|
},
|
|
1844
1870
|
...rest
|