@react-three/fiber 8.0.0-alpha.0 → 8.0.0-beta-04
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 +103 -0
- package/dist/declarations/src/core/events.d.ts +64 -59
- package/dist/declarations/src/core/hooks.d.ts +21 -29
- package/dist/declarations/src/core/index.d.ts +31 -0
- package/dist/declarations/src/core/loop.d.ts +12 -12
- package/dist/declarations/src/core/renderer.d.ts +50 -52
- package/dist/declarations/src/core/store.d.ts +117 -106
- package/dist/declarations/src/core/utils.d.ts +50 -0
- package/dist/declarations/src/index.d.ts +10 -7
- package/dist/declarations/src/native/Canvas.d.ts +13 -0
- package/dist/declarations/src/native/events.d.ts +5 -0
- package/dist/declarations/src/native/hooks.d.ts +9 -0
- package/dist/declarations/src/native.d.ts +10 -0
- package/dist/declarations/src/three-types.d.ts +309 -320
- package/dist/declarations/src/web/Canvas.d.ts +13 -13
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/index-eb414398.cjs.prod.js +1805 -0
- package/dist/index-fccd77b0.esm.js +1750 -0
- package/dist/index-ff3eb68b.cjs.dev.js +1805 -0
- package/dist/react-three-fiber.cjs.dev.js +108 -1734
- package/dist/react-three-fiber.cjs.prod.js +108 -1734
- package/dist/react-three-fiber.esm.js +63 -1686
- package/native/dist/react-three-fiber-native.cjs.d.ts +1 -0
- package/native/dist/react-three-fiber-native.cjs.dev.js +388 -0
- package/native/dist/react-three-fiber-native.cjs.js +7 -0
- package/native/dist/react-three-fiber-native.cjs.prod.js +388 -0
- package/native/dist/react-three-fiber-native.esm.js +336 -0
- package/native/package.json +5 -0
- package/package.json +19 -8
- package/readme.md +10 -10
- package/__mocks__/react-use-measure/index.ts +0 -22
- package/dist/declarations/src/core/is.d.ts +0 -9
- package/dist/declarations/src/web/index.d.ts +0 -30
|
@@ -0,0 +1,336 @@
|
|
|
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
|
+
import * as THREE from 'three';
|
|
4
|
+
import { Asset } from 'expo-asset';
|
|
5
|
+
import { readAsStringAsync } from 'expo-file-system';
|
|
6
|
+
import { decode } from 'base64-arraybuffer';
|
|
7
|
+
import { suspend, preload, clear } from 'suspend-react';
|
|
8
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
9
|
+
import * as React from 'react';
|
|
10
|
+
import { PixelRatio, View, StyleSheet } from 'react-native';
|
|
11
|
+
import { GLView } from 'expo-gl';
|
|
12
|
+
import Pressability from 'react-native/Libraries/Pressability/Pressability';
|
|
13
|
+
import 'react-reconciler/constants';
|
|
14
|
+
import 'zustand';
|
|
15
|
+
import 'react-reconciler';
|
|
16
|
+
import 'scheduler';
|
|
17
|
+
|
|
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
|
+
const EVENTS = {
|
|
129
|
+
PRESS: 'onPress',
|
|
130
|
+
PRESSIN: 'onPressIn',
|
|
131
|
+
PRESSOUT: 'onPressOut',
|
|
132
|
+
LONGPRESS: 'onLongPress',
|
|
133
|
+
HOVERIN: 'onHoverIn',
|
|
134
|
+
HOVEROUT: 'onHoverOut',
|
|
135
|
+
PRESSMOVE: 'onPressMove'
|
|
136
|
+
};
|
|
137
|
+
const DOM_EVENTS = {
|
|
138
|
+
[EVENTS.PRESS]: 'onClick',
|
|
139
|
+
[EVENTS.PRESSIN]: 'onPointerDown',
|
|
140
|
+
[EVENTS.PRESSOUT]: 'onPointerUp',
|
|
141
|
+
[EVENTS.LONGPRESS]: 'onDoubleClick',
|
|
142
|
+
[EVENTS.HOVERIN]: 'onPointerOver',
|
|
143
|
+
[EVENTS.HOVEROUT]: 'onPointerOut',
|
|
144
|
+
[EVENTS.PRESSMOVE]: 'onPointerMove'
|
|
145
|
+
};
|
|
146
|
+
function createTouchEvents(store) {
|
|
147
|
+
const {
|
|
148
|
+
handlePointer
|
|
149
|
+
} = createEvents(store);
|
|
150
|
+
|
|
151
|
+
const handleTouch = (event, name) => {
|
|
152
|
+
event.persist() // Apply offset
|
|
153
|
+
;
|
|
154
|
+
event.nativeEvent.offsetX = event.nativeEvent.pageX;
|
|
155
|
+
event.nativeEvent.offsetY = event.nativeEvent.pageY; // Emulate DOM event
|
|
156
|
+
|
|
157
|
+
const callback = handlePointer(DOM_EVENTS[name]);
|
|
158
|
+
return callback(event.nativeEvent);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
connected: false,
|
|
163
|
+
handlers: Object.values(EVENTS).reduce((acc, name) => ({ ...acc,
|
|
164
|
+
[name]: event => handleTouch(event, name)
|
|
165
|
+
}), {}),
|
|
166
|
+
connect: () => {
|
|
167
|
+
const {
|
|
168
|
+
set,
|
|
169
|
+
events
|
|
170
|
+
} = store.getState();
|
|
171
|
+
events.disconnect == null ? void 0 : events.disconnect();
|
|
172
|
+
const connected = new Pressability(events == null ? void 0 : events.handlers);
|
|
173
|
+
const handlers = connected.getEventHandlers();
|
|
174
|
+
set(state => ({
|
|
175
|
+
events: { ...state.events,
|
|
176
|
+
connected,
|
|
177
|
+
handlers
|
|
178
|
+
}
|
|
179
|
+
}));
|
|
180
|
+
},
|
|
181
|
+
disconnect: () => {
|
|
182
|
+
const {
|
|
183
|
+
set,
|
|
184
|
+
events
|
|
185
|
+
} = store.getState();
|
|
186
|
+
|
|
187
|
+
if (events.connected) {
|
|
188
|
+
events.connected.reset();
|
|
189
|
+
set(state => ({
|
|
190
|
+
events: { ...state.events,
|
|
191
|
+
connected: false
|
|
192
|
+
}
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'performance', 'clock', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
200
|
+
|
|
201
|
+
function Block({
|
|
202
|
+
set
|
|
203
|
+
}) {
|
|
204
|
+
React.useLayoutEffect(() => {
|
|
205
|
+
set(new Promise(() => null));
|
|
206
|
+
return () => set(false);
|
|
207
|
+
}, [set]);
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
class ErrorBoundary extends React.Component {
|
|
212
|
+
constructor(...args) {
|
|
213
|
+
super(...args);
|
|
214
|
+
this.state = {
|
|
215
|
+
error: false
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
componentDidCatch(error) {
|
|
220
|
+
this.props.set(error);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
render() {
|
|
224
|
+
return this.state.error ? null : this.props.children;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
230
|
+
error: true
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const Canvas = /*#__PURE__*/React.forwardRef(({
|
|
234
|
+
children,
|
|
235
|
+
fallback,
|
|
236
|
+
style,
|
|
237
|
+
events,
|
|
238
|
+
...props
|
|
239
|
+
}, forwardedRef) => {
|
|
240
|
+
// Create a known catalogue of Threejs-native elements
|
|
241
|
+
// This will include the entire THREE namespace by default, users can extend
|
|
242
|
+
// their own elements by using the createRoot API instead
|
|
243
|
+
React.useMemo(() => extend(THREE), []);
|
|
244
|
+
const [{
|
|
245
|
+
width,
|
|
246
|
+
height
|
|
247
|
+
}, setSize] = React.useState({
|
|
248
|
+
width: 0,
|
|
249
|
+
height: 0
|
|
250
|
+
});
|
|
251
|
+
const [canvas, setCanvas] = React.useState(null);
|
|
252
|
+
const [bind, setBind] = React.useState();
|
|
253
|
+
const canvasProps = pick(props, CANVAS_PROPS);
|
|
254
|
+
const viewProps = omit(props, CANVAS_PROPS);
|
|
255
|
+
const [block, setBlock] = React.useState(false);
|
|
256
|
+
const [error, setError] = React.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
257
|
+
|
|
258
|
+
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
259
|
+
|
|
260
|
+
if (error) throw error;
|
|
261
|
+
const onLayout = React.useCallback(e => {
|
|
262
|
+
const {
|
|
263
|
+
width,
|
|
264
|
+
height
|
|
265
|
+
} = e.nativeEvent.layout;
|
|
266
|
+
setSize({
|
|
267
|
+
width,
|
|
268
|
+
height
|
|
269
|
+
});
|
|
270
|
+
}, []);
|
|
271
|
+
const onContextCreate = React.useCallback(context => {
|
|
272
|
+
const canvasShim = {
|
|
273
|
+
width: context.drawingBufferWidth,
|
|
274
|
+
height: context.drawingBufferHeight,
|
|
275
|
+
style: {},
|
|
276
|
+
addEventListener: () => {},
|
|
277
|
+
removeEventListener: () => {},
|
|
278
|
+
clientHeight: context.drawingBufferHeight,
|
|
279
|
+
getContext: () => context
|
|
280
|
+
};
|
|
281
|
+
setCanvas(canvasShim);
|
|
282
|
+
}, []);
|
|
283
|
+
|
|
284
|
+
if (width > 0 && height > 0 && canvas) {
|
|
285
|
+
// Overwrite onCreated to apply RN bindings
|
|
286
|
+
const onCreated = state => {
|
|
287
|
+
// Bind events after creation
|
|
288
|
+
setBind(state.events.handlers); // Bind render to RN bridge
|
|
289
|
+
|
|
290
|
+
const context = state.gl.getContext();
|
|
291
|
+
const renderFrame = state.gl.render.bind(state.gl);
|
|
292
|
+
|
|
293
|
+
state.gl.render = (scene, camera) => {
|
|
294
|
+
renderFrame(scene, camera);
|
|
295
|
+
context.endFrameEXP();
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
return canvasProps == null ? void 0 : canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
createRoot(canvas, { ...canvasProps,
|
|
302
|
+
// expo-gl can only render at native dpr/resolution
|
|
303
|
+
// https://github.com/expo/expo-three/issues/39
|
|
304
|
+
dpr: PixelRatio.get(),
|
|
305
|
+
size: {
|
|
306
|
+
width,
|
|
307
|
+
height
|
|
308
|
+
},
|
|
309
|
+
events: events || createTouchEvents,
|
|
310
|
+
onCreated
|
|
311
|
+
}).render( /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
312
|
+
set: setError
|
|
313
|
+
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
314
|
+
fallback: /*#__PURE__*/React.createElement(Block, {
|
|
315
|
+
set: setBlock
|
|
316
|
+
})
|
|
317
|
+
}, children)));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
React.useEffect(() => {
|
|
321
|
+
return () => unmountComponentAtNode(canvas);
|
|
322
|
+
}, [canvas]);
|
|
323
|
+
return /*#__PURE__*/React.createElement(View, _extends({}, viewProps, {
|
|
324
|
+
ref: forwardedRef,
|
|
325
|
+
onLayout: onLayout,
|
|
326
|
+
style: {
|
|
327
|
+
flex: 1,
|
|
328
|
+
...style
|
|
329
|
+
}
|
|
330
|
+
}, bind), width > 0 && /*#__PURE__*/React.createElement(GLView, {
|
|
331
|
+
onContextCreate: onContextCreate,
|
|
332
|
+
style: StyleSheet.absoluteFill
|
|
333
|
+
}));
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
export { Canvas, createTouchEvents as events, useLoader };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-three/fiber",
|
|
3
|
-
"version": "8.0.0-
|
|
3
|
+
"version": "8.0.0-beta-04",
|
|
4
4
|
"description": "A React renderer for Threejs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"author": "Paul Henschel (https://github.com/drcmda)",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"maintainers": [
|
|
15
|
-
"Josh Ellis (https://github.com/joshuaellis)"
|
|
15
|
+
"Josh Ellis (https://github.com/joshuaellis)",
|
|
16
|
+
"Cody Bennett (https://github.com/codyjasonbennett)"
|
|
16
17
|
],
|
|
17
18
|
"bugs": {
|
|
18
19
|
"url": "https://github.com/pmndrs/react-three-fiber/issues"
|
|
@@ -29,11 +30,12 @@
|
|
|
29
30
|
"main": "dist/react-three-fiber.cjs.js",
|
|
30
31
|
"module": "dist/react-three-fiber.esm.js",
|
|
31
32
|
"types": "dist/react-three-fiber.cjs.d.ts",
|
|
32
|
-
"react-native": "dist/native.js",
|
|
33
|
+
"react-native": "native/dist/react-three-fiber-native.cjs.js",
|
|
33
34
|
"sideEffects": false,
|
|
34
35
|
"preconstruct": {
|
|
35
36
|
"entrypoints": [
|
|
36
|
-
"index.tsx"
|
|
37
|
+
"index.tsx",
|
|
38
|
+
"native.tsx"
|
|
37
39
|
]
|
|
38
40
|
},
|
|
39
41
|
"scripts": {
|
|
@@ -41,23 +43,32 @@
|
|
|
41
43
|
},
|
|
42
44
|
"dependencies": {
|
|
43
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",
|
|
44
51
|
"react-merge-refs": "^1.1.0",
|
|
45
|
-
"react-reconciler": "^0.27.0-
|
|
46
|
-
"react-use-measure": "^2.
|
|
52
|
+
"react-reconciler": "^0.27.0-rc.0",
|
|
53
|
+
"react-use-measure": "^2.1.1",
|
|
47
54
|
"resize-observer-polyfill": "^1.5.1",
|
|
48
|
-
"scheduler": "
|
|
49
|
-
"
|
|
55
|
+
"scheduler": "0.21.0-rc.0",
|
|
56
|
+
"suspend-react": "^0.0.8",
|
|
50
57
|
"utility-types": "^3.10.0",
|
|
51
58
|
"zustand": "^3.5.10"
|
|
52
59
|
},
|
|
53
60
|
"peerDependencies": {
|
|
54
61
|
"react": ">=18.0",
|
|
55
62
|
"react-dom": ">=18.0",
|
|
63
|
+
"react-native": ">=0.64",
|
|
56
64
|
"three": ">=0.132"
|
|
57
65
|
},
|
|
58
66
|
"peerDependenciesMeta": {
|
|
59
67
|
"react-dom": {
|
|
60
68
|
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"react-native": {
|
|
71
|
+
"optional": true
|
|
61
72
|
}
|
|
62
73
|
}
|
|
63
74
|
}
|
package/readme.md
CHANGED
|
@@ -156,7 +156,7 @@ ReactDOM.render(
|
|
|
156
156
|
You need to be versed in both React and Threejs before rushing into this. If you are unsure about React consult the official [React docs](https://reactjs.org/docs/getting-started.html), especially [the section about hooks](https://reactjs.org/docs/hooks-reference.html). As for Threejs, make sure you at least glance over the following links:
|
|
157
157
|
|
|
158
158
|
1. Make sure you have a [basic grasp of Threejs](https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene). Keep that site open.
|
|
159
|
-
2. When you know what a scene is, a camera, mesh, geometry, material, fork the [demo above](https://github.com/
|
|
159
|
+
2. When you know what a scene is, a camera, mesh, geometry, material, fork the [demo above](https://github.com/pmndrs/react-three-fiber#what-does-it-look-like).
|
|
160
160
|
3. [Look up](https://threejs.org/docs/index.html#api/en/objects/Mesh) the JSX elements that you see (mesh, ambientLight, etc), _all_ threejs exports are native to three-fiber.
|
|
161
161
|
4. Try changing some values, scroll though our [Api](/markdown/api.md) to see what the various settings and hooks do.
|
|
162
162
|
|
|
@@ -171,15 +171,15 @@ Some reading material:
|
|
|
171
171
|
|
|
172
172
|
# Ecosystem
|
|
173
173
|
|
|
174
|
-
- [`@react-three/gltfjsx`](https://github.com/
|
|
175
|
-
- [`@react-three/drei`](https://github.com/
|
|
176
|
-
- [`@react-three/postprocessing`](https://github.com/
|
|
177
|
-
- [`@react-three/flex`](https://github.com/
|
|
178
|
-
- [`@react-three/xr`](https://github.com/
|
|
179
|
-
- [`@react-three/cannon`](https://github.com/
|
|
180
|
-
- [`zustand`](https://github.com/
|
|
181
|
-
- [`react-spring`](https://github.com/
|
|
182
|
-
- [`react-use-gesture`](https://github.com/
|
|
174
|
+
- [`@react-three/gltfjsx`](https://github.com/pmndrs/gltfjsx) – turns GLTFs into JSX components
|
|
175
|
+
- [`@react-three/drei`](https://github.com/pmndrs/drei) – useful helpers for react-three-fiber
|
|
176
|
+
- [`@react-three/postprocessing`](https://github.com/pmndrs/react-postprocessing) – post-processing effects
|
|
177
|
+
- [`@react-three/flex`](https://github.com/pmndrs/react-three-flex) – flexbox for react-three-fiber
|
|
178
|
+
- [`@react-three/xr`](https://github.com/pmndrs/react-xr) – VR/AR controllers and events
|
|
179
|
+
- [`@react-three/cannon`](https://github.com/pmndrs/use-cannon) – physics based hooks
|
|
180
|
+
- [`zustand`](https://github.com/pmndrs/zustand) – state management
|
|
181
|
+
- [`react-spring`](https://github.com/pmndrs/react-spring) – a spring-physics-based animation library
|
|
182
|
+
- [`react-use-gesture`](https://github.com/pmndrs/react-use-gesture) – mouse/touch gestures
|
|
183
183
|
|
|
184
184
|
# How to contribute
|
|
185
185
|
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
|
|
3
|
-
export default function useMeasure() {
|
|
4
|
-
const element = React.useRef<HTMLElement | null>(null)
|
|
5
|
-
const [bounds] = React.useState({
|
|
6
|
-
left: 0,
|
|
7
|
-
top: 0,
|
|
8
|
-
width: 1280,
|
|
9
|
-
height: 800,
|
|
10
|
-
bottom: 0,
|
|
11
|
-
right: 0,
|
|
12
|
-
x: 0,
|
|
13
|
-
y: 0,
|
|
14
|
-
})
|
|
15
|
-
const ref = (node: HTMLElement) => {
|
|
16
|
-
if (!node || element.current) {
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
element.current = node
|
|
20
|
-
}
|
|
21
|
-
return [ref, bounds]
|
|
22
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/// <reference types="react-reconciler" />
|
|
2
|
-
import * as THREE from 'three';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import { UseStore } from 'zustand';
|
|
5
|
-
import { StoreProps, context, RootState, Size } from '../core/store';
|
|
6
|
-
import { extend, Root } from '../core/renderer';
|
|
7
|
-
import { addEffect, addAfterEffect, addTail } from '../core/loop';
|
|
8
|
-
import { createPointerEvents as events } from './events';
|
|
9
|
-
import { Canvas } from './Canvas';
|
|
10
|
-
import { EventManager } from '../core/events';
|
|
11
|
-
declare const roots: Map<Element, Root>;
|
|
12
|
-
declare const invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined) => void;
|
|
13
|
-
declare const reconciler: import("react-reconciler").Reconciler<unknown, unknown, unknown, unknown, unknown>, applyProps: (instance: import("../core/renderer").Instance, newProps: import("../core/renderer").InstanceProps, oldProps?: import("../core/renderer").InstanceProps, accumulative?: boolean) => void;
|
|
14
|
-
export declare type RenderProps<TCanvas extends Element> = Omit<StoreProps, 'gl' | 'events' | 'size'> & {
|
|
15
|
-
gl?: THREE.WebGLRenderer | THREE.WebGLRendererParameters;
|
|
16
|
-
events?: (store: UseStore<RootState>) => EventManager<TCanvas>;
|
|
17
|
-
size?: Size;
|
|
18
|
-
onCreated?: (state: RootState) => void;
|
|
19
|
-
};
|
|
20
|
-
declare function render<TCanvas extends Element>(element: React.ReactNode, canvas: TCanvas, { gl, size, events, onCreated, ...props }?: RenderProps<TCanvas>): UseStore<RootState>;
|
|
21
|
-
declare function unmountComponentAtNode<TElement extends Element>(canvas: TElement, callback?: (canvas: TElement) => void): void;
|
|
22
|
-
declare function dispose<TObj extends {
|
|
23
|
-
dispose?: () => void;
|
|
24
|
-
type?: string;
|
|
25
|
-
[key: string]: any;
|
|
26
|
-
}>(obj: TObj): void;
|
|
27
|
-
declare const act: (callback: () => import("react-reconciler").Thenable<unknown>) => import("react-reconciler").Thenable<void>;
|
|
28
|
-
declare function createPortal(children: React.ReactNode, container: THREE.Object3D, implementation?: any, key?: any): React.ReactNode;
|
|
29
|
-
export * from '../core/hooks';
|
|
30
|
-
export { context, render, unmountComponentAtNode, createPortal, events, reconciler, applyProps, dispose, invalidate, advance, extend, addEffect, addAfterEffect, addTail, Canvas, act, roots as _roots, };
|