@react-three/postprocessing 2.1.6 → 2.2.2
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 +65 -2
- package/dist/EffectComposer.d.ts +1 -2
- package/dist/Selection.d.ts +16 -0
- package/dist/index.cjs.js +111 -16
- package/dist/index.d.ts +2 -1
- package/dist/index.js +86 -11
- package/package.json +2 -1
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
|
-
|
|
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
|
-
|
|
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 autoclear={false}>
|
|
102
|
+
<Outline blur edgeStrength={100} />
|
|
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/)
|
package/dist/EffectComposer.d.ts
CHANGED
|
@@ -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;
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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,8 +313,64 @@ 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,
|
|
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,
|
|
@@ -359,10 +418,26 @@ var Outline = /*#__PURE__*/React.forwardRef(function Outline(_ref, ref) {
|
|
|
359
418
|
React.useEffect(function () {
|
|
360
419
|
effect.selectionLayer = selectionLayer;
|
|
361
420
|
}, [effect, selectionLayer]);
|
|
421
|
+
var api = React.useContext(selectionContext);
|
|
422
|
+
var ref = React.useRef();
|
|
423
|
+
React.useEffect(function () {
|
|
424
|
+
if (api && api.enabled) {
|
|
425
|
+
var _api$selected;
|
|
426
|
+
|
|
427
|
+
var _effect = ref.current;
|
|
428
|
+
|
|
429
|
+
if ((_api$selected = api.selected) != null && _api$selected.length) {
|
|
430
|
+
_effect.selection.set(api.selected);
|
|
431
|
+
|
|
432
|
+
return function () {
|
|
433
|
+
return void _effect.selection.clear();
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}, [api]);
|
|
362
438
|
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
363
|
-
ref: ref,
|
|
364
|
-
object: effect
|
|
365
|
-
dispose: null
|
|
439
|
+
ref: mergeRefs__default["default"]([ref, forwardRef]),
|
|
440
|
+
object: effect
|
|
366
441
|
});
|
|
367
442
|
});
|
|
368
443
|
|
|
@@ -391,7 +466,7 @@ var removeLight = function removeLight(light, effect) {
|
|
|
391
466
|
return light.layers.disable(effect.selection.layer);
|
|
392
467
|
};
|
|
393
468
|
|
|
394
|
-
var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref,
|
|
469
|
+
var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref, forwardRef) {
|
|
395
470
|
var _ref$selection = _ref.selection,
|
|
396
471
|
selection = _ref$selection === void 0 ? [] : _ref$selection,
|
|
397
472
|
_ref$selectionLayer = _ref.selectionLayer,
|
|
@@ -447,8 +522,25 @@ var SelectiveBloom = /*#__PURE__*/React.forwardRef(function SelectiveBloom(_ref,
|
|
|
447
522
|
};
|
|
448
523
|
}
|
|
449
524
|
}, [effect, lights, selectionLayer]);
|
|
525
|
+
var api = React.useContext(selectionContext);
|
|
526
|
+
var ref = React.useRef();
|
|
527
|
+
React.useEffect(function () {
|
|
528
|
+
if (api && api.enabled) {
|
|
529
|
+
var _api$selected;
|
|
530
|
+
|
|
531
|
+
var _effect = ref.current;
|
|
532
|
+
|
|
533
|
+
if ((_api$selected = api.selected) != null && _api$selected.length) {
|
|
534
|
+
_effect.selection.set(api.selected);
|
|
535
|
+
|
|
536
|
+
return function () {
|
|
537
|
+
return void _effect.selection.clear();
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}, [api]);
|
|
450
542
|
return /*#__PURE__*/React__default["default"].createElement("primitive", {
|
|
451
|
-
ref: ref,
|
|
543
|
+
ref: mergeRefs__default["default"]([ref, forwardRef]),
|
|
452
544
|
object: effect,
|
|
453
545
|
dispose: null
|
|
454
546
|
});
|
|
@@ -563,7 +655,7 @@ exports.ColorDepth = ColorDepth;
|
|
|
563
655
|
exports.Depth = Depth;
|
|
564
656
|
exports.DepthOfField = DepthOfField;
|
|
565
657
|
exports.DotScreen = DotScreen;
|
|
566
|
-
exports.EffectComposer = EffectComposer
|
|
658
|
+
exports.EffectComposer = EffectComposer;
|
|
567
659
|
exports.EffectComposerContext = EffectComposerContext;
|
|
568
660
|
exports.Glitch = Glitch;
|
|
569
661
|
exports.GodRays = GodRays;
|
|
@@ -576,9 +668,12 @@ exports.Pixelation = Pixelation;
|
|
|
576
668
|
exports.SMAA = SMAA;
|
|
577
669
|
exports.SSAO = SSAO;
|
|
578
670
|
exports.Scanline = Scanline;
|
|
671
|
+
exports.Select = Select;
|
|
672
|
+
exports.Selection = Selection;
|
|
579
673
|
exports.SelectiveBloom = SelectiveBloom;
|
|
580
674
|
exports.Sepia = Sepia;
|
|
581
675
|
exports.ShockWave = ShockWave;
|
|
582
676
|
exports.Texture = Texture;
|
|
583
677
|
exports.ToneMapping = ToneMapping;
|
|
584
678
|
exports.Vignette = Vignette;
|
|
679
|
+
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
|
|
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
|
-
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$
|
|
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,7 +244,53 @@ const HueSaturation = wrapEffect(HueSaturationEffect);
|
|
|
242
244
|
|
|
243
245
|
const Noise = wrapEffect(NoiseEffect, BlendFunction.COLOR_DODGE);
|
|
244
246
|
|
|
245
|
-
const
|
|
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,
|
|
@@ -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,
|
|
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
|
|
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.
|
|
3
|
+
"version": "2.2.2",
|
|
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"
|