@react-three/fiber 8.0.0-beta-04 → 8.0.0-beta-05
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 +12 -0
- package/dist/declarations/src/core/index.d.ts +2 -1
- package/dist/declarations/src/core/loop.d.ts +2 -1
- package/dist/declarations/src/core/store.d.ts +4 -2
- package/dist/declarations/src/index.d.ts +0 -1
- package/dist/declarations/src/native.d.ts +0 -1
- package/dist/declarations/src/three-types.d.ts +7 -8
- package/dist/{index-fccd77b0.esm.js → index-3f4e5f46.esm.js} +79 -78
- package/dist/{index-ff3eb68b.cjs.dev.js → index-95c17855.cjs.dev.js} +78 -79
- package/dist/{index-eb414398.cjs.prod.js → index-ff8b5912.cjs.prod.js} +78 -79
- 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 +91 -121
- package/native/dist/react-three-fiber-native.cjs.prod.js +91 -121
- package/native/dist/react-three-fiber-native.esm.js +92 -122
- package/package.json +14 -7
- package/dist/declarations/src/native/hooks.d.ts +0 -9
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../dist/index-eb414398.cjs.prod.js');
|
|
6
5
|
var THREE = require('three');
|
|
7
6
|
var expoAsset = require('expo-asset');
|
|
8
|
-
var
|
|
9
|
-
var base64Arraybuffer = require('base64-arraybuffer');
|
|
10
|
-
var suspendReact = require('suspend-react');
|
|
7
|
+
var index = require('../../dist/index-ff8b5912.cjs.prod.js');
|
|
11
8
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
12
9
|
var React = require('react');
|
|
13
10
|
var reactNative = require('react-native');
|
|
14
11
|
var expoGl = require('expo-gl');
|
|
15
12
|
var Pressability = require('react-native/Libraries/Pressability/Pressability');
|
|
13
|
+
require('suspend-react');
|
|
16
14
|
require('react-reconciler/constants');
|
|
17
15
|
require('zustand');
|
|
18
16
|
require('react-reconciler');
|
|
@@ -44,116 +42,6 @@ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
|
44
42
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
45
43
|
var Pressability__default = /*#__PURE__*/_interopDefault(Pressability);
|
|
46
44
|
|
|
47
|
-
/**
|
|
48
|
-
* Generates an asset based on input type.
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
const getAsset = input => {
|
|
52
|
-
if (input instanceof expoAsset.Asset) return input;
|
|
53
|
-
|
|
54
|
-
switch (typeof input) {
|
|
55
|
-
case 'string':
|
|
56
|
-
return expoAsset.Asset.fromURI(input);
|
|
57
|
-
|
|
58
|
-
case 'number':
|
|
59
|
-
return expoAsset.Asset.fromModule(input);
|
|
60
|
-
|
|
61
|
-
default:
|
|
62
|
-
throw 'Invalid asset! Must be a URI or module.';
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Downloads from a local URI and decodes into an ArrayBuffer.
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const toBuffer = async localUri => expoFileSystem.readAsStringAsync(localUri, {
|
|
71
|
-
encoding: 'base64'
|
|
72
|
-
}).then(base64Arraybuffer.decode);
|
|
73
|
-
|
|
74
|
-
function loadingFn(extensions, onProgress) {
|
|
75
|
-
return function (Proto, ...input) {
|
|
76
|
-
// Construct new loader and run extensions
|
|
77
|
-
const loader = new Proto();
|
|
78
|
-
if (extensions) extensions(loader); // Go through the urls and load them
|
|
79
|
-
|
|
80
|
-
return Promise.all(input.map(entry => new Promise(async (res, reject) => {
|
|
81
|
-
// Construct URL
|
|
82
|
-
const url = typeof entry === 'string' ? loader.path + entry : entry; // There's no Image in native, so we create & pass a data texture instead
|
|
83
|
-
|
|
84
|
-
if (loader instanceof THREE__namespace.TextureLoader) {
|
|
85
|
-
const asset = await getAsset(url).downloadAsync();
|
|
86
|
-
const texture = new THREE__namespace.Texture();
|
|
87
|
-
texture.isDataTexture = true;
|
|
88
|
-
texture.image = {
|
|
89
|
-
data: asset,
|
|
90
|
-
width: asset.width,
|
|
91
|
-
height: asset.height
|
|
92
|
-
};
|
|
93
|
-
texture.needsUpdate = true;
|
|
94
|
-
return res(texture);
|
|
95
|
-
} // Do similar for CubeTextures
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (loader instanceof THREE__namespace.CubeTextureLoader) {
|
|
99
|
-
const texture = new THREE__namespace.CubeTexture();
|
|
100
|
-
texture.isDataTexture = true;
|
|
101
|
-
texture.images = await Promise.all(url.map(async src => {
|
|
102
|
-
const asset = await getAsset(src).downloadAsync();
|
|
103
|
-
return {
|
|
104
|
-
data: asset,
|
|
105
|
-
width: asset.width,
|
|
106
|
-
height: asset.height
|
|
107
|
-
};
|
|
108
|
-
}));
|
|
109
|
-
texture.needsUpdate = true;
|
|
110
|
-
return res(texture);
|
|
111
|
-
} // If asset is external and not an Image, load it
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (url.startsWith != null && url.startsWith('http') && Proto.prototype.hasOwnProperty('load')) {
|
|
115
|
-
return loader.load(entry, data => {
|
|
116
|
-
if (data.scene) Object.assign(data, index.buildGraph(data.scene));
|
|
117
|
-
res(data);
|
|
118
|
-
}, onProgress, error => reject(`Could not load ${url}: ${error.message}`));
|
|
119
|
-
} // Otherwise, create a localUri and a file buffer
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const {
|
|
123
|
-
localUri
|
|
124
|
-
} = await getAsset(url).downloadAsync();
|
|
125
|
-
const arrayBuffer = await toBuffer(localUri); // Parse it
|
|
126
|
-
|
|
127
|
-
const parsed = loader.parse == null ? void 0 : loader.parse(arrayBuffer, undefined, data => {
|
|
128
|
-
if (data.scene) Object.assign(data, index.buildGraph(data.scene));
|
|
129
|
-
res(data);
|
|
130
|
-
}, error => reject(`Could not load ${url}: ${error.message}`)); // Respect synchronous parsers which don't have callbacks
|
|
131
|
-
|
|
132
|
-
if (parsed) return res(parsed);
|
|
133
|
-
})));
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function useLoader(Proto, input, extensions, onProgress) {
|
|
138
|
-
// Use suspense to load async assets
|
|
139
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
140
|
-
const results = suspendReact.suspend(loadingFn(extensions, onProgress), [Proto, ...keys], {
|
|
141
|
-
equal: index.is.equ
|
|
142
|
-
}); // Return the object/s
|
|
143
|
-
|
|
144
|
-
return Array.isArray(input) ? results : results[0];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
useLoader.preload = function (Proto, input, extensions) {
|
|
148
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
149
|
-
return suspendReact.preload(loadingFn(extensions), [Proto, ...keys]);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
useLoader.clear = function (Proto, input) {
|
|
153
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
154
|
-
return suspendReact.clear([Proto, ...keys]);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
45
|
const EVENTS = {
|
|
158
46
|
PRESS: 'onPress',
|
|
159
47
|
PRESSIN: 'onPressIn',
|
|
@@ -180,8 +68,8 @@ function createTouchEvents(store) {
|
|
|
180
68
|
const handleTouch = (event, name) => {
|
|
181
69
|
event.persist() // Apply offset
|
|
182
70
|
;
|
|
183
|
-
event.nativeEvent.offsetX = event.nativeEvent.
|
|
184
|
-
event.nativeEvent.offsetY = event.nativeEvent.
|
|
71
|
+
event.nativeEvent.offsetX = event.nativeEvent.locationX;
|
|
72
|
+
event.nativeEvent.offsetY = event.nativeEvent.locationY; // Emulate DOM event
|
|
185
73
|
|
|
186
74
|
const callback = handlePointer(DOM_EVENTS[name]);
|
|
187
75
|
return callback(event.nativeEvent);
|
|
@@ -199,13 +87,13 @@ function createTouchEvents(store) {
|
|
|
199
87
|
} = store.getState();
|
|
200
88
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
201
89
|
const connected = new Pressability__default['default'](events == null ? void 0 : events.handlers);
|
|
202
|
-
const handlers = connected.getEventHandlers();
|
|
203
90
|
set(state => ({
|
|
204
91
|
events: { ...state.events,
|
|
205
|
-
connected
|
|
206
|
-
handlers
|
|
92
|
+
connected
|
|
207
93
|
}
|
|
208
94
|
}));
|
|
95
|
+
const handlers = connected.getEventHandlers();
|
|
96
|
+
return handlers;
|
|
209
97
|
},
|
|
210
98
|
disconnect: () => {
|
|
211
99
|
const {
|
|
@@ -314,7 +202,8 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
314
202
|
// Overwrite onCreated to apply RN bindings
|
|
315
203
|
const onCreated = state => {
|
|
316
204
|
// Bind events after creation
|
|
317
|
-
|
|
205
|
+
const handlers = state.events.connect == null ? void 0 : state.events.connect(canvas);
|
|
206
|
+
setBind(handlers); // Bind render to RN bridge
|
|
318
207
|
|
|
319
208
|
const context = state.gl.getContext();
|
|
320
209
|
const renderFrame = state.gl.render.bind(state.gl);
|
|
@@ -362,6 +251,87 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
362
251
|
}));
|
|
363
252
|
});
|
|
364
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Generates an asset based on input type.
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
const getAsset = input => {
|
|
259
|
+
if (input instanceof expoAsset.Asset) return input;
|
|
260
|
+
|
|
261
|
+
switch (typeof input) {
|
|
262
|
+
case 'string':
|
|
263
|
+
return expoAsset.Asset.fromURI(input);
|
|
264
|
+
|
|
265
|
+
case 'number':
|
|
266
|
+
return expoAsset.Asset.fromModule(input);
|
|
267
|
+
|
|
268
|
+
default:
|
|
269
|
+
throw 'Invalid asset! Must be a URI or module.';
|
|
270
|
+
}
|
|
271
|
+
}; // Don't pre-process urls, let expo-asset generate an absolute URL
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
THREE__namespace.LoaderUtils.extractUrlBase = () => './'; // There's no Image in native, so create a data texture instead
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
278
|
+
const texture = new THREE__namespace.Texture(); // @ts-expect-error
|
|
279
|
+
|
|
280
|
+
texture.isDataTexture = true;
|
|
281
|
+
getAsset(url).downloadAsync().then(asset => {
|
|
282
|
+
texture.image = {
|
|
283
|
+
data: asset,
|
|
284
|
+
width: asset.width,
|
|
285
|
+
height: asset.height
|
|
286
|
+
};
|
|
287
|
+
texture.needsUpdate = true;
|
|
288
|
+
onLoad == null ? void 0 : onLoad(texture);
|
|
289
|
+
}).catch(onError);
|
|
290
|
+
return texture;
|
|
291
|
+
}; // Fetches assets via XMLHttpRequest
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
THREE__namespace.FileLoader.prototype.load = function (url, onLoad, onProgress, onError) {
|
|
295
|
+
if (this.path) url = this.path + url;
|
|
296
|
+
const request = new XMLHttpRequest();
|
|
297
|
+
getAsset(url).downloadAsync().then(asset => {
|
|
298
|
+
request.open('GET', asset.uri, true);
|
|
299
|
+
request.addEventListener('load', event => {
|
|
300
|
+
if (request.status === 200) {
|
|
301
|
+
onLoad == null ? void 0 : onLoad(request.response);
|
|
302
|
+
this.manager.itemEnd(url);
|
|
303
|
+
} else {
|
|
304
|
+
onError == null ? void 0 : onError(event);
|
|
305
|
+
this.manager.itemError(url);
|
|
306
|
+
this.manager.itemEnd(url);
|
|
307
|
+
}
|
|
308
|
+
}, false);
|
|
309
|
+
request.addEventListener('progress', event => {
|
|
310
|
+
onProgress == null ? void 0 : onProgress(event);
|
|
311
|
+
}, false);
|
|
312
|
+
request.addEventListener('error', event => {
|
|
313
|
+
onError == null ? void 0 : onError(event);
|
|
314
|
+
this.manager.itemError(url);
|
|
315
|
+
this.manager.itemEnd(url);
|
|
316
|
+
}, false);
|
|
317
|
+
request.addEventListener('abort', event => {
|
|
318
|
+
onError == null ? void 0 : onError(event);
|
|
319
|
+
this.manager.itemError(url);
|
|
320
|
+
this.manager.itemEnd(url);
|
|
321
|
+
}, false);
|
|
322
|
+
if (this.responseType) request.responseType = this.responseType;
|
|
323
|
+
if (this.withCredentials) request.withCredentials = this.withCredentials;
|
|
324
|
+
|
|
325
|
+
for (const header in this.requestHeader) {
|
|
326
|
+
request.setRequestHeader(header, this.requestHeader[header]);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
request.send(null);
|
|
330
|
+
this.manager.itemStart(url);
|
|
331
|
+
});
|
|
332
|
+
return request;
|
|
333
|
+
};
|
|
334
|
+
|
|
365
335
|
exports.ReactThreeFiber = index.threeTypes;
|
|
366
336
|
exports._roots = index.roots;
|
|
367
337
|
exports.act = index.act;
|
|
@@ -381,8 +351,8 @@ exports.render = index.render;
|
|
|
381
351
|
exports.unmountComponentAtNode = index.unmountComponentAtNode;
|
|
382
352
|
exports.useFrame = index.useFrame;
|
|
383
353
|
exports.useGraph = index.useGraph;
|
|
354
|
+
exports.useLoader = index.useLoader;
|
|
384
355
|
exports.useStore = index.useStore;
|
|
385
356
|
exports.useThree = index.useThree;
|
|
386
357
|
exports.Canvas = Canvas;
|
|
387
358
|
exports.events = createTouchEvents;
|
|
388
|
-
exports.useLoader = useLoader;
|
|
@@ -1,130 +1,18 @@
|
|
|
1
|
-
import { z as buildGraph, A as is, c as createEvents, e as extend, p as pick, o as omit, a as createRoot, u as unmountComponentAtNode } from '../../dist/index-fccd77b0.esm.js';
|
|
2
|
-
export { t as ReactThreeFiber, y as _roots, x as act, v as addAfterEffect, s as addEffect, w as addTail, q as advance, l as applyProps, i as context, j as createPortal, a as createRoot, m as dispose, e as extend, n as invalidate, k as reconciler, r as render, u as unmountComponentAtNode, f as useFrame, g as useGraph, b as useStore, d as useThree } from '../../dist/index-fccd77b0.esm.js';
|
|
3
1
|
import * as THREE from 'three';
|
|
4
2
|
import { Asset } from 'expo-asset';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { suspend, preload, clear } from 'suspend-react';
|
|
3
|
+
import { c as createEvents, e as extend, p as pick, o as omit, a as createRoot, u as unmountComponentAtNode } from '../../dist/index-3f4e5f46.esm.js';
|
|
4
|
+
export { t as ReactThreeFiber, q as _roots, n as act, l as addAfterEffect, k as addEffect, m as addTail, j as advance, g as applyProps, b as context, d as createPortal, a as createRoot, h as dispose, e as extend, i as invalidate, f as reconciler, r as render, u as unmountComponentAtNode, w as useFrame, x as useGraph, y as useLoader, s as useStore, v as useThree } from '../../dist/index-3f4e5f46.esm.js';
|
|
8
5
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
9
6
|
import * as React from 'react';
|
|
10
7
|
import { PixelRatio, View, StyleSheet } from 'react-native';
|
|
11
8
|
import { GLView } from 'expo-gl';
|
|
12
9
|
import Pressability from 'react-native/Libraries/Pressability/Pressability';
|
|
10
|
+
import 'suspend-react';
|
|
13
11
|
import 'react-reconciler/constants';
|
|
14
12
|
import 'zustand';
|
|
15
13
|
import 'react-reconciler';
|
|
16
14
|
import 'scheduler';
|
|
17
15
|
|
|
18
|
-
/**
|
|
19
|
-
* Generates an asset based on input type.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const getAsset = input => {
|
|
23
|
-
if (input instanceof Asset) return input;
|
|
24
|
-
|
|
25
|
-
switch (typeof input) {
|
|
26
|
-
case 'string':
|
|
27
|
-
return Asset.fromURI(input);
|
|
28
|
-
|
|
29
|
-
case 'number':
|
|
30
|
-
return Asset.fromModule(input);
|
|
31
|
-
|
|
32
|
-
default:
|
|
33
|
-
throw 'Invalid asset! Must be a URI or module.';
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Downloads from a local URI and decodes into an ArrayBuffer.
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const toBuffer = async localUri => readAsStringAsync(localUri, {
|
|
42
|
-
encoding: 'base64'
|
|
43
|
-
}).then(decode);
|
|
44
|
-
|
|
45
|
-
function loadingFn(extensions, onProgress) {
|
|
46
|
-
return function (Proto, ...input) {
|
|
47
|
-
// Construct new loader and run extensions
|
|
48
|
-
const loader = new Proto();
|
|
49
|
-
if (extensions) extensions(loader); // Go through the urls and load them
|
|
50
|
-
|
|
51
|
-
return Promise.all(input.map(entry => new Promise(async (res, reject) => {
|
|
52
|
-
// Construct URL
|
|
53
|
-
const url = typeof entry === 'string' ? loader.path + entry : entry; // There's no Image in native, so we create & pass a data texture instead
|
|
54
|
-
|
|
55
|
-
if (loader instanceof THREE.TextureLoader) {
|
|
56
|
-
const asset = await getAsset(url).downloadAsync();
|
|
57
|
-
const texture = new THREE.Texture();
|
|
58
|
-
texture.isDataTexture = true;
|
|
59
|
-
texture.image = {
|
|
60
|
-
data: asset,
|
|
61
|
-
width: asset.width,
|
|
62
|
-
height: asset.height
|
|
63
|
-
};
|
|
64
|
-
texture.needsUpdate = true;
|
|
65
|
-
return res(texture);
|
|
66
|
-
} // Do similar for CubeTextures
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (loader instanceof THREE.CubeTextureLoader) {
|
|
70
|
-
const texture = new THREE.CubeTexture();
|
|
71
|
-
texture.isDataTexture = true;
|
|
72
|
-
texture.images = await Promise.all(url.map(async src => {
|
|
73
|
-
const asset = await getAsset(src).downloadAsync();
|
|
74
|
-
return {
|
|
75
|
-
data: asset,
|
|
76
|
-
width: asset.width,
|
|
77
|
-
height: asset.height
|
|
78
|
-
};
|
|
79
|
-
}));
|
|
80
|
-
texture.needsUpdate = true;
|
|
81
|
-
return res(texture);
|
|
82
|
-
} // If asset is external and not an Image, load it
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (url.startsWith != null && url.startsWith('http') && Proto.prototype.hasOwnProperty('load')) {
|
|
86
|
-
return loader.load(entry, data => {
|
|
87
|
-
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
88
|
-
res(data);
|
|
89
|
-
}, onProgress, error => reject(`Could not load ${url}: ${error.message}`));
|
|
90
|
-
} // Otherwise, create a localUri and a file buffer
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const {
|
|
94
|
-
localUri
|
|
95
|
-
} = await getAsset(url).downloadAsync();
|
|
96
|
-
const arrayBuffer = await toBuffer(localUri); // Parse it
|
|
97
|
-
|
|
98
|
-
const parsed = loader.parse == null ? void 0 : loader.parse(arrayBuffer, undefined, data => {
|
|
99
|
-
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
100
|
-
res(data);
|
|
101
|
-
}, error => reject(`Could not load ${url}: ${error.message}`)); // Respect synchronous parsers which don't have callbacks
|
|
102
|
-
|
|
103
|
-
if (parsed) return res(parsed);
|
|
104
|
-
})));
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function useLoader(Proto, input, extensions, onProgress) {
|
|
109
|
-
// Use suspense to load async assets
|
|
110
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
111
|
-
const results = suspend(loadingFn(extensions, onProgress), [Proto, ...keys], {
|
|
112
|
-
equal: is.equ
|
|
113
|
-
}); // Return the object/s
|
|
114
|
-
|
|
115
|
-
return Array.isArray(input) ? results : results[0];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
useLoader.preload = function (Proto, input, extensions) {
|
|
119
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
120
|
-
return preload(loadingFn(extensions), [Proto, ...keys]);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
useLoader.clear = function (Proto, input) {
|
|
124
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
125
|
-
return clear([Proto, ...keys]);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
16
|
const EVENTS = {
|
|
129
17
|
PRESS: 'onPress',
|
|
130
18
|
PRESSIN: 'onPressIn',
|
|
@@ -151,8 +39,8 @@ function createTouchEvents(store) {
|
|
|
151
39
|
const handleTouch = (event, name) => {
|
|
152
40
|
event.persist() // Apply offset
|
|
153
41
|
;
|
|
154
|
-
event.nativeEvent.offsetX = event.nativeEvent.
|
|
155
|
-
event.nativeEvent.offsetY = event.nativeEvent.
|
|
42
|
+
event.nativeEvent.offsetX = event.nativeEvent.locationX;
|
|
43
|
+
event.nativeEvent.offsetY = event.nativeEvent.locationY; // Emulate DOM event
|
|
156
44
|
|
|
157
45
|
const callback = handlePointer(DOM_EVENTS[name]);
|
|
158
46
|
return callback(event.nativeEvent);
|
|
@@ -170,13 +58,13 @@ function createTouchEvents(store) {
|
|
|
170
58
|
} = store.getState();
|
|
171
59
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
172
60
|
const connected = new Pressability(events == null ? void 0 : events.handlers);
|
|
173
|
-
const handlers = connected.getEventHandlers();
|
|
174
61
|
set(state => ({
|
|
175
62
|
events: { ...state.events,
|
|
176
|
-
connected
|
|
177
|
-
handlers
|
|
63
|
+
connected
|
|
178
64
|
}
|
|
179
65
|
}));
|
|
66
|
+
const handlers = connected.getEventHandlers();
|
|
67
|
+
return handlers;
|
|
180
68
|
},
|
|
181
69
|
disconnect: () => {
|
|
182
70
|
const {
|
|
@@ -285,7 +173,8 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
|
|
|
285
173
|
// Overwrite onCreated to apply RN bindings
|
|
286
174
|
const onCreated = state => {
|
|
287
175
|
// Bind events after creation
|
|
288
|
-
|
|
176
|
+
const handlers = state.events.connect == null ? void 0 : state.events.connect(canvas);
|
|
177
|
+
setBind(handlers); // Bind render to RN bridge
|
|
289
178
|
|
|
290
179
|
const context = state.gl.getContext();
|
|
291
180
|
const renderFrame = state.gl.render.bind(state.gl);
|
|
@@ -333,4 +222,85 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
|
|
|
333
222
|
}));
|
|
334
223
|
});
|
|
335
224
|
|
|
336
|
-
|
|
225
|
+
/**
|
|
226
|
+
* Generates an asset based on input type.
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
const getAsset = input => {
|
|
230
|
+
if (input instanceof Asset) return input;
|
|
231
|
+
|
|
232
|
+
switch (typeof input) {
|
|
233
|
+
case 'string':
|
|
234
|
+
return Asset.fromURI(input);
|
|
235
|
+
|
|
236
|
+
case 'number':
|
|
237
|
+
return Asset.fromModule(input);
|
|
238
|
+
|
|
239
|
+
default:
|
|
240
|
+
throw 'Invalid asset! Must be a URI or module.';
|
|
241
|
+
}
|
|
242
|
+
}; // Don't pre-process urls, let expo-asset generate an absolute URL
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
THREE.LoaderUtils.extractUrlBase = () => './'; // There's no Image in native, so create a data texture instead
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
THREE.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
249
|
+
const texture = new THREE.Texture(); // @ts-expect-error
|
|
250
|
+
|
|
251
|
+
texture.isDataTexture = true;
|
|
252
|
+
getAsset(url).downloadAsync().then(asset => {
|
|
253
|
+
texture.image = {
|
|
254
|
+
data: asset,
|
|
255
|
+
width: asset.width,
|
|
256
|
+
height: asset.height
|
|
257
|
+
};
|
|
258
|
+
texture.needsUpdate = true;
|
|
259
|
+
onLoad == null ? void 0 : onLoad(texture);
|
|
260
|
+
}).catch(onError);
|
|
261
|
+
return texture;
|
|
262
|
+
}; // Fetches assets via XMLHttpRequest
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
THREE.FileLoader.prototype.load = function (url, onLoad, onProgress, onError) {
|
|
266
|
+
if (this.path) url = this.path + url;
|
|
267
|
+
const request = new XMLHttpRequest();
|
|
268
|
+
getAsset(url).downloadAsync().then(asset => {
|
|
269
|
+
request.open('GET', asset.uri, true);
|
|
270
|
+
request.addEventListener('load', event => {
|
|
271
|
+
if (request.status === 200) {
|
|
272
|
+
onLoad == null ? void 0 : onLoad(request.response);
|
|
273
|
+
this.manager.itemEnd(url);
|
|
274
|
+
} else {
|
|
275
|
+
onError == null ? void 0 : onError(event);
|
|
276
|
+
this.manager.itemError(url);
|
|
277
|
+
this.manager.itemEnd(url);
|
|
278
|
+
}
|
|
279
|
+
}, false);
|
|
280
|
+
request.addEventListener('progress', event => {
|
|
281
|
+
onProgress == null ? void 0 : onProgress(event);
|
|
282
|
+
}, false);
|
|
283
|
+
request.addEventListener('error', event => {
|
|
284
|
+
onError == null ? void 0 : onError(event);
|
|
285
|
+
this.manager.itemError(url);
|
|
286
|
+
this.manager.itemEnd(url);
|
|
287
|
+
}, false);
|
|
288
|
+
request.addEventListener('abort', event => {
|
|
289
|
+
onError == null ? void 0 : onError(event);
|
|
290
|
+
this.manager.itemError(url);
|
|
291
|
+
this.manager.itemEnd(url);
|
|
292
|
+
}, false);
|
|
293
|
+
if (this.responseType) request.responseType = this.responseType;
|
|
294
|
+
if (this.withCredentials) request.withCredentials = this.withCredentials;
|
|
295
|
+
|
|
296
|
+
for (const header in this.requestHeader) {
|
|
297
|
+
request.setRequestHeader(header, this.requestHeader[header]);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
request.send(null);
|
|
301
|
+
this.manager.itemStart(url);
|
|
302
|
+
});
|
|
303
|
+
return request;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
export { Canvas, createTouchEvents as events };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-three/fiber",
|
|
3
|
-
"version": "8.0.0-beta-
|
|
3
|
+
"version": "8.0.0-beta-05",
|
|
4
4
|
"description": "A React renderer for Threejs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -43,11 +43,6 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@babel/runtime": "^7.15.4",
|
|
46
|
-
"base64-arraybuffer": "^1.0.1",
|
|
47
|
-
"expo-asset": "^8.4.3",
|
|
48
|
-
"expo-file-system": "^13.0.3",
|
|
49
|
-
"expo-gl": "^11.0.3",
|
|
50
|
-
"expo": "^43.0.1",
|
|
51
46
|
"react-merge-refs": "^1.1.0",
|
|
52
47
|
"react-reconciler": "^0.27.0-rc.0",
|
|
53
48
|
"react-use-measure": "^2.1.1",
|
|
@@ -61,7 +56,10 @@
|
|
|
61
56
|
"react": ">=18.0",
|
|
62
57
|
"react-dom": ">=18.0",
|
|
63
58
|
"react-native": ">=0.64",
|
|
64
|
-
"
|
|
59
|
+
"expo": ">=43.0",
|
|
60
|
+
"expo-asset": ">=8.4",
|
|
61
|
+
"expo-gl": ">=11.0",
|
|
62
|
+
"three": ">=0.133"
|
|
65
63
|
},
|
|
66
64
|
"peerDependenciesMeta": {
|
|
67
65
|
"react-dom": {
|
|
@@ -69,6 +67,15 @@
|
|
|
69
67
|
},
|
|
70
68
|
"react-native": {
|
|
71
69
|
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"expo": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"expo-asset": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"expo-gl": {
|
|
78
|
+
"optional": true
|
|
72
79
|
}
|
|
73
80
|
}
|
|
74
81
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
|
|
2
|
-
import { ObjectMap } from '../core/utils';
|
|
3
|
-
import { Extensions, LoaderResult, BranchingReturn, useStore, useThree, useFrame, useGraph } from '../core/hooks';
|
|
4
|
-
declare function useLoader<T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U, extensions?: Extensions, onProgress?: (event: ProgressEvent<EventTarget>) => void): U extends any[] ? BranchingReturn<T, GLTF, GLTF & ObjectMap>[] : BranchingReturn<T, GLTF, GLTF & ObjectMap>;
|
|
5
|
-
declare namespace useLoader {
|
|
6
|
-
var preload: <T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U, extensions?: Extensions | undefined) => undefined;
|
|
7
|
-
var clear: <T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U) => void;
|
|
8
|
-
}
|
|
9
|
-
export { useStore, useThree, useFrame, useGraph, useLoader };
|