@react-three/fiber 8.0.0-beta-04 → 8.0.0-beta.1
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 +18 -0
- package/dist/declarations/src/core/index.d.ts +10 -7
- package/dist/declarations/src/core/loop.d.ts +3 -2
- package/dist/declarations/src/core/store.d.ts +13 -15
- package/dist/declarations/src/core/utils.d.ts +7 -1
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/native.d.ts +1 -1
- package/dist/declarations/src/three-types.d.ts +7 -8
- package/dist/{index-ff3eb68b.cjs.dev.js → index-05ebefd3.cjs.dev.js} +322 -279
- package/dist/{index-eb414398.cjs.prod.js → index-85b2df17.cjs.prod.js} +322 -279
- package/dist/{index-fccd77b0.esm.js → index-e78dd2f0.esm.js} +323 -278
- package/dist/react-three-fiber.cjs.dev.js +9 -6
- package/dist/react-three-fiber.cjs.prod.js +9 -6
- package/dist/react-three-fiber.esm.js +10 -7
- package/native/dist/react-three-fiber-native.cjs.dev.js +100 -125
- package/native/dist/react-three-fiber-native.cjs.prod.js +100 -125
- package/native/dist/react-three-fiber-native.esm.js +101 -126
- package/package.json +14 -9
- package/dist/declarations/src/native/hooks.d.ts +0 -9
|
@@ -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-05ebefd3.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -107,7 +107,7 @@ function createPointerEvents(store) {
|
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', '
|
|
110
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
111
111
|
|
|
112
112
|
function Block({
|
|
113
113
|
set
|
|
@@ -146,7 +146,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
146
146
|
fallback,
|
|
147
147
|
resize,
|
|
148
148
|
style,
|
|
149
|
-
events,
|
|
149
|
+
events = createPointerEvents,
|
|
150
150
|
...props
|
|
151
151
|
}, forwardedRef) {
|
|
152
152
|
// Create a known catalogue of Threejs-native elements
|
|
@@ -174,15 +174,18 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
174
174
|
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
175
175
|
|
|
176
176
|
if (error) throw error;
|
|
177
|
+
const root = React__namespace.useRef(null);
|
|
177
178
|
|
|
178
179
|
if (width > 0 && height > 0 && canvas) {
|
|
179
|
-
index.createRoot(canvas
|
|
180
|
+
if (!root.current) root.current = index.createRoot(canvas);
|
|
181
|
+
root.current.configure({ ...canvasProps,
|
|
180
182
|
size: {
|
|
181
183
|
width,
|
|
182
184
|
height
|
|
183
185
|
},
|
|
184
|
-
events
|
|
185
|
-
})
|
|
186
|
+
events
|
|
187
|
+
});
|
|
188
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
186
189
|
set: setError
|
|
187
190
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
188
191
|
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
@@ -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-85b2df17.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -107,7 +107,7 @@ function createPointerEvents(store) {
|
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', '
|
|
110
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
111
111
|
|
|
112
112
|
function Block({
|
|
113
113
|
set
|
|
@@ -146,7 +146,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
146
146
|
fallback,
|
|
147
147
|
resize,
|
|
148
148
|
style,
|
|
149
|
-
events,
|
|
149
|
+
events = createPointerEvents,
|
|
150
150
|
...props
|
|
151
151
|
}, forwardedRef) {
|
|
152
152
|
// Create a known catalogue of Threejs-native elements
|
|
@@ -174,15 +174,18 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
174
174
|
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
175
175
|
|
|
176
176
|
if (error) throw error;
|
|
177
|
+
const root = React__namespace.useRef(null);
|
|
177
178
|
|
|
178
179
|
if (width > 0 && height > 0 && canvas) {
|
|
179
|
-
index.createRoot(canvas
|
|
180
|
+
if (!root.current) root.current = index.createRoot(canvas);
|
|
181
|
+
root.current.configure({ ...canvasProps,
|
|
180
182
|
size: {
|
|
181
183
|
width,
|
|
182
184
|
height
|
|
183
185
|
},
|
|
184
|
-
events
|
|
185
|
-
})
|
|
186
|
+
events
|
|
187
|
+
});
|
|
188
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
186
189
|
set: setError
|
|
187
190
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
188
191
|
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createEvents, e as extend, p as pick, o as omit, a as createRoot, u as unmountComponentAtNode } from './index-
|
|
2
|
-
export { t as ReactThreeFiber,
|
|
1
|
+
import { c as createEvents, e as extend, p as pick, o as omit, a as createRoot, u as unmountComponentAtNode } from './index-e78dd2f0.esm.js';
|
|
2
|
+
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 './index-e78dd2f0.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';
|
|
@@ -77,7 +77,7 @@ function createPointerEvents(store) {
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', '
|
|
80
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
81
81
|
|
|
82
82
|
function Block({
|
|
83
83
|
set
|
|
@@ -116,7 +116,7 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
116
116
|
fallback,
|
|
117
117
|
resize,
|
|
118
118
|
style,
|
|
119
|
-
events,
|
|
119
|
+
events = createPointerEvents,
|
|
120
120
|
...props
|
|
121
121
|
}, forwardedRef) {
|
|
122
122
|
// Create a known catalogue of Threejs-native elements
|
|
@@ -144,15 +144,18 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
144
144
|
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
145
145
|
|
|
146
146
|
if (error) throw error;
|
|
147
|
+
const root = React.useRef(null);
|
|
147
148
|
|
|
148
149
|
if (width > 0 && height > 0 && canvas) {
|
|
149
|
-
createRoot(canvas
|
|
150
|
+
if (!root.current) root.current = createRoot(canvas);
|
|
151
|
+
root.current.configure({ ...canvasProps,
|
|
150
152
|
size: {
|
|
151
153
|
width,
|
|
152
154
|
height
|
|
153
155
|
},
|
|
154
|
-
events
|
|
155
|
-
})
|
|
156
|
+
events
|
|
157
|
+
});
|
|
158
|
+
root.current.render( /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
156
159
|
set: setError
|
|
157
160
|
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
158
161
|
fallback: /*#__PURE__*/React.createElement(Block, {
|
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../dist/index-ff3eb68b.cjs.dev.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-05ebefd3.cjs.dev.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 {
|
|
@@ -225,7 +113,7 @@ function createTouchEvents(store) {
|
|
|
225
113
|
};
|
|
226
114
|
}
|
|
227
115
|
|
|
228
|
-
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'performance', '
|
|
116
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
229
117
|
|
|
230
118
|
function Block({
|
|
231
119
|
set
|
|
@@ -287,6 +175,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
287
175
|
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
288
176
|
|
|
289
177
|
if (error) throw error;
|
|
178
|
+
const root = React__namespace.useRef(null);
|
|
290
179
|
const onLayout = React__namespace.useCallback(e => {
|
|
291
180
|
const {
|
|
292
181
|
width,
|
|
@@ -311,10 +200,12 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
311
200
|
}, []);
|
|
312
201
|
|
|
313
202
|
if (width > 0 && height > 0 && canvas) {
|
|
314
|
-
// Overwrite onCreated to apply RN bindings
|
|
203
|
+
if (!root.current) root.current = index.createRoot(canvas); // Overwrite onCreated to apply RN bindings
|
|
204
|
+
|
|
315
205
|
const onCreated = state => {
|
|
316
206
|
// Bind events after creation
|
|
317
|
-
|
|
207
|
+
const handlers = state.events.connect == null ? void 0 : state.events.connect(canvas);
|
|
208
|
+
setBind(handlers); // Bind render to RN bridge
|
|
318
209
|
|
|
319
210
|
const context = state.gl.getContext();
|
|
320
211
|
const renderFrame = state.gl.render.bind(state.gl);
|
|
@@ -327,7 +218,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
327
218
|
return canvasProps == null ? void 0 : canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
|
|
328
219
|
};
|
|
329
220
|
|
|
330
|
-
|
|
221
|
+
root.current.configure({ ...canvasProps,
|
|
331
222
|
// expo-gl can only render at native dpr/resolution
|
|
332
223
|
// https://github.com/expo/expo-three/issues/39
|
|
333
224
|
dpr: reactNative.PixelRatio.get(),
|
|
@@ -337,7 +228,8 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
337
228
|
},
|
|
338
229
|
events: events || createTouchEvents,
|
|
339
230
|
onCreated
|
|
340
|
-
})
|
|
231
|
+
});
|
|
232
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
341
233
|
set: setError
|
|
342
234
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
343
235
|
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
@@ -362,6 +254,89 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
362
254
|
}));
|
|
363
255
|
});
|
|
364
256
|
|
|
257
|
+
/**
|
|
258
|
+
* Generates an asset based on input type.
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
const getAsset = input => {
|
|
262
|
+
if (input instanceof expoAsset.Asset) return input;
|
|
263
|
+
|
|
264
|
+
switch (typeof input) {
|
|
265
|
+
case 'string':
|
|
266
|
+
return expoAsset.Asset.fromURI(input);
|
|
267
|
+
|
|
268
|
+
case 'number':
|
|
269
|
+
return expoAsset.Asset.fromModule(input);
|
|
270
|
+
|
|
271
|
+
default:
|
|
272
|
+
throw 'Invalid asset! Must be a URI or module.';
|
|
273
|
+
}
|
|
274
|
+
}; // Don't pre-process urls, let expo-asset generate an absolute URL
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
|
|
278
|
+
|
|
279
|
+
THREE__namespace.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './'; // There's no Image in native, so create a data texture instead
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
283
|
+
const texture = new THREE__namespace.Texture(); // @ts-expect-error
|
|
284
|
+
|
|
285
|
+
texture.isDataTexture = true;
|
|
286
|
+
getAsset(url).downloadAsync().then(asset => {
|
|
287
|
+
texture.image = {
|
|
288
|
+
data: asset,
|
|
289
|
+
width: asset.width,
|
|
290
|
+
height: asset.height
|
|
291
|
+
};
|
|
292
|
+
texture.needsUpdate = true;
|
|
293
|
+
onLoad == null ? void 0 : onLoad(texture);
|
|
294
|
+
}).catch(onError);
|
|
295
|
+
return texture;
|
|
296
|
+
}; // Fetches assets via XMLHttpRequest
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
THREE__namespace.FileLoader.prototype.load = function (url, onLoad, onProgress, onError) {
|
|
300
|
+
if (this.path) url = this.path + url;
|
|
301
|
+
const request = new XMLHttpRequest();
|
|
302
|
+
getAsset(url).downloadAsync().then(asset => {
|
|
303
|
+
request.open('GET', asset.uri, true);
|
|
304
|
+
request.addEventListener('load', event => {
|
|
305
|
+
if (request.status === 200) {
|
|
306
|
+
onLoad == null ? void 0 : onLoad(request.response);
|
|
307
|
+
this.manager.itemEnd(url);
|
|
308
|
+
} else {
|
|
309
|
+
onError == null ? void 0 : onError(event);
|
|
310
|
+
this.manager.itemError(url);
|
|
311
|
+
this.manager.itemEnd(url);
|
|
312
|
+
}
|
|
313
|
+
}, false);
|
|
314
|
+
request.addEventListener('progress', event => {
|
|
315
|
+
onProgress == null ? void 0 : onProgress(event);
|
|
316
|
+
}, false);
|
|
317
|
+
request.addEventListener('error', event => {
|
|
318
|
+
onError == null ? void 0 : onError(event);
|
|
319
|
+
this.manager.itemError(url);
|
|
320
|
+
this.manager.itemEnd(url);
|
|
321
|
+
}, false);
|
|
322
|
+
request.addEventListener('abort', event => {
|
|
323
|
+
onError == null ? void 0 : onError(event);
|
|
324
|
+
this.manager.itemError(url);
|
|
325
|
+
this.manager.itemEnd(url);
|
|
326
|
+
}, false);
|
|
327
|
+
if (this.responseType) request.responseType = this.responseType;
|
|
328
|
+
if (this.withCredentials) request.withCredentials = this.withCredentials;
|
|
329
|
+
|
|
330
|
+
for (const header in this.requestHeader) {
|
|
331
|
+
request.setRequestHeader(header, this.requestHeader[header]);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
request.send(null);
|
|
335
|
+
this.manager.itemStart(url);
|
|
336
|
+
});
|
|
337
|
+
return request;
|
|
338
|
+
};
|
|
339
|
+
|
|
365
340
|
exports.ReactThreeFiber = index.threeTypes;
|
|
366
341
|
exports._roots = index.roots;
|
|
367
342
|
exports.act = index.act;
|
|
@@ -381,8 +356,8 @@ exports.render = index.render;
|
|
|
381
356
|
exports.unmountComponentAtNode = index.unmountComponentAtNode;
|
|
382
357
|
exports.useFrame = index.useFrame;
|
|
383
358
|
exports.useGraph = index.useGraph;
|
|
359
|
+
exports.useLoader = index.useLoader;
|
|
384
360
|
exports.useStore = index.useStore;
|
|
385
361
|
exports.useThree = index.useThree;
|
|
386
362
|
exports.Canvas = Canvas;
|
|
387
363
|
exports.events = createTouchEvents;
|
|
388
|
-
exports.useLoader = useLoader;
|