@react-three/fiber 9.0.0-rc.5 → 9.0.0-rc.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 +1088 -1076
- package/dist/declarations/src/core/events.d.ts +91 -91
- package/dist/declarations/src/core/hooks.d.ts +51 -51
- package/dist/declarations/src/core/index.d.ts +13 -13
- package/dist/declarations/src/core/loop.d.ts +31 -31
- package/dist/declarations/src/core/reconciler.d.ts +50 -52
- package/dist/declarations/src/core/renderer.d.ts +89 -89
- package/dist/declarations/src/core/store.d.ts +130 -130
- package/dist/declarations/src/core/utils.d.ts +186 -186
- package/dist/declarations/src/index.d.ts +6 -6
- package/dist/declarations/src/native/Canvas.d.ts +13 -13
- package/dist/declarations/src/native/events.d.ts +4 -4
- package/dist/declarations/src/native.d.ts +6 -6
- package/dist/declarations/src/three-types.d.ts +66 -62
- package/dist/declarations/src/web/Canvas.d.ts +23 -23
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/{events-a7b08b1a.esm.js → events-12fa3319.esm.js} +138 -118
- package/dist/{events-b4061ace.cjs.dev.js → events-56f909a9.cjs.dev.js} +138 -118
- package/dist/{events-60ed2d7b.cjs.prod.js → events-858f07e7.cjs.prod.js} +138 -118
- package/dist/react-three-fiber.cjs.dev.js +7 -201
- package/dist/react-three-fiber.cjs.prod.js +7 -201
- package/dist/react-three-fiber.esm.js +6 -201
- package/native/dist/react-three-fiber-native.cjs.d.ts +2 -0
- package/native/dist/react-three-fiber-native.cjs.dev.js +554 -0
- package/native/dist/react-three-fiber-native.cjs.js +7 -0
- package/native/dist/react-three-fiber-native.cjs.prod.js +554 -0
- package/native/dist/react-three-fiber-native.esm.js +502 -0
- package/native/package.json +5 -5
- package/package.json +87 -88
- package/readme.md +253 -253
- package/dist/declarations/src/web/use-measure.d.ts +0 -34
|
@@ -12,29 +12,29 @@ var threeTypes = /*#__PURE__*/Object.freeze({
|
|
|
12
12
|
__proto__: null
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* Returns the instance's initial (outmost) root.
|
|
15
|
+
/**
|
|
16
|
+
* Returns the instance's initial (outmost) root.
|
|
17
17
|
*/
|
|
18
18
|
function findInitialRoot(instance) {
|
|
19
19
|
let root = instance.root;
|
|
20
20
|
while (root.getState().previousRoot) root = root.getState().previousRoot;
|
|
21
21
|
return root;
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Safely flush async effects when testing, simulating a legacy root.
|
|
23
|
+
/**
|
|
24
|
+
* Safely flush async effects when testing, simulating a legacy root.
|
|
25
25
|
*/
|
|
26
26
|
const act = React.act;
|
|
27
27
|
const isOrthographicCamera = def => def && def.isOrthographicCamera;
|
|
28
28
|
const isRef = obj => obj && obj.hasOwnProperty('current');
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
* An SSR-friendly useLayoutEffect.
|
|
32
|
-
*
|
|
33
|
-
* React currently throws a warning when using useLayoutEffect on the server.
|
|
34
|
-
* To get around it, we can conditionally useEffect on the server (no-op) and
|
|
35
|
-
* useLayoutEffect elsewhere.
|
|
36
|
-
*
|
|
37
|
-
* @see https://github.com/facebook/react/issues/14927
|
|
30
|
+
/**
|
|
31
|
+
* An SSR-friendly useLayoutEffect.
|
|
32
|
+
*
|
|
33
|
+
* React currently throws a warning when using useLayoutEffect on the server.
|
|
34
|
+
* To get around it, we can conditionally useEffect on the server (no-op) and
|
|
35
|
+
* useLayoutEffect elsewhere.
|
|
36
|
+
*
|
|
37
|
+
* @see https://github.com/facebook/react/issues/14927
|
|
38
38
|
*/
|
|
39
39
|
const useIsomorphicLayoutEffect = /* @__PURE__ */((_window$document, _window$navigator) => typeof window !== 'undefined' && (((_window$document = window.document) == null ? void 0 : _window$document.createElement) || ((_window$navigator = window.navigator) == null ? void 0 : _window$navigator.product) === 'ReactNative'))() ? React.useLayoutEffect : React.useEffect;
|
|
40
40
|
function useMutableCallback(fn) {
|
|
@@ -42,8 +42,8 @@ function useMutableCallback(fn) {
|
|
|
42
42
|
useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
|
|
43
43
|
return ref;
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Bridges renderer Context and StrictMode from a primary renderer.
|
|
45
|
+
/**
|
|
46
|
+
* Bridges renderer Context and StrictMode from a primary renderer.
|
|
47
47
|
*/
|
|
48
48
|
function useBridge() {
|
|
49
49
|
const fiber = useFiber();
|
|
@@ -95,8 +95,8 @@ function calculateDpr(dpr) {
|
|
|
95
95
|
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
/**
|
|
99
|
-
* Returns instance root state
|
|
98
|
+
/**
|
|
99
|
+
* Returns instance root state
|
|
100
100
|
*/
|
|
101
101
|
function getRootState(obj) {
|
|
102
102
|
var _r3f;
|
|
@@ -204,10 +204,7 @@ function prepare(target, root, type, props) {
|
|
|
204
204
|
handlers: {},
|
|
205
205
|
isHidden: false
|
|
206
206
|
};
|
|
207
|
-
if (object)
|
|
208
|
-
object.__r3f = instance;
|
|
209
|
-
if (type) applyProps(object, instance.props);
|
|
210
|
-
}
|
|
207
|
+
if (object) object.__r3f = instance;
|
|
211
208
|
}
|
|
212
209
|
return instance;
|
|
213
210
|
}
|
|
@@ -357,6 +354,7 @@ function applyProps(object, props) {
|
|
|
357
354
|
if (instance && EVENT_REGEX.test(prop)) {
|
|
358
355
|
if (typeof value === 'function') instance.handlers[prop] = value;else delete instance.handlers[prop];
|
|
359
356
|
instance.eventCount = Object.keys(instance.handlers).length;
|
|
357
|
+
continue;
|
|
360
358
|
}
|
|
361
359
|
|
|
362
360
|
// Ignore setting undefined props
|
|
@@ -459,9 +457,9 @@ function makeId(event) {
|
|
|
459
457
|
return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
|
|
460
458
|
}
|
|
461
459
|
|
|
462
|
-
/**
|
|
463
|
-
* Release pointer captures.
|
|
464
|
-
* This is called by releasePointerCapture in the API, and when an object is removed.
|
|
460
|
+
/**
|
|
461
|
+
* Release pointer captures.
|
|
462
|
+
* This is called by releasePointerCapture in the API, and when an object is removed.
|
|
465
463
|
*/
|
|
466
464
|
function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
|
|
467
465
|
const captureData = captures.get(obj);
|
|
@@ -597,7 +595,19 @@ function createEvents(store) {
|
|
|
597
595
|
stopped: false
|
|
598
596
|
};
|
|
599
597
|
for (const hit of intersections) {
|
|
600
|
-
|
|
598
|
+
let state = getRootState(hit.object);
|
|
599
|
+
|
|
600
|
+
// If the object is not managed by R3F, it might be parented to an element which is.
|
|
601
|
+
// Traverse upwards until we find a managed parent and use its state instead.
|
|
602
|
+
if (!state) {
|
|
603
|
+
hit.object.traverseAncestors(obj => {
|
|
604
|
+
const parentState = getRootState(obj);
|
|
605
|
+
if (parentState) {
|
|
606
|
+
state = parentState;
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
}
|
|
601
611
|
if (state) {
|
|
602
612
|
const {
|
|
603
613
|
raycaster,
|
|
@@ -796,19 +806,19 @@ function createEvents(store) {
|
|
|
796
806
|
if (!(instance != null && instance.eventCount)) return;
|
|
797
807
|
const handlers = instance.handlers;
|
|
798
808
|
|
|
799
|
-
/*
|
|
800
|
-
MAYBE TODO, DELETE IF NOT:
|
|
801
|
-
Check if the object is captured, captured events should not have intersects running in parallel
|
|
802
|
-
But wouldn't it be better to just replace capturedMap with a single entry?
|
|
803
|
-
Also, are we OK with straight up making picking up multiple objects impossible?
|
|
804
|
-
|
|
805
|
-
const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
|
|
806
|
-
if (pointerId !== undefined) {
|
|
807
|
-
const capturedMeshSet = internal.capturedMap.get(pointerId)
|
|
808
|
-
if (capturedMeshSet) {
|
|
809
|
-
const captured = capturedMeshSet.get(eventObject)
|
|
810
|
-
if (captured && captured.localState.stopped) return
|
|
811
|
-
}
|
|
809
|
+
/*
|
|
810
|
+
MAYBE TODO, DELETE IF NOT:
|
|
811
|
+
Check if the object is captured, captured events should not have intersects running in parallel
|
|
812
|
+
But wouldn't it be better to just replace capturedMap with a single entry?
|
|
813
|
+
Also, are we OK with straight up making picking up multiple objects impossible?
|
|
814
|
+
|
|
815
|
+
const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
|
|
816
|
+
if (pointerId !== undefined) {
|
|
817
|
+
const capturedMeshSet = internal.capturedMap.get(pointerId)
|
|
818
|
+
if (capturedMeshSet) {
|
|
819
|
+
const captured = capturedMeshSet.get(eventObject)
|
|
820
|
+
if (captured && captured.localState.stopped) return
|
|
821
|
+
}
|
|
812
822
|
}*/
|
|
813
823
|
|
|
814
824
|
if (isPointerMove) {
|
|
@@ -1099,11 +1109,11 @@ const createStore = (invalidate, advance) => {
|
|
|
1099
1109
|
return rootStore;
|
|
1100
1110
|
};
|
|
1101
1111
|
|
|
1102
|
-
/**
|
|
1103
|
-
* Exposes an object's {@link Instance}.
|
|
1104
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
|
|
1105
|
-
*
|
|
1106
|
-
* **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
|
|
1112
|
+
/**
|
|
1113
|
+
* Exposes an object's {@link Instance}.
|
|
1114
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
|
|
1115
|
+
*
|
|
1116
|
+
* **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
|
|
1107
1117
|
*/
|
|
1108
1118
|
function useInstanceHandle(ref) {
|
|
1109
1119
|
const instance = React.useRef(null);
|
|
@@ -1111,9 +1121,9 @@ function useInstanceHandle(ref) {
|
|
|
1111
1121
|
return instance;
|
|
1112
1122
|
}
|
|
1113
1123
|
|
|
1114
|
-
/**
|
|
1115
|
-
* Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
|
|
1116
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
|
|
1124
|
+
/**
|
|
1125
|
+
* Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
|
|
1126
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
|
|
1117
1127
|
*/
|
|
1118
1128
|
function useStore() {
|
|
1119
1129
|
const store = React.useContext(context);
|
|
@@ -1121,18 +1131,18 @@ function useStore() {
|
|
|
1121
1131
|
return store;
|
|
1122
1132
|
}
|
|
1123
1133
|
|
|
1124
|
-
/**
|
|
1125
|
-
* Accesses R3F's internal state, containing renderer, canvas, scene, etc.
|
|
1126
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
|
|
1134
|
+
/**
|
|
1135
|
+
* Accesses R3F's internal state, containing renderer, canvas, scene, etc.
|
|
1136
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
|
|
1127
1137
|
*/
|
|
1128
1138
|
function useThree(selector = state => state, equalityFn) {
|
|
1129
1139
|
return useStore()(selector, equalityFn);
|
|
1130
1140
|
}
|
|
1131
1141
|
|
|
1132
|
-
/**
|
|
1133
|
-
* Executes a callback before render in a shared frame loop.
|
|
1134
|
-
* Can order effects with render priority or manually render with a positive priority.
|
|
1135
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
|
|
1142
|
+
/**
|
|
1143
|
+
* Executes a callback before render in a shared frame loop.
|
|
1144
|
+
* Can order effects with render priority or manually render with a positive priority.
|
|
1145
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
|
|
1136
1146
|
*/
|
|
1137
1147
|
function useFrame(callback, renderPriority = 0) {
|
|
1138
1148
|
const store = useStore();
|
|
@@ -1144,9 +1154,9 @@ function useFrame(callback, renderPriority = 0) {
|
|
|
1144
1154
|
return null;
|
|
1145
1155
|
}
|
|
1146
1156
|
|
|
1147
|
-
/**
|
|
1148
|
-
* Returns a node graph of an object with named nodes & materials.
|
|
1149
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
|
|
1157
|
+
/**
|
|
1158
|
+
* Returns a node graph of an object with named nodes & materials.
|
|
1159
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
|
|
1150
1160
|
*/
|
|
1151
1161
|
function useGraph(object) {
|
|
1152
1162
|
return React.useMemo(() => buildGraph(object), [object]);
|
|
@@ -1182,11 +1192,11 @@ function loadingFn(extensions, onProgress) {
|
|
|
1182
1192
|
};
|
|
1183
1193
|
}
|
|
1184
1194
|
|
|
1185
|
-
/**
|
|
1186
|
-
* Synchronously loads and caches assets with a three loader.
|
|
1187
|
-
*
|
|
1188
|
-
* Note: this hook's caller must be wrapped with `React.Suspense`
|
|
1189
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
|
|
1195
|
+
/**
|
|
1196
|
+
* Synchronously loads and caches assets with a three loader.
|
|
1197
|
+
*
|
|
1198
|
+
* Note: this hook's caller must be wrapped with `React.Suspense`
|
|
1199
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
|
|
1190
1200
|
*/
|
|
1191
1201
|
function useLoader(loader, input, extensions, onProgress) {
|
|
1192
1202
|
// Use suspense to load async assets
|
|
@@ -1198,16 +1208,16 @@ function useLoader(loader, input, extensions, onProgress) {
|
|
|
1198
1208
|
return Array.isArray(input) ? results : results[0];
|
|
1199
1209
|
}
|
|
1200
1210
|
|
|
1201
|
-
/**
|
|
1202
|
-
* Preloads an asset into cache as a side-effect.
|
|
1211
|
+
/**
|
|
1212
|
+
* Preloads an asset into cache as a side-effect.
|
|
1203
1213
|
*/
|
|
1204
1214
|
useLoader.preload = function (loader, input, extensions) {
|
|
1205
1215
|
const keys = Array.isArray(input) ? input : [input];
|
|
1206
1216
|
return preload(loadingFn(extensions), [loader, ...keys]);
|
|
1207
1217
|
};
|
|
1208
1218
|
|
|
1209
|
-
/**
|
|
1210
|
-
* Removes a loaded asset from cache.
|
|
1219
|
+
/**
|
|
1220
|
+
* Removes a loaded asset from cache.
|
|
1211
1221
|
*/
|
|
1212
1222
|
useLoader.clear = function (loader, input) {
|
|
1213
1223
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1233,6 +1243,8 @@ const NoEventPriority = 0;
|
|
|
1233
1243
|
// https://github.com/microsoft/TypeScript/issues/37079
|
|
1234
1244
|
|
|
1235
1245
|
const catalogue = {};
|
|
1246
|
+
const PREFIX_REGEX = /^three(?=[A-Z])/;
|
|
1247
|
+
const toPascalCase = type => `${type[0].toUpperCase()}${type.slice(1)}`;
|
|
1236
1248
|
let i = 0;
|
|
1237
1249
|
const isConstructor = object => typeof object === 'function';
|
|
1238
1250
|
function extend(objects) {
|
|
@@ -1260,6 +1272,8 @@ function validateInstance(type, props) {
|
|
|
1260
1272
|
}
|
|
1261
1273
|
function createInstance(type, props, root) {
|
|
1262
1274
|
var _props$object;
|
|
1275
|
+
// Remove three* prefix from elements
|
|
1276
|
+
type = type.replace(PREFIX_REGEX, '');
|
|
1263
1277
|
validateInstance(type, props);
|
|
1264
1278
|
|
|
1265
1279
|
// Regenerate the R3F instance for primitives to simulate a new object
|
|
@@ -1303,17 +1317,16 @@ function handleContainerEffects(parent, child, beforeChild) {
|
|
|
1303
1317
|
if (!child.object) {
|
|
1304
1318
|
var _child$props$object, _child$props$args;
|
|
1305
1319
|
// Get target from catalogue
|
|
1306
|
-
const
|
|
1307
|
-
const target = catalogue[name];
|
|
1320
|
+
const target = catalogue[toPascalCase(child.type)];
|
|
1308
1321
|
|
|
1309
1322
|
// Create object
|
|
1310
1323
|
child.object = (_child$props$object = child.props.object) != null ? _child$props$object : new target(...((_child$props$args = child.props.args) != null ? _child$props$args : []));
|
|
1311
1324
|
child.object.__r3f = child;
|
|
1312
|
-
|
|
1313
|
-
// Set initial props
|
|
1314
|
-
applyProps(child.object, child.props);
|
|
1315
1325
|
}
|
|
1316
1326
|
|
|
1327
|
+
// Set initial props
|
|
1328
|
+
applyProps(child.object, child.props);
|
|
1329
|
+
|
|
1317
1330
|
// Append instance
|
|
1318
1331
|
if (child.props.attach) {
|
|
1319
1332
|
attach(parent, child);
|
|
@@ -1325,7 +1338,6 @@ function handleContainerEffects(parent, child, beforeChild) {
|
|
|
1325
1338
|
child.object.dispatchEvent({
|
|
1326
1339
|
type: 'added'
|
|
1327
1340
|
});
|
|
1328
|
-
// expect-error https://github.com/mrdoob/three.js/pull/16934
|
|
1329
1341
|
parent.object.dispatchEvent({
|
|
1330
1342
|
type: 'childadded',
|
|
1331
1343
|
child: child.object
|
|
@@ -1471,8 +1483,7 @@ function swapInstances() {
|
|
|
1471
1483
|
if (parent) {
|
|
1472
1484
|
var _instance$props$objec, _instance$props$args;
|
|
1473
1485
|
// Get target from catalogue
|
|
1474
|
-
const
|
|
1475
|
-
const target = catalogue[name];
|
|
1486
|
+
const target = catalogue[toPascalCase(instance.type)];
|
|
1476
1487
|
|
|
1477
1488
|
// Create object
|
|
1478
1489
|
instance.object = (_instance$props$objec = instance.props.object) != null ? _instance$props$objec : new target(...((_instance$props$args = instance.props.args) != null ? _instance$props$args : []));
|
|
@@ -1641,20 +1652,6 @@ const shallowLoose = {
|
|
|
1641
1652
|
objects: 'shallow',
|
|
1642
1653
|
strict: false
|
|
1643
1654
|
};
|
|
1644
|
-
async function createRendererInstance(gl, canvas) {
|
|
1645
|
-
const defaultProps = {
|
|
1646
|
-
canvas: canvas,
|
|
1647
|
-
powerPreference: 'high-performance',
|
|
1648
|
-
antialias: true,
|
|
1649
|
-
alpha: true
|
|
1650
|
-
};
|
|
1651
|
-
const customRenderer = typeof gl === 'function' ? await gl(defaultProps) : gl;
|
|
1652
|
-
if (isRenderer(customRenderer)) return customRenderer;
|
|
1653
|
-
return new THREE.WebGLRenderer({
|
|
1654
|
-
...defaultProps,
|
|
1655
|
-
...gl
|
|
1656
|
-
});
|
|
1657
|
-
}
|
|
1658
1655
|
function computeInitialSize(canvas, size) {
|
|
1659
1656
|
if (!size && typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
|
|
1660
1657
|
const {
|
|
@@ -1732,10 +1729,13 @@ function createRoot(canvas) {
|
|
|
1732
1729
|
|
|
1733
1730
|
// Locals
|
|
1734
1731
|
let onCreated;
|
|
1735
|
-
let configured = false;
|
|
1736
1732
|
let lastCamera;
|
|
1733
|
+
let configured = false;
|
|
1734
|
+
let pending = null;
|
|
1737
1735
|
return {
|
|
1738
1736
|
async configure(props = {}) {
|
|
1737
|
+
let resolve;
|
|
1738
|
+
pending = new Promise(_resolve => resolve = _resolve);
|
|
1739
1739
|
let {
|
|
1740
1740
|
gl: glConfig,
|
|
1741
1741
|
size: propsSize,
|
|
@@ -1758,9 +1758,26 @@ function createRoot(canvas) {
|
|
|
1758
1758
|
|
|
1759
1759
|
// Set up renderer (one time only!)
|
|
1760
1760
|
let gl = state.gl;
|
|
1761
|
-
if (!state.gl)
|
|
1762
|
-
|
|
1763
|
-
|
|
1761
|
+
if (!state.gl) {
|
|
1762
|
+
const defaultProps = {
|
|
1763
|
+
canvas: canvas,
|
|
1764
|
+
powerPreference: 'high-performance',
|
|
1765
|
+
antialias: true,
|
|
1766
|
+
alpha: true
|
|
1767
|
+
};
|
|
1768
|
+
const customRenderer = typeof glConfig === 'function' ? await glConfig(defaultProps) : glConfig;
|
|
1769
|
+
if (isRenderer(customRenderer)) {
|
|
1770
|
+
gl = customRenderer;
|
|
1771
|
+
} else {
|
|
1772
|
+
gl = new THREE.WebGLRenderer({
|
|
1773
|
+
...defaultProps,
|
|
1774
|
+
...glConfig
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
state.set({
|
|
1778
|
+
gl
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1764
1781
|
|
|
1765
1782
|
// Set up raycaster (one time only!)
|
|
1766
1783
|
let raycaster = state.raycaster;
|
|
@@ -1939,17 +1956,20 @@ function createRoot(canvas) {
|
|
|
1939
1956
|
// Set locals
|
|
1940
1957
|
onCreated = onCreatedCallback;
|
|
1941
1958
|
configured = true;
|
|
1959
|
+
resolve();
|
|
1942
1960
|
return this;
|
|
1943
1961
|
},
|
|
1944
1962
|
render(children) {
|
|
1945
1963
|
// The root has to be configured before it can be rendered
|
|
1946
|
-
if (!configured
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1964
|
+
if (!configured && !pending) this.configure();
|
|
1965
|
+
pending.then(() => {
|
|
1966
|
+
reconciler.updateContainer( /*#__PURE__*/jsx(Provider, {
|
|
1967
|
+
store: store,
|
|
1968
|
+
children: children,
|
|
1969
|
+
onCreated: onCreated,
|
|
1970
|
+
rootElement: canvas
|
|
1971
|
+
}), fiber, null, () => undefined);
|
|
1972
|
+
});
|
|
1953
1973
|
return store;
|
|
1954
1974
|
},
|
|
1955
1975
|
unmount() {
|
|
@@ -2022,10 +2042,10 @@ function Portal({
|
|
|
2022
2042
|
children,
|
|
2023
2043
|
container
|
|
2024
2044
|
}) {
|
|
2025
|
-
/** This has to be a component because it would not be able to call useThree/useStore otherwise since
|
|
2026
|
-
* if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
|
|
2027
|
-
* the "R3F hooks can only be used within the Canvas component!" warning:
|
|
2028
|
-
* <Canvas>
|
|
2045
|
+
/** This has to be a component because it would not be able to call useThree/useStore otherwise since
|
|
2046
|
+
* if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
|
|
2047
|
+
* the "R3F hooks can only be used within the Canvas component!" warning:
|
|
2048
|
+
* <Canvas>
|
|
2029
2049
|
* {createPortal(...)} */
|
|
2030
2050
|
const {
|
|
2031
2051
|
events,
|
|
@@ -2117,21 +2137,21 @@ const globalEffects = new Set();
|
|
|
2117
2137
|
const globalAfterEffects = new Set();
|
|
2118
2138
|
const globalTailEffects = new Set();
|
|
2119
2139
|
|
|
2120
|
-
/**
|
|
2121
|
-
* Adds a global render callback which is called each frame.
|
|
2122
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
2140
|
+
/**
|
|
2141
|
+
* Adds a global render callback which is called each frame.
|
|
2142
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
2123
2143
|
*/
|
|
2124
2144
|
const addEffect = callback => createSubs(callback, globalEffects);
|
|
2125
2145
|
|
|
2126
|
-
/**
|
|
2127
|
-
* Adds a global after-render callback which is called each frame.
|
|
2128
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
|
|
2146
|
+
/**
|
|
2147
|
+
* Adds a global after-render callback which is called each frame.
|
|
2148
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
|
|
2129
2149
|
*/
|
|
2130
2150
|
const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
|
|
2131
2151
|
|
|
2132
|
-
/**
|
|
2133
|
-
* Adds a global callback which is called when rendering stops.
|
|
2134
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
|
|
2152
|
+
/**
|
|
2153
|
+
* Adds a global callback which is called when rendering stops.
|
|
2154
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
|
|
2135
2155
|
*/
|
|
2136
2156
|
const addTail = callback => createSubs(callback, globalTailEffects);
|
|
2137
2157
|
function run(effects, timestamp) {
|
|
@@ -2203,7 +2223,7 @@ function loop(timestamp) {
|
|
|
2203
2223
|
repeat += update(timestamp, state);
|
|
2204
2224
|
}
|
|
2205
2225
|
}
|
|
2206
|
-
useFrameInProgress =
|
|
2226
|
+
useFrameInProgress = false;
|
|
2207
2227
|
|
|
2208
2228
|
// Run after-effects
|
|
2209
2229
|
flushGlobalEffects('after', timestamp);
|
|
@@ -2219,9 +2239,9 @@ function loop(timestamp) {
|
|
|
2219
2239
|
}
|
|
2220
2240
|
}
|
|
2221
2241
|
|
|
2222
|
-
/**
|
|
2223
|
-
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
2224
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
2242
|
+
/**
|
|
2243
|
+
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
2244
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
2225
2245
|
*/
|
|
2226
2246
|
function invalidate(state, frames = 1) {
|
|
2227
2247
|
var _state$gl$xr2;
|
|
@@ -2248,9 +2268,9 @@ function invalidate(state, frames = 1) {
|
|
|
2248
2268
|
}
|
|
2249
2269
|
}
|
|
2250
2270
|
|
|
2251
|
-
/**
|
|
2252
|
-
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
2253
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
2271
|
+
/**
|
|
2272
|
+
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
2273
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
2254
2274
|
*/
|
|
2255
2275
|
function advance(timestamp, runGlobalEffects = true, state, frame) {
|
|
2256
2276
|
if (runGlobalEffects) flushGlobalEffects('before', timestamp);
|
|
@@ -2282,7 +2302,7 @@ function createPointerEvents(store) {
|
|
|
2282
2302
|
compute(event, state, previous) {
|
|
2283
2303
|
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
2284
2304
|
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
2285
|
-
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
2305
|
+
state.pointer.set((event.offsetX - state.size.left) / state.size.width * 2 - 1, -((event.offsetY - state.size.top) / state.size.height) * 2 + 1);
|
|
2286
2306
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
2287
2307
|
},
|
|
2288
2308
|
connected: undefined,
|