@react-three/fiber 8.14.1 → 8.14.2
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/declarations/src/core/hooks.d.ts +1 -1
- package/dist/{index-be1f7f7b.cjs.dev.js → index-2f978f7b.cjs.dev.js} +1 -1
- package/dist/{index-dad7ba86.cjs.prod.js → index-a401adf5.cjs.prod.js} +1 -1
- package/dist/{index-6662eaf2.esm.js → index-dc6125bc.esm.js} +1 -1
- package/dist/react-three-fiber.cjs.dev.js +1 -1
- package/dist/react-three-fiber.cjs.prod.js +1 -1
- package/dist/react-three-fiber.esm.js +2 -2
- package/native/dist/react-three-fiber-native.cjs.dev.js +36 -48
- package/native/dist/react-three-fiber-native.cjs.prod.js +36 -48
- package/native/dist/react-three-fiber-native.esm.js +37 -49
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,7 @@ import { RootState, RenderCallback } from './store';
|
|
|
6
6
|
import { ObjectMap } from './utils';
|
|
7
7
|
import { LocalState } from './renderer';
|
|
8
8
|
export interface Loader<T> extends THREE.Loader {
|
|
9
|
-
load(url: string, onLoad?: (result: T) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event:
|
|
9
|
+
load(url: string, onLoad?: (result: T) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: unknown) => void): unknown;
|
|
10
10
|
loadAsync(url: string, onProgress?: (event: ProgressEvent) => void): Promise<T>;
|
|
11
11
|
}
|
|
12
12
|
export declare type LoaderProto<T> = new (...args: any) => Loader<T extends unknown ? any : T>;
|
|
@@ -1672,7 +1672,7 @@ function loadingFn(extensions, onProgress) {
|
|
|
1672
1672
|
return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
|
|
1673
1673
|
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
1674
1674
|
res(data);
|
|
1675
|
-
}, onProgress, error => reject(new Error(`Could not load ${input}: ${error.message}`)))))).finally(() => loader.dispose == null ? void 0 : loader.dispose());
|
|
1675
|
+
}, onProgress, error => reject(new Error(`Could not load ${input}: ${error == null ? void 0 : error.message}`)))))).finally(() => loader.dispose == null ? void 0 : loader.dispose());
|
|
1676
1676
|
};
|
|
1677
1677
|
}
|
|
1678
1678
|
|
|
@@ -1672,7 +1672,7 @@ function loadingFn(extensions, onProgress) {
|
|
|
1672
1672
|
return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
|
|
1673
1673
|
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
1674
1674
|
res(data);
|
|
1675
|
-
}, onProgress, error => reject(new Error(`Could not load ${input}: ${error.message}`)))))).finally(() => loader.dispose == null ? void 0 : loader.dispose());
|
|
1675
|
+
}, onProgress, error => reject(new Error(`Could not load ${input}: ${error == null ? void 0 : error.message}`)))))).finally(() => loader.dispose == null ? void 0 : loader.dispose());
|
|
1676
1676
|
};
|
|
1677
1677
|
}
|
|
1678
1678
|
|
|
@@ -1645,7 +1645,7 @@ function loadingFn(extensions, onProgress) {
|
|
|
1645
1645
|
return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
|
|
1646
1646
|
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
1647
1647
|
res(data);
|
|
1648
|
-
}, onProgress, error => reject(new Error(`Could not load ${input}: ${error.message}`)))))).finally(() => loader.dispose == null ? void 0 : loader.dispose());
|
|
1648
|
+
}, onProgress, error => reject(new Error(`Could not load ${input}: ${error == null ? void 0 : error.message}`)))))).finally(() => loader.dispose == null ? void 0 : loader.dispose());
|
|
1649
1649
|
};
|
|
1650
1650
|
}
|
|
1651
1651
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-2f978f7b.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-a401adf5.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -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-
|
|
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-
|
|
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-dc6125bc.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-dc6125bc.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';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../dist/index-
|
|
5
|
+
var index = require('../../dist/index-2f978f7b.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -265,6 +265,7 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
265
265
|
...style
|
|
266
266
|
}
|
|
267
267
|
}, bind), width > 0 && /*#__PURE__*/React__namespace.createElement(expoGl.GLView, {
|
|
268
|
+
msaaSamples: 0,
|
|
268
269
|
onContextCreate: onContextCreate,
|
|
269
270
|
style: reactNative.StyleSheet.absoluteFill
|
|
270
271
|
}));
|
|
@@ -305,10 +306,8 @@ function polyfills() {
|
|
|
305
306
|
}
|
|
306
307
|
async function getAsset(input) {
|
|
307
308
|
if (typeof input === 'string') {
|
|
308
|
-
//
|
|
309
|
-
if (input.startsWith('file:')) return
|
|
310
|
-
localUri: input
|
|
311
|
-
};
|
|
309
|
+
// Don't process storage or data uris
|
|
310
|
+
if (input.startsWith('file:') || input.startsWith('data:')) return input;
|
|
312
311
|
|
|
313
312
|
// Unpack Blobs from react-native BlobManager
|
|
314
313
|
if (input.startsWith('blob:')) {
|
|
@@ -326,40 +325,27 @@ function polyfills() {
|
|
|
326
325
|
reader.onerror = rej;
|
|
327
326
|
reader.readAsText(blob);
|
|
328
327
|
});
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Create safe URI for JSI
|
|
333
|
-
if (input.startsWith('data:')) {
|
|
334
|
-
const [header, data] = input.split(',');
|
|
335
|
-
const [, type] = header.split('/');
|
|
336
|
-
const localUri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
|
|
337
|
-
await fs__namespace.writeAsStringAsync(localUri, data, {
|
|
338
|
-
encoding: fs__namespace.EncodingType.Base64
|
|
339
|
-
});
|
|
340
|
-
return {
|
|
341
|
-
localUri
|
|
342
|
-
};
|
|
328
|
+
return `data:${blob.type};base64,${data}`;
|
|
343
329
|
}
|
|
344
330
|
}
|
|
345
331
|
|
|
346
332
|
// Download bundler module or external URL
|
|
347
|
-
const asset = expoAsset.Asset.fromModule(input);
|
|
333
|
+
const asset = await expoAsset.Asset.fromModule(input).downloadAsync();
|
|
334
|
+
let uri = asset.localUri || asset.uri;
|
|
348
335
|
|
|
349
336
|
// Unpack assets in Android Release Mode
|
|
350
|
-
if (!
|
|
351
|
-
const
|
|
352
|
-
await fs__namespace.
|
|
353
|
-
|
|
354
|
-
to: localUri
|
|
337
|
+
if (!uri.includes(':')) {
|
|
338
|
+
const file = `${fs__namespace.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
339
|
+
const stats = await fs__namespace.getInfoAsync(file, {
|
|
340
|
+
size: false
|
|
355
341
|
});
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
342
|
+
if (!stats.exists) await fs__namespace.copyAsync({
|
|
343
|
+
from: uri,
|
|
344
|
+
to: file
|
|
345
|
+
});
|
|
346
|
+
uri = file;
|
|
359
347
|
}
|
|
360
|
-
|
|
361
|
-
// Otherwise, resolve from registry
|
|
362
|
-
return asset.downloadAsync();
|
|
348
|
+
return uri;
|
|
363
349
|
}
|
|
364
350
|
|
|
365
351
|
// Don't pre-process urls, let expo-asset generate an absolute URL
|
|
@@ -370,25 +356,29 @@ function polyfills() {
|
|
|
370
356
|
THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
371
357
|
if (this.path) url = this.path + url;
|
|
372
358
|
const texture = new THREE__namespace.Texture();
|
|
373
|
-
getAsset(url).then(async
|
|
374
|
-
|
|
375
|
-
if (
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}), rej));
|
|
383
|
-
asset.width = width;
|
|
384
|
-
asset.height = height;
|
|
359
|
+
getAsset(url).then(async uri => {
|
|
360
|
+
// Create safe URI for JSI
|
|
361
|
+
if (uri.startsWith('data:')) {
|
|
362
|
+
const [header, data] = uri.split(',');
|
|
363
|
+
const [, type] = header.split('/');
|
|
364
|
+
uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
|
|
365
|
+
await fs__namespace.writeAsStringAsync(uri, data, {
|
|
366
|
+
encoding: fs__namespace.EncodingType.Base64
|
|
367
|
+
});
|
|
385
368
|
}
|
|
369
|
+
const {
|
|
370
|
+
width,
|
|
371
|
+
height
|
|
372
|
+
} = await new Promise((res, rej) => reactNative.Image.getSize(uri, (width, height) => res({
|
|
373
|
+
width,
|
|
374
|
+
height
|
|
375
|
+
}), rej));
|
|
386
376
|
texture.image = {
|
|
387
377
|
data: {
|
|
388
378
|
localUri: uri
|
|
389
379
|
},
|
|
390
|
-
width
|
|
391
|
-
height
|
|
380
|
+
width,
|
|
381
|
+
height
|
|
392
382
|
};
|
|
393
383
|
texture.flipY = true;
|
|
394
384
|
texture.unpackAlignment = 1;
|
|
@@ -406,9 +396,7 @@ function polyfills() {
|
|
|
406
396
|
THREE__namespace.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
407
397
|
if (this.path) url = this.path + url;
|
|
408
398
|
const request = new XMLHttpRequest();
|
|
409
|
-
getAsset(url).then(async
|
|
410
|
-
let uri = asset.localUri || asset.uri;
|
|
411
|
-
|
|
399
|
+
getAsset(url).then(async uri => {
|
|
412
400
|
// Make FS paths web-safe
|
|
413
401
|
if (uri.startsWith('file://')) {
|
|
414
402
|
const data = await fs__namespace.readAsStringAsync(uri, {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../dist/index-
|
|
5
|
+
var index = require('../../dist/index-a401adf5.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -265,6 +265,7 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
265
265
|
...style
|
|
266
266
|
}
|
|
267
267
|
}, bind), width > 0 && /*#__PURE__*/React__namespace.createElement(expoGl.GLView, {
|
|
268
|
+
msaaSamples: 0,
|
|
268
269
|
onContextCreate: onContextCreate,
|
|
269
270
|
style: reactNative.StyleSheet.absoluteFill
|
|
270
271
|
}));
|
|
@@ -305,10 +306,8 @@ function polyfills() {
|
|
|
305
306
|
}
|
|
306
307
|
async function getAsset(input) {
|
|
307
308
|
if (typeof input === 'string') {
|
|
308
|
-
//
|
|
309
|
-
if (input.startsWith('file:')) return
|
|
310
|
-
localUri: input
|
|
311
|
-
};
|
|
309
|
+
// Don't process storage or data uris
|
|
310
|
+
if (input.startsWith('file:') || input.startsWith('data:')) return input;
|
|
312
311
|
|
|
313
312
|
// Unpack Blobs from react-native BlobManager
|
|
314
313
|
if (input.startsWith('blob:')) {
|
|
@@ -326,40 +325,27 @@ function polyfills() {
|
|
|
326
325
|
reader.onerror = rej;
|
|
327
326
|
reader.readAsText(blob);
|
|
328
327
|
});
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Create safe URI for JSI
|
|
333
|
-
if (input.startsWith('data:')) {
|
|
334
|
-
const [header, data] = input.split(',');
|
|
335
|
-
const [, type] = header.split('/');
|
|
336
|
-
const localUri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
|
|
337
|
-
await fs__namespace.writeAsStringAsync(localUri, data, {
|
|
338
|
-
encoding: fs__namespace.EncodingType.Base64
|
|
339
|
-
});
|
|
340
|
-
return {
|
|
341
|
-
localUri
|
|
342
|
-
};
|
|
328
|
+
return `data:${blob.type};base64,${data}`;
|
|
343
329
|
}
|
|
344
330
|
}
|
|
345
331
|
|
|
346
332
|
// Download bundler module or external URL
|
|
347
|
-
const asset = expoAsset.Asset.fromModule(input);
|
|
333
|
+
const asset = await expoAsset.Asset.fromModule(input).downloadAsync();
|
|
334
|
+
let uri = asset.localUri || asset.uri;
|
|
348
335
|
|
|
349
336
|
// Unpack assets in Android Release Mode
|
|
350
|
-
if (!
|
|
351
|
-
const
|
|
352
|
-
await fs__namespace.
|
|
353
|
-
|
|
354
|
-
to: localUri
|
|
337
|
+
if (!uri.includes(':')) {
|
|
338
|
+
const file = `${fs__namespace.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
339
|
+
const stats = await fs__namespace.getInfoAsync(file, {
|
|
340
|
+
size: false
|
|
355
341
|
});
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
342
|
+
if (!stats.exists) await fs__namespace.copyAsync({
|
|
343
|
+
from: uri,
|
|
344
|
+
to: file
|
|
345
|
+
});
|
|
346
|
+
uri = file;
|
|
359
347
|
}
|
|
360
|
-
|
|
361
|
-
// Otherwise, resolve from registry
|
|
362
|
-
return asset.downloadAsync();
|
|
348
|
+
return uri;
|
|
363
349
|
}
|
|
364
350
|
|
|
365
351
|
// Don't pre-process urls, let expo-asset generate an absolute URL
|
|
@@ -370,25 +356,29 @@ function polyfills() {
|
|
|
370
356
|
THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
371
357
|
if (this.path) url = this.path + url;
|
|
372
358
|
const texture = new THREE__namespace.Texture();
|
|
373
|
-
getAsset(url).then(async
|
|
374
|
-
|
|
375
|
-
if (
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}), rej));
|
|
383
|
-
asset.width = width;
|
|
384
|
-
asset.height = height;
|
|
359
|
+
getAsset(url).then(async uri => {
|
|
360
|
+
// Create safe URI for JSI
|
|
361
|
+
if (uri.startsWith('data:')) {
|
|
362
|
+
const [header, data] = uri.split(',');
|
|
363
|
+
const [, type] = header.split('/');
|
|
364
|
+
uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
|
|
365
|
+
await fs__namespace.writeAsStringAsync(uri, data, {
|
|
366
|
+
encoding: fs__namespace.EncodingType.Base64
|
|
367
|
+
});
|
|
385
368
|
}
|
|
369
|
+
const {
|
|
370
|
+
width,
|
|
371
|
+
height
|
|
372
|
+
} = await new Promise((res, rej) => reactNative.Image.getSize(uri, (width, height) => res({
|
|
373
|
+
width,
|
|
374
|
+
height
|
|
375
|
+
}), rej));
|
|
386
376
|
texture.image = {
|
|
387
377
|
data: {
|
|
388
378
|
localUri: uri
|
|
389
379
|
},
|
|
390
|
-
width
|
|
391
|
-
height
|
|
380
|
+
width,
|
|
381
|
+
height
|
|
392
382
|
};
|
|
393
383
|
texture.flipY = true;
|
|
394
384
|
texture.unpackAlignment = 1;
|
|
@@ -406,9 +396,7 @@ function polyfills() {
|
|
|
406
396
|
THREE__namespace.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
407
397
|
if (this.path) url = this.path + url;
|
|
408
398
|
const request = new XMLHttpRequest();
|
|
409
|
-
getAsset(url).then(async
|
|
410
|
-
let uri = asset.localUri || asset.uri;
|
|
411
|
-
|
|
399
|
+
getAsset(url).then(async uri => {
|
|
412
400
|
// Make FS paths web-safe
|
|
413
401
|
if (uri.startsWith('file://')) {
|
|
414
402
|
const data = await fs__namespace.readAsStringAsync(uri, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-
|
|
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 '../../dist/index-
|
|
1
|
+
import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-dc6125bc.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 '../../dist/index-dc6125bc.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';
|
|
@@ -240,6 +240,7 @@ const CanvasImpl = /*#__PURE__*/React.forwardRef(({
|
|
|
240
240
|
...style
|
|
241
241
|
}
|
|
242
242
|
}, bind), width > 0 && /*#__PURE__*/React.createElement(GLView, {
|
|
243
|
+
msaaSamples: 0,
|
|
243
244
|
onContextCreate: onContextCreate,
|
|
244
245
|
style: StyleSheet.absoluteFill
|
|
245
246
|
}));
|
|
@@ -280,10 +281,8 @@ function polyfills() {
|
|
|
280
281
|
}
|
|
281
282
|
async function getAsset(input) {
|
|
282
283
|
if (typeof input === 'string') {
|
|
283
|
-
//
|
|
284
|
-
if (input.startsWith('file:')) return
|
|
285
|
-
localUri: input
|
|
286
|
-
};
|
|
284
|
+
// Don't process storage or data uris
|
|
285
|
+
if (input.startsWith('file:') || input.startsWith('data:')) return input;
|
|
287
286
|
|
|
288
287
|
// Unpack Blobs from react-native BlobManager
|
|
289
288
|
if (input.startsWith('blob:')) {
|
|
@@ -301,40 +300,27 @@ function polyfills() {
|
|
|
301
300
|
reader.onerror = rej;
|
|
302
301
|
reader.readAsText(blob);
|
|
303
302
|
});
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// Create safe URI for JSI
|
|
308
|
-
if (input.startsWith('data:')) {
|
|
309
|
-
const [header, data] = input.split(',');
|
|
310
|
-
const [, type] = header.split('/');
|
|
311
|
-
const localUri = fs.cacheDirectory + uuidv4() + `.${type}`;
|
|
312
|
-
await fs.writeAsStringAsync(localUri, data, {
|
|
313
|
-
encoding: fs.EncodingType.Base64
|
|
314
|
-
});
|
|
315
|
-
return {
|
|
316
|
-
localUri
|
|
317
|
-
};
|
|
303
|
+
return `data:${blob.type};base64,${data}`;
|
|
318
304
|
}
|
|
319
305
|
}
|
|
320
306
|
|
|
321
307
|
// Download bundler module or external URL
|
|
322
|
-
const asset = Asset.fromModule(input);
|
|
308
|
+
const asset = await Asset.fromModule(input).downloadAsync();
|
|
309
|
+
let uri = asset.localUri || asset.uri;
|
|
323
310
|
|
|
324
311
|
// Unpack assets in Android Release Mode
|
|
325
|
-
if (!
|
|
326
|
-
const
|
|
327
|
-
await fs.
|
|
328
|
-
|
|
329
|
-
to: localUri
|
|
312
|
+
if (!uri.includes(':')) {
|
|
313
|
+
const file = `${fs.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
314
|
+
const stats = await fs.getInfoAsync(file, {
|
|
315
|
+
size: false
|
|
330
316
|
});
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
317
|
+
if (!stats.exists) await fs.copyAsync({
|
|
318
|
+
from: uri,
|
|
319
|
+
to: file
|
|
320
|
+
});
|
|
321
|
+
uri = file;
|
|
334
322
|
}
|
|
335
|
-
|
|
336
|
-
// Otherwise, resolve from registry
|
|
337
|
-
return asset.downloadAsync();
|
|
323
|
+
return uri;
|
|
338
324
|
}
|
|
339
325
|
|
|
340
326
|
// Don't pre-process urls, let expo-asset generate an absolute URL
|
|
@@ -345,25 +331,29 @@ function polyfills() {
|
|
|
345
331
|
THREE.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
346
332
|
if (this.path) url = this.path + url;
|
|
347
333
|
const texture = new THREE.Texture();
|
|
348
|
-
getAsset(url).then(async
|
|
349
|
-
|
|
350
|
-
if (
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}), rej));
|
|
358
|
-
asset.width = width;
|
|
359
|
-
asset.height = height;
|
|
334
|
+
getAsset(url).then(async uri => {
|
|
335
|
+
// Create safe URI for JSI
|
|
336
|
+
if (uri.startsWith('data:')) {
|
|
337
|
+
const [header, data] = uri.split(',');
|
|
338
|
+
const [, type] = header.split('/');
|
|
339
|
+
uri = fs.cacheDirectory + uuidv4() + `.${type}`;
|
|
340
|
+
await fs.writeAsStringAsync(uri, data, {
|
|
341
|
+
encoding: fs.EncodingType.Base64
|
|
342
|
+
});
|
|
360
343
|
}
|
|
344
|
+
const {
|
|
345
|
+
width,
|
|
346
|
+
height
|
|
347
|
+
} = await new Promise((res, rej) => Image.getSize(uri, (width, height) => res({
|
|
348
|
+
width,
|
|
349
|
+
height
|
|
350
|
+
}), rej));
|
|
361
351
|
texture.image = {
|
|
362
352
|
data: {
|
|
363
353
|
localUri: uri
|
|
364
354
|
},
|
|
365
|
-
width
|
|
366
|
-
height
|
|
355
|
+
width,
|
|
356
|
+
height
|
|
367
357
|
};
|
|
368
358
|
texture.flipY = true;
|
|
369
359
|
texture.unpackAlignment = 1;
|
|
@@ -381,9 +371,7 @@ function polyfills() {
|
|
|
381
371
|
THREE.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
382
372
|
if (this.path) url = this.path + url;
|
|
383
373
|
const request = new XMLHttpRequest();
|
|
384
|
-
getAsset(url).then(async
|
|
385
|
-
let uri = asset.localUri || asset.uri;
|
|
386
|
-
|
|
374
|
+
getAsset(url).then(async uri => {
|
|
387
375
|
// Make FS paths web-safe
|
|
388
376
|
if (uri.startsWith('file://')) {
|
|
389
377
|
const data = await fs.readAsStringAsync(uri, {
|