@react-three/postprocessing 2.1.6 → 2.2.0

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
@@ -30,7 +30,7 @@ Postprocessing also supports srgb-encoding out of the box, as well as WebGL2 MSA
30
30
 
31
31
  #### What does it look like?
32
32
 
33
- Well, you can do pretty much anything, but here's an example combining a couple of effects ([live demo](https://codesandbox.io/s/react-postprocessing-dof-blob-pqrpl?)).
33
+ Here's an example combining a couple of effects ([live demo](https://codesandbox.io/s/react-postprocessing-dof-blob-pqrpl?)).
34
34
 
35
35
  <a href="https://codesandbox.io/s/react-postprocessing-dof-blob-pqrpl?" target="_blank" rel="noopener">
36
36
  <img src="bubbles.jpg" alt="Bubbles Demo" />
@@ -56,7 +56,70 @@ function App() {
56
56
  }
57
57
  ```
58
58
 
59
- #### Documentation
59
+ ## Documentation
60
+
61
+ #### EffectComposer
62
+
63
+ The EffectComposer is must wrap all your effects. It will manage them for you.
64
+
65
+ ```jsx
66
+ <EffectComposer
67
+ enabled?: boolean
68
+ children: JSX.Element | JSX.Element[]
69
+ depthBuffer?: boolean
70
+ disableNormalPass?: boolean
71
+ stencilBuffer?: boolean
72
+ autoClear?: boolean
73
+ multisampling?: number
74
+ frameBufferType?: TextureDataType
75
+ renderPriority?: number
76
+ camera?: THREE.Camera
77
+ scene?: THREE.Scene
78
+ >
79
+ ```
80
+
81
+ #### Selection/Select
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.
84
+
85
+ ```jsx
86
+ <Selection
87
+ children: JSX.Element | JSX.Element[]
88
+ enabled?: boolean
89
+ >
90
+
91
+ <Select
92
+ children: JSX.Element | JSX.Element[]
93
+ enabled?: boolean
94
+ >
95
+ ```
96
+
97
+ You wrap everything into a selection, and then select object or groups. Effects working with selections will acknowledge the selections.
98
+
99
+ ```jsx
100
+ <Selection>
101
+ <EffectComposer>
102
+ <Outline xRay blur edgeStrength={100} width={1000} />
103
+ </EffectComposer>
104
+ <Select enabled>
105
+ <mesh />
106
+ </Select>
107
+ </Selection>
108
+ ```
109
+
110
+ Selection can be nested and group multiple object, higher up selection take precence over lower ones. The following for instance will select everything. Remove the outmost `enabled` and only the two mesh group is selected. You can flip the selections or bind them to interactions and state.
111
+
112
+ ```jsx
113
+ <Select enabled>
114
+ <Select enabled>
115
+ <mesh />
116
+ <mesh />
117
+ </Select>
118
+ <Select>
119
+ <mesh />
120
+ </Select>
121
+ </Select>
122
+ ```
60
123
 
61
124
  - [react-postprocessing exports](https://github.com/pmndrs/react-postprocessing/blob/master/api.md)
62
125
  - [postprocessing docs](https://vanruesc.github.io/postprocessing/public/docs/)
@@ -21,5 +21,4 @@ export declare type EffectComposerProps = {
21
21
  camera?: THREE.Camera;
22
22
  scene?: THREE.Scene;
23
23
  };
24
- declare const EffectComposer: React.MemoExoticComponent<React.ForwardRefExoticComponent<EffectComposerProps & React.RefAttributes<unknown>>>;
25
- export default EffectComposer;
24
+ export declare const EffectComposer: React.MemoExoticComponent<React.ForwardRefExoticComponent<EffectComposerProps & React.RefAttributes<unknown>>>;
@@ -0,0 +1,16 @@
1
+ import * as THREE from 'three';
2
+ import React from 'react';
3
+ export declare type Api = {
4
+ selected: THREE.Object3D[];
5
+ select: React.Dispatch<React.SetStateAction<THREE.Object3D[]>>;
6
+ enabled: boolean;
7
+ };
8
+ export declare type SelectApi = JSX.IntrinsicElements['group'] & {
9
+ enabled?: boolean;
10
+ };
11
+ export declare const selectionContext: React.Context<Api>;
12
+ export declare function Selection({ children, enabled }: {
13
+ enabled?: boolean;
14
+ children: React.ReactNode;
15
+ }): JSX.Element;
16
+ export declare function Select({ enabled, children, ...props }: SelectApi): JSX.Element;
@@ -1,13 +1,14 @@
1
1
  import { OutlineEffect } from 'postprocessing';
2
2
  import React, { MutableRefObject } from 'react';
3
3
  import { Object3D } from 'three';
4
+ import { BlendFunction } from 'postprocessing';
4
5
  declare type ObjectRef = MutableRefObject<Object3D>;
5
6
  export declare type OutlineProps = ConstructorParameters<typeof OutlineEffect>[2] & Partial<{
6
7
  selection: Object3D | Object3D[] | ObjectRef | ObjectRef[];
7
8
  selectionLayer: number;
8
9
  }>;
9
10
  export declare const Outline: React.ForwardRefExoticComponent<Partial<{
10
- blendFunction: import("postprocessing").BlendFunction;
11
+ blendFunction: BlendFunction;
11
12
  patternTexture: number;
12
13
  edgeStrength: number;
13
14
  pulseSpeed: number;
package/dist/index.cjs.js CHANGED
@@ -10,6 +10,8 @@ var _extends = require('@babel/runtime/helpers/extends');
10
10
  var _construct = require('@babel/runtime/helpers/construct');
11
11
  var fiber = require('@react-three/fiber');
12
12
  var threeStdlib = require('three-stdlib');
13
+ var mergeRefs = require('react-merge-refs');
14
+ var without = require('lodash-es/without');
13
15
 
14
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
17
 
@@ -36,8 +38,10 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
36
38
  var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
37
39
  var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
38
40
  var _construct__default = /*#__PURE__*/_interopDefaultLegacy(_construct);
41
+ var mergeRefs__default = /*#__PURE__*/_interopDefaultLegacy(mergeRefs);
42
+ var without__default = /*#__PURE__*/_interopDefaultLegacy(without);
39
43
 
40
- var _excluded$6 = ["blendFunction", "opacity"];
44
+ var _excluded$7 = ["blendFunction", "opacity"];
41
45
 
42
46
  var isRef = function isRef(ref) {
43
47
  return !!ref.current;
@@ -54,7 +58,7 @@ var wrapEffect = function wrapEffect(effectImpl, defaultBlendMode) {
54
58
  return /*#__PURE__*/React.forwardRef(function Wrap(_ref, ref) {
55
59
  var blendFunction = _ref.blendFunction,
56
60
  opacity = _ref.opacity,
57
- props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$6);
61
+ props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$7);
58
62
 
59
63
  var effect = React.useMemo(function () {
60
64
  return new effectImpl(props);
@@ -217,13 +221,12 @@ var EffectComposer = /*#__PURE__*/React__default["default"].memo( /*#__PURE__*/R
217
221
  ref: group
218
222
  }, children));
219
223
  }));
220
- var EffectComposer$1 = EffectComposer;
221
224
 
222
- var _excluded$5 = ["target", "depthTexture"];
225
+ var _excluded$6 = ["target", "depthTexture"];
223
226
  var DepthOfField = /*#__PURE__*/React.forwardRef(function DepthOfField(_ref, ref) {
224
227
  var target = _ref.target,
225
228
  depthTexture = _ref.depthTexture,
226
- props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$5);
229
+ props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$6);
227
230
 
228
231
  var _useContext = React.useContext(EffectComposerContext),
229
232
  camera = _useContext.camera;
@@ -248,11 +251,11 @@ var DepthOfField = /*#__PURE__*/React.forwardRef(function DepthOfField(_ref, ref
248
251
 
249
252
  var DotScreen = wrapEffect(postprocessing.DotScreenEffect);
250
253
 
251
- var _excluded$4 = ["active"];
254
+ var _excluded$5 = ["active"];
252
255
  var Glitch = /*#__PURE__*/React.forwardRef(function Glitch(_ref, ref) {
253
256
  var _ref$active = _ref.active,
254
257
  active = _ref$active === void 0 ? true : _ref$active,
255
- props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$4);
258
+ props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$5);
256
259
 
257
260
  var delay = useVector2(props, 'delay');
258
261
  var duration = useVector2(props, 'duration');
@@ -288,10 +291,10 @@ var GodRays = /*#__PURE__*/React.forwardRef(function GodRays(props, ref) {
288
291
  });
289
292
  });
290
293
 
291
- var _excluded$3 = ["size"];
294
+ var _excluded$4 = ["size"];
292
295
  var Grid = /*#__PURE__*/React.forwardRef(function Grid(_ref, ref) {
293
296
  var size = _ref.size,
294
- props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$3);
297
+ props = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$4);
295
298
 
296
299
  var effect = React.useMemo(function () {
297
300
  return new postprocessing.GridEffect(props);
@@ -310,18 +313,77 @@ var HueSaturation = wrapEffect(postprocessing.HueSaturationEffect);
310
313
 
311
314
  var Noise = wrapEffect(postprocessing.NoiseEffect, postprocessing.BlendFunction.COLOR_DODGE);
312
315
 
316
+ var _excluded$3 = ["enabled", "children"];
317
+ var selectionContext = /*#__PURE__*/React.createContext(null);
318
+ function Selection(_ref) {
319
+ var children = _ref.children,
320
+ _ref$enabled = _ref.enabled,
321
+ enabled = _ref$enabled === void 0 ? true : _ref$enabled;
322
+
323
+ var _useState = React.useState([]),
324
+ selected = _useState[0],
325
+ select = _useState[1];
326
+
327
+ var value = React.useMemo(function () {
328
+ return {
329
+ selected: selected,
330
+ select: select,
331
+ enabled: enabled
332
+ };
333
+ }, [selected, select, enabled]);
334
+ return /*#__PURE__*/React__default["default"].createElement(selectionContext.Provider, {
335
+ value: value
336
+ }, children);
337
+ }
338
+ function Select(_ref2) {
339
+ var _ref2$enabled = _ref2.enabled,
340
+ enabled = _ref2$enabled === void 0 ? false : _ref2$enabled,
341
+ children = _ref2.children,
342
+ props = _objectWithoutPropertiesLoose__default["default"](_ref2, _excluded$3);
343
+
344
+ var group = React.useRef(null);
345
+ var api = React.useContext(selectionContext);
346
+ React.useEffect(function () {
347
+ if (api && enabled) {
348
+ var changed = false;
349
+ var current = [];
350
+ group.current.traverse(function (o) {
351
+ o.type === 'Mesh' && current.push(o);
352
+ if (api.selected.indexOf(o) === -1) changed = true;
353
+ });
354
+
355
+ if (changed) {
356
+ api.select(function (state) {
357
+ return [].concat(state, current);
358
+ });
359
+ return function () {
360
+ api.select(function (state) {
361
+ return without__default["default"].apply(void 0, [state].concat(current));
362
+ });
363
+ };
364
+ }
365
+ }
366
+ }, [enabled, children]);
367
+ return /*#__PURE__*/React__default["default"].createElement("group", _extends__default["default"]({
368
+ ref: group
369
+ }, props), children);
370
+ }
371
+
313
372
  var _excluded$2 = ["selection", "selectionLayer", "blendFunction", "patternTexture", "edgeStrength", "pulseSpeed", "visibleEdgeColor", "hiddenEdgeColor", "width", "height", "kernelSize", "blur", "xRay"];
314
- var Outline = /*#__PURE__*/React.forwardRef(function Outline(_ref, ref) {
373
+ var Outline = /*#__PURE__*/React.forwardRef(function Outline(_ref, forwardRef) {
315
374
  var _ref$selection = _ref.selection,
316
375
  selection = _ref$selection === void 0 ? [] : _ref$selection,
317
376
  _ref$selectionLayer = _ref.selectionLayer,
318
377
  selectionLayer = _ref$selectionLayer === void 0 ? 10 : _ref$selectionLayer,
319
- blendFunction = _ref.blendFunction,
378
+ _ref$blendFunction = _ref.blendFunction,
379
+ blendFunction = _ref$blendFunction === void 0 ? postprocessing.BlendFunction.ADD : _ref$blendFunction,
320
380
  patternTexture = _ref.patternTexture,
321
381
  edgeStrength = _ref.edgeStrength,
322
382
  pulseSpeed = _ref.pulseSpeed,
323
- visibleEdgeColor = _ref.visibleEdgeColor,
324
- hiddenEdgeColor = _ref.hiddenEdgeColor,
383
+ _ref$visibleEdgeColor = _ref.visibleEdgeColor,
384
+ visibleEdgeColor = _ref$visibleEdgeColor === void 0 ? 0xffffff : _ref$visibleEdgeColor,
385
+ _ref$hiddenEdgeColor = _ref.hiddenEdgeColor,
386
+ hiddenEdgeColor = _ref$hiddenEdgeColor === void 0 ? 0xffffff : _ref$hiddenEdgeColor,
325
387
  width = _ref.width,
326
388
  height = _ref.height,
327
389
  kernelSize = _ref.kernelSize,
@@ -359,10 +421,26 @@ var Outline = /*#__PURE__*/React.forwardRef(function Outline(_ref, ref) {
359
421
  React.useEffect(function () {
360
422
  effect.selectionLayer = selectionLayer;
361
423
  }, [effect, selectionLayer]);
424
+ var api = React.useContext(selectionContext);
425
+ var ref = React.useRef();
426
+ React.useEffect(function () {
427
+ if (api && api.enabled) {
428
+ var _api$selected;
429
+
430
+ var _effect = ref.current;
431
+
432
+ if ((_api$selected = api.selected) != null && _api$selected.length) {
433
+ _effect.selection.set(api.selected);
434
+
435
+ return function () {
436
+ return void _effect.selection.clear();
437
+ };
438
+ }
439
+ }
440
+ }, [api]);
362
441
  return /*#__PURE__*/React__default["default"].createElement("primitive", {
363
- ref: ref,
364
- object: effect,
365
- dispose: null
442
+ ref: mergeRefs__default["default"]([ref, forwardRef]),
443
+ object: effect
366
444
  });
367
445
  });
368
446
 
@@ -391,7 +469,7 @@ var removeLight = function removeLight(light, effect) {
391
469
  return light.layers.disable(effect.selection.layer);
392
470
  };
393
471
 
394
- var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref, ref) {
472
+ var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref, forwardRef) {
395
473
  var _ref$selection = _ref.selection,
396
474
  selection = _ref$selection === void 0 ? [] : _ref$selection,
397
475
  _ref$selectionLayer = _ref.selectionLayer,
@@ -447,8 +525,25 @@ var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref,
447
525
  };
448
526
  }
449
527
  }, [effect, lights, selectionLayer]);
528
+ var api = React.useContext(selectionContext);
529
+ var ref = React.useRef();
530
+ React.useEffect(function () {
531
+ if (api && api.enabled) {
532
+ var _api$selected;
533
+
534
+ var _effect = ref.current;
535
+
536
+ if ((_api$selected = api.selected) != null && _api$selected.length) {
537
+ _effect.selection.set(api.selected);
538
+
539
+ return function () {
540
+ return void _effect.selection.clear();
541
+ };
542
+ }
543
+ }
544
+ }, [api]);
450
545
  return /*#__PURE__*/React__default["default"].createElement("primitive", {
451
- ref: ref,
546
+ ref: mergeRefs__default["default"]([ref, forwardRef]),
452
547
  object: effect,
453
548
  dispose: null
454
549
  });
@@ -563,7 +658,7 @@ exports.ColorDepth = ColorDepth;
563
658
  exports.Depth = Depth;
564
659
  exports.DepthOfField = DepthOfField;
565
660
  exports.DotScreen = DotScreen;
566
- exports.EffectComposer = EffectComposer$1;
661
+ exports.EffectComposer = EffectComposer;
567
662
  exports.EffectComposerContext = EffectComposerContext;
568
663
  exports.Glitch = Glitch;
569
664
  exports.GodRays = GodRays;
@@ -576,9 +671,12 @@ exports.Pixelation = Pixelation;
576
671
  exports.SMAA = SMAA;
577
672
  exports.SSAO = SSAO;
578
673
  exports.Scanline = Scanline;
674
+ exports.Select = Select;
675
+ exports.Selection = Selection;
579
676
  exports.SelectiveBloom = SelectiveBloom;
580
677
  exports.Sepia = Sepia;
581
678
  exports.ShockWave = ShockWave;
582
679
  exports.Texture = Texture;
583
680
  exports.ToneMapping = ToneMapping;
584
681
  exports.Vignette = Vignette;
682
+ exports.selectionContext = selectionContext;
package/dist/index.d.ts CHANGED
@@ -23,4 +23,5 @@ export * from './effects/ToneMapping';
23
23
  export * from './effects/Vignette';
24
24
  export * from './effects/ShockWave';
25
25
  export * from './effects/LUT';
26
- export { default as EffectComposer, EffectComposerContext } from './EffectComposer';
26
+ export * from './Selection';
27
+ export * from './EffectComposer';
package/dist/index.js CHANGED
@@ -1,9 +1,12 @@
1
- import { BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$2, RenderPass, NormalPass, EffectPass, DepthOfFieldEffect, DotScreenEffect, GlitchEffect, GlitchMode, GodRaysEffect, GridEffect, HueSaturationEffect, NoiseEffect, OutlineEffect, PixelationEffect, ScanlineEffect, SelectiveBloomEffect, SepiaEffect, SSAOEffect, SMAAPreset, EdgeDetectionMode, SMAAImageLoader, SMAAEffect, TextureEffect, ToneMappingEffect, VignetteEffect, ShockWaveEffect, LUTEffect } from 'postprocessing';
2
- import React, { forwardRef, useMemo, useLayoutEffect, createContext, useRef, useImperativeHandle, useContext, useEffect } from 'react';
1
+ import { BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$1, RenderPass, NormalPass, EffectPass, DepthOfFieldEffect, DotScreenEffect, GlitchEffect, GlitchMode, GodRaysEffect, GridEffect, HueSaturationEffect, NoiseEffect, OutlineEffect, PixelationEffect, ScanlineEffect, SelectiveBloomEffect, SepiaEffect, SSAOEffect, SMAAPreset, EdgeDetectionMode, SMAAImageLoader, SMAAEffect, TextureEffect, ToneMappingEffect, VignetteEffect, ShockWaveEffect, LUTEffect } from 'postprocessing';
2
+ import React, { forwardRef, useMemo, useLayoutEffect, createContext, useRef, useImperativeHandle, useContext, useState, useEffect } from 'react';
3
3
  import * as THREE from 'three';
4
4
  import { Vector2, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping } from 'three';
5
5
  import { useThree, useFrame, useLoader } from '@react-three/fiber';
6
6
  import { isWebGL2Available } from 'three-stdlib';
7
+ import mergeRefs from 'react-merge-refs';
8
+ import _extends from '@babel/runtime/helpers/esm/extends';
9
+ import without from 'lodash-es/without';
7
10
 
8
11
  const isRef = ref => !!ref.current;
9
12
 
@@ -102,7 +105,7 @@ const EffectComposer = /*#__PURE__*/React.memo( /*#__PURE__*/forwardRef((_ref, r
102
105
  camera = camera || defaultCamera;
103
106
  const [composer, normalPass] = useMemo(() => {
104
107
  // Initialize composer
105
- const effectComposer = new EffectComposer$2(gl, {
108
+ const effectComposer = new EffectComposer$1(gl, {
106
109
  depthBuffer,
107
110
  stencilBuffer,
108
111
  multisampling: multisampling > 0 && isWebGL2Available() ? multisampling : 0,
@@ -158,7 +161,6 @@ const EffectComposer = /*#__PURE__*/React.memo( /*#__PURE__*/forwardRef((_ref, r
158
161
  ref: group
159
162
  }, children));
160
163
  }));
161
- var EffectComposer$1 = EffectComposer;
162
164
 
163
165
  const DepthOfField = /*#__PURE__*/forwardRef(function DepthOfField(_ref, ref) {
164
166
  let {
@@ -242,16 +244,62 @@ const HueSaturation = wrapEffect(HueSaturationEffect);
242
244
 
243
245
  const Noise = wrapEffect(NoiseEffect, BlendFunction.COLOR_DODGE);
244
246
 
245
- const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, ref) {
247
+ const selectionContext = /*#__PURE__*/createContext(null);
248
+ function Selection(_ref) {
249
+ let {
250
+ children,
251
+ enabled = true
252
+ } = _ref;
253
+ const [selected, select] = useState([]);
254
+ const value = useMemo(() => ({
255
+ selected,
256
+ select,
257
+ enabled
258
+ }), [selected, select, enabled]);
259
+ return /*#__PURE__*/React.createElement(selectionContext.Provider, {
260
+ value: value
261
+ }, children);
262
+ }
263
+ function Select(_ref2) {
264
+ let {
265
+ enabled = false,
266
+ children,
267
+ ...props
268
+ } = _ref2;
269
+ const group = useRef(null);
270
+ const api = useContext(selectionContext);
271
+ useEffect(() => {
272
+ if (api && enabled) {
273
+ let changed = false;
274
+ const current = [];
275
+ group.current.traverse(o => {
276
+ o.type === 'Mesh' && current.push(o);
277
+ if (api.selected.indexOf(o) === -1) changed = true;
278
+ });
279
+
280
+ if (changed) {
281
+ api.select(state => [...state, ...current]);
282
+ return () => {
283
+ api.select(state => without(state, ...current));
284
+ };
285
+ }
286
+ }
287
+ }, [enabled, children]);
288
+ return /*#__PURE__*/React.createElement("group", _extends({
289
+ ref: group
290
+ }, props), children);
291
+ }
292
+
293
+ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, forwardRef) {
246
294
  let {
247
295
  selection = [],
248
296
  selectionLayer = 10,
249
- blendFunction,
297
+ blendFunction = BlendFunction.ADD,
250
298
  patternTexture,
251
299
  edgeStrength,
252
300
  pulseSpeed,
253
- visibleEdgeColor,
254
- hiddenEdgeColor,
301
+ visibleEdgeColor = 0xffffff,
302
+ hiddenEdgeColor = 0xffffff,
255
303
  width,
256
304
  height,
257
305
  kernelSize,
@@ -285,10 +333,23 @@ const Outline = /*#__PURE__*/forwardRef(function Outline(_ref, ref) {
285
333
  useEffect(() => {
286
334
  effect.selectionLayer = selectionLayer;
287
335
  }, [effect, selectionLayer]);
336
+ const api = useContext(selectionContext);
337
+ const ref = useRef();
338
+ useEffect(() => {
339
+ if (api && api.enabled) {
340
+ var _api$selected;
341
+
342
+ const effect = ref.current;
343
+
344
+ if ((_api$selected = api.selected) != null && _api$selected.length) {
345
+ effect.selection.set(api.selected);
346
+ return () => void effect.selection.clear();
347
+ }
348
+ }
349
+ }, [api]);
288
350
  return /*#__PURE__*/React.createElement("primitive", {
289
- ref: ref,
290
- object: effect,
291
- dispose: null
351
+ ref: mergeRefs([ref, forwardRef]),
352
+ object: effect
292
353
  });
293
354
  });
294
355
 
@@ -312,7 +373,7 @@ const addLight = (light, effect) => light.layers.enable(effect.selection.layer);
312
373
 
313
374
  const removeLight = (light, effect) => light.layers.disable(effect.selection.layer);
314
375
 
315
- const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, ref) {
376
+ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, forwardRef) {
316
377
  let {
317
378
  selection = [],
318
379
  selectionLayer = 10,
@@ -357,8 +418,22 @@ const SelectiveBloom = /*#__PURE__*/forwardRef(function SelectiveBloom(_ref, ref
357
418
  return () => lights.forEach(light => removeLight(resolveRef(light), effect));
358
419
  }
359
420
  }, [effect, lights, selectionLayer]);
421
+ const api = useContext(selectionContext);
422
+ const ref = useRef();
423
+ useEffect(() => {
424
+ if (api && api.enabled) {
425
+ var _api$selected;
426
+
427
+ const effect = ref.current;
428
+
429
+ if ((_api$selected = api.selected) != null && _api$selected.length) {
430
+ effect.selection.set(api.selected);
431
+ return () => void effect.selection.clear();
432
+ }
433
+ }
434
+ }, [api]);
360
435
  return /*#__PURE__*/React.createElement("primitive", {
361
- ref: ref,
436
+ ref: mergeRefs([ref, forwardRef]),
362
437
  object: effect,
363
438
  dispose: null
364
439
  });
@@ -460,4 +535,4 @@ const LUT = /*#__PURE__*/forwardRef(function LUT(_ref, ref) {
460
535
  });
461
536
  });
462
537
 
463
- export { Bloom, BrightnessContrast, ChromaticAberration, ColorAverage, ColorDepth, Depth, DepthOfField, DotScreen, EffectComposer$1 as EffectComposer, EffectComposerContext, Glitch, GodRays, Grid, HueSaturation, LUT, Noise, Outline, Pixelation, SMAA, SSAO, Scanline, SelectiveBloom, Sepia, ShockWave, Texture, ToneMapping, Vignette };
538
+ export { Bloom, BrightnessContrast, ChromaticAberration, ColorAverage, ColorDepth, Depth, DepthOfField, DotScreen, EffectComposer, EffectComposerContext, Glitch, GodRays, Grid, HueSaturation, LUT, Noise, Outline, Pixelation, SMAA, SSAO, Scanline, Select, Selection, SelectiveBloom, Sepia, ShockWave, Texture, ToneMapping, Vignette, selectionContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/postprocessing",
3
- "version": "2.1.6",
3
+ "version": "2.2.0",
4
4
  "description": "postprocessing wrapper for React and @react-three/fiber",
5
5
  "keywords": [
6
6
  "postprocessing",
@@ -38,6 +38,7 @@
38
38
  "typegen": "tsc --emitDeclarationOnly || true"
39
39
  },
40
40
  "dependencies": {
41
+ "lodash-es": "^4.17.21",
41
42
  "postprocessing": "^6.24.1",
42
43
  "react-merge-refs": "^1.1.0",
43
44
  "three-stdlib": "^2.8.6"