@react-three/fiber 7.0.23 → 7.0.24
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 +6 -0
- package/dist/react-three-fiber.cjs.dev.js +21 -7
- package/dist/react-three-fiber.cjs.prod.js +21 -7
- package/dist/react-three-fiber.esm.js +21 -7
- package/native/dist/react-three-fiber-native.cjs.dev.js +209 -411
- package/native/dist/react-three-fiber-native.cjs.prod.js +209 -411
- package/native/dist/react-three-fiber-native.esm.js +185 -387
- package/package.json +1 -1
|
@@ -1,22 +1,130 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { t as ReactThreeFiber,
|
|
1
|
+
import { z as buildGraph, A as is, c as createEvents, e as extend, p as pick, o as omit, a as createRoot, u as unmountComponentAtNode } from '../../dist/index-fccd77b0.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, y as _roots, x as act, v as addAfterEffect, s as addEffect, w as addTail, q as advance, l as applyProps, i as context, j as createPortal, a as createRoot, m as dispose, e as extend, n as invalidate, k as reconciler, r as render, u as unmountComponentAtNode, f as useFrame, g as useGraph, b as useStore, d as useThree } from '../../dist/index-fccd77b0.esm.js';
|
|
3
3
|
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
4
|
import { Asset } from 'expo-asset';
|
|
9
5
|
import { readAsStringAsync } from 'expo-file-system';
|
|
10
6
|
import { decode } from 'base64-arraybuffer';
|
|
11
7
|
import { suspend, preload, clear } from 'suspend-react';
|
|
12
8
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
9
|
+
import * as React from 'react';
|
|
10
|
+
import { PixelRatio, View, StyleSheet } from 'react-native';
|
|
13
11
|
import { GLView } from 'expo-gl';
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import 'react-reconciler';
|
|
12
|
+
import Pressability from 'react-native/Libraries/Pressability/Pressability';
|
|
13
|
+
import 'react-reconciler/constants';
|
|
17
14
|
import 'zustand';
|
|
15
|
+
import 'react-reconciler';
|
|
16
|
+
import 'scheduler';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generates an asset based on input type.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const getAsset = input => {
|
|
23
|
+
if (input instanceof Asset) return input;
|
|
24
|
+
|
|
25
|
+
switch (typeof input) {
|
|
26
|
+
case 'string':
|
|
27
|
+
return Asset.fromURI(input);
|
|
28
|
+
|
|
29
|
+
case 'number':
|
|
30
|
+
return Asset.fromModule(input);
|
|
31
|
+
|
|
32
|
+
default:
|
|
33
|
+
throw 'Invalid asset! Must be a URI or module.';
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Downloads from a local URI and decodes into an ArrayBuffer.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
const toBuffer = async localUri => readAsStringAsync(localUri, {
|
|
42
|
+
encoding: 'base64'
|
|
43
|
+
}).then(decode);
|
|
44
|
+
|
|
45
|
+
function loadingFn(extensions, onProgress) {
|
|
46
|
+
return function (Proto, ...input) {
|
|
47
|
+
// Construct new loader and run extensions
|
|
48
|
+
const loader = new Proto();
|
|
49
|
+
if (extensions) extensions(loader); // Go through the urls and load them
|
|
50
|
+
|
|
51
|
+
return Promise.all(input.map(entry => new Promise(async (res, reject) => {
|
|
52
|
+
// Construct URL
|
|
53
|
+
const url = typeof entry === 'string' ? loader.path + entry : entry; // There's no Image in native, so we create & pass a data texture instead
|
|
54
|
+
|
|
55
|
+
if (loader instanceof THREE.TextureLoader) {
|
|
56
|
+
const asset = await getAsset(url).downloadAsync();
|
|
57
|
+
const texture = new THREE.Texture();
|
|
58
|
+
texture.isDataTexture = true;
|
|
59
|
+
texture.image = {
|
|
60
|
+
data: asset,
|
|
61
|
+
width: asset.width,
|
|
62
|
+
height: asset.height
|
|
63
|
+
};
|
|
64
|
+
texture.needsUpdate = true;
|
|
65
|
+
return res(texture);
|
|
66
|
+
} // Do similar for CubeTextures
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if (loader instanceof THREE.CubeTextureLoader) {
|
|
70
|
+
const texture = new THREE.CubeTexture();
|
|
71
|
+
texture.isDataTexture = true;
|
|
72
|
+
texture.images = await Promise.all(url.map(async src => {
|
|
73
|
+
const asset = await getAsset(src).downloadAsync();
|
|
74
|
+
return {
|
|
75
|
+
data: asset,
|
|
76
|
+
width: asset.width,
|
|
77
|
+
height: asset.height
|
|
78
|
+
};
|
|
79
|
+
}));
|
|
80
|
+
texture.needsUpdate = true;
|
|
81
|
+
return res(texture);
|
|
82
|
+
} // If asset is external and not an Image, load it
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if (url.startsWith != null && url.startsWith('http') && Proto.prototype.hasOwnProperty('load')) {
|
|
86
|
+
return loader.load(entry, data => {
|
|
87
|
+
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
88
|
+
res(data);
|
|
89
|
+
}, onProgress, error => reject(`Could not load ${url}: ${error.message}`));
|
|
90
|
+
} // Otherwise, create a localUri and a file buffer
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
const {
|
|
94
|
+
localUri
|
|
95
|
+
} = await getAsset(url).downloadAsync();
|
|
96
|
+
const arrayBuffer = await toBuffer(localUri); // Parse it
|
|
97
|
+
|
|
98
|
+
const parsed = loader.parse == null ? void 0 : loader.parse(arrayBuffer, undefined, data => {
|
|
99
|
+
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
100
|
+
res(data);
|
|
101
|
+
}, error => reject(`Could not load ${url}: ${error.message}`)); // Respect synchronous parsers which don't have callbacks
|
|
102
|
+
|
|
103
|
+
if (parsed) return res(parsed);
|
|
104
|
+
})));
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function useLoader(Proto, input, extensions, onProgress) {
|
|
109
|
+
// Use suspense to load async assets
|
|
110
|
+
const keys = Array.isArray(input) ? input : [input];
|
|
111
|
+
const results = suspend(loadingFn(extensions, onProgress), [Proto, ...keys], {
|
|
112
|
+
equal: is.equ
|
|
113
|
+
}); // Return the object/s
|
|
114
|
+
|
|
115
|
+
return Array.isArray(input) ? results : results[0];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
useLoader.preload = function (Proto, input, extensions) {
|
|
119
|
+
const keys = Array.isArray(input) ? input : [input];
|
|
120
|
+
return preload(loadingFn(extensions), [Proto, ...keys]);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
useLoader.clear = function (Proto, input) {
|
|
124
|
+
const keys = Array.isArray(input) ? input : [input];
|
|
125
|
+
return clear([Proto, ...keys]);
|
|
126
|
+
};
|
|
18
127
|
|
|
19
|
-
// @ts-ignore
|
|
20
128
|
const EVENTS = {
|
|
21
129
|
PRESS: 'onPress',
|
|
22
130
|
PRESSIN: 'onPressIn',
|
|
@@ -34,30 +142,7 @@ const DOM_EVENTS = {
|
|
|
34
142
|
[EVENTS.HOVERIN]: 'onPointerOver',
|
|
35
143
|
[EVENTS.HOVEROUT]: 'onPointerOut',
|
|
36
144
|
[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
|
-
}
|
|
145
|
+
};
|
|
61
146
|
function createTouchEvents(store) {
|
|
62
147
|
const {
|
|
63
148
|
handlePointer
|
|
@@ -84,10 +169,12 @@ function createTouchEvents(store) {
|
|
|
84
169
|
events
|
|
85
170
|
} = store.getState();
|
|
86
171
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
87
|
-
const
|
|
172
|
+
const connected = new Pressability(events == null ? void 0 : events.handlers);
|
|
173
|
+
const handlers = connected.getEventHandlers();
|
|
88
174
|
set(state => ({
|
|
89
175
|
events: { ...state.events,
|
|
90
|
-
connected
|
|
176
|
+
connected,
|
|
177
|
+
handlers
|
|
91
178
|
}
|
|
92
179
|
}));
|
|
93
180
|
},
|
|
@@ -109,20 +196,15 @@ function createTouchEvents(store) {
|
|
|
109
196
|
};
|
|
110
197
|
}
|
|
111
198
|
|
|
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;
|
|
199
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'performance', 'clock', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
118
200
|
|
|
119
201
|
function Block({
|
|
120
202
|
set
|
|
121
203
|
}) {
|
|
122
|
-
|
|
204
|
+
React.useLayoutEffect(() => {
|
|
123
205
|
set(new Promise(() => null));
|
|
124
206
|
return () => set(false);
|
|
125
|
-
}, []);
|
|
207
|
+
}, [set]);
|
|
126
208
|
return null;
|
|
127
209
|
}
|
|
128
210
|
|
|
@@ -153,13 +235,12 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
|
|
|
153
235
|
fallback,
|
|
154
236
|
style,
|
|
155
237
|
events,
|
|
156
|
-
nativeRef_EXPERIMENTAL,
|
|
157
|
-
onContextCreate,
|
|
158
238
|
...props
|
|
159
239
|
}, forwardedRef) => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
240
|
+
// Create a known catalogue of Threejs-native elements
|
|
241
|
+
// This will include the entire THREE namespace by default, users can extend
|
|
242
|
+
// their own elements by using the createRoot API instead
|
|
243
|
+
React.useMemo(() => extend(THREE), []);
|
|
163
244
|
const [{
|
|
164
245
|
width,
|
|
165
246
|
height
|
|
@@ -167,7 +248,10 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
|
|
|
167
248
|
width: 0,
|
|
168
249
|
height: 0
|
|
169
250
|
});
|
|
251
|
+
const [canvas, setCanvas] = React.useState(null);
|
|
170
252
|
const [bind, setBind] = React.useState();
|
|
253
|
+
const canvasProps = pick(props, CANVAS_PROPS);
|
|
254
|
+
const viewProps = omit(props, CANVAS_PROPS);
|
|
171
255
|
const [block, setBlock] = React.useState(false);
|
|
172
256
|
const [error, setError] = React.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
173
257
|
|
|
@@ -183,356 +267,70 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
|
|
|
183
267
|
width,
|
|
184
268
|
height
|
|
185
269
|
});
|
|
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);
|
|
270
|
+
}, []);
|
|
271
|
+
const onContextCreate = React.useCallback(context => {
|
|
272
|
+
const canvasShim = {
|
|
273
|
+
width: context.drawingBufferWidth,
|
|
274
|
+
height: context.drawingBufferHeight,
|
|
275
|
+
style: {},
|
|
276
|
+
addEventListener: () => {},
|
|
277
|
+
removeEventListener: () => {},
|
|
278
|
+
clientHeight: context.drawingBufferHeight,
|
|
279
|
+
getContext: () => context
|
|
210
280
|
};
|
|
281
|
+
setCanvas(canvasShim);
|
|
211
282
|
}, []);
|
|
212
|
-
return /*#__PURE__*/React.createElement(View, _extends({}, viewProps, {
|
|
213
|
-
ref: forwardedRef,
|
|
214
|
-
onLayout: onLayout,
|
|
215
|
-
style: {
|
|
216
|
-
flex: 1,
|
|
217
|
-
...style
|
|
218
|
-
}
|
|
219
|
-
}, bind), width > 0 && /*#__PURE__*/React.createElement(GLView, {
|
|
220
|
-
nativeRef_EXPERIMENTAL: ref => {
|
|
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
|
-
},
|
|
229
|
-
style: StyleSheet.absoluteFill
|
|
230
|
-
}));
|
|
231
|
-
});
|
|
232
283
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
284
|
+
if (width > 0 && height > 0 && canvas) {
|
|
285
|
+
// Overwrite onCreated to apply RN bindings
|
|
286
|
+
const onCreated = state => {
|
|
287
|
+
// Bind events after creation
|
|
288
|
+
setBind(state.events.handlers); // Bind render to RN bridge
|
|
236
289
|
|
|
237
|
-
const
|
|
238
|
-
|
|
290
|
+
const context = state.gl.getContext();
|
|
291
|
+
const renderFrame = state.gl.render.bind(state.gl);
|
|
239
292
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
293
|
+
state.gl.render = (scene, camera) => {
|
|
294
|
+
renderFrame(scene, camera);
|
|
295
|
+
context.endFrameEXP();
|
|
296
|
+
};
|
|
243
297
|
|
|
244
|
-
|
|
245
|
-
return Asset.fromModule(input);
|
|
246
|
-
|
|
247
|
-
default:
|
|
248
|
-
throw 'Invalid asset! Must be a URI or module.';
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
/**
|
|
252
|
-
* Downloads from a local URI and decodes into an ArrayBuffer.
|
|
253
|
-
*/
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const toBuffer = async localUri => readAsStringAsync(localUri, {
|
|
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
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (url.startsWith != null && url.startsWith('http') && Proto.prototype.hasOwnProperty('load')) {
|
|
303
|
-
return loader.load(entry, data => {
|
|
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
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const {
|
|
311
|
-
localUri
|
|
312
|
-
} = await getAsset(url).downloadAsync();
|
|
313
|
-
const arrayBuffer = await toBuffer(localUri); // Parse it
|
|
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();
|
|
298
|
+
return canvasProps == null ? void 0 : canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
|
|
389
299
|
};
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
return renderer;
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
function createRoot(context, config) {
|
|
396
|
-
return {
|
|
397
|
-
render: element => render(element, context, config),
|
|
398
|
-
unmount: () => unmountComponentAtNode(context)
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
function render(element, context, {
|
|
403
|
-
gl,
|
|
404
|
-
size = {
|
|
405
|
-
width: 0,
|
|
406
|
-
height: 0
|
|
407
|
-
},
|
|
408
|
-
events,
|
|
409
|
-
onCreated,
|
|
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
300
|
|
|
438
|
-
|
|
439
|
-
gl: glRenderer,
|
|
440
|
-
size,
|
|
441
|
-
...props,
|
|
301
|
+
createRoot(canvas, { ...canvasProps,
|
|
442
302
|
// expo-gl can only render at native dpr/resolution
|
|
443
303
|
// https://github.com/expo/expo-three/issues/39
|
|
444
|
-
dpr: PixelRatio.get()
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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
|
-
}
|
|
304
|
+
dpr: PixelRatio.get(),
|
|
305
|
+
size: {
|
|
306
|
+
width,
|
|
307
|
+
height
|
|
308
|
+
},
|
|
309
|
+
events: events || createTouchEvents,
|
|
310
|
+
onCreated
|
|
311
|
+
}).render( /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
312
|
+
set: setError
|
|
313
|
+
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
314
|
+
fallback: /*#__PURE__*/React.createElement(Block, {
|
|
315
|
+
set: setBlock
|
|
316
|
+
})
|
|
317
|
+
}, children)));
|
|
463
318
|
}
|
|
464
319
|
|
|
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
320
|
React.useEffect(() => {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
},
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
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);
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
const act = reconciler.act;
|
|
527
|
-
|
|
528
|
-
function createPortal(children, container) {
|
|
529
|
-
return reconciler.createPortal(children, container, null, null);
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
reconciler.injectIntoDevTools({
|
|
533
|
-
bundleType: process.env.NODE_ENV === 'production' ? 0 : 1,
|
|
534
|
-
rendererPackageName: '@react-three/fiber',
|
|
535
|
-
version: '18.0.0'
|
|
321
|
+
return () => unmountComponentAtNode(canvas);
|
|
322
|
+
}, [canvas]);
|
|
323
|
+
return /*#__PURE__*/React.createElement(View, _extends({}, viewProps, {
|
|
324
|
+
ref: forwardedRef,
|
|
325
|
+
onLayout: onLayout,
|
|
326
|
+
style: {
|
|
327
|
+
flex: 1,
|
|
328
|
+
...style
|
|
329
|
+
}
|
|
330
|
+
}, bind), width > 0 && /*#__PURE__*/React.createElement(GLView, {
|
|
331
|
+
onContextCreate: onContextCreate,
|
|
332
|
+
style: StyleSheet.absoluteFill
|
|
333
|
+
}));
|
|
536
334
|
});
|
|
537
335
|
|
|
538
|
-
export { Canvas,
|
|
336
|
+
export { Canvas, createTouchEvents as events, useLoader };
|