@react-three/fiber 8.0.0-alpha-09 → 8.0.0-beta-03
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 +97 -0
- package/dist/declarations/src/core/events.d.ts +63 -59
- package/dist/declarations/src/core/hooks.d.ts +21 -29
- package/dist/declarations/src/core/loop.d.ts +12 -12
- package/dist/declarations/src/core/renderer.d.ts +50 -51
- package/dist/declarations/src/core/store.d.ts +117 -106
- package/dist/declarations/src/core/utils.d.ts +50 -27
- package/dist/declarations/src/index.d.ts +8 -7
- package/dist/declarations/src/native/Canvas.d.ts +16 -0
- package/dist/declarations/src/native/events.d.ts +6 -0
- package/dist/declarations/src/native/hooks.d.ts +9 -0
- package/dist/declarations/src/native/index.d.ts +36 -0
- package/dist/declarations/src/native.d.ts +8 -0
- package/dist/declarations/src/three-types.d.ts +309 -319
- package/dist/declarations/src/web/Canvas.d.ts +13 -13
- package/dist/declarations/src/web/events.d.ts +5 -5
- package/dist/declarations/src/web/index.d.ts +33 -30
- package/dist/hooks-15c12e3e.esm.js +1539 -0
- package/dist/hooks-6526f63c.cjs.dev.js +1589 -0
- package/dist/hooks-7b7e01e6.cjs.prod.js +1589 -0
- package/dist/react-three-fiber.cjs.dev.js +261 -1596
- package/dist/react-three-fiber.cjs.prod.js +261 -1596
- package/dist/react-three-fiber.esm.js +222 -1554
- package/native/dist/react-three-fiber-native.cjs.d.ts +1 -0
- package/native/dist/react-three-fiber-native.cjs.dev.js +589 -0
- package/native/dist/react-three-fiber-native.cjs.js +7 -0
- package/native/dist/react-three-fiber-native.cjs.prod.js +589 -0
- package/native/dist/react-three-fiber-native.esm.js +537 -0
- package/native/package.json +5 -0
- package/package.json +18 -8
- package/readme.md +10 -10
- package/__mocks__/react-use-measure/index.ts +0 -22
|
@@ -2,1320 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function _interopNamespace(e) {
|
|
18
|
-
if (e && e.__esModule) return e;
|
|
19
|
-
var n = Object.create(null);
|
|
20
|
-
if (e) {
|
|
21
|
-
Object.keys(e).forEach(function (k) {
|
|
22
|
-
if (k !== 'default') {
|
|
23
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
24
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return e[k];
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
n['default'] = e;
|
|
34
|
-
return Object.freeze(n);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
38
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
39
|
-
var create__default = /*#__PURE__*/_interopDefault(create);
|
|
40
|
-
var shallow__default = /*#__PURE__*/_interopDefault(shallow);
|
|
41
|
-
var Reconciler__default = /*#__PURE__*/_interopDefault(Reconciler);
|
|
42
|
-
var mergeRefs__default = /*#__PURE__*/_interopDefault(mergeRefs);
|
|
43
|
-
var useMeasure__default = /*#__PURE__*/_interopDefault(useMeasure);
|
|
44
|
-
|
|
45
|
-
var threeTypes = /*#__PURE__*/Object.freeze({
|
|
46
|
-
__proto__: null
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const DEFAULT = '__default';
|
|
50
|
-
const isDiffSet = def => def && !!def.memoized && !!def.changes;
|
|
51
|
-
// A collection of compare functions
|
|
52
|
-
const is = {
|
|
53
|
-
obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
|
|
54
|
-
fun: a => typeof a === 'function',
|
|
55
|
-
str: a => typeof a === 'string',
|
|
56
|
-
num: a => typeof a === 'number',
|
|
57
|
-
und: a => a === void 0,
|
|
58
|
-
arr: a => Array.isArray(a),
|
|
59
|
-
|
|
60
|
-
equ(a, b) {
|
|
61
|
-
// Wrong type or one of the two undefined, doesn't match
|
|
62
|
-
if (typeof a !== typeof b || !!a !== !!b) return false; // Atomic, just compare a against b
|
|
63
|
-
|
|
64
|
-
if (is.str(a) || is.num(a) || is.obj(a)) return a === b; // Array, shallow compare first to see if it's a match
|
|
65
|
-
|
|
66
|
-
if (is.arr(a) && a == b) return true; // Last resort, go through keys
|
|
67
|
-
|
|
68
|
-
let i;
|
|
69
|
-
|
|
70
|
-
for (i in a) if (!(i in b)) return false;
|
|
71
|
-
|
|
72
|
-
for (i in b) if (a[i] !== b[i]) return false;
|
|
73
|
-
|
|
74
|
-
return is.und(i) ? a === b : true;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
}; // Each object in the scene carries a small LocalState descriptor
|
|
78
|
-
|
|
79
|
-
function prepare(object, state) {
|
|
80
|
-
const instance = object;
|
|
81
|
-
|
|
82
|
-
if (state != null && state.primitive || !instance.__r3f) {
|
|
83
|
-
instance.__r3f = {
|
|
84
|
-
root: null,
|
|
85
|
-
memoizedProps: {},
|
|
86
|
-
handlers: {
|
|
87
|
-
count: 0
|
|
88
|
-
},
|
|
89
|
-
objects: [],
|
|
90
|
-
...state
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return object;
|
|
95
|
-
} // Shallow check arrays, but check objects atomically
|
|
96
|
-
|
|
97
|
-
function checkShallow(a, b) {
|
|
98
|
-
if (is.arr(a) && is.equ(a, b)) return true;
|
|
99
|
-
if (a === b) return true;
|
|
100
|
-
return false;
|
|
101
|
-
} // This function prepares a set of changes to be applied to the instance
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
function diffProps(instance, {
|
|
105
|
-
children: cN,
|
|
106
|
-
key: kN,
|
|
107
|
-
ref: rN,
|
|
108
|
-
...props
|
|
109
|
-
}, {
|
|
110
|
-
children: cP,
|
|
111
|
-
key: kP,
|
|
112
|
-
ref: rP,
|
|
113
|
-
...previous
|
|
114
|
-
} = {}, remove = false) {
|
|
115
|
-
var _instance$__r3f;
|
|
116
|
-
|
|
117
|
-
const localState = (_instance$__r3f = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f : {};
|
|
118
|
-
const entries = Object.entries(props);
|
|
119
|
-
const changes = []; // Catch removed props, prepend them so they can be reset or removed
|
|
120
|
-
|
|
121
|
-
if (remove) {
|
|
122
|
-
const previousKeys = Object.keys(previous);
|
|
123
|
-
|
|
124
|
-
for (let i = 0; i < previousKeys.length; i++) if (!props.hasOwnProperty(previousKeys[i])) entries.unshift([previousKeys[i], DEFAULT + 'remove']);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
entries.forEach(([key, value]) => {
|
|
128
|
-
var _instance$__r3f2;
|
|
129
|
-
|
|
130
|
-
// Bail out on primitive object
|
|
131
|
-
if ((_instance$__r3f2 = instance.__r3f) != null && _instance$__r3f2.primitive && key === 'object') return; // When props match bail out
|
|
132
|
-
|
|
133
|
-
if (checkShallow(value, previous[key])) return;
|
|
134
|
-
let currentInstance = instance;
|
|
135
|
-
let targetProp = currentInstance[key]; // Collect handlers and bail out
|
|
136
|
-
|
|
137
|
-
if (/^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, currentInstance, targetProp]); // Revolve dashed props
|
|
138
|
-
|
|
139
|
-
if (key.includes('-')) {
|
|
140
|
-
const entries = key.split('-');
|
|
141
|
-
targetProp = entries.reduce((acc, key) => acc[key], instance); // If the target is atomic, it forces us to switch the root
|
|
142
|
-
|
|
143
|
-
if (!(targetProp && targetProp.set)) {
|
|
144
|
-
const [name, ...reverseEntries] = entries.reverse();
|
|
145
|
-
currentInstance = reverseEntries.reverse().reduce((acc, key) => acc[key], instance);
|
|
146
|
-
key = name;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
changes.push([key, value, false, currentInstance, targetProp]);
|
|
151
|
-
});
|
|
152
|
-
const memoized = { ...props
|
|
153
|
-
};
|
|
154
|
-
if (localState.memoizedProps && localState.memoizedProps.args) memoized.args = localState.memoizedProps.args;
|
|
155
|
-
if (localState.memoizedProps && localState.memoizedProps.attach) memoized.attach = localState.memoizedProps.attach;
|
|
156
|
-
return {
|
|
157
|
-
memoized,
|
|
158
|
-
changes
|
|
159
|
-
};
|
|
160
|
-
} // This function applies a set of changes to the instance
|
|
161
|
-
|
|
162
|
-
function applyProps$1(instance, data) {
|
|
163
|
-
var _instance$__r3f3, _root$getState, _localState$handlers, _localState$handlers2;
|
|
164
|
-
|
|
165
|
-
// Filter equals, events and reserved props
|
|
166
|
-
const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {};
|
|
167
|
-
const root = localState.root;
|
|
168
|
-
const rootState = (_root$getState = root == null ? void 0 : root.getState == null ? void 0 : root.getState()) != null ? _root$getState : {};
|
|
169
|
-
const {
|
|
170
|
-
memoized,
|
|
171
|
-
changes
|
|
172
|
-
} = isDiffSet(data) ? data : diffProps(instance, data);
|
|
173
|
-
const prevHandlers = (_localState$handlers = localState.handlers) == null ? void 0 : _localState$handlers.count; // Prepare memoized props
|
|
174
|
-
|
|
175
|
-
if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
|
|
176
|
-
changes.forEach(([key, value, isEvent, currentInstance, targetProp]) => {
|
|
177
|
-
// https://github.com/mrdoob/three.js/issues/21209
|
|
178
|
-
// HMR/fast-refresh relies on the ability to cancel out props, but threejs
|
|
179
|
-
// has no means to do this. Hence we curate a small collection of value-classes
|
|
180
|
-
// with their respective constructor/set arguments
|
|
181
|
-
// For removed props, try to set default values, if possible
|
|
182
|
-
if (value === DEFAULT + 'remove') {
|
|
183
|
-
if (targetProp && targetProp.constructor) {
|
|
184
|
-
// use the prop constructor to find the default it should be
|
|
185
|
-
value = new targetProp.constructor(memoized.args);
|
|
186
|
-
} else if (currentInstance.constructor) {
|
|
187
|
-
// create a blank slate of the instance and copy the particular parameter.
|
|
188
|
-
// @ts-ignore
|
|
189
|
-
const defaultClassCall = new currentInstance.constructor(currentInstance.__r3f.memoizedProps.args);
|
|
190
|
-
value = defaultClassCall[targetProp]; // destory the instance
|
|
191
|
-
|
|
192
|
-
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
193
|
-
} else value = 0;
|
|
194
|
-
} // Deal with pointer events ...
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (isEvent) {
|
|
198
|
-
if (value) localState.handlers[key] = value;else delete localState.handlers[key];
|
|
199
|
-
localState.handlers.count = Object.keys(localState.handlers).length;
|
|
200
|
-
} // Special treatment for objects with support for set/copy, and layers
|
|
201
|
-
else if (targetProp && targetProp.set && (targetProp.copy || targetProp instanceof THREE__namespace.Layers)) {
|
|
202
|
-
// If value is an array
|
|
203
|
-
if (Array.isArray(value)) {
|
|
204
|
-
if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
|
|
205
|
-
} // Test again target.copy(class) next ...
|
|
206
|
-
else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) targetProp.copy(value); // If nothing else fits, just set the single value, ignore undefined
|
|
207
|
-
// https://github.com/react-spring/react-three-fiber/issues/274
|
|
208
|
-
else if (value !== undefined) {
|
|
209
|
-
const isColor = targetProp instanceof THREE__namespace.Color; // Allow setting array scalars
|
|
210
|
-
|
|
211
|
-
if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
|
|
212
|
-
else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
|
|
213
|
-
else targetProp.set(value); // Auto-convert sRGB colors, for now ...
|
|
214
|
-
// https://github.com/react-spring/react-three-fiber/issues/344
|
|
215
|
-
|
|
216
|
-
if (!rootState.linear && isColor) targetProp.convertSRGBToLinear();
|
|
217
|
-
} // Else, just overwrite the value
|
|
218
|
-
|
|
219
|
-
} else {
|
|
220
|
-
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
221
|
-
// https://github.com/react-spring/react-three-fiber/issues/344
|
|
222
|
-
|
|
223
|
-
if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture) currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
invalidateInstance(instance);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
if (rootState.internal && instance.raycast && prevHandlers !== ((_localState$handlers2 = localState.handlers) == null ? void 0 : _localState$handlers2.count)) {
|
|
230
|
-
// Pre-emptively remove the instance from the interaction manager
|
|
231
|
-
const index = rootState.internal.interaction.indexOf(instance);
|
|
232
|
-
if (index > -1) rootState.internal.interaction.splice(index, 1); // Add the instance to the interaction manager only when it has handlers
|
|
233
|
-
|
|
234
|
-
if (localState.handlers.count) rootState.internal.interaction.push(instance);
|
|
235
|
-
} // Call the update lifecycle when it is being updated, but only when it is part of the scene
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (changes.length && instance.parent) updateInstance(instance);
|
|
239
|
-
}
|
|
240
|
-
function invalidateInstance(instance) {
|
|
241
|
-
var _instance$__r3f4, _instance$__r3f4$root;
|
|
242
|
-
|
|
243
|
-
const state = (_instance$__r3f4 = instance.__r3f) == null ? void 0 : (_instance$__r3f4$root = _instance$__r3f4.root) == null ? void 0 : _instance$__r3f4$root.getState == null ? void 0 : _instance$__r3f4$root.getState();
|
|
244
|
-
if (state && state.internal.frames === 0) state.invalidate();
|
|
245
|
-
}
|
|
246
|
-
function updateInstance(instance) {
|
|
247
|
-
instance.onUpdate == null ? void 0 : instance.onUpdate(instance);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function makeId(event) {
|
|
251
|
-
return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
function removeInteractivity(store, object) {
|
|
255
|
-
const {
|
|
256
|
-
internal
|
|
257
|
-
} = store.getState(); // Removes every trace of an object from the data store
|
|
258
|
-
|
|
259
|
-
internal.interaction = internal.interaction.filter(o => o !== object);
|
|
260
|
-
internal.initialHits = internal.initialHits.filter(o => o !== object);
|
|
261
|
-
internal.hovered.forEach((value, key) => {
|
|
262
|
-
if (value.eventObject === object || value.object === object) {
|
|
263
|
-
internal.hovered.delete(key);
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
function createEvents(store) {
|
|
268
|
-
const temp = new THREE__namespace.Vector3();
|
|
269
|
-
/** Sets up defaultRaycaster */
|
|
270
|
-
|
|
271
|
-
function prepareRay(event) {
|
|
272
|
-
var _raycaster$computeOff;
|
|
273
|
-
|
|
274
|
-
const state = store.getState();
|
|
275
|
-
const {
|
|
276
|
-
raycaster,
|
|
277
|
-
mouse,
|
|
278
|
-
camera,
|
|
279
|
-
size
|
|
280
|
-
} = state; // https://github.com/pmndrs/react-three-fiber/pull/782
|
|
281
|
-
// Events trigger outside of canvas when moved
|
|
282
|
-
|
|
283
|
-
const {
|
|
284
|
-
offsetX,
|
|
285
|
-
offsetY
|
|
286
|
-
} = (_raycaster$computeOff = raycaster.computeOffsets == null ? void 0 : raycaster.computeOffsets(event, state)) != null ? _raycaster$computeOff : event;
|
|
287
|
-
const {
|
|
288
|
-
width,
|
|
289
|
-
height
|
|
290
|
-
} = size;
|
|
291
|
-
mouse.set(offsetX / width * 2 - 1, -(offsetY / height) * 2 + 1);
|
|
292
|
-
raycaster.setFromCamera(mouse, camera);
|
|
293
|
-
}
|
|
294
|
-
/** Calculates delta */
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
function calculateDistance(event) {
|
|
298
|
-
const {
|
|
299
|
-
internal
|
|
300
|
-
} = store.getState();
|
|
301
|
-
const dx = event.offsetX - internal.initialClick[0];
|
|
302
|
-
const dy = event.offsetY - internal.initialClick[1];
|
|
303
|
-
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
304
|
-
}
|
|
305
|
-
/** Returns true if an instance has a valid pointer-event registered, this excludes scroll, clicks etc */
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
function filterPointerEvents(objects) {
|
|
309
|
-
return objects.filter(obj => ['Move', 'Over', 'Enter', 'Out', 'Leave'].some(name => obj.__r3f.handlers['onPointer' + name]));
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function intersect(filter) {
|
|
313
|
-
const state = store.getState();
|
|
314
|
-
const {
|
|
315
|
-
raycaster,
|
|
316
|
-
internal
|
|
317
|
-
} = state; // Skip event handling when noEvents is set
|
|
318
|
-
|
|
319
|
-
if (!raycaster.enabled) return [];
|
|
320
|
-
const seen = new Set();
|
|
321
|
-
const intersections = []; // Allow callers to eliminate event objects
|
|
322
|
-
|
|
323
|
-
const eventsObjects = filter ? filter(internal.interaction) : internal.interaction; // Intersect known handler objects and filter against duplicates
|
|
324
|
-
|
|
325
|
-
let intersects = raycaster.intersectObjects(eventsObjects, true).filter(item => {
|
|
326
|
-
const id = makeId(item);
|
|
327
|
-
if (seen.has(id)) return false;
|
|
328
|
-
seen.add(id);
|
|
329
|
-
return true;
|
|
330
|
-
}); // https://github.com/mrdoob/three.js/issues/16031
|
|
331
|
-
// Allow custom userland intersect sort order
|
|
332
|
-
|
|
333
|
-
if (raycaster.filter) intersects = raycaster.filter(intersects, state);
|
|
334
|
-
|
|
335
|
-
for (const intersect of intersects) {
|
|
336
|
-
let eventObject = intersect.object; // Bubble event up
|
|
337
|
-
|
|
338
|
-
while (eventObject) {
|
|
339
|
-
if (eventObject.__r3f.handlers.count) intersections.push({ ...intersect,
|
|
340
|
-
eventObject
|
|
341
|
-
});
|
|
342
|
-
eventObject = eventObject.parent;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
return intersections;
|
|
347
|
-
}
|
|
348
|
-
/** Creates filtered intersects and returns an array of positive hits */
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
function patchIntersects(intersections, event) {
|
|
352
|
-
const {
|
|
353
|
-
internal
|
|
354
|
-
} = store.getState(); // If the interaction is captured, make all capturing targets part of the
|
|
355
|
-
// intersect.
|
|
356
|
-
|
|
357
|
-
if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
|
|
358
|
-
intersections.push(...internal.capturedMap.get(event.pointerId).values());
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
return intersections;
|
|
362
|
-
}
|
|
363
|
-
/** Handles intersections by forwarding them to handlers */
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
function handleIntersects(intersections, event, callback) {
|
|
367
|
-
const {
|
|
368
|
-
raycaster,
|
|
369
|
-
mouse,
|
|
370
|
-
camera,
|
|
371
|
-
internal
|
|
372
|
-
} = store.getState(); // If anything has been found, forward it to the event listeners
|
|
373
|
-
|
|
374
|
-
if (intersections.length) {
|
|
375
|
-
const unprojectedPoint = temp.set(mouse.x, mouse.y, 0).unproject(camera);
|
|
376
|
-
const delta = event.type === 'click' ? calculateDistance(event) : 0;
|
|
377
|
-
|
|
378
|
-
const releasePointerCapture = id => event.target.releasePointerCapture(id);
|
|
379
|
-
|
|
380
|
-
const localState = {
|
|
381
|
-
stopped: false
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
for (const hit of intersections) {
|
|
385
|
-
const hasPointerCapture = id => {
|
|
386
|
-
var _internal$capturedMap, _internal$capturedMap2;
|
|
387
|
-
|
|
388
|
-
return (_internal$capturedMap = (_internal$capturedMap2 = internal.capturedMap.get(id)) == null ? void 0 : _internal$capturedMap2.has(hit.eventObject)) != null ? _internal$capturedMap : false;
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
const setPointerCapture = id => {
|
|
392
|
-
if (internal.capturedMap.has(id)) {
|
|
393
|
-
// if the pointerId was previously captured, we add the hit to the
|
|
394
|
-
// event capturedMap.
|
|
395
|
-
internal.capturedMap.get(id).set(hit.eventObject, hit);
|
|
396
|
-
} else {
|
|
397
|
-
// if the pointerId was not previously captured, we create a map
|
|
398
|
-
// containing the hitObject, and the hit. hitObject is used for
|
|
399
|
-
// faster access.
|
|
400
|
-
internal.capturedMap.set(id, new Map([[hit.eventObject, hit]]));
|
|
401
|
-
} // Call the original event now
|
|
402
|
-
event.target.setPointerCapture(id);
|
|
403
|
-
}; // Add native event props
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
let extractEventProps = {};
|
|
407
|
-
|
|
408
|
-
for (let prop in Object.getPrototypeOf(event)) {
|
|
409
|
-
let property = event[prop]; // Only copy over atomics, leave functions alone as these should be
|
|
410
|
-
// called as event.nativeEvent.fn()
|
|
411
|
-
|
|
412
|
-
if (typeof property !== 'function') extractEventProps[prop] = property;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
let raycastEvent = { ...hit,
|
|
416
|
-
...extractEventProps,
|
|
417
|
-
spaceX: mouse.x,
|
|
418
|
-
spaceY: mouse.y,
|
|
419
|
-
intersections,
|
|
420
|
-
stopped: localState.stopped,
|
|
421
|
-
delta,
|
|
422
|
-
unprojectedPoint,
|
|
423
|
-
ray: raycaster.ray,
|
|
424
|
-
camera: camera,
|
|
425
|
-
// Hijack stopPropagation, which just sets a flag
|
|
426
|
-
stopPropagation: () => {
|
|
427
|
-
// https://github.com/pmndrs/react-three-fiber/issues/596
|
|
428
|
-
// Events are not allowed to stop propagation if the pointer has been captured
|
|
429
|
-
const capturesForPointer = 'pointerId' in event && internal.capturedMap.get(event.pointerId); // We only authorize stopPropagation...
|
|
430
|
-
|
|
431
|
-
if ( // ...if this pointer hasn't been captured
|
|
432
|
-
!capturesForPointer || // ... or if the hit object is capturing the pointer
|
|
433
|
-
capturesForPointer.has(hit.eventObject)) {
|
|
434
|
-
raycastEvent.stopped = localState.stopped = true; // Propagation is stopped, remove all other hover records
|
|
435
|
-
// An event handler is only allowed to flush other handlers if it is hovered itself
|
|
436
|
-
|
|
437
|
-
if (internal.hovered.size && Array.from(internal.hovered.values()).find(i => i.eventObject === hit.eventObject)) {
|
|
438
|
-
// Objects cannot flush out higher up objects that have already caught the event
|
|
439
|
-
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
440
|
-
cancelPointer([...higher, hit]);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
},
|
|
444
|
-
// there should be a distinction between target and currentTarget
|
|
445
|
-
target: {
|
|
446
|
-
hasPointerCapture,
|
|
447
|
-
setPointerCapture,
|
|
448
|
-
releasePointerCapture
|
|
449
|
-
},
|
|
450
|
-
currentTarget: {
|
|
451
|
-
hasPointerCapture,
|
|
452
|
-
setPointerCapture,
|
|
453
|
-
releasePointerCapture
|
|
454
|
-
},
|
|
455
|
-
sourceEvent: event,
|
|
456
|
-
// deprecated
|
|
457
|
-
nativeEvent: event
|
|
458
|
-
}; // Call subscribers
|
|
459
|
-
|
|
460
|
-
callback(raycastEvent); // Event bubbling may be interrupted by stopPropagation
|
|
461
|
-
|
|
462
|
-
if (localState.stopped === true) break;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
return intersections;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function cancelPointer(hits) {
|
|
470
|
-
const {
|
|
471
|
-
internal
|
|
472
|
-
} = store.getState();
|
|
473
|
-
Array.from(internal.hovered.values()).forEach(hoveredObj => {
|
|
474
|
-
// When no objects were hit or the the hovered object wasn't found underneath the cursor
|
|
475
|
-
// we call onPointerOut and delete the object from the hovered-elements map
|
|
476
|
-
if (!hits.length || !hits.find(hit => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId)) {
|
|
477
|
-
const eventObject = hoveredObj.eventObject;
|
|
478
|
-
const handlers = eventObject.__r3f.handlers;
|
|
479
|
-
internal.hovered.delete(makeId(hoveredObj));
|
|
480
|
-
|
|
481
|
-
if (handlers.count) {
|
|
482
|
-
// Clear out intersects, they are outdated by now
|
|
483
|
-
const data = { ...hoveredObj,
|
|
484
|
-
intersections: hits || []
|
|
485
|
-
};
|
|
486
|
-
handlers.onPointerOut == null ? void 0 : handlers.onPointerOut(data);
|
|
487
|
-
handlers.onPointerLeave == null ? void 0 : handlers.onPointerLeave(data);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
const handlePointer = name => {
|
|
494
|
-
// Deal with cancelation
|
|
495
|
-
switch (name) {
|
|
496
|
-
case 'onPointerLeave':
|
|
497
|
-
case 'onPointerCancel':
|
|
498
|
-
return () => cancelPointer([]);
|
|
499
|
-
|
|
500
|
-
case 'onLostPointerCapture':
|
|
501
|
-
return event => {
|
|
502
|
-
if ('pointerId' in event) {
|
|
503
|
-
// this will be a problem if one target releases the pointerId
|
|
504
|
-
// and another one is still keeping it, as the line below
|
|
505
|
-
// indifferently deletes all capturing references.
|
|
506
|
-
store.getState().internal.capturedMap.delete(event.pointerId);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
cancelPointer([]);
|
|
510
|
-
};
|
|
511
|
-
} // Any other pointer goes here ...
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
return event => {
|
|
515
|
-
const {
|
|
516
|
-
onPointerMissed,
|
|
517
|
-
internal
|
|
518
|
-
} = store.getState();
|
|
519
|
-
prepareRay(event); // Get fresh intersects
|
|
520
|
-
|
|
521
|
-
const isPointerMove = name === 'onPointerMove';
|
|
522
|
-
const filter = isPointerMove ? filterPointerEvents : undefined;
|
|
523
|
-
const hits = patchIntersects(intersect(filter), event); // Take care of unhover
|
|
524
|
-
|
|
525
|
-
if (isPointerMove) cancelPointer(hits);
|
|
526
|
-
handleIntersects(hits, event, data => {
|
|
527
|
-
const eventObject = data.eventObject;
|
|
528
|
-
const handlers = eventObject.__r3f.handlers; // Check presence of handlers
|
|
529
|
-
|
|
530
|
-
if (!handlers.count) return;
|
|
531
|
-
|
|
532
|
-
if (isPointerMove) {
|
|
533
|
-
// Move event ...
|
|
534
|
-
if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
|
|
535
|
-
// When enter or out is present take care of hover-state
|
|
536
|
-
const id = makeId(data);
|
|
537
|
-
const hoveredItem = internal.hovered.get(id);
|
|
538
|
-
|
|
539
|
-
if (!hoveredItem) {
|
|
540
|
-
// If the object wasn't previously hovered, book it and call its handler
|
|
541
|
-
internal.hovered.set(id, data);
|
|
542
|
-
handlers.onPointerOver == null ? void 0 : handlers.onPointerOver(data);
|
|
543
|
-
handlers.onPointerEnter == null ? void 0 : handlers.onPointerEnter(data);
|
|
544
|
-
} else if (hoveredItem.stopped) {
|
|
545
|
-
// If the object was previously hovered and stopped, we shouldn't allow other items to proceed
|
|
546
|
-
data.stopPropagation();
|
|
547
|
-
}
|
|
548
|
-
} // Call mouse move
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
handlers.onPointerMove == null ? void 0 : handlers.onPointerMove(data);
|
|
552
|
-
} else {
|
|
553
|
-
// All other events ...
|
|
554
|
-
const handler = handlers[name];
|
|
555
|
-
|
|
556
|
-
if (handler) {
|
|
557
|
-
// Forward all events back to their respective handlers with the exception of click events,
|
|
558
|
-
// which must use the initial target
|
|
559
|
-
if (name !== 'onClick' && name !== 'onContextMenu' && name !== 'onDoubleClick' || internal.initialHits.includes(eventObject)) {
|
|
560
|
-
handler(data);
|
|
561
|
-
pointerMissed(event, internal.interaction.filter(object => !internal.initialHits.includes(object)));
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}); // Save initial coordinates on pointer-down
|
|
566
|
-
|
|
567
|
-
if (name === 'onPointerDown') {
|
|
568
|
-
internal.initialClick = [event.offsetX, event.offsetY];
|
|
569
|
-
internal.initialHits = hits.map(hit => hit.eventObject);
|
|
570
|
-
} // If a click yields no results, pass it back to the user as a miss
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
if ((name === 'onClick' || name === 'onContextMenu' || name === 'onDoubleClick') && !hits.length) {
|
|
574
|
-
if (calculateDistance(event) <= 2) {
|
|
575
|
-
pointerMissed(event, internal.interaction);
|
|
576
|
-
if (onPointerMissed) onPointerMissed(event);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
function pointerMissed(event, objects) {
|
|
583
|
-
objects.forEach(object => {
|
|
584
|
-
var _r3f$handlers$onPoin, _r3f$handlers;
|
|
585
|
-
|
|
586
|
-
return (_r3f$handlers$onPoin = (_r3f$handlers = object.__r3f.handlers).onPointerMissed) == null ? void 0 : _r3f$handlers$onPoin.call(_r3f$handlers, event);
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
return {
|
|
591
|
-
handlePointer
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
// Type guard to tell a store from a portal
|
|
596
|
-
const isStore = def => def && !!def.getState;
|
|
597
|
-
|
|
598
|
-
const getContainer = (container, child) => {
|
|
599
|
-
var _container$__r3f$root, _container$__r3f;
|
|
600
|
-
|
|
601
|
-
return {
|
|
602
|
-
// If the container is not a root-store then it must be a THREE.Object3D into which part of the
|
|
603
|
-
// scene is portalled into. Now there can be two variants of this, either that object is part of
|
|
604
|
-
// the regular jsx tree, in which case it already has __r3f with a valid root attached, or it lies
|
|
605
|
-
// outside react, in which case we must take the root of the child that is about to be attached to it.
|
|
606
|
-
root: isStore(container) ? container : (_container$__r3f$root = (_container$__r3f = container.__r3f) == null ? void 0 : _container$__r3f.root) != null ? _container$__r3f$root : child.__r3f.root,
|
|
607
|
-
// The container is the eventual target into which objects are mounted, it has to be a THREE.Object3D
|
|
608
|
-
container: isStore(container) ? container.getState().scene : container
|
|
609
|
-
};
|
|
610
|
-
};
|
|
611
|
-
|
|
612
|
-
let catalogue = {};
|
|
613
|
-
|
|
614
|
-
let extend = objects => void (catalogue = { ...catalogue,
|
|
615
|
-
...objects
|
|
616
|
-
});
|
|
617
|
-
|
|
618
|
-
function createRenderer(roots, getEventPriority) {
|
|
619
|
-
function createInstance(type, {
|
|
620
|
-
args = [],
|
|
621
|
-
...props
|
|
622
|
-
}, root, hostContext, internalInstanceHandle) {
|
|
623
|
-
let name = `${type[0].toUpperCase()}${type.slice(1)}`;
|
|
624
|
-
let instance; // https://github.com/facebook/react/issues/17147
|
|
625
|
-
// Portals do not give us a root, they are themselves treated as a root by the reconciler
|
|
626
|
-
// In order to figure out the actual root we have to climb through fiber internals :(
|
|
627
|
-
|
|
628
|
-
if (!isStore(root) && internalInstanceHandle) {
|
|
629
|
-
const fn = node => {
|
|
630
|
-
if (!node.return) return node.stateNode && node.stateNode.containerInfo;else return fn(node.return);
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
root = fn(internalInstanceHandle);
|
|
634
|
-
} // Assert that by now we have a valid root
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
if (!root || !isStore(root)) throw `No valid root for ${name}!`;
|
|
638
|
-
|
|
639
|
-
if (type === 'primitive') {
|
|
640
|
-
if (props.object === undefined) throw `Primitives without 'object' are invalid!`;
|
|
641
|
-
const object = props.object;
|
|
642
|
-
instance = prepare(object, {
|
|
643
|
-
root,
|
|
644
|
-
primitive: true
|
|
645
|
-
});
|
|
646
|
-
} else {
|
|
647
|
-
const target = catalogue[name] || THREE__namespace[name];
|
|
648
|
-
if (!target) throw `${name} is not part of the THREE namespace! Did you forget to extend? See: https://github.com/pmndrs/react-three-fiber/blob/master/markdown/api.md#using-3rd-party-objects-declaratively`;
|
|
649
|
-
const isArgsArr = is.arr(args); // Instanciate new object, link it to the root
|
|
650
|
-
|
|
651
|
-
instance = prepare(isArgsArr ? new target(...args) : new target(args), {
|
|
652
|
-
root,
|
|
653
|
-
// append memoized props with args so it's not forgotten
|
|
654
|
-
memoizedProps: {
|
|
655
|
-
args: isArgsArr && args.length === 0 ? null : args
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
} // Auto-attach geometries and materials
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
if (!('attachFns' in props)) {
|
|
662
|
-
if (name.endsWith('Geometry')) {
|
|
663
|
-
props = {
|
|
664
|
-
attach: 'geometry',
|
|
665
|
-
...props
|
|
666
|
-
};
|
|
667
|
-
} else if (name.endsWith('Material')) {
|
|
668
|
-
props = {
|
|
669
|
-
attach: 'material',
|
|
670
|
-
...props
|
|
671
|
-
};
|
|
672
|
-
}
|
|
673
|
-
} // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
|
|
674
|
-
// view yet. If the callback relies on references for instance, they won't be ready yet, this is
|
|
675
|
-
// why it passes "true" here
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
applyProps$1(instance, props);
|
|
679
|
-
return instance;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
function appendChild(parentInstance, child) {
|
|
683
|
-
let addedAsChild = false;
|
|
684
|
-
|
|
685
|
-
if (child) {
|
|
686
|
-
// The attach attribute implies that the object attaches itself on the parent
|
|
687
|
-
if (child.attachArray) {
|
|
688
|
-
if (!is.arr(parentInstance[child.attachArray])) parentInstance[child.attachArray] = [];
|
|
689
|
-
parentInstance[child.attachArray].push(child);
|
|
690
|
-
} else if (child.attachObject) {
|
|
691
|
-
if (!is.obj(parentInstance[child.attachObject[0]])) parentInstance[child.attachObject[0]] = {};
|
|
692
|
-
parentInstance[child.attachObject[0]][child.attachObject[1]] = child;
|
|
693
|
-
} else if (child.attach && !is.fun(child.attach)) {
|
|
694
|
-
parentInstance[child.attach] = child;
|
|
695
|
-
} else if (is.arr(child.attachFns)) {
|
|
696
|
-
const [attachFn] = child.attachFns;
|
|
697
|
-
|
|
698
|
-
if (is.str(attachFn) && is.fun(parentInstance[attachFn])) {
|
|
699
|
-
parentInstance[attachFn](child);
|
|
700
|
-
} else if (is.fun(attachFn)) {
|
|
701
|
-
attachFn(child, parentInstance);
|
|
702
|
-
}
|
|
703
|
-
} else if (child.isObject3D) {
|
|
704
|
-
// add in the usual parent-child way
|
|
705
|
-
parentInstance.add(child);
|
|
706
|
-
addedAsChild = true;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
if (!addedAsChild) {
|
|
710
|
-
// This is for anything that used attach, and for non-Object3Ds that don't get attached to props;
|
|
711
|
-
// that is, anything that's a child in React but not a child in the scenegraph.
|
|
712
|
-
parentInstance.__r3f.objects.push(child);
|
|
713
|
-
|
|
714
|
-
child.parent = parentInstance;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
updateInstance(child);
|
|
718
|
-
invalidateInstance(child);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
function insertBefore(parentInstance, child, beforeChild) {
|
|
723
|
-
let added = false;
|
|
724
|
-
|
|
725
|
-
if (child) {
|
|
726
|
-
if (child.attachArray) {
|
|
727
|
-
const array = parentInstance[child.attachArray];
|
|
728
|
-
if (!is.arr(array)) parentInstance[child.attachArray] = [];
|
|
729
|
-
array.splice(array.indexOf(beforeChild), 0, child);
|
|
730
|
-
} else if (child.attachObject || child.attach && !is.fun(child.attach)) {
|
|
731
|
-
// attach and attachObject don't have an order anyway, so just append
|
|
732
|
-
return appendChild(parentInstance, child);
|
|
733
|
-
} else if (child.isObject3D) {
|
|
734
|
-
child.parent = parentInstance;
|
|
735
|
-
child.dispatchEvent({
|
|
736
|
-
type: 'added'
|
|
737
|
-
});
|
|
738
|
-
const restSiblings = parentInstance.children.filter(sibling => sibling !== child);
|
|
739
|
-
const index = restSiblings.indexOf(beforeChild);
|
|
740
|
-
parentInstance.children = [...restSiblings.slice(0, index), child, ...restSiblings.slice(index)];
|
|
741
|
-
added = true;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
if (!added) {
|
|
745
|
-
parentInstance.__r3f.objects.push(child);
|
|
746
|
-
|
|
747
|
-
child.parent = parentInstance;
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
updateInstance(child);
|
|
751
|
-
invalidateInstance(child);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
function removeRecursive(array, parent, dispose = false) {
|
|
756
|
-
if (array) [...array].forEach(child => removeChild(parent, child, dispose));
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
function removeChild(parentInstance, child, dispose) {
|
|
760
|
-
if (child) {
|
|
761
|
-
var _child$__r3f2;
|
|
762
|
-
|
|
763
|
-
if (parentInstance.__r3f.objects) {
|
|
764
|
-
const oldLength = parentInstance.__r3f.objects.length;
|
|
765
|
-
parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child);
|
|
766
|
-
const newLength = parentInstance.__r3f.objects.length; // was it in the list?
|
|
767
|
-
|
|
768
|
-
if (newLength < oldLength) {
|
|
769
|
-
// we had also set this, so we must clear it now
|
|
770
|
-
child.parent = null;
|
|
771
|
-
}
|
|
772
|
-
} // Remove attachment
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
if (child.attachArray) {
|
|
776
|
-
parentInstance[child.attachArray] = parentInstance[child.attachArray].filter(x => x !== child);
|
|
777
|
-
} else if (child.attachObject) {
|
|
778
|
-
delete parentInstance[child.attachObject[0]][child.attachObject[1]];
|
|
779
|
-
} else if (child.attach && !is.fun(child.attach)) {
|
|
780
|
-
parentInstance[child.attach] = null;
|
|
781
|
-
} else if (is.arr(child.attachFns)) {
|
|
782
|
-
const [, detachFn] = child.attachFns;
|
|
783
|
-
|
|
784
|
-
if (is.str(detachFn) && is.fun(parentInstance[detachFn])) {
|
|
785
|
-
parentInstance[detachFn](child);
|
|
786
|
-
} else if (is.fun(detachFn)) {
|
|
787
|
-
detachFn(child, parentInstance);
|
|
788
|
-
}
|
|
789
|
-
} else if (child.isObject3D) {
|
|
790
|
-
var _child$__r3f;
|
|
791
|
-
|
|
792
|
-
parentInstance.remove(child); // Remove interactivity
|
|
793
|
-
|
|
794
|
-
if ((_child$__r3f = child.__r3f) != null && _child$__r3f.root) {
|
|
795
|
-
removeInteractivity(child.__r3f.root, child);
|
|
796
|
-
}
|
|
797
|
-
} // Allow objects to bail out of recursive dispose alltogether by passing dispose={null}
|
|
798
|
-
// Never dispose of primitives because their state may be kept outside of React!
|
|
799
|
-
// In order for an object to be able to dispose it has to have
|
|
800
|
-
// - a dispose method,
|
|
801
|
-
// - it cannot be a <primitive object={...} />
|
|
802
|
-
// - it cannot be a THREE.Scene, because three has broken it's own api
|
|
803
|
-
//
|
|
804
|
-
// Since disposal is recursive, we can check the optional dispose arg, which will be undefined
|
|
805
|
-
// when the reconciler calls it, but then carry our own check recursively
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
const isPrimitive = (_child$__r3f2 = child.__r3f) == null ? void 0 : _child$__r3f2.primitive;
|
|
809
|
-
const shouldDispose = dispose === undefined ? child.dispose !== null && !isPrimitive : dispose; // Remove nested child objects. Primitives should not have objects and children that are
|
|
810
|
-
// attached to them declaratively ...
|
|
811
|
-
|
|
812
|
-
if (!isPrimitive) {
|
|
813
|
-
var _child$__r3f3;
|
|
814
|
-
|
|
815
|
-
removeRecursive((_child$__r3f3 = child.__r3f) == null ? void 0 : _child$__r3f3.objects, child, shouldDispose);
|
|
816
|
-
removeRecursive(child.children, child, shouldDispose);
|
|
817
|
-
} // Remove references
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
if (child.__r3f) {
|
|
821
|
-
delete child.__r3f.root;
|
|
822
|
-
delete child.__r3f.objects;
|
|
823
|
-
delete child.__r3f.handlers;
|
|
824
|
-
delete child.__r3f.memoizedProps;
|
|
825
|
-
if (!isPrimitive) delete child.__r3f;
|
|
826
|
-
} // Dispose item whenever the reconciler feels like it
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
if (shouldDispose && child.dispose && child.type !== 'Scene') {
|
|
830
|
-
reconciler.runWithPriority(constants.IdleEventPriority, () => {
|
|
831
|
-
try {
|
|
832
|
-
child.dispose();
|
|
833
|
-
} catch (e) {
|
|
834
|
-
/* ... */
|
|
835
|
-
}
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
invalidateInstance(parentInstance);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
function switchInstance(instance, type, newProps, fiber) {
|
|
844
|
-
const parent = instance.parent;
|
|
845
|
-
if (!parent) return;
|
|
846
|
-
const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
|
|
847
|
-
// When args change the instance has to be re-constructed, which then
|
|
848
|
-
// forces r3f to re-parent the children and non-scene objects
|
|
849
|
-
|
|
850
|
-
if (instance.children) {
|
|
851
|
-
instance.children.forEach(child => appendChild(newInstance, child));
|
|
852
|
-
instance.children = [];
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
|
|
856
|
-
|
|
857
|
-
instance.__r3f.objects = [];
|
|
858
|
-
removeChild(parent, instance);
|
|
859
|
-
appendChild(parent, newInstance) // This evil hack switches the react-internal fiber node
|
|
860
|
-
// https://github.com/facebook/react/issues/14983
|
|
861
|
-
// https://github.com/facebook/react/pull/15021
|
|
862
|
-
;
|
|
863
|
-
[fiber, fiber.alternate].forEach(fiber => {
|
|
864
|
-
if (fiber !== null) {
|
|
865
|
-
fiber.stateNode = newInstance;
|
|
866
|
-
|
|
867
|
-
if (fiber.ref) {
|
|
868
|
-
if (typeof fiber.ref === 'function') fiber.ref(newInstance);else fiber.ref.current = newInstance;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
});
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
const reconciler = Reconciler__default['default']({
|
|
875
|
-
appendChildToContainer: (parentInstance, child) => {
|
|
876
|
-
const {
|
|
877
|
-
container,
|
|
878
|
-
root
|
|
879
|
-
} = getContainer(parentInstance, child); // Link current root to the default scene
|
|
880
|
-
|
|
881
|
-
container.__r3f.root = root;
|
|
882
|
-
appendChild(container, child);
|
|
883
|
-
},
|
|
884
|
-
removeChildFromContainer: (parentInstance, child) => removeChild(getContainer(parentInstance, child).container, child),
|
|
885
|
-
insertInContainerBefore: (parentInstance, child, beforeChild) => insertBefore(getContainer(parentInstance, child).container, child, beforeChild),
|
|
886
|
-
|
|
887
|
-
prepareUpdate(instance, type, oldProps, newProps) {
|
|
888
|
-
if (instance.__r3f.primitive && newProps.object && newProps.object !== instance) return [true];else {
|
|
889
|
-
// This is a data object, let's extract critical information about it
|
|
890
|
-
const {
|
|
891
|
-
args: argsNew = [],
|
|
892
|
-
children: cN,
|
|
893
|
-
...restNew
|
|
894
|
-
} = newProps;
|
|
895
|
-
const {
|
|
896
|
-
args: argsOld = [],
|
|
897
|
-
children: cO,
|
|
898
|
-
...restOld
|
|
899
|
-
} = oldProps; // If it has new props or arguments, then it needs to be re-instanciated
|
|
900
|
-
|
|
901
|
-
if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
|
|
902
|
-
|
|
903
|
-
const diff = diffProps(instance, restNew, restOld, true);
|
|
904
|
-
if (diff.changes.length) return [false, diff]; // Otherwise do not touch the instance
|
|
905
|
-
|
|
906
|
-
return null;
|
|
907
|
-
}
|
|
908
|
-
},
|
|
909
|
-
|
|
910
|
-
commitUpdate(instance, [reconstruct, diff], type, oldProps, newProps, fiber) {
|
|
911
|
-
// Reconstruct when args or <primitive object={...} have changes
|
|
912
|
-
if (reconstruct) switchInstance(instance, type, newProps, fiber); // Otherwise just overwrite props
|
|
913
|
-
else applyProps$1(instance, diff);
|
|
914
|
-
},
|
|
915
|
-
|
|
916
|
-
hideInstance(instance) {
|
|
917
|
-
if (instance.isObject3D) {
|
|
918
|
-
instance.visible = false;
|
|
919
|
-
invalidateInstance(instance);
|
|
920
|
-
}
|
|
921
|
-
},
|
|
922
|
-
|
|
923
|
-
unhideInstance(instance, props) {
|
|
924
|
-
if (instance.isObject3D && props.visible == null || props.visible) {
|
|
925
|
-
instance.visible = true;
|
|
926
|
-
invalidateInstance(instance);
|
|
927
|
-
}
|
|
928
|
-
},
|
|
929
|
-
|
|
930
|
-
createInstance,
|
|
931
|
-
removeChild,
|
|
932
|
-
appendChild,
|
|
933
|
-
appendInitialChild: appendChild,
|
|
934
|
-
insertBefore,
|
|
935
|
-
warnsIfNotActing: true,
|
|
936
|
-
supportsMutation: true,
|
|
937
|
-
isPrimaryRenderer: false,
|
|
938
|
-
getCurrentEventPriority: () => getEventPriority ? getEventPriority() : constants.DefaultEventPriority,
|
|
939
|
-
// @ts-ignore
|
|
940
|
-
now: is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
|
|
941
|
-
// @ts-ignore
|
|
942
|
-
scheduleTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
943
|
-
// @ts-ignore
|
|
944
|
-
cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
|
|
945
|
-
setTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
946
|
-
clearTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
|
|
947
|
-
noTimeout: -1,
|
|
948
|
-
hideTextInstance: () => {
|
|
949
|
-
throw new Error('Text is not allowed in the R3F tree.');
|
|
950
|
-
},
|
|
951
|
-
// prettier-ignore
|
|
952
|
-
getPublicInstance: instance => instance,
|
|
953
|
-
getRootHostContext: () => null,
|
|
954
|
-
getChildHostContext: parentHostContext => parentHostContext,
|
|
955
|
-
createTextInstance: () => {},
|
|
956
|
-
finalizeInitialChildren: () => false,
|
|
957
|
-
commitMount: () => {},
|
|
958
|
-
shouldDeprioritizeSubtree: () => false,
|
|
959
|
-
prepareForCommit: () => null,
|
|
960
|
-
preparePortalMount: containerInfo => prepare(containerInfo),
|
|
961
|
-
resetAfterCommit: () => {},
|
|
962
|
-
shouldSetTextContent: () => false,
|
|
963
|
-
clearContainer: () => false,
|
|
964
|
-
detachDeletedInstance: () => {}
|
|
965
|
-
});
|
|
966
|
-
return {
|
|
967
|
-
reconciler,
|
|
968
|
-
applyProps: applyProps$1
|
|
969
|
-
};
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
const isRenderer = def => def && !!def.render;
|
|
973
|
-
const isOrthographicCamera = def => def && def.isOrthographicCamera;
|
|
974
|
-
const context = /*#__PURE__*/React__namespace.createContext(null);
|
|
975
|
-
|
|
976
|
-
const createStore = (applyProps, invalidate, advance, props) => {
|
|
977
|
-
const {
|
|
978
|
-
gl,
|
|
979
|
-
size,
|
|
980
|
-
shadows = false,
|
|
981
|
-
linear = false,
|
|
982
|
-
flat = false,
|
|
983
|
-
vr = false,
|
|
984
|
-
orthographic = false,
|
|
985
|
-
frameloop = 'always',
|
|
986
|
-
dpr = 1,
|
|
987
|
-
performance,
|
|
988
|
-
clock = new THREE__namespace.Clock(),
|
|
989
|
-
raycaster: raycastOptions,
|
|
990
|
-
camera: cameraOptions,
|
|
991
|
-
onPointerMissed
|
|
992
|
-
} = props; // Set shadowmap
|
|
993
|
-
|
|
994
|
-
if (shadows) {
|
|
995
|
-
gl.shadowMap.enabled = true;
|
|
996
|
-
if (typeof shadows === 'object') Object.assign(gl.shadowMap, shadows);else gl.shadowMap.type = THREE__namespace.PCFSoftShadowMap;
|
|
997
|
-
} // Set color management
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
if (!linear) gl.outputEncoding = THREE__namespace.sRGBEncoding;
|
|
1001
|
-
if (!flat) gl.toneMapping = THREE__namespace.ACESFilmicToneMapping; // clock.elapsedTime is updated using advance(timestamp)
|
|
1002
|
-
|
|
1003
|
-
if (frameloop === 'never') {
|
|
1004
|
-
clock.stop();
|
|
1005
|
-
clock.elapsedTime = 0;
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
const rootState = create__default['default']((set, get) => {
|
|
1009
|
-
// Create custom raycaster
|
|
1010
|
-
const raycaster = new THREE__namespace.Raycaster();
|
|
1011
|
-
const {
|
|
1012
|
-
params,
|
|
1013
|
-
...options
|
|
1014
|
-
} = raycastOptions || {};
|
|
1015
|
-
applyProps(raycaster, {
|
|
1016
|
-
enabled: true,
|
|
1017
|
-
...options,
|
|
1018
|
-
params: { ...raycaster.params,
|
|
1019
|
-
...params
|
|
1020
|
-
}
|
|
1021
|
-
}); // Create default camera
|
|
1022
|
-
|
|
1023
|
-
const isCamera = cameraOptions instanceof THREE__namespace.Camera;
|
|
1024
|
-
const camera = isCamera ? cameraOptions : orthographic ? new THREE__namespace.OrthographicCamera(0, 0, 0, 0, 0.1, 1000) : new THREE__namespace.PerspectiveCamera(75, 0, 0.1, 1000);
|
|
1025
|
-
|
|
1026
|
-
if (!isCamera) {
|
|
1027
|
-
camera.position.z = 5;
|
|
1028
|
-
if (cameraOptions) applyProps(camera, cameraOptions); // Always look at center by default
|
|
1029
|
-
|
|
1030
|
-
camera.lookAt(0, 0, 0);
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
function setDpr(dpr) {
|
|
1034
|
-
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], window.devicePixelRatio), dpr[1]) : dpr;
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
const initialDpr = setDpr(dpr);
|
|
1038
|
-
const position = new THREE__namespace.Vector3();
|
|
1039
|
-
const defaultTarget = new THREE__namespace.Vector3();
|
|
1040
|
-
|
|
1041
|
-
function getCurrentViewport(camera = get().camera, target = defaultTarget, size = get().size) {
|
|
1042
|
-
const {
|
|
1043
|
-
width,
|
|
1044
|
-
height
|
|
1045
|
-
} = size;
|
|
1046
|
-
const aspect = width / height;
|
|
1047
|
-
const distance = camera.getWorldPosition(position).distanceTo(target);
|
|
1048
|
-
|
|
1049
|
-
if (isOrthographicCamera(camera)) {
|
|
1050
|
-
return {
|
|
1051
|
-
width: width / camera.zoom,
|
|
1052
|
-
height: height / camera.zoom,
|
|
1053
|
-
factor: 1,
|
|
1054
|
-
distance,
|
|
1055
|
-
aspect
|
|
1056
|
-
};
|
|
1057
|
-
} else {
|
|
1058
|
-
const fov = camera.fov * Math.PI / 180; // convert vertical fov to radians
|
|
1059
|
-
|
|
1060
|
-
const h = 2 * Math.tan(fov / 2) * distance; // visible height
|
|
1061
|
-
|
|
1062
|
-
const w = h * (width / height);
|
|
1063
|
-
return {
|
|
1064
|
-
width: w,
|
|
1065
|
-
height: h,
|
|
1066
|
-
factor: width / w,
|
|
1067
|
-
distance,
|
|
1068
|
-
aspect
|
|
1069
|
-
};
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
let performanceTimeout = undefined;
|
|
1074
|
-
|
|
1075
|
-
const setPerformanceCurrent = current => set(state => ({
|
|
1076
|
-
performance: { ...state.performance,
|
|
1077
|
-
current
|
|
1078
|
-
}
|
|
1079
|
-
}));
|
|
1080
|
-
|
|
1081
|
-
return {
|
|
1082
|
-
gl,
|
|
1083
|
-
set,
|
|
1084
|
-
get,
|
|
1085
|
-
invalidate: () => invalidate(get()),
|
|
1086
|
-
advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
|
|
1087
|
-
linear,
|
|
1088
|
-
flat,
|
|
1089
|
-
scene: prepare(new THREE__namespace.Scene()),
|
|
1090
|
-
camera,
|
|
1091
|
-
controls: null,
|
|
1092
|
-
raycaster,
|
|
1093
|
-
clock,
|
|
1094
|
-
mouse: new THREE__namespace.Vector2(),
|
|
1095
|
-
vr,
|
|
1096
|
-
frameloop,
|
|
1097
|
-
onPointerMissed,
|
|
1098
|
-
performance: {
|
|
1099
|
-
current: 1,
|
|
1100
|
-
min: 0.5,
|
|
1101
|
-
max: 1,
|
|
1102
|
-
debounce: 200,
|
|
1103
|
-
...performance,
|
|
1104
|
-
regress: () => {
|
|
1105
|
-
const state = get(); // Clear timeout
|
|
1106
|
-
|
|
1107
|
-
if (performanceTimeout) clearTimeout(performanceTimeout); // Set lower bound performance
|
|
1108
|
-
|
|
1109
|
-
if (state.performance.current !== state.performance.min) setPerformanceCurrent(state.performance.min); // Go back to upper bound performance after a while unless something regresses meanwhile
|
|
1110
|
-
|
|
1111
|
-
performanceTimeout = setTimeout(() => setPerformanceCurrent(get().performance.max), state.performance.debounce);
|
|
1112
|
-
}
|
|
1113
|
-
},
|
|
1114
|
-
size: {
|
|
1115
|
-
width: 0,
|
|
1116
|
-
height: 0
|
|
1117
|
-
},
|
|
1118
|
-
viewport: {
|
|
1119
|
-
initialDpr,
|
|
1120
|
-
dpr: initialDpr,
|
|
1121
|
-
width: 0,
|
|
1122
|
-
height: 0,
|
|
1123
|
-
aspect: 0,
|
|
1124
|
-
distance: 0,
|
|
1125
|
-
factor: 0,
|
|
1126
|
-
getCurrentViewport
|
|
1127
|
-
},
|
|
1128
|
-
setSize: (width, height) => {
|
|
1129
|
-
const size = {
|
|
1130
|
-
width,
|
|
1131
|
-
height
|
|
1132
|
-
};
|
|
1133
|
-
set(state => ({
|
|
1134
|
-
size,
|
|
1135
|
-
viewport: { ...state.viewport,
|
|
1136
|
-
...getCurrentViewport(camera, defaultTarget, size)
|
|
1137
|
-
}
|
|
1138
|
-
}));
|
|
1139
|
-
},
|
|
1140
|
-
setDpr: dpr => set(state => ({
|
|
1141
|
-
viewport: { ...state.viewport,
|
|
1142
|
-
dpr: setDpr(dpr)
|
|
1143
|
-
}
|
|
1144
|
-
})),
|
|
1145
|
-
events: {
|
|
1146
|
-
connected: false
|
|
1147
|
-
},
|
|
1148
|
-
internal: {
|
|
1149
|
-
active: false,
|
|
1150
|
-
priority: 0,
|
|
1151
|
-
frames: 0,
|
|
1152
|
-
lastProps: props,
|
|
1153
|
-
interaction: [],
|
|
1154
|
-
hovered: new Map(),
|
|
1155
|
-
subscribers: [],
|
|
1156
|
-
initialClick: [0, 0],
|
|
1157
|
-
initialHits: [],
|
|
1158
|
-
capturedMap: new Map(),
|
|
1159
|
-
subscribe: (ref, priority = 0) => {
|
|
1160
|
-
set(({
|
|
1161
|
-
internal
|
|
1162
|
-
}) => ({
|
|
1163
|
-
internal: { ...internal,
|
|
1164
|
-
// If this subscription was given a priority, it takes rendering into its own hands
|
|
1165
|
-
// For that reason we switch off automatic rendering and increase the manual flag
|
|
1166
|
-
// As long as this flag is positive there can be no internal rendering at all
|
|
1167
|
-
// because there could be multiple render subscriptions
|
|
1168
|
-
priority: internal.priority + (priority > 0 ? 1 : 0),
|
|
1169
|
-
// Register subscriber and sort layers from lowest to highest, meaning,
|
|
1170
|
-
// highest priority renders last (on top of the other frames)
|
|
1171
|
-
subscribers: [...internal.subscribers, {
|
|
1172
|
-
ref,
|
|
1173
|
-
priority
|
|
1174
|
-
}].sort((a, b) => a.priority - b.priority)
|
|
1175
|
-
}
|
|
1176
|
-
}));
|
|
1177
|
-
return () => {
|
|
1178
|
-
set(({
|
|
1179
|
-
internal
|
|
1180
|
-
}) => ({
|
|
1181
|
-
internal: { ...internal,
|
|
1182
|
-
// Decrease manual flag if this subscription had a priority
|
|
1183
|
-
priority: internal.priority - (priority > 0 ? 1 : 0),
|
|
1184
|
-
// Remove subscriber from list
|
|
1185
|
-
subscribers: internal.subscribers.filter(s => s.ref !== ref)
|
|
1186
|
-
}
|
|
1187
|
-
}));
|
|
1188
|
-
};
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
};
|
|
1192
|
-
}); // Resize camera and renderer on changes to size and pixelratio
|
|
1193
|
-
|
|
1194
|
-
rootState.subscribe(() => {
|
|
1195
|
-
const {
|
|
1196
|
-
camera,
|
|
1197
|
-
size,
|
|
1198
|
-
viewport,
|
|
1199
|
-
internal
|
|
1200
|
-
} = rootState.getState(); // https://github.com/pmndrs/react-three-fiber/issues/92
|
|
1201
|
-
// Do not mess with the camera if it belongs to the user
|
|
1202
|
-
|
|
1203
|
-
if (!(internal.lastProps.camera instanceof THREE__namespace.Camera)) {
|
|
1204
|
-
if (isOrthographicCamera(camera)) {
|
|
1205
|
-
camera.left = size.width / -2;
|
|
1206
|
-
camera.right = size.width / 2;
|
|
1207
|
-
camera.top = size.height / 2;
|
|
1208
|
-
camera.bottom = size.height / -2;
|
|
1209
|
-
} else {
|
|
1210
|
-
camera.aspect = size.width / size.height;
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
camera.updateProjectionMatrix(); // https://github.com/pmndrs/react-three-fiber/issues/178
|
|
1214
|
-
// Update matrix world since the renderer is a frame late
|
|
1215
|
-
|
|
1216
|
-
camera.updateMatrixWorld();
|
|
1217
|
-
} // Update renderer
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
gl.setPixelRatio(viewport.dpr);
|
|
1221
|
-
gl.setSize(size.width, size.height);
|
|
1222
|
-
}, state => [state.viewport.dpr, state.size], shallow__default['default']);
|
|
1223
|
-
const state = rootState.getState(); // Update size
|
|
1224
|
-
|
|
1225
|
-
if (size) state.setSize(size.width, size.height); // Invalidate on any change
|
|
1226
|
-
|
|
1227
|
-
rootState.subscribe(state => invalidate(state)); // Return root state
|
|
1228
|
-
|
|
1229
|
-
return rootState;
|
|
1230
|
-
};
|
|
1231
|
-
|
|
1232
|
-
function createSubs(callback, subs) {
|
|
1233
|
-
const index = subs.length;
|
|
1234
|
-
subs.push(callback);
|
|
1235
|
-
return () => void subs.splice(index, 1);
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
let i;
|
|
1239
|
-
let globalEffects = [];
|
|
1240
|
-
let globalAfterEffects = [];
|
|
1241
|
-
let globalTailEffects = [];
|
|
1242
|
-
const addEffect = callback => createSubs(callback, globalEffects);
|
|
1243
|
-
const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
|
|
1244
|
-
const addTail = callback => createSubs(callback, globalTailEffects);
|
|
1245
|
-
|
|
1246
|
-
function run(effects, timestamp) {
|
|
1247
|
-
for (i = 0; i < effects.length; i++) effects[i](timestamp);
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
function render$1(timestamp, state) {
|
|
1251
|
-
// Run local effects
|
|
1252
|
-
let delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1253
|
-
|
|
1254
|
-
if (state.frameloop === 'never' && typeof timestamp === 'number') {
|
|
1255
|
-
delta = timestamp - state.clock.elapsedTime;
|
|
1256
|
-
state.clock.oldTime = state.clock.elapsedTime;
|
|
1257
|
-
state.clock.elapsedTime = timestamp;
|
|
1258
|
-
} // Call subscribers (useFrame)
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
for (i = 0; i < state.internal.subscribers.length; i++) state.internal.subscribers[i].ref.current(state, delta); // Render content
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
if (!state.internal.priority && state.gl.render) state.gl.render(state.scene, state.camera); // Decrease frame count
|
|
1265
|
-
|
|
1266
|
-
state.internal.frames = Math.max(0, state.internal.frames - 1);
|
|
1267
|
-
return state.frameloop === 'always' ? 1 : state.internal.frames;
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
function createLoop(roots) {
|
|
1271
|
-
let running = false;
|
|
1272
|
-
let repeat;
|
|
1273
|
-
|
|
1274
|
-
function loop(timestamp) {
|
|
1275
|
-
running = true;
|
|
1276
|
-
repeat = 0; // Run effects
|
|
1277
|
-
|
|
1278
|
-
run(globalEffects, timestamp); // Render all roots
|
|
1279
|
-
|
|
1280
|
-
roots.forEach(root => {
|
|
1281
|
-
const state = root.store.getState(); // If the frameloop is invalidated, do not run another frame
|
|
1282
|
-
|
|
1283
|
-
if (state.internal.active && (state.frameloop === 'always' || state.internal.frames > 0)) repeat += render$1(timestamp, state);
|
|
1284
|
-
}); // Run after-effects
|
|
1285
|
-
|
|
1286
|
-
run(globalAfterEffects, timestamp); // Keep on looping if anything invalidates the frameloop
|
|
1287
|
-
|
|
1288
|
-
if (repeat > 0) return requestAnimationFrame(loop); // Tail call effects, they are called when rendering stops
|
|
1289
|
-
else run(globalTailEffects, timestamp); // Flag end of operation
|
|
1290
|
-
|
|
1291
|
-
running = false;
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
function invalidate(state) {
|
|
1295
|
-
if (!state) return roots.forEach(root => invalidate(root.store.getState()));
|
|
1296
|
-
if (state.vr || !state.internal.active || state.frameloop === 'never') return; // Increase frames, do not go higher than 60
|
|
1297
|
-
|
|
1298
|
-
state.internal.frames = Math.min(60, state.internal.frames + 1); // If the render-loop isn't active, start it
|
|
5
|
+
var hooks = require('./hooks-6526f63c.cjs.dev.js');
|
|
6
|
+
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var THREE = require('three');
|
|
9
|
+
var mergeRefs = require('react-merge-refs');
|
|
10
|
+
var useMeasure = require('react-use-measure');
|
|
11
|
+
var constants = require('react-reconciler/constants');
|
|
12
|
+
require('react-reconciler');
|
|
13
|
+
require('scheduler');
|
|
14
|
+
require('suspend-react');
|
|
15
|
+
require('zustand');
|
|
1299
16
|
|
|
1300
|
-
|
|
1301
|
-
running = true;
|
|
1302
|
-
requestAnimationFrame(loop);
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
17
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
1305
18
|
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
19
|
+
function _interopNamespace(e) {
|
|
20
|
+
if (e && e.__esModule) return e;
|
|
21
|
+
var n = Object.create(null);
|
|
22
|
+
if (e) {
|
|
23
|
+
Object.keys(e).forEach(function (k) {
|
|
24
|
+
if (k !== 'default') {
|
|
25
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
26
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () {
|
|
29
|
+
return e[k];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
1310
34
|
}
|
|
1311
|
-
|
|
1312
|
-
return
|
|
1313
|
-
loop,
|
|
1314
|
-
invalidate,
|
|
1315
|
-
advance
|
|
1316
|
-
};
|
|
35
|
+
n['default'] = e;
|
|
36
|
+
return Object.freeze(n);
|
|
1317
37
|
}
|
|
1318
38
|
|
|
39
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
40
|
+
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
41
|
+
var mergeRefs__default = /*#__PURE__*/_interopDefault(mergeRefs);
|
|
42
|
+
var useMeasure__default = /*#__PURE__*/_interopDefault(useMeasure);
|
|
43
|
+
|
|
1319
44
|
// @ts-ignore
|
|
1320
45
|
const CLICK = 'click';
|
|
1321
46
|
const CONTEXTMENU = 'contextmenu';
|
|
@@ -1360,7 +85,7 @@ function getEventPriority() {
|
|
|
1360
85
|
function createPointerEvents(store) {
|
|
1361
86
|
const {
|
|
1362
87
|
handlePointer
|
|
1363
|
-
} = createEvents(store);
|
|
88
|
+
} = hooks.createEvents(store);
|
|
1364
89
|
const names = {
|
|
1365
90
|
onClick: [CLICK, false],
|
|
1366
91
|
onContextMenu: [CONTEXTMENU, false],
|
|
@@ -1423,282 +148,122 @@ function createPointerEvents(store) {
|
|
|
1423
148
|
};
|
|
1424
149
|
}
|
|
1425
150
|
|
|
1426
|
-
// React currently throws a warning when using useLayoutEffect on the server.
|
|
1427
|
-
// To get around it, we can conditionally useEffect on the server (no-op) and
|
|
1428
|
-
// useLayoutEffect in the browser.
|
|
1429
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
1430
|
-
|
|
1431
|
-
function Block({
|
|
1432
|
-
set
|
|
1433
|
-
}) {
|
|
1434
|
-
useIsomorphicLayoutEffect(() => {
|
|
1435
|
-
set(new Promise(() => null));
|
|
1436
|
-
return () => set(false);
|
|
1437
|
-
}, []);
|
|
1438
|
-
return null;
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
class ErrorBoundary extends React__namespace.Component {
|
|
1442
|
-
constructor(...args) {
|
|
1443
|
-
super(...args);
|
|
1444
|
-
this.state = {
|
|
1445
|
-
error: false
|
|
1446
|
-
};
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
componentDidCatch(error) {
|
|
1450
|
-
this.props.set(error);
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
render() {
|
|
1454
|
-
return this.state.error ? null : this.props.children;
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
1460
|
-
error: true
|
|
1461
|
-
});
|
|
1462
|
-
|
|
1463
|
-
const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
1464
|
-
children,
|
|
1465
|
-
fallback,
|
|
1466
|
-
tabIndex,
|
|
1467
|
-
resize,
|
|
1468
|
-
id,
|
|
1469
|
-
style,
|
|
1470
|
-
className,
|
|
1471
|
-
events,
|
|
1472
|
-
...props
|
|
1473
|
-
}, forwardedRef) {
|
|
1474
|
-
const [containerRef, size] = useMeasure__default['default']({
|
|
1475
|
-
scroll: true,
|
|
1476
|
-
debounce: {
|
|
1477
|
-
scroll: 50,
|
|
1478
|
-
resize: 0
|
|
1479
|
-
},
|
|
1480
|
-
...resize
|
|
1481
|
-
});
|
|
1482
|
-
const canvasRef = React__namespace.useRef(null);
|
|
1483
|
-
const [block, setBlock] = React__namespace.useState(false);
|
|
1484
|
-
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
1485
|
-
|
|
1486
|
-
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
1487
|
-
|
|
1488
|
-
if (error) throw error; // Execute JSX in the reconciler as a layout-effect
|
|
1489
|
-
|
|
1490
|
-
useIsomorphicLayoutEffect(() => {
|
|
1491
|
-
if (size.width > 0 && size.height > 0) {
|
|
1492
|
-
render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
1493
|
-
set: setError
|
|
1494
|
-
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
1495
|
-
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
1496
|
-
set: setBlock
|
|
1497
|
-
})
|
|
1498
|
-
}, children)), canvasRef.current, { ...props,
|
|
1499
|
-
size,
|
|
1500
|
-
events: events || createPointerEvents
|
|
1501
|
-
});
|
|
1502
|
-
}
|
|
1503
|
-
}, [size, children]);
|
|
1504
|
-
React__namespace.useEffect(() => {
|
|
1505
|
-
const container = canvasRef.current;
|
|
1506
|
-
return () => unmountComponentAtNode(container);
|
|
1507
|
-
}, []);
|
|
1508
|
-
return /*#__PURE__*/React__namespace.createElement("div", {
|
|
1509
|
-
ref: containerRef,
|
|
1510
|
-
id: id,
|
|
1511
|
-
className: className,
|
|
1512
|
-
tabIndex: tabIndex,
|
|
1513
|
-
style: {
|
|
1514
|
-
position: 'relative',
|
|
1515
|
-
width: '100%',
|
|
1516
|
-
height: '100%',
|
|
1517
|
-
overflow: 'hidden',
|
|
1518
|
-
...style
|
|
1519
|
-
}
|
|
1520
|
-
}, /*#__PURE__*/React__namespace.createElement("canvas", {
|
|
1521
|
-
ref: mergeRefs__default['default']([canvasRef, forwardedRef]),
|
|
1522
|
-
style: {
|
|
1523
|
-
display: 'block'
|
|
1524
|
-
}
|
|
1525
|
-
}, fallback));
|
|
1526
|
-
});
|
|
1527
|
-
|
|
1528
|
-
function useStore() {
|
|
1529
|
-
const store = React__namespace.useContext(context);
|
|
1530
|
-
if (!store) throw `R3F hooks can only be used within the Canvas component!`;
|
|
1531
|
-
return store;
|
|
1532
|
-
}
|
|
1533
|
-
function useThree(selector = state => state, equalityFn) {
|
|
1534
|
-
return useStore()(selector, equalityFn);
|
|
1535
|
-
}
|
|
1536
|
-
function useFrame(callback, renderPriority = 0) {
|
|
1537
|
-
const subscribe = useStore().getState().internal.subscribe; // Update ref
|
|
1538
|
-
|
|
1539
|
-
const ref = React__namespace.useRef(callback);
|
|
1540
|
-
React__namespace.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
|
|
1541
|
-
|
|
1542
|
-
React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority), [renderPriority, subscribe]);
|
|
1543
|
-
return null;
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
function buildGraph(object) {
|
|
1547
|
-
const data = {
|
|
1548
|
-
nodes: {},
|
|
1549
|
-
materials: {}
|
|
1550
|
-
};
|
|
1551
|
-
|
|
1552
|
-
if (object) {
|
|
1553
|
-
object.traverse(obj => {
|
|
1554
|
-
if (obj.name) {
|
|
1555
|
-
data.nodes[obj.name] = obj;
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1558
|
-
if (obj.material && !data.materials[obj.material.name]) {
|
|
1559
|
-
data.materials[obj.material.name] = obj.material;
|
|
1560
|
-
}
|
|
1561
|
-
});
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
return data;
|
|
1565
|
-
}
|
|
1566
|
-
|
|
1567
|
-
function useGraph(object) {
|
|
1568
|
-
return React__namespace.useMemo(() => buildGraph(object), [object]);
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
function loadingFn(extensions, onProgress) {
|
|
1572
|
-
return function (Proto, ...input) {
|
|
1573
|
-
// Construct new loader and run extensions
|
|
1574
|
-
const loader = new Proto();
|
|
1575
|
-
if (extensions) extensions(loader); // Go through the urls and load them
|
|
1576
|
-
|
|
1577
|
-
return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
|
|
1578
|
-
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
1579
|
-
res(data);
|
|
1580
|
-
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1581
|
-
};
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
function useLoader(Proto, input, extensions, onProgress) {
|
|
1585
|
-
// Use suspense to load async assets
|
|
1586
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1587
|
-
const results = useAsset.useAsset(loadingFn(extensions, onProgress), Proto, ...keys); // Return the object/s
|
|
1588
|
-
|
|
1589
|
-
return Array.isArray(input) ? results : results[0];
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
useLoader.preload = function (Proto, input, extensions) {
|
|
1593
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1594
|
-
return useAsset.useAsset.preload(loadingFn(extensions), Proto, ...keys);
|
|
1595
|
-
};
|
|
1596
|
-
|
|
1597
|
-
useLoader.clear = function (Proto, input) {
|
|
1598
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1599
|
-
return useAsset.useAsset.clear(Proto, ...keys);
|
|
1600
|
-
};
|
|
1601
|
-
|
|
1602
151
|
const roots = new Map();
|
|
1603
152
|
const {
|
|
1604
153
|
invalidate,
|
|
1605
154
|
advance
|
|
1606
|
-
} = createLoop(roots);
|
|
155
|
+
} = hooks.createLoop(roots);
|
|
1607
156
|
const {
|
|
1608
157
|
reconciler,
|
|
1609
158
|
applyProps
|
|
1610
|
-
} = createRenderer(roots, getEventPriority);
|
|
1611
|
-
|
|
1612
|
-
const createRendererInstance = (gl, canvas) =>
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
159
|
+
} = hooks.createRenderer(roots, getEventPriority);
|
|
160
|
+
|
|
161
|
+
const createRendererInstance = (gl, canvas) => {
|
|
162
|
+
const customRenderer = typeof gl === 'function' ? gl(canvas) : gl;
|
|
163
|
+
if (hooks.isRenderer(customRenderer)) return customRenderer;
|
|
164
|
+
const renderer = new THREE__namespace.WebGLRenderer({
|
|
165
|
+
powerPreference: 'high-performance',
|
|
166
|
+
canvas: canvas,
|
|
167
|
+
antialias: true,
|
|
168
|
+
alpha: true,
|
|
169
|
+
...gl
|
|
170
|
+
}); // Set color management
|
|
171
|
+
|
|
172
|
+
renderer.outputEncoding = THREE__namespace.sRGBEncoding;
|
|
173
|
+
renderer.toneMapping = THREE__namespace.ACESFilmicToneMapping; // Set gl props
|
|
174
|
+
|
|
175
|
+
if (gl) applyProps(renderer, gl);
|
|
176
|
+
return renderer;
|
|
177
|
+
};
|
|
1619
178
|
|
|
1620
|
-
function
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
onCreated,
|
|
1625
|
-
...props
|
|
1626
|
-
} = {}) {
|
|
1627
|
-
var _store;
|
|
179
|
+
function createRoot(canvas, config) {
|
|
180
|
+
return {
|
|
181
|
+
render: element => {
|
|
182
|
+
var _store;
|
|
1628
183
|
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
184
|
+
let {
|
|
185
|
+
gl,
|
|
186
|
+
size,
|
|
187
|
+
events,
|
|
188
|
+
onCreated,
|
|
189
|
+
...props
|
|
190
|
+
} = config || {}; // Allow size to take on container bounds initially
|
|
1632
191
|
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
|
|
1636
|
-
};
|
|
1637
|
-
}
|
|
192
|
+
if (!size) {
|
|
193
|
+
var _canvas$parentElement, _canvas$parentElement2, _canvas$parentElement3, _canvas$parentElement4;
|
|
1638
194
|
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
195
|
+
size = {
|
|
196
|
+
width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
|
|
197
|
+
height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
|
|
198
|
+
};
|
|
199
|
+
}
|
|
1643
200
|
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
201
|
+
let root = roots.get(canvas);
|
|
202
|
+
let fiber = root == null ? void 0 : root.fiber;
|
|
203
|
+
let store = root == null ? void 0 : root.store;
|
|
204
|
+
let state = (_store = store) == null ? void 0 : _store.getState();
|
|
1647
205
|
|
|
1648
|
-
|
|
206
|
+
if (fiber && state) {
|
|
207
|
+
// When a root was found, see if any fundamental props must be changed or exchanged
|
|
208
|
+
// Check pixelratio
|
|
209
|
+
if (props.dpr !== undefined && state.viewport.dpr !== hooks.calculateDpr(props.dpr)) state.setDpr(props.dpr); // Check size
|
|
1649
210
|
|
|
1650
|
-
|
|
1651
|
-
// Changes to the color-space
|
|
211
|
+
if (state.size.width !== size.width || state.size.height !== size.height) state.setSize(size.width, size.height); // Check frameloop
|
|
1652
212
|
|
|
1653
|
-
|
|
213
|
+
if (state.frameloop !== props.frameloop) state.setFrameloop(props.frameloop); // For some props we want to reset the entire root
|
|
214
|
+
// Changes to the color-space
|
|
1654
215
|
|
|
1655
|
-
|
|
1656
|
-
unmountComponentAtNode(canvas);
|
|
1657
|
-
fiber = undefined;
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
216
|
+
const linearChanged = props.linear !== state.internal.lastProps.linear;
|
|
1660
217
|
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
218
|
+
if (linearChanged) {
|
|
219
|
+
unmountComponentAtNode(canvas);
|
|
220
|
+
fiber = undefined;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
1665
223
|
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
224
|
+
if (!fiber) {
|
|
225
|
+
// If no root has been found, make one
|
|
226
|
+
// Create gl
|
|
227
|
+
const glRenderer = createRendererInstance(gl, canvas); // Create store
|
|
1670
228
|
|
|
229
|
+
store = hooks.createStore(applyProps, invalidate, advance, {
|
|
230
|
+
gl: glRenderer,
|
|
231
|
+
size,
|
|
232
|
+
...props
|
|
233
|
+
});
|
|
234
|
+
const state = store.getState(); // Create renderer
|
|
1671
235
|
|
|
1672
|
-
|
|
1673
|
-
gl: glRenderer,
|
|
1674
|
-
size,
|
|
1675
|
-
...props
|
|
1676
|
-
});
|
|
1677
|
-
const state = store.getState(); // Create renderer
|
|
236
|
+
fiber = reconciler.createContainer(store, constants.ConcurrentRoot, false, null); // Map it
|
|
1678
237
|
|
|
1679
|
-
|
|
238
|
+
roots.set(canvas, {
|
|
239
|
+
fiber,
|
|
240
|
+
store
|
|
241
|
+
}); // Store events internally
|
|
1680
242
|
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
243
|
+
if (events) state.set({
|
|
244
|
+
events: events(store)
|
|
245
|
+
});
|
|
246
|
+
}
|
|
1685
247
|
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
248
|
+
if (store && fiber) {
|
|
249
|
+
reconciler.updateContainer( /*#__PURE__*/React__namespace.createElement(Provider, {
|
|
250
|
+
store: store,
|
|
251
|
+
element: element,
|
|
252
|
+
onCreated: onCreated,
|
|
253
|
+
target: canvas
|
|
254
|
+
}), fiber, null, () => undefined);
|
|
255
|
+
return store;
|
|
256
|
+
} else {
|
|
257
|
+
throw 'Error creating root!';
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
unmount: () => unmountComponentAtNode(canvas)
|
|
261
|
+
};
|
|
262
|
+
}
|
|
1690
263
|
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
element: element,
|
|
1695
|
-
onCreated: onCreated,
|
|
1696
|
-
target: canvas
|
|
1697
|
-
}), fiber, null, () => undefined);
|
|
1698
|
-
return store;
|
|
1699
|
-
} else {
|
|
1700
|
-
throw 'Error creating root!';
|
|
1701
|
-
}
|
|
264
|
+
function render(element, canvas, config = {}) {
|
|
265
|
+
console.warn('R3F.render is no longer supported in React 18. Use createRoot instead!');
|
|
266
|
+
return createRoot(canvas, config).render(element);
|
|
1702
267
|
}
|
|
1703
268
|
|
|
1704
269
|
function Provider({
|
|
@@ -1718,9 +283,9 @@ function Provider({
|
|
|
1718
283
|
|
|
1719
284
|
state.events.connect == null ? void 0 : state.events.connect(target); // Notifiy that init is completed, the scene graph exists, but nothing has yet rendered
|
|
1720
285
|
|
|
1721
|
-
if (onCreated) onCreated(state);
|
|
286
|
+
if (onCreated) onCreated(state); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1722
287
|
}, []);
|
|
1723
|
-
return /*#__PURE__*/React__namespace.createElement(context.Provider, {
|
|
288
|
+
return /*#__PURE__*/React__namespace.createElement(hooks.context.Provider, {
|
|
1724
289
|
value: store
|
|
1725
290
|
}, element);
|
|
1726
291
|
}
|
|
@@ -1735,31 +300,26 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
1735
300
|
reconciler.updateContainer(null, fiber, null, () => {
|
|
1736
301
|
if (state) {
|
|
1737
302
|
setTimeout(() => {
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
303
|
+
try {
|
|
304
|
+
var _state$gl, _state$gl$renderLists, _state$gl2, _state$gl3;
|
|
305
|
+
|
|
306
|
+
state.events.disconnect == null ? void 0 : state.events.disconnect();
|
|
307
|
+
(_state$gl = state.gl) == null ? void 0 : (_state$gl$renderLists = _state$gl.renderLists) == null ? void 0 : _state$gl$renderLists.dispose == null ? void 0 : _state$gl$renderLists.dispose();
|
|
308
|
+
(_state$gl2 = state.gl) == null ? void 0 : _state$gl2.forceContextLoss == null ? void 0 : _state$gl2.forceContextLoss();
|
|
309
|
+
if ((_state$gl3 = state.gl) != null && _state$gl3.xr) state.internal.xr.disconnect();
|
|
310
|
+
hooks.dispose(state);
|
|
311
|
+
roots.delete(canvas);
|
|
312
|
+
if (callback) callback(canvas);
|
|
313
|
+
} catch (e) {
|
|
314
|
+
/* ... */
|
|
315
|
+
}
|
|
1746
316
|
}, 500);
|
|
1747
317
|
}
|
|
1748
318
|
});
|
|
1749
319
|
}
|
|
1750
320
|
}
|
|
1751
321
|
|
|
1752
|
-
|
|
1753
|
-
if (obj.dispose && obj.type !== 'Scene') obj.dispose();
|
|
1754
|
-
|
|
1755
|
-
for (const p in obj) {
|
|
1756
|
-
var _dispose, _ref;
|
|
1757
|
-
(_dispose = (_ref = p).dispose) == null ? void 0 : _dispose.call(_ref);
|
|
1758
|
-
delete obj[p];
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
const act = reconciler.act;
|
|
322
|
+
const act = React__namespace.unstable_act;
|
|
1763
323
|
|
|
1764
324
|
function createPortal(children, container) {
|
|
1765
325
|
return reconciler.createPortal(children, container, null, null);
|
|
@@ -1768,29 +328,134 @@ function createPortal(children, container) {
|
|
|
1768
328
|
reconciler.injectIntoDevTools({
|
|
1769
329
|
bundleType: process.env.NODE_ENV === 'production' ? 0 : 1,
|
|
1770
330
|
rendererPackageName: '@react-three/fiber',
|
|
1771
|
-
version: '
|
|
331
|
+
version: '18.0.0'
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'clock', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
335
|
+
|
|
336
|
+
function Block({
|
|
337
|
+
set
|
|
338
|
+
}) {
|
|
339
|
+
React__namespace.useLayoutEffect(() => {
|
|
340
|
+
set(new Promise(() => null));
|
|
341
|
+
return () => set(false);
|
|
342
|
+
}, [set]);
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
class ErrorBoundary extends React__namespace.Component {
|
|
347
|
+
constructor(...args) {
|
|
348
|
+
super(...args);
|
|
349
|
+
this.state = {
|
|
350
|
+
error: false
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
componentDidCatch(error) {
|
|
355
|
+
this.props.set(error);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
render() {
|
|
359
|
+
return this.state.error ? null : this.props.children;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
365
|
+
error: true
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
369
|
+
children,
|
|
370
|
+
fallback,
|
|
371
|
+
resize,
|
|
372
|
+
style,
|
|
373
|
+
events,
|
|
374
|
+
...props
|
|
375
|
+
}, forwardedRef) {
|
|
376
|
+
// Create a known catalogue of Threejs-native elements
|
|
377
|
+
// This will include the entire THREE namespace by default, users can extend
|
|
378
|
+
// their own elements by using the createRoot API instead
|
|
379
|
+
React__namespace.useMemo(() => hooks.extend(THREE__namespace), []);
|
|
380
|
+
const [containerRef, {
|
|
381
|
+
width,
|
|
382
|
+
height
|
|
383
|
+
}] = useMeasure__default['default']({
|
|
384
|
+
scroll: true,
|
|
385
|
+
debounce: {
|
|
386
|
+
scroll: 50,
|
|
387
|
+
resize: 0
|
|
388
|
+
},
|
|
389
|
+
...resize
|
|
390
|
+
});
|
|
391
|
+
const canvasRef = React__namespace.useRef(null);
|
|
392
|
+
const canvasProps = hooks.pick(props, CANVAS_PROPS);
|
|
393
|
+
const divProps = hooks.omit(props, CANVAS_PROPS);
|
|
394
|
+
const [block, setBlock] = React__namespace.useState(false);
|
|
395
|
+
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
396
|
+
|
|
397
|
+
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
398
|
+
|
|
399
|
+
if (error) throw error;
|
|
400
|
+
|
|
401
|
+
if (width > 0 && height > 0) {
|
|
402
|
+
createRoot(canvasRef.current, { ...canvasProps,
|
|
403
|
+
size: {
|
|
404
|
+
width,
|
|
405
|
+
height
|
|
406
|
+
},
|
|
407
|
+
events: events || createPointerEvents
|
|
408
|
+
}).render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
409
|
+
set: setError
|
|
410
|
+
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
411
|
+
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
412
|
+
set: setBlock
|
|
413
|
+
})
|
|
414
|
+
}, children)));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
React__namespace.useEffect(() => {
|
|
418
|
+
const container = canvasRef.current;
|
|
419
|
+
return () => unmountComponentAtNode(container);
|
|
420
|
+
}, []);
|
|
421
|
+
return /*#__PURE__*/React__namespace.createElement("div", _extends({
|
|
422
|
+
ref: containerRef,
|
|
423
|
+
style: {
|
|
424
|
+
position: 'relative',
|
|
425
|
+
width: '100%',
|
|
426
|
+
height: '100%',
|
|
427
|
+
overflow: 'hidden',
|
|
428
|
+
...style
|
|
429
|
+
}
|
|
430
|
+
}, divProps), /*#__PURE__*/React__namespace.createElement("canvas", {
|
|
431
|
+
ref: mergeRefs__default['default']([canvasRef, forwardedRef]),
|
|
432
|
+
style: {
|
|
433
|
+
display: 'block'
|
|
434
|
+
}
|
|
435
|
+
}, fallback));
|
|
1772
436
|
});
|
|
1773
437
|
|
|
438
|
+
exports.ReactThreeFiber = hooks.threeTypes;
|
|
439
|
+
exports.addAfterEffect = hooks.addAfterEffect;
|
|
440
|
+
exports.addEffect = hooks.addEffect;
|
|
441
|
+
exports.addTail = hooks.addTail;
|
|
442
|
+
exports.context = hooks.context;
|
|
443
|
+
exports.dispose = hooks.dispose;
|
|
444
|
+
exports.extend = hooks.extend;
|
|
445
|
+
exports.useFrame = hooks.useFrame;
|
|
446
|
+
exports.useGraph = hooks.useGraph;
|
|
447
|
+
exports.useLoader = hooks.useLoader;
|
|
448
|
+
exports.useStore = hooks.useStore;
|
|
449
|
+
exports.useThree = hooks.useThree;
|
|
1774
450
|
exports.Canvas = Canvas;
|
|
1775
|
-
exports.ReactThreeFiber = threeTypes;
|
|
1776
451
|
exports._roots = roots;
|
|
1777
452
|
exports.act = act;
|
|
1778
|
-
exports.addAfterEffect = addAfterEffect;
|
|
1779
|
-
exports.addEffect = addEffect;
|
|
1780
|
-
exports.addTail = addTail;
|
|
1781
453
|
exports.advance = advance;
|
|
1782
454
|
exports.applyProps = applyProps;
|
|
1783
|
-
exports.context = context;
|
|
1784
455
|
exports.createPortal = createPortal;
|
|
1785
|
-
exports.
|
|
456
|
+
exports.createRoot = createRoot;
|
|
1786
457
|
exports.events = createPointerEvents;
|
|
1787
|
-
exports.extend = extend;
|
|
1788
458
|
exports.invalidate = invalidate;
|
|
1789
459
|
exports.reconciler = reconciler;
|
|
1790
460
|
exports.render = render;
|
|
1791
461
|
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
1792
|
-
exports.useFrame = useFrame;
|
|
1793
|
-
exports.useGraph = useGraph;
|
|
1794
|
-
exports.useLoader = useLoader;
|
|
1795
|
-
exports.useStore = useStore;
|
|
1796
|
-
exports.useThree = useThree;
|