@react-three/fiber 8.0.0-beta-05 → 8.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/declarations/src/core/events.d.ts +14 -9
- package/dist/declarations/src/core/hooks.d.ts +5 -1
- package/dist/declarations/src/core/index.d.ts +23 -13
- package/dist/declarations/src/core/loop.d.ts +1 -1
- package/dist/declarations/src/core/renderer.d.ts +7 -6
- package/dist/declarations/src/core/store.d.ts +20 -33
- package/dist/declarations/src/core/utils.d.ts +10 -3
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/native/Canvas.d.ts +2 -2
- package/dist/declarations/src/native/events.d.ts +2 -2
- package/dist/declarations/src/native.d.ts +1 -0
- package/dist/declarations/src/three-types.d.ts +18 -0
- package/dist/declarations/src/web/Canvas.d.ts +2 -2
- package/dist/declarations/src/web/events.d.ts +2 -2
- package/dist/{index-95c17855.cjs.dev.js → index-012f96fe.cjs.dev.js} +507 -414
- package/dist/{index-3f4e5f46.esm.js → index-56b68682.esm.js} +505 -414
- package/dist/{index-ff8b5912.cjs.prod.js → index-8d2b9a82.cjs.prod.js} +507 -414
- package/dist/react-three-fiber.cjs.dev.js +37 -12
- package/dist/react-three-fiber.cjs.prod.js +37 -12
- package/dist/react-three-fiber.esm.js +36 -13
- package/native/dist/react-three-fiber-native.cjs.dev.js +39 -14
- package/native/dist/react-three-fiber-native.cjs.prod.js +39 -14
- package/native/dist/react-three-fiber-native.esm.js +37 -15
- package/package.json +10 -11
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-012f96fe.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
9
9
|
var mergeRefs = require('react-merge-refs');
|
|
10
10
|
var useMeasure = require('react-use-measure');
|
|
11
|
-
require('suspend-react');
|
|
12
11
|
require('react-reconciler/constants');
|
|
13
12
|
require('zustand');
|
|
14
13
|
require('react-reconciler');
|
|
15
14
|
require('scheduler');
|
|
15
|
+
require('suspend-react');
|
|
16
16
|
|
|
17
17
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
18
18
|
|
|
@@ -58,7 +58,17 @@ function createPointerEvents(store) {
|
|
|
58
58
|
handlePointer
|
|
59
59
|
} = index.createEvents(store);
|
|
60
60
|
return {
|
|
61
|
-
|
|
61
|
+
priority: 1,
|
|
62
|
+
enabled: true,
|
|
63
|
+
|
|
64
|
+
compute(event, state, previous) {
|
|
65
|
+
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
66
|
+
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
67
|
+
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
68
|
+
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
connected: undefined,
|
|
62
72
|
handlers: Object.keys(DOM_EVENTS).reduce((acc, key) => ({ ...acc,
|
|
63
73
|
[key]: handlePointer(key)
|
|
64
74
|
}), {}),
|
|
@@ -99,7 +109,7 @@ function createPointerEvents(store) {
|
|
|
99
109
|
});
|
|
100
110
|
set(state => ({
|
|
101
111
|
events: { ...state.events,
|
|
102
|
-
connected:
|
|
112
|
+
connected: undefined
|
|
103
113
|
}
|
|
104
114
|
}));
|
|
105
115
|
}
|
|
@@ -107,7 +117,7 @@ function createPointerEvents(store) {
|
|
|
107
117
|
};
|
|
108
118
|
}
|
|
109
119
|
|
|
110
|
-
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', '
|
|
120
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
111
121
|
|
|
112
122
|
function Block({
|
|
113
123
|
set
|
|
@@ -146,13 +156,14 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
146
156
|
fallback,
|
|
147
157
|
resize,
|
|
148
158
|
style,
|
|
149
|
-
events,
|
|
159
|
+
events = createPointerEvents,
|
|
150
160
|
...props
|
|
151
161
|
}, forwardedRef) {
|
|
152
162
|
// Create a known catalogue of Threejs-native elements
|
|
153
163
|
// This will include the entire THREE namespace by default, users can extend
|
|
154
164
|
// their own elements by using the createRoot API instead
|
|
155
165
|
React__namespace.useMemo(() => index.extend(THREE__namespace), []);
|
|
166
|
+
const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
|
|
156
167
|
const [containerRef, {
|
|
157
168
|
width,
|
|
158
169
|
height
|
|
@@ -164,25 +175,37 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
164
175
|
},
|
|
165
176
|
...resize
|
|
166
177
|
});
|
|
178
|
+
const meshRef = React__namespace.useRef(null);
|
|
167
179
|
const canvasRef = React__namespace.useRef(null);
|
|
168
180
|
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
169
|
-
const canvasProps = index.pick(props,
|
|
170
|
-
|
|
181
|
+
const canvasProps = index.pick({ ...props,
|
|
182
|
+
onPointerMissed
|
|
183
|
+
}, CANVAS_PROPS);
|
|
184
|
+
const divProps = index.omit({ ...props,
|
|
185
|
+
onPointerMissed
|
|
186
|
+
}, CANVAS_PROPS);
|
|
171
187
|
const [block, setBlock] = React__namespace.useState(false);
|
|
172
188
|
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
173
189
|
|
|
174
190
|
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
175
191
|
|
|
176
192
|
if (error) throw error;
|
|
193
|
+
const root = React__namespace.useRef(null);
|
|
177
194
|
|
|
178
195
|
if (width > 0 && height > 0 && canvas) {
|
|
179
|
-
index.createRoot(canvas
|
|
196
|
+
if (!root.current) root.current = index.createRoot(canvas);
|
|
197
|
+
root.current.configure({ ...canvasProps,
|
|
198
|
+
onCreated: state => {
|
|
199
|
+
state.events.connect == null ? void 0 : state.events.connect(meshRef.current);
|
|
200
|
+
canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
|
|
201
|
+
},
|
|
180
202
|
size: {
|
|
181
203
|
width,
|
|
182
204
|
height
|
|
183
205
|
},
|
|
184
|
-
events
|
|
185
|
-
})
|
|
206
|
+
events
|
|
207
|
+
});
|
|
208
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
186
209
|
set: setError
|
|
187
210
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
188
211
|
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
@@ -198,7 +221,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
198
221
|
return () => index.unmountComponentAtNode(canvas);
|
|
199
222
|
}, [canvas]);
|
|
200
223
|
return /*#__PURE__*/React__namespace.createElement("div", _extends({
|
|
201
|
-
ref: containerRef,
|
|
224
|
+
ref: mergeRefs__default['default']([meshRef, containerRef]),
|
|
202
225
|
style: {
|
|
203
226
|
position: 'relative',
|
|
204
227
|
width: '100%',
|
|
@@ -227,6 +250,7 @@ exports.createPortal = index.createPortal;
|
|
|
227
250
|
exports.createRoot = index.createRoot;
|
|
228
251
|
exports.dispose = index.dispose;
|
|
229
252
|
exports.extend = index.extend;
|
|
253
|
+
exports.getRootState = index.getRootState;
|
|
230
254
|
exports.invalidate = index.invalidate;
|
|
231
255
|
exports.reconciler = index.reconciler;
|
|
232
256
|
exports.render = index.render;
|
|
@@ -234,6 +258,7 @@ exports.unmountComponentAtNode = index.unmountComponentAtNode;
|
|
|
234
258
|
exports.useFrame = index.useFrame;
|
|
235
259
|
exports.useGraph = index.useGraph;
|
|
236
260
|
exports.useLoader = index.useLoader;
|
|
261
|
+
exports.useMemoizedFn = index.useMemoizedFn;
|
|
237
262
|
exports.useStore = index.useStore;
|
|
238
263
|
exports.useThree = index.useThree;
|
|
239
264
|
exports.Canvas = Canvas;
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-8d2b9a82.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
9
9
|
var mergeRefs = require('react-merge-refs');
|
|
10
10
|
var useMeasure = require('react-use-measure');
|
|
11
|
-
require('suspend-react');
|
|
12
11
|
require('react-reconciler/constants');
|
|
13
12
|
require('zustand');
|
|
14
13
|
require('react-reconciler');
|
|
15
14
|
require('scheduler');
|
|
15
|
+
require('suspend-react');
|
|
16
16
|
|
|
17
17
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
18
18
|
|
|
@@ -58,7 +58,17 @@ function createPointerEvents(store) {
|
|
|
58
58
|
handlePointer
|
|
59
59
|
} = index.createEvents(store);
|
|
60
60
|
return {
|
|
61
|
-
|
|
61
|
+
priority: 1,
|
|
62
|
+
enabled: true,
|
|
63
|
+
|
|
64
|
+
compute(event, state, previous) {
|
|
65
|
+
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
66
|
+
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
67
|
+
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
68
|
+
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
connected: undefined,
|
|
62
72
|
handlers: Object.keys(DOM_EVENTS).reduce((acc, key) => ({ ...acc,
|
|
63
73
|
[key]: handlePointer(key)
|
|
64
74
|
}), {}),
|
|
@@ -99,7 +109,7 @@ function createPointerEvents(store) {
|
|
|
99
109
|
});
|
|
100
110
|
set(state => ({
|
|
101
111
|
events: { ...state.events,
|
|
102
|
-
connected:
|
|
112
|
+
connected: undefined
|
|
103
113
|
}
|
|
104
114
|
}));
|
|
105
115
|
}
|
|
@@ -107,7 +117,7 @@ function createPointerEvents(store) {
|
|
|
107
117
|
};
|
|
108
118
|
}
|
|
109
119
|
|
|
110
|
-
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', '
|
|
120
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
111
121
|
|
|
112
122
|
function Block({
|
|
113
123
|
set
|
|
@@ -146,13 +156,14 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
146
156
|
fallback,
|
|
147
157
|
resize,
|
|
148
158
|
style,
|
|
149
|
-
events,
|
|
159
|
+
events = createPointerEvents,
|
|
150
160
|
...props
|
|
151
161
|
}, forwardedRef) {
|
|
152
162
|
// Create a known catalogue of Threejs-native elements
|
|
153
163
|
// This will include the entire THREE namespace by default, users can extend
|
|
154
164
|
// their own elements by using the createRoot API instead
|
|
155
165
|
React__namespace.useMemo(() => index.extend(THREE__namespace), []);
|
|
166
|
+
const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
|
|
156
167
|
const [containerRef, {
|
|
157
168
|
width,
|
|
158
169
|
height
|
|
@@ -164,25 +175,37 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
164
175
|
},
|
|
165
176
|
...resize
|
|
166
177
|
});
|
|
178
|
+
const meshRef = React__namespace.useRef(null);
|
|
167
179
|
const canvasRef = React__namespace.useRef(null);
|
|
168
180
|
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
169
|
-
const canvasProps = index.pick(props,
|
|
170
|
-
|
|
181
|
+
const canvasProps = index.pick({ ...props,
|
|
182
|
+
onPointerMissed
|
|
183
|
+
}, CANVAS_PROPS);
|
|
184
|
+
const divProps = index.omit({ ...props,
|
|
185
|
+
onPointerMissed
|
|
186
|
+
}, CANVAS_PROPS);
|
|
171
187
|
const [block, setBlock] = React__namespace.useState(false);
|
|
172
188
|
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
173
189
|
|
|
174
190
|
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
175
191
|
|
|
176
192
|
if (error) throw error;
|
|
193
|
+
const root = React__namespace.useRef(null);
|
|
177
194
|
|
|
178
195
|
if (width > 0 && height > 0 && canvas) {
|
|
179
|
-
index.createRoot(canvas
|
|
196
|
+
if (!root.current) root.current = index.createRoot(canvas);
|
|
197
|
+
root.current.configure({ ...canvasProps,
|
|
198
|
+
onCreated: state => {
|
|
199
|
+
state.events.connect == null ? void 0 : state.events.connect(meshRef.current);
|
|
200
|
+
canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
|
|
201
|
+
},
|
|
180
202
|
size: {
|
|
181
203
|
width,
|
|
182
204
|
height
|
|
183
205
|
},
|
|
184
|
-
events
|
|
185
|
-
})
|
|
206
|
+
events
|
|
207
|
+
});
|
|
208
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
186
209
|
set: setError
|
|
187
210
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
188
211
|
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
@@ -198,7 +221,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
198
221
|
return () => index.unmountComponentAtNode(canvas);
|
|
199
222
|
}, [canvas]);
|
|
200
223
|
return /*#__PURE__*/React__namespace.createElement("div", _extends({
|
|
201
|
-
ref: containerRef,
|
|
224
|
+
ref: mergeRefs__default['default']([meshRef, containerRef]),
|
|
202
225
|
style: {
|
|
203
226
|
position: 'relative',
|
|
204
227
|
width: '100%',
|
|
@@ -227,6 +250,7 @@ exports.createPortal = index.createPortal;
|
|
|
227
250
|
exports.createRoot = index.createRoot;
|
|
228
251
|
exports.dispose = index.dispose;
|
|
229
252
|
exports.extend = index.extend;
|
|
253
|
+
exports.getRootState = index.getRootState;
|
|
230
254
|
exports.invalidate = index.invalidate;
|
|
231
255
|
exports.reconciler = index.reconciler;
|
|
232
256
|
exports.render = index.render;
|
|
@@ -234,6 +258,7 @@ exports.unmountComponentAtNode = index.unmountComponentAtNode;
|
|
|
234
258
|
exports.useFrame = index.useFrame;
|
|
235
259
|
exports.useGraph = index.useGraph;
|
|
236
260
|
exports.useLoader = index.useLoader;
|
|
261
|
+
exports.useMemoizedFn = index.useMemoizedFn;
|
|
237
262
|
exports.useStore = index.useStore;
|
|
238
263
|
exports.useThree = index.useThree;
|
|
239
264
|
exports.Canvas = Canvas;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { c as createEvents, e as extend, p as pick, o as omit, a as createRoot,
|
|
2
|
-
export { t as ReactThreeFiber,
|
|
1
|
+
import { c as createEvents, e as extend, u as useMemoizedFn, p as pick, o as omit, a as createRoot, b as unmountComponentAtNode } from './index-56b68682.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, v as _roots, s as act, m as addAfterEffect, l as addEffect, n as addTail, k as advance, h as applyProps, d as context, f as createPortal, a as createRoot, i as dispose, e as extend, q as getRootState, j as invalidate, g as reconciler, r as render, b as unmountComponentAtNode, y as useFrame, z as useGraph, A as useLoader, u as useMemoizedFn, w as useStore, x as useThree } from './index-56b68682.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
6
|
import mergeRefs from 'react-merge-refs';
|
|
7
7
|
import useMeasure from 'react-use-measure';
|
|
8
|
-
import 'suspend-react';
|
|
9
8
|
import 'react-reconciler/constants';
|
|
10
9
|
import 'zustand';
|
|
11
10
|
import 'react-reconciler';
|
|
12
11
|
import 'scheduler';
|
|
12
|
+
import 'suspend-react';
|
|
13
13
|
|
|
14
14
|
const DOM_EVENTS = {
|
|
15
15
|
onClick: ['click', false],
|
|
@@ -28,7 +28,17 @@ function createPointerEvents(store) {
|
|
|
28
28
|
handlePointer
|
|
29
29
|
} = createEvents(store);
|
|
30
30
|
return {
|
|
31
|
-
|
|
31
|
+
priority: 1,
|
|
32
|
+
enabled: true,
|
|
33
|
+
|
|
34
|
+
compute(event, state, previous) {
|
|
35
|
+
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
36
|
+
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
37
|
+
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
38
|
+
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
connected: undefined,
|
|
32
42
|
handlers: Object.keys(DOM_EVENTS).reduce((acc, key) => ({ ...acc,
|
|
33
43
|
[key]: handlePointer(key)
|
|
34
44
|
}), {}),
|
|
@@ -69,7 +79,7 @@ function createPointerEvents(store) {
|
|
|
69
79
|
});
|
|
70
80
|
set(state => ({
|
|
71
81
|
events: { ...state.events,
|
|
72
|
-
connected:
|
|
82
|
+
connected: undefined
|
|
73
83
|
}
|
|
74
84
|
}));
|
|
75
85
|
}
|
|
@@ -77,7 +87,7 @@ function createPointerEvents(store) {
|
|
|
77
87
|
};
|
|
78
88
|
}
|
|
79
89
|
|
|
80
|
-
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', '
|
|
90
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
81
91
|
|
|
82
92
|
function Block({
|
|
83
93
|
set
|
|
@@ -116,13 +126,14 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
116
126
|
fallback,
|
|
117
127
|
resize,
|
|
118
128
|
style,
|
|
119
|
-
events,
|
|
129
|
+
events = createPointerEvents,
|
|
120
130
|
...props
|
|
121
131
|
}, forwardedRef) {
|
|
122
132
|
// Create a known catalogue of Threejs-native elements
|
|
123
133
|
// This will include the entire THREE namespace by default, users can extend
|
|
124
134
|
// their own elements by using the createRoot API instead
|
|
125
135
|
React.useMemo(() => extend(THREE), []);
|
|
136
|
+
const onPointerMissed = useMemoizedFn(props.onPointerMissed);
|
|
126
137
|
const [containerRef, {
|
|
127
138
|
width,
|
|
128
139
|
height
|
|
@@ -134,25 +145,37 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
134
145
|
},
|
|
135
146
|
...resize
|
|
136
147
|
});
|
|
148
|
+
const meshRef = React.useRef(null);
|
|
137
149
|
const canvasRef = React.useRef(null);
|
|
138
150
|
const [canvas, setCanvas] = React.useState(null);
|
|
139
|
-
const canvasProps = pick(props,
|
|
140
|
-
|
|
151
|
+
const canvasProps = pick({ ...props,
|
|
152
|
+
onPointerMissed
|
|
153
|
+
}, CANVAS_PROPS);
|
|
154
|
+
const divProps = omit({ ...props,
|
|
155
|
+
onPointerMissed
|
|
156
|
+
}, CANVAS_PROPS);
|
|
141
157
|
const [block, setBlock] = React.useState(false);
|
|
142
158
|
const [error, setError] = React.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
143
159
|
|
|
144
160
|
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
145
161
|
|
|
146
162
|
if (error) throw error;
|
|
163
|
+
const root = React.useRef(null);
|
|
147
164
|
|
|
148
165
|
if (width > 0 && height > 0 && canvas) {
|
|
149
|
-
createRoot(canvas
|
|
166
|
+
if (!root.current) root.current = createRoot(canvas);
|
|
167
|
+
root.current.configure({ ...canvasProps,
|
|
168
|
+
onCreated: state => {
|
|
169
|
+
state.events.connect == null ? void 0 : state.events.connect(meshRef.current);
|
|
170
|
+
canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
|
|
171
|
+
},
|
|
150
172
|
size: {
|
|
151
173
|
width,
|
|
152
174
|
height
|
|
153
175
|
},
|
|
154
|
-
events
|
|
155
|
-
})
|
|
176
|
+
events
|
|
177
|
+
});
|
|
178
|
+
root.current.render( /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
156
179
|
set: setError
|
|
157
180
|
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
158
181
|
fallback: /*#__PURE__*/React.createElement(Block, {
|
|
@@ -168,7 +191,7 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
168
191
|
return () => unmountComponentAtNode(canvas);
|
|
169
192
|
}, [canvas]);
|
|
170
193
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
171
|
-
ref: containerRef,
|
|
194
|
+
ref: mergeRefs([meshRef, containerRef]),
|
|
172
195
|
style: {
|
|
173
196
|
position: 'relative',
|
|
174
197
|
width: '100%',
|
|
@@ -4,17 +4,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var THREE = require('three');
|
|
6
6
|
var expoAsset = require('expo-asset');
|
|
7
|
-
var index = require('../../dist/index-
|
|
7
|
+
var index = require('../../dist/index-012f96fe.cjs.dev.js');
|
|
8
8
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
9
9
|
var React = require('react');
|
|
10
|
+
var mergeRefs = require('react-merge-refs');
|
|
10
11
|
var reactNative = require('react-native');
|
|
11
12
|
var expoGl = require('expo-gl');
|
|
12
13
|
var Pressability = require('react-native/Libraries/Pressability/Pressability');
|
|
13
|
-
require('suspend-react');
|
|
14
14
|
require('react-reconciler/constants');
|
|
15
15
|
require('zustand');
|
|
16
16
|
require('react-reconciler');
|
|
17
17
|
require('scheduler');
|
|
18
|
+
require('suspend-react');
|
|
18
19
|
|
|
19
20
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
20
21
|
|
|
@@ -40,6 +41,7 @@ function _interopNamespace(e) {
|
|
|
40
41
|
|
|
41
42
|
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
42
43
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
44
|
+
var mergeRefs__default = /*#__PURE__*/_interopDefault(mergeRefs);
|
|
43
45
|
var Pressability__default = /*#__PURE__*/_interopDefault(Pressability);
|
|
44
46
|
|
|
45
47
|
const EVENTS = {
|
|
@@ -76,7 +78,17 @@ function createTouchEvents(store) {
|
|
|
76
78
|
};
|
|
77
79
|
|
|
78
80
|
return {
|
|
79
|
-
|
|
81
|
+
priority: 1,
|
|
82
|
+
enabled: true,
|
|
83
|
+
|
|
84
|
+
compute(event, state, previous) {
|
|
85
|
+
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
86
|
+
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
87
|
+
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
88
|
+
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
connected: undefined,
|
|
80
92
|
handlers: Object.values(EVENTS).reduce((acc, name) => ({ ...acc,
|
|
81
93
|
[name]: event => handleTouch(event, name)
|
|
82
94
|
}), {}),
|
|
@@ -105,7 +117,7 @@ function createTouchEvents(store) {
|
|
|
105
117
|
events.connected.reset();
|
|
106
118
|
set(state => ({
|
|
107
119
|
events: { ...state.events,
|
|
108
|
-
connected:
|
|
120
|
+
connected: undefined
|
|
109
121
|
}
|
|
110
122
|
}));
|
|
111
123
|
}
|
|
@@ -113,7 +125,7 @@ function createTouchEvents(store) {
|
|
|
113
125
|
};
|
|
114
126
|
}
|
|
115
127
|
|
|
116
|
-
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'performance', '
|
|
128
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
117
129
|
|
|
118
130
|
function Block({
|
|
119
131
|
set
|
|
@@ -158,6 +170,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
158
170
|
// This will include the entire THREE namespace by default, users can extend
|
|
159
171
|
// their own elements by using the createRoot API instead
|
|
160
172
|
React__namespace.useMemo(() => index.extend(THREE__namespace), []);
|
|
173
|
+
const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
|
|
161
174
|
const [{
|
|
162
175
|
width,
|
|
163
176
|
height
|
|
@@ -167,14 +180,20 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
167
180
|
});
|
|
168
181
|
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
169
182
|
const [bind, setBind] = React__namespace.useState();
|
|
170
|
-
const canvasProps = index.pick(props,
|
|
171
|
-
|
|
183
|
+
const canvasProps = index.pick({ ...props,
|
|
184
|
+
onPointerMissed
|
|
185
|
+
}, CANVAS_PROPS);
|
|
186
|
+
const viewProps = index.omit({ ...props,
|
|
187
|
+
onPointerMissed
|
|
188
|
+
}, CANVAS_PROPS);
|
|
172
189
|
const [block, setBlock] = React__namespace.useState(false);
|
|
173
190
|
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
174
191
|
|
|
175
192
|
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
176
193
|
|
|
177
194
|
if (error) throw error;
|
|
195
|
+
const viewRef = React__namespace.useRef(null);
|
|
196
|
+
const root = React__namespace.useRef(null);
|
|
178
197
|
const onLayout = React__namespace.useCallback(e => {
|
|
179
198
|
const {
|
|
180
199
|
width,
|
|
@@ -199,10 +218,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
199
218
|
}, []);
|
|
200
219
|
|
|
201
220
|
if (width > 0 && height > 0 && canvas) {
|
|
202
|
-
// Overwrite onCreated to apply RN bindings
|
|
221
|
+
if (!root.current) root.current = index.createRoot(canvas); // Overwrite onCreated to apply RN bindings
|
|
222
|
+
|
|
203
223
|
const onCreated = state => {
|
|
204
224
|
// Bind events after creation
|
|
205
|
-
const handlers = state.events.connect == null ? void 0 : state.events.connect(
|
|
225
|
+
const handlers = state.events.connect == null ? void 0 : state.events.connect(viewRef.current);
|
|
206
226
|
setBind(handlers); // Bind render to RN bridge
|
|
207
227
|
|
|
208
228
|
const context = state.gl.getContext();
|
|
@@ -216,7 +236,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
216
236
|
return canvasProps == null ? void 0 : canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
|
|
217
237
|
};
|
|
218
238
|
|
|
219
|
-
|
|
239
|
+
root.current.configure({ ...canvasProps,
|
|
220
240
|
// expo-gl can only render at native dpr/resolution
|
|
221
241
|
// https://github.com/expo/expo-three/issues/39
|
|
222
242
|
dpr: reactNative.PixelRatio.get(),
|
|
@@ -226,7 +246,8 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
226
246
|
},
|
|
227
247
|
events: events || createTouchEvents,
|
|
228
248
|
onCreated
|
|
229
|
-
})
|
|
249
|
+
});
|
|
250
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
230
251
|
set: setError
|
|
231
252
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
232
253
|
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
@@ -239,7 +260,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
239
260
|
return () => index.unmountComponentAtNode(canvas);
|
|
240
261
|
}, [canvas]);
|
|
241
262
|
return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, viewProps, {
|
|
242
|
-
ref: forwardedRef,
|
|
263
|
+
ref: mergeRefs__default['default']([viewRef, forwardedRef]),
|
|
243
264
|
onLayout: onLayout,
|
|
244
265
|
style: {
|
|
245
266
|
flex: 1,
|
|
@@ -271,11 +292,13 @@ const getAsset = input => {
|
|
|
271
292
|
}; // Don't pre-process urls, let expo-asset generate an absolute URL
|
|
272
293
|
|
|
273
294
|
|
|
274
|
-
THREE__namespace.LoaderUtils.extractUrlBase
|
|
295
|
+
const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
|
|
296
|
+
|
|
297
|
+
THREE__namespace.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './'; // There's no Image in native, so create a data texture instead
|
|
275
298
|
|
|
276
299
|
|
|
277
300
|
THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
278
|
-
const texture = new THREE__namespace.Texture(); // @ts-
|
|
301
|
+
const texture = new THREE__namespace.Texture(); // @ts-ignore
|
|
279
302
|
|
|
280
303
|
texture.isDataTexture = true;
|
|
281
304
|
getAsset(url).downloadAsync().then(asset => {
|
|
@@ -345,6 +368,7 @@ exports.createPortal = index.createPortal;
|
|
|
345
368
|
exports.createRoot = index.createRoot;
|
|
346
369
|
exports.dispose = index.dispose;
|
|
347
370
|
exports.extend = index.extend;
|
|
371
|
+
exports.getRootState = index.getRootState;
|
|
348
372
|
exports.invalidate = index.invalidate;
|
|
349
373
|
exports.reconciler = index.reconciler;
|
|
350
374
|
exports.render = index.render;
|
|
@@ -352,6 +376,7 @@ exports.unmountComponentAtNode = index.unmountComponentAtNode;
|
|
|
352
376
|
exports.useFrame = index.useFrame;
|
|
353
377
|
exports.useGraph = index.useGraph;
|
|
354
378
|
exports.useLoader = index.useLoader;
|
|
379
|
+
exports.useMemoizedFn = index.useMemoizedFn;
|
|
355
380
|
exports.useStore = index.useStore;
|
|
356
381
|
exports.useThree = index.useThree;
|
|
357
382
|
exports.Canvas = Canvas;
|