@react-three/fiber 7.0.22 → 7.0.26
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 +24 -0
- package/dist/declarations/src/core/store.d.ts +2 -0
- package/dist/declarations/src/three-types.d.ts +7 -16
- package/dist/react-three-fiber.cjs.dev.js +40 -25
- package/dist/react-three-fiber.cjs.prod.js +40 -25
- package/dist/react-three-fiber.esm.js +40 -25
- package/native/dist/react-three-fiber-native.cjs.dev.js +160 -392
- package/native/dist/react-three-fiber-native.cjs.prod.js +160 -392
- package/native/dist/react-three-fiber-native.esm.js +135 -367
- package/package.json +2 -2
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { c as createEvents, q as buildGraph, r as is, a as createLoop, b as createRenderer, e as createStore, f as context, g as dispose, i as isRenderer } from '../../dist/hooks-8fbc4995.esm.js';
|
|
2
|
-
export { t as ReactThreeFiber, k as addAfterEffect, j as addEffect, l as addTail, f as context, g as dispose, h as extend, n as useFrame, o as useGraph, u as useStore, m as useThree } from '../../dist/hooks-8fbc4995.esm.js';
|
|
3
1
|
import * as THREE from 'three';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import { DefaultEventPriority, ContinuousEventPriority, DiscreteEventPriority, ConcurrentRoot } from 'react-reconciler/constants';
|
|
6
|
-
import Pressability from 'react-native/Libraries/Pressability/Pressability';
|
|
7
|
-
import { View, StyleSheet, PixelRatio } from 'react-native';
|
|
8
2
|
import { Asset } from 'expo-asset';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { suspend, preload, clear } from 'suspend-react';
|
|
3
|
+
import { c as createEvents, e as extend, p as pick, o as omit, a as createRoot, u as unmountComponentAtNode } from '../../dist/index-3f4e5f46.esm.js';
|
|
4
|
+
export { t as ReactThreeFiber, q as _roots, n as act, l as addAfterEffect, k as addEffect, m as addTail, j as advance, g as applyProps, b as context, d as createPortal, a as createRoot, h as dispose, e as extend, i as invalidate, f as reconciler, r as render, u as unmountComponentAtNode, w as useFrame, x as useGraph, y as useLoader, s as useStore, v as useThree } from '../../dist/index-3f4e5f46.esm.js';
|
|
12
5
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import { PixelRatio, View, StyleSheet } from 'react-native';
|
|
13
8
|
import { GLView } from 'expo-gl';
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import 'react-reconciler';
|
|
9
|
+
import Pressability from 'react-native/Libraries/Pressability/Pressability';
|
|
10
|
+
import 'suspend-react';
|
|
11
|
+
import 'react-reconciler/constants';
|
|
17
12
|
import 'zustand';
|
|
13
|
+
import 'react-reconciler';
|
|
14
|
+
import 'scheduler';
|
|
18
15
|
|
|
19
|
-
// @ts-ignore
|
|
20
16
|
const EVENTS = {
|
|
21
17
|
PRESS: 'onPress',
|
|
22
18
|
PRESSIN: 'onPressIn',
|
|
@@ -34,30 +30,7 @@ const DOM_EVENTS = {
|
|
|
34
30
|
[EVENTS.HOVERIN]: 'onPointerOver',
|
|
35
31
|
[EVENTS.HOVEROUT]: 'onPointerOut',
|
|
36
32
|
[EVENTS.PRESSMOVE]: 'onPointerMove'
|
|
37
|
-
};
|
|
38
|
-
// Gives React a clue as to how import the current interaction is
|
|
39
|
-
|
|
40
|
-
function getEventPriority() {
|
|
41
|
-
var _window, _window$event;
|
|
42
|
-
|
|
43
|
-
let name = (_window = window) == null ? void 0 : (_window$event = _window.event) == null ? void 0 : _window$event.type;
|
|
44
|
-
|
|
45
|
-
switch (name) {
|
|
46
|
-
case EVENTS.PRESS:
|
|
47
|
-
case EVENTS.PRESSIN:
|
|
48
|
-
case EVENTS.PRESSOUT:
|
|
49
|
-
case EVENTS.LONGPRESS:
|
|
50
|
-
return DiscreteEventPriority;
|
|
51
|
-
|
|
52
|
-
case EVENTS.HOVERIN:
|
|
53
|
-
case EVENTS.HOVEROUT:
|
|
54
|
-
case EVENTS.PRESSMOVE:
|
|
55
|
-
return ContinuousEventPriority;
|
|
56
|
-
|
|
57
|
-
default:
|
|
58
|
-
return DefaultEventPriority;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
33
|
+
};
|
|
61
34
|
function createTouchEvents(store) {
|
|
62
35
|
const {
|
|
63
36
|
handlePointer
|
|
@@ -66,8 +39,8 @@ function createTouchEvents(store) {
|
|
|
66
39
|
const handleTouch = (event, name) => {
|
|
67
40
|
event.persist() // Apply offset
|
|
68
41
|
;
|
|
69
|
-
event.nativeEvent.offsetX = event.nativeEvent.
|
|
70
|
-
event.nativeEvent.offsetY = event.nativeEvent.
|
|
42
|
+
event.nativeEvent.offsetX = event.nativeEvent.locationX;
|
|
43
|
+
event.nativeEvent.offsetY = event.nativeEvent.locationY; // Emulate DOM event
|
|
71
44
|
|
|
72
45
|
const callback = handlePointer(DOM_EVENTS[name]);
|
|
73
46
|
return callback(event.nativeEvent);
|
|
@@ -84,12 +57,14 @@ function createTouchEvents(store) {
|
|
|
84
57
|
events
|
|
85
58
|
} = store.getState();
|
|
86
59
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
87
|
-
const
|
|
60
|
+
const connected = new Pressability(events == null ? void 0 : events.handlers);
|
|
88
61
|
set(state => ({
|
|
89
62
|
events: { ...state.events,
|
|
90
|
-
connected
|
|
63
|
+
connected
|
|
91
64
|
}
|
|
92
65
|
}));
|
|
66
|
+
const handlers = connected.getEventHandlers();
|
|
67
|
+
return handlers;
|
|
93
68
|
},
|
|
94
69
|
disconnect: () => {
|
|
95
70
|
const {
|
|
@@ -109,20 +84,15 @@ function createTouchEvents(store) {
|
|
|
109
84
|
};
|
|
110
85
|
}
|
|
111
86
|
|
|
112
|
-
const CANVAS_PROPS = ['gl', 'events', '
|
|
113
|
-
'performance', 'clock', 'raycaster', 'camera', 'onPointerMissed', 'onCreated']; // React currently throws a warning when using useLayoutEffect on the server.
|
|
114
|
-
// To get around it, we can conditionally useEffect on the server (no-op) and
|
|
115
|
-
// useLayoutEffect in the browser.
|
|
116
|
-
|
|
117
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
87
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'performance', 'clock', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
118
88
|
|
|
119
89
|
function Block({
|
|
120
90
|
set
|
|
121
91
|
}) {
|
|
122
|
-
|
|
92
|
+
React.useLayoutEffect(() => {
|
|
123
93
|
set(new Promise(() => null));
|
|
124
94
|
return () => set(false);
|
|
125
|
-
}, []);
|
|
95
|
+
}, [set]);
|
|
126
96
|
return null;
|
|
127
97
|
}
|
|
128
98
|
|
|
@@ -153,13 +123,12 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
|
|
|
153
123
|
fallback,
|
|
154
124
|
style,
|
|
155
125
|
events,
|
|
156
|
-
nativeRef_EXPERIMENTAL,
|
|
157
|
-
onContextCreate,
|
|
158
126
|
...props
|
|
159
127
|
}, forwardedRef) => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
128
|
+
// Create a known catalogue of Threejs-native elements
|
|
129
|
+
// This will include the entire THREE namespace by default, users can extend
|
|
130
|
+
// their own elements by using the createRoot API instead
|
|
131
|
+
React.useMemo(() => extend(THREE), []);
|
|
163
132
|
const [{
|
|
164
133
|
width,
|
|
165
134
|
height
|
|
@@ -167,7 +136,10 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
|
|
|
167
136
|
width: 0,
|
|
168
137
|
height: 0
|
|
169
138
|
});
|
|
139
|
+
const [canvas, setCanvas] = React.useState(null);
|
|
170
140
|
const [bind, setBind] = React.useState();
|
|
141
|
+
const canvasProps = pick(props, CANVAS_PROPS);
|
|
142
|
+
const viewProps = omit(props, CANVAS_PROPS);
|
|
171
143
|
const [block, setBlock] = React.useState(false);
|
|
172
144
|
const [error, setError] = React.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
173
145
|
|
|
@@ -183,32 +155,60 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
|
|
|
183
155
|
width,
|
|
184
156
|
height
|
|
185
157
|
});
|
|
186
|
-
}, []);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}, children)), context, { ...canvasProps,
|
|
197
|
-
size: {
|
|
198
|
-
width,
|
|
199
|
-
height
|
|
200
|
-
},
|
|
201
|
-
events: events || createTouchEvents
|
|
202
|
-
});
|
|
203
|
-
const state = store.getState();
|
|
204
|
-
setBind(state.events.connected.getEventHandlers());
|
|
205
|
-
}
|
|
206
|
-
}, [width, height, children, context, canvasProps]);
|
|
207
|
-
useIsomorphicLayoutEffect(() => {
|
|
208
|
-
return () => {
|
|
209
|
-
if (context) unmountComponentAtNode(context);
|
|
158
|
+
}, []);
|
|
159
|
+
const onContextCreate = React.useCallback(context => {
|
|
160
|
+
const canvasShim = {
|
|
161
|
+
width: context.drawingBufferWidth,
|
|
162
|
+
height: context.drawingBufferHeight,
|
|
163
|
+
style: {},
|
|
164
|
+
addEventListener: () => {},
|
|
165
|
+
removeEventListener: () => {},
|
|
166
|
+
clientHeight: context.drawingBufferHeight,
|
|
167
|
+
getContext: () => context
|
|
210
168
|
};
|
|
169
|
+
setCanvas(canvasShim);
|
|
211
170
|
}, []);
|
|
171
|
+
|
|
172
|
+
if (width > 0 && height > 0 && canvas) {
|
|
173
|
+
// Overwrite onCreated to apply RN bindings
|
|
174
|
+
const onCreated = state => {
|
|
175
|
+
// Bind events after creation
|
|
176
|
+
const handlers = state.events.connect == null ? void 0 : state.events.connect(canvas);
|
|
177
|
+
setBind(handlers); // Bind render to RN bridge
|
|
178
|
+
|
|
179
|
+
const context = state.gl.getContext();
|
|
180
|
+
const renderFrame = state.gl.render.bind(state.gl);
|
|
181
|
+
|
|
182
|
+
state.gl.render = (scene, camera) => {
|
|
183
|
+
renderFrame(scene, camera);
|
|
184
|
+
context.endFrameEXP();
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
return canvasProps == null ? void 0 : canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
createRoot(canvas, { ...canvasProps,
|
|
191
|
+
// expo-gl can only render at native dpr/resolution
|
|
192
|
+
// https://github.com/expo/expo-three/issues/39
|
|
193
|
+
dpr: PixelRatio.get(),
|
|
194
|
+
size: {
|
|
195
|
+
width,
|
|
196
|
+
height
|
|
197
|
+
},
|
|
198
|
+
events: events || createTouchEvents,
|
|
199
|
+
onCreated
|
|
200
|
+
}).render( /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
201
|
+
set: setError
|
|
202
|
+
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
203
|
+
fallback: /*#__PURE__*/React.createElement(Block, {
|
|
204
|
+
set: setBlock
|
|
205
|
+
})
|
|
206
|
+
}, children)));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
React.useEffect(() => {
|
|
210
|
+
return () => unmountComponentAtNode(canvas);
|
|
211
|
+
}, [canvas]);
|
|
212
212
|
return /*#__PURE__*/React.createElement(View, _extends({}, viewProps, {
|
|
213
213
|
ref: forwardedRef,
|
|
214
214
|
onLayout: onLayout,
|
|
@@ -217,15 +217,7 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
|
|
|
217
217
|
...style
|
|
218
218
|
}
|
|
219
219
|
}, bind), width > 0 && /*#__PURE__*/React.createElement(GLView, {
|
|
220
|
-
|
|
221
|
-
if (nativeRef_EXPERIMENTAL && !nativeRef_EXPERIMENTAL.current) {
|
|
222
|
-
nativeRef_EXPERIMENTAL.current = ref;
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
onContextCreate: async gl => {
|
|
226
|
-
await (onContextCreate == null ? void 0 : onContextCreate(gl));
|
|
227
|
-
setContext(gl);
|
|
228
|
-
},
|
|
220
|
+
onContextCreate: onContextCreate,
|
|
229
221
|
style: StyleSheet.absoluteFill
|
|
230
222
|
}));
|
|
231
223
|
});
|
|
@@ -247,292 +239,68 @@ const getAsset = input => {
|
|
|
247
239
|
default:
|
|
248
240
|
throw 'Invalid asset! Must be a URI or module.';
|
|
249
241
|
}
|
|
250
|
-
};
|
|
251
|
-
/**
|
|
252
|
-
* Downloads from a local URI and decodes into an ArrayBuffer.
|
|
253
|
-
*/
|
|
242
|
+
}; // Don't pre-process urls, let expo-asset generate an absolute URL
|
|
254
243
|
|
|
255
244
|
|
|
256
|
-
|
|
257
|
-
encoding: 'base64'
|
|
258
|
-
}).then(decode);
|
|
259
|
-
|
|
260
|
-
function loadingFn(extensions, onProgress) {
|
|
261
|
-
return function (Proto, ...input) {
|
|
262
|
-
// Construct new loader and run extensions
|
|
263
|
-
const loader = new Proto();
|
|
264
|
-
if (extensions) extensions(loader); // Go through the urls and load them
|
|
265
|
-
|
|
266
|
-
return Promise.all(input.map(entry => new Promise(async (res, reject) => {
|
|
267
|
-
var _parse, _ref;
|
|
268
|
-
|
|
269
|
-
// Construct URL
|
|
270
|
-
const url = typeof entry === 'string' ? loader.path + entry : entry; // There's no Image in native, so we create & pass a data texture instead
|
|
271
|
-
|
|
272
|
-
if (loader instanceof THREE.TextureLoader) {
|
|
273
|
-
const asset = await getAsset(url).downloadAsync();
|
|
274
|
-
const texture = new THREE.Texture();
|
|
275
|
-
texture.isDataTexture = true;
|
|
276
|
-
texture.image = {
|
|
277
|
-
data: asset,
|
|
278
|
-
width: asset.width,
|
|
279
|
-
height: asset.height
|
|
280
|
-
};
|
|
281
|
-
texture.needsUpdate = true;
|
|
282
|
-
return res(texture);
|
|
283
|
-
} // Do similar for CubeTextures
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if (loader instanceof THREE.CubeTextureLoader) {
|
|
287
|
-
const texture = new THREE.CubeTexture();
|
|
288
|
-
texture.isDataTexture = true;
|
|
289
|
-
texture.images = await Promise.all(url.map(async src => {
|
|
290
|
-
const asset = await getAsset(src).downloadAsync();
|
|
291
|
-
return {
|
|
292
|
-
data: asset,
|
|
293
|
-
width: asset.width,
|
|
294
|
-
height: asset.height
|
|
295
|
-
};
|
|
296
|
-
}));
|
|
297
|
-
texture.needsUpdate = true;
|
|
298
|
-
return res(texture);
|
|
299
|
-
} // If asset is external and not an Image, load it
|
|
245
|
+
THREE.LoaderUtils.extractUrlBase = () => './'; // There's no Image in native, so create a data texture instead
|
|
300
246
|
|
|
301
247
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
305
|
-
res(data);
|
|
306
|
-
}, onProgress, error => reject(`Could not load ${url}: ${error.message}`));
|
|
307
|
-
} // Otherwise, create a localUri and a file buffer
|
|
248
|
+
THREE.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
249
|
+
const texture = new THREE.Texture(); // @ts-expect-error
|
|
308
250
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const parsed = (_parse = (_ref = loader).parse) == null ? void 0 : _parse.call(_ref, arrayBuffer, undefined, data => {
|
|
316
|
-
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
317
|
-
res(data);
|
|
318
|
-
}, error => reject(`Could not load ${url}: ${error.message}`)); // Respect synchronous parsers which don't have callbacks
|
|
319
|
-
|
|
320
|
-
if (parsed) return res(parsed);
|
|
321
|
-
})));
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
function useLoader(Proto, input, extensions, onProgress) {
|
|
326
|
-
// Use suspense to load async assets
|
|
327
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
328
|
-
const results = suspend(loadingFn(extensions, onProgress), [Proto, ...keys], {
|
|
329
|
-
equal: is.equ
|
|
330
|
-
}); // Return the object/s
|
|
331
|
-
|
|
332
|
-
return Array.isArray(input) ? results : results[0];
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
useLoader.preload = function (Proto, input, extensions) {
|
|
336
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
337
|
-
return preload(loadingFn(extensions), [Proto, ...keys]);
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
useLoader.clear = function (Proto, input) {
|
|
341
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
342
|
-
return clear([Proto, ...keys]);
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
const roots = new Map();
|
|
346
|
-
const {
|
|
347
|
-
invalidate,
|
|
348
|
-
advance
|
|
349
|
-
} = createLoop(roots);
|
|
350
|
-
const {
|
|
351
|
-
reconciler,
|
|
352
|
-
applyProps
|
|
353
|
-
} = createRenderer(roots, getEventPriority);
|
|
354
|
-
|
|
355
|
-
const createRendererInstance = (gl, context) => {
|
|
356
|
-
// Create canvas shim
|
|
357
|
-
const canvas = {
|
|
358
|
-
width: context.drawingBufferWidth,
|
|
359
|
-
height: context.drawingBufferHeight,
|
|
360
|
-
style: {},
|
|
361
|
-
addEventListener: () => {},
|
|
362
|
-
removeEventListener: () => {},
|
|
363
|
-
clientHeight: context.drawingBufferHeight
|
|
364
|
-
}; // If a renderer is specified, return it
|
|
365
|
-
|
|
366
|
-
const customRenderer = typeof gl === 'function' ? gl(canvas, context) : gl;
|
|
367
|
-
if (isRenderer(customRenderer)) return customRenderer; // Create renderer and pass our canvas and its context
|
|
368
|
-
|
|
369
|
-
const renderer = new THREE.WebGLRenderer({
|
|
370
|
-
powerPreference: 'high-performance',
|
|
371
|
-
antialias: true,
|
|
372
|
-
alpha: true,
|
|
373
|
-
...gl,
|
|
374
|
-
canvas,
|
|
375
|
-
context
|
|
376
|
-
}); // Set color management
|
|
377
|
-
|
|
378
|
-
renderer.outputEncoding = THREE.sRGBEncoding;
|
|
379
|
-
renderer.toneMapping = THREE.ACESFilmicToneMapping; // Set GL props
|
|
380
|
-
|
|
381
|
-
if (gl) applyProps(renderer, gl); // Bind render to RN bridge
|
|
382
|
-
|
|
383
|
-
if (context.endFrameEXP) {
|
|
384
|
-
const renderFrame = renderer.render.bind(renderer);
|
|
385
|
-
|
|
386
|
-
renderer.render = (scene, camera) => {
|
|
387
|
-
renderFrame(scene, camera);
|
|
388
|
-
context.endFrameEXP();
|
|
251
|
+
texture.isDataTexture = true;
|
|
252
|
+
getAsset(url).downloadAsync().then(asset => {
|
|
253
|
+
texture.image = {
|
|
254
|
+
data: asset,
|
|
255
|
+
width: asset.width,
|
|
256
|
+
height: asset.height
|
|
389
257
|
};
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
...props
|
|
411
|
-
} = {}) {
|
|
412
|
-
var _store;
|
|
413
|
-
|
|
414
|
-
let root = roots.get(context);
|
|
415
|
-
let fiber = root == null ? void 0 : root.fiber;
|
|
416
|
-
let store = root == null ? void 0 : root.store;
|
|
417
|
-
let state = (_store = store) == null ? void 0 : _store.getState();
|
|
418
|
-
|
|
419
|
-
if (fiber && state) {
|
|
420
|
-
// When a root was found, see if any fundamental props must be changed or exchanged
|
|
421
|
-
// Check size
|
|
422
|
-
if (state.size.width !== size.width || state.size.height !== size.height) state.setSize(size.width, size.height); // For some props we want to reset the entire root
|
|
423
|
-
// Changes to the color-space
|
|
424
|
-
|
|
425
|
-
const linearChanged = props.linear !== state.internal.lastProps.linear;
|
|
426
|
-
|
|
427
|
-
if (linearChanged) {
|
|
428
|
-
unmountComponentAtNode(context);
|
|
429
|
-
fiber = undefined;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
if (!fiber) {
|
|
434
|
-
// If no root has been found, make one
|
|
435
|
-
// Create gl
|
|
436
|
-
const glRenderer = createRendererInstance(gl, context); // Create store
|
|
437
|
-
|
|
438
|
-
store = createStore(applyProps, invalidate, advance, {
|
|
439
|
-
gl: glRenderer,
|
|
440
|
-
size,
|
|
441
|
-
...props,
|
|
442
|
-
// expo-gl can only render at native dpr/resolution
|
|
443
|
-
// https://github.com/expo/expo-three/issues/39
|
|
444
|
-
dpr: PixelRatio.get()
|
|
445
|
-
});
|
|
446
|
-
const state = store.getState(); // Create renderer
|
|
447
|
-
|
|
448
|
-
fiber = reconciler.createContainer(store, ConcurrentRoot, false, null); // Map it
|
|
449
|
-
|
|
450
|
-
roots.set(context, {
|
|
451
|
-
fiber,
|
|
452
|
-
store
|
|
453
|
-
}); // Store event manager internally and connect it
|
|
454
|
-
|
|
455
|
-
if (events) {
|
|
456
|
-
var _state$get$events$con, _state$get$events;
|
|
457
|
-
|
|
458
|
-
state.set({
|
|
459
|
-
events: events(store)
|
|
460
|
-
});
|
|
461
|
-
(_state$get$events$con = (_state$get$events = state.get().events).connect) == null ? void 0 : _state$get$events$con.call(_state$get$events, context);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if (store && fiber) {
|
|
466
|
-
reconciler.updateContainer( /*#__PURE__*/React.createElement(Provider, {
|
|
467
|
-
store: store,
|
|
468
|
-
element: element,
|
|
469
|
-
onCreated: onCreated
|
|
470
|
-
}), fiber, null, () => undefined);
|
|
471
|
-
return store;
|
|
472
|
-
} else {
|
|
473
|
-
throw 'Error creating root!';
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
function Provider({
|
|
478
|
-
store,
|
|
479
|
-
element,
|
|
480
|
-
onCreated
|
|
481
|
-
}) {
|
|
482
|
-
React.useEffect(() => {
|
|
483
|
-
const state = store.getState(); // Flag the canvas active, rendering will now begin
|
|
484
|
-
|
|
485
|
-
state.set(state => ({
|
|
486
|
-
internal: { ...state.internal,
|
|
487
|
-
active: true
|
|
488
|
-
}
|
|
489
|
-
})); // Notifiy that init is completed, the scene graph exists, but nothing has yet rendered
|
|
490
|
-
|
|
491
|
-
if (onCreated) onCreated(state); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
492
|
-
}, []);
|
|
493
|
-
return /*#__PURE__*/React.createElement(context.Provider, {
|
|
494
|
-
value: store
|
|
495
|
-
}, element);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
function unmountComponentAtNode(context, callback) {
|
|
499
|
-
const root = roots.get(context);
|
|
500
|
-
const fiber = root == null ? void 0 : root.fiber;
|
|
501
|
-
|
|
502
|
-
if (fiber) {
|
|
503
|
-
const state = root == null ? void 0 : root.store.getState();
|
|
504
|
-
if (state) state.internal.active = false;
|
|
505
|
-
reconciler.updateContainer(null, fiber, null, () => {
|
|
506
|
-
if (state) {
|
|
507
|
-
setTimeout(() => {
|
|
508
|
-
try {
|
|
509
|
-
var _state$gl, _state$gl$renderLists, _state$gl2;
|
|
510
|
-
|
|
511
|
-
state.events.disconnect == null ? void 0 : state.events.disconnect();
|
|
512
|
-
(_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();
|
|
513
|
-
(_state$gl2 = state.gl) == null ? void 0 : _state$gl2.forceContextLoss == null ? void 0 : _state$gl2.forceContextLoss();
|
|
514
|
-
dispose(state);
|
|
515
|
-
roots.delete(context);
|
|
516
|
-
if (callback) callback(context);
|
|
517
|
-
} catch (e) {
|
|
518
|
-
/* ... */
|
|
519
|
-
}
|
|
520
|
-
}, 500);
|
|
258
|
+
texture.needsUpdate = true;
|
|
259
|
+
onLoad == null ? void 0 : onLoad(texture);
|
|
260
|
+
}).catch(onError);
|
|
261
|
+
return texture;
|
|
262
|
+
}; // Fetches assets via XMLHttpRequest
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
THREE.FileLoader.prototype.load = function (url, onLoad, onProgress, onError) {
|
|
266
|
+
if (this.path) url = this.path + url;
|
|
267
|
+
const request = new XMLHttpRequest();
|
|
268
|
+
getAsset(url).downloadAsync().then(asset => {
|
|
269
|
+
request.open('GET', asset.uri, true);
|
|
270
|
+
request.addEventListener('load', event => {
|
|
271
|
+
if (request.status === 200) {
|
|
272
|
+
onLoad == null ? void 0 : onLoad(request.response);
|
|
273
|
+
this.manager.itemEnd(url);
|
|
274
|
+
} else {
|
|
275
|
+
onError == null ? void 0 : onError(event);
|
|
276
|
+
this.manager.itemError(url);
|
|
277
|
+
this.manager.itemEnd(url);
|
|
521
278
|
}
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
279
|
+
}, false);
|
|
280
|
+
request.addEventListener('progress', event => {
|
|
281
|
+
onProgress == null ? void 0 : onProgress(event);
|
|
282
|
+
}, false);
|
|
283
|
+
request.addEventListener('error', event => {
|
|
284
|
+
onError == null ? void 0 : onError(event);
|
|
285
|
+
this.manager.itemError(url);
|
|
286
|
+
this.manager.itemEnd(url);
|
|
287
|
+
}, false);
|
|
288
|
+
request.addEventListener('abort', event => {
|
|
289
|
+
onError == null ? void 0 : onError(event);
|
|
290
|
+
this.manager.itemError(url);
|
|
291
|
+
this.manager.itemEnd(url);
|
|
292
|
+
}, false);
|
|
293
|
+
if (this.responseType) request.responseType = this.responseType;
|
|
294
|
+
if (this.withCredentials) request.withCredentials = this.withCredentials;
|
|
295
|
+
|
|
296
|
+
for (const header in this.requestHeader) {
|
|
297
|
+
request.setRequestHeader(header, this.requestHeader[header]);
|
|
298
|
+
}
|
|
531
299
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
}
|
|
300
|
+
request.send(null);
|
|
301
|
+
this.manager.itemStart(url);
|
|
302
|
+
});
|
|
303
|
+
return request;
|
|
304
|
+
};
|
|
537
305
|
|
|
538
|
-
export { Canvas,
|
|
306
|
+
export { Canvas, createTouchEvents as events };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-three/fiber",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.26",
|
|
4
4
|
"description": "A React renderer for Threejs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"react": ">=17.0",
|
|
57
57
|
"react-dom": ">=17.0",
|
|
58
|
-
"three": ">=0.
|
|
58
|
+
"three": ">=0.133"
|
|
59
59
|
},
|
|
60
60
|
"peerDependenciesMeta": {
|
|
61
61
|
"react-dom": {
|