@react-three/fiber 9.0.0-rc.4 → 9.0.0-rc.6
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 +1 -1
- package/dist/declarations/src/core/renderer.d.ts +5 -3
- package/dist/declarations/src/core/utils.d.ts +1 -0
- package/dist/declarations/src/web/Canvas.d.ts +1 -1
- package/dist/{events-64d1e225.esm.js → events-06bc1550.esm.js} +78 -65
- package/dist/{events-c2452172.cjs.dev.js → events-4464c9d4.cjs.dev.js} +77 -65
- package/dist/{events-484fb9c5.cjs.prod.js → events-79ccf613.cjs.prod.js} +77 -65
- package/dist/react-three-fiber.cjs.dev.js +51 -243
- package/dist/react-three-fiber.cjs.prod.js +51 -243
- package/dist/react-three-fiber.esm.js +50 -242
- package/native/dist/react-three-fiber-native.cjs.dev.js +54 -50
- package/native/dist/react-three-fiber-native.cjs.prod.js +54 -50
- package/native/dist/react-three-fiber-native.esm.js +55 -50
- package/package.json +2 -3
- package/dist/declarations/src/web/use-measure.d.ts +0 -34
package/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,7 @@ export { flushGlobalEffects, addEffect, addAfterEffect, addTail, invalidate, adv
|
|
|
6
6
|
export type { AttachFnType, AttachType, ConstructorRepresentation, Catalogue, Args, InstanceProps, Instance, } from "./reconciler.js";
|
|
7
7
|
export { extend, reconciler } from "./reconciler.js";
|
|
8
8
|
export type { ReconcilerRoot, GLProps, CameraProps, RenderProps, InjectState } from "./renderer.js";
|
|
9
|
-
export { _roots,
|
|
9
|
+
export { _roots, createRoot, unmountComponentAtNode, createPortal } from "./renderer.js";
|
|
10
10
|
export type { Subscription, Dpr, Size, Viewport, RenderCallback, Frameloop, Performance, Renderer, XRManager, RootState, RootStore, } from "./store.js";
|
|
11
11
|
export { context } from "./store.js";
|
|
12
12
|
export type { ObjectMap, Camera, Disposable, Act } from "./utils.js";
|
|
@@ -8,7 +8,10 @@ import { type Properties, Camera } from "./utils.js";
|
|
|
8
8
|
interface OffscreenCanvas extends EventTarget {
|
|
9
9
|
}
|
|
10
10
|
export declare const _roots: Map<HTMLCanvasElement | OffscreenCanvas, Root>;
|
|
11
|
-
export type
|
|
11
|
+
export type DefaultGLProps = Omit<THREE.WebGLRendererParameters, 'canvas'> & {
|
|
12
|
+
canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
13
|
+
};
|
|
14
|
+
export type GLProps = Renderer | ((defaultProps: DefaultGLProps) => Renderer) | ((defaultProps: DefaultGLProps) => Promise<Renderer>) | Partial<Properties<THREE.WebGLRenderer> | THREE.WebGLRendererParameters>;
|
|
12
15
|
export type CameraProps = (Camera | Partial<ThreeElement<typeof THREE.Camera> & ThreeElement<typeof THREE.PerspectiveCamera> & ThreeElement<typeof THREE.OrthographicCamera>>) & {
|
|
13
16
|
/** Flags the camera as manual, putting projection into your own hands */
|
|
14
17
|
manual?: boolean;
|
|
@@ -61,12 +64,11 @@ export interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas
|
|
|
61
64
|
onPointerMissed?: (event: MouseEvent) => void;
|
|
62
65
|
}
|
|
63
66
|
export interface ReconcilerRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas> {
|
|
64
|
-
configure: (config?: RenderProps<TCanvas>) => ReconcilerRoot<TCanvas
|
|
67
|
+
configure: (config?: RenderProps<TCanvas>) => Promise<ReconcilerRoot<TCanvas>>;
|
|
65
68
|
render: (element: React.ReactNode) => RootStore;
|
|
66
69
|
unmount: () => void;
|
|
67
70
|
}
|
|
68
71
|
export declare function createRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas>(canvas: TCanvas): ReconcilerRoot<TCanvas>;
|
|
69
|
-
export declare function render<TCanvas extends HTMLCanvasElement | OffscreenCanvas>(children: React.ReactNode, canvas: TCanvas, config: RenderProps<TCanvas>): RootStore;
|
|
70
72
|
export declare function unmountComponentAtNode<TCanvas extends HTMLCanvasElement | OffscreenCanvas>(canvas: TCanvas, callback?: (canvas: TCanvas) => void): void;
|
|
71
73
|
export type InjectState = Partial<Omit<RootState, 'events'> & {
|
|
72
74
|
events?: {
|
|
@@ -158,6 +158,7 @@ export declare const is: {
|
|
|
158
158
|
num: (a: any) => a is number;
|
|
159
159
|
boo: (a: any) => a is boolean;
|
|
160
160
|
und: (a: any) => boolean;
|
|
161
|
+
nul: (a: any) => boolean;
|
|
161
162
|
arr: (a: any) => boolean;
|
|
162
163
|
equ(a: any, b: any, { arrays, objects, strict }?: EquConfig): boolean;
|
|
163
164
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Options as ResizeOptions } from
|
|
2
|
+
import { Options as ResizeOptions } from 'react-use-measure';
|
|
3
3
|
import { RenderProps } from "../core/index.js";
|
|
4
4
|
export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'size'>, React.HTMLAttributes<HTMLDivElement> {
|
|
5
5
|
children: React.ReactNode;
|
|
@@ -110,6 +110,7 @@ const is = {
|
|
|
110
110
|
num: a => typeof a === 'number',
|
|
111
111
|
boo: a => typeof a === 'boolean',
|
|
112
112
|
und: a => a === void 0,
|
|
113
|
+
nul: a => a === null,
|
|
113
114
|
arr: a => Array.isArray(a),
|
|
114
115
|
equ(a, b, {
|
|
115
116
|
arrays = 'shallow',
|
|
@@ -203,10 +204,7 @@ function prepare(target, root, type, props) {
|
|
|
203
204
|
handlers: {},
|
|
204
205
|
isHidden: false
|
|
205
206
|
};
|
|
206
|
-
if (object)
|
|
207
|
-
object.__r3f = instance;
|
|
208
|
-
if (type) applyProps(object, instance.props);
|
|
209
|
-
}
|
|
207
|
+
if (object) object.__r3f = instance;
|
|
210
208
|
}
|
|
211
209
|
return instance;
|
|
212
210
|
}
|
|
@@ -278,6 +276,18 @@ const RESERVED_PROPS = [...REACT_INTERNAL_PROPS,
|
|
|
278
276
|
// Behavior flags
|
|
279
277
|
'dispose'];
|
|
280
278
|
const MEMOIZED_PROTOTYPES = new Map();
|
|
279
|
+
function getMemoizedPrototype(root) {
|
|
280
|
+
let ctor = MEMOIZED_PROTOTYPES.get(root.constructor);
|
|
281
|
+
try {
|
|
282
|
+
if (!ctor) {
|
|
283
|
+
ctor = new root.constructor();
|
|
284
|
+
MEMOIZED_PROTOTYPES.set(root.constructor, ctor);
|
|
285
|
+
}
|
|
286
|
+
} catch (e) {
|
|
287
|
+
// ...
|
|
288
|
+
}
|
|
289
|
+
return ctor;
|
|
290
|
+
}
|
|
281
291
|
|
|
282
292
|
// This function prepares a set of changes to be applied to the instance
|
|
283
293
|
function diffProps(instance, newProps) {
|
|
@@ -314,12 +324,8 @@ function diffProps(instance, newProps) {
|
|
|
314
324
|
// For removed props, try to set default values, if possible
|
|
315
325
|
if (root.constructor && root.constructor.length === 0) {
|
|
316
326
|
// create a blank slate of the instance and copy the particular parameter.
|
|
317
|
-
|
|
318
|
-
if (!ctor)
|
|
319
|
-
ctor = new root.constructor();
|
|
320
|
-
MEMOIZED_PROTOTYPES.set(root.constructor, ctor);
|
|
321
|
-
}
|
|
322
|
-
changedProps[key] = ctor[key];
|
|
327
|
+
const ctor = getMemoizedPrototype(root);
|
|
328
|
+
if (!is.und(ctor)) changedProps[key] = ctor[key];
|
|
323
329
|
} else {
|
|
324
330
|
// instance does not have constructor, just set it to 0
|
|
325
331
|
changedProps[key] = 0;
|
|
@@ -361,7 +367,13 @@ function applyProps(object, props) {
|
|
|
361
367
|
|
|
362
368
|
// Copy if properties match signatures
|
|
363
369
|
if (target != null && target.copy && value != null && value.constructor && target.constructor === value.constructor) {
|
|
364
|
-
target
|
|
370
|
+
// fetch the default state of the target
|
|
371
|
+
const ctor = getMemoizedPrototype(root);
|
|
372
|
+
// The target key was originally null or undefined, which indicates that the object which
|
|
373
|
+
// is now present was externally set by the user, we should therefore assign the value directly
|
|
374
|
+
if (!is.und(ctor) && (is.und(ctor[key]) || is.nul(ctor[key]))) root[key] = value;
|
|
375
|
+
// Otherwise copy is correct
|
|
376
|
+
else target.copy(value);
|
|
365
377
|
}
|
|
366
378
|
// Layers have no copy function, we must therefore copy the mask property
|
|
367
379
|
else if (target instanceof THREE.Layers && value instanceof THREE.Layers) {
|
|
@@ -1059,7 +1071,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1059
1071
|
oldDpr = viewport.dpr;
|
|
1060
1072
|
// Update camera & renderer
|
|
1061
1073
|
updateCamera(camera, size);
|
|
1062
|
-
gl.setPixelRatio(viewport.dpr);
|
|
1074
|
+
if (viewport.dpr > 0) gl.setPixelRatio(viewport.dpr);
|
|
1063
1075
|
const updateStyle = typeof HTMLCanvasElement !== 'undefined' && gl.domElement instanceof HTMLCanvasElement;
|
|
1064
1076
|
gl.setSize(size.width, size.height, updateStyle);
|
|
1065
1077
|
}
|
|
@@ -1294,11 +1306,11 @@ function handleContainerEffects(parent, child, beforeChild) {
|
|
|
1294
1306
|
// Create object
|
|
1295
1307
|
child.object = (_child$props$object = child.props.object) != null ? _child$props$object : new target(...((_child$props$args = child.props.args) != null ? _child$props$args : []));
|
|
1296
1308
|
child.object.__r3f = child;
|
|
1297
|
-
|
|
1298
|
-
// Set initial props
|
|
1299
|
-
applyProps(child.object, child.props);
|
|
1300
1309
|
}
|
|
1301
1310
|
|
|
1311
|
+
// Set initial props
|
|
1312
|
+
applyProps(child.object, child.props);
|
|
1313
|
+
|
|
1302
1314
|
// Append instance
|
|
1303
1315
|
if (child.props.attach) {
|
|
1304
1316
|
attach(parent, child);
|
|
@@ -1310,7 +1322,6 @@ function handleContainerEffects(parent, child, beforeChild) {
|
|
|
1310
1322
|
child.object.dispatchEvent({
|
|
1311
1323
|
type: 'added'
|
|
1312
1324
|
});
|
|
1313
|
-
// @ts-expect-error https://github.com/mrdoob/three.js/pull/16934
|
|
1314
1325
|
parent.object.dispatchEvent({
|
|
1315
1326
|
type: 'childadded',
|
|
1316
1327
|
child: child.object
|
|
@@ -1626,17 +1637,20 @@ const shallowLoose = {
|
|
|
1626
1637
|
objects: 'shallow',
|
|
1627
1638
|
strict: false
|
|
1628
1639
|
};
|
|
1629
|
-
|
|
1630
|
-
const
|
|
1631
|
-
if (isRenderer(customRenderer)) return customRenderer;
|
|
1632
|
-
return new THREE.WebGLRenderer({
|
|
1633
|
-
powerPreference: 'high-performance',
|
|
1640
|
+
async function createRendererInstance(gl, canvas) {
|
|
1641
|
+
const defaultProps = {
|
|
1634
1642
|
canvas: canvas,
|
|
1643
|
+
powerPreference: 'high-performance',
|
|
1635
1644
|
antialias: true,
|
|
1636
|
-
alpha: true
|
|
1645
|
+
alpha: true
|
|
1646
|
+
};
|
|
1647
|
+
const customRenderer = typeof gl === 'function' ? await gl(defaultProps) : gl;
|
|
1648
|
+
if (isRenderer(customRenderer)) return customRenderer;
|
|
1649
|
+
return new THREE.WebGLRenderer({
|
|
1650
|
+
...defaultProps,
|
|
1637
1651
|
...gl
|
|
1638
1652
|
});
|
|
1639
|
-
}
|
|
1653
|
+
}
|
|
1640
1654
|
function computeInitialSize(canvas, size) {
|
|
1641
1655
|
if (!size && typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
|
|
1642
1656
|
const {
|
|
@@ -1717,7 +1731,7 @@ function createRoot(canvas) {
|
|
|
1717
1731
|
let configured = false;
|
|
1718
1732
|
let lastCamera;
|
|
1719
1733
|
return {
|
|
1720
|
-
configure(props = {}) {
|
|
1734
|
+
async configure(props = {}) {
|
|
1721
1735
|
let {
|
|
1722
1736
|
gl: glConfig,
|
|
1723
1737
|
size: propsSize,
|
|
@@ -1741,7 +1755,7 @@ function createRoot(canvas) {
|
|
|
1741
1755
|
// Set up renderer (one time only!)
|
|
1742
1756
|
let gl = state.gl;
|
|
1743
1757
|
if (!state.gl) state.set({
|
|
1744
|
-
gl: gl = createRendererInstance(glConfig, canvas)
|
|
1758
|
+
gl: gl = await createRendererInstance(glConfig, canvas)
|
|
1745
1759
|
});
|
|
1746
1760
|
|
|
1747
1761
|
// Set up raycaster (one time only!)
|
|
@@ -1811,6 +1825,31 @@ function createRoot(canvas) {
|
|
|
1811
1825
|
});
|
|
1812
1826
|
}
|
|
1813
1827
|
|
|
1828
|
+
// Store events internally
|
|
1829
|
+
if (events && !state.events.handlers) state.set({
|
|
1830
|
+
events: events(store)
|
|
1831
|
+
});
|
|
1832
|
+
// Check size, allow it to take on container bounds initially
|
|
1833
|
+
const size = computeInitialSize(canvas, propsSize);
|
|
1834
|
+
if (!is.equ(size, state.size, shallowLoose)) {
|
|
1835
|
+
state.setSize(size.width, size.height, size.top, size.left);
|
|
1836
|
+
}
|
|
1837
|
+
// Check pixelratio
|
|
1838
|
+
if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr);
|
|
1839
|
+
// Check frameloop
|
|
1840
|
+
if (state.frameloop !== frameloop) state.setFrameloop(frameloop);
|
|
1841
|
+
// Check pointer missed
|
|
1842
|
+
if (!state.onPointerMissed) state.set({
|
|
1843
|
+
onPointerMissed
|
|
1844
|
+
});
|
|
1845
|
+
// Check performance
|
|
1846
|
+
if (performance && !is.equ(performance, state.performance, shallowLoose)) state.set(state => ({
|
|
1847
|
+
performance: {
|
|
1848
|
+
...state.performance,
|
|
1849
|
+
...performance
|
|
1850
|
+
}
|
|
1851
|
+
}));
|
|
1852
|
+
|
|
1814
1853
|
// Set up XR (one time only!)
|
|
1815
1854
|
if (!state.xr) {
|
|
1816
1855
|
var _gl$xr;
|
|
@@ -1892,30 +1931,6 @@ function createRoot(canvas) {
|
|
|
1892
1931
|
|
|
1893
1932
|
// Set gl props
|
|
1894
1933
|
if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, gl, shallowLoose)) applyProps(gl, glConfig);
|
|
1895
|
-
// Store events internally
|
|
1896
|
-
if (events && !state.events.handlers) state.set({
|
|
1897
|
-
events: events(store)
|
|
1898
|
-
});
|
|
1899
|
-
// Check size, allow it to take on container bounds initially
|
|
1900
|
-
const size = computeInitialSize(canvas, propsSize);
|
|
1901
|
-
if (!is.equ(size, state.size, shallowLoose)) {
|
|
1902
|
-
state.setSize(size.width, size.height, size.top, size.left);
|
|
1903
|
-
}
|
|
1904
|
-
// Check pixelratio
|
|
1905
|
-
if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr);
|
|
1906
|
-
// Check frameloop
|
|
1907
|
-
if (state.frameloop !== frameloop) state.setFrameloop(frameloop);
|
|
1908
|
-
// Check pointer missed
|
|
1909
|
-
if (!state.onPointerMissed) state.set({
|
|
1910
|
-
onPointerMissed
|
|
1911
|
-
});
|
|
1912
|
-
// Check performance
|
|
1913
|
-
if (performance && !is.equ(performance, state.performance, shallowLoose)) state.set(state => ({
|
|
1914
|
-
performance: {
|
|
1915
|
-
...state.performance,
|
|
1916
|
-
...performance
|
|
1917
|
-
}
|
|
1918
|
-
}));
|
|
1919
1934
|
|
|
1920
1935
|
// Set locals
|
|
1921
1936
|
onCreated = onCreatedCallback;
|
|
@@ -1924,7 +1939,7 @@ function createRoot(canvas) {
|
|
|
1924
1939
|
},
|
|
1925
1940
|
render(children) {
|
|
1926
1941
|
// The root has to be configured before it can be rendered
|
|
1927
|
-
if (!configured)
|
|
1942
|
+
if (!configured) throw "The root has to be configured before it can be rendered, call 'configure' first!";
|
|
1928
1943
|
reconciler.updateContainer( /*#__PURE__*/jsx(Provider, {
|
|
1929
1944
|
store: store,
|
|
1930
1945
|
children: children,
|
|
@@ -1938,12 +1953,6 @@ function createRoot(canvas) {
|
|
|
1938
1953
|
}
|
|
1939
1954
|
};
|
|
1940
1955
|
}
|
|
1941
|
-
function render(children, canvas, config) {
|
|
1942
|
-
console.warn('R3F.render is no longer supported in React 18. Use createRoot instead!');
|
|
1943
|
-
const root = createRoot(canvas);
|
|
1944
|
-
root.configure(config);
|
|
1945
|
-
return root.render(children);
|
|
1946
|
-
}
|
|
1947
1956
|
function Provider({
|
|
1948
1957
|
store,
|
|
1949
1958
|
children,
|
|
@@ -2081,12 +2090,16 @@ function Portal({
|
|
|
2081
2090
|
return store;
|
|
2082
2091
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2083
2092
|
}, [previousRoot, container]);
|
|
2084
|
-
return
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2093
|
+
return (
|
|
2094
|
+
/*#__PURE__*/
|
|
2095
|
+
// @ts-ignore, reconciler types are not maintained
|
|
2096
|
+
jsx(Fragment, {
|
|
2097
|
+
children: reconciler.createPortal( /*#__PURE__*/jsx(context.Provider, {
|
|
2098
|
+
value: usePortalStore,
|
|
2099
|
+
children: children
|
|
2100
|
+
}), usePortalStore, null)
|
|
2101
|
+
})
|
|
2102
|
+
);
|
|
2090
2103
|
}
|
|
2091
2104
|
|
|
2092
2105
|
function createSubs(callback, subs) {
|
|
@@ -2186,7 +2199,7 @@ function loop(timestamp) {
|
|
|
2186
2199
|
repeat += update(timestamp, state);
|
|
2187
2200
|
}
|
|
2188
2201
|
}
|
|
2189
|
-
useFrameInProgress =
|
|
2202
|
+
useFrameInProgress = false;
|
|
2190
2203
|
|
|
2191
2204
|
// Run after-effects
|
|
2192
2205
|
flushGlobalEffects('after', timestamp);
|
|
@@ -2265,7 +2278,7 @@ function createPointerEvents(store) {
|
|
|
2265
2278
|
compute(event, state, previous) {
|
|
2266
2279
|
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
2267
2280
|
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
2268
|
-
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
2281
|
+
state.pointer.set((event.offsetX - state.size.left) / state.size.width * 2 - 1, -((event.offsetY - state.size.top) / state.size.height) * 2 + 1);
|
|
2269
2282
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
2270
2283
|
},
|
|
2271
2284
|
connected: undefined,
|
|
@@ -2327,4 +2340,4 @@ function createPointerEvents(store) {
|
|
|
2327
2340
|
};
|
|
2328
2341
|
}
|
|
2329
2342
|
|
|
2330
|
-
export {
|
|
2343
|
+
export { useThree as A, Block as B, useFrame as C, useGraph as D, ErrorBoundary as E, useLoader as F, _roots as _, useMutableCallback as a, useIsomorphicLayoutEffect as b, createRoot as c, unmountComponentAtNode as d, extend as e, createPointerEvents as f, createEvents as g, flushGlobalEffects as h, isRef as i, addEffect as j, addAfterEffect as k, addTail as l, invalidate as m, advance as n, createPortal as o, context as p, applyProps as q, reconciler as r, getRootState as s, threeTypes as t, useBridge as u, dispose as v, act as w, buildGraph as x, useInstanceHandle as y, useStore as z };
|
|
@@ -136,6 +136,7 @@ const is = {
|
|
|
136
136
|
num: a => typeof a === 'number',
|
|
137
137
|
boo: a => typeof a === 'boolean',
|
|
138
138
|
und: a => a === void 0,
|
|
139
|
+
nul: a => a === null,
|
|
139
140
|
arr: a => Array.isArray(a),
|
|
140
141
|
equ(a, b, {
|
|
141
142
|
arrays = 'shallow',
|
|
@@ -229,10 +230,7 @@ function prepare(target, root, type, props) {
|
|
|
229
230
|
handlers: {},
|
|
230
231
|
isHidden: false
|
|
231
232
|
};
|
|
232
|
-
if (object)
|
|
233
|
-
object.__r3f = instance;
|
|
234
|
-
if (type) applyProps(object, instance.props);
|
|
235
|
-
}
|
|
233
|
+
if (object) object.__r3f = instance;
|
|
236
234
|
}
|
|
237
235
|
return instance;
|
|
238
236
|
}
|
|
@@ -304,6 +302,18 @@ const RESERVED_PROPS = [...REACT_INTERNAL_PROPS,
|
|
|
304
302
|
// Behavior flags
|
|
305
303
|
'dispose'];
|
|
306
304
|
const MEMOIZED_PROTOTYPES = new Map();
|
|
305
|
+
function getMemoizedPrototype(root) {
|
|
306
|
+
let ctor = MEMOIZED_PROTOTYPES.get(root.constructor);
|
|
307
|
+
try {
|
|
308
|
+
if (!ctor) {
|
|
309
|
+
ctor = new root.constructor();
|
|
310
|
+
MEMOIZED_PROTOTYPES.set(root.constructor, ctor);
|
|
311
|
+
}
|
|
312
|
+
} catch (e) {
|
|
313
|
+
// ...
|
|
314
|
+
}
|
|
315
|
+
return ctor;
|
|
316
|
+
}
|
|
307
317
|
|
|
308
318
|
// This function prepares a set of changes to be applied to the instance
|
|
309
319
|
function diffProps(instance, newProps) {
|
|
@@ -340,12 +350,8 @@ function diffProps(instance, newProps) {
|
|
|
340
350
|
// For removed props, try to set default values, if possible
|
|
341
351
|
if (root.constructor && root.constructor.length === 0) {
|
|
342
352
|
// create a blank slate of the instance and copy the particular parameter.
|
|
343
|
-
|
|
344
|
-
if (!ctor)
|
|
345
|
-
ctor = new root.constructor();
|
|
346
|
-
MEMOIZED_PROTOTYPES.set(root.constructor, ctor);
|
|
347
|
-
}
|
|
348
|
-
changedProps[key] = ctor[key];
|
|
353
|
+
const ctor = getMemoizedPrototype(root);
|
|
354
|
+
if (!is.und(ctor)) changedProps[key] = ctor[key];
|
|
349
355
|
} else {
|
|
350
356
|
// instance does not have constructor, just set it to 0
|
|
351
357
|
changedProps[key] = 0;
|
|
@@ -387,7 +393,13 @@ function applyProps(object, props) {
|
|
|
387
393
|
|
|
388
394
|
// Copy if properties match signatures
|
|
389
395
|
if (target != null && target.copy && value != null && value.constructor && target.constructor === value.constructor) {
|
|
390
|
-
target
|
|
396
|
+
// fetch the default state of the target
|
|
397
|
+
const ctor = getMemoizedPrototype(root);
|
|
398
|
+
// The target key was originally null or undefined, which indicates that the object which
|
|
399
|
+
// is now present was externally set by the user, we should therefore assign the value directly
|
|
400
|
+
if (!is.und(ctor) && (is.und(ctor[key]) || is.nul(ctor[key]))) root[key] = value;
|
|
401
|
+
// Otherwise copy is correct
|
|
402
|
+
else target.copy(value);
|
|
391
403
|
}
|
|
392
404
|
// Layers have no copy function, we must therefore copy the mask property
|
|
393
405
|
else if (target instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) {
|
|
@@ -1085,7 +1097,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1085
1097
|
oldDpr = viewport.dpr;
|
|
1086
1098
|
// Update camera & renderer
|
|
1087
1099
|
updateCamera(camera, size);
|
|
1088
|
-
gl.setPixelRatio(viewport.dpr);
|
|
1100
|
+
if (viewport.dpr > 0) gl.setPixelRatio(viewport.dpr);
|
|
1089
1101
|
const updateStyle = typeof HTMLCanvasElement !== 'undefined' && gl.domElement instanceof HTMLCanvasElement;
|
|
1090
1102
|
gl.setSize(size.width, size.height, updateStyle);
|
|
1091
1103
|
}
|
|
@@ -1320,11 +1332,11 @@ function handleContainerEffects(parent, child, beforeChild) {
|
|
|
1320
1332
|
// Create object
|
|
1321
1333
|
child.object = (_child$props$object = child.props.object) != null ? _child$props$object : new target(...((_child$props$args = child.props.args) != null ? _child$props$args : []));
|
|
1322
1334
|
child.object.__r3f = child;
|
|
1323
|
-
|
|
1324
|
-
// Set initial props
|
|
1325
|
-
applyProps(child.object, child.props);
|
|
1326
1335
|
}
|
|
1327
1336
|
|
|
1337
|
+
// Set initial props
|
|
1338
|
+
applyProps(child.object, child.props);
|
|
1339
|
+
|
|
1328
1340
|
// Append instance
|
|
1329
1341
|
if (child.props.attach) {
|
|
1330
1342
|
attach(parent, child);
|
|
@@ -1336,7 +1348,6 @@ function handleContainerEffects(parent, child, beforeChild) {
|
|
|
1336
1348
|
child.object.dispatchEvent({
|
|
1337
1349
|
type: 'added'
|
|
1338
1350
|
});
|
|
1339
|
-
// @ts-expect-error https://github.com/mrdoob/three.js/pull/16934
|
|
1340
1351
|
parent.object.dispatchEvent({
|
|
1341
1352
|
type: 'childadded',
|
|
1342
1353
|
child: child.object
|
|
@@ -1652,17 +1663,20 @@ const shallowLoose = {
|
|
|
1652
1663
|
objects: 'shallow',
|
|
1653
1664
|
strict: false
|
|
1654
1665
|
};
|
|
1655
|
-
|
|
1656
|
-
const
|
|
1657
|
-
if (isRenderer(customRenderer)) return customRenderer;
|
|
1658
|
-
return new THREE__namespace.WebGLRenderer({
|
|
1659
|
-
powerPreference: 'high-performance',
|
|
1666
|
+
async function createRendererInstance(gl, canvas) {
|
|
1667
|
+
const defaultProps = {
|
|
1660
1668
|
canvas: canvas,
|
|
1669
|
+
powerPreference: 'high-performance',
|
|
1661
1670
|
antialias: true,
|
|
1662
|
-
alpha: true
|
|
1671
|
+
alpha: true
|
|
1672
|
+
};
|
|
1673
|
+
const customRenderer = typeof gl === 'function' ? await gl(defaultProps) : gl;
|
|
1674
|
+
if (isRenderer(customRenderer)) return customRenderer;
|
|
1675
|
+
return new THREE__namespace.WebGLRenderer({
|
|
1676
|
+
...defaultProps,
|
|
1663
1677
|
...gl
|
|
1664
1678
|
});
|
|
1665
|
-
}
|
|
1679
|
+
}
|
|
1666
1680
|
function computeInitialSize(canvas, size) {
|
|
1667
1681
|
if (!size && typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
|
|
1668
1682
|
const {
|
|
@@ -1743,7 +1757,7 @@ function createRoot(canvas) {
|
|
|
1743
1757
|
let configured = false;
|
|
1744
1758
|
let lastCamera;
|
|
1745
1759
|
return {
|
|
1746
|
-
configure(props = {}) {
|
|
1760
|
+
async configure(props = {}) {
|
|
1747
1761
|
let {
|
|
1748
1762
|
gl: glConfig,
|
|
1749
1763
|
size: propsSize,
|
|
@@ -1767,7 +1781,7 @@ function createRoot(canvas) {
|
|
|
1767
1781
|
// Set up renderer (one time only!)
|
|
1768
1782
|
let gl = state.gl;
|
|
1769
1783
|
if (!state.gl) state.set({
|
|
1770
|
-
gl: gl = createRendererInstance(glConfig, canvas)
|
|
1784
|
+
gl: gl = await createRendererInstance(glConfig, canvas)
|
|
1771
1785
|
});
|
|
1772
1786
|
|
|
1773
1787
|
// Set up raycaster (one time only!)
|
|
@@ -1837,6 +1851,31 @@ function createRoot(canvas) {
|
|
|
1837
1851
|
});
|
|
1838
1852
|
}
|
|
1839
1853
|
|
|
1854
|
+
// Store events internally
|
|
1855
|
+
if (events && !state.events.handlers) state.set({
|
|
1856
|
+
events: events(store)
|
|
1857
|
+
});
|
|
1858
|
+
// Check size, allow it to take on container bounds initially
|
|
1859
|
+
const size = computeInitialSize(canvas, propsSize);
|
|
1860
|
+
if (!is.equ(size, state.size, shallowLoose)) {
|
|
1861
|
+
state.setSize(size.width, size.height, size.top, size.left);
|
|
1862
|
+
}
|
|
1863
|
+
// Check pixelratio
|
|
1864
|
+
if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr);
|
|
1865
|
+
// Check frameloop
|
|
1866
|
+
if (state.frameloop !== frameloop) state.setFrameloop(frameloop);
|
|
1867
|
+
// Check pointer missed
|
|
1868
|
+
if (!state.onPointerMissed) state.set({
|
|
1869
|
+
onPointerMissed
|
|
1870
|
+
});
|
|
1871
|
+
// Check performance
|
|
1872
|
+
if (performance && !is.equ(performance, state.performance, shallowLoose)) state.set(state => ({
|
|
1873
|
+
performance: {
|
|
1874
|
+
...state.performance,
|
|
1875
|
+
...performance
|
|
1876
|
+
}
|
|
1877
|
+
}));
|
|
1878
|
+
|
|
1840
1879
|
// Set up XR (one time only!)
|
|
1841
1880
|
if (!state.xr) {
|
|
1842
1881
|
var _gl$xr;
|
|
@@ -1918,30 +1957,6 @@ function createRoot(canvas) {
|
|
|
1918
1957
|
|
|
1919
1958
|
// Set gl props
|
|
1920
1959
|
if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, gl, shallowLoose)) applyProps(gl, glConfig);
|
|
1921
|
-
// Store events internally
|
|
1922
|
-
if (events && !state.events.handlers) state.set({
|
|
1923
|
-
events: events(store)
|
|
1924
|
-
});
|
|
1925
|
-
// Check size, allow it to take on container bounds initially
|
|
1926
|
-
const size = computeInitialSize(canvas, propsSize);
|
|
1927
|
-
if (!is.equ(size, state.size, shallowLoose)) {
|
|
1928
|
-
state.setSize(size.width, size.height, size.top, size.left);
|
|
1929
|
-
}
|
|
1930
|
-
// Check pixelratio
|
|
1931
|
-
if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr);
|
|
1932
|
-
// Check frameloop
|
|
1933
|
-
if (state.frameloop !== frameloop) state.setFrameloop(frameloop);
|
|
1934
|
-
// Check pointer missed
|
|
1935
|
-
if (!state.onPointerMissed) state.set({
|
|
1936
|
-
onPointerMissed
|
|
1937
|
-
});
|
|
1938
|
-
// Check performance
|
|
1939
|
-
if (performance && !is.equ(performance, state.performance, shallowLoose)) state.set(state => ({
|
|
1940
|
-
performance: {
|
|
1941
|
-
...state.performance,
|
|
1942
|
-
...performance
|
|
1943
|
-
}
|
|
1944
|
-
}));
|
|
1945
1960
|
|
|
1946
1961
|
// Set locals
|
|
1947
1962
|
onCreated = onCreatedCallback;
|
|
@@ -1950,7 +1965,7 @@ function createRoot(canvas) {
|
|
|
1950
1965
|
},
|
|
1951
1966
|
render(children) {
|
|
1952
1967
|
// The root has to be configured before it can be rendered
|
|
1953
|
-
if (!configured)
|
|
1968
|
+
if (!configured) throw "The root has to be configured before it can be rendered, call 'configure' first!";
|
|
1954
1969
|
reconciler.updateContainer( /*#__PURE__*/jsxRuntime.jsx(Provider, {
|
|
1955
1970
|
store: store,
|
|
1956
1971
|
children: children,
|
|
@@ -1964,12 +1979,6 @@ function createRoot(canvas) {
|
|
|
1964
1979
|
}
|
|
1965
1980
|
};
|
|
1966
1981
|
}
|
|
1967
|
-
function render(children, canvas, config) {
|
|
1968
|
-
console.warn('R3F.render is no longer supported in React 18. Use createRoot instead!');
|
|
1969
|
-
const root = createRoot(canvas);
|
|
1970
|
-
root.configure(config);
|
|
1971
|
-
return root.render(children);
|
|
1972
|
-
}
|
|
1973
1982
|
function Provider({
|
|
1974
1983
|
store,
|
|
1975
1984
|
children,
|
|
@@ -2107,12 +2116,16 @@ function Portal({
|
|
|
2107
2116
|
return store;
|
|
2108
2117
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2109
2118
|
}, [previousRoot, container]);
|
|
2110
|
-
return
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2119
|
+
return (
|
|
2120
|
+
/*#__PURE__*/
|
|
2121
|
+
// @ts-ignore, reconciler types are not maintained
|
|
2122
|
+
jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
2123
|
+
children: reconciler.createPortal( /*#__PURE__*/jsxRuntime.jsx(context.Provider, {
|
|
2124
|
+
value: usePortalStore,
|
|
2125
|
+
children: children
|
|
2126
|
+
}), usePortalStore, null)
|
|
2127
|
+
})
|
|
2128
|
+
);
|
|
2116
2129
|
}
|
|
2117
2130
|
|
|
2118
2131
|
function createSubs(callback, subs) {
|
|
@@ -2212,7 +2225,7 @@ function loop(timestamp) {
|
|
|
2212
2225
|
repeat += update(timestamp, state);
|
|
2213
2226
|
}
|
|
2214
2227
|
}
|
|
2215
|
-
useFrameInProgress =
|
|
2228
|
+
useFrameInProgress = false;
|
|
2216
2229
|
|
|
2217
2230
|
// Run after-effects
|
|
2218
2231
|
flushGlobalEffects('after', timestamp);
|
|
@@ -2291,7 +2304,7 @@ function createPointerEvents(store) {
|
|
|
2291
2304
|
compute(event, state, previous) {
|
|
2292
2305
|
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
2293
2306
|
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
2294
|
-
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
2307
|
+
state.pointer.set((event.offsetX - state.size.left) / state.size.width * 2 - 1, -((event.offsetY - state.size.top) / state.size.height) * 2 + 1);
|
|
2295
2308
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
2296
2309
|
},
|
|
2297
2310
|
connected: undefined,
|
|
@@ -2375,7 +2388,6 @@ exports.getRootState = getRootState;
|
|
|
2375
2388
|
exports.invalidate = invalidate;
|
|
2376
2389
|
exports.isRef = isRef;
|
|
2377
2390
|
exports.reconciler = reconciler;
|
|
2378
|
-
exports.render = render;
|
|
2379
2391
|
exports.threeTypes = threeTypes;
|
|
2380
2392
|
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
2381
2393
|
exports.useBridge = useBridge;
|