@react-three/fiber 8.11.1 → 8.11.3

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.11.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 2bce569c: fix: progressively set colormanagement
8
+
9
+ ## 8.11.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 41d655cd: fix: hmr, srgb encode
14
+
3
15
  ## 8.11.1
4
16
 
5
17
  ### Patch Changes
@@ -2,6 +2,12 @@ import * as THREE from 'three';
2
2
  import * as React from 'react';
3
3
  import { AttachType, Instance, InstanceProps, LocalState } from './renderer';
4
4
  import { Dpr, RootState, Size } from './store';
5
+ export declare type ColorManagementRepresentation = {
6
+ enabled: boolean | never;
7
+ } | {
8
+ legacyMode: boolean | never;
9
+ };
10
+ export declare const ColorManagement: ColorManagementRepresentation | null;
5
11
  export declare type Camera = THREE.OrthographicCamera | THREE.PerspectiveCamera;
6
12
  export declare const isOrthographicCamera: (def: Camera) => def is THREE.OrthographicCamera;
7
13
  export declare const isRef: (obj: any) => obj is React.MutableRefObject<unknown>;
@@ -29,6 +35,7 @@ export declare class ErrorBoundary extends React.Component<{
29
35
  render(): React.ReactNode;
30
36
  }
31
37
  export declare const DEFAULT = "__default";
38
+ export declare const DEFAULTS: Map<any, any>;
32
39
  export declare type DiffSet = {
33
40
  memoized: {
34
41
  [key: string]: any;
@@ -80,4 +87,3 @@ export declare function updateInstance(instance: Instance): void;
80
87
  export declare function updateCamera(camera: Camera & {
81
88
  manual?: boolean;
82
89
  }, size: Size): void;
83
- export declare function setDeep(obj: any, value: any, keys: string[]): any;
@@ -11,6 +11,14 @@ var threeTypes = /*#__PURE__*/Object.freeze({
11
11
  });
12
12
 
13
13
  var _window$document, _window$navigator;
14
+ /**
15
+ * Safely accesses a deeply-nested value on an object to get around static bundler analysis.
16
+ */
17
+ const getDeep = (obj, ...keys) => keys.reduce((acc, key) => acc == null ? void 0 : acc[key], obj);
18
+ /**
19
+ * The current THREE.ColorManagement instance, if present.
20
+ */
21
+ const ColorManagement = 'ColorManagement' in THREE && getDeep(THREE, 'ColorManagement') || null;
14
22
  const isOrthographicCamera = def => def && def.isOrthographicCamera;
15
23
  const isRef = obj => obj && obj.hasOwnProperty('current');
16
24
 
@@ -56,6 +64,7 @@ ErrorBoundary.getDerivedStateFromError = () => ({
56
64
  error: true
57
65
  });
58
66
  const DEFAULT = '__default';
67
+ const DEFAULTS = new Map();
59
68
  const isDiffSet = def => def && !!def.memoized && !!def.changes;
60
69
  function calculateDpr(dpr) {
61
70
  const target = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
@@ -293,13 +302,14 @@ function applyProps$1(instance, data) {
293
302
  // For removed props, try to set default values, if possible
294
303
  if (value === DEFAULT + 'remove') {
295
304
  if (currentInstance.constructor) {
296
- var _currentInstance$__r;
297
305
  // create a blank slate of the instance and copy the particular parameter.
298
- // @ts-ignore
299
- const defaultClassCall = new currentInstance.constructor(...((_currentInstance$__r = currentInstance.__r3f.memoizedProps.args) != null ? _currentInstance$__r : []));
300
- value = defaultClassCall[key];
301
- // destroy the instance
302
- if (defaultClassCall.dispose) defaultClassCall.dispose();
306
+ let ctor = DEFAULTS.get(currentInstance.constructor);
307
+ if (!ctor) {
308
+ // @ts-ignore
309
+ ctor = new currentInstance.constructor();
310
+ DEFAULTS.set(currentInstance.constructor, ctor);
311
+ }
312
+ value = ctor[key];
303
313
  } else {
304
314
  // instance does not have constructor, just set it to 0
305
315
  value = 0;
@@ -318,7 +328,7 @@ function applyProps$1(instance, data) {
318
328
  if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
319
329
  }
320
330
  // Test again target.copy(class) next ...
321
- else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) {
331
+ else if (targetProp.copy && value && value.constructor && targetProp.constructor === value.constructor) {
322
332
  targetProp.copy(value);
323
333
  }
324
334
  // If nothing else fits, just set the single value, ignore undefined
@@ -334,15 +344,16 @@ function applyProps$1(instance, data) {
334
344
  // For versions of three which don't support THREE.ColorManagement,
335
345
  // Auto-convert sRGB colors
336
346
  // https://github.com/pmndrs/react-three-fiber/issues/344
337
- const supportsColorManagement = ('ColorManagement' in THREE);
338
- if (!supportsColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
347
+ if (!ColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
339
348
  }
340
349
  // Else, just overwrite the value
341
350
  } else {
342
351
  currentInstance[key] = value;
343
352
  // Auto-convert sRGB textures, for now ...
344
353
  // https://github.com/pmndrs/react-three-fiber/issues/344
345
- if (!rootState.linear && currentInstance[key] instanceof THREE.Texture) {
354
+ if (!rootState.linear && currentInstance[key] instanceof THREE.Texture &&
355
+ // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
356
+ currentInstance[key].format === THREE.RGBAFormat && currentInstance[key].type === THREE.UnsignedByteType) {
346
357
  currentInstance[key].encoding = THREE.sRGBEncoding;
347
358
  }
348
359
  }
@@ -389,15 +400,6 @@ function updateCamera(camera, size) {
389
400
  }
390
401
  }
391
402
 
392
- /**
393
- * Safely sets a deeply-nested value on an object.
394
- */
395
- function setDeep(obj, value, keys) {
396
- const key = keys.pop();
397
- const target = keys.reduce((acc, key) => acc[key], obj);
398
- return target[key] = value;
399
- }
400
-
401
403
  function makeId(event) {
402
404
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
403
405
  }
@@ -1826,8 +1828,8 @@ function createRoot(canvas) {
1826
1828
 
1827
1829
  // Safely set color management if available.
1828
1830
  // Avoid accessing THREE.ColorManagement to play nice with older versions
1829
- if ('ColorManagement' in THREE) {
1830
- setDeep(THREE, legacy, ['ColorManagement', 'legacyMode']);
1831
+ if (ColorManagement) {
1832
+ if ('enabled' in ColorManagement) ColorManagement.enabled = !legacy;else if ('legacyMode' in ColorManagement) ColorManagement.legacyMode = legacy;
1831
1833
  }
1832
1834
  const outputEncoding = linear ? THREE.LinearEncoding : THREE.sRGBEncoding;
1833
1835
  const toneMapping = flat ? THREE.NoToneMapping : THREE.ACESFilmicToneMapping;
@@ -38,6 +38,14 @@ var threeTypes = /*#__PURE__*/Object.freeze({
38
38
  });
39
39
 
40
40
  var _window$document, _window$navigator;
41
+ /**
42
+ * Safely accesses a deeply-nested value on an object to get around static bundler analysis.
43
+ */
44
+ const getDeep = (obj, ...keys) => keys.reduce((acc, key) => acc == null ? void 0 : acc[key], obj);
45
+ /**
46
+ * The current THREE.ColorManagement instance, if present.
47
+ */
48
+ const ColorManagement = 'ColorManagement' in THREE__namespace && getDeep(THREE__namespace, 'ColorManagement') || null;
41
49
  const isOrthographicCamera = def => def && def.isOrthographicCamera;
42
50
  const isRef = obj => obj && obj.hasOwnProperty('current');
43
51
 
@@ -83,6 +91,7 @@ ErrorBoundary.getDerivedStateFromError = () => ({
83
91
  error: true
84
92
  });
85
93
  const DEFAULT = '__default';
94
+ const DEFAULTS = new Map();
86
95
  const isDiffSet = def => def && !!def.memoized && !!def.changes;
87
96
  function calculateDpr(dpr) {
88
97
  const target = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
@@ -320,13 +329,14 @@ function applyProps$1(instance, data) {
320
329
  // For removed props, try to set default values, if possible
321
330
  if (value === DEFAULT + 'remove') {
322
331
  if (currentInstance.constructor) {
323
- var _currentInstance$__r;
324
332
  // create a blank slate of the instance and copy the particular parameter.
325
- // @ts-ignore
326
- const defaultClassCall = new currentInstance.constructor(...((_currentInstance$__r = currentInstance.__r3f.memoizedProps.args) != null ? _currentInstance$__r : []));
327
- value = defaultClassCall[key];
328
- // destroy the instance
329
- if (defaultClassCall.dispose) defaultClassCall.dispose();
333
+ let ctor = DEFAULTS.get(currentInstance.constructor);
334
+ if (!ctor) {
335
+ // @ts-ignore
336
+ ctor = new currentInstance.constructor();
337
+ DEFAULTS.set(currentInstance.constructor, ctor);
338
+ }
339
+ value = ctor[key];
330
340
  } else {
331
341
  // instance does not have constructor, just set it to 0
332
342
  value = 0;
@@ -345,7 +355,7 @@ function applyProps$1(instance, data) {
345
355
  if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
346
356
  }
347
357
  // Test again target.copy(class) next ...
348
- else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) {
358
+ else if (targetProp.copy && value && value.constructor && targetProp.constructor === value.constructor) {
349
359
  targetProp.copy(value);
350
360
  }
351
361
  // If nothing else fits, just set the single value, ignore undefined
@@ -361,15 +371,16 @@ function applyProps$1(instance, data) {
361
371
  // For versions of three which don't support THREE.ColorManagement,
362
372
  // Auto-convert sRGB colors
363
373
  // https://github.com/pmndrs/react-three-fiber/issues/344
364
- const supportsColorManagement = ('ColorManagement' in THREE__namespace);
365
- if (!supportsColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
374
+ if (!ColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
366
375
  }
367
376
  // Else, just overwrite the value
368
377
  } else {
369
378
  currentInstance[key] = value;
370
379
  // Auto-convert sRGB textures, for now ...
371
380
  // https://github.com/pmndrs/react-three-fiber/issues/344
372
- if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture) {
381
+ if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture &&
382
+ // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
383
+ currentInstance[key].format === THREE__namespace.RGBAFormat && currentInstance[key].type === THREE__namespace.UnsignedByteType) {
373
384
  currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
374
385
  }
375
386
  }
@@ -416,15 +427,6 @@ function updateCamera(camera, size) {
416
427
  }
417
428
  }
418
429
 
419
- /**
420
- * Safely sets a deeply-nested value on an object.
421
- */
422
- function setDeep(obj, value, keys) {
423
- const key = keys.pop();
424
- const target = keys.reduce((acc, key) => acc[key], obj);
425
- return target[key] = value;
426
- }
427
-
428
430
  function makeId(event) {
429
431
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
430
432
  }
@@ -1853,8 +1855,8 @@ function createRoot(canvas) {
1853
1855
 
1854
1856
  // Safely set color management if available.
1855
1857
  // Avoid accessing THREE.ColorManagement to play nice with older versions
1856
- if ('ColorManagement' in THREE__namespace) {
1857
- setDeep(THREE__namespace, legacy, ['ColorManagement', 'legacyMode']);
1858
+ if (ColorManagement) {
1859
+ if ('enabled' in ColorManagement) ColorManagement.enabled = !legacy;else if ('legacyMode' in ColorManagement) ColorManagement.legacyMode = legacy;
1858
1860
  }
1859
1861
  const outputEncoding = linear ? THREE__namespace.LinearEncoding : THREE__namespace.sRGBEncoding;
1860
1862
  const toneMapping = flat ? THREE__namespace.NoToneMapping : THREE__namespace.ACESFilmicToneMapping;
@@ -38,6 +38,14 @@ var threeTypes = /*#__PURE__*/Object.freeze({
38
38
  });
39
39
 
40
40
  var _window$document, _window$navigator;
41
+ /**
42
+ * Safely accesses a deeply-nested value on an object to get around static bundler analysis.
43
+ */
44
+ const getDeep = (obj, ...keys) => keys.reduce((acc, key) => acc == null ? void 0 : acc[key], obj);
45
+ /**
46
+ * The current THREE.ColorManagement instance, if present.
47
+ */
48
+ const ColorManagement = 'ColorManagement' in THREE__namespace && getDeep(THREE__namespace, 'ColorManagement') || null;
41
49
  const isOrthographicCamera = def => def && def.isOrthographicCamera;
42
50
  const isRef = obj => obj && obj.hasOwnProperty('current');
43
51
 
@@ -83,6 +91,7 @@ ErrorBoundary.getDerivedStateFromError = () => ({
83
91
  error: true
84
92
  });
85
93
  const DEFAULT = '__default';
94
+ const DEFAULTS = new Map();
86
95
  const isDiffSet = def => def && !!def.memoized && !!def.changes;
87
96
  function calculateDpr(dpr) {
88
97
  const target = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
@@ -320,13 +329,14 @@ function applyProps$1(instance, data) {
320
329
  // For removed props, try to set default values, if possible
321
330
  if (value === DEFAULT + 'remove') {
322
331
  if (currentInstance.constructor) {
323
- var _currentInstance$__r;
324
332
  // create a blank slate of the instance and copy the particular parameter.
325
- // @ts-ignore
326
- const defaultClassCall = new currentInstance.constructor(...((_currentInstance$__r = currentInstance.__r3f.memoizedProps.args) != null ? _currentInstance$__r : []));
327
- value = defaultClassCall[key];
328
- // destroy the instance
329
- if (defaultClassCall.dispose) defaultClassCall.dispose();
333
+ let ctor = DEFAULTS.get(currentInstance.constructor);
334
+ if (!ctor) {
335
+ // @ts-ignore
336
+ ctor = new currentInstance.constructor();
337
+ DEFAULTS.set(currentInstance.constructor, ctor);
338
+ }
339
+ value = ctor[key];
330
340
  } else {
331
341
  // instance does not have constructor, just set it to 0
332
342
  value = 0;
@@ -345,7 +355,7 @@ function applyProps$1(instance, data) {
345
355
  if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
346
356
  }
347
357
  // Test again target.copy(class) next ...
348
- else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) {
358
+ else if (targetProp.copy && value && value.constructor && targetProp.constructor === value.constructor) {
349
359
  targetProp.copy(value);
350
360
  }
351
361
  // If nothing else fits, just set the single value, ignore undefined
@@ -361,15 +371,16 @@ function applyProps$1(instance, data) {
361
371
  // For versions of three which don't support THREE.ColorManagement,
362
372
  // Auto-convert sRGB colors
363
373
  // https://github.com/pmndrs/react-three-fiber/issues/344
364
- const supportsColorManagement = ('ColorManagement' in THREE__namespace);
365
- if (!supportsColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
374
+ if (!ColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
366
375
  }
367
376
  // Else, just overwrite the value
368
377
  } else {
369
378
  currentInstance[key] = value;
370
379
  // Auto-convert sRGB textures, for now ...
371
380
  // https://github.com/pmndrs/react-three-fiber/issues/344
372
- if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture) {
381
+ if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture &&
382
+ // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
383
+ currentInstance[key].format === THREE__namespace.RGBAFormat && currentInstance[key].type === THREE__namespace.UnsignedByteType) {
373
384
  currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
374
385
  }
375
386
  }
@@ -416,15 +427,6 @@ function updateCamera(camera, size) {
416
427
  }
417
428
  }
418
429
 
419
- /**
420
- * Safely sets a deeply-nested value on an object.
421
- */
422
- function setDeep(obj, value, keys) {
423
- const key = keys.pop();
424
- const target = keys.reduce((acc, key) => acc[key], obj);
425
- return target[key] = value;
426
- }
427
-
428
430
  function makeId(event) {
429
431
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
430
432
  }
@@ -1853,8 +1855,8 @@ function createRoot(canvas) {
1853
1855
 
1854
1856
  // Safely set color management if available.
1855
1857
  // Avoid accessing THREE.ColorManagement to play nice with older versions
1856
- if ('ColorManagement' in THREE__namespace) {
1857
- setDeep(THREE__namespace, legacy, ['ColorManagement', 'legacyMode']);
1858
+ if (ColorManagement) {
1859
+ if ('enabled' in ColorManagement) ColorManagement.enabled = !legacy;else if ('legacyMode' in ColorManagement) ColorManagement.legacyMode = legacy;
1858
1860
  }
1859
1861
  const outputEncoding = linear ? THREE__namespace.LinearEncoding : THREE__namespace.sRGBEncoding;
1860
1862
  const toneMapping = flat ? THREE__namespace.NoToneMapping : THREE__namespace.ACESFilmicToneMapping;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-d9aa5cee.cjs.dev.js');
5
+ var index = require('./index-e172420e.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-2929b2e6.cjs.prod.js');
5
+ var index = require('./index-e8867c70.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 createRoot, i as isRef, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-73d51a81.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, a 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-73d51a81.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, i as isRef, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-606e613e.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, a 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-606e613e.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-d9aa5cee.cjs.dev.js');
5
+ var index = require('../../dist/index-e172420e.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-2929b2e6.cjs.prod.js');
5
+ var index = require('../../dist/index-e8867c70.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 createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-73d51a81.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, a 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-73d51a81.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-606e613e.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, a 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-606e613e.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.11.1",
3
+ "version": "8.11.3",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",