@react-three/postprocessing 2.11.0 → 2.11.1
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/dist/{Autofocus.d.ts → effects/Autofocus.d.ts} +1 -1
- package/dist/effects/Bloom.d.ts +4 -3
- package/dist/effects/Noise.d.ts +7 -3
- package/dist/effects/ScanlineEffect.d.ts +7 -4
- package/dist/effects/TiltShift.d.ts +15 -3
- package/dist/effects/TiltShift2.d.ts +12 -3
- package/dist/index.cjs +83 -76
- package/dist/index.d.ts +1 -1
- package/dist/index.js +85 -78
- package/dist/util.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import React, { RefObject } from 'react';
|
|
3
3
|
import { DepthOfFieldEffect } from 'postprocessing';
|
|
4
|
-
import { DepthOfField } from '
|
|
4
|
+
import { DepthOfField } from '..';
|
|
5
5
|
export type AutofocusProps = typeof DepthOfField & {
|
|
6
6
|
target?: [number, number, number];
|
|
7
7
|
mouse?: boolean;
|
package/dist/effects/Bloom.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { BloomEffect, BlendFunction } from 'postprocessing';
|
|
3
|
-
export declare const Bloom: import("react").ForwardRefExoticComponent<{
|
|
4
|
-
blendFunction
|
|
5
|
-
|
|
3
|
+
export declare const Bloom: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<BloomEffect>, import("@react-three/fiber").NodeProps<BloomEffect, typeof BloomEffect>>> & import("postprocessing").BloomEffectOptions & {
|
|
4
|
+
blendFunction?: BlendFunction | undefined;
|
|
5
|
+
opacity?: number | undefined;
|
|
6
|
+
}, "ref"> & import("react").RefAttributes<typeof BloomEffect>>;
|
package/dist/effects/Noise.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { NoiseEffect, BlendFunction } from 'postprocessing';
|
|
3
|
-
export declare const Noise: import("react").ForwardRefExoticComponent<{
|
|
4
|
-
blendFunction
|
|
5
|
-
|
|
3
|
+
export declare const Noise: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<NoiseEffect>, import("@react-three/fiber").NodeProps<NoiseEffect, typeof NoiseEffect>>> & {
|
|
4
|
+
blendFunction?: BlendFunction | undefined;
|
|
5
|
+
premultiply?: boolean | undefined;
|
|
6
|
+
} & {
|
|
7
|
+
blendFunction?: BlendFunction | undefined;
|
|
8
|
+
opacity?: number | undefined;
|
|
9
|
+
}, "ref"> & import("react").RefAttributes<typeof NoiseEffect>>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ScanlineEffect, BlendFunction } from 'postprocessing';
|
|
3
|
-
export declare const Scanline: import("react").ForwardRefExoticComponent<{
|
|
4
|
-
blendFunction
|
|
5
|
-
density
|
|
6
|
-
} &
|
|
3
|
+
export declare const Scanline: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<ScanlineEffect>, import("@react-three/fiber").NodeProps<ScanlineEffect, typeof ScanlineEffect>>> & {
|
|
4
|
+
blendFunction?: BlendFunction | undefined;
|
|
5
|
+
density?: number | undefined;
|
|
6
|
+
} & {
|
|
7
|
+
blendFunction?: BlendFunction | undefined;
|
|
8
|
+
opacity?: number | undefined;
|
|
9
|
+
}, "ref"> & import("react").RefAttributes<typeof ScanlineEffect>>;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { TiltShiftEffect, BlendFunction } from 'postprocessing';
|
|
3
|
-
export declare const TiltShift: import("react").ForwardRefExoticComponent<{
|
|
4
|
-
blendFunction
|
|
5
|
-
|
|
3
|
+
export declare const TiltShift: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<TiltShiftEffect>, import("@react-three/fiber").NodeProps<TiltShiftEffect, typeof TiltShiftEffect>>> & {
|
|
4
|
+
blendFunction?: BlendFunction | undefined;
|
|
5
|
+
offset?: number | undefined;
|
|
6
|
+
rotation?: number | undefined;
|
|
7
|
+
focusArea?: number | undefined;
|
|
8
|
+
feather?: number | undefined;
|
|
9
|
+
bias?: number | undefined;
|
|
10
|
+
kernelSize?: import("postprocessing").KernelSize | undefined;
|
|
11
|
+
resolutionScale?: number | undefined;
|
|
12
|
+
resolutionX?: number | undefined;
|
|
13
|
+
resolutionY?: number | undefined;
|
|
14
|
+
} & {
|
|
15
|
+
blendFunction?: BlendFunction | undefined;
|
|
16
|
+
opacity?: number | undefined;
|
|
17
|
+
}, "ref"> & import("react").RefAttributes<typeof TiltShiftEffect>>;
|
|
@@ -16,6 +16,15 @@ export declare class TiltShiftEffect extends Effect {
|
|
|
16
16
|
direction?: number[] | undefined;
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
export declare const TiltShift2: import("react").ForwardRefExoticComponent<{
|
|
20
|
-
blendFunction
|
|
21
|
-
|
|
19
|
+
export declare const TiltShift2: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<TiltShiftEffect>, import("@react-three/fiber").NodeProps<TiltShiftEffect, typeof TiltShiftEffect>>> & {
|
|
20
|
+
blendFunction?: BlendFunction | undefined;
|
|
21
|
+
blur?: number | undefined;
|
|
22
|
+
taper?: number | undefined;
|
|
23
|
+
start?: number[] | undefined;
|
|
24
|
+
end?: number[] | undefined;
|
|
25
|
+
samples?: number | undefined;
|
|
26
|
+
direction?: number[] | undefined;
|
|
27
|
+
} & {
|
|
28
|
+
blendFunction?: BlendFunction | undefined;
|
|
29
|
+
opacity?: number | undefined;
|
|
30
|
+
}, "ref"> & import("react").RefAttributes<typeof TiltShiftEffect>>;
|
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var postprocessing = require('postprocessing');
|
|
4
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var React = require('react');
|
|
6
4
|
var THREE = require('three');
|
|
5
|
+
var React = require('react');
|
|
7
6
|
var fiber = require('@react-three/fiber');
|
|
7
|
+
var postprocessing = require('postprocessing');
|
|
8
|
+
var maath = require('maath');
|
|
8
9
|
var threeStdlib = require('three-stdlib');
|
|
9
10
|
var screenSpaceReflections = require('screen-space-reflections');
|
|
10
|
-
var maath = require('maath');
|
|
11
11
|
|
|
12
12
|
function _interopNamespaceDefault(e) {
|
|
13
13
|
var n = Object.create(null);
|
|
@@ -28,6 +28,86 @@ function _interopNamespaceDefault(e) {
|
|
|
28
28
|
|
|
29
29
|
var THREE__namespace = /*#__PURE__*/_interopNamespaceDefault(THREE);
|
|
30
30
|
|
|
31
|
+
const Autofocus = React.forwardRef(({ target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0, ...props }, fref) => {
|
|
32
|
+
const dofRef = React.useRef(null);
|
|
33
|
+
const hitpointRef = React.useRef(null);
|
|
34
|
+
const targetRef = React.useRef(null);
|
|
35
|
+
const scene = fiber.useThree(({ scene }) => scene);
|
|
36
|
+
const pointer = fiber.useThree(({ pointer }) => pointer);
|
|
37
|
+
const { composer, camera } = React.useContext(EffectComposerContext);
|
|
38
|
+
// see: https://codesandbox.io/s/depthpickingpass-x130hg
|
|
39
|
+
const [depthPickingPass] = React.useState(() => new postprocessing.DepthPickingPass());
|
|
40
|
+
const [copyPass] = React.useState(() => new postprocessing.CopyPass());
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
composer.addPass(depthPickingPass);
|
|
43
|
+
composer.addPass(copyPass);
|
|
44
|
+
return () => {
|
|
45
|
+
composer.removePass(depthPickingPass);
|
|
46
|
+
composer.removePass(copyPass);
|
|
47
|
+
};
|
|
48
|
+
}, [composer, depthPickingPass, copyPass]);
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
return () => {
|
|
51
|
+
depthPickingPass.dispose();
|
|
52
|
+
copyPass.dispose();
|
|
53
|
+
};
|
|
54
|
+
}, [depthPickingPass, copyPass]);
|
|
55
|
+
const [hitpoint] = React.useState(() => new THREE__namespace.Vector3(0, 0, 0));
|
|
56
|
+
const [ndc] = React.useState(() => new THREE__namespace.Vector3(0, 0, 0));
|
|
57
|
+
const getHit = React.useCallback(async (x, y) => {
|
|
58
|
+
ndc.x = x;
|
|
59
|
+
ndc.y = y;
|
|
60
|
+
ndc.z = await depthPickingPass.readDepth(ndc);
|
|
61
|
+
ndc.z = ndc.z * 2.0 - 1.0;
|
|
62
|
+
const hit = 1 - ndc.z > 0.0000001; // it is missed if ndc.z is close to 1
|
|
63
|
+
return hit ? ndc.unproject(camera) : false;
|
|
64
|
+
}, [ndc, depthPickingPass, camera]);
|
|
65
|
+
const update = React.useCallback(async (delta, updateTarget = true) => {
|
|
66
|
+
var _a;
|
|
67
|
+
// Update hitpoint
|
|
68
|
+
if (target) {
|
|
69
|
+
hitpoint.set(...target);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const { x, y } = followMouse ? pointer : { x: 0, y: 0 };
|
|
73
|
+
const hit = await getHit(x, y);
|
|
74
|
+
if (hit)
|
|
75
|
+
hitpoint.copy(hit);
|
|
76
|
+
}
|
|
77
|
+
// Update target
|
|
78
|
+
if (updateTarget && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
|
|
79
|
+
if (smoothTime > 0 && delta > 0) {
|
|
80
|
+
maath.easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
dofRef.current.target.copy(hitpoint);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}, [target, hitpoint, followMouse, getHit, smoothTime, pointer]);
|
|
87
|
+
fiber.useFrame(async (_, delta) => {
|
|
88
|
+
var _a;
|
|
89
|
+
if (!manual) {
|
|
90
|
+
update(delta);
|
|
91
|
+
}
|
|
92
|
+
if (hitpointRef.current) {
|
|
93
|
+
hitpointRef.current.position.copy(hitpoint);
|
|
94
|
+
}
|
|
95
|
+
if (targetRef.current && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
|
|
96
|
+
targetRef.current.position.copy(dofRef.current.target);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
// Ref API
|
|
100
|
+
const api = React.useMemo(() => ({
|
|
101
|
+
dofRef,
|
|
102
|
+
hitpoint,
|
|
103
|
+
update,
|
|
104
|
+
}), [hitpoint, update]);
|
|
105
|
+
React.useImperativeHandle(fref, () => api, [api]);
|
|
106
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [debug
|
|
107
|
+
? fiber.createPortal(jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("mesh", { ref: hitpointRef, children: [jsxRuntime.jsx("sphereGeometry", { args: [debug, 16, 16] }), jsxRuntime.jsx("meshBasicMaterial", { color: "#00ff00", opacity: 1, transparent: true, depthWrite: false })] }), jsxRuntime.jsxs("mesh", { ref: targetRef, children: [jsxRuntime.jsx("sphereGeometry", { args: [debug / 2, 16, 16] }), jsxRuntime.jsx("meshBasicMaterial", { color: "#00ff00", opacity: 0.5, transparent: true, depthWrite: false })] })] }), scene)
|
|
108
|
+
: null, jsxRuntime.jsx(DepthOfField, { ref: dofRef, ...props, target: hitpoint })] }));
|
|
109
|
+
});
|
|
110
|
+
|
|
31
111
|
const resolveRef = (ref) => typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref;
|
|
32
112
|
let i = 0;
|
|
33
113
|
const components = new WeakMap();
|
|
@@ -552,79 +632,6 @@ const SSR = React.forwardRef(function SSR({ ENABLE_BLUR = true, USE_MRT = true,
|
|
|
552
632
|
return jsxRuntime.jsx("primitive", { ref: ref, object: effect, ...props });
|
|
553
633
|
});
|
|
554
634
|
|
|
555
|
-
const Autofocus = React.forwardRef(({ target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0, ...props }, fref) => {
|
|
556
|
-
const dofRef = React.useRef(null);
|
|
557
|
-
const hitpointRef = React.useRef(null);
|
|
558
|
-
const targetRef = React.useRef(null);
|
|
559
|
-
const scene = fiber.useThree(({ scene }) => scene);
|
|
560
|
-
const pointer = fiber.useThree(({ pointer }) => pointer);
|
|
561
|
-
const { composer, camera } = React.useContext(EffectComposerContext);
|
|
562
|
-
// see: https://codesandbox.io/s/depthpickingpass-x130hg
|
|
563
|
-
const [depthPickingPass] = React.useState(new postprocessing.DepthPickingPass());
|
|
564
|
-
const [copyPass] = React.useState(new postprocessing.CopyPass());
|
|
565
|
-
React.useEffect(() => {
|
|
566
|
-
composer.addPass(depthPickingPass);
|
|
567
|
-
composer.addPass(copyPass);
|
|
568
|
-
return () => {
|
|
569
|
-
composer.removePass(depthPickingPass);
|
|
570
|
-
composer.removePass(copyPass);
|
|
571
|
-
};
|
|
572
|
-
}, [composer, depthPickingPass, copyPass]);
|
|
573
|
-
const [hitpoint] = React.useState(new THREE__namespace.Vector3(0, 0, 0));
|
|
574
|
-
const [ndc] = React.useState(new THREE__namespace.Vector3(0, 0, 0));
|
|
575
|
-
const getHit = React.useCallback(async (x, y) => {
|
|
576
|
-
ndc.x = x;
|
|
577
|
-
ndc.y = y;
|
|
578
|
-
ndc.z = await depthPickingPass.readDepth(ndc);
|
|
579
|
-
ndc.z = ndc.z * 2.0 - 1.0;
|
|
580
|
-
const hit = 1 - ndc.z > 0.0000001; // it is missed if ndc.z is close to 1
|
|
581
|
-
return hit ? ndc.unproject(camera) : false;
|
|
582
|
-
}, [ndc, depthPickingPass, camera]);
|
|
583
|
-
const update = React.useCallback(async (delta, updateTarget = true) => {
|
|
584
|
-
var _a;
|
|
585
|
-
// Update hitpoint
|
|
586
|
-
if (target) {
|
|
587
|
-
hitpoint.set(...target);
|
|
588
|
-
}
|
|
589
|
-
else {
|
|
590
|
-
const { x, y } = followMouse ? pointer : { x: 0, y: 0 };
|
|
591
|
-
const hit = await getHit(x, y);
|
|
592
|
-
if (hit)
|
|
593
|
-
hitpoint.copy(hit);
|
|
594
|
-
}
|
|
595
|
-
// Update target
|
|
596
|
-
if (updateTarget && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
|
|
597
|
-
if (smoothTime > 0 && delta > 0) {
|
|
598
|
-
maath.easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta);
|
|
599
|
-
}
|
|
600
|
-
else {
|
|
601
|
-
dofRef.current.target.copy(hitpoint);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}, [target, hitpoint, followMouse, getHit, smoothTime, pointer]);
|
|
605
|
-
fiber.useFrame(async (_, delta) => {
|
|
606
|
-
var _a;
|
|
607
|
-
if (!manual) {
|
|
608
|
-
update(delta);
|
|
609
|
-
}
|
|
610
|
-
if (hitpointRef.current) {
|
|
611
|
-
hitpointRef.current.position.copy(hitpoint);
|
|
612
|
-
}
|
|
613
|
-
if (targetRef.current && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
|
|
614
|
-
targetRef.current.position.copy(dofRef.current.target);
|
|
615
|
-
}
|
|
616
|
-
});
|
|
617
|
-
// Ref API
|
|
618
|
-
React.useImperativeHandle(fref, () => ({
|
|
619
|
-
dofRef,
|
|
620
|
-
hitpoint,
|
|
621
|
-
update,
|
|
622
|
-
}), [hitpoint, update]);
|
|
623
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [debug
|
|
624
|
-
? fiber.createPortal(jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("mesh", { ref: hitpointRef, children: [jsxRuntime.jsx("sphereGeometry", { args: [debug, 16, 16] }), jsxRuntime.jsx("meshBasicMaterial", { color: "#00ff00", opacity: 1, transparent: true, depthWrite: false })] }), jsxRuntime.jsxs("mesh", { ref: targetRef, children: [jsxRuntime.jsx("sphereGeometry", { args: [debug / 2, 16, 16] }), jsxRuntime.jsx("meshBasicMaterial", { color: "#00ff00", opacity: 0.5, transparent: true, depthWrite: false })] })] }), scene)
|
|
625
|
-
: null, jsxRuntime.jsx(DepthOfField, { ref: dofRef, ...props, target: hitpoint })] }));
|
|
626
|
-
});
|
|
627
|
-
|
|
628
635
|
exports.Autofocus = Autofocus;
|
|
629
636
|
exports.Bloom = Bloom;
|
|
630
637
|
exports.BrightnessContrast = BrightnessContrast;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './effects/Autofocus';
|
|
1
2
|
export * from './effects/Bloom';
|
|
2
3
|
export * from './effects/BrightnessContrast';
|
|
3
4
|
export * from './effects/ChromaticAberration';
|
|
@@ -27,6 +28,5 @@ export * from './effects/TiltShift';
|
|
|
27
28
|
export * from './effects/TiltShift2';
|
|
28
29
|
export * from './effects/SSR';
|
|
29
30
|
export * from './Selection';
|
|
30
|
-
export * from './Autofocus';
|
|
31
31
|
export * from './EffectComposer';
|
|
32
32
|
export * from './util';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,92 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
-
import React, { forwardRef, useMemo, createContext, useEffect, useRef, useLayoutEffect, useImperativeHandle, useContext, useState, useCallback } from 'react';
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
4
2
|
import * as THREE from 'three';
|
|
5
3
|
import { HalfFloatType, Vector3, TextureLoader, sRGBEncoding, RepeatWrapping, Uniform } from 'three';
|
|
6
|
-
import {
|
|
4
|
+
import React, { forwardRef, useRef, useContext, useState, useEffect, useCallback, useMemo, useImperativeHandle, createContext, useLayoutEffect } from 'react';
|
|
5
|
+
import { useThree, useFrame, createPortal, extend, useInstanceHandle, useLoader } from '@react-three/fiber';
|
|
6
|
+
import { DepthPickingPass, CopyPass, BlendFunction, BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, DepthEffect, EffectComposer as EffectComposer$1, RenderPass, NormalPass, DepthDownsamplingPass, EffectPass, DepthOfFieldEffect, MaskFunction, DotScreenEffect, GlitchEffect, GlitchMode, GodRaysEffect, GridEffect, HueSaturationEffect, NoiseEffect, OutlineEffect, PixelationEffect, ScanlineEffect, SelectiveBloomEffect, SepiaEffect, SSAOEffect, SMAAEffect, TextureEffect, ToneMappingEffect, VignetteEffect, ShockWaveEffect, LUT3DEffect, TiltShiftEffect as TiltShiftEffect$1, Effect, EffectAttribute } from 'postprocessing';
|
|
7
|
+
import { easing } from 'maath';
|
|
7
8
|
import { isWebGL2Available } from 'three-stdlib';
|
|
8
9
|
import { SSREffect } from 'screen-space-reflections';
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
const Autofocus = forwardRef(({ target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0, ...props }, fref) => {
|
|
12
|
+
const dofRef = useRef(null);
|
|
13
|
+
const hitpointRef = useRef(null);
|
|
14
|
+
const targetRef = useRef(null);
|
|
15
|
+
const scene = useThree(({ scene }) => scene);
|
|
16
|
+
const pointer = useThree(({ pointer }) => pointer);
|
|
17
|
+
const { composer, camera } = useContext(EffectComposerContext);
|
|
18
|
+
// see: https://codesandbox.io/s/depthpickingpass-x130hg
|
|
19
|
+
const [depthPickingPass] = useState(() => new DepthPickingPass());
|
|
20
|
+
const [copyPass] = useState(() => new CopyPass());
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
composer.addPass(depthPickingPass);
|
|
23
|
+
composer.addPass(copyPass);
|
|
24
|
+
return () => {
|
|
25
|
+
composer.removePass(depthPickingPass);
|
|
26
|
+
composer.removePass(copyPass);
|
|
27
|
+
};
|
|
28
|
+
}, [composer, depthPickingPass, copyPass]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
return () => {
|
|
31
|
+
depthPickingPass.dispose();
|
|
32
|
+
copyPass.dispose();
|
|
33
|
+
};
|
|
34
|
+
}, [depthPickingPass, copyPass]);
|
|
35
|
+
const [hitpoint] = useState(() => new THREE.Vector3(0, 0, 0));
|
|
36
|
+
const [ndc] = useState(() => new THREE.Vector3(0, 0, 0));
|
|
37
|
+
const getHit = useCallback(async (x, y) => {
|
|
38
|
+
ndc.x = x;
|
|
39
|
+
ndc.y = y;
|
|
40
|
+
ndc.z = await depthPickingPass.readDepth(ndc);
|
|
41
|
+
ndc.z = ndc.z * 2.0 - 1.0;
|
|
42
|
+
const hit = 1 - ndc.z > 0.0000001; // it is missed if ndc.z is close to 1
|
|
43
|
+
return hit ? ndc.unproject(camera) : false;
|
|
44
|
+
}, [ndc, depthPickingPass, camera]);
|
|
45
|
+
const update = useCallback(async (delta, updateTarget = true) => {
|
|
46
|
+
var _a;
|
|
47
|
+
// Update hitpoint
|
|
48
|
+
if (target) {
|
|
49
|
+
hitpoint.set(...target);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const { x, y } = followMouse ? pointer : { x: 0, y: 0 };
|
|
53
|
+
const hit = await getHit(x, y);
|
|
54
|
+
if (hit)
|
|
55
|
+
hitpoint.copy(hit);
|
|
56
|
+
}
|
|
57
|
+
// Update target
|
|
58
|
+
if (updateTarget && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
|
|
59
|
+
if (smoothTime > 0 && delta > 0) {
|
|
60
|
+
easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
dofRef.current.target.copy(hitpoint);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}, [target, hitpoint, followMouse, getHit, smoothTime, pointer]);
|
|
67
|
+
useFrame(async (_, delta) => {
|
|
68
|
+
var _a;
|
|
69
|
+
if (!manual) {
|
|
70
|
+
update(delta);
|
|
71
|
+
}
|
|
72
|
+
if (hitpointRef.current) {
|
|
73
|
+
hitpointRef.current.position.copy(hitpoint);
|
|
74
|
+
}
|
|
75
|
+
if (targetRef.current && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
|
|
76
|
+
targetRef.current.position.copy(dofRef.current.target);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
// Ref API
|
|
80
|
+
const api = useMemo(() => ({
|
|
81
|
+
dofRef,
|
|
82
|
+
hitpoint,
|
|
83
|
+
update,
|
|
84
|
+
}), [hitpoint, update]);
|
|
85
|
+
useImperativeHandle(fref, () => api, [api]);
|
|
86
|
+
return (jsxs(Fragment, { children: [debug
|
|
87
|
+
? createPortal(jsxs(Fragment, { children: [jsxs("mesh", { ref: hitpointRef, children: [jsx("sphereGeometry", { args: [debug, 16, 16] }), jsx("meshBasicMaterial", { color: "#00ff00", opacity: 1, transparent: true, depthWrite: false })] }), jsxs("mesh", { ref: targetRef, children: [jsx("sphereGeometry", { args: [debug / 2, 16, 16] }), jsx("meshBasicMaterial", { color: "#00ff00", opacity: 0.5, transparent: true, depthWrite: false })] })] }), scene)
|
|
88
|
+
: null, jsx(DepthOfField, { ref: dofRef, ...props, target: hitpoint })] }));
|
|
89
|
+
});
|
|
10
90
|
|
|
11
91
|
const resolveRef = (ref) => typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref;
|
|
12
92
|
let i = 0;
|
|
@@ -532,77 +612,4 @@ const SSR = forwardRef(function SSR({ ENABLE_BLUR = true, USE_MRT = true, ...pro
|
|
|
532
612
|
return jsx("primitive", { ref: ref, object: effect, ...props });
|
|
533
613
|
});
|
|
534
614
|
|
|
535
|
-
const Autofocus = forwardRef(({ target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0, ...props }, fref) => {
|
|
536
|
-
const dofRef = useRef(null);
|
|
537
|
-
const hitpointRef = useRef(null);
|
|
538
|
-
const targetRef = useRef(null);
|
|
539
|
-
const scene = useThree(({ scene }) => scene);
|
|
540
|
-
const pointer = useThree(({ pointer }) => pointer);
|
|
541
|
-
const { composer, camera } = useContext(EffectComposerContext);
|
|
542
|
-
// see: https://codesandbox.io/s/depthpickingpass-x130hg
|
|
543
|
-
const [depthPickingPass] = useState(new DepthPickingPass());
|
|
544
|
-
const [copyPass] = useState(new CopyPass());
|
|
545
|
-
useEffect(() => {
|
|
546
|
-
composer.addPass(depthPickingPass);
|
|
547
|
-
composer.addPass(copyPass);
|
|
548
|
-
return () => {
|
|
549
|
-
composer.removePass(depthPickingPass);
|
|
550
|
-
composer.removePass(copyPass);
|
|
551
|
-
};
|
|
552
|
-
}, [composer, depthPickingPass, copyPass]);
|
|
553
|
-
const [hitpoint] = useState(new THREE.Vector3(0, 0, 0));
|
|
554
|
-
const [ndc] = useState(new THREE.Vector3(0, 0, 0));
|
|
555
|
-
const getHit = useCallback(async (x, y) => {
|
|
556
|
-
ndc.x = x;
|
|
557
|
-
ndc.y = y;
|
|
558
|
-
ndc.z = await depthPickingPass.readDepth(ndc);
|
|
559
|
-
ndc.z = ndc.z * 2.0 - 1.0;
|
|
560
|
-
const hit = 1 - ndc.z > 0.0000001; // it is missed if ndc.z is close to 1
|
|
561
|
-
return hit ? ndc.unproject(camera) : false;
|
|
562
|
-
}, [ndc, depthPickingPass, camera]);
|
|
563
|
-
const update = useCallback(async (delta, updateTarget = true) => {
|
|
564
|
-
var _a;
|
|
565
|
-
// Update hitpoint
|
|
566
|
-
if (target) {
|
|
567
|
-
hitpoint.set(...target);
|
|
568
|
-
}
|
|
569
|
-
else {
|
|
570
|
-
const { x, y } = followMouse ? pointer : { x: 0, y: 0 };
|
|
571
|
-
const hit = await getHit(x, y);
|
|
572
|
-
if (hit)
|
|
573
|
-
hitpoint.copy(hit);
|
|
574
|
-
}
|
|
575
|
-
// Update target
|
|
576
|
-
if (updateTarget && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
|
|
577
|
-
if (smoothTime > 0 && delta > 0) {
|
|
578
|
-
easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta);
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
dofRef.current.target.copy(hitpoint);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}, [target, hitpoint, followMouse, getHit, smoothTime, pointer]);
|
|
585
|
-
useFrame(async (_, delta) => {
|
|
586
|
-
var _a;
|
|
587
|
-
if (!manual) {
|
|
588
|
-
update(delta);
|
|
589
|
-
}
|
|
590
|
-
if (hitpointRef.current) {
|
|
591
|
-
hitpointRef.current.position.copy(hitpoint);
|
|
592
|
-
}
|
|
593
|
-
if (targetRef.current && ((_a = dofRef.current) === null || _a === void 0 ? void 0 : _a.target)) {
|
|
594
|
-
targetRef.current.position.copy(dofRef.current.target);
|
|
595
|
-
}
|
|
596
|
-
});
|
|
597
|
-
// Ref API
|
|
598
|
-
useImperativeHandle(fref, () => ({
|
|
599
|
-
dofRef,
|
|
600
|
-
hitpoint,
|
|
601
|
-
update,
|
|
602
|
-
}), [hitpoint, update]);
|
|
603
|
-
return (jsxs(Fragment, { children: [debug
|
|
604
|
-
? createPortal(jsxs(Fragment, { children: [jsxs("mesh", { ref: hitpointRef, children: [jsx("sphereGeometry", { args: [debug, 16, 16] }), jsx("meshBasicMaterial", { color: "#00ff00", opacity: 1, transparent: true, depthWrite: false })] }), jsxs("mesh", { ref: targetRef, children: [jsx("sphereGeometry", { args: [debug / 2, 16, 16] }), jsx("meshBasicMaterial", { color: "#00ff00", opacity: 0.5, transparent: true, depthWrite: false })] })] }), scene)
|
|
605
|
-
: null, jsx(DepthOfField, { ref: dofRef, ...props, target: hitpoint })] }));
|
|
606
|
-
});
|
|
607
|
-
|
|
608
615
|
export { Autofocus, Bloom, BrightnessContrast, ChromaticAberration, ColorAverage, ColorDepth, Depth, DepthOfField, DotScreen, EffectComposer, EffectComposerContext, Glitch, GodRays, Grid, HueSaturation, LUT, Noise, Outline, Pixelation, SMAA, SSAO, SSR, Scanline, Select, Selection, SelectiveBloom, Sepia, ShockWave, Texture, TiltShift, TiltShift2, TiltShiftEffect, ToneMapping, Vignette, resolveRef, selectionContext, useVector2, wrapEffect };
|
package/dist/util.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export type EffectProps<T extends EffectConstructor> = ReactThreeFiber.Node<T ex
|
|
|
9
9
|
blendFunction?: BlendFunction;
|
|
10
10
|
opacity?: number;
|
|
11
11
|
};
|
|
12
|
-
export declare const wrapEffect: <T extends EffectConstructor
|
|
12
|
+
export declare const wrapEffect: <T extends EffectConstructor>(effect: T, defaults?: EffectProps<T> | undefined) => React.ForwardRefExoticComponent<React.PropsWithoutRef<EffectProps<T>> & React.RefAttributes<T>>;
|
|
13
13
|
export declare const useVector2: (props: Record<string, unknown>, key: string) => THREE.Vector2;
|