@react-three/fiber 8.0.3 → 8.0.4

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.
@@ -1,13 +1,13 @@
1
- import * as React from 'react';
2
- import type { Options as ResizeOptions } from 'react-use-measure';
3
- import { UseBoundStore } from 'zustand';
4
- import { RenderProps } from '../core';
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
+ import * as React from 'react';
2
+ import type { Options as ResizeOptions } from 'react-use-measure';
3
+ import { UseBoundStore } from 'zustand';
4
+ import { RenderProps } from '../core';
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 { UseBoundStore } from 'zustand';
2
- import { RootState } from '../core/store';
3
- import { EventManager } from '../core/events';
4
- export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
1
+ import { UseBoundStore } from 'zustand';
2
+ import { RootState } from '../core/store';
3
+ import { EventManager } from '../core/events';
4
+ export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
@@ -334,10 +334,22 @@ function applyProps$1(instance, data) {
334
334
 
335
335
  if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
336
336
  else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
337
- else targetProp.set(value);
337
+ else targetProp.set(value); // For versions of three which don't support THREE.ColorManagement,
338
+ // Auto-convert sRGB colors
339
+ // https://github.com/pmndrs/react-three-fiber/issues/344
340
+
341
+ const supportsColorManagement = THREE__namespace.ColorManagement;
342
+ if (!supportsColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
338
343
  } // Else, just overwrite the value
339
344
 
340
- } else currentInstance[key] = value;
345
+ } else {
346
+ currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
347
+ // https://github.com/pmndrs/react-three-fiber/issues/344
348
+
349
+ if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture) {
350
+ currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
351
+ }
352
+ }
341
353
 
342
354
  invalidateInstance(instance);
343
355
  });
@@ -1192,6 +1204,7 @@ const createStore = (invalidate, advance) => {
1192
1204
  xr: null,
1193
1205
  invalidate: () => invalidate(get()),
1194
1206
  advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
1207
+ legacy: false,
1195
1208
  linear: false,
1196
1209
  flat: false,
1197
1210
  scene: prepare(new THREE__namespace.Scene()),
@@ -1689,7 +1702,17 @@ function createRoot(canvas) {
1689
1702
  const outputEncoding = linear ? THREE__namespace.LinearEncoding : THREE__namespace.sRGBEncoding;
1690
1703
  const toneMapping = flat ? THREE__namespace.NoToneMapping : THREE__namespace.ACESFilmicToneMapping;
1691
1704
  if (gl.outputEncoding !== outputEncoding) gl.outputEncoding = outputEncoding;
1692
- if (gl.toneMapping !== toneMapping) gl.toneMapping = toneMapping; // Set gl props
1705
+ if (gl.toneMapping !== toneMapping) gl.toneMapping = toneMapping; // Update color management state
1706
+
1707
+ if (state.legacy !== legacy) state.set(() => ({
1708
+ legacy
1709
+ }));
1710
+ if (state.linear !== linear) state.set(() => ({
1711
+ linear
1712
+ }));
1713
+ if (state.flat !== flat) state.set(() => ({
1714
+ flat
1715
+ })); // Set gl props
1693
1716
 
1694
1717
  if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, gl, shallowLoose)) applyProps(gl, glConfig); // Store events internally
1695
1718
 
@@ -334,10 +334,22 @@ function applyProps$1(instance, data) {
334
334
 
335
335
  if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
336
336
  else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
337
- else targetProp.set(value);
337
+ else targetProp.set(value); // For versions of three which don't support THREE.ColorManagement,
338
+ // Auto-convert sRGB colors
339
+ // https://github.com/pmndrs/react-three-fiber/issues/344
340
+
341
+ const supportsColorManagement = THREE__namespace.ColorManagement;
342
+ if (!supportsColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
338
343
  } // Else, just overwrite the value
339
344
 
340
- } else currentInstance[key] = value;
345
+ } else {
346
+ currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
347
+ // https://github.com/pmndrs/react-three-fiber/issues/344
348
+
349
+ if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture) {
350
+ currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
351
+ }
352
+ }
341
353
 
342
354
  invalidateInstance(instance);
343
355
  });
@@ -1192,6 +1204,7 @@ const createStore = (invalidate, advance) => {
1192
1204
  xr: null,
1193
1205
  invalidate: () => invalidate(get()),
1194
1206
  advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
1207
+ legacy: false,
1195
1208
  linear: false,
1196
1209
  flat: false,
1197
1210
  scene: prepare(new THREE__namespace.Scene()),
@@ -1689,7 +1702,17 @@ function createRoot(canvas) {
1689
1702
  const outputEncoding = linear ? THREE__namespace.LinearEncoding : THREE__namespace.sRGBEncoding;
1690
1703
  const toneMapping = flat ? THREE__namespace.NoToneMapping : THREE__namespace.ACESFilmicToneMapping;
1691
1704
  if (gl.outputEncoding !== outputEncoding) gl.outputEncoding = outputEncoding;
1692
- if (gl.toneMapping !== toneMapping) gl.toneMapping = toneMapping; // Set gl props
1705
+ if (gl.toneMapping !== toneMapping) gl.toneMapping = toneMapping; // Update color management state
1706
+
1707
+ if (state.legacy !== legacy) state.set(() => ({
1708
+ legacy
1709
+ }));
1710
+ if (state.linear !== linear) state.set(() => ({
1711
+ linear
1712
+ }));
1713
+ if (state.flat !== flat) state.set(() => ({
1714
+ flat
1715
+ })); // Set gl props
1693
1716
 
1694
1717
  if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, gl, shallowLoose)) applyProps(gl, glConfig); // Store events internally
1695
1718
 
@@ -305,10 +305,22 @@ function applyProps$1(instance, data) {
305
305
 
306
306
  if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
307
307
  else if (targetProp instanceof THREE.Layers && value instanceof THREE.Layers) targetProp.mask = value.mask; // Otherwise just set ...
308
- else targetProp.set(value);
308
+ else targetProp.set(value); // For versions of three which don't support THREE.ColorManagement,
309
+ // Auto-convert sRGB colors
310
+ // https://github.com/pmndrs/react-three-fiber/issues/344
311
+
312
+ const supportsColorManagement = THREE.ColorManagement;
313
+ if (!supportsColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
309
314
  } // Else, just overwrite the value
310
315
 
311
- } else currentInstance[key] = value;
316
+ } else {
317
+ currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
318
+ // https://github.com/pmndrs/react-three-fiber/issues/344
319
+
320
+ if (!rootState.linear && currentInstance[key] instanceof THREE.Texture) {
321
+ currentInstance[key].encoding = THREE.sRGBEncoding;
322
+ }
323
+ }
312
324
 
313
325
  invalidateInstance(instance);
314
326
  });
@@ -1163,6 +1175,7 @@ const createStore = (invalidate, advance) => {
1163
1175
  xr: null,
1164
1176
  invalidate: () => invalidate(get()),
1165
1177
  advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
1178
+ legacy: false,
1166
1179
  linear: false,
1167
1180
  flat: false,
1168
1181
  scene: prepare(new THREE.Scene()),
@@ -1660,7 +1673,17 @@ function createRoot(canvas) {
1660
1673
  const outputEncoding = linear ? THREE.LinearEncoding : THREE.sRGBEncoding;
1661
1674
  const toneMapping = flat ? THREE.NoToneMapping : THREE.ACESFilmicToneMapping;
1662
1675
  if (gl.outputEncoding !== outputEncoding) gl.outputEncoding = outputEncoding;
1663
- if (gl.toneMapping !== toneMapping) gl.toneMapping = toneMapping; // Set gl props
1676
+ if (gl.toneMapping !== toneMapping) gl.toneMapping = toneMapping; // Update color management state
1677
+
1678
+ if (state.legacy !== legacy) state.set(() => ({
1679
+ legacy
1680
+ }));
1681
+ if (state.linear !== linear) state.set(() => ({
1682
+ linear
1683
+ }));
1684
+ if (state.flat !== flat) state.set(() => ({
1685
+ flat
1686
+ })); // Set gl props
1664
1687
 
1665
1688
  if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, gl, shallowLoose)) applyProps(gl, glConfig); // Store events internally
1666
1689
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-77a5f42b.cjs.dev.js');
5
+ var index = require('./index-6cf8dd4b.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -117,7 +117,7 @@ function createPointerEvents(store) {
117
117
  };
118
118
  }
119
119
 
120
- const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
120
+ const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
121
121
 
122
122
  function Block({
123
123
  set
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-4557e6e6.cjs.prod.js');
5
+ var index = require('./index-227921b7.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -117,7 +117,7 @@ function createPointerEvents(store) {
117
117
  };
118
118
  }
119
119
 
120
- const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
120
+ const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
121
121
 
122
122
  function Block({
123
123
  set
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMemoizedFn, p as pick, o as omit, a as createRoot, b as unmountComponentAtNode } from './index-1155e5bd.esm.js';
2
- export { t as ReactThreeFiber, v as _roots, s as act, m as addAfterEffect, l as addEffect, n as addTail, k as advance, h as applyProps, d as context, f as createPortal, a as createRoot, i as dispose, e as extend, q as getRootState, j as invalidate, g as reconciler, r as render, b as unmountComponentAtNode, y as useFrame, z as useGraph, A as useLoader, u as useMemoizedFn, w as useStore, x as useThree } from './index-1155e5bd.esm.js';
1
+ import { c as createEvents, e as extend, u as useMemoizedFn, p as pick, o as omit, a as createRoot, b as unmountComponentAtNode } from './index-de9e845e.esm.js';
2
+ export { t as ReactThreeFiber, v as _roots, s as act, m as addAfterEffect, l as addEffect, n as addTail, k as advance, h as applyProps, d as context, f as createPortal, a as createRoot, i as dispose, e as extend, q as getRootState, j as invalidate, g as reconciler, r as render, b as unmountComponentAtNode, y as useFrame, z as useGraph, A as useLoader, u as useMemoizedFn, w as useStore, x as useThree } from './index-de9e845e.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';
@@ -87,7 +87,7 @@ function createPointerEvents(store) {
87
87
  };
88
88
  }
89
89
 
90
- const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
90
+ const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
91
91
 
92
92
  function Block({
93
93
  set
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var THREE = require('three');
6
6
  var expoAsset = require('expo-asset');
7
- var index = require('../../dist/index-77a5f42b.cjs.dev.js');
7
+ var index = require('../../dist/index-6cf8dd4b.cjs.dev.js');
8
8
  var _extends = require('@babel/runtime/helpers/extends');
9
9
  var React = require('react');
10
10
  var mergeRefs = require('react-merge-refs');
@@ -125,7 +125,7 @@ function createTouchEvents(store) {
125
125
  };
126
126
  }
127
127
 
128
- const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
128
+ const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
129
129
 
130
130
  function Block({
131
131
  set
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var THREE = require('three');
6
6
  var expoAsset = require('expo-asset');
7
- var index = require('../../dist/index-4557e6e6.cjs.prod.js');
7
+ var index = require('../../dist/index-227921b7.cjs.prod.js');
8
8
  var _extends = require('@babel/runtime/helpers/extends');
9
9
  var React = require('react');
10
10
  var mergeRefs = require('react-merge-refs');
@@ -125,7 +125,7 @@ function createTouchEvents(store) {
125
125
  };
126
126
  }
127
127
 
128
- const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
128
+ const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
129
129
 
130
130
  function Block({
131
131
  set
@@ -1,7 +1,7 @@
1
1
  import * as THREE from 'three';
2
2
  import { Asset } from 'expo-asset';
3
- import { c as createEvents, e as extend, u as useMemoizedFn, p as pick, o as omit, a as createRoot, b as unmountComponentAtNode } from '../../dist/index-1155e5bd.esm.js';
4
- export { t as ReactThreeFiber, v as _roots, s as act, m as addAfterEffect, l as addEffect, n as addTail, k as advance, h as applyProps, d as context, f as createPortal, a as createRoot, i as dispose, e as extend, q as getRootState, j as invalidate, g as reconciler, r as render, b as unmountComponentAtNode, y as useFrame, z as useGraph, A as useLoader, u as useMemoizedFn, w as useStore, x as useThree } from '../../dist/index-1155e5bd.esm.js';
3
+ import { c as createEvents, e as extend, u as useMemoizedFn, p as pick, o as omit, a as createRoot, b as unmountComponentAtNode } from '../../dist/index-de9e845e.esm.js';
4
+ export { t as ReactThreeFiber, v as _roots, s as act, m as addAfterEffect, l as addEffect, n as addTail, k as advance, h as applyProps, d as context, f as createPortal, a as createRoot, i as dispose, e as extend, q as getRootState, j as invalidate, g as reconciler, r as render, b as unmountComponentAtNode, y as useFrame, z as useGraph, A as useLoader, u as useMemoizedFn, w as useStore, x as useThree } from '../../dist/index-de9e845e.esm.js';
5
5
  import _extends from '@babel/runtime/helpers/esm/extends';
6
6
  import * as React from 'react';
7
7
  import mergeRefs from 'react-merge-refs';
@@ -95,7 +95,7 @@ function createTouchEvents(store) {
95
95
  };
96
96
  }
97
97
 
98
- const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
98
+ const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
99
99
 
100
100
  function Block({
101
101
  set
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.0.3",
3
+ "version": "8.0.4",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",
@@ -58,7 +58,7 @@
58
58
  "react": ">=18.0",
59
59
  "react-dom": ">=18.0",
60
60
  "react-native": ">=0.64",
61
- "three": ">=0.139"
61
+ "three": ">=0.133"
62
62
  },
63
63
  "peerDependenciesMeta": {
64
64
  "react-dom": {