@react-three/fiber 8.14.6 → 8.15.0
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 +835 -823
- package/dist/declarations/src/core/index.d.ts +2 -2
- package/dist/declarations/src/native/polyfills.d.ts +1 -1
- package/dist/{index-886811f8.cjs.dev.js → index-34a45f4c.cjs.dev.js} +77 -74
- package/dist/{index-563322db.esm.js → index-5918012a.esm.js} +77 -75
- package/dist/{index-0ed4bbca.cjs.prod.js → index-f4d4539a.cjs.prod.js} +77 -74
- package/dist/react-three-fiber.cjs.dev.js +5 -4
- package/dist/react-three-fiber.cjs.prod.js +5 -4
- package/dist/react-three-fiber.esm.js +5 -5
- package/native/dist/react-three-fiber-native.cjs.dev.js +140 -64
- package/native/dist/react-three-fiber-native.cjs.prod.js +140 -64
- package/native/dist/react-three-fiber-native.esm.js +140 -66
- package/native/package.json +5 -5
- package/package.json +2 -1
- package/readme.md +253 -253
- package/yarn-error.log +10628 -0
|
@@ -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-f4d4539a.cjs.prod.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
|
|
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
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
|
398
|
+
getAsset(url).then(async uri => {
|
|
307
399
|
const {
|
|
308
400
|
width,
|
|
309
401
|
height
|
|
310
|
-
} = await new Promise((res, rej) => reactNative.Image.getSize(
|
|
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(
|
|
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
|
-
|
|
337
|
-
getAsset(url).then(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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')
|
|
449
|
+
if (reactNative.Platform.OS !== 'web') polyfills();
|
|
375
450
|
|
|
376
451
|
exports.ReactThreeFiber = index.threeTypes;
|
|
377
452
|
exports._roots = index.roots;
|
|
@@ -381,6 +456,7 @@ exports.addEffect = index.addEffect;
|
|
|
381
456
|
exports.addTail = index.addTail;
|
|
382
457
|
exports.advance = index.advance;
|
|
383
458
|
exports.applyProps = index.applyProps;
|
|
459
|
+
exports.buildGraph = index.buildGraph;
|
|
384
460
|
exports.context = index.context;
|
|
385
461
|
exports.createEvents = index.createEvents;
|
|
386
462
|
exports.createPortal = index.createPortal;
|
|
@@ -1,13 +1,15 @@
|
|
|
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,
|
|
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-5918012a.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, x as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, w as buildGraph, 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, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from '../../dist/index-5918012a.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';
|
|
6
|
-
import { PanResponder, PixelRatio, View, StyleSheet, Image, Platform } from 'react-native';
|
|
6
|
+
import { PanResponder, PixelRatio, View, StyleSheet, NativeModules, Image, Platform } from 'react-native';
|
|
7
7
|
import { GLView } from 'expo-gl';
|
|
8
8
|
import { FiberProvider, useContextBridge } from 'its-fine';
|
|
9
9
|
import { Asset } from 'expo-asset';
|
|
10
|
-
import
|
|
10
|
+
import * as fs from 'expo-file-system';
|
|
11
|
+
import { fromByteArray } from 'base64-js';
|
|
12
|
+
import { Buffer } from 'buffer';
|
|
11
13
|
import 'react-reconciler/constants';
|
|
12
14
|
import 'zustand';
|
|
13
15
|
import 'react-reconciler';
|
|
@@ -96,9 +98,9 @@ function createTouchEvents(store) {
|
|
|
96
98
|
};
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
/**
|
|
100
|
-
* A native canvas which accepts threejs elements as children.
|
|
101
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
101
|
+
/**
|
|
102
|
+
* A native canvas which accepts threejs elements as children.
|
|
103
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
102
104
|
*/
|
|
103
105
|
const CanvasImpl = /*#__PURE__*/React.forwardRef(({
|
|
104
106
|
children,
|
|
@@ -245,9 +247,9 @@ const CanvasImpl = /*#__PURE__*/React.forwardRef(({
|
|
|
245
247
|
}));
|
|
246
248
|
});
|
|
247
249
|
|
|
248
|
-
/**
|
|
249
|
-
* A native canvas which accepts threejs elements as children.
|
|
250
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
250
|
+
/**
|
|
251
|
+
* A native canvas which accepts threejs elements as children.
|
|
252
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
251
253
|
*/
|
|
252
254
|
const Canvas = /*#__PURE__*/React.forwardRef(function CanvasWrapper(props, ref) {
|
|
253
255
|
return /*#__PURE__*/React.createElement(FiberProvider, null, /*#__PURE__*/React.createElement(CanvasImpl, _extends({}, props, {
|
|
@@ -255,41 +257,130 @@ const Canvas = /*#__PURE__*/React.forwardRef(function CanvasWrapper(props, ref)
|
|
|
255
257
|
})));
|
|
256
258
|
});
|
|
257
259
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (!localUri.includes('://')) {
|
|
265
|
-
localUri = `${cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
266
|
-
await copyAsync({
|
|
267
|
-
from: localUri,
|
|
268
|
-
to: localUri
|
|
260
|
+
function polyfills() {
|
|
261
|
+
function uuidv4() {
|
|
262
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
263
|
+
const r = Math.random() * 16 | 0,
|
|
264
|
+
v = c == 'x' ? r : r & 0x3 | 0x8;
|
|
265
|
+
return v.toString(16);
|
|
269
266
|
});
|
|
270
267
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
268
|
+
|
|
269
|
+
// Patch Blob for ArrayBuffer if unsupported
|
|
270
|
+
try {
|
|
271
|
+
new Blob([new ArrayBuffer(4)]);
|
|
272
|
+
} catch (_) {
|
|
273
|
+
const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
|
|
274
|
+
BlobManager.createFromParts = function createFromParts(parts, options) {
|
|
275
|
+
const blobId = uuidv4();
|
|
276
|
+
const items = parts.map(part => {
|
|
277
|
+
if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
|
|
278
|
+
const data = fromByteArray(new Uint8Array(part));
|
|
279
|
+
return {
|
|
280
|
+
data,
|
|
281
|
+
type: 'string'
|
|
282
|
+
};
|
|
283
|
+
} else if (part instanceof Blob) {
|
|
284
|
+
return {
|
|
285
|
+
data: part.data,
|
|
286
|
+
type: 'blob'
|
|
287
|
+
};
|
|
288
|
+
} else {
|
|
289
|
+
return {
|
|
290
|
+
data: String(part),
|
|
291
|
+
type: 'string'
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
const size = items.reduce((acc, curr) => {
|
|
296
|
+
if (curr.type === 'string') {
|
|
297
|
+
return acc + global.unescape(encodeURI(curr.data)).length;
|
|
298
|
+
} else {
|
|
299
|
+
return acc + curr.data.size;
|
|
300
|
+
}
|
|
301
|
+
}, 0);
|
|
302
|
+
NativeModules.BlobModule.createFromParts(items, blobId);
|
|
303
|
+
return BlobManager.createFromOptions({
|
|
304
|
+
blobId,
|
|
305
|
+
offset: 0,
|
|
306
|
+
size,
|
|
307
|
+
type: options ? options.type : '',
|
|
308
|
+
lastModified: options ? options.lastModified : Date.now()
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
async function getAsset(input) {
|
|
313
|
+
if (typeof input === 'string') {
|
|
314
|
+
// Don't process storage
|
|
315
|
+
if (input.startsWith('file:')) return input;
|
|
316
|
+
|
|
317
|
+
// Unpack Blobs from react-native BlobManager
|
|
318
|
+
if (input.startsWith('blob:')) {
|
|
319
|
+
const blob = await new Promise((res, rej) => {
|
|
320
|
+
const xhr = new XMLHttpRequest();
|
|
321
|
+
xhr.open('GET', input);
|
|
322
|
+
xhr.responseType = 'blob';
|
|
323
|
+
xhr.onload = () => res(xhr.response);
|
|
324
|
+
xhr.onerror = rej;
|
|
325
|
+
xhr.send();
|
|
326
|
+
});
|
|
327
|
+
const data = await new Promise((res, rej) => {
|
|
328
|
+
const reader = new FileReader();
|
|
329
|
+
reader.onload = () => res(reader.result);
|
|
330
|
+
reader.onerror = rej;
|
|
331
|
+
reader.readAsText(blob);
|
|
332
|
+
});
|
|
333
|
+
input = `data:${blob.type};base64,${data}`;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Create safe URI for JSI
|
|
337
|
+
if (input.startsWith('data:')) {
|
|
338
|
+
const [header, data] = input.split(',');
|
|
339
|
+
const [, type] = header.split('/');
|
|
340
|
+
const uri = fs.cacheDirectory + uuidv4() + `.${type}`;
|
|
341
|
+
await fs.writeAsStringAsync(uri, data, {
|
|
342
|
+
encoding: fs.EncodingType.Base64
|
|
343
|
+
});
|
|
344
|
+
return uri;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Download bundler module or external URL
|
|
349
|
+
const asset = await Asset.fromModule(input).downloadAsync();
|
|
350
|
+
let uri = asset.localUri || asset.uri;
|
|
351
|
+
|
|
352
|
+
// Unpack assets in Android Release Mode
|
|
353
|
+
if (!uri.includes(':')) {
|
|
354
|
+
const file = `${fs.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
355
|
+
await fs.copyAsync({
|
|
356
|
+
from: uri,
|
|
357
|
+
to: file
|
|
358
|
+
});
|
|
359
|
+
uri = file;
|
|
360
|
+
}
|
|
361
|
+
return uri;
|
|
362
|
+
}
|
|
363
|
+
|
|
274
364
|
// Don't pre-process urls, let expo-asset generate an absolute URL
|
|
275
365
|
const extractUrlBase = THREE.LoaderUtils.extractUrlBase.bind(THREE.LoaderUtils);
|
|
276
366
|
THREE.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './';
|
|
277
367
|
|
|
278
368
|
// There's no Image in native, so create a data texture instead
|
|
279
369
|
THREE.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
280
|
-
if (this.path) url = this.path + url;
|
|
370
|
+
if (this.path && typeof url === 'string') url = this.path + url;
|
|
371
|
+
this.manager.itemStart(url);
|
|
281
372
|
const texture = new THREE.Texture();
|
|
282
|
-
getAsset(url).then(async
|
|
373
|
+
getAsset(url).then(async uri => {
|
|
283
374
|
const {
|
|
284
375
|
width,
|
|
285
376
|
height
|
|
286
|
-
} = await new Promise((res, rej) => Image.getSize(
|
|
377
|
+
} = await new Promise((res, rej) => Image.getSize(uri, (width, height) => res({
|
|
287
378
|
width,
|
|
288
379
|
height
|
|
289
380
|
}), rej));
|
|
290
381
|
texture.image = {
|
|
291
382
|
data: {
|
|
292
|
-
localUri
|
|
383
|
+
localUri: uri
|
|
293
384
|
},
|
|
294
385
|
width,
|
|
295
386
|
height
|
|
@@ -302,51 +393,34 @@ function _polyfills() {
|
|
|
302
393
|
// @ts-ignore
|
|
303
394
|
texture.isDataTexture = true;
|
|
304
395
|
onLoad == null ? void 0 : onLoad(texture);
|
|
305
|
-
}).catch(
|
|
396
|
+
}).catch(error => {
|
|
397
|
+
onError == null ? void 0 : onError(error);
|
|
398
|
+
this.manager.itemError(url);
|
|
399
|
+
}).finally(() => {
|
|
400
|
+
this.manager.itemEnd(url);
|
|
401
|
+
});
|
|
306
402
|
return texture;
|
|
307
403
|
};
|
|
308
404
|
|
|
309
405
|
// Fetches assets via XMLHttpRequest
|
|
310
406
|
THREE.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
311
|
-
if (this.path) url = this.path + url;
|
|
312
|
-
|
|
313
|
-
getAsset(url).then(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
request.addEventListener('progress', event => {
|
|
326
|
-
onProgress == null ? void 0 : onProgress(event);
|
|
327
|
-
}, false);
|
|
328
|
-
request.addEventListener('error', event => {
|
|
329
|
-
onError == null ? void 0 : onError(event);
|
|
330
|
-
this.manager.itemError(url);
|
|
331
|
-
this.manager.itemEnd(url);
|
|
332
|
-
}, false);
|
|
333
|
-
request.addEventListener('abort', event => {
|
|
334
|
-
onError == null ? void 0 : onError(event);
|
|
335
|
-
this.manager.itemError(url);
|
|
336
|
-
this.manager.itemEnd(url);
|
|
337
|
-
}, false);
|
|
338
|
-
if (this.responseType) request.responseType = this.responseType;
|
|
339
|
-
if (this.withCredentials) request.withCredentials = this.withCredentials;
|
|
340
|
-
for (const header in this.requestHeader) {
|
|
341
|
-
request.setRequestHeader(header, this.requestHeader[header]);
|
|
342
|
-
}
|
|
343
|
-
request.send(null);
|
|
344
|
-
this.manager.itemStart(url);
|
|
345
|
-
}).catch(onError);
|
|
346
|
-
return request;
|
|
407
|
+
if (this.path && typeof url === 'string') url = this.path + url;
|
|
408
|
+
this.manager.itemStart(url);
|
|
409
|
+
getAsset(url).then(async uri => {
|
|
410
|
+
const base64 = await fs.readAsStringAsync(uri, {
|
|
411
|
+
encoding: fs.EncodingType.Base64
|
|
412
|
+
});
|
|
413
|
+
const data = Buffer.from(base64, 'base64');
|
|
414
|
+
onLoad == null ? void 0 : onLoad(data.buffer);
|
|
415
|
+
}).catch(error => {
|
|
416
|
+
onError == null ? void 0 : onError(error);
|
|
417
|
+
this.manager.itemError(url);
|
|
418
|
+
}).finally(() => {
|
|
419
|
+
this.manager.itemEnd(url);
|
|
420
|
+
});
|
|
347
421
|
};
|
|
348
422
|
}
|
|
349
423
|
|
|
350
|
-
if (Platform.OS !== 'web')
|
|
424
|
+
if (Platform.OS !== 'web') polyfills();
|
|
351
425
|
|
|
352
426
|
export { Canvas, createTouchEvents as events };
|
package/native/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
{
|
|
2
|
-
"main": "dist/react-three-fiber-native.cjs.js",
|
|
3
|
-
"module": "dist/react-three-fiber-native.esm.js",
|
|
4
|
-
"types": "dist/react-three-fiber-native.cjs.d.ts"
|
|
5
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"main": "dist/react-three-fiber-native.cjs.js",
|
|
3
|
+
"module": "dist/react-three-fiber-native.esm.js",
|
|
4
|
+
"types": "dist/react-three-fiber-native.cjs.d.ts"
|
|
5
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-three/fiber",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.15.0",
|
|
4
4
|
"description": "A React renderer for Threejs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"@babel/runtime": "^7.17.8",
|
|
46
46
|
"@types/react-reconciler": "^0.26.7",
|
|
47
47
|
"base64-js": "^1.5.1",
|
|
48
|
+
"buffer": "^6.0.3",
|
|
48
49
|
"its-fine": "^1.0.6",
|
|
49
50
|
"react-reconciler": "^0.27.0",
|
|
50
51
|
"react-use-measure": "^2.1.1",
|