@react-three/fiber 8.14.6 → 8.14.7

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.
@@ -374,12 +374,12 @@ function createRenderer(_roots, _getEventPriority) {
374
374
  }
375
375
 
376
376
  var _window$document, _window$navigator;
377
- /**
378
- * Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
377
+ /**
378
+ * Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
379
379
  */
380
380
  const hasColorSpace = object => 'colorSpace' in object || 'outputColorSpace' in object;
381
- /**
382
- * The current THREE.ColorManagement instance, if present.
381
+ /**
382
+ * The current THREE.ColorManagement instance, if present.
383
383
  */
384
384
  const getColorManagement = () => {
385
385
  var _ColorManagement;
@@ -388,14 +388,14 @@ const getColorManagement = () => {
388
388
  const isOrthographicCamera = def => def && def.isOrthographicCamera;
389
389
  const isRef = obj => obj && obj.hasOwnProperty('current');
390
390
 
391
- /**
392
- * An SSR-friendly useLayoutEffect.
393
- *
394
- * React currently throws a warning when using useLayoutEffect on the server.
395
- * To get around it, we can conditionally useEffect on the server (no-op) and
396
- * useLayoutEffect elsewhere.
397
- *
398
- * @see https://github.com/facebook/react/issues/14927
391
+ /**
392
+ * An SSR-friendly useLayoutEffect.
393
+ *
394
+ * React currently throws a warning when using useLayoutEffect on the server.
395
+ * To get around it, we can conditionally useEffect on the server (no-op) and
396
+ * useLayoutEffect elsewhere.
397
+ *
398
+ * @see https://github.com/facebook/react/issues/14927
399
399
  */
400
400
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' && ((_window$document = window.document) != null && _window$document.createElement || ((_window$navigator = window.navigator) == null ? void 0 : _window$navigator.product) === 'ReactNative') ? React__namespace.useLayoutEffect : React__namespace.useEffect;
401
401
  function useMutableCallback(fn) {
@@ -440,8 +440,8 @@ function calculateDpr(dpr) {
440
440
  return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
441
441
  }
442
442
 
443
- /**
444
- * Returns instance root state
443
+ /**
444
+ * Returns instance root state
445
445
  */
446
446
  const getRootState = obj => {
447
447
  var _r3f;
@@ -836,9 +836,9 @@ function getEventPriority() {
836
836
  }
837
837
  }
838
838
 
839
- /**
840
- * Release pointer captures.
841
- * This is called by releasePointerCapture in the API, and when an object is removed.
839
+ /**
840
+ * Release pointer captures.
841
+ * This is called by releasePointerCapture in the API, and when an object is removed.
842
842
  */
843
843
  function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
844
844
  const captureData = captures.get(obj);
@@ -1173,19 +1173,19 @@ function createEvents(store) {
1173
1173
  // Check presence of handlers
1174
1174
  if (!(instance != null && instance.eventCount)) return;
1175
1175
 
1176
- /*
1177
- MAYBE TODO, DELETE IF NOT:
1178
- Check if the object is captured, captured events should not have intersects running in parallel
1179
- But wouldn't it be better to just replace capturedMap with a single entry?
1180
- Also, are we OK with straight up making picking up multiple objects impossible?
1181
-
1182
- const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
1183
- if (pointerId !== undefined) {
1184
- const capturedMeshSet = internal.capturedMap.get(pointerId)
1185
- if (capturedMeshSet) {
1186
- const captured = capturedMeshSet.get(eventObject)
1187
- if (captured && captured.localState.stopped) return
1188
- }
1176
+ /*
1177
+ MAYBE TODO, DELETE IF NOT:
1178
+ Check if the object is captured, captured events should not have intersects running in parallel
1179
+ But wouldn't it be better to just replace capturedMap with a single entry?
1180
+ Also, are we OK with straight up making picking up multiple objects impossible?
1181
+
1182
+ const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
1183
+ if (pointerId !== undefined) {
1184
+ const capturedMeshSet = internal.capturedMap.get(pointerId)
1185
+ if (capturedMeshSet) {
1186
+ const captured = capturedMeshSet.get(eventObject)
1187
+ if (captured && captured.localState.stopped) return
1188
+ }
1189
1189
  }*/
1190
1190
 
1191
1191
  if (isPointerMove) {
@@ -1491,21 +1491,21 @@ let globalEffects = new Set();
1491
1491
  let globalAfterEffects = new Set();
1492
1492
  let globalTailEffects = new Set();
1493
1493
 
1494
- /**
1495
- * Adds a global render callback which is called each frame.
1496
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
1494
+ /**
1495
+ * Adds a global render callback which is called each frame.
1496
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
1497
1497
  */
1498
1498
  const addEffect = callback => createSubs(callback, globalEffects);
1499
1499
 
1500
- /**
1501
- * Adds a global after-render callback which is called each frame.
1502
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
1500
+ /**
1501
+ * Adds a global after-render callback which is called each frame.
1502
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
1503
1503
  */
1504
1504
  const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
1505
1505
 
1506
- /**
1507
- * Adds a global callback which is called when rendering stops.
1508
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
1506
+ /**
1507
+ * Adds a global callback which is called when rendering stops.
1508
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
1509
1509
  */
1510
1510
  const addTail = callback => createSubs(callback, globalTailEffects);
1511
1511
  function run(effects, timestamp) {
@@ -1604,24 +1604,24 @@ function createLoop(roots) {
1604
1604
  }
1605
1605
  return {
1606
1606
  loop,
1607
- /**
1608
- * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
1609
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
1607
+ /**
1608
+ * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
1609
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
1610
1610
  */
1611
1611
  invalidate,
1612
- /**
1613
- * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
1614
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
1612
+ /**
1613
+ * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
1614
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
1615
1615
  */
1616
1616
  advance
1617
1617
  };
1618
1618
  }
1619
1619
 
1620
- /**
1621
- * Exposes an object's {@link LocalState}.
1622
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1623
- *
1624
- * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1620
+ /**
1621
+ * Exposes an object's {@link LocalState}.
1622
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1623
+ *
1624
+ * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1625
1625
  */
1626
1626
  function useInstanceHandle(ref) {
1627
1627
  const instance = React__namespace.useRef(null);
@@ -1634,18 +1634,18 @@ function useStore() {
1634
1634
  return store;
1635
1635
  }
1636
1636
 
1637
- /**
1638
- * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1639
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1637
+ /**
1638
+ * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1639
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1640
1640
  */
1641
1641
  function useThree(selector = state => state, equalityFn) {
1642
1642
  return useStore()(selector, equalityFn);
1643
1643
  }
1644
1644
 
1645
- /**
1646
- * Executes a callback before render in a shared frame loop.
1647
- * Can order effects with render priority or manually render with a positive priority.
1648
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1645
+ /**
1646
+ * Executes a callback before render in a shared frame loop.
1647
+ * Can order effects with render priority or manually render with a positive priority.
1648
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1649
1649
  */
1650
1650
  function useFrame(callback, renderPriority = 0) {
1651
1651
  const store = useStore();
@@ -1657,9 +1657,9 @@ function useFrame(callback, renderPriority = 0) {
1657
1657
  return null;
1658
1658
  }
1659
1659
 
1660
- /**
1661
- * Returns a node graph of an object with named nodes & materials.
1662
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1660
+ /**
1661
+ * Returns a node graph of an object with named nodes & materials.
1662
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1663
1663
  */
1664
1664
  function useGraph(object) {
1665
1665
  return React__namespace.useMemo(() => buildGraph(object), [object]);
@@ -1682,11 +1682,11 @@ function loadingFn(extensions, onProgress) {
1682
1682
  };
1683
1683
  }
1684
1684
 
1685
- /**
1686
- * Synchronously loads and caches assets with a three loader.
1687
- *
1688
- * Note: this hook's caller must be wrapped with `React.Suspense`
1689
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1685
+ /**
1686
+ * Synchronously loads and caches assets with a three loader.
1687
+ *
1688
+ * Note: this hook's caller must be wrapped with `React.Suspense`
1689
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1690
1690
  */
1691
1691
  function useLoader(Proto, input, extensions, onProgress) {
1692
1692
  // Use suspense to load async assets
@@ -1698,16 +1698,16 @@ function useLoader(Proto, input, extensions, onProgress) {
1698
1698
  return Array.isArray(input) ? results : results[0];
1699
1699
  }
1700
1700
 
1701
- /**
1702
- * Preloads an asset into cache as a side-effect.
1701
+ /**
1702
+ * Preloads an asset into cache as a side-effect.
1703
1703
  */
1704
1704
  useLoader.preload = function (Proto, input, extensions) {
1705
1705
  const keys = Array.isArray(input) ? input : [input];
1706
1706
  return suspendReact.preload(loadingFn(extensions), [Proto, ...keys]);
1707
1707
  };
1708
1708
 
1709
- /**
1710
- * Removes a loaded asset from cache.
1709
+ /**
1710
+ * Removes a loaded asset from cache.
1711
1711
  */
1712
1712
  useLoader.clear = function (Proto, input) {
1713
1713
  const keys = Array.isArray(input) ? input : [input];
@@ -2082,10 +2082,10 @@ function Portal({
2082
2082
  children,
2083
2083
  container
2084
2084
  }) {
2085
- /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2086
- * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2087
- * the "R3F hooks can only be used within the Canvas component!" warning:
2088
- * <Canvas>
2085
+ /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2086
+ * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2087
+ * the "R3F hooks can only be used within the Canvas component!" warning:
2088
+ * <Canvas>
2089
2089
  * {createPortal(...)} */
2090
2090
  const {
2091
2091
  events,
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-886811f8.cjs.dev.js');
5
+ var index = require('./index-d1f17345.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -251,9 +251,9 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
251
251
  }, fallback)));
252
252
  });
253
253
 
254
- /**
255
- * A DOM canvas which accepts threejs elements as children.
256
- * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
254
+ /**
255
+ * A DOM canvas which accepts threejs elements as children.
256
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
257
257
  */
258
258
  const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(props, ref) {
259
259
  return /*#__PURE__*/React__namespace.createElement(itsFine.FiberProvider, null, /*#__PURE__*/React__namespace.createElement(CanvasImpl, _extends({}, props, {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-0ed4bbca.cjs.prod.js');
5
+ var index = require('./index-ce1a9f04.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -251,9 +251,9 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
251
251
  }, fallback)));
252
252
  });
253
253
 
254
- /**
255
- * A DOM canvas which accepts threejs elements as children.
256
- * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
254
+ /**
255
+ * A DOM canvas which accepts threejs elements as children.
256
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
257
257
  */
258
258
  const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(props, ref) {
259
259
  return /*#__PURE__*/React__namespace.createElement(itsFine.FiberProvider, null, /*#__PURE__*/React__namespace.createElement(CanvasImpl, _extends({}, props, {
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-563322db.esm.js';
2
- export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-563322db.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-c4d1c86e.esm.js';
2
+ export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-c4d1c86e.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
@@ -224,9 +224,9 @@ const CanvasImpl = /*#__PURE__*/React.forwardRef(function Canvas({
224
224
  }, fallback)));
225
225
  });
226
226
 
227
- /**
228
- * A DOM canvas which accepts threejs elements as children.
229
- * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
227
+ /**
228
+ * A DOM canvas which accepts threejs elements as children.
229
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
230
230
  */
231
231
  const Canvas = /*#__PURE__*/React.forwardRef(function CanvasWrapper(props, ref) {
232
232
  return /*#__PURE__*/React.createElement(FiberProvider, null, /*#__PURE__*/React.createElement(CanvasImpl, _extends({}, props, {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-886811f8.cjs.dev.js');
5
+ var index = require('../../dist/index-d1f17345.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -10,7 +10,9 @@ var reactNative = require('react-native');
10
10
  var expoGl = require('expo-gl');
11
11
  var itsFine = require('its-fine');
12
12
  var expoAsset = require('expo-asset');
13
- var expoFileSystem = require('expo-file-system');
13
+ var fs = require('expo-file-system');
14
+ var base64Js = require('base64-js');
15
+ var buffer = require('buffer');
14
16
  require('react-reconciler/constants');
15
17
  require('zustand');
16
18
  require('react-reconciler');
@@ -37,6 +39,7 @@ function _interopNamespace(e) {
37
39
 
38
40
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
39
41
  var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
42
+ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
40
43
 
41
44
  /** Default R3F event manager for react-native */
42
45
  function createTouchEvents(store) {
@@ -120,9 +123,9 @@ function createTouchEvents(store) {
120
123
  };
121
124
  }
122
125
 
123
- /**
124
- * A native canvas which accepts threejs elements as children.
125
- * @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
126
129
  */
127
130
  const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
128
131
  children,
@@ -269,9 +272,9 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
269
272
  }));
270
273
  });
271
274
 
272
- /**
273
- * A native canvas which accepts threejs elements as children.
274
- * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
275
+ /**
276
+ * A native canvas which accepts threejs elements as children.
277
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
275
278
  */
276
279
  const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(props, ref) {
277
280
  return /*#__PURE__*/React__namespace.createElement(itsFine.FiberProvider, null, /*#__PURE__*/React__namespace.createElement(CanvasImpl, _extends({}, props, {
@@ -279,41 +282,130 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(p
279
282
  })));
280
283
  });
281
284
 
282
- async function getAsset(input) {
283
- const asset = typeof input === 'string' ? expoAsset.Asset.fromURI(input) : expoAsset.Asset.fromModule(input);
284
- await asset.downloadAsync();
285
- let localUri = asset.localUri || asset.uri;
286
-
287
- // Unpack assets in Android Release Mode
288
- if (!localUri.includes('://')) {
289
- localUri = `${expoFileSystem.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
290
- await expoFileSystem.copyAsync({
291
- from: localUri,
292
- to: localUri
285
+ function polyfills() {
286
+ function uuidv4() {
287
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
288
+ const r = Math.random() * 16 | 0,
289
+ v = c == 'x' ? r : r & 0x3 | 0x8;
290
+ return v.toString(16);
293
291
  });
294
292
  }
295
- return localUri;
296
- }
297
- function _polyfills() {
293
+
294
+ // Patch Blob for ArrayBuffer if unsupported
295
+ try {
296
+ new Blob([new ArrayBuffer(4)]);
297
+ } catch (_) {
298
+ const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
299
+ BlobManager.createFromParts = function createFromParts(parts, options) {
300
+ const blobId = uuidv4();
301
+ const items = parts.map(part => {
302
+ if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
303
+ const data = base64Js.fromByteArray(new Uint8Array(part));
304
+ return {
305
+ data,
306
+ type: 'string'
307
+ };
308
+ } else if (part instanceof Blob) {
309
+ return {
310
+ data: part.data,
311
+ type: 'blob'
312
+ };
313
+ } else {
314
+ return {
315
+ data: String(part),
316
+ type: 'string'
317
+ };
318
+ }
319
+ });
320
+ const size = items.reduce((acc, curr) => {
321
+ if (curr.type === 'string') {
322
+ return acc + global.unescape(encodeURI(curr.data)).length;
323
+ } else {
324
+ return acc + curr.data.size;
325
+ }
326
+ }, 0);
327
+ reactNative.NativeModules.BlobModule.createFromParts(items, blobId);
328
+ return BlobManager.createFromOptions({
329
+ blobId,
330
+ offset: 0,
331
+ size,
332
+ type: options ? options.type : '',
333
+ lastModified: options ? options.lastModified : Date.now()
334
+ });
335
+ };
336
+ }
337
+ async function getAsset(input) {
338
+ if (typeof input === 'string') {
339
+ // Don't process storage
340
+ if (input.startsWith('file:')) return input;
341
+
342
+ // Unpack Blobs from react-native BlobManager
343
+ if (input.startsWith('blob:')) {
344
+ const blob = await new Promise((res, rej) => {
345
+ const xhr = new XMLHttpRequest();
346
+ xhr.open('GET', input);
347
+ xhr.responseType = 'blob';
348
+ xhr.onload = () => res(xhr.response);
349
+ xhr.onerror = rej;
350
+ xhr.send();
351
+ });
352
+ const data = await new Promise((res, rej) => {
353
+ const reader = new FileReader();
354
+ reader.onload = () => res(reader.result);
355
+ reader.onerror = rej;
356
+ reader.readAsText(blob);
357
+ });
358
+ input = `data:${blob.type};base64,${data}`;
359
+ }
360
+
361
+ // Create safe URI for JSI
362
+ if (input.startsWith('data:')) {
363
+ const [header, data] = input.split(',');
364
+ const [, type] = header.split('/');
365
+ const uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
366
+ await fs__namespace.writeAsStringAsync(uri, data, {
367
+ encoding: fs__namespace.EncodingType.Base64
368
+ });
369
+ return uri;
370
+ }
371
+ }
372
+
373
+ // Download bundler module or external URL
374
+ const asset = await expoAsset.Asset.fromModule(input).downloadAsync();
375
+ let uri = asset.localUri || asset.uri;
376
+
377
+ // Unpack assets in Android Release Mode
378
+ if (!uri.includes(':')) {
379
+ const file = `${fs__namespace.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
380
+ await fs__namespace.copyAsync({
381
+ from: uri,
382
+ to: file
383
+ });
384
+ uri = file;
385
+ }
386
+ return uri;
387
+ }
388
+
298
389
  // Don't pre-process urls, let expo-asset generate an absolute URL
299
390
  const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
300
391
  THREE__namespace.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './';
301
392
 
302
393
  // There's no Image in native, so create a data texture instead
303
394
  THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
304
- if (this.path) url = this.path + url;
395
+ if (this.path && typeof url === 'string') url = this.path + url;
396
+ this.manager.itemStart(url);
305
397
  const texture = new THREE__namespace.Texture();
306
- getAsset(url).then(async localUri => {
398
+ getAsset(url).then(async uri => {
307
399
  const {
308
400
  width,
309
401
  height
310
- } = await new Promise((res, rej) => reactNative.Image.getSize(localUri, (width, height) => res({
402
+ } = await new Promise((res, rej) => reactNative.Image.getSize(uri, (width, height) => res({
311
403
  width,
312
404
  height
313
405
  }), rej));
314
406
  texture.image = {
315
407
  data: {
316
- localUri
408
+ localUri: uri
317
409
  },
318
410
  width,
319
411
  height
@@ -326,52 +418,35 @@ function _polyfills() {
326
418
  // @ts-ignore
327
419
  texture.isDataTexture = true;
328
420
  onLoad == null ? void 0 : onLoad(texture);
329
- }).catch(onError);
421
+ }).catch(error => {
422
+ onError == null ? void 0 : onError(error);
423
+ this.manager.itemError(url);
424
+ }).finally(() => {
425
+ this.manager.itemEnd(url);
426
+ });
330
427
  return texture;
331
428
  };
332
429
 
333
430
  // Fetches assets via XMLHttpRequest
334
431
  THREE__namespace.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
335
- if (this.path) url = this.path + url;
336
- const request = new XMLHttpRequest();
337
- getAsset(url).then(localUri => {
338
- request.open('GET', localUri, true);
339
- request.addEventListener('load', event => {
340
- if (request.status === 200) {
341
- onLoad == null ? void 0 : onLoad(request.response);
342
- this.manager.itemEnd(url);
343
- } else {
344
- onError == null ? void 0 : onError(event);
345
- this.manager.itemError(url);
346
- this.manager.itemEnd(url);
347
- }
348
- }, false);
349
- request.addEventListener('progress', event => {
350
- onProgress == null ? void 0 : onProgress(event);
351
- }, false);
352
- request.addEventListener('error', event => {
353
- onError == null ? void 0 : onError(event);
354
- this.manager.itemError(url);
355
- this.manager.itemEnd(url);
356
- }, false);
357
- request.addEventListener('abort', event => {
358
- onError == null ? void 0 : onError(event);
359
- this.manager.itemError(url);
360
- this.manager.itemEnd(url);
361
- }, false);
362
- if (this.responseType) request.responseType = this.responseType;
363
- if (this.withCredentials) request.withCredentials = this.withCredentials;
364
- for (const header in this.requestHeader) {
365
- request.setRequestHeader(header, this.requestHeader[header]);
366
- }
367
- request.send(null);
368
- this.manager.itemStart(url);
369
- }).catch(onError);
370
- return request;
432
+ if (this.path && typeof url === 'string') url = this.path + url;
433
+ this.manager.itemStart(url);
434
+ getAsset(url).then(async uri => {
435
+ const base64 = await fs__namespace.readAsStringAsync(uri, {
436
+ encoding: fs__namespace.EncodingType.Base64
437
+ });
438
+ const data = buffer.Buffer.from(base64, 'base64');
439
+ onLoad == null ? void 0 : onLoad(data.buffer);
440
+ }).catch(error => {
441
+ onError == null ? void 0 : onError(error);
442
+ this.manager.itemError(url);
443
+ }).finally(() => {
444
+ this.manager.itemEnd(url);
445
+ });
371
446
  };
372
447
  }
373
448
 
374
- if (reactNative.Platform.OS !== 'web') _polyfills();
449
+ if (reactNative.Platform.OS !== 'web') polyfills();
375
450
 
376
451
  exports.ReactThreeFiber = index.threeTypes;
377
452
  exports._roots = index.roots;