@react-three/postprocessing 2.2.3 → 2.2.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.
package/README.md CHANGED
@@ -60,7 +60,7 @@ function App() {
60
60
 
61
61
  #### EffectComposer
62
62
 
63
- The EffectComposer is must wrap all your effects. It will manage them for you.
63
+ The EffectComposer must wrap all your effects. It will manage them for you.
64
64
 
65
65
  ```jsx
66
66
  <EffectComposer
@@ -80,7 +80,7 @@ The EffectComposer is must wrap all your effects. It will manage them for you.
80
80
 
81
81
  #### Selection/Select
82
82
 
83
- Some effects, like Outline or SelectiveBloom can select specific objects. To manage this in a declarative scene with just references can be messy, so we have two components that help you.
83
+ Some effects, like Outline or SelectiveBloom can select specific objects. To manage this in a declarative scene with just references can be messy, especially when things have to be grouped. These two components take care of it:
84
84
 
85
85
  ```jsx
86
86
  <Selection
@@ -94,7 +94,7 @@ Some effects, like Outline or SelectiveBloom can select specific objects. To man
94
94
  >
95
95
  ```
96
96
 
97
- You wrap everything into a selection, and then select object or groups. Effects working with selections will acknowledge the selections.
97
+ You wrap everything into a selection, this one holds all the selections. Now you can individually select objects or groups. Effects that support selections (for instance `Outline`) will acknowledge it.
98
98
 
99
99
  ```jsx
100
100
  <Selection>
package/dist/index.cjs.js CHANGED
@@ -6,9 +6,9 @@ var postprocessing = require('postprocessing');
6
6
  var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
9
+ var fiber = require('@react-three/fiber');
9
10
  var _extends = require('@babel/runtime/helpers/extends');
10
11
  var _construct = require('@babel/runtime/helpers/construct');
11
- var fiber = require('@react-three/fiber');
12
12
  var threeStdlib = require('three-stdlib');
13
13
  var mergeRefs = require('react-merge-refs');
14
14
  var without = require('lodash-es/without');
@@ -60,12 +60,16 @@ var wrapEffect = function wrapEffect(effectImpl, defaultBlendMode) {
60
60
  opacity = _ref.opacity,
61
61
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$7);
62
62
 
63
+ var invalidate = fiber.useThree(function (state) {
64
+ return state.invalidate;
65
+ });
63
66
  var effect = React.useMemo(function () {
64
67
  return new effectImpl(props);
65
68
  }, [props]);
66
69
  React.useLayoutEffect(function () {
67
70
  effect.blendMode.blendFunction = blendFunction || defaultBlendMode;
68
71
  if (opacity !== undefined) effect.blendMode.opacity.value = opacity;
72
+ invalidate();
69
73
  }, [blendFunction, effect.blendMode, opacity]);
70
74
  return /*#__PURE__*/React__default["default"].createElement("primitive", {
71
75
  ref: ref,
@@ -228,6 +232,10 @@ var DepthOfField = /*#__PURE__*/React.forwardRef(function DepthOfField(_ref, ref
228
232
  depthTexture = _ref.depthTexture,
229
233
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$6);
230
234
 
235
+ var invalidate = fiber.useThree(function (state) {
236
+ return state.invalidate;
237
+ });
238
+
231
239
  var _useContext = React.useContext(EffectComposerContext),
232
240
  camera = _useContext.camera;
233
241
 
@@ -241,6 +249,7 @@ var DepthOfField = /*#__PURE__*/React.forwardRef(function DepthOfField(_ref, ref
241
249
  }
242
250
 
243
251
  if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
252
+ invalidate();
244
253
  }, [target, depthTexture, effect]);
245
254
  return /*#__PURE__*/React__default["default"].createElement("primitive", {
246
255
  ref: ref,
@@ -257,6 +266,9 @@ var Glitch = /*#__PURE__*/React.forwardRef(function Glitch(_ref, ref) {
257
266
  active = _ref$active === void 0 ? true : _ref$active,
258
267
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$5);
259
268
 
269
+ var invalidate = fiber.useThree(function (state) {
270
+ return state.invalidate;
271
+ });
260
272
  var delay = useVector2(props, 'delay');
261
273
  var duration = useVector2(props, 'duration');
262
274
  var strength = useVector2(props, 'strength');
@@ -269,6 +281,7 @@ var Glitch = /*#__PURE__*/React.forwardRef(function Glitch(_ref, ref) {
269
281
  }, [delay, duration, props, strength]);
270
282
  React.useLayoutEffect(function () {
271
283
  effect.mode = active ? props.mode || postprocessing.GlitchMode.SPORADIC : postprocessing.GlitchMode.DISABLED;
284
+ invalidate();
272
285
  }, [active, effect, props.mode]);
273
286
  return /*#__PURE__*/React__default["default"].createElement("primitive", {
274
287
  ref: ref,
@@ -296,11 +309,15 @@ var Grid = /*#__PURE__*/React.forwardRef(function Grid(_ref, ref) {
296
309
  var size = _ref.size,
297
310
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$4);
298
311
 
312
+ var invalidate = fiber.useThree(function (state) {
313
+ return state.invalidate;
314
+ });
299
315
  var effect = React.useMemo(function () {
300
316
  return new postprocessing.GridEffect(props);
301
317
  }, [props]);
302
318
  React.useLayoutEffect(function () {
303
319
  if (size) effect.setSize(size.width, size.height);
320
+ invalidate();
304
321
  }, [effect, size]);
305
322
  return /*#__PURE__*/React__default["default"].createElement("primitive", {
306
323
  ref: ref,
@@ -388,6 +405,10 @@ var Outline = /*#__PURE__*/React.forwardRef(function Outline(_ref, forwardRef) {
388
405
  xRay = _ref.xRay;
389
406
  _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$2);
390
407
 
408
+ var invalidate = fiber.useThree(function (state) {
409
+ return state.invalidate;
410
+ });
411
+
391
412
  var _useContext = React.useContext(EffectComposerContext),
392
413
  scene = _useContext.scene,
393
414
  camera = _useContext.camera;
@@ -410,13 +431,16 @@ var Outline = /*#__PURE__*/React.forwardRef(function Outline(_ref, forwardRef) {
410
431
  React.useEffect(function () {
411
432
  if (selection) {
412
433
  effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
434
+ invalidate();
413
435
  return function () {
414
- return void effect.selection.clear();
436
+ effect.selection.clear();
437
+ invalidate();
415
438
  };
416
439
  }
417
440
  }, [effect, selection]);
418
441
  React.useEffect(function () {
419
442
  effect.selectionLayer = selectionLayer;
443
+ invalidate();
420
444
  }, [effect, selectionLayer]);
421
445
  var api = React.useContext(selectionContext);
422
446
  var ref = React.useRef();
@@ -429,8 +453,11 @@ var Outline = /*#__PURE__*/React.forwardRef(function Outline(_ref, forwardRef) {
429
453
  if ((_api$selected = api.selected) != null && _api$selected.length) {
430
454
  _effect.selection.set(api.selected);
431
455
 
456
+ invalidate();
432
457
  return function () {
433
- return void _effect.selection.clear();
458
+ _effect.selection.clear();
459
+
460
+ invalidate();
434
461
  };
435
462
  }
436
463
  }
@@ -484,6 +511,10 @@ var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref,
484
511
  console.warn('SelectiveBloom requires lights to work.');
485
512
  }
486
513
 
514
+ var invalidate = fiber.useThree(function (state) {
515
+ return state.invalidate;
516
+ });
517
+
487
518
  var _useContext = React.useContext(EffectComposerContext),
488
519
  scene = _useContext.scene,
489
520
  camera = _useContext.camera;
@@ -502,23 +533,28 @@ var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref,
502
533
  React.useEffect(function () {
503
534
  if (selection) {
504
535
  effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
536
+ invalidate();
505
537
  return function () {
506
- return void effect.selection.clear();
538
+ effect.selection.clear();
539
+ invalidate();
507
540
  };
508
541
  }
509
542
  }, [effect, selection]);
510
543
  React.useEffect(function () {
511
544
  effect.selection.layer = selectionLayer;
545
+ invalidate();
512
546
  }, [effect, selectionLayer]);
513
547
  React.useEffect(function () {
514
548
  if (lights && lights.length > 0) {
515
549
  lights.forEach(function (light) {
516
550
  return addLight(resolveRef(light), effect);
517
551
  });
552
+ invalidate();
518
553
  return function () {
519
- return lights.forEach(function (light) {
554
+ lights.forEach(function (light) {
520
555
  return removeLight(resolveRef(light), effect);
521
556
  });
557
+ invalidate();
522
558
  };
523
559
  }
524
560
  }, [effect, lights, selectionLayer]);
@@ -533,8 +569,11 @@ var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref,
533
569
  if ((_api$selected = api.selected) != null && _api$selected.length) {
534
570
  _effect.selection.set(api.selected);
535
571
 
572
+ invalidate();
536
573
  return function () {
537
- return void _effect.selection.clear();
574
+ _effect.selection.clear();
575
+
576
+ invalidate();
538
577
  };
539
578
  }
540
579
  }
@@ -633,12 +672,16 @@ var LUT = /*#__PURE__*/React.forwardRef(function LUT(_ref, ref) {
633
672
  tetrahedralInterpolation = _ref.tetrahedralInterpolation,
634
673
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded);
635
674
 
675
+ var invalidate = fiber.useThree(function (state) {
676
+ return state.invalidate;
677
+ });
636
678
  var effect = React.useMemo(function () {
637
679
  return new postprocessing.LUTEffect(lut, props);
638
680
  }, [lut, props]);
639
681
  React.useLayoutEffect(function () {
640
682
  if (lut) effect.setLUT(lut);
641
683
  if (tetrahedralInterpolation) effect.setTetrahedralInterpolationEnabled(tetrahedralInterpolation);
684
+ invalidate();
642
685
  }, [effect, lut, tetrahedralInterpolation]);
643
686
  return /*#__PURE__*/React__default["default"].createElement("primitive", {
644
687
  ref: ref,
package/dist/index.js CHANGED
@@ -22,10 +22,12 @@ const wrapEffect = function (effectImpl, defaultBlendMode) {
22
22
  opacity,
23
23
  ...props
24
24
  } = _ref;
25
+ const invalidate = useThree(state => state.invalidate);
25
26
  const effect = useMemo(() => new effectImpl(props), [props]);
26
27
  useLayoutEffect(() => {
27
28
  effect.blendMode.blendFunction = blendFunction || defaultBlendMode;
28
29
  if (opacity !== undefined) effect.blendMode.opacity.value = opacity;
30
+ invalidate();
29
31
  }, [blendFunction, effect.blendMode, opacity]);
30
32
  return /*#__PURE__*/React.createElement("primitive", {
31
33
  ref: ref,
@@ -168,6 +170,7 @@ const DepthOfField = /*#__PURE__*/forwardRef(function DepthOfField(_ref, ref) {
168
170
  depthTexture,
169
171
  ...props
170
172
  } = _ref;
173
+ const invalidate = useThree(state => state.invalidate);
171
174
  const {
172
175
  camera
173
176
  } = useContext(EffectComposerContext);
@@ -179,6 +182,7 @@ const DepthOfField = /*#__PURE__*/forwardRef(function DepthOfField(_ref, ref) {
179
182
  }
180
183
 
181
184
  if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
185
+ invalidate();
182
186
  }, [target, depthTexture, effect]);
183
187
  return /*#__PURE__*/React.createElement("primitive", {
184
188
  ref: ref,
@@ -194,6 +198,7 @@ const Glitch = /*#__PURE__*/forwardRef(function Glitch(_ref, ref) {
194
198
  active = true,
195
199
  ...props
196
200
  } = _ref;
201
+ const invalidate = useThree(state => state.invalidate);
197
202
  const delay = useVector2(props, 'delay');
198
203
  const duration = useVector2(props, 'duration');
199
204
  const strength = useVector2(props, 'strength');
@@ -204,6 +209,7 @@ const Glitch = /*#__PURE__*/forwardRef(function Glitch(_ref, ref) {
204
209
  }), [delay, duration, props, strength]);
205
210
  useLayoutEffect(() => {
206
211
  effect.mode = active ? props.mode || GlitchMode.SPORADIC : GlitchMode.DISABLED;
212
+ invalidate();
207
213
  }, [active, effect, props.mode]);
208
214
  return /*#__PURE__*/React.createElement("primitive", {
209
215
  ref: ref,
@@ -229,9 +235,11 @@ const Grid = /*#__PURE__*/forwardRef(function Grid(_ref, ref) {
229
235
  size,
230
236
  ...props
231
237
  } = _ref;
238
+ const invalidate = useThree(state => state.invalidate);
232
239
  const effect = useMemo(() => new GridEffect(props), [props]);
233
240
  useLayoutEffect(() => {
234
241
  if (size) effect.setSize(size.width, size.height);
242
+ invalidate();
235
243
  }, [effect, size]);
236
244
  return /*#__PURE__*/React.createElement("primitive", {
237
245
  ref: ref,
@@ -307,6 +315,7 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
307
315
  xRay,
308
316
  ...props
309
317
  } = _ref;
318
+ const invalidate = useThree(state => state.invalidate);
310
319
  const {
311
320
  scene,
312
321
  camera
@@ -327,11 +336,16 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
327
336
  useEffect(() => {
328
337
  if (selection) {
329
338
  effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
330
- return () => void effect.selection.clear();
339
+ invalidate();
340
+ return () => {
341
+ effect.selection.clear();
342
+ invalidate();
343
+ };
331
344
  }
332
345
  }, [effect, selection]);
333
346
  useEffect(() => {
334
347
  effect.selectionLayer = selectionLayer;
348
+ invalidate();
335
349
  }, [effect, selectionLayer]);
336
350
  const api = useContext(selectionContext);
337
351
  const ref = useRef();
@@ -343,7 +357,11 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
343
357
 
344
358
  if ((_api$selected = api.selected) != null && _api$selected.length) {
345
359
  effect.selection.set(api.selected);
346
- return () => void effect.selection.clear();
360
+ invalidate();
361
+ return () => {
362
+ effect.selection.clear();
363
+ invalidate();
364
+ };
347
365
  }
348
366
  }
349
367
  }, [api]);
@@ -390,6 +408,7 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
390
408
  console.warn('SelectiveBloom requires lights to work.');
391
409
  }
392
410
 
411
+ const invalidate = useThree(state => state.invalidate);
393
412
  const {
394
413
  scene,
395
414
  camera
@@ -406,16 +425,25 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
406
425
  useEffect(() => {
407
426
  if (selection) {
408
427
  effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
409
- return () => void effect.selection.clear();
428
+ invalidate();
429
+ return () => {
430
+ effect.selection.clear();
431
+ invalidate();
432
+ };
410
433
  }
411
434
  }, [effect, selection]);
412
435
  useEffect(() => {
413
436
  effect.selection.layer = selectionLayer;
437
+ invalidate();
414
438
  }, [effect, selectionLayer]);
415
439
  useEffect(() => {
416
440
  if (lights && lights.length > 0) {
417
441
  lights.forEach(light => addLight(resolveRef(light), effect));
418
- return () => lights.forEach(light => removeLight(resolveRef(light), effect));
442
+ invalidate();
443
+ return () => {
444
+ lights.forEach(light => removeLight(resolveRef(light), effect));
445
+ invalidate();
446
+ };
419
447
  }
420
448
  }, [effect, lights, selectionLayer]);
421
449
  const api = useContext(selectionContext);
@@ -428,7 +456,11 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
428
456
 
429
457
  if ((_api$selected = api.selected) != null && _api$selected.length) {
430
458
  effect.selection.set(api.selected);
431
- return () => void effect.selection.clear();
459
+ invalidate();
460
+ return () => {
461
+ effect.selection.clear();
462
+ invalidate();
463
+ };
432
464
  }
433
465
  }
434
466
  }, [api]);
@@ -523,10 +555,12 @@ const LUT = /*#__PURE__*/forwardRef(function LUT(_ref, ref) {
523
555
  tetrahedralInterpolation,
524
556
  ...props
525
557
  } = _ref;
558
+ const invalidate = useThree(state => state.invalidate);
526
559
  const effect = useMemo(() => new LUTEffect(lut, props), [lut, props]);
527
560
  useLayoutEffect(() => {
528
561
  if (lut) effect.setLUT(lut);
529
562
  if (tetrahedralInterpolation) effect.setTetrahedralInterpolationEnabled(tetrahedralInterpolation);
563
+ invalidate();
530
564
  }, [effect, lut, tetrahedralInterpolation]);
531
565
  return /*#__PURE__*/React.createElement("primitive", {
532
566
  ref: ref,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/postprocessing",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "postprocessing wrapper for React and @react-three/fiber",
5
5
  "keywords": [
6
6
  "postprocessing",