@react-three/fiber 7.0.24 → 7.0.27
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 +63 -63
- package/dist/declarations/src/core/hooks.d.ts +32 -29
- package/dist/declarations/src/core/is.d.ts +9 -9
- package/dist/declarations/src/core/loop.d.ts +12 -12
- package/dist/declarations/src/core/renderer.d.ts +61 -61
- package/dist/declarations/src/core/store.d.ts +118 -116
- package/dist/declarations/src/index.d.ts +8 -7
- package/dist/declarations/src/three-types.d.ts +329 -320
- package/dist/declarations/src/web/Canvas.d.ts +13 -13
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/declarations/src/web/index.d.ts +36 -36
- package/dist/react-three-fiber.cjs.dev.js +55 -49
- package/dist/react-three-fiber.cjs.prod.js +55 -49
- package/dist/react-three-fiber.esm.js +49 -42
- package/native/dist/react-three-fiber-native.cjs.d.ts +11 -1
- package/native/dist/react-three-fiber-native.cjs.js +15 -6
- package/package.json +3 -2
- package/native/dist/react-three-fiber-native.cjs.dev.js +0 -388
- package/native/dist/react-three-fiber-native.cjs.prod.js +0 -388
- package/native/dist/react-three-fiber-native.esm.js +0 -336
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { Options as ResizeOptions } from 'react-use-measure';
|
|
3
|
-
import { RenderProps } from './index';
|
|
4
|
-
import {
|
|
5
|
-
import { RootState } from '../core/store';
|
|
6
|
-
import { EventManager } from '../core/events';
|
|
7
|
-
export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size' | 'events'>, React.HTMLAttributes<HTMLDivElement> {
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
fallback?: React.ReactNode;
|
|
10
|
-
resize?: ResizeOptions;
|
|
11
|
-
events?: (store:
|
|
12
|
-
}
|
|
13
|
-
export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Options as ResizeOptions } from 'react-use-measure';
|
|
3
|
+
import { RenderProps } from './index';
|
|
4
|
+
import { UseBoundStore } from 'zustand';
|
|
5
|
+
import { RootState } from '../core/store';
|
|
6
|
+
import { EventManager } from '../core/events';
|
|
7
|
+
export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size' | 'events'>, React.HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
fallback?: React.ReactNode;
|
|
10
|
+
resize?: ResizeOptions;
|
|
11
|
+
events?: (store: UseBoundStore<RootState>) => EventManager<any>;
|
|
12
|
+
}
|
|
13
|
+
export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { RootState } from '../core/store';
|
|
3
|
-
import type { EventManager } from '../core/events';
|
|
4
|
-
export declare function createPointerEvents(store:
|
|
1
|
+
import { UseBoundStore } from 'zustand';
|
|
2
|
+
import { RootState } from '../core/store';
|
|
3
|
+
import type { EventManager } from '../core/events';
|
|
4
|
+
export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
/// <reference types="react-reconciler" />
|
|
2
|
-
import * as THREE from 'three';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import {
|
|
5
|
-
import { Renderer, StoreProps, context, RootState, Size } from '../core/store';
|
|
6
|
-
import { extend, Root } from '../core/renderer';
|
|
7
|
-
import { addEffect, addAfterEffect, addTail } from '../core/loop';
|
|
8
|
-
import { createPointerEvents as events } from './events';
|
|
9
|
-
import { Canvas } from './Canvas';
|
|
10
|
-
import { EventManager } from '../core/events';
|
|
11
|
-
declare const roots: Map<Element, Root>;
|
|
12
|
-
declare const modes: readonly ["legacy", "blocking", "concurrent"];
|
|
13
|
-
declare const invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined) => void;
|
|
14
|
-
declare const reconciler: import("react-reconciler").Reconciler<unknown, unknown, unknown, unknown, unknown>, applyProps: (instance: import("../core/renderer").Instance, data: import("../core/renderer").
|
|
15
|
-
declare type Properties<T> = Pick<T, {
|
|
16
|
-
[K in keyof T]: T[K] extends (_: any) => any ? never : K;
|
|
17
|
-
}[keyof T]>;
|
|
18
|
-
declare type GLProps = Renderer | ((canvas: HTMLCanvasElement) => Renderer) | Partial<Properties<THREE.WebGLRenderer> | THREE.WebGLRendererParameters> | undefined;
|
|
19
|
-
export declare type RenderProps<TCanvas extends Element> = Omit<StoreProps, 'gl' | 'events' | 'size'> & {
|
|
20
|
-
gl?: GLProps;
|
|
21
|
-
events?: (store:
|
|
22
|
-
size?: Size;
|
|
23
|
-
mode?: typeof modes[number];
|
|
24
|
-
onCreated?: (state: RootState) => void;
|
|
25
|
-
};
|
|
26
|
-
declare function render<TCanvas extends Element>(element: React.ReactNode, canvas: TCanvas, { gl, size, mode, events, onCreated, ...props }?: RenderProps<TCanvas>):
|
|
27
|
-
declare function unmountComponentAtNode<TElement extends Element>(canvas: TElement, callback?: (canvas: TElement) => void): void;
|
|
28
|
-
declare function dispose<TObj extends {
|
|
29
|
-
dispose?: () => void;
|
|
30
|
-
type?: string;
|
|
31
|
-
[key: string]: any;
|
|
32
|
-
}>(obj: TObj): void;
|
|
33
|
-
declare const act: (callback: () => import("react-reconciler").Thenable<unknown>) => import("react-reconciler").Thenable<void>;
|
|
34
|
-
declare function createPortal(children: React.ReactNode, container: THREE.Object3D): React.ReactNode;
|
|
35
|
-
export * from '../core/hooks';
|
|
36
|
-
export { context, render, unmountComponentAtNode, createPortal, events, reconciler, applyProps, dispose, invalidate, advance, extend, addEffect, addAfterEffect, addTail, Canvas, act, roots as _roots, };
|
|
1
|
+
/// <reference types="react-reconciler" />
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { UseBoundStore } from 'zustand';
|
|
5
|
+
import { Renderer, StoreProps, context, RootState, Size } from '../core/store';
|
|
6
|
+
import { extend, Root } from '../core/renderer';
|
|
7
|
+
import { addEffect, addAfterEffect, addTail } from '../core/loop';
|
|
8
|
+
import { createPointerEvents as events } from './events';
|
|
9
|
+
import { Canvas } from './Canvas';
|
|
10
|
+
import { EventManager } from '../core/events';
|
|
11
|
+
declare const roots: Map<Element, Root>;
|
|
12
|
+
declare const modes: readonly ["legacy", "blocking", "concurrent"];
|
|
13
|
+
declare const invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined) => void;
|
|
14
|
+
declare const reconciler: import("react-reconciler").Reconciler<unknown, unknown, unknown, unknown, unknown>, applyProps: (instance: import("../core/renderer").Instance, data: import("../core/renderer").DiffSet | import("../core/renderer").InstanceProps) => import("../core/renderer").Instance;
|
|
15
|
+
declare type Properties<T> = Pick<T, {
|
|
16
|
+
[K in keyof T]: T[K] extends (_: any) => any ? never : K;
|
|
17
|
+
}[keyof T]>;
|
|
18
|
+
declare type GLProps = Renderer | ((canvas: HTMLCanvasElement) => Renderer) | Partial<Properties<THREE.WebGLRenderer> | THREE.WebGLRendererParameters> | undefined;
|
|
19
|
+
export declare type RenderProps<TCanvas extends Element> = Omit<StoreProps, 'gl' | 'events' | 'size'> & {
|
|
20
|
+
gl?: GLProps;
|
|
21
|
+
events?: (store: UseBoundStore<RootState>) => EventManager<TCanvas>;
|
|
22
|
+
size?: Size;
|
|
23
|
+
mode?: typeof modes[number];
|
|
24
|
+
onCreated?: (state: RootState) => void;
|
|
25
|
+
};
|
|
26
|
+
declare function render<TCanvas extends Element>(element: React.ReactNode, canvas: TCanvas, { gl, size, mode, events, onCreated, ...props }?: RenderProps<TCanvas>): UseBoundStore<RootState>;
|
|
27
|
+
declare function unmountComponentAtNode<TElement extends Element>(canvas: TElement, callback?: (canvas: TElement) => void): void;
|
|
28
|
+
declare function dispose<TObj extends {
|
|
29
|
+
dispose?: () => void;
|
|
30
|
+
type?: string;
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
}>(obj: TObj): void;
|
|
33
|
+
declare const act: (callback: () => import("react-reconciler").Thenable<unknown>) => import("react-reconciler").Thenable<void>;
|
|
34
|
+
declare function createPortal(children: React.ReactNode, container: THREE.Object3D): React.ReactNode;
|
|
35
|
+
export * from '../core/hooks';
|
|
36
|
+
export { context, render, unmountComponentAtNode, createPortal, events, reconciler, applyProps, dispose, invalidate, advance, extend, addEffect, addAfterEffect, addTail, Canvas, act, roots as _roots, };
|
|
@@ -22,14 +22,12 @@ function _interopNamespace(e) {
|
|
|
22
22
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
23
|
Object.defineProperty(n, k, d.get ? d : {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () {
|
|
26
|
-
return e[k];
|
|
27
|
-
}
|
|
25
|
+
get: function () { return e[k]; }
|
|
28
26
|
});
|
|
29
27
|
}
|
|
30
28
|
});
|
|
31
29
|
}
|
|
32
|
-
n[
|
|
30
|
+
n["default"] = e;
|
|
33
31
|
return Object.freeze(n);
|
|
34
32
|
}
|
|
35
33
|
|
|
@@ -114,7 +112,7 @@ function createEvents(store) {
|
|
|
114
112
|
/** Sets up defaultRaycaster */
|
|
115
113
|
|
|
116
114
|
function prepareRay(event) {
|
|
117
|
-
var
|
|
115
|
+
var _customOffsets$offset, _customOffsets$offset2, _customOffsets$width, _customOffsets$height;
|
|
118
116
|
|
|
119
117
|
const state = store.getState();
|
|
120
118
|
const {
|
|
@@ -125,14 +123,11 @@ function createEvents(store) {
|
|
|
125
123
|
} = state; // https://github.com/pmndrs/react-three-fiber/pull/782
|
|
126
124
|
// Events trigger outside of canvas when moved
|
|
127
125
|
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
width,
|
|
134
|
-
height
|
|
135
|
-
} = size;
|
|
126
|
+
const customOffsets = raycaster.computeOffsets == null ? void 0 : raycaster.computeOffsets(event, state);
|
|
127
|
+
const offsetX = (_customOffsets$offset = customOffsets == null ? void 0 : customOffsets.offsetX) != null ? _customOffsets$offset : event.offsetX;
|
|
128
|
+
const offsetY = (_customOffsets$offset2 = customOffsets == null ? void 0 : customOffsets.offsetY) != null ? _customOffsets$offset2 : event.offsetY;
|
|
129
|
+
const width = (_customOffsets$width = customOffsets == null ? void 0 : customOffsets.width) != null ? _customOffsets$width : size.width;
|
|
130
|
+
const height = (_customOffsets$height = customOffsets == null ? void 0 : customOffsets.height) != null ? _customOffsets$height : size.height;
|
|
136
131
|
mouse.set(offsetX / width * 2 - 1, -(offsetY / height) * 2 + 1);
|
|
137
132
|
raycaster.setFromCamera(mouse, camera);
|
|
138
133
|
}
|
|
@@ -588,6 +583,8 @@ function createRenderer(roots) {
|
|
|
588
583
|
|
|
589
584
|
if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
|
|
590
585
|
changes.forEach(([key, value, isEvent, keys]) => {
|
|
586
|
+
var _rootState$gl;
|
|
587
|
+
|
|
591
588
|
let currentInstance = instance;
|
|
592
589
|
let targetProp = currentInstance[key]; // Revolve dashed props
|
|
593
590
|
|
|
@@ -618,37 +615,38 @@ function createRenderer(roots) {
|
|
|
618
615
|
|
|
619
616
|
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
620
617
|
} else value = 0;
|
|
621
|
-
}
|
|
618
|
+
}
|
|
622
619
|
|
|
620
|
+
const isLinear = (rootState == null ? void 0 : (_rootState$gl = rootState.gl) == null ? void 0 : _rootState$gl.outputEncoding) === THREE__namespace.LinearEncoding; // Deal with pointer events ...
|
|
623
621
|
|
|
624
622
|
if (isEvent) {
|
|
625
623
|
if (value) localState.handlers[key] = value;else delete localState.handlers[key];
|
|
626
624
|
localState.eventCount = Object.keys(localState.handlers).length;
|
|
627
625
|
} // Special treatment for objects with support for set/copy, and layers
|
|
628
626
|
else if (targetProp && targetProp.set && (targetProp.copy || targetProp instanceof THREE__namespace.Layers)) {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
642
|
-
|
|
643
|
-
if (!rootState.linear && isColor) targetProp.convertSRGBToLinear();
|
|
644
|
-
} // Else, just overwrite the value
|
|
645
|
-
|
|
646
|
-
} else {
|
|
647
|
-
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
627
|
+
// If value is an array
|
|
628
|
+
if (Array.isArray(value)) {
|
|
629
|
+
if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
|
|
630
|
+
} // Test again target.copy(class) next ...
|
|
631
|
+
else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) targetProp.copy(value); // If nothing else fits, just set the single value, ignore undefined
|
|
632
|
+
// https://github.com/pmndrs/react-three-fiber/issues/274
|
|
633
|
+
else if (value !== undefined) {
|
|
634
|
+
const isColor = targetProp instanceof THREE__namespace.Color; // Allow setting array scalars
|
|
635
|
+
|
|
636
|
+
if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
|
|
637
|
+
else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
|
|
638
|
+
else targetProp.set(value); // Auto-convert sRGB colors, for now ...
|
|
648
639
|
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
649
640
|
|
|
650
|
-
if (!
|
|
651
|
-
}
|
|
641
|
+
if (!isLinear && isColor) targetProp.convertSRGBToLinear();
|
|
642
|
+
} // Else, just overwrite the value
|
|
643
|
+
|
|
644
|
+
} else {
|
|
645
|
+
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
646
|
+
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
647
|
+
|
|
648
|
+
if (!isLinear && currentInstance[key] instanceof THREE__namespace.Texture) currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
|
|
649
|
+
}
|
|
652
650
|
|
|
653
651
|
invalidateInstance(instance);
|
|
654
652
|
});
|
|
@@ -924,10 +922,13 @@ function createRenderer(roots) {
|
|
|
924
922
|
|
|
925
923
|
instance.__r3f.objects = [];
|
|
926
924
|
removeChild(parent, instance);
|
|
927
|
-
appendChild(parent, newInstance) //
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
925
|
+
appendChild(parent, newInstance); // Re-bind event handlers
|
|
926
|
+
|
|
927
|
+
if (newInstance.raycast && newInstance.__r3f.eventCount) {
|
|
928
|
+
const rootState = newInstance.__r3f.root.getState();
|
|
929
|
+
|
|
930
|
+
rootState.internal.interaction.push(newInstance);
|
|
931
|
+
} // This evil hack switches the react-internal fiber node
|
|
931
932
|
[fiber, fiber.alternate].forEach(fiber => {
|
|
932
933
|
if (fiber !== null) {
|
|
933
934
|
fiber.stateNode = newInstance;
|
|
@@ -939,7 +940,7 @@ function createRenderer(roots) {
|
|
|
939
940
|
});
|
|
940
941
|
}
|
|
941
942
|
|
|
942
|
-
const reconciler = Reconciler__default[
|
|
943
|
+
const reconciler = Reconciler__default["default"]({
|
|
943
944
|
now: scheduler.unstable_now,
|
|
944
945
|
createInstance,
|
|
945
946
|
removeChild,
|
|
@@ -1053,9 +1054,7 @@ function createRenderer(roots) {
|
|
|
1053
1054
|
return !!localState.handlers;
|
|
1054
1055
|
},
|
|
1055
1056
|
|
|
1056
|
-
commitMount(instance)
|
|
1057
|
-
/*, type, props*/
|
|
1058
|
-
{
|
|
1057
|
+
commitMount(instance) {
|
|
1059
1058
|
var _instance$__r3f8;
|
|
1060
1059
|
|
|
1061
1060
|
// https://github.com/facebook/react/issues/20271
|
|
@@ -1133,7 +1132,7 @@ const createStore = (applyProps, invalidate, advance, props) => {
|
|
|
1133
1132
|
clock.elapsedTime = 0;
|
|
1134
1133
|
}
|
|
1135
1134
|
|
|
1136
|
-
const rootState = create__default[
|
|
1135
|
+
const rootState = create__default["default"]((set, get) => {
|
|
1137
1136
|
// Create custom raycaster
|
|
1138
1137
|
const raycaster = new THREE__namespace.Raycaster();
|
|
1139
1138
|
const {
|
|
@@ -1567,10 +1566,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
1567
1566
|
events,
|
|
1568
1567
|
...props
|
|
1569
1568
|
}, forwardedRef) {
|
|
1569
|
+
const onPointerMissed = useMemoizedFn(props.onPointerMissed);
|
|
1570
1570
|
const [containerRef, {
|
|
1571
1571
|
width,
|
|
1572
1572
|
height
|
|
1573
|
-
}] = useMeasure__default[
|
|
1573
|
+
}] = useMeasure__default["default"]({
|
|
1574
1574
|
scroll: true,
|
|
1575
1575
|
debounce: {
|
|
1576
1576
|
scroll: 50,
|
|
@@ -1599,10 +1599,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
1599
1599
|
width,
|
|
1600
1600
|
height
|
|
1601
1601
|
},
|
|
1602
|
+
onPointerMissed,
|
|
1602
1603
|
events: events || createPointerEvents
|
|
1603
1604
|
});
|
|
1604
1605
|
}
|
|
1605
|
-
}, [width, height, children]);
|
|
1606
|
+
}, [width, height, children, onPointerMissed]);
|
|
1606
1607
|
useIsomorphicLayoutEffect(() => {
|
|
1607
1608
|
const container = canvasRef.current;
|
|
1608
1609
|
return () => unmountComponentAtNode(container);
|
|
@@ -1620,7 +1621,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
1620
1621
|
...style
|
|
1621
1622
|
}
|
|
1622
1623
|
}, /*#__PURE__*/React__namespace.createElement("canvas", {
|
|
1623
|
-
ref: mergeRefs__default[
|
|
1624
|
+
ref: mergeRefs__default["default"]([canvasRef, forwardedRef]),
|
|
1624
1625
|
style: {
|
|
1625
1626
|
display: 'block'
|
|
1626
1627
|
}
|
|
@@ -1683,6 +1684,11 @@ function loadingFn(extensions, onProgress) {
|
|
|
1683
1684
|
};
|
|
1684
1685
|
}
|
|
1685
1686
|
|
|
1687
|
+
function useMemoizedFn(fn) {
|
|
1688
|
+
const fnRef = React__namespace.useRef(fn);
|
|
1689
|
+
React__namespace.useLayoutEffect(() => void (fnRef.current = fn), [fn]);
|
|
1690
|
+
return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
|
|
1691
|
+
}
|
|
1686
1692
|
function useLoader(Proto, input, extensions, onProgress) {
|
|
1687
1693
|
// Use suspense to load async assets
|
|
1688
1694
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1868,8 +1874,7 @@ function dispose(obj) {
|
|
|
1868
1874
|
if (obj.dispose && obj.type !== 'Scene') obj.dispose();
|
|
1869
1875
|
|
|
1870
1876
|
for (const p in obj) {
|
|
1871
|
-
|
|
1872
|
-
(_dispose = (_ref = p).dispose) == null ? void 0 : _dispose.call(_ref);
|
|
1877
|
+
p.dispose == null ? void 0 : p.dispose();
|
|
1873
1878
|
delete obj[p];
|
|
1874
1879
|
}
|
|
1875
1880
|
}
|
|
@@ -1907,5 +1912,6 @@ exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
|
1907
1912
|
exports.useFrame = useFrame;
|
|
1908
1913
|
exports.useGraph = useGraph;
|
|
1909
1914
|
exports.useLoader = useLoader;
|
|
1915
|
+
exports.useMemoizedFn = useMemoizedFn;
|
|
1910
1916
|
exports.useStore = useStore;
|
|
1911
1917
|
exports.useThree = useThree;
|
|
@@ -22,14 +22,12 @@ function _interopNamespace(e) {
|
|
|
22
22
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
23
|
Object.defineProperty(n, k, d.get ? d : {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () {
|
|
26
|
-
return e[k];
|
|
27
|
-
}
|
|
25
|
+
get: function () { return e[k]; }
|
|
28
26
|
});
|
|
29
27
|
}
|
|
30
28
|
});
|
|
31
29
|
}
|
|
32
|
-
n[
|
|
30
|
+
n["default"] = e;
|
|
33
31
|
return Object.freeze(n);
|
|
34
32
|
}
|
|
35
33
|
|
|
@@ -114,7 +112,7 @@ function createEvents(store) {
|
|
|
114
112
|
/** Sets up defaultRaycaster */
|
|
115
113
|
|
|
116
114
|
function prepareRay(event) {
|
|
117
|
-
var
|
|
115
|
+
var _customOffsets$offset, _customOffsets$offset2, _customOffsets$width, _customOffsets$height;
|
|
118
116
|
|
|
119
117
|
const state = store.getState();
|
|
120
118
|
const {
|
|
@@ -125,14 +123,11 @@ function createEvents(store) {
|
|
|
125
123
|
} = state; // https://github.com/pmndrs/react-three-fiber/pull/782
|
|
126
124
|
// Events trigger outside of canvas when moved
|
|
127
125
|
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
width,
|
|
134
|
-
height
|
|
135
|
-
} = size;
|
|
126
|
+
const customOffsets = raycaster.computeOffsets == null ? void 0 : raycaster.computeOffsets(event, state);
|
|
127
|
+
const offsetX = (_customOffsets$offset = customOffsets == null ? void 0 : customOffsets.offsetX) != null ? _customOffsets$offset : event.offsetX;
|
|
128
|
+
const offsetY = (_customOffsets$offset2 = customOffsets == null ? void 0 : customOffsets.offsetY) != null ? _customOffsets$offset2 : event.offsetY;
|
|
129
|
+
const width = (_customOffsets$width = customOffsets == null ? void 0 : customOffsets.width) != null ? _customOffsets$width : size.width;
|
|
130
|
+
const height = (_customOffsets$height = customOffsets == null ? void 0 : customOffsets.height) != null ? _customOffsets$height : size.height;
|
|
136
131
|
mouse.set(offsetX / width * 2 - 1, -(offsetY / height) * 2 + 1);
|
|
137
132
|
raycaster.setFromCamera(mouse, camera);
|
|
138
133
|
}
|
|
@@ -588,6 +583,8 @@ function createRenderer(roots) {
|
|
|
588
583
|
|
|
589
584
|
if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
|
|
590
585
|
changes.forEach(([key, value, isEvent, keys]) => {
|
|
586
|
+
var _rootState$gl;
|
|
587
|
+
|
|
591
588
|
let currentInstance = instance;
|
|
592
589
|
let targetProp = currentInstance[key]; // Revolve dashed props
|
|
593
590
|
|
|
@@ -618,37 +615,38 @@ function createRenderer(roots) {
|
|
|
618
615
|
|
|
619
616
|
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
620
617
|
} else value = 0;
|
|
621
|
-
}
|
|
618
|
+
}
|
|
622
619
|
|
|
620
|
+
const isLinear = (rootState == null ? void 0 : (_rootState$gl = rootState.gl) == null ? void 0 : _rootState$gl.outputEncoding) === THREE__namespace.LinearEncoding; // Deal with pointer events ...
|
|
623
621
|
|
|
624
622
|
if (isEvent) {
|
|
625
623
|
if (value) localState.handlers[key] = value;else delete localState.handlers[key];
|
|
626
624
|
localState.eventCount = Object.keys(localState.handlers).length;
|
|
627
625
|
} // Special treatment for objects with support for set/copy, and layers
|
|
628
626
|
else if (targetProp && targetProp.set && (targetProp.copy || targetProp instanceof THREE__namespace.Layers)) {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
642
|
-
|
|
643
|
-
if (!rootState.linear && isColor) targetProp.convertSRGBToLinear();
|
|
644
|
-
} // Else, just overwrite the value
|
|
645
|
-
|
|
646
|
-
} else {
|
|
647
|
-
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
627
|
+
// If value is an array
|
|
628
|
+
if (Array.isArray(value)) {
|
|
629
|
+
if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
|
|
630
|
+
} // Test again target.copy(class) next ...
|
|
631
|
+
else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) targetProp.copy(value); // If nothing else fits, just set the single value, ignore undefined
|
|
632
|
+
// https://github.com/pmndrs/react-three-fiber/issues/274
|
|
633
|
+
else if (value !== undefined) {
|
|
634
|
+
const isColor = targetProp instanceof THREE__namespace.Color; // Allow setting array scalars
|
|
635
|
+
|
|
636
|
+
if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
|
|
637
|
+
else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
|
|
638
|
+
else targetProp.set(value); // Auto-convert sRGB colors, for now ...
|
|
648
639
|
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
649
640
|
|
|
650
|
-
if (!
|
|
651
|
-
}
|
|
641
|
+
if (!isLinear && isColor) targetProp.convertSRGBToLinear();
|
|
642
|
+
} // Else, just overwrite the value
|
|
643
|
+
|
|
644
|
+
} else {
|
|
645
|
+
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
646
|
+
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
647
|
+
|
|
648
|
+
if (!isLinear && currentInstance[key] instanceof THREE__namespace.Texture) currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
|
|
649
|
+
}
|
|
652
650
|
|
|
653
651
|
invalidateInstance(instance);
|
|
654
652
|
});
|
|
@@ -924,10 +922,13 @@ function createRenderer(roots) {
|
|
|
924
922
|
|
|
925
923
|
instance.__r3f.objects = [];
|
|
926
924
|
removeChild(parent, instance);
|
|
927
|
-
appendChild(parent, newInstance) //
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
925
|
+
appendChild(parent, newInstance); // Re-bind event handlers
|
|
926
|
+
|
|
927
|
+
if (newInstance.raycast && newInstance.__r3f.eventCount) {
|
|
928
|
+
const rootState = newInstance.__r3f.root.getState();
|
|
929
|
+
|
|
930
|
+
rootState.internal.interaction.push(newInstance);
|
|
931
|
+
} // This evil hack switches the react-internal fiber node
|
|
931
932
|
[fiber, fiber.alternate].forEach(fiber => {
|
|
932
933
|
if (fiber !== null) {
|
|
933
934
|
fiber.stateNode = newInstance;
|
|
@@ -939,7 +940,7 @@ function createRenderer(roots) {
|
|
|
939
940
|
});
|
|
940
941
|
}
|
|
941
942
|
|
|
942
|
-
const reconciler = Reconciler__default[
|
|
943
|
+
const reconciler = Reconciler__default["default"]({
|
|
943
944
|
now: scheduler.unstable_now,
|
|
944
945
|
createInstance,
|
|
945
946
|
removeChild,
|
|
@@ -1053,9 +1054,7 @@ function createRenderer(roots) {
|
|
|
1053
1054
|
return !!localState.handlers;
|
|
1054
1055
|
},
|
|
1055
1056
|
|
|
1056
|
-
commitMount(instance)
|
|
1057
|
-
/*, type, props*/
|
|
1058
|
-
{
|
|
1057
|
+
commitMount(instance) {
|
|
1059
1058
|
var _instance$__r3f8;
|
|
1060
1059
|
|
|
1061
1060
|
// https://github.com/facebook/react/issues/20271
|
|
@@ -1133,7 +1132,7 @@ const createStore = (applyProps, invalidate, advance, props) => {
|
|
|
1133
1132
|
clock.elapsedTime = 0;
|
|
1134
1133
|
}
|
|
1135
1134
|
|
|
1136
|
-
const rootState = create__default[
|
|
1135
|
+
const rootState = create__default["default"]((set, get) => {
|
|
1137
1136
|
// Create custom raycaster
|
|
1138
1137
|
const raycaster = new THREE__namespace.Raycaster();
|
|
1139
1138
|
const {
|
|
@@ -1567,10 +1566,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
1567
1566
|
events,
|
|
1568
1567
|
...props
|
|
1569
1568
|
}, forwardedRef) {
|
|
1569
|
+
const onPointerMissed = useMemoizedFn(props.onPointerMissed);
|
|
1570
1570
|
const [containerRef, {
|
|
1571
1571
|
width,
|
|
1572
1572
|
height
|
|
1573
|
-
}] = useMeasure__default[
|
|
1573
|
+
}] = useMeasure__default["default"]({
|
|
1574
1574
|
scroll: true,
|
|
1575
1575
|
debounce: {
|
|
1576
1576
|
scroll: 50,
|
|
@@ -1599,10 +1599,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
1599
1599
|
width,
|
|
1600
1600
|
height
|
|
1601
1601
|
},
|
|
1602
|
+
onPointerMissed,
|
|
1602
1603
|
events: events || createPointerEvents
|
|
1603
1604
|
});
|
|
1604
1605
|
}
|
|
1605
|
-
}, [width, height, children]);
|
|
1606
|
+
}, [width, height, children, onPointerMissed]);
|
|
1606
1607
|
useIsomorphicLayoutEffect(() => {
|
|
1607
1608
|
const container = canvasRef.current;
|
|
1608
1609
|
return () => unmountComponentAtNode(container);
|
|
@@ -1620,7 +1621,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
1620
1621
|
...style
|
|
1621
1622
|
}
|
|
1622
1623
|
}, /*#__PURE__*/React__namespace.createElement("canvas", {
|
|
1623
|
-
ref: mergeRefs__default[
|
|
1624
|
+
ref: mergeRefs__default["default"]([canvasRef, forwardedRef]),
|
|
1624
1625
|
style: {
|
|
1625
1626
|
display: 'block'
|
|
1626
1627
|
}
|
|
@@ -1683,6 +1684,11 @@ function loadingFn(extensions, onProgress) {
|
|
|
1683
1684
|
};
|
|
1684
1685
|
}
|
|
1685
1686
|
|
|
1687
|
+
function useMemoizedFn(fn) {
|
|
1688
|
+
const fnRef = React__namespace.useRef(fn);
|
|
1689
|
+
React__namespace.useLayoutEffect(() => void (fnRef.current = fn), [fn]);
|
|
1690
|
+
return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
|
|
1691
|
+
}
|
|
1686
1692
|
function useLoader(Proto, input, extensions, onProgress) {
|
|
1687
1693
|
// Use suspense to load async assets
|
|
1688
1694
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1868,8 +1874,7 @@ function dispose(obj) {
|
|
|
1868
1874
|
if (obj.dispose && obj.type !== 'Scene') obj.dispose();
|
|
1869
1875
|
|
|
1870
1876
|
for (const p in obj) {
|
|
1871
|
-
|
|
1872
|
-
(_dispose = (_ref = p).dispose) == null ? void 0 : _dispose.call(_ref);
|
|
1877
|
+
p.dispose == null ? void 0 : p.dispose();
|
|
1873
1878
|
delete obj[p];
|
|
1874
1879
|
}
|
|
1875
1880
|
}
|
|
@@ -1907,5 +1912,6 @@ exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
|
1907
1912
|
exports.useFrame = useFrame;
|
|
1908
1913
|
exports.useGraph = useGraph;
|
|
1909
1914
|
exports.useLoader = useLoader;
|
|
1915
|
+
exports.useMemoizedFn = useMemoizedFn;
|
|
1910
1916
|
exports.useStore = useStore;
|
|
1911
1917
|
exports.useThree = useThree;
|