@react-three/postprocessing 2.2.2 → 2.2.5

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,12 +6,11 @@ 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
- var without = require('lodash-es/without');
15
14
 
16
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
16
 
@@ -39,7 +38,6 @@ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
39
38
  var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
40
39
  var _construct__default = /*#__PURE__*/_interopDefaultLegacy(_construct);
41
40
  var mergeRefs__default = /*#__PURE__*/_interopDefaultLegacy(mergeRefs);
42
- var without__default = /*#__PURE__*/_interopDefaultLegacy(without);
43
41
 
44
42
  var _excluded$7 = ["blendFunction", "opacity"];
45
43
 
@@ -60,12 +58,16 @@ var wrapEffect = function wrapEffect(effectImpl, defaultBlendMode) {
60
58
  opacity = _ref.opacity,
61
59
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$7);
62
60
 
61
+ var invalidate = fiber.useThree(function (state) {
62
+ return state.invalidate;
63
+ });
63
64
  var effect = React.useMemo(function () {
64
65
  return new effectImpl(props);
65
66
  }, [props]);
66
67
  React.useLayoutEffect(function () {
67
68
  effect.blendMode.blendFunction = blendFunction || defaultBlendMode;
68
69
  if (opacity !== undefined) effect.blendMode.opacity.value = opacity;
70
+ invalidate();
69
71
  }, [blendFunction, effect.blendMode, opacity]);
70
72
  return /*#__PURE__*/React__default["default"].createElement("primitive", {
71
73
  ref: ref,
@@ -228,6 +230,10 @@ var DepthOfField = /*#__PURE__*/React.forwardRef(function DepthOfField(_ref, ref
228
230
  depthTexture = _ref.depthTexture,
229
231
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$6);
230
232
 
233
+ var invalidate = fiber.useThree(function (state) {
234
+ return state.invalidate;
235
+ });
236
+
231
237
  var _useContext = React.useContext(EffectComposerContext),
232
238
  camera = _useContext.camera;
233
239
 
@@ -241,6 +247,7 @@ var DepthOfField = /*#__PURE__*/React.forwardRef(function DepthOfField(_ref, ref
241
247
  }
242
248
 
243
249
  if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
250
+ invalidate();
244
251
  }, [target, depthTexture, effect]);
245
252
  return /*#__PURE__*/React__default["default"].createElement("primitive", {
246
253
  ref: ref,
@@ -257,6 +264,9 @@ var Glitch = /*#__PURE__*/React.forwardRef(function Glitch(_ref, ref) {
257
264
  active = _ref$active === void 0 ? true : _ref$active,
258
265
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$5);
259
266
 
267
+ var invalidate = fiber.useThree(function (state) {
268
+ return state.invalidate;
269
+ });
260
270
  var delay = useVector2(props, 'delay');
261
271
  var duration = useVector2(props, 'duration');
262
272
  var strength = useVector2(props, 'strength');
@@ -269,6 +279,7 @@ var Glitch = /*#__PURE__*/React.forwardRef(function Glitch(_ref, ref) {
269
279
  }, [delay, duration, props, strength]);
270
280
  React.useLayoutEffect(function () {
271
281
  effect.mode = active ? props.mode || postprocessing.GlitchMode.SPORADIC : postprocessing.GlitchMode.DISABLED;
282
+ invalidate();
272
283
  }, [active, effect, props.mode]);
273
284
  return /*#__PURE__*/React__default["default"].createElement("primitive", {
274
285
  ref: ref,
@@ -296,11 +307,15 @@ var Grid = /*#__PURE__*/React.forwardRef(function Grid(_ref, ref) {
296
307
  var size = _ref.size,
297
308
  props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$4);
298
309
 
310
+ var invalidate = fiber.useThree(function (state) {
311
+ return state.invalidate;
312
+ });
299
313
  var effect = React.useMemo(function () {
300
314
  return new postprocessing.GridEffect(props);
301
315
  }, [props]);
302
316
  React.useLayoutEffect(function () {
303
317
  if (size) effect.setSize(size.width, size.height);
318
+ invalidate();
304
319
  }, [effect, size]);
305
320
  return /*#__PURE__*/React__default["default"].createElement("primitive", {
306
321
  ref: ref,
@@ -358,7 +373,9 @@ function Select(_ref2) {
358
373
  });
359
374
  return function () {
360
375
  api.select(function (state) {
361
- return without__default["default"].apply(void 0, [state].concat(current));
376
+ return state.filter(function (selected) {
377
+ return !current.includes(selected);
378
+ });
362
379
  });
363
380
  };
364
381
  }
@@ -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
@@ -6,7 +6,6 @@ import { useThree, useFrame, useLoader } from '@react-three/fiber';
6
6
  import { isWebGL2Available } from 'three-stdlib';
7
7
  import mergeRefs from 'react-merge-refs';
8
8
  import _extends from '@babel/runtime/helpers/esm/extends';
9
- import without from 'lodash-es/without';
10
9
 
11
10
  const isRef = ref => !!ref.current;
12
11
 
@@ -22,10 +21,12 @@ const wrapEffect = function (effectImpl, defaultBlendMode) {
22
21
  opacity,
23
22
  ...props
24
23
  } = _ref;
24
+ const invalidate = useThree(state => state.invalidate);
25
25
  const effect = useMemo(() => new effectImpl(props), [props]);
26
26
  useLayoutEffect(() => {
27
27
  effect.blendMode.blendFunction = blendFunction || defaultBlendMode;
28
28
  if (opacity !== undefined) effect.blendMode.opacity.value = opacity;
29
+ invalidate();
29
30
  }, [blendFunction, effect.blendMode, opacity]);
30
31
  return /*#__PURE__*/React.createElement("primitive", {
31
32
  ref: ref,
@@ -168,6 +169,7 @@ const DepthOfField = /*#__PURE__*/forwardRef(function DepthOfField(_ref, ref) {
168
169
  depthTexture,
169
170
  ...props
170
171
  } = _ref;
172
+ const invalidate = useThree(state => state.invalidate);
171
173
  const {
172
174
  camera
173
175
  } = useContext(EffectComposerContext);
@@ -179,6 +181,7 @@ const DepthOfField = /*#__PURE__*/forwardRef(function DepthOfField(_ref, ref) {
179
181
  }
180
182
 
181
183
  if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing);
184
+ invalidate();
182
185
  }, [target, depthTexture, effect]);
183
186
  return /*#__PURE__*/React.createElement("primitive", {
184
187
  ref: ref,
@@ -194,6 +197,7 @@ const Glitch = /*#__PURE__*/forwardRef(function Glitch(_ref, ref) {
194
197
  active = true,
195
198
  ...props
196
199
  } = _ref;
200
+ const invalidate = useThree(state => state.invalidate);
197
201
  const delay = useVector2(props, 'delay');
198
202
  const duration = useVector2(props, 'duration');
199
203
  const strength = useVector2(props, 'strength');
@@ -204,6 +208,7 @@ const Glitch = /*#__PURE__*/forwardRef(function Glitch(_ref, ref) {
204
208
  }), [delay, duration, props, strength]);
205
209
  useLayoutEffect(() => {
206
210
  effect.mode = active ? props.mode || GlitchMode.SPORADIC : GlitchMode.DISABLED;
211
+ invalidate();
207
212
  }, [active, effect, props.mode]);
208
213
  return /*#__PURE__*/React.createElement("primitive", {
209
214
  ref: ref,
@@ -229,9 +234,11 @@ const Grid = /*#__PURE__*/forwardRef(function Grid(_ref, ref) {
229
234
  size,
230
235
  ...props
231
236
  } = _ref;
237
+ const invalidate = useThree(state => state.invalidate);
232
238
  const effect = useMemo(() => new GridEffect(props), [props]);
233
239
  useLayoutEffect(() => {
234
240
  if (size) effect.setSize(size.width, size.height);
241
+ invalidate();
235
242
  }, [effect, size]);
236
243
  return /*#__PURE__*/React.createElement("primitive", {
237
244
  ref: ref,
@@ -280,7 +287,7 @@ function Select(_ref2) {
280
287
  if (changed) {
281
288
  api.select(state => [...state, ...current]);
282
289
  return () => {
283
- api.select(state => without(state, ...current));
290
+ api.select(state => state.filter(selected => !current.includes(selected)));
284
291
  };
285
292
  }
286
293
  }
@@ -307,6 +314,7 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
307
314
  xRay,
308
315
  ...props
309
316
  } = _ref;
317
+ const invalidate = useThree(state => state.invalidate);
310
318
  const {
311
319
  scene,
312
320
  camera
@@ -327,11 +335,16 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
327
335
  useEffect(() => {
328
336
  if (selection) {
329
337
  effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
330
- return () => void effect.selection.clear();
338
+ invalidate();
339
+ return () => {
340
+ effect.selection.clear();
341
+ invalidate();
342
+ };
331
343
  }
332
344
  }, [effect, selection]);
333
345
  useEffect(() => {
334
346
  effect.selectionLayer = selectionLayer;
347
+ invalidate();
335
348
  }, [effect, selectionLayer]);
336
349
  const api = useContext(selectionContext);
337
350
  const ref = useRef();
@@ -343,7 +356,11 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
343
356
 
344
357
  if ((_api$selected = api.selected) != null && _api$selected.length) {
345
358
  effect.selection.set(api.selected);
346
- return () => void effect.selection.clear();
359
+ invalidate();
360
+ return () => {
361
+ effect.selection.clear();
362
+ invalidate();
363
+ };
347
364
  }
348
365
  }
349
366
  }, [api]);
@@ -390,6 +407,7 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
390
407
  console.warn('SelectiveBloom requires lights to work.');
391
408
  }
392
409
 
410
+ const invalidate = useThree(state => state.invalidate);
393
411
  const {
394
412
  scene,
395
413
  camera
@@ -406,16 +424,25 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
406
424
  useEffect(() => {
407
425
  if (selection) {
408
426
  effect.selection.set(Array.isArray(selection) ? selection.map(resolveRef) : [resolveRef(selection)]);
409
- return () => void effect.selection.clear();
427
+ invalidate();
428
+ return () => {
429
+ effect.selection.clear();
430
+ invalidate();
431
+ };
410
432
  }
411
433
  }, [effect, selection]);
412
434
  useEffect(() => {
413
435
  effect.selection.layer = selectionLayer;
436
+ invalidate();
414
437
  }, [effect, selectionLayer]);
415
438
  useEffect(() => {
416
439
  if (lights && lights.length > 0) {
417
440
  lights.forEach(light => addLight(resolveRef(light), effect));
418
- return () => lights.forEach(light => removeLight(resolveRef(light), effect));
441
+ invalidate();
442
+ return () => {
443
+ lights.forEach(light => removeLight(resolveRef(light), effect));
444
+ invalidate();
445
+ };
419
446
  }
420
447
  }, [effect, lights, selectionLayer]);
421
448
  const api = useContext(selectionContext);
@@ -428,7 +455,11 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, for
428
455
 
429
456
  if ((_api$selected = api.selected) != null && _api$selected.length) {
430
457
  effect.selection.set(api.selected);
431
- return () => void effect.selection.clear();
458
+ invalidate();
459
+ return () => {
460
+ effect.selection.clear();
461
+ invalidate();
462
+ };
432
463
  }
433
464
  }
434
465
  }, [api]);
@@ -523,10 +554,12 @@ const LUT = /*#__PURE__*/forwardRef(function LUT(_ref, ref) {
523
554
  tetrahedralInterpolation,
524
555
  ...props
525
556
  } = _ref;
557
+ const invalidate = useThree(state => state.invalidate);
526
558
  const effect = useMemo(() => new LUTEffect(lut, props), [lut, props]);
527
559
  useLayoutEffect(() => {
528
560
  if (lut) effect.setLUT(lut);
529
561
  if (tetrahedralInterpolation) effect.setTetrahedralInterpolationEnabled(tetrahedralInterpolation);
562
+ invalidate();
530
563
  }, [effect, lut, tetrahedralInterpolation]);
531
564
  return /*#__PURE__*/React.createElement("primitive", {
532
565
  ref: ref,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/postprocessing",
3
- "version": "2.2.2",
3
+ "version": "2.2.5",
4
4
  "description": "postprocessing wrapper for React and @react-three/fiber",
5
5
  "keywords": [
6
6
  "postprocessing",
@@ -38,8 +38,7 @@
38
38
  "typegen": "tsc --emitDeclarationOnly || true"
39
39
  },
40
40
  "dependencies": {
41
- "lodash-es": "^4.17.21",
42
- "postprocessing": "^6.24.1",
41
+ "postprocessing": "6.24.1",
43
42
  "react-merge-refs": "^1.1.0",
44
43
  "three-stdlib": "^2.8.6"
45
44
  },