@react-three/fiber 8.0.0-beta-04 → 8.0.0-beta-05
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/declarations/src/core/index.d.ts +2 -1
- package/dist/declarations/src/core/loop.d.ts +2 -1
- package/dist/declarations/src/core/store.d.ts +4 -2
- package/dist/declarations/src/index.d.ts +0 -1
- package/dist/declarations/src/native.d.ts +0 -1
- package/dist/declarations/src/three-types.d.ts +7 -8
- package/dist/{index-fccd77b0.esm.js → index-3f4e5f46.esm.js} +79 -78
- package/dist/{index-ff3eb68b.cjs.dev.js → index-95c17855.cjs.dev.js} +78 -79
- package/dist/{index-eb414398.cjs.prod.js → index-ff8b5912.cjs.prod.js} +78 -79
- package/dist/react-three-fiber.cjs.dev.js +1 -1
- package/dist/react-three-fiber.cjs.prod.js +1 -1
- package/dist/react-three-fiber.esm.js +2 -2
- package/native/dist/react-three-fiber-native.cjs.dev.js +91 -121
- package/native/dist/react-three-fiber-native.cjs.prod.js +91 -121
- package/native/dist/react-three-fiber-native.esm.js +92 -122
- package/package.json +14 -7
- package/dist/declarations/src/native/hooks.d.ts +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,7 @@ import { extend, Root } from '../core/renderer';
|
|
|
8
8
|
import { addEffect, addAfterEffect, addTail } from '../core/loop';
|
|
9
9
|
import { EventManager } from './events';
|
|
10
10
|
declare const roots: Map<Element, Root>;
|
|
11
|
-
declare const invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined) => void;
|
|
11
|
+
declare const invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined, frame?: THREE.XRFrame | undefined) => void;
|
|
12
12
|
declare const reconciler: import("react-reconciler").Reconciler<unknown, unknown, unknown, unknown, unknown>, applyProps: typeof import("../core/utils").applyProps;
|
|
13
13
|
declare type Properties<T> = Pick<T, {
|
|
14
14
|
[K in keyof T]: T[K] extends (_: any) => any ? never : K;
|
|
@@ -28,4 +28,5 @@ declare function render<TCanvas extends Element>(element: React.ReactNode, canva
|
|
|
28
28
|
declare function unmountComponentAtNode<TElement extends Element>(canvas: TElement, callback?: (canvas: TElement) => void): void;
|
|
29
29
|
declare const act: any;
|
|
30
30
|
declare function createPortal(children: React.ReactNode, container: THREE.Object3D): React.ReactNode;
|
|
31
|
+
export * from './hooks';
|
|
31
32
|
export { context, render, createRoot, unmountComponentAtNode, createPortal, reconciler, applyProps, dispose, invalidate, advance, extend, addEffect, addAfterEffect, addTail, act, roots as _roots, };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
1
2
|
import { Root } from './renderer';
|
|
2
3
|
import { RootState } from './store';
|
|
3
4
|
declare type GlobalRenderCallback = (timeStamp: number) => void;
|
|
@@ -7,6 +8,6 @@ export declare const addTail: (callback: GlobalRenderCallback) => () => void;
|
|
|
7
8
|
export declare function createLoop<TCanvas>(roots: Map<TCanvas, Root>): {
|
|
8
9
|
loop: (timestamp: number) => number | undefined;
|
|
9
10
|
invalidate: (state?: RootState | undefined) => void;
|
|
10
|
-
advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined) => void;
|
|
11
|
+
advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined, frame?: THREE.XRFrame | undefined) => void;
|
|
11
12
|
};
|
|
12
13
|
export {};
|
|
@@ -29,7 +29,7 @@ export declare type Raycaster = THREE.Raycaster & {
|
|
|
29
29
|
filter?: FilterFunction;
|
|
30
30
|
computeOffsets?: ComputeOffsetsFunction;
|
|
31
31
|
};
|
|
32
|
-
export declare type RenderCallback = (state: RootState, delta: number) => void;
|
|
32
|
+
export declare type RenderCallback = (state: RootState, delta: number, frame?: THREE.XRFrame) => void;
|
|
33
33
|
export declare type Performance = {
|
|
34
34
|
current: number;
|
|
35
35
|
min: number;
|
|
@@ -93,6 +93,8 @@ export declare type FilterFunction = (items: THREE.Intersection[], state: RootSt
|
|
|
93
93
|
export declare type ComputeOffsetsFunction = (event: any, state: RootState) => {
|
|
94
94
|
offsetX: number;
|
|
95
95
|
offsetY: number;
|
|
96
|
+
width?: number;
|
|
97
|
+
height?: number;
|
|
96
98
|
};
|
|
97
99
|
export declare type StoreProps = {
|
|
98
100
|
gl: THREE.WebGLRenderer;
|
|
@@ -113,5 +115,5 @@ export declare type StoreProps = {
|
|
|
113
115
|
};
|
|
114
116
|
export declare type ApplyProps = (instance: Instance, newProps: InstanceProps) => void;
|
|
115
117
|
declare const context: React.Context<UseStore<RootState>>;
|
|
116
|
-
declare const createStore: (applyProps: ApplyProps, invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean | undefined, state?: RootState | undefined) => void, props: StoreProps) => UseStore<RootState>;
|
|
118
|
+
declare const createStore: (applyProps: ApplyProps, invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean | undefined, state?: RootState | undefined, frame?: THREE.XRFrame | undefined) => void, props: StoreProps) => UseStore<RootState>;
|
|
117
119
|
export { createStore, context };
|
|
@@ -4,7 +4,6 @@ export { ReactThreeFiber };
|
|
|
4
4
|
export type { Intersection, Subscription, Dpr, Size, Viewport, Camera, RenderCallback, Performance, RootState, } from './core/store';
|
|
5
5
|
export type { ThreeEvent, Events, EventManager } from './core/events';
|
|
6
6
|
export type { ObjectMap } from './core/utils';
|
|
7
|
-
export * from './core/hooks';
|
|
8
7
|
export * from './web/Canvas';
|
|
9
8
|
export { createPointerEvents as events } from './web/events';
|
|
10
9
|
export * from './core';
|
|
@@ -4,7 +4,6 @@ export { ReactThreeFiber };
|
|
|
4
4
|
export type { Intersection, Subscription, Dpr, Size, Viewport, Camera, RenderCallback, Performance, RootState, } from './core/store';
|
|
5
5
|
export type { ThreeEvent, Events, EventManager } from './core/events';
|
|
6
6
|
export type { ObjectMap } from './core/utils';
|
|
7
|
-
export * from './native/hooks';
|
|
8
7
|
export * from './native/Canvas';
|
|
9
8
|
export { createTouchEvents as events } from './native/events';
|
|
10
9
|
export * from './core';
|
|
@@ -24,7 +24,10 @@ export interface NodeProps<T, P> {
|
|
|
24
24
|
key?: React.Key;
|
|
25
25
|
onUpdate?: (self: T) => void;
|
|
26
26
|
}
|
|
27
|
-
export declare type
|
|
27
|
+
export declare type ExtendedColors<T> = {
|
|
28
|
+
[K in keyof T]: T[K] extends THREE.Color | undefined ? Color : T[K];
|
|
29
|
+
};
|
|
30
|
+
export declare type Node<T, P> = ExtendedColors<Overwrite<Partial<T>, NodeProps<T, P>>>;
|
|
28
31
|
export declare type Object3DNode<T, P> = Overwrite<Node<T, P>, {
|
|
29
32
|
position?: Vector3;
|
|
30
33
|
up?: Vector3;
|
|
@@ -35,13 +38,9 @@ export declare type Object3DNode<T, P> = Overwrite<Node<T, P>, {
|
|
|
35
38
|
layers?: Layers;
|
|
36
39
|
dispose?: (() => void) | null;
|
|
37
40
|
}> & EventHandlers;
|
|
38
|
-
export declare type BufferGeometryNode<T extends THREE.BufferGeometry, P> =
|
|
39
|
-
export declare type MaterialNode<T extends THREE.Material, P> =
|
|
40
|
-
|
|
41
|
-
}>;
|
|
42
|
-
export declare type LightNode<T extends THREE.Light, P> = Overwrite<Object3DNode<T, P>, {
|
|
43
|
-
color?: Color;
|
|
44
|
-
}>;
|
|
41
|
+
export declare type BufferGeometryNode<T extends THREE.BufferGeometry, P> = Node<T, P>;
|
|
42
|
+
export declare type MaterialNode<T extends THREE.Material, P> = Node<T, P>;
|
|
43
|
+
export declare type LightNode<T extends THREE.Light, P> = Object3DNode<T, P>;
|
|
45
44
|
export declare type AudioListenerProps = Object3DNode<THREE.AudioListener, typeof THREE.AudioListener>;
|
|
46
45
|
export declare type PositionalAudioProps = Object3DNode<THREE.PositionalAudio, typeof THREE.PositionalAudio>;
|
|
47
46
|
export declare type MeshProps = Object3DNode<THREE.Mesh, typeof THREE.Mesh>;
|
|
@@ -391,7 +391,7 @@ function createEvents(store) {
|
|
|
391
391
|
/** Sets up defaultRaycaster */
|
|
392
392
|
|
|
393
393
|
function prepareRay(event) {
|
|
394
|
-
var
|
|
394
|
+
var _customOffsets$offset, _customOffsets$offset2, _customOffsets$width, _customOffsets$height;
|
|
395
395
|
|
|
396
396
|
const state = store.getState();
|
|
397
397
|
const {
|
|
@@ -402,14 +402,11 @@ function createEvents(store) {
|
|
|
402
402
|
} = state; // https://github.com/pmndrs/react-three-fiber/pull/782
|
|
403
403
|
// Events trigger outside of canvas when moved
|
|
404
404
|
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
const
|
|
410
|
-
width,
|
|
411
|
-
height
|
|
412
|
-
} = size;
|
|
405
|
+
const customOffsets = raycaster.computeOffsets == null ? void 0 : raycaster.computeOffsets(event, state);
|
|
406
|
+
const offsetX = (_customOffsets$offset = customOffsets == null ? void 0 : customOffsets.offsetX) != null ? _customOffsets$offset : event.offsetX;
|
|
407
|
+
const offsetY = (_customOffsets$offset2 = customOffsets == null ? void 0 : customOffsets.offsetY) != null ? _customOffsets$offset2 : event.offsetY;
|
|
408
|
+
const width = (_customOffsets$width = customOffsets == null ? void 0 : customOffsets.width) != null ? _customOffsets$width : size.width;
|
|
409
|
+
const height = (_customOffsets$height = customOffsets == null ? void 0 : customOffsets.height) != null ? _customOffsets$height : size.height;
|
|
413
410
|
mouse.set(offsetX / width * 2 - 1, -(offsetY / height) * 2 + 1);
|
|
414
411
|
raycaster.setFromCamera(mouse, camera);
|
|
415
412
|
}
|
|
@@ -968,10 +965,13 @@ function createRenderer(roots, getEventPriority) {
|
|
|
968
965
|
|
|
969
966
|
instance.__r3f.objects = [];
|
|
970
967
|
removeChild(parent, instance);
|
|
971
|
-
appendChild(parent, newInstance) //
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
968
|
+
appendChild(parent, newInstance); // Re-bind event handlers
|
|
969
|
+
|
|
970
|
+
if (newInstance.raycast && newInstance.__r3f.eventCount) {
|
|
971
|
+
const rootState = newInstance.__r3f.root.getState();
|
|
972
|
+
|
|
973
|
+
rootState.internal.interaction.push(newInstance);
|
|
974
|
+
} // This evil hack switches the react-internal fiber node
|
|
975
975
|
[fiber, fiber.alternate].forEach(fiber => {
|
|
976
976
|
if (fiber !== null) {
|
|
977
977
|
fiber.stateNode = newInstance;
|
|
@@ -1065,7 +1065,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
1065
1065
|
isPrimaryRenderer: false,
|
|
1066
1066
|
getCurrentEventPriority: () => getEventPriority ? getEventPriority() : DefaultEventPriority,
|
|
1067
1067
|
// @ts-ignore
|
|
1068
|
-
now: is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
|
|
1068
|
+
now: typeof performance !== 'undefined' && is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
|
|
1069
1069
|
// @ts-ignore
|
|
1070
1070
|
scheduleTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
1071
1071
|
// @ts-ignore
|
|
@@ -1226,18 +1226,19 @@ const createStore = (applyProps, invalidate, advance, props) => {
|
|
|
1226
1226
|
})); // Handle frame behavior in WebXR
|
|
1227
1227
|
|
|
1228
1228
|
|
|
1229
|
-
const handleXRFrame = timestamp => {
|
|
1229
|
+
const handleXRFrame = (timestamp, frame) => {
|
|
1230
1230
|
const state = get();
|
|
1231
1231
|
if (state.frameloop === 'never') return;
|
|
1232
|
-
advance(timestamp, true);
|
|
1232
|
+
advance(timestamp, true, state, frame);
|
|
1233
1233
|
}; // Toggle render switching on session
|
|
1234
1234
|
|
|
1235
1235
|
|
|
1236
1236
|
const handleSessionChange = () => {
|
|
1237
|
-
gl.xr.enabled = gl.xr.isPresenting;
|
|
1238
|
-
|
|
1237
|
+
gl.xr.enabled = gl.xr.isPresenting; // @ts-expect-error
|
|
1238
|
+
// WebXRManager's signature is incorrect.
|
|
1239
|
+
// See: https://github.com/pmndrs/react-three-fiber/pull/2017#discussion_r790134505
|
|
1239
1240
|
|
|
1240
|
-
|
|
1241
|
+
gl.xr.setAnimationLoop(gl.xr.isPresenting ? handleXRFrame : null);
|
|
1241
1242
|
}; // WebXR session manager
|
|
1242
1243
|
|
|
1243
1244
|
|
|
@@ -1417,60 +1418,6 @@ const createStore = (applyProps, invalidate, advance, props) => {
|
|
|
1417
1418
|
return rootState;
|
|
1418
1419
|
};
|
|
1419
1420
|
|
|
1420
|
-
function useStore() {
|
|
1421
|
-
const store = React.useContext(context);
|
|
1422
|
-
if (!store) throw `R3F hooks can only be used within the Canvas component!`;
|
|
1423
|
-
return store;
|
|
1424
|
-
}
|
|
1425
|
-
function useThree(selector = state => state, equalityFn) {
|
|
1426
|
-
return useStore()(selector, equalityFn);
|
|
1427
|
-
}
|
|
1428
|
-
function useFrame(callback, renderPriority = 0) {
|
|
1429
|
-
const subscribe = useStore().getState().internal.subscribe; // Update ref
|
|
1430
|
-
|
|
1431
|
-
const ref = React.useRef(callback);
|
|
1432
|
-
React.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
|
|
1433
|
-
|
|
1434
|
-
React.useLayoutEffect(() => subscribe(ref, renderPriority), [renderPriority, subscribe]);
|
|
1435
|
-
return null;
|
|
1436
|
-
}
|
|
1437
|
-
function useGraph(object) {
|
|
1438
|
-
return React.useMemo(() => buildGraph(object), [object]);
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
function loadingFn(extensions, onProgress) {
|
|
1442
|
-
return function (Proto, ...input) {
|
|
1443
|
-
// Construct new loader and run extensions
|
|
1444
|
-
const loader = new Proto();
|
|
1445
|
-
if (extensions) extensions(loader); // Go through the urls and load them
|
|
1446
|
-
|
|
1447
|
-
return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
|
|
1448
|
-
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
1449
|
-
res(data);
|
|
1450
|
-
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1451
|
-
};
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
function useLoader(Proto, input, extensions, onProgress) {
|
|
1455
|
-
// Use suspense to load async assets
|
|
1456
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1457
|
-
const results = suspend(loadingFn(extensions, onProgress), [Proto, ...keys], {
|
|
1458
|
-
equal: is.equ
|
|
1459
|
-
}); // Return the object/s
|
|
1460
|
-
|
|
1461
|
-
return Array.isArray(input) ? results : results[0];
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1464
|
-
useLoader.preload = function (Proto, input, extensions) {
|
|
1465
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1466
|
-
return preload(loadingFn(extensions), [Proto, ...keys]);
|
|
1467
|
-
};
|
|
1468
|
-
|
|
1469
|
-
useLoader.clear = function (Proto, input) {
|
|
1470
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1471
|
-
return clear([Proto, ...keys]);
|
|
1472
|
-
};
|
|
1473
|
-
|
|
1474
1421
|
function createSubs(callback, subs) {
|
|
1475
1422
|
const index = subs.length;
|
|
1476
1423
|
subs.push(callback);
|
|
@@ -1489,7 +1436,7 @@ function run(effects, timestamp) {
|
|
|
1489
1436
|
for (i = 0; i < effects.length; i++) effects[i](timestamp);
|
|
1490
1437
|
}
|
|
1491
1438
|
|
|
1492
|
-
function render$1(timestamp, state) {
|
|
1439
|
+
function render$1(timestamp, state, frame) {
|
|
1493
1440
|
// Run local effects
|
|
1494
1441
|
let delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1495
1442
|
|
|
@@ -1500,7 +1447,7 @@ function render$1(timestamp, state) {
|
|
|
1500
1447
|
} // Call subscribers (useFrame)
|
|
1501
1448
|
|
|
1502
1449
|
|
|
1503
|
-
for (i = 0; i < state.internal.subscribers.length; i++) state.internal.subscribers[i].ref.current(state, delta); // Render content
|
|
1450
|
+
for (i = 0; i < state.internal.subscribers.length; i++) state.internal.subscribers[i].ref.current(state, delta, frame); // Render content
|
|
1504
1451
|
|
|
1505
1452
|
|
|
1506
1453
|
if (!state.internal.priority && state.gl.render) state.gl.render(state.scene, state.camera); // Decrease frame count
|
|
@@ -1551,9 +1498,9 @@ function createLoop(roots) {
|
|
|
1551
1498
|
}
|
|
1552
1499
|
}
|
|
1553
1500
|
|
|
1554
|
-
function advance(timestamp, runGlobalEffects = true, state) {
|
|
1501
|
+
function advance(timestamp, runGlobalEffects = true, state, frame) {
|
|
1555
1502
|
if (runGlobalEffects) run(globalEffects, timestamp);
|
|
1556
|
-
if (!state) roots.forEach(root => render$1(timestamp, root.store.getState()));else render$1(timestamp, state);
|
|
1503
|
+
if (!state) roots.forEach(root => render$1(timestamp, root.store.getState()));else render$1(timestamp, state, frame);
|
|
1557
1504
|
if (runGlobalEffects) run(globalAfterEffects, timestamp);
|
|
1558
1505
|
}
|
|
1559
1506
|
|
|
@@ -1564,6 +1511,60 @@ function createLoop(roots) {
|
|
|
1564
1511
|
};
|
|
1565
1512
|
}
|
|
1566
1513
|
|
|
1514
|
+
function useStore() {
|
|
1515
|
+
const store = React.useContext(context);
|
|
1516
|
+
if (!store) throw `R3F hooks can only be used within the Canvas component!`;
|
|
1517
|
+
return store;
|
|
1518
|
+
}
|
|
1519
|
+
function useThree(selector = state => state, equalityFn) {
|
|
1520
|
+
return useStore()(selector, equalityFn);
|
|
1521
|
+
}
|
|
1522
|
+
function useFrame(callback, renderPriority = 0) {
|
|
1523
|
+
const subscribe = useStore().getState().internal.subscribe; // Update ref
|
|
1524
|
+
|
|
1525
|
+
const ref = React.useRef(callback);
|
|
1526
|
+
React.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
|
|
1527
|
+
|
|
1528
|
+
React.useLayoutEffect(() => subscribe(ref, renderPriority), [renderPriority, subscribe]);
|
|
1529
|
+
return null;
|
|
1530
|
+
}
|
|
1531
|
+
function useGraph(object) {
|
|
1532
|
+
return React.useMemo(() => buildGraph(object), [object]);
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
function loadingFn(extensions, onProgress) {
|
|
1536
|
+
return function (Proto, ...input) {
|
|
1537
|
+
// Construct new loader and run extensions
|
|
1538
|
+
const loader = new Proto();
|
|
1539
|
+
if (extensions) extensions(loader); // Go through the urls and load them
|
|
1540
|
+
|
|
1541
|
+
return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
|
|
1542
|
+
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
1543
|
+
res(data);
|
|
1544
|
+
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
function useLoader(Proto, input, extensions, onProgress) {
|
|
1549
|
+
// Use suspense to load async assets
|
|
1550
|
+
const keys = Array.isArray(input) ? input : [input];
|
|
1551
|
+
const results = suspend(loadingFn(extensions, onProgress), [Proto, ...keys], {
|
|
1552
|
+
equal: is.equ
|
|
1553
|
+
}); // Return the object/s
|
|
1554
|
+
|
|
1555
|
+
return Array.isArray(input) ? results : results[0];
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
useLoader.preload = function (Proto, input, extensions) {
|
|
1559
|
+
const keys = Array.isArray(input) ? input : [input];
|
|
1560
|
+
return preload(loadingFn(extensions), [Proto, ...keys]);
|
|
1561
|
+
};
|
|
1562
|
+
|
|
1563
|
+
useLoader.clear = function (Proto, input) {
|
|
1564
|
+
const keys = Array.isArray(input) ? input : [input];
|
|
1565
|
+
return clear([Proto, ...keys]);
|
|
1566
|
+
};
|
|
1567
|
+
|
|
1567
1568
|
const roots = new Map();
|
|
1568
1569
|
const {
|
|
1569
1570
|
invalidate,
|
|
@@ -1747,4 +1748,4 @@ reconciler.injectIntoDevTools({
|
|
|
1747
1748
|
version: '18.0.0'
|
|
1748
1749
|
});
|
|
1749
1750
|
|
|
1750
|
-
export {
|
|
1751
|
+
export { createRoot as a, context as b, createEvents as c, createPortal as d, extend as e, reconciler as f, applyProps as g, dispose as h, invalidate as i, advance as j, addEffect as k, addAfterEffect as l, addTail as m, act as n, omit as o, pick as p, roots as q, render as r, useStore as s, threeTypes as t, unmountComponentAtNode as u, useThree as v, useFrame as w, useGraph as x, useLoader as y };
|
|
@@ -420,7 +420,7 @@ function createEvents(store) {
|
|
|
420
420
|
/** Sets up defaultRaycaster */
|
|
421
421
|
|
|
422
422
|
function prepareRay(event) {
|
|
423
|
-
var
|
|
423
|
+
var _customOffsets$offset, _customOffsets$offset2, _customOffsets$width, _customOffsets$height;
|
|
424
424
|
|
|
425
425
|
const state = store.getState();
|
|
426
426
|
const {
|
|
@@ -431,14 +431,11 @@ function createEvents(store) {
|
|
|
431
431
|
} = state; // https://github.com/pmndrs/react-three-fiber/pull/782
|
|
432
432
|
// Events trigger outside of canvas when moved
|
|
433
433
|
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
const
|
|
439
|
-
width,
|
|
440
|
-
height
|
|
441
|
-
} = size;
|
|
434
|
+
const customOffsets = raycaster.computeOffsets == null ? void 0 : raycaster.computeOffsets(event, state);
|
|
435
|
+
const offsetX = (_customOffsets$offset = customOffsets == null ? void 0 : customOffsets.offsetX) != null ? _customOffsets$offset : event.offsetX;
|
|
436
|
+
const offsetY = (_customOffsets$offset2 = customOffsets == null ? void 0 : customOffsets.offsetY) != null ? _customOffsets$offset2 : event.offsetY;
|
|
437
|
+
const width = (_customOffsets$width = customOffsets == null ? void 0 : customOffsets.width) != null ? _customOffsets$width : size.width;
|
|
438
|
+
const height = (_customOffsets$height = customOffsets == null ? void 0 : customOffsets.height) != null ? _customOffsets$height : size.height;
|
|
442
439
|
mouse.set(offsetX / width * 2 - 1, -(offsetY / height) * 2 + 1);
|
|
443
440
|
raycaster.setFromCamera(mouse, camera);
|
|
444
441
|
}
|
|
@@ -997,10 +994,13 @@ function createRenderer(roots, getEventPriority) {
|
|
|
997
994
|
|
|
998
995
|
instance.__r3f.objects = [];
|
|
999
996
|
removeChild(parent, instance);
|
|
1000
|
-
appendChild(parent, newInstance) //
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
997
|
+
appendChild(parent, newInstance); // Re-bind event handlers
|
|
998
|
+
|
|
999
|
+
if (newInstance.raycast && newInstance.__r3f.eventCount) {
|
|
1000
|
+
const rootState = newInstance.__r3f.root.getState();
|
|
1001
|
+
|
|
1002
|
+
rootState.internal.interaction.push(newInstance);
|
|
1003
|
+
} // This evil hack switches the react-internal fiber node
|
|
1004
1004
|
[fiber, fiber.alternate].forEach(fiber => {
|
|
1005
1005
|
if (fiber !== null) {
|
|
1006
1006
|
fiber.stateNode = newInstance;
|
|
@@ -1094,7 +1094,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
1094
1094
|
isPrimaryRenderer: false,
|
|
1095
1095
|
getCurrentEventPriority: () => getEventPriority ? getEventPriority() : constants.DefaultEventPriority,
|
|
1096
1096
|
// @ts-ignore
|
|
1097
|
-
now: is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
|
|
1097
|
+
now: typeof performance !== 'undefined' && is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
|
|
1098
1098
|
// @ts-ignore
|
|
1099
1099
|
scheduleTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
1100
1100
|
// @ts-ignore
|
|
@@ -1255,18 +1255,19 @@ const createStore = (applyProps, invalidate, advance, props) => {
|
|
|
1255
1255
|
})); // Handle frame behavior in WebXR
|
|
1256
1256
|
|
|
1257
1257
|
|
|
1258
|
-
const handleXRFrame = timestamp => {
|
|
1258
|
+
const handleXRFrame = (timestamp, frame) => {
|
|
1259
1259
|
const state = get();
|
|
1260
1260
|
if (state.frameloop === 'never') return;
|
|
1261
|
-
advance(timestamp, true);
|
|
1261
|
+
advance(timestamp, true, state, frame);
|
|
1262
1262
|
}; // Toggle render switching on session
|
|
1263
1263
|
|
|
1264
1264
|
|
|
1265
1265
|
const handleSessionChange = () => {
|
|
1266
|
-
gl.xr.enabled = gl.xr.isPresenting;
|
|
1267
|
-
|
|
1266
|
+
gl.xr.enabled = gl.xr.isPresenting; // @ts-expect-error
|
|
1267
|
+
// WebXRManager's signature is incorrect.
|
|
1268
|
+
// See: https://github.com/pmndrs/react-three-fiber/pull/2017#discussion_r790134505
|
|
1268
1269
|
|
|
1269
|
-
|
|
1270
|
+
gl.xr.setAnimationLoop(gl.xr.isPresenting ? handleXRFrame : null);
|
|
1270
1271
|
}; // WebXR session manager
|
|
1271
1272
|
|
|
1272
1273
|
|
|
@@ -1446,60 +1447,6 @@ const createStore = (applyProps, invalidate, advance, props) => {
|
|
|
1446
1447
|
return rootState;
|
|
1447
1448
|
};
|
|
1448
1449
|
|
|
1449
|
-
function useStore() {
|
|
1450
|
-
const store = React__namespace.useContext(context);
|
|
1451
|
-
if (!store) throw `R3F hooks can only be used within the Canvas component!`;
|
|
1452
|
-
return store;
|
|
1453
|
-
}
|
|
1454
|
-
function useThree(selector = state => state, equalityFn) {
|
|
1455
|
-
return useStore()(selector, equalityFn);
|
|
1456
|
-
}
|
|
1457
|
-
function useFrame(callback, renderPriority = 0) {
|
|
1458
|
-
const subscribe = useStore().getState().internal.subscribe; // Update ref
|
|
1459
|
-
|
|
1460
|
-
const ref = React__namespace.useRef(callback);
|
|
1461
|
-
React__namespace.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
|
|
1462
|
-
|
|
1463
|
-
React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority), [renderPriority, subscribe]);
|
|
1464
|
-
return null;
|
|
1465
|
-
}
|
|
1466
|
-
function useGraph(object) {
|
|
1467
|
-
return React__namespace.useMemo(() => buildGraph(object), [object]);
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
function loadingFn(extensions, onProgress) {
|
|
1471
|
-
return function (Proto, ...input) {
|
|
1472
|
-
// Construct new loader and run extensions
|
|
1473
|
-
const loader = new Proto();
|
|
1474
|
-
if (extensions) extensions(loader); // Go through the urls and load them
|
|
1475
|
-
|
|
1476
|
-
return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
|
|
1477
|
-
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
1478
|
-
res(data);
|
|
1479
|
-
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1480
|
-
};
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
function useLoader(Proto, input, extensions, onProgress) {
|
|
1484
|
-
// Use suspense to load async assets
|
|
1485
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1486
|
-
const results = suspendReact.suspend(loadingFn(extensions, onProgress), [Proto, ...keys], {
|
|
1487
|
-
equal: is.equ
|
|
1488
|
-
}); // Return the object/s
|
|
1489
|
-
|
|
1490
|
-
return Array.isArray(input) ? results : results[0];
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
useLoader.preload = function (Proto, input, extensions) {
|
|
1494
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1495
|
-
return suspendReact.preload(loadingFn(extensions), [Proto, ...keys]);
|
|
1496
|
-
};
|
|
1497
|
-
|
|
1498
|
-
useLoader.clear = function (Proto, input) {
|
|
1499
|
-
const keys = Array.isArray(input) ? input : [input];
|
|
1500
|
-
return suspendReact.clear([Proto, ...keys]);
|
|
1501
|
-
};
|
|
1502
|
-
|
|
1503
1450
|
function createSubs(callback, subs) {
|
|
1504
1451
|
const index = subs.length;
|
|
1505
1452
|
subs.push(callback);
|
|
@@ -1518,7 +1465,7 @@ function run(effects, timestamp) {
|
|
|
1518
1465
|
for (i = 0; i < effects.length; i++) effects[i](timestamp);
|
|
1519
1466
|
}
|
|
1520
1467
|
|
|
1521
|
-
function render$1(timestamp, state) {
|
|
1468
|
+
function render$1(timestamp, state, frame) {
|
|
1522
1469
|
// Run local effects
|
|
1523
1470
|
let delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
1524
1471
|
|
|
@@ -1529,7 +1476,7 @@ function render$1(timestamp, state) {
|
|
|
1529
1476
|
} // Call subscribers (useFrame)
|
|
1530
1477
|
|
|
1531
1478
|
|
|
1532
|
-
for (i = 0; i < state.internal.subscribers.length; i++) state.internal.subscribers[i].ref.current(state, delta); // Render content
|
|
1479
|
+
for (i = 0; i < state.internal.subscribers.length; i++) state.internal.subscribers[i].ref.current(state, delta, frame); // Render content
|
|
1533
1480
|
|
|
1534
1481
|
|
|
1535
1482
|
if (!state.internal.priority && state.gl.render) state.gl.render(state.scene, state.camera); // Decrease frame count
|
|
@@ -1580,9 +1527,9 @@ function createLoop(roots) {
|
|
|
1580
1527
|
}
|
|
1581
1528
|
}
|
|
1582
1529
|
|
|
1583
|
-
function advance(timestamp, runGlobalEffects = true, state) {
|
|
1530
|
+
function advance(timestamp, runGlobalEffects = true, state, frame) {
|
|
1584
1531
|
if (runGlobalEffects) run(globalEffects, timestamp);
|
|
1585
|
-
if (!state) roots.forEach(root => render$1(timestamp, root.store.getState()));else render$1(timestamp, state);
|
|
1532
|
+
if (!state) roots.forEach(root => render$1(timestamp, root.store.getState()));else render$1(timestamp, state, frame);
|
|
1586
1533
|
if (runGlobalEffects) run(globalAfterEffects, timestamp);
|
|
1587
1534
|
}
|
|
1588
1535
|
|
|
@@ -1593,6 +1540,60 @@ function createLoop(roots) {
|
|
|
1593
1540
|
};
|
|
1594
1541
|
}
|
|
1595
1542
|
|
|
1543
|
+
function useStore() {
|
|
1544
|
+
const store = React__namespace.useContext(context);
|
|
1545
|
+
if (!store) throw `R3F hooks can only be used within the Canvas component!`;
|
|
1546
|
+
return store;
|
|
1547
|
+
}
|
|
1548
|
+
function useThree(selector = state => state, equalityFn) {
|
|
1549
|
+
return useStore()(selector, equalityFn);
|
|
1550
|
+
}
|
|
1551
|
+
function useFrame(callback, renderPriority = 0) {
|
|
1552
|
+
const subscribe = useStore().getState().internal.subscribe; // Update ref
|
|
1553
|
+
|
|
1554
|
+
const ref = React__namespace.useRef(callback);
|
|
1555
|
+
React__namespace.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
|
|
1556
|
+
|
|
1557
|
+
React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority), [renderPriority, subscribe]);
|
|
1558
|
+
return null;
|
|
1559
|
+
}
|
|
1560
|
+
function useGraph(object) {
|
|
1561
|
+
return React__namespace.useMemo(() => buildGraph(object), [object]);
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
function loadingFn(extensions, onProgress) {
|
|
1565
|
+
return function (Proto, ...input) {
|
|
1566
|
+
// Construct new loader and run extensions
|
|
1567
|
+
const loader = new Proto();
|
|
1568
|
+
if (extensions) extensions(loader); // Go through the urls and load them
|
|
1569
|
+
|
|
1570
|
+
return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
|
|
1571
|
+
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
1572
|
+
res(data);
|
|
1573
|
+
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
function useLoader(Proto, input, extensions, onProgress) {
|
|
1578
|
+
// Use suspense to load async assets
|
|
1579
|
+
const keys = Array.isArray(input) ? input : [input];
|
|
1580
|
+
const results = suspendReact.suspend(loadingFn(extensions, onProgress), [Proto, ...keys], {
|
|
1581
|
+
equal: is.equ
|
|
1582
|
+
}); // Return the object/s
|
|
1583
|
+
|
|
1584
|
+
return Array.isArray(input) ? results : results[0];
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
useLoader.preload = function (Proto, input, extensions) {
|
|
1588
|
+
const keys = Array.isArray(input) ? input : [input];
|
|
1589
|
+
return suspendReact.preload(loadingFn(extensions), [Proto, ...keys]);
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1592
|
+
useLoader.clear = function (Proto, input) {
|
|
1593
|
+
const keys = Array.isArray(input) ? input : [input];
|
|
1594
|
+
return suspendReact.clear([Proto, ...keys]);
|
|
1595
|
+
};
|
|
1596
|
+
|
|
1596
1597
|
const roots = new Map();
|
|
1597
1598
|
const {
|
|
1598
1599
|
invalidate,
|
|
@@ -1782,7 +1783,6 @@ exports.addEffect = addEffect;
|
|
|
1782
1783
|
exports.addTail = addTail;
|
|
1783
1784
|
exports.advance = advance;
|
|
1784
1785
|
exports.applyProps = applyProps;
|
|
1785
|
-
exports.buildGraph = buildGraph;
|
|
1786
1786
|
exports.context = context;
|
|
1787
1787
|
exports.createEvents = createEvents;
|
|
1788
1788
|
exports.createPortal = createPortal;
|
|
@@ -1790,7 +1790,6 @@ exports.createRoot = createRoot;
|
|
|
1790
1790
|
exports.dispose = dispose;
|
|
1791
1791
|
exports.extend = extend;
|
|
1792
1792
|
exports.invalidate = invalidate;
|
|
1793
|
-
exports.is = is;
|
|
1794
1793
|
exports.omit = omit;
|
|
1795
1794
|
exports.pick = pick;
|
|
1796
1795
|
exports.reconciler = reconciler;
|