@react-three/fiber 8.12.2 → 8.13.1
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/events.d.ts +71 -71
- package/dist/declarations/src/core/hooks.d.ts +29 -29
- package/dist/declarations/src/core/index.d.ts +57 -58
- package/dist/declarations/src/core/loop.d.ts +14 -14
- package/dist/declarations/src/core/renderer.d.ts +58 -58
- package/dist/declarations/src/core/store.d.ts +94 -95
- package/dist/declarations/src/core/utils.d.ts +94 -89
- package/dist/declarations/src/index.d.ts +12 -12
- package/dist/declarations/src/native/Canvas.d.ts +10 -8
- package/dist/declarations/src/native/events.d.ts +4 -4
- package/dist/declarations/src/native/polyfills.d.ts +1 -1
- package/dist/declarations/src/native.d.ts +12 -12
- package/dist/declarations/src/three-types.d.ts +335 -335
- package/dist/declarations/src/web/Canvas.d.ts +13 -11
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/{index-21bbaaf9.esm.js → index-13b06ff5.esm.js} +56 -75
- package/dist/{index-1fcbd5a8.cjs.prod.js → index-948f4806.cjs.prod.js} +56 -75
- package/dist/{index-ab4b9c97.cjs.dev.js → index-a0deb08b.cjs.dev.js} +56 -75
- 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 +1 -1
- package/native/dist/react-three-fiber-native.cjs.prod.js +1 -1
- package/native/dist/react-three-fiber-native.esm.js +2 -2
- package/package.json +1 -1
- package/readme.md +1 -1
|
@@ -177,13 +177,7 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
// Remove references
|
|
180
|
-
|
|
181
|
-
delete child.__r3f.root;
|
|
182
|
-
delete child.__r3f.objects;
|
|
183
|
-
delete child.__r3f.handlers;
|
|
184
|
-
delete child.__r3f.memoizedProps;
|
|
185
|
-
if (!isPrimitive) delete child.__r3f;
|
|
186
|
-
}
|
|
180
|
+
delete child.__r3f;
|
|
187
181
|
|
|
188
182
|
// Dispose item whenever the reconciler feels like it
|
|
189
183
|
if (shouldDispose && child.dispose && child.type !== 'Scene') {
|
|
@@ -377,6 +371,10 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
377
371
|
}
|
|
378
372
|
|
|
379
373
|
var _window$document, _window$navigator;
|
|
374
|
+
/**
|
|
375
|
+
* Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
|
|
376
|
+
*/
|
|
377
|
+
const hasColorSpace = object => 'colorSpace' in object || 'outputColorSpace' in object;
|
|
380
378
|
/**
|
|
381
379
|
* The current THREE.ColorManagement instance, if present.
|
|
382
380
|
*/
|
|
@@ -662,6 +660,21 @@ function applyProps$1(instance, data) {
|
|
|
662
660
|
if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
|
|
663
661
|
for (let i = 0; i < changes.length; i++) {
|
|
664
662
|
let [key, value, isEvent, keys] = changes[i];
|
|
663
|
+
|
|
664
|
+
// Alias (output)encoding => (output)colorSpace (since r152)
|
|
665
|
+
// https://github.com/pmndrs/react-three-fiber/pull/2829
|
|
666
|
+
if (hasColorSpace(instance)) {
|
|
667
|
+
const sRGBEncoding = 3001;
|
|
668
|
+
const SRGBColorSpace = 'srgb';
|
|
669
|
+
const LinearSRGBColorSpace = 'srgb-linear';
|
|
670
|
+
if (key === 'encoding') {
|
|
671
|
+
key = 'colorSpace';
|
|
672
|
+
value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
|
|
673
|
+
} else if (key === 'outputEncoding') {
|
|
674
|
+
key = 'outputColorSpace';
|
|
675
|
+
value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
665
678
|
let currentInstance = instance;
|
|
666
679
|
let targetProp = currentInstance[key];
|
|
667
680
|
|
|
@@ -730,12 +743,14 @@ function applyProps$1(instance, data) {
|
|
|
730
743
|
// Else, just overwrite the value
|
|
731
744
|
} else {
|
|
732
745
|
currentInstance[key] = value;
|
|
746
|
+
|
|
733
747
|
// Auto-convert sRGB textures, for now ...
|
|
734
748
|
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
735
|
-
if (
|
|
749
|
+
if (currentInstance[key] instanceof THREE__namespace.Texture &&
|
|
736
750
|
// sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
|
|
737
751
|
currentInstance[key].format === THREE__namespace.RGBAFormat && currentInstance[key].type === THREE__namespace.UnsignedByteType) {
|
|
738
|
-
currentInstance[key]
|
|
752
|
+
const texture = currentInstance[key];
|
|
753
|
+
if (hasColorSpace(texture) && hasColorSpace(rootState.gl)) texture.colorSpace = rootState.gl.outputColorSpace;else texture.encoding = rootState.gl.outputEncoding;
|
|
739
754
|
}
|
|
740
755
|
}
|
|
741
756
|
invalidateInstance(instance);
|
|
@@ -1212,8 +1227,6 @@ function createEvents(store) {
|
|
|
1212
1227
|
};
|
|
1213
1228
|
}
|
|
1214
1229
|
|
|
1215
|
-
// Keys that shouldn't be copied between R3F stores
|
|
1216
|
-
const privateKeys = ['set', 'get', 'setSize', 'setFrameloop', 'setDpr', 'events', 'invalidate', 'advance', 'size', 'viewport'];
|
|
1217
1230
|
const isRenderer = def => !!(def != null && def.render);
|
|
1218
1231
|
const context = /*#__PURE__*/React__namespace.createContext(null);
|
|
1219
1232
|
const createStore = (invalidate, advance) => {
|
|
@@ -1915,10 +1928,14 @@ function createRoot(canvas) {
|
|
|
1915
1928
|
if (ColorManagement) {
|
|
1916
1929
|
if ('enabled' in ColorManagement) ColorManagement.enabled = !legacy;else if ('legacyMode' in ColorManagement) ColorManagement.legacyMode = legacy;
|
|
1917
1930
|
}
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1931
|
+
|
|
1932
|
+
// Set color space and tonemapping preferences
|
|
1933
|
+
const LinearEncoding = 3000;
|
|
1934
|
+
const sRGBEncoding = 3001;
|
|
1935
|
+
applyProps(gl, {
|
|
1936
|
+
outputEncoding: linear ? LinearEncoding : sRGBEncoding,
|
|
1937
|
+
toneMapping: flat ? THREE__namespace.NoToneMapping : THREE__namespace.ACESFilmicToneMapping
|
|
1938
|
+
});
|
|
1922
1939
|
|
|
1923
1940
|
// Update color management state
|
|
1924
1941
|
if (state.legacy !== legacy) state.set(() => ({
|
|
@@ -2039,7 +2056,6 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
2039
2056
|
}
|
|
2040
2057
|
function createPortal(children, container, state) {
|
|
2041
2058
|
return /*#__PURE__*/React__namespace.createElement(Portal, {
|
|
2042
|
-
key: container.uuid,
|
|
2043
2059
|
children: children,
|
|
2044
2060
|
container: container,
|
|
2045
2061
|
state: state
|
|
@@ -2063,26 +2079,9 @@ function Portal({
|
|
|
2063
2079
|
const previousRoot = useStore();
|
|
2064
2080
|
const [raycaster] = React__namespace.useState(() => new THREE__namespace.Raycaster());
|
|
2065
2081
|
const [pointer] = React__namespace.useState(() => new THREE__namespace.Vector2());
|
|
2066
|
-
const inject =
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
}; // all prev state props
|
|
2070
|
-
|
|
2071
|
-
// Only the fields of "rootState" that do not differ from injectState
|
|
2072
|
-
// Some props should be off-limits
|
|
2073
|
-
// Otherwise filter out the props that are different and let the inject layer take precedence
|
|
2074
|
-
Object.keys(rootState).forEach(key => {
|
|
2075
|
-
if (
|
|
2076
|
-
// Some props should be off-limits
|
|
2077
|
-
privateKeys.includes(key) ||
|
|
2078
|
-
// Otherwise filter out the props that are different and let the inject layer take precedence
|
|
2079
|
-
// Unless the inject layer props is undefined, then we keep the root layer
|
|
2080
|
-
rootState[key] !== injectState[key] && injectState[key]) {
|
|
2081
|
-
delete intersect[key];
|
|
2082
|
-
}
|
|
2083
|
-
});
|
|
2084
|
-
let viewport = undefined;
|
|
2085
|
-
if (injectState && size) {
|
|
2082
|
+
const inject = useMutableCallback((rootState, injectState) => {
|
|
2083
|
+
let viewport;
|
|
2084
|
+
if (injectState.camera && size) {
|
|
2086
2085
|
const camera = injectState.camera;
|
|
2087
2086
|
// Calculate the override viewport, if present
|
|
2088
2087
|
viewport = rootState.viewport.getCurrentViewport(camera, new THREE__namespace.Vector3(), size);
|
|
@@ -2091,7 +2090,9 @@ function Portal({
|
|
|
2091
2090
|
}
|
|
2092
2091
|
return {
|
|
2093
2092
|
// The intersect consists of the previous root state
|
|
2094
|
-
...
|
|
2093
|
+
...rootState,
|
|
2094
|
+
get: injectState.get,
|
|
2095
|
+
set: injectState.set,
|
|
2095
2096
|
// Portals have their own scene, which forms the root, a raycaster and a pointer
|
|
2096
2097
|
scene: container,
|
|
2097
2098
|
raycaster,
|
|
@@ -2102,7 +2103,7 @@ function Portal({
|
|
|
2102
2103
|
// Events, size and viewport can be overridden by the inject layer
|
|
2103
2104
|
events: {
|
|
2104
2105
|
...rootState.events,
|
|
2105
|
-
...
|
|
2106
|
+
...injectState.events,
|
|
2106
2107
|
...events
|
|
2107
2108
|
},
|
|
2108
2109
|
size: {
|
|
@@ -2113,53 +2114,33 @@ function Portal({
|
|
|
2113
2114
|
...rootState.viewport,
|
|
2114
2115
|
...viewport
|
|
2115
2116
|
},
|
|
2116
|
-
...rest
|
|
2117
|
-
};
|
|
2118
|
-
}, [state]);
|
|
2119
|
-
const [usePortalStore] = React__namespace.useState(() => {
|
|
2120
|
-
// Create a mirrored store, based on the previous root with a few overrides ...
|
|
2121
|
-
const previousState = previousRoot.getState();
|
|
2122
|
-
const store = create__default["default"]((set, get) => ({
|
|
2123
|
-
...previousState,
|
|
2124
|
-
scene: container,
|
|
2125
|
-
raycaster,
|
|
2126
|
-
pointer,
|
|
2127
|
-
mouse: pointer,
|
|
2128
|
-
previousRoot,
|
|
2129
|
-
events: {
|
|
2130
|
-
...previousState.events,
|
|
2131
|
-
...events
|
|
2132
|
-
},
|
|
2133
|
-
size: {
|
|
2134
|
-
...previousState.size,
|
|
2135
|
-
...size
|
|
2136
|
-
},
|
|
2137
|
-
...rest,
|
|
2138
|
-
// Set and get refer to this root-state
|
|
2139
|
-
set,
|
|
2140
|
-
get,
|
|
2141
2117
|
// Layers are allowed to override events
|
|
2142
|
-
setEvents: events => set(state => ({
|
|
2118
|
+
setEvents: events => injectState.set(state => ({
|
|
2143
2119
|
...state,
|
|
2144
2120
|
events: {
|
|
2145
2121
|
...state.events,
|
|
2146
2122
|
...events
|
|
2147
2123
|
}
|
|
2148
2124
|
}))
|
|
2149
|
-
}
|
|
2150
|
-
return store;
|
|
2125
|
+
};
|
|
2151
2126
|
});
|
|
2152
|
-
React__namespace.
|
|
2127
|
+
const usePortalStore = React__namespace.useMemo(() => {
|
|
2128
|
+
const store = create__default["default"]((set, get) => ({
|
|
2129
|
+
...rest,
|
|
2130
|
+
set,
|
|
2131
|
+
get
|
|
2132
|
+
}));
|
|
2133
|
+
|
|
2153
2134
|
// Subscribe to previous root-state and copy changes over to the mirrored portal-state
|
|
2154
|
-
const
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
}, []);
|
|
2135
|
+
const onMutate = prev => store.setState(state => inject.current(prev, state));
|
|
2136
|
+
onMutate(previousRoot.getState());
|
|
2137
|
+
previousRoot.subscribe(onMutate);
|
|
2138
|
+
return store;
|
|
2139
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2140
|
+
}, [previousRoot, container]);
|
|
2160
2141
|
React__namespace.useEffect(() => {
|
|
2161
|
-
|
|
2162
|
-
}, [
|
|
2142
|
+
return () => usePortalStore.destroy();
|
|
2143
|
+
}, [usePortalStore]);
|
|
2163
2144
|
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, reconciler.createPortal( /*#__PURE__*/React__namespace.createElement(context.Provider, {
|
|
2164
2145
|
value: usePortalStore
|
|
2165
2146
|
}, children), usePortalStore, null));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-a0deb08b.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-948f4806.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-
|
|
2
|
-
export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-
|
|
1
|
+
import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-13b06ff5.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-13b06ff5.esm.js';
|
|
3
3
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import * as THREE from 'three';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../dist/index-
|
|
5
|
+
var index = require('../../dist/index-a0deb08b.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../dist/index-
|
|
5
|
+
var index = require('../../dist/index-948f4806.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-
|
|
2
|
-
export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-
|
|
1
|
+
import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-13b06ff5.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-13b06ff5.esm.js';
|
|
3
3
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import * as THREE from 'three';
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -201,7 +201,7 @@ Visit [docs.pmnd.rs](https://docs.pmnd.rs/react-three-fiber)
|
|
|
201
201
|
|
|
202
202
|
# Fundamentals
|
|
203
203
|
|
|
204
|
-
You need to be versed in both React and Threejs before rushing into this. If you are unsure about React consult the official [React docs](https://
|
|
204
|
+
You need to be versed in both React and Threejs before rushing into this. If you are unsure about React consult the official [React docs](https://react.dev/learn), especially [the section about hooks](https://react.dev/reference/react). As for Threejs, make sure you at least glance over the following links:
|
|
205
205
|
|
|
206
206
|
1. Make sure you have a [basic grasp of Threejs](https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene). Keep that site open.
|
|
207
207
|
2. When you know what a scene is, a camera, mesh, geometry, material, fork the [demo above](https://github.com/pmndrs/react-three-fiber#what-does-it-look-like).
|