@react-three/fiber 9.0.0-alpha.2 → 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 -522
- package/dist/declarations/src/core/events.d.ts +91 -69
- package/dist/declarations/src/core/hooks.d.ts +53 -27
- package/dist/declarations/src/core/index.d.ts +15 -60
- package/dist/declarations/src/core/loop.d.ts +31 -15
- package/dist/declarations/src/core/reconciler.d.ts +43 -0
- package/dist/declarations/src/core/renderer.d.ts +85 -40
- package/dist/declarations/src/core/stages.d.ts +64 -59
- package/dist/declarations/src/core/store.d.ts +147 -109
- package/dist/declarations/src/core/utils.d.ts +128 -80
- package/dist/declarations/src/index.d.ts +6 -10
- 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 -8
- package/dist/declarations/src/three-types.d.ts +56 -47
- package/dist/declarations/src/web/Canvas.d.ts +24 -11
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/{index-5bd4d3cf.cjs.dev.js → loop-0698c205.cjs.dev.js} +1469 -1268
- package/dist/{index-8128f248.cjs.prod.js → loop-a0ef8208.cjs.prod.js} +1469 -1268
- package/dist/{index-47b7622a.esm.js → loop-b2aca207.esm.js} +1466 -1268
- package/dist/react-three-fiber.cjs.d.ts +1 -0
- package/dist/react-three-fiber.cjs.dev.js +126 -115
- package/dist/react-three-fiber.cjs.prod.js +126 -115
- package/dist/react-three-fiber.esm.js +92 -84
- package/native/dist/react-three-fiber-native.cjs.d.ts +1 -0
- package/native/dist/react-three-fiber-native.cjs.dev.js +278 -211
- package/native/dist/react-three-fiber-native.cjs.prod.js +278 -211
- package/native/dist/react-three-fiber-native.esm.js +242 -180
- package/native/package.json +5 -5
- package/package.json +18 -12
- package/readme.md +253 -202
- package/dist/declarations/src/native/polyfills.d.ts +0 -1
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var loop = require('../../dist/loop-a0ef8208.cjs.prod.js');
|
|
5
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
6
7
|
var React = require('react');
|
|
7
8
|
var THREE = require('three');
|
|
8
9
|
var reactNative = require('react-native');
|
|
9
10
|
var expoGl = require('expo-gl');
|
|
10
11
|
var itsFine = require('its-fine');
|
|
11
|
-
var
|
|
12
|
-
var
|
|
12
|
+
var expoAsset = require('expo-asset');
|
|
13
|
+
var fs = require('expo-file-system');
|
|
14
|
+
var base64Js = require('base64-js');
|
|
15
|
+
var buffer = require('buffer');
|
|
13
16
|
require('react-reconciler/constants');
|
|
14
17
|
require('zustand');
|
|
15
18
|
require('react-reconciler');
|
|
16
19
|
require('scheduler');
|
|
17
20
|
require('suspend-react');
|
|
18
21
|
|
|
19
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
20
|
-
|
|
21
22
|
function _interopNamespace(e) {
|
|
22
23
|
if (e && e.__esModule) return e;
|
|
23
24
|
var n = Object.create(null);
|
|
@@ -38,201 +39,94 @@ function _interopNamespace(e) {
|
|
|
38
39
|
|
|
39
40
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
40
41
|
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
/* eslint-enable import/default, import/no-named-as-default, import/no-named-as-default-member */
|
|
42
|
+
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
44
43
|
|
|
45
|
-
const EVENTS = {
|
|
46
|
-
PRESS: 'onPress',
|
|
47
|
-
PRESSIN: 'onPressIn',
|
|
48
|
-
PRESSOUT: 'onPressOut',
|
|
49
|
-
LONGPRESS: 'onLongPress',
|
|
50
|
-
HOVERIN: 'onHoverIn',
|
|
51
|
-
HOVEROUT: 'onHoverOut',
|
|
52
|
-
PRESSMOVE: 'onPressMove'
|
|
53
|
-
};
|
|
54
|
-
const DOM_EVENTS = {
|
|
55
|
-
[EVENTS.PRESS]: 'onClick',
|
|
56
|
-
[EVENTS.PRESSIN]: 'onPointerDown',
|
|
57
|
-
[EVENTS.PRESSOUT]: 'onPointerUp',
|
|
58
|
-
[EVENTS.LONGPRESS]: 'onDoubleClick',
|
|
59
|
-
[EVENTS.HOVERIN]: 'onPointerOver',
|
|
60
|
-
[EVENTS.HOVEROUT]: 'onPointerOut',
|
|
61
|
-
[EVENTS.PRESSMOVE]: 'onPointerMove'
|
|
62
|
-
};
|
|
63
44
|
/** Default R3F event manager for react-native */
|
|
64
|
-
|
|
65
45
|
function createTouchEvents(store) {
|
|
66
46
|
const {
|
|
67
47
|
handlePointer
|
|
68
|
-
} =
|
|
69
|
-
|
|
48
|
+
} = loop.createEvents(store);
|
|
70
49
|
const handleTouch = (event, name) => {
|
|
71
|
-
event.persist()
|
|
50
|
+
event.persist()
|
|
51
|
+
|
|
52
|
+
// Apply offset
|
|
72
53
|
;
|
|
73
54
|
event.nativeEvent.offsetX = event.nativeEvent.locationX;
|
|
74
|
-
event.nativeEvent.offsetY = event.nativeEvent.locationY;
|
|
55
|
+
event.nativeEvent.offsetY = event.nativeEvent.locationY;
|
|
75
56
|
|
|
76
|
-
|
|
77
|
-
|
|
57
|
+
// Emulate DOM event
|
|
58
|
+
const callback = handlePointer(name);
|
|
59
|
+
callback(event.nativeEvent);
|
|
60
|
+
return true;
|
|
78
61
|
};
|
|
79
|
-
|
|
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
|
+
});
|
|
80
78
|
return {
|
|
81
79
|
priority: 1,
|
|
82
80
|
enabled: true,
|
|
83
|
-
|
|
84
81
|
compute(event, state, previous) {
|
|
85
82
|
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
86
83
|
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
87
84
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
88
85
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
89
86
|
},
|
|
90
|
-
|
|
91
87
|
connected: undefined,
|
|
92
|
-
handlers:
|
|
93
|
-
|
|
94
|
-
|
|
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
|
+
},
|
|
95
99
|
connect: () => {
|
|
96
100
|
const {
|
|
97
101
|
set,
|
|
98
102
|
events
|
|
99
103
|
} = store.getState();
|
|
100
104
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
101
|
-
const connected = new Pressability__default["default"](events.handlers);
|
|
102
105
|
set(state => ({
|
|
103
|
-
events: {
|
|
104
|
-
|
|
106
|
+
events: {
|
|
107
|
+
...state.events,
|
|
108
|
+
connected: true
|
|
105
109
|
}
|
|
106
110
|
}));
|
|
107
|
-
const handlers = connected.getEventHandlers();
|
|
108
|
-
return handlers;
|
|
109
111
|
},
|
|
110
112
|
disconnect: () => {
|
|
111
113
|
const {
|
|
112
|
-
set
|
|
113
|
-
events
|
|
114
|
+
set
|
|
114
115
|
} = store.getState();
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
}));
|
|
123
|
-
}
|
|
116
|
+
set(state => ({
|
|
117
|
+
events: {
|
|
118
|
+
...state.events,
|
|
119
|
+
connected: false
|
|
120
|
+
}
|
|
121
|
+
}));
|
|
124
122
|
}
|
|
125
123
|
};
|
|
126
124
|
}
|
|
127
125
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
var _require;
|
|
133
|
-
|
|
134
|
-
expAsset = (_require = require('expo-asset')) == null ? void 0 : _require.Asset;
|
|
135
|
-
} catch (_) {}
|
|
136
|
-
/**
|
|
137
|
-
* Generates an asset based on input type.
|
|
126
|
+
/**
|
|
127
|
+
* A native canvas which accepts threejs elements as children.
|
|
128
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
138
129
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
function getAsset(input) {
|
|
142
|
-
switch (typeof input) {
|
|
143
|
-
case 'string':
|
|
144
|
-
return expAsset.fromURI(input);
|
|
145
|
-
|
|
146
|
-
case 'number':
|
|
147
|
-
return expAsset.fromModule(input);
|
|
148
|
-
|
|
149
|
-
default:
|
|
150
|
-
throw new Error('R3F: Invalid asset! Must be a URI or module.');
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
let injected = false;
|
|
155
|
-
function polyfills() {
|
|
156
|
-
if (!expAsset || injected) return;
|
|
157
|
-
injected = true; // Don't pre-process urls, let expo-asset generate an absolute URL
|
|
158
|
-
|
|
159
|
-
const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
|
|
160
|
-
|
|
161
|
-
THREE__namespace.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './'; // There's no Image in native, so create a data texture instead
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const prevTextureLoad = THREE__namespace.TextureLoader.prototype.load;
|
|
165
|
-
|
|
166
|
-
THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
167
|
-
const texture = new THREE__namespace.Texture(); // @ts-ignore
|
|
168
|
-
|
|
169
|
-
texture.isDataTexture = true;
|
|
170
|
-
getAsset(url).downloadAsync().then(asset => {
|
|
171
|
-
texture.image = {
|
|
172
|
-
data: asset,
|
|
173
|
-
width: asset.width,
|
|
174
|
-
height: asset.height
|
|
175
|
-
};
|
|
176
|
-
texture.flipY = true;
|
|
177
|
-
texture.unpackAlignment = 1;
|
|
178
|
-
texture.needsUpdate = true;
|
|
179
|
-
onLoad == null ? void 0 : onLoad(texture);
|
|
180
|
-
}).catch(onError);
|
|
181
|
-
return texture;
|
|
182
|
-
}; // Fetches assets via XMLHttpRequest
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const prevFileLoad = THREE__namespace.FileLoader.prototype.load;
|
|
186
|
-
|
|
187
|
-
THREE__namespace.FileLoader.prototype.load = function (url, onLoad, onProgress, onError) {
|
|
188
|
-
if (this.path) url = this.path + url;
|
|
189
|
-
const request = new XMLHttpRequest();
|
|
190
|
-
getAsset(url).downloadAsync().then(asset => {
|
|
191
|
-
request.open('GET', asset.uri, true);
|
|
192
|
-
request.addEventListener('load', event => {
|
|
193
|
-
if (request.status === 200) {
|
|
194
|
-
onLoad == null ? void 0 : onLoad(request.response);
|
|
195
|
-
this.manager.itemEnd(url);
|
|
196
|
-
} else {
|
|
197
|
-
onError == null ? void 0 : onError(event);
|
|
198
|
-
this.manager.itemError(url);
|
|
199
|
-
this.manager.itemEnd(url);
|
|
200
|
-
}
|
|
201
|
-
}, false);
|
|
202
|
-
request.addEventListener('progress', event => {
|
|
203
|
-
onProgress == null ? void 0 : onProgress(event);
|
|
204
|
-
}, false);
|
|
205
|
-
request.addEventListener('error', event => {
|
|
206
|
-
onError == null ? void 0 : onError(event);
|
|
207
|
-
this.manager.itemError(url);
|
|
208
|
-
this.manager.itemEnd(url);
|
|
209
|
-
}, false);
|
|
210
|
-
request.addEventListener('abort', event => {
|
|
211
|
-
onError == null ? void 0 : onError(event);
|
|
212
|
-
this.manager.itemError(url);
|
|
213
|
-
this.manager.itemEnd(url);
|
|
214
|
-
}, false);
|
|
215
|
-
if (this.responseType) request.responseType = this.responseType;
|
|
216
|
-
if (this.withCredentials) request.withCredentials = this.withCredentials;
|
|
217
|
-
|
|
218
|
-
for (const header in this.requestHeader) {
|
|
219
|
-
request.setRequestHeader(header, this.requestHeader[header]);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
request.send(null);
|
|
223
|
-
this.manager.itemStart(url);
|
|
224
|
-
});
|
|
225
|
-
return request;
|
|
226
|
-
}; // Cleanup function
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return () => {
|
|
230
|
-
THREE__namespace.LoaderUtils.extractUrlBase = extractUrlBase;
|
|
231
|
-
THREE__namespace.TextureLoader.prototype.load = prevTextureLoad;
|
|
232
|
-
THREE__namespace.FileLoader.prototype.load = prevFileLoad;
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
130
|
const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
237
131
|
children,
|
|
238
132
|
style,
|
|
@@ -247,6 +141,7 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
247
141
|
performance,
|
|
248
142
|
raycaster,
|
|
249
143
|
camera,
|
|
144
|
+
scene,
|
|
250
145
|
onPointerMissed,
|
|
251
146
|
onCreated,
|
|
252
147
|
stages,
|
|
@@ -255,8 +150,8 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
255
150
|
// Create a known catalogue of Threejs-native elements
|
|
256
151
|
// This will include the entire THREE namespace by default, users can extend
|
|
257
152
|
// their own elements by using the createRoot API instead
|
|
258
|
-
React__namespace.useMemo(() =>
|
|
259
|
-
const Bridge =
|
|
153
|
+
React__namespace.useMemo(() => loop.extend(THREE__namespace), []);
|
|
154
|
+
const Bridge = loop.useBridge();
|
|
260
155
|
const [{
|
|
261
156
|
width,
|
|
262
157
|
height,
|
|
@@ -271,17 +166,17 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
271
166
|
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
272
167
|
const [bind, setBind] = React__namespace.useState();
|
|
273
168
|
React__namespace.useImperativeHandle(forwardedRef, () => viewRef.current);
|
|
274
|
-
const handlePointerMissed =
|
|
169
|
+
const handlePointerMissed = loop.useMutableCallback(onPointerMissed);
|
|
275
170
|
const [block, setBlock] = React__namespace.useState(false);
|
|
276
|
-
const [error, setError] = React__namespace.useState(undefined);
|
|
277
|
-
|
|
278
|
-
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
171
|
+
const [error, setError] = React__namespace.useState(undefined);
|
|
279
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
|
|
280
176
|
if (error) throw error;
|
|
281
177
|
const viewRef = React__namespace.useRef(null);
|
|
282
|
-
const root = React__namespace.useRef(null);
|
|
283
|
-
|
|
284
|
-
React__namespace.useLayoutEffect(() => polyfills(), []);
|
|
178
|
+
const root = React__namespace.useRef(null);
|
|
179
|
+
const [antialias, setAntialias] = React__namespace.useState(true);
|
|
285
180
|
const onLayout = React__namespace.useCallback(e => {
|
|
286
181
|
const {
|
|
287
182
|
width,
|
|
@@ -295,9 +190,10 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
295
190
|
top: y,
|
|
296
191
|
left: x
|
|
297
192
|
});
|
|
298
|
-
}, []);
|
|
299
|
-
// https://github.com/pmndrs/react-three-fiber/pull/2297
|
|
193
|
+
}, []);
|
|
300
194
|
|
|
195
|
+
// Called on context create or swap
|
|
196
|
+
// https://github.com/pmndrs/react-three-fiber/pull/2297
|
|
301
197
|
const onContextCreate = React__namespace.useCallback(context => {
|
|
302
198
|
const canvasShim = {
|
|
303
199
|
width: context.drawingBufferWidth,
|
|
@@ -306,12 +202,16 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
306
202
|
addEventListener: () => {},
|
|
307
203
|
removeEventListener: () => {},
|
|
308
204
|
clientHeight: context.drawingBufferHeight,
|
|
309
|
-
getContext: (
|
|
205
|
+
getContext: (_, {
|
|
206
|
+
antialias = false
|
|
207
|
+
}) => {
|
|
208
|
+
setAntialias(antialias);
|
|
209
|
+
return context;
|
|
210
|
+
}
|
|
310
211
|
};
|
|
311
|
-
root.current =
|
|
212
|
+
root.current = loop.createRoot(canvasShim);
|
|
312
213
|
setCanvas(canvasShim);
|
|
313
214
|
}, []);
|
|
314
|
-
|
|
315
215
|
if (root.current && width > 0 && height > 0) {
|
|
316
216
|
root.current.configure({
|
|
317
217
|
gl,
|
|
@@ -326,6 +226,7 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
326
226
|
raycaster,
|
|
327
227
|
camera,
|
|
328
228
|
stages,
|
|
229
|
+
scene,
|
|
329
230
|
// expo-gl can only render at native dpr/resolution
|
|
330
231
|
// https://github.com/expo/expo-three/issues/39
|
|
331
232
|
dpr: reactNative.PixelRatio.get(),
|
|
@@ -340,32 +241,29 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
340
241
|
// Overwrite onCreated to apply RN bindings
|
|
341
242
|
onCreated: state => {
|
|
342
243
|
// Bind events after creation
|
|
343
|
-
|
|
344
|
-
setBind(handlers); // Bind render to RN bridge
|
|
244
|
+
setBind(state.events.handlers);
|
|
345
245
|
|
|
246
|
+
// Bind render to RN bridge
|
|
346
247
|
const context = state.gl.getContext();
|
|
347
248
|
const renderFrame = state.gl.render.bind(state.gl);
|
|
348
|
-
|
|
349
249
|
state.gl.render = (scene, camera) => {
|
|
350
250
|
renderFrame(scene, camera);
|
|
351
251
|
context.endFrameEXP();
|
|
352
252
|
};
|
|
353
|
-
|
|
354
253
|
return onCreated == null ? void 0 : onCreated(state);
|
|
355
254
|
}
|
|
356
255
|
});
|
|
357
|
-
root.current.render( /*#__PURE__*/React__namespace.createElement(Bridge, null, /*#__PURE__*/React__namespace.createElement(
|
|
256
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(Bridge, null, /*#__PURE__*/React__namespace.createElement(loop.ErrorBoundary, {
|
|
358
257
|
set: setError
|
|
359
258
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
360
|
-
fallback: /*#__PURE__*/React__namespace.createElement(
|
|
259
|
+
fallback: /*#__PURE__*/React__namespace.createElement(loop.Block, {
|
|
361
260
|
set: setBlock
|
|
362
261
|
})
|
|
363
262
|
}, children))));
|
|
364
263
|
}
|
|
365
|
-
|
|
366
264
|
React__namespace.useEffect(() => {
|
|
367
265
|
if (canvas) {
|
|
368
|
-
return () =>
|
|
266
|
+
return () => loop.unmountComponentAtNode(canvas);
|
|
369
267
|
}
|
|
370
268
|
}, [canvas]);
|
|
371
269
|
return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, props, {
|
|
@@ -376,44 +274,213 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
376
274
|
...style
|
|
377
275
|
}
|
|
378
276
|
}, bind), width > 0 && /*#__PURE__*/React__namespace.createElement(expoGl.GLView, {
|
|
277
|
+
msaaSamples: antialias ? 4 : 0,
|
|
379
278
|
onContextCreate: onContextCreate,
|
|
380
279
|
style: reactNative.StyleSheet.absoluteFill
|
|
381
280
|
}));
|
|
382
281
|
});
|
|
383
|
-
/**
|
|
384
|
-
* A native canvas which accepts threejs elements as children.
|
|
385
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
386
|
-
*/
|
|
387
282
|
|
|
283
|
+
/**
|
|
284
|
+
* A native canvas which accepts threejs elements as children.
|
|
285
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
286
|
+
*/
|
|
388
287
|
const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(props, ref) {
|
|
389
288
|
return /*#__PURE__*/React__namespace.createElement(itsFine.FiberProvider, null, /*#__PURE__*/React__namespace.createElement(CanvasImpl, _extends({}, props, {
|
|
390
289
|
ref: ref
|
|
391
290
|
})));
|
|
392
291
|
});
|
|
393
292
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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;
|
|
418
485
|
exports.Canvas = Canvas;
|
|
419
486
|
exports.events = createTouchEvents;
|