@react-three/fiber 9.0.0-alpha.1 → 9.0.0-alpha.3
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 +962 -444
- package/dist/declarations/src/core/events.d.ts +91 -69
- package/dist/declarations/src/core/hooks.d.ts +53 -24
- package/dist/declarations/src/core/index.d.ts +15 -61
- package/dist/declarations/src/core/loop.d.ts +31 -13
- package/dist/declarations/src/core/reconciler.d.ts +43 -0
- package/dist/declarations/src/core/renderer.d.ts +85 -51
- package/dist/declarations/src/core/stages.d.ts +64 -59
- package/dist/declarations/src/core/store.d.ts +147 -110
- package/dist/declarations/src/core/utils.d.ts +128 -81
- package/dist/declarations/src/index.d.ts +6 -12
- package/dist/declarations/src/native/Canvas.d.ts +14 -8
- package/dist/declarations/src/native/events.d.ts +4 -4
- package/dist/declarations/src/native.d.ts +6 -10
- package/dist/declarations/src/three-types.d.ts +56 -331
- package/dist/declarations/src/web/Canvas.d.ts +24 -9
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/loop-0698c205.cjs.dev.js +2496 -0
- package/dist/loop-a0ef8208.cjs.prod.js +2496 -0
- package/dist/loop-b2aca207.esm.js +2434 -0
- package/dist/react-three-fiber.cjs.d.ts +1 -0
- package/dist/react-three-fiber.cjs.dev.js +139 -100
- package/dist/react-three-fiber.cjs.prod.js +139 -100
- package/dist/react-three-fiber.esm.js +104 -68
- package/native/dist/react-three-fiber-native.cjs.d.ts +1 -0
- package/native/dist/react-three-fiber-native.cjs.dev.js +287 -212
- package/native/dist/react-three-fiber-native.cjs.prod.js +287 -212
- package/native/dist/react-three-fiber-native.esm.js +251 -181
- package/native/package.json +5 -5
- package/package.json +18 -11
- package/readme.md +253 -202
- package/dist/declarations/src/native/polyfills.d.ts +0 -1
- package/dist/index-2e1b7052.cjs.prod.js +0 -2362
- package/dist/index-65e750e4.cjs.dev.js +0 -2362
- package/dist/index-a9c7a6cd.esm.js +0 -2304
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var loop = require('../../dist/loop-0698c205.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
9
9
|
var reactNative = require('react-native');
|
|
10
10
|
var expoGl = require('expo-gl');
|
|
11
|
-
var
|
|
11
|
+
var itsFine = require('its-fine');
|
|
12
|
+
var expoAsset = require('expo-asset');
|
|
13
|
+
var fs = require('expo-file-system');
|
|
14
|
+
var base64Js = require('base64-js');
|
|
15
|
+
var buffer = require('buffer');
|
|
12
16
|
require('react-reconciler/constants');
|
|
13
17
|
require('zustand');
|
|
14
18
|
require('react-reconciler');
|
|
15
19
|
require('scheduler');
|
|
16
20
|
require('suspend-react');
|
|
17
21
|
|
|
18
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
-
|
|
20
22
|
function _interopNamespace(e) {
|
|
21
23
|
if (e && e.__esModule) return e;
|
|
22
24
|
var n = Object.create(null);
|
|
@@ -37,206 +39,95 @@ function _interopNamespace(e) {
|
|
|
37
39
|
|
|
38
40
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
39
41
|
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
/* eslint-enable import/default, import/no-named-as-default, import/no-named-as-default-member */
|
|
42
|
+
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
43
43
|
|
|
44
|
-
const EVENTS = {
|
|
45
|
-
PRESS: 'onPress',
|
|
46
|
-
PRESSIN: 'onPressIn',
|
|
47
|
-
PRESSOUT: 'onPressOut',
|
|
48
|
-
LONGPRESS: 'onLongPress',
|
|
49
|
-
HOVERIN: 'onHoverIn',
|
|
50
|
-
HOVEROUT: 'onHoverOut',
|
|
51
|
-
PRESSMOVE: 'onPressMove'
|
|
52
|
-
};
|
|
53
|
-
const DOM_EVENTS = {
|
|
54
|
-
[EVENTS.PRESS]: 'onClick',
|
|
55
|
-
[EVENTS.PRESSIN]: 'onPointerDown',
|
|
56
|
-
[EVENTS.PRESSOUT]: 'onPointerUp',
|
|
57
|
-
[EVENTS.LONGPRESS]: 'onDoubleClick',
|
|
58
|
-
[EVENTS.HOVERIN]: 'onPointerOver',
|
|
59
|
-
[EVENTS.HOVEROUT]: 'onPointerOut',
|
|
60
|
-
[EVENTS.PRESSMOVE]: 'onPointerMove'
|
|
61
|
-
};
|
|
62
44
|
/** Default R3F event manager for react-native */
|
|
63
|
-
|
|
64
45
|
function createTouchEvents(store) {
|
|
65
46
|
const {
|
|
66
47
|
handlePointer
|
|
67
|
-
} =
|
|
68
|
-
|
|
48
|
+
} = loop.createEvents(store);
|
|
69
49
|
const handleTouch = (event, name) => {
|
|
70
|
-
event.persist()
|
|
50
|
+
event.persist()
|
|
51
|
+
|
|
52
|
+
// Apply offset
|
|
71
53
|
;
|
|
72
54
|
event.nativeEvent.offsetX = event.nativeEvent.locationX;
|
|
73
|
-
event.nativeEvent.offsetY = event.nativeEvent.locationY;
|
|
55
|
+
event.nativeEvent.offsetY = event.nativeEvent.locationY;
|
|
74
56
|
|
|
75
|
-
|
|
76
|
-
|
|
57
|
+
// Emulate DOM event
|
|
58
|
+
const callback = handlePointer(name);
|
|
59
|
+
callback(event.nativeEvent);
|
|
60
|
+
return true;
|
|
77
61
|
};
|
|
78
|
-
|
|
62
|
+
const responder = reactNative.PanResponder.create({
|
|
63
|
+
onStartShouldSetPanResponder: () => true,
|
|
64
|
+
onMoveShouldSetPanResponder: () => true,
|
|
65
|
+
onMoveShouldSetPanResponderCapture: () => true,
|
|
66
|
+
onPanResponderTerminationRequest: () => true,
|
|
67
|
+
onStartShouldSetPanResponderCapture: e => handleTouch(e, 'onPointerCapture'),
|
|
68
|
+
onPanResponderStart: e => handleTouch(e, 'onPointerDown'),
|
|
69
|
+
onPanResponderMove: e => handleTouch(e, 'onPointerMove'),
|
|
70
|
+
onPanResponderEnd: (e, state) => {
|
|
71
|
+
handleTouch(e, 'onPointerUp');
|
|
72
|
+
if (Math.hypot(state.dx, state.dy) < 20) handleTouch(e, 'onClick');
|
|
73
|
+
},
|
|
74
|
+
onPanResponderRelease: e => handleTouch(e, 'onPointerLeave'),
|
|
75
|
+
onPanResponderTerminate: e => handleTouch(e, 'onLostPointerCapture'),
|
|
76
|
+
onPanResponderReject: e => handleTouch(e, 'onLostPointerCapture')
|
|
77
|
+
});
|
|
79
78
|
return {
|
|
80
79
|
priority: 1,
|
|
81
80
|
enabled: true,
|
|
82
|
-
|
|
83
81
|
compute(event, state, previous) {
|
|
84
82
|
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
85
83
|
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
86
84
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
87
85
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
88
86
|
},
|
|
89
|
-
|
|
90
87
|
connected: undefined,
|
|
91
|
-
handlers:
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
handlers: responder.panHandlers,
|
|
89
|
+
update: () => {
|
|
90
|
+
var _internal$lastEvent;
|
|
91
|
+
const {
|
|
92
|
+
events,
|
|
93
|
+
internal
|
|
94
|
+
} = store.getState();
|
|
95
|
+
if ((_internal$lastEvent = internal.lastEvent) != null && _internal$lastEvent.current && events.handlers) {
|
|
96
|
+
handlePointer('onPointerMove')(internal.lastEvent.current);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
94
99
|
connect: () => {
|
|
95
100
|
const {
|
|
96
101
|
set,
|
|
97
102
|
events
|
|
98
103
|
} = store.getState();
|
|
99
104
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
100
|
-
const connected = new Pressability__default["default"](events.handlers);
|
|
101
105
|
set(state => ({
|
|
102
|
-
events: {
|
|
103
|
-
|
|
106
|
+
events: {
|
|
107
|
+
...state.events,
|
|
108
|
+
connected: true
|
|
104
109
|
}
|
|
105
110
|
}));
|
|
106
|
-
const handlers = connected.getEventHandlers();
|
|
107
|
-
return handlers;
|
|
108
111
|
},
|
|
109
112
|
disconnect: () => {
|
|
110
113
|
const {
|
|
111
|
-
set
|
|
112
|
-
events
|
|
114
|
+
set
|
|
113
115
|
} = store.getState();
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
events: { ...state.events,
|
|
119
|
-
connected: undefined
|
|
120
|
-
}
|
|
121
|
-
}));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Check if expo-asset is installed (available with expo modules)
|
|
128
|
-
let expAsset;
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
var _require;
|
|
132
|
-
|
|
133
|
-
expAsset = (_require = require('expo-asset')) == null ? void 0 : _require.Asset;
|
|
134
|
-
} catch (_) {}
|
|
135
|
-
/**
|
|
136
|
-
* Generates an asset based on input type.
|
|
137
|
-
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
function getAsset(input) {
|
|
141
|
-
switch (typeof input) {
|
|
142
|
-
case 'string':
|
|
143
|
-
return expAsset.fromURI(input);
|
|
144
|
-
|
|
145
|
-
case 'number':
|
|
146
|
-
return expAsset.fromModule(input);
|
|
147
|
-
|
|
148
|
-
default:
|
|
149
|
-
throw new Error('R3F: Invalid asset! Must be a URI or module.');
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
let injected = false;
|
|
154
|
-
function polyfills() {
|
|
155
|
-
if (!expAsset || injected) return;
|
|
156
|
-
injected = true; // Don't pre-process urls, let expo-asset generate an absolute URL
|
|
157
|
-
|
|
158
|
-
const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
|
|
159
|
-
|
|
160
|
-
THREE__namespace.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './'; // There's no Image in native, so create a data texture instead
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const prevTextureLoad = THREE__namespace.TextureLoader.prototype.load;
|
|
164
|
-
|
|
165
|
-
THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
166
|
-
const texture = new THREE__namespace.Texture(); // @ts-ignore
|
|
167
|
-
|
|
168
|
-
texture.isDataTexture = true;
|
|
169
|
-
getAsset(url).downloadAsync().then(asset => {
|
|
170
|
-
texture.image = {
|
|
171
|
-
data: asset,
|
|
172
|
-
width: asset.width,
|
|
173
|
-
height: asset.height
|
|
174
|
-
};
|
|
175
|
-
texture.flipY = true;
|
|
176
|
-
texture.unpackAlignment = 1;
|
|
177
|
-
texture.needsUpdate = true;
|
|
178
|
-
onLoad == null ? void 0 : onLoad(texture);
|
|
179
|
-
}).catch(onError);
|
|
180
|
-
return texture;
|
|
181
|
-
}; // Fetches assets via XMLHttpRequest
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const prevFileLoad = THREE__namespace.FileLoader.prototype.load;
|
|
185
|
-
|
|
186
|
-
THREE__namespace.FileLoader.prototype.load = function (url, onLoad, onProgress, onError) {
|
|
187
|
-
if (this.path) url = this.path + url;
|
|
188
|
-
const request = new XMLHttpRequest();
|
|
189
|
-
getAsset(url).downloadAsync().then(asset => {
|
|
190
|
-
request.open('GET', asset.uri, true);
|
|
191
|
-
request.addEventListener('load', event => {
|
|
192
|
-
if (request.status === 200) {
|
|
193
|
-
onLoad == null ? void 0 : onLoad(request.response);
|
|
194
|
-
this.manager.itemEnd(url);
|
|
195
|
-
} else {
|
|
196
|
-
onError == null ? void 0 : onError(event);
|
|
197
|
-
this.manager.itemError(url);
|
|
198
|
-
this.manager.itemEnd(url);
|
|
116
|
+
set(state => ({
|
|
117
|
+
events: {
|
|
118
|
+
...state.events,
|
|
119
|
+
connected: false
|
|
199
120
|
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
onProgress == null ? void 0 : onProgress(event);
|
|
203
|
-
}, false);
|
|
204
|
-
request.addEventListener('error', event => {
|
|
205
|
-
onError == null ? void 0 : onError(event);
|
|
206
|
-
this.manager.itemError(url);
|
|
207
|
-
this.manager.itemEnd(url);
|
|
208
|
-
}, false);
|
|
209
|
-
request.addEventListener('abort', event => {
|
|
210
|
-
onError == null ? void 0 : onError(event);
|
|
211
|
-
this.manager.itemError(url);
|
|
212
|
-
this.manager.itemEnd(url);
|
|
213
|
-
}, false);
|
|
214
|
-
if (this.responseType) request.responseType = this.responseType;
|
|
215
|
-
if (this.withCredentials) request.withCredentials = this.withCredentials;
|
|
216
|
-
|
|
217
|
-
for (const header in this.requestHeader) {
|
|
218
|
-
request.setRequestHeader(header, this.requestHeader[header]);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
request.send(null);
|
|
222
|
-
this.manager.itemStart(url);
|
|
223
|
-
});
|
|
224
|
-
return request;
|
|
225
|
-
}; // Cleanup function
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return () => {
|
|
229
|
-
THREE__namespace.LoaderUtils.extractUrlBase = extractUrlBase;
|
|
230
|
-
THREE__namespace.TextureLoader.prototype.load = prevTextureLoad;
|
|
231
|
-
THREE__namespace.FileLoader.prototype.load = prevFileLoad;
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
232
123
|
};
|
|
233
124
|
}
|
|
234
125
|
|
|
235
|
-
/**
|
|
236
|
-
* A native canvas which accepts threejs elements as children.
|
|
237
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
126
|
+
/**
|
|
127
|
+
* A native canvas which accepts threejs elements as children.
|
|
128
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
238
129
|
*/
|
|
239
|
-
const
|
|
130
|
+
const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
240
131
|
children,
|
|
241
132
|
style,
|
|
242
133
|
gl,
|
|
@@ -250,6 +141,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
250
141
|
performance,
|
|
251
142
|
raycaster,
|
|
252
143
|
camera,
|
|
144
|
+
scene,
|
|
253
145
|
onPointerMissed,
|
|
254
146
|
onCreated,
|
|
255
147
|
stages,
|
|
@@ -258,7 +150,8 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
258
150
|
// Create a known catalogue of Threejs-native elements
|
|
259
151
|
// This will include the entire THREE namespace by default, users can extend
|
|
260
152
|
// their own elements by using the createRoot API instead
|
|
261
|
-
React__namespace.useMemo(() =>
|
|
153
|
+
React__namespace.useMemo(() => loop.extend(THREE__namespace), []);
|
|
154
|
+
const Bridge = loop.useBridge();
|
|
262
155
|
const [{
|
|
263
156
|
width,
|
|
264
157
|
height,
|
|
@@ -273,17 +166,17 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
273
166
|
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
274
167
|
const [bind, setBind] = React__namespace.useState();
|
|
275
168
|
React__namespace.useImperativeHandle(forwardedRef, () => viewRef.current);
|
|
276
|
-
const handlePointerMissed =
|
|
169
|
+
const handlePointerMissed = loop.useMutableCallback(onPointerMissed);
|
|
277
170
|
const [block, setBlock] = React__namespace.useState(false);
|
|
278
|
-
const [error, setError] = React__namespace.useState(undefined);
|
|
279
|
-
|
|
280
|
-
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
171
|
+
const [error, setError] = React__namespace.useState(undefined);
|
|
281
172
|
|
|
173
|
+
// Suspend this component if block is a promise (2nd run)
|
|
174
|
+
if (block) throw block;
|
|
175
|
+
// Throw exception outwards if anything within canvas throws
|
|
282
176
|
if (error) throw error;
|
|
283
177
|
const viewRef = React__namespace.useRef(null);
|
|
284
|
-
const root = React__namespace.useRef(null);
|
|
285
|
-
|
|
286
|
-
React__namespace.useLayoutEffect(() => polyfills(), []);
|
|
178
|
+
const root = React__namespace.useRef(null);
|
|
179
|
+
const [antialias, setAntialias] = React__namespace.useState(true);
|
|
287
180
|
const onLayout = React__namespace.useCallback(e => {
|
|
288
181
|
const {
|
|
289
182
|
width,
|
|
@@ -297,9 +190,10 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
297
190
|
top: y,
|
|
298
191
|
left: x
|
|
299
192
|
});
|
|
300
|
-
}, []);
|
|
301
|
-
// https://github.com/pmndrs/react-three-fiber/pull/2297
|
|
193
|
+
}, []);
|
|
302
194
|
|
|
195
|
+
// Called on context create or swap
|
|
196
|
+
// https://github.com/pmndrs/react-three-fiber/pull/2297
|
|
303
197
|
const onContextCreate = React__namespace.useCallback(context => {
|
|
304
198
|
const canvasShim = {
|
|
305
199
|
width: context.drawingBufferWidth,
|
|
@@ -308,12 +202,16 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
308
202
|
addEventListener: () => {},
|
|
309
203
|
removeEventListener: () => {},
|
|
310
204
|
clientHeight: context.drawingBufferHeight,
|
|
311
|
-
getContext: (
|
|
205
|
+
getContext: (_, {
|
|
206
|
+
antialias = false
|
|
207
|
+
}) => {
|
|
208
|
+
setAntialias(antialias);
|
|
209
|
+
return context;
|
|
210
|
+
}
|
|
312
211
|
};
|
|
313
|
-
root.current =
|
|
212
|
+
root.current = loop.createRoot(canvasShim);
|
|
314
213
|
setCanvas(canvasShim);
|
|
315
214
|
}, []);
|
|
316
|
-
|
|
317
215
|
if (root.current && width > 0 && height > 0) {
|
|
318
216
|
root.current.configure({
|
|
319
217
|
gl,
|
|
@@ -328,6 +226,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
328
226
|
raycaster,
|
|
329
227
|
camera,
|
|
330
228
|
stages,
|
|
229
|
+
scene,
|
|
331
230
|
// expo-gl can only render at native dpr/resolution
|
|
332
231
|
// https://github.com/expo/expo-three/issues/39
|
|
333
232
|
dpr: reactNative.PixelRatio.get(),
|
|
@@ -342,32 +241,29 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
342
241
|
// Overwrite onCreated to apply RN bindings
|
|
343
242
|
onCreated: state => {
|
|
344
243
|
// Bind events after creation
|
|
345
|
-
|
|
346
|
-
setBind(handlers); // Bind render to RN bridge
|
|
244
|
+
setBind(state.events.handlers);
|
|
347
245
|
|
|
246
|
+
// Bind render to RN bridge
|
|
348
247
|
const context = state.gl.getContext();
|
|
349
248
|
const renderFrame = state.gl.render.bind(state.gl);
|
|
350
|
-
|
|
351
249
|
state.gl.render = (scene, camera) => {
|
|
352
250
|
renderFrame(scene, camera);
|
|
353
251
|
context.endFrameEXP();
|
|
354
252
|
};
|
|
355
|
-
|
|
356
253
|
return onCreated == null ? void 0 : onCreated(state);
|
|
357
254
|
}
|
|
358
255
|
});
|
|
359
|
-
root.current.render( /*#__PURE__*/React__namespace.createElement(
|
|
256
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(Bridge, null, /*#__PURE__*/React__namespace.createElement(loop.ErrorBoundary, {
|
|
360
257
|
set: setError
|
|
361
258
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
362
|
-
fallback: /*#__PURE__*/React__namespace.createElement(
|
|
259
|
+
fallback: /*#__PURE__*/React__namespace.createElement(loop.Block, {
|
|
363
260
|
set: setBlock
|
|
364
261
|
})
|
|
365
|
-
}, children)));
|
|
262
|
+
}, children))));
|
|
366
263
|
}
|
|
367
|
-
|
|
368
264
|
React__namespace.useEffect(() => {
|
|
369
265
|
if (canvas) {
|
|
370
|
-
return () =>
|
|
266
|
+
return () => loop.unmountComponentAtNode(canvas);
|
|
371
267
|
}
|
|
372
268
|
}, [canvas]);
|
|
373
269
|
return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, props, {
|
|
@@ -378,34 +274,213 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
378
274
|
...style
|
|
379
275
|
}
|
|
380
276
|
}, bind), width > 0 && /*#__PURE__*/React__namespace.createElement(expoGl.GLView, {
|
|
277
|
+
msaaSamples: antialias ? 4 : 0,
|
|
381
278
|
onContextCreate: onContextCreate,
|
|
382
279
|
style: reactNative.StyleSheet.absoluteFill
|
|
383
280
|
}));
|
|
384
281
|
});
|
|
385
282
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
283
|
+
/**
|
|
284
|
+
* A native canvas which accepts threejs elements as children.
|
|
285
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
286
|
+
*/
|
|
287
|
+
const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(props, ref) {
|
|
288
|
+
return /*#__PURE__*/React__namespace.createElement(itsFine.FiberProvider, null, /*#__PURE__*/React__namespace.createElement(CanvasImpl, _extends({}, props, {
|
|
289
|
+
ref: ref
|
|
290
|
+
})));
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// http://stackoverflow.com/questions/105034
|
|
294
|
+
function uuidv4() {
|
|
295
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
296
|
+
const r = Math.random() * 16 | 0,
|
|
297
|
+
v = c == 'x' ? r : r & 0x3 | 0x8;
|
|
298
|
+
return v.toString(16);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
async function getAsset(input) {
|
|
302
|
+
if (typeof input === 'string') {
|
|
303
|
+
var _NativeModules$BlobMo;
|
|
304
|
+
// Don't process storage
|
|
305
|
+
if (input.startsWith('file:')) return input;
|
|
306
|
+
|
|
307
|
+
// Unpack Blobs from react-native BlobManager
|
|
308
|
+
// https://github.com/facebook/react-native/issues/22681#issuecomment-523258955
|
|
309
|
+
if (input.startsWith('blob:') || input.startsWith((_NativeModules$BlobMo = reactNative.NativeModules.BlobModule) == null ? void 0 : _NativeModules$BlobMo.BLOB_URI_SCHEME)) {
|
|
310
|
+
const blob = await new Promise((res, rej) => {
|
|
311
|
+
const xhr = new XMLHttpRequest();
|
|
312
|
+
xhr.open('GET', input);
|
|
313
|
+
xhr.responseType = 'blob';
|
|
314
|
+
xhr.onload = () => res(xhr.response);
|
|
315
|
+
xhr.onerror = rej;
|
|
316
|
+
xhr.send();
|
|
317
|
+
});
|
|
318
|
+
const data = await new Promise((res, rej) => {
|
|
319
|
+
const reader = new FileReader();
|
|
320
|
+
reader.onload = () => res(reader.result);
|
|
321
|
+
reader.onerror = rej;
|
|
322
|
+
reader.readAsText(blob);
|
|
323
|
+
});
|
|
324
|
+
input = `data:${blob.type};base64,${data}`;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Create safe URI for JSI serialization
|
|
328
|
+
if (input.startsWith('data:')) {
|
|
329
|
+
const [header, data] = input.split(';base64,');
|
|
330
|
+
const [, type] = header.split('/');
|
|
331
|
+
const uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
|
|
332
|
+
await fs__namespace.writeAsStringAsync(uri, data, {
|
|
333
|
+
encoding: fs__namespace.EncodingType.Base64
|
|
334
|
+
});
|
|
335
|
+
return uri;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Download bundler module or external URL
|
|
340
|
+
const asset = await expoAsset.Asset.fromModule(input).downloadAsync();
|
|
341
|
+
let uri = asset.localUri || asset.uri;
|
|
342
|
+
|
|
343
|
+
// Unpack assets in Android Release Mode
|
|
344
|
+
if (!uri.includes(':')) {
|
|
345
|
+
const file = `${fs__namespace.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
346
|
+
await fs__namespace.copyAsync({
|
|
347
|
+
from: uri,
|
|
348
|
+
to: file
|
|
349
|
+
});
|
|
350
|
+
uri = file;
|
|
351
|
+
}
|
|
352
|
+
return uri;
|
|
353
|
+
}
|
|
354
|
+
function polyfills() {
|
|
355
|
+
// Patch Blob for ArrayBuffer and URL if unsupported
|
|
356
|
+
// https://github.com/facebook/react-native/pull/39276
|
|
357
|
+
// https://github.com/pmndrs/react-three-fiber/issues/3058
|
|
358
|
+
if (reactNative.Platform.OS !== 'web') {
|
|
359
|
+
try {
|
|
360
|
+
const blob = new Blob([new ArrayBuffer(4)]);
|
|
361
|
+
const url = URL.createObjectURL(blob);
|
|
362
|
+
URL.revokeObjectURL(url);
|
|
363
|
+
} catch (_) {
|
|
364
|
+
const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
|
|
365
|
+
const createObjectURL = URL.createObjectURL;
|
|
366
|
+
URL.createObjectURL = function (blob) {
|
|
367
|
+
if (blob.data._base64) {
|
|
368
|
+
return `data:${blob.type};base64,${blob.data._base64}`;
|
|
369
|
+
}
|
|
370
|
+
return createObjectURL(blob);
|
|
371
|
+
};
|
|
372
|
+
const createFromParts = BlobManager.createFromParts;
|
|
373
|
+
BlobManager.createFromParts = function (parts, options) {
|
|
374
|
+
parts = parts.map(part => {
|
|
375
|
+
if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
|
|
376
|
+
part = base64Js.fromByteArray(new Uint8Array(part));
|
|
377
|
+
}
|
|
378
|
+
return part;
|
|
379
|
+
});
|
|
380
|
+
const blob = createFromParts(parts, options);
|
|
381
|
+
|
|
382
|
+
// Always enable slow but safe path for iOS (previously for Android unauth)
|
|
383
|
+
// https://github.com/pmndrs/react-three-fiber/issues/3075
|
|
384
|
+
// if (!NativeModules.BlobModule?.BLOB_URI_SCHEME) {
|
|
385
|
+
blob.data._base64 = '';
|
|
386
|
+
for (const part of parts) {
|
|
387
|
+
var _data$_base, _data;
|
|
388
|
+
blob.data._base64 += (_data$_base = (_data = part.data) == null ? void 0 : _data._base64) != null ? _data$_base : part;
|
|
389
|
+
}
|
|
390
|
+
// }
|
|
391
|
+
|
|
392
|
+
return blob;
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Don't pre-process urls, let expo-asset generate an absolute URL
|
|
398
|
+
const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
|
|
399
|
+
THREE__namespace.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './';
|
|
400
|
+
|
|
401
|
+
// There's no Image in native, so create a data texture instead
|
|
402
|
+
THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
403
|
+
if (this.path && typeof url === 'string') url = this.path + url;
|
|
404
|
+
const texture = new THREE__namespace.Texture();
|
|
405
|
+
getAsset(url).then(async uri => {
|
|
406
|
+
// https://github.com/expo/expo-three/pull/266
|
|
407
|
+
const {
|
|
408
|
+
width,
|
|
409
|
+
height
|
|
410
|
+
} = await new Promise((res, rej) => reactNative.Image.getSize(uri, (width, height) => res({
|
|
411
|
+
width,
|
|
412
|
+
height
|
|
413
|
+
}), rej));
|
|
414
|
+
texture.image = {
|
|
415
|
+
// Special case for EXGLImageUtils::loadImage
|
|
416
|
+
data: {
|
|
417
|
+
localUri: uri
|
|
418
|
+
},
|
|
419
|
+
width,
|
|
420
|
+
height
|
|
421
|
+
};
|
|
422
|
+
texture.flipY = true; // Since expo-gl@12.4.0
|
|
423
|
+
texture.needsUpdate = true;
|
|
424
|
+
|
|
425
|
+
// Force non-DOM upload for EXGL texImage2D
|
|
426
|
+
// @ts-ignore
|
|
427
|
+
texture.isDataTexture = true;
|
|
428
|
+
onLoad == null ? void 0 : onLoad(texture);
|
|
429
|
+
}).catch(onError);
|
|
430
|
+
return texture;
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
// Fetches assets via FS
|
|
434
|
+
THREE__namespace.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
435
|
+
if (this.path && typeof url === 'string') url = this.path + url;
|
|
436
|
+
this.manager.itemStart(url);
|
|
437
|
+
getAsset(url).then(async uri => {
|
|
438
|
+
const base64 = await fs__namespace.readAsStringAsync(uri, {
|
|
439
|
+
encoding: fs__namespace.EncodingType.Base64
|
|
440
|
+
});
|
|
441
|
+
const data = buffer.Buffer.from(base64, 'base64');
|
|
442
|
+
onLoad == null ? void 0 : onLoad(data.buffer);
|
|
443
|
+
}).catch(error => {
|
|
444
|
+
onError == null ? void 0 : onError(error);
|
|
445
|
+
this.manager.itemError(url);
|
|
446
|
+
}).finally(() => {
|
|
447
|
+
this.manager.itemEnd(url);
|
|
448
|
+
});
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (reactNative.Platform.OS !== 'web') polyfills();
|
|
453
|
+
|
|
454
|
+
exports.FixedStage = loop.FixedStage;
|
|
455
|
+
exports.ReactThreeFiber = loop.threeTypes;
|
|
456
|
+
exports.Stage = loop.Stage;
|
|
457
|
+
exports.Stages = loop.Stages;
|
|
458
|
+
exports._roots = loop._roots;
|
|
459
|
+
exports.act = loop.act;
|
|
460
|
+
exports.addAfterEffect = loop.addAfterEffect;
|
|
461
|
+
exports.addEffect = loop.addEffect;
|
|
462
|
+
exports.addTail = loop.addTail;
|
|
463
|
+
exports.advance = loop.advance;
|
|
464
|
+
exports.applyProps = loop.applyProps;
|
|
465
|
+
exports.buildGraph = loop.buildGraph;
|
|
466
|
+
exports.context = loop.context;
|
|
467
|
+
exports.createEvents = loop.createEvents;
|
|
468
|
+
exports.createPortal = loop.createPortal;
|
|
469
|
+
exports.createRoot = loop.createRoot;
|
|
470
|
+
exports.dispose = loop.dispose;
|
|
471
|
+
exports.extend = loop.extend;
|
|
472
|
+
exports.flushGlobalEffects = loop.flushGlobalEffects;
|
|
473
|
+
exports.getRootState = loop.getRootState;
|
|
474
|
+
exports.invalidate = loop.invalidate;
|
|
475
|
+
exports.reconciler = loop.reconciler;
|
|
476
|
+
exports.render = loop.render;
|
|
477
|
+
exports.unmountComponentAtNode = loop.unmountComponentAtNode;
|
|
478
|
+
exports.useFrame = loop.useFrame;
|
|
479
|
+
exports.useGraph = loop.useGraph;
|
|
480
|
+
exports.useInstanceHandle = loop.useInstanceHandle;
|
|
481
|
+
exports.useLoader = loop.useLoader;
|
|
482
|
+
exports.useStore = loop.useStore;
|
|
483
|
+
exports.useThree = loop.useThree;
|
|
484
|
+
exports.useUpdate = loop.useUpdate;
|
|
410
485
|
exports.Canvas = Canvas;
|
|
411
486
|
exports.events = createTouchEvents;
|