@tresjs/post-processing 0.1.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/LICENSE +21 -0
- package/README.md +92 -0
- package/dist/core/effects/Bloom.d.ts +69 -0
- package/dist/core/effects/Glitch.d.ts +90 -0
- package/dist/core/useCore.d.ts +11 -0
- package/dist/core/useEffectComposer/component.d.ts +119 -0
- package/dist/index.d.ts +4 -0
- package/dist/tres-postprocessing.js +215 -0
- package/dist/tres-postprocessing.umd.cjs +8 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-present, (alvarosabu) Alvaro Saburido and Tres contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://www.npmjs.com/package/@tresjs/core"><img src="https://img.shields.io/npm/v/@tresjs/core?color=%2382DBCA" alt="npm package"></a>
|
|
5
|
+
|
|
6
|
+
<a href="https://discord.gg/tfY9aSNT"><img src="https://img.shields.io/badge/chat-discord-purple?style=flat&logo=discord" alt="discord chat"></a>
|
|
7
|
+
|
|
8
|
+
</p>
|
|
9
|
+
<br/>
|
|
10
|
+
|
|
11
|
+
# Post-Processing
|
|
12
|
+
|
|
13
|
+
> Collection of useful helpers and fully functional, ready-made abstractions for Tres
|
|
14
|
+
|
|
15
|
+
- 💡 Build a 3D scene working only with Vue components.
|
|
16
|
+
- ⚡️ Powered by Vite
|
|
17
|
+
- 🥰 It brings all the updated features of ThreeJS right awayregardless the version
|
|
18
|
+
- 🦾 Fully Typed
|
|
19
|
+
|
|
20
|
+
Cientos (Spanish word for "hundreds", pronounced /θjentos/ ) is is a collection of useful ready-to-go helpers and components that are not part of the core package. The name uses the word uses in spanish to multiply by 100, to refer to the potential reach of the package to hold a amazing abstractions.
|
|
21
|
+
|
|
22
|
+
The postprocessing package uses three-stdlib module under the hood instead of the three/examples/jsm module. This means that you don't need to extend the catalogue of components using the extend method from the `core`, postprocessing does it for you.
|
|
23
|
+
|
|
24
|
+
It just works. 💯
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm i @tresjs/post-processing
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Docs
|
|
33
|
+
|
|
34
|
+
Checkout the [docs](https://cientos.tresjs.org/)
|
|
35
|
+
|
|
36
|
+
## Demos
|
|
37
|
+
|
|
38
|
+
- [Stackblitz Collection](https://stackblitz.com/@alvarosabu/collections/tresjs)
|
|
39
|
+
|
|
40
|
+
## Contributing
|
|
41
|
+
|
|
42
|
+
We are open to contributions, please read the [contributing guide](/CONTRIBUTING.md) to get started.
|
|
43
|
+
|
|
44
|
+
### Build
|
|
45
|
+
|
|
46
|
+
To build the package run:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pnpm run build
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Playground
|
|
53
|
+
|
|
54
|
+
To run the playground run, its a great way to test the components and helpers locally:
|
|
55
|
+
|
|
56
|
+
First install dependencies
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
pnpm i
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
And then to run the development server on http://localhost:5173
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pnpm run playground
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Test
|
|
69
|
+
|
|
70
|
+
TODO...
|
|
71
|
+
|
|
72
|
+
### Docs
|
|
73
|
+
|
|
74
|
+
To run de docs in dev mode
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pnpm run docs:dev
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
To build them
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pnpm run docs:build
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
[MIT](/LICENSE)
|
|
89
|
+
|
|
90
|
+
## Sponsors
|
|
91
|
+
|
|
92
|
+
Be the first to support this project [here](https://github.com/sponsors/alvarosabu) ☺️
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BlurPass, KernelSize } from 'postprocessing';
|
|
2
|
+
export interface BloomProps {
|
|
3
|
+
/**
|
|
4
|
+
* The intensity of the bloom effect.
|
|
5
|
+
*
|
|
6
|
+
* @default 1
|
|
7
|
+
* @type {number}
|
|
8
|
+
* @memberof BloomProps
|
|
9
|
+
*/
|
|
10
|
+
intensity?: number;
|
|
11
|
+
/**
|
|
12
|
+
* An efficient, incremental blur pass.
|
|
13
|
+
*
|
|
14
|
+
* @type {BlurPass}
|
|
15
|
+
* @memberof BloomProps
|
|
16
|
+
*/
|
|
17
|
+
blurPass?: BlurPass;
|
|
18
|
+
/**
|
|
19
|
+
* The width of the render
|
|
20
|
+
*
|
|
21
|
+
* @type {number}
|
|
22
|
+
* @memberof BloomProps
|
|
23
|
+
*/
|
|
24
|
+
width?: number;
|
|
25
|
+
/**
|
|
26
|
+
* The height of the render
|
|
27
|
+
*
|
|
28
|
+
* @type {number}
|
|
29
|
+
* @memberof BloomProps
|
|
30
|
+
*/
|
|
31
|
+
height?: number;
|
|
32
|
+
/**
|
|
33
|
+
* The kernel size.
|
|
34
|
+
*
|
|
35
|
+
* @default KernelSize.LARGE
|
|
36
|
+
*
|
|
37
|
+
* @type {KernelSize}
|
|
38
|
+
* @memberof BloomProps
|
|
39
|
+
*/
|
|
40
|
+
kernelSize?: KernelSize;
|
|
41
|
+
/**
|
|
42
|
+
* The luminance threshold. Raise this value to mask out darker elements in the scene. Range is [0, 1].
|
|
43
|
+
*
|
|
44
|
+
* @default 0.9
|
|
45
|
+
*
|
|
46
|
+
* @type {number}
|
|
47
|
+
* @memberof BloomProps
|
|
48
|
+
*/
|
|
49
|
+
luminanceThreshold?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Controls the smoothness of the luminance threshold. Range is [0, 1].
|
|
52
|
+
*
|
|
53
|
+
* @default 0.025
|
|
54
|
+
*
|
|
55
|
+
* @type {number}
|
|
56
|
+
* @memberof BloomProps
|
|
57
|
+
*/
|
|
58
|
+
luminanceSmoothing?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Enables mip map blur.
|
|
61
|
+
*
|
|
62
|
+
* @default false
|
|
63
|
+
*
|
|
64
|
+
* @type {boolean}
|
|
65
|
+
* @memberof BloomProps
|
|
66
|
+
*/
|
|
67
|
+
mipMapBlur?: boolean;
|
|
68
|
+
}
|
|
69
|
+
export declare const Bloom: import("vue").DefineComponent<BloomProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<BloomProps>, {}>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Texture, Vector2 } from 'three';
|
|
2
|
+
import { GlitchMode } from 'postprocessing';
|
|
3
|
+
export interface GlitchProps {
|
|
4
|
+
/**
|
|
5
|
+
* The minimum and maximum delay between glitch activations in seconds.
|
|
6
|
+
*
|
|
7
|
+
* @default [1.5, 3.5]
|
|
8
|
+
*
|
|
9
|
+
* @type {Vector2}
|
|
10
|
+
* @memberof GlitchProps
|
|
11
|
+
*/
|
|
12
|
+
delay?: Vector2;
|
|
13
|
+
/**
|
|
14
|
+
* The minimum and maximum duration of a glitch in seconds.
|
|
15
|
+
*
|
|
16
|
+
* @default [0.6, 1.0]
|
|
17
|
+
*
|
|
18
|
+
* @type {Vector2}
|
|
19
|
+
* @memberof GlitchProps
|
|
20
|
+
*/
|
|
21
|
+
duration?: Vector2;
|
|
22
|
+
/**
|
|
23
|
+
* The strength of weak and strong glitches.
|
|
24
|
+
*
|
|
25
|
+
* @default [0.3, 1.0]
|
|
26
|
+
*
|
|
27
|
+
* @type {Vector2}
|
|
28
|
+
* @memberof GlitchProps
|
|
29
|
+
*/
|
|
30
|
+
strength?: Vector2;
|
|
31
|
+
/**
|
|
32
|
+
* The glitch mode. Can be DISABLED | SPORADIC | CONSTANT_MILD | CONSTANT_WILD .
|
|
33
|
+
*
|
|
34
|
+
* @default GlitchMode.SPORADIC
|
|
35
|
+
*
|
|
36
|
+
* @type {GlitchMode}
|
|
37
|
+
* @memberof GlitchProps
|
|
38
|
+
*/
|
|
39
|
+
mode?: GlitchMode;
|
|
40
|
+
/**
|
|
41
|
+
* Turn the effect on and off.
|
|
42
|
+
*
|
|
43
|
+
* @type {boolean}
|
|
44
|
+
* @memberof GlitchProps
|
|
45
|
+
*/
|
|
46
|
+
active?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* The threshold for strong glitches.
|
|
50
|
+
*
|
|
51
|
+
* @default 0.85
|
|
52
|
+
*
|
|
53
|
+
* @type {number}
|
|
54
|
+
* @memberof GlitchProps
|
|
55
|
+
*/
|
|
56
|
+
ratio?: number;
|
|
57
|
+
/**
|
|
58
|
+
* The scale of the blocky glitch columns.
|
|
59
|
+
*
|
|
60
|
+
* @default 0.05
|
|
61
|
+
*
|
|
62
|
+
* @type {number}
|
|
63
|
+
* @memberof GlitchProps
|
|
64
|
+
*/
|
|
65
|
+
columns?: number;
|
|
66
|
+
/**
|
|
67
|
+
* A chromatic aberration offset. If provided, the glitch effect will influence this offset.
|
|
68
|
+
*
|
|
69
|
+
* @type {Vector2}
|
|
70
|
+
* @memberof GlitchProps
|
|
71
|
+
*/
|
|
72
|
+
chromaticAberrationOffset?: Vector2;
|
|
73
|
+
/**
|
|
74
|
+
* A perturbation map. If none is provided, a noise texture will be created.
|
|
75
|
+
*
|
|
76
|
+
* @type {Texture}
|
|
77
|
+
* @memberof GlitchProps
|
|
78
|
+
*/
|
|
79
|
+
peturbationMap?: Texture;
|
|
80
|
+
/**
|
|
81
|
+
* The size of the generated noise map. Will be ignored if a perturbation map is provided.
|
|
82
|
+
*
|
|
83
|
+
* @default 64
|
|
84
|
+
*
|
|
85
|
+
* @type {number}
|
|
86
|
+
* @memberof GlitchProps
|
|
87
|
+
*/
|
|
88
|
+
dtSize?: number;
|
|
89
|
+
}
|
|
90
|
+
export declare const Glitch: import("vue").DefineComponent<GlitchProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<GlitchProps>, {}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allows to use and extend the state of the core package.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @return {*}
|
|
6
|
+
*/
|
|
7
|
+
export declare function useCore(): {
|
|
8
|
+
state: import("@tresjs/core").TresState;
|
|
9
|
+
setState: (key: string, value: any) => void;
|
|
10
|
+
extend: (objects: any) => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Camera } from '@tresjs/core';
|
|
2
|
+
import { Scene } from 'three';
|
|
3
|
+
export interface EffectComposerProps {
|
|
4
|
+
/**
|
|
5
|
+
* Whether the effect composer is enabled.
|
|
6
|
+
* @default true
|
|
7
|
+
* @type {boolean}
|
|
8
|
+
* @memberof EffectComposerProps
|
|
9
|
+
* @name enabled
|
|
10
|
+
*
|
|
11
|
+
**/
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The children of the effect composer.
|
|
15
|
+
* @default []
|
|
16
|
+
* @type {Array}
|
|
17
|
+
* @memberof EffectComposerProps
|
|
18
|
+
* @name children
|
|
19
|
+
*
|
|
20
|
+
**/
|
|
21
|
+
children?: Array<any>;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the depth buffer is enabled.
|
|
24
|
+
* @default true
|
|
25
|
+
* @type {boolean}
|
|
26
|
+
* @memberof EffectComposerProps
|
|
27
|
+
* @name depthBuffer
|
|
28
|
+
*
|
|
29
|
+
**/
|
|
30
|
+
depthBuffer?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @default false
|
|
34
|
+
* @type {boolean}
|
|
35
|
+
* @memberof EffectComposerProps
|
|
36
|
+
* @name dissableNormalPass
|
|
37
|
+
*
|
|
38
|
+
**/
|
|
39
|
+
dissableNormalPass?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* Stencil buffer.
|
|
43
|
+
*
|
|
44
|
+
* @type {boolean}
|
|
45
|
+
* @memberof EffectComposerProps
|
|
46
|
+
* @name stencilBuffer
|
|
47
|
+
*
|
|
48
|
+
**/
|
|
49
|
+
stencilBuffer?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* Whether the effect composer should clear the buffers before rendering.
|
|
53
|
+
*
|
|
54
|
+
* @type {boolean}
|
|
55
|
+
* @memberof EffectComposerProps
|
|
56
|
+
* @name autoClear
|
|
57
|
+
*
|
|
58
|
+
**/
|
|
59
|
+
autoClear?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* The resolution scale.
|
|
63
|
+
*
|
|
64
|
+
* @type {number}
|
|
65
|
+
* @memberof EffectComposerProps
|
|
66
|
+
* @name resolutionScale
|
|
67
|
+
*
|
|
68
|
+
**/
|
|
69
|
+
resolutionScale?: number;
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
* The multisampling.
|
|
73
|
+
*
|
|
74
|
+
* @type {number}
|
|
75
|
+
* @memberof EffectComposerProps
|
|
76
|
+
* @name multisampling
|
|
77
|
+
*
|
|
78
|
+
**/
|
|
79
|
+
multisampling?: number;
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* The frame buffer type.
|
|
83
|
+
*
|
|
84
|
+
* @type {number}
|
|
85
|
+
* @memberof EffectComposerProps
|
|
86
|
+
* @name frameBufferType
|
|
87
|
+
*
|
|
88
|
+
**/
|
|
89
|
+
frameBufferType?: number;
|
|
90
|
+
/**
|
|
91
|
+
*
|
|
92
|
+
* The render priority.
|
|
93
|
+
*
|
|
94
|
+
* @type {number}
|
|
95
|
+
* @memberof EffectComposerProps
|
|
96
|
+
* @name renderPriority
|
|
97
|
+
*
|
|
98
|
+
**/
|
|
99
|
+
renderPriority?: number;
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* A camera to use for rendering.
|
|
103
|
+
*
|
|
104
|
+
* @type {Camera}
|
|
105
|
+
* @memberof EffectComposerProps
|
|
106
|
+
* @name camera
|
|
107
|
+
*
|
|
108
|
+
**/
|
|
109
|
+
camera?: Camera;
|
|
110
|
+
/**
|
|
111
|
+
* A scene to use for rendering.
|
|
112
|
+
* @type {Scene}
|
|
113
|
+
* @memberof EffectComposerProps
|
|
114
|
+
* @name scene
|
|
115
|
+
*
|
|
116
|
+
**/
|
|
117
|
+
scene?: Scene;
|
|
118
|
+
}
|
|
119
|
+
export declare const EffectComposer: import("vue").DefineComponent<EffectComposerProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<EffectComposerProps>, {}>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* name: @tresjs/post-processing
|
|
3
|
+
* version: v0.1.0
|
|
4
|
+
* (c) 2023
|
|
5
|
+
* description: Post-processing library for Tres
|
|
6
|
+
* author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
|
|
7
|
+
*/
|
|
8
|
+
import { getCurrentInstance as L, onMounted as S, nextTick as H, getCurrentScope as N, onScopeDispose as O, unref as P, toRef as I, readonly as k, customRef as Q, ref as v, watch as y, watchEffect as b, computed as j, inject as w, defineComponent as g, toRefs as F, shallowRef as V, provide as _, toRaw as M } from "vue";
|
|
9
|
+
import { useTres as $, useRenderLoop as q } from "@tresjs/core";
|
|
10
|
+
import { HalfFloatType as J } from "three";
|
|
11
|
+
import { EffectComposer as K, RenderPass as U, NormalPass as X, DepthDownsamplingPass as Y, EffectPass as R, BloomEffect as Z, GlitchEffect as ee } from "postprocessing";
|
|
12
|
+
function x(e) {
|
|
13
|
+
return N() ? (O(e), !0) : !1;
|
|
14
|
+
}
|
|
15
|
+
function A(e) {
|
|
16
|
+
return typeof e == "function" ? e() : P(e);
|
|
17
|
+
}
|
|
18
|
+
const te = typeof window < "u", B = () => {
|
|
19
|
+
};
|
|
20
|
+
function ne(...e) {
|
|
21
|
+
if (e.length !== 1)
|
|
22
|
+
return I(...e);
|
|
23
|
+
const t = e[0];
|
|
24
|
+
return typeof t == "function" ? k(Q(() => ({ get: t, set: B }))) : v(t);
|
|
25
|
+
}
|
|
26
|
+
function ae(e, t = !0) {
|
|
27
|
+
L() ? S(e) : t ? e() : H(e);
|
|
28
|
+
}
|
|
29
|
+
function re(e) {
|
|
30
|
+
var t;
|
|
31
|
+
const n = A(e);
|
|
32
|
+
return (t = n == null ? void 0 : n.$el) != null ? t : n;
|
|
33
|
+
}
|
|
34
|
+
const E = te ? window : void 0;
|
|
35
|
+
function oe(...e) {
|
|
36
|
+
let t, n, r, a;
|
|
37
|
+
if (typeof e[0] == "string" || Array.isArray(e[0]) ? ([n, r, a] = e, t = E) : [t, n, r, a] = e, !t)
|
|
38
|
+
return B;
|
|
39
|
+
Array.isArray(n) || (n = [n]), Array.isArray(r) || (r = [r]);
|
|
40
|
+
const o = [], l = () => {
|
|
41
|
+
o.forEach((c) => c()), o.length = 0;
|
|
42
|
+
}, s = (c, m, d, f) => (c.addEventListener(m, d, f), () => c.removeEventListener(m, d, f)), u = y(
|
|
43
|
+
() => [re(t), A(a)],
|
|
44
|
+
([c, m]) => {
|
|
45
|
+
l(), c && o.push(
|
|
46
|
+
...n.flatMap((d) => r.map((f) => s(c, d, f, m)))
|
|
47
|
+
);
|
|
48
|
+
},
|
|
49
|
+
{ immediate: !0, flush: "post" }
|
|
50
|
+
), i = () => {
|
|
51
|
+
u(), l();
|
|
52
|
+
};
|
|
53
|
+
return x(i), i;
|
|
54
|
+
}
|
|
55
|
+
function ie() {
|
|
56
|
+
const e = v(!1);
|
|
57
|
+
return L() && S(() => {
|
|
58
|
+
e.value = !0;
|
|
59
|
+
}), e;
|
|
60
|
+
}
|
|
61
|
+
function se(e) {
|
|
62
|
+
const t = ie();
|
|
63
|
+
return j(() => (t.value, !!e()));
|
|
64
|
+
}
|
|
65
|
+
function ue(e, t = {}) {
|
|
66
|
+
const { window: n = E } = t, r = se(() => n && "matchMedia" in n && typeof n.matchMedia == "function");
|
|
67
|
+
let a;
|
|
68
|
+
const o = v(!1), l = () => {
|
|
69
|
+
a && ("removeEventListener" in a ? a.removeEventListener("change", s) : a.removeListener(s));
|
|
70
|
+
}, s = () => {
|
|
71
|
+
r.value && (l(), a = n.matchMedia(ne(e).value), o.value = !!(a != null && a.matches), a && ("addEventListener" in a ? a.addEventListener("change", s) : a.addListener(s)));
|
|
72
|
+
};
|
|
73
|
+
return b(s), x(() => l()), o;
|
|
74
|
+
}
|
|
75
|
+
function le(e = {}) {
|
|
76
|
+
const {
|
|
77
|
+
window: t = E,
|
|
78
|
+
initialWidth: n = 1 / 0,
|
|
79
|
+
initialHeight: r = 1 / 0,
|
|
80
|
+
listenOrientation: a = !0,
|
|
81
|
+
includeScrollbar: o = !0
|
|
82
|
+
} = e, l = v(n), s = v(r), u = () => {
|
|
83
|
+
t && (o ? (l.value = t.innerWidth, s.value = t.innerHeight) : (l.value = t.document.documentElement.clientWidth, s.value = t.document.documentElement.clientHeight));
|
|
84
|
+
};
|
|
85
|
+
if (u(), ae(u), oe("resize", u, { passive: !0 }), a) {
|
|
86
|
+
const i = ue("(orientation: portrait)");
|
|
87
|
+
y(i, () => u());
|
|
88
|
+
}
|
|
89
|
+
return { width: l, height: s };
|
|
90
|
+
}
|
|
91
|
+
let p;
|
|
92
|
+
function ce() {
|
|
93
|
+
if (p !== void 0)
|
|
94
|
+
return p;
|
|
95
|
+
try {
|
|
96
|
+
var e;
|
|
97
|
+
let t;
|
|
98
|
+
const n = document.createElement("canvas");
|
|
99
|
+
return p = !!(window.WebGL2RenderingContext && (t = n.getContext("webgl2"))), t && ((e = t.getExtension("WEBGL_lose_context")) === null || e === void 0 || e.loseContext()), p;
|
|
100
|
+
} catch {
|
|
101
|
+
return p = !1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function C() {
|
|
105
|
+
const { state: e, setState: t } = w("useTres", $()), n = w("extend") || (() => {
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
state: e,
|
|
109
|
+
setState: t,
|
|
110
|
+
extend: n
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const pe = g({
|
|
114
|
+
name: "EffectComposer",
|
|
115
|
+
props: [
|
|
116
|
+
"enabled",
|
|
117
|
+
"children",
|
|
118
|
+
"depthBuffer",
|
|
119
|
+
"dissableNormalPass",
|
|
120
|
+
"stencilBuffer",
|
|
121
|
+
"autoClear",
|
|
122
|
+
"resolutionScale",
|
|
123
|
+
"multisampling",
|
|
124
|
+
"frameBufferType",
|
|
125
|
+
"renderPriority",
|
|
126
|
+
"camera",
|
|
127
|
+
"scene"
|
|
128
|
+
],
|
|
129
|
+
setup(e, { slots: t }) {
|
|
130
|
+
const { state: n } = C(), {
|
|
131
|
+
enabled: r = !0,
|
|
132
|
+
renderPriority: a = 1,
|
|
133
|
+
autoClear: o = !0,
|
|
134
|
+
multisampling: l = 8,
|
|
135
|
+
frameBufferType: s = J,
|
|
136
|
+
resolutionScale: u
|
|
137
|
+
} = F(e), i = V(null), c = e.scene || n.scene, m = e.camera || n.camera;
|
|
138
|
+
let d = null, f = null;
|
|
139
|
+
const W = ce();
|
|
140
|
+
_("effectComposer", i);
|
|
141
|
+
const { width: G, height: T } = le();
|
|
142
|
+
function z() {
|
|
143
|
+
i.value && (f = new X(c, m), f.enabled = !1, i.value.addPass(f), u.value !== void 0 && W && (d = new Y({
|
|
144
|
+
normalBuffer: f.texture,
|
|
145
|
+
resolutionScale: u == null ? void 0 : u.value
|
|
146
|
+
}), d.enabled = !1, i.value.addPass(d)));
|
|
147
|
+
}
|
|
148
|
+
b(() => {
|
|
149
|
+
n.renderer && n.scene && n.camera && (n.renderer.setSize(G.value, T.value), n.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)), i.value = new K(n.renderer), i.value.addPass(new U(c, m)), e.dissableNormalPass || z());
|
|
150
|
+
}), y(
|
|
151
|
+
() => e.enabled,
|
|
152
|
+
(h) => {
|
|
153
|
+
i.value && (i.value.enabled = h);
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
const { onLoop: D } = q();
|
|
157
|
+
return D(() => {
|
|
158
|
+
i.value && i.value.render();
|
|
159
|
+
}), () => {
|
|
160
|
+
var h;
|
|
161
|
+
return (h = t.default) == null ? void 0 : h.call(t);
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}), he = g({
|
|
165
|
+
name: "Bloom",
|
|
166
|
+
props: [
|
|
167
|
+
"intensity",
|
|
168
|
+
"blurPass",
|
|
169
|
+
"width",
|
|
170
|
+
"height",
|
|
171
|
+
"kernelSize",
|
|
172
|
+
"luminanceThreshold",
|
|
173
|
+
"luminanceSmoothing"
|
|
174
|
+
],
|
|
175
|
+
async setup(e, { expose: t }) {
|
|
176
|
+
const { state: n } = C(), r = w("effectComposer"), a = v(null);
|
|
177
|
+
return t({ getPass: () => a.value }), b(() => {
|
|
178
|
+
var o;
|
|
179
|
+
n.camera && r && r.value && (a.value = new R(P(n.camera), new Z(e)), (o = r == null ? void 0 : r.value) == null || o.addPass(M(a.value)));
|
|
180
|
+
}), () => {
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}), we = g({
|
|
184
|
+
name: "Glitch",
|
|
185
|
+
props: [
|
|
186
|
+
"delay",
|
|
187
|
+
"duration",
|
|
188
|
+
"strength",
|
|
189
|
+
"mode",
|
|
190
|
+
"active",
|
|
191
|
+
"ratio",
|
|
192
|
+
"columns",
|
|
193
|
+
"chromaticAberrationOffset",
|
|
194
|
+
"peturbationMap",
|
|
195
|
+
"dtSize"
|
|
196
|
+
],
|
|
197
|
+
async setup(e, { expose: t }) {
|
|
198
|
+
const { state: n } = C(), r = w("effectComposer"), a = v(null);
|
|
199
|
+
return t({ getPass: () => a.value }), b(() => {
|
|
200
|
+
var o;
|
|
201
|
+
n.camera && r && r.value && (a.value = new R(P(n.camera), new ee(e)), (o = r == null ? void 0 : r.value) == null || o.addPass(M(a.value)));
|
|
202
|
+
}), y(
|
|
203
|
+
() => e.active,
|
|
204
|
+
(o) => {
|
|
205
|
+
a.value && (a.value.enabled = o);
|
|
206
|
+
}
|
|
207
|
+
), () => {
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
export {
|
|
212
|
+
he as Bloom,
|
|
213
|
+
pe as EffectComposer,
|
|
214
|
+
we as Glitch
|
|
215
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* name: @tresjs/post-processing
|
|
3
|
+
* version: v0.1.0
|
|
4
|
+
* (c) 2023
|
|
5
|
+
* description: Post-processing library for Tres
|
|
6
|
+
* author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
|
|
7
|
+
*/
|
|
8
|
+
(function(c,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("@tresjs/core"),require("three"),require("postprocessing")):typeof define=="function"&&define.amd?define(["exports","vue","@tresjs/core","three","postprocessing"],t):(c=typeof globalThis<"u"?globalThis:c||self,t(c["tres-postprocessing"]={},c.Vue,c.TresjsCore,c.Three,c.Postprocessing))})(this,function(c,t,C,S,h){"use strict";function b(e){return t.getCurrentScope()?(t.onScopeDispose(e),!0):!1}function g(e){return typeof e=="function"?e():t.unref(e)}const M=typeof window<"u",L=()=>{};function R(...e){if(e.length!==1)return t.toRef(...e);const n=e[0];return typeof n=="function"?t.readonly(t.customRef(()=>({get:n,set:L}))):t.ref(n)}function T(e,n=!0){t.getCurrentInstance()?t.onMounted(e):n?e():t.nextTick(e)}function B(e){var n;const r=g(e);return(n=r==null?void 0:r.$el)!=null?n:r}const E=M?window:void 0;function A(...e){let n,r,i,a;if(typeof e[0]=="string"||Array.isArray(e[0])?([r,i,a]=e,n=E):[n,r,i,a]=e,!n)return L;Array.isArray(r)||(r=[r]),Array.isArray(i)||(i=[i]);const o=[],u=()=>{o.forEach(d=>d()),o.length=0},l=(d,w,p,m)=>(d.addEventListener(w,p,m),()=>d.removeEventListener(w,p,m)),f=t.watch(()=>[B(n),g(a)],([d,w])=>{u(),d&&o.push(...r.flatMap(p=>i.map(m=>l(d,p,m,w))))},{immediate:!0,flush:"post"}),s=()=>{f(),u()};return b(s),s}function j(){const e=t.ref(!1);return t.getCurrentInstance()&&t.onMounted(()=>{e.value=!0}),e}function x(e){const n=j();return t.computed(()=>(n.value,!!e()))}function G(e,n={}){const{window:r=E}=n,i=x(()=>r&&"matchMedia"in r&&typeof r.matchMedia=="function");let a;const o=t.ref(!1),u=()=>{a&&("removeEventListener"in a?a.removeEventListener("change",l):a.removeListener(l))},l=()=>{i.value&&(u(),a=r.matchMedia(R(e).value),o.value=!!(a!=null&&a.matches),a&&("addEventListener"in a?a.addEventListener("change",l):a.addListener(l)))};return t.watchEffect(l),b(()=>u()),o}function W(e={}){const{window:n=E,initialWidth:r=1/0,initialHeight:i=1/0,listenOrientation:a=!0,includeScrollbar:o=!0}=e,u=t.ref(r),l=t.ref(i),f=()=>{n&&(o?(u.value=n.innerWidth,l.value=n.innerHeight):(u.value=n.document.documentElement.clientWidth,l.value=n.document.documentElement.clientHeight))};if(f(),T(f),A("resize",f,{passive:!0}),a){const s=G("(orientation: portrait)");t.watch(s,()=>f())}return{width:u,height:l}}let y;function z(){if(y!==void 0)return y;try{var e;let n;const r=document.createElement("canvas");return y=!!(window.WebGL2RenderingContext&&(n=r.getContext("webgl2"))),n&&((e=n.getExtension("WEBGL_lose_context"))===null||e===void 0||e.loseContext()),y}catch{return y=!1}}function P(){const{state:e,setState:n}=t.inject("useTres",C.useTres()),r=t.inject("extend")||(()=>{});return{state:e,setState:n,extend:r}}const O=t.defineComponent({name:"EffectComposer",props:["enabled","children","depthBuffer","dissableNormalPass","stencilBuffer","autoClear","resolutionScale","multisampling","frameBufferType","renderPriority","camera","scene"],setup(e,{slots:n}){const{state:r}=P(),{enabled:i=!0,renderPriority:a=1,autoClear:o=!0,multisampling:u=8,frameBufferType:l=S.HalfFloatType,resolutionScale:f}=t.toRefs(e),s=t.shallowRef(null),d=e.scene||r.scene,w=e.camera||r.camera;let p=null,m=null;const H=z();t.provide("effectComposer",s);const{width:I,height:N}=W();function k(){s.value&&(m=new h.NormalPass(d,w),m.enabled=!1,s.value.addPass(m),f.value!==void 0&&H&&(p=new h.DepthDownsamplingPass({normalBuffer:m.texture,resolutionScale:f==null?void 0:f.value}),p.enabled=!1,s.value.addPass(p)))}t.watchEffect(()=>{r.renderer&&r.scene&&r.camera&&(r.renderer.setSize(I.value,N.value),r.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),s.value=new h.EffectComposer(r.renderer),s.value.addPass(new h.RenderPass(d,w)),e.dissableNormalPass||k())}),t.watch(()=>e.enabled,v=>{s.value&&(s.value.enabled=v)});const{onLoop:Q}=C.useRenderLoop();return Q(()=>{s.value&&s.value.render()}),()=>{var v;return(v=n.default)==null?void 0:v.call(n)}}}),q=t.defineComponent({name:"Bloom",props:["intensity","blurPass","width","height","kernelSize","luminanceThreshold","luminanceSmoothing"],async setup(e,{expose:n}){const{state:r}=P(),i=t.inject("effectComposer"),a=t.ref(null);return n({getPass:()=>a.value}),t.watchEffect(()=>{var o;r.camera&&i&&i.value&&(a.value=new h.EffectPass(t.unref(r.camera),new h.BloomEffect(e)),(o=i==null?void 0:i.value)==null||o.addPass(t.toRaw(a.value)))}),()=>{}}}),D=t.defineComponent({name:"Glitch",props:["delay","duration","strength","mode","active","ratio","columns","chromaticAberrationOffset","peturbationMap","dtSize"],async setup(e,{expose:n}){const{state:r}=P(),i=t.inject("effectComposer"),a=t.ref(null);return n({getPass:()=>a.value}),t.watchEffect(()=>{var o;r.camera&&i&&i.value&&(a.value=new h.EffectPass(t.unref(r.camera),new h.GlitchEffect(e)),(o=i==null?void 0:i.value)==null||o.addPass(t.toRaw(a.value)))}),t.watch(()=>e.active,o=>{a.value&&(a.value.enabled=o)}),()=>{}}});c.Bloom=q,c.EffectComposer=O,c.Glitch=D,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tresjs/post-processing",
|
|
3
|
+
"description": "Post-processing library for TresJS",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "./dist/tres-postprocessing.umd.cjs",
|
|
12
|
+
"module": "./dist/tres-postprocessing.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/tres-postprocessing.js",
|
|
17
|
+
"require": "./dist/tres-postprocessing.umd.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./styles": "./dist/style.css",
|
|
20
|
+
"./*": "./dist/tres-postprocessing.js"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"dev": "vite",
|
|
27
|
+
"playground": "cd playground && nr dev",
|
|
28
|
+
"build": "vite build",
|
|
29
|
+
"preview": "vite preview",
|
|
30
|
+
"release": "release-it",
|
|
31
|
+
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue",
|
|
32
|
+
"docs:dev": "vitepress dev docs",
|
|
33
|
+
"docs:build": "vitepress build docs",
|
|
34
|
+
"docs:preview": "vitepress preview docs"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@tresjs/core": "2.0.0-beta.8",
|
|
38
|
+
"three": "latest",
|
|
39
|
+
"vue": "^3.2.47"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@vueuse/core": "^10.0.2",
|
|
43
|
+
"postprocessing": "^6.30.2",
|
|
44
|
+
"three": "^0.151.3",
|
|
45
|
+
"three-stdlib": "^2.21.8",
|
|
46
|
+
"vue": "^3.2.47"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@alvarosabu/prettier-config": "^1.3.0",
|
|
50
|
+
"@release-it/conventional-changelog": "^5.1.1",
|
|
51
|
+
"@tresjs/core": "2.0.0-beta.9",
|
|
52
|
+
"@types/three": "^0.150.1",
|
|
53
|
+
"@vitejs/plugin-vue": "^4.1.0",
|
|
54
|
+
"kolorist": "^1.7.0",
|
|
55
|
+
"pathe": "^1.1.0",
|
|
56
|
+
"prettier": "^2.8.7",
|
|
57
|
+
"release-it": "^15.10.1",
|
|
58
|
+
"rollup-plugin-analyzer": "^4.0.0",
|
|
59
|
+
"rollup-plugin-visualizer": "^5.9.0",
|
|
60
|
+
"typescript": "^5.0.4",
|
|
61
|
+
"unocss": "^0.51.4",
|
|
62
|
+
"vite": "^4.2.1",
|
|
63
|
+
"vite-plugin-banner": "^0.7.0",
|
|
64
|
+
"vite-plugin-dts": "2.3.0",
|
|
65
|
+
"vitepress": "1.0.0-alpha.72",
|
|
66
|
+
"vue-tsc": "^1.2.0"
|
|
67
|
+
}
|
|
68
|
+
}
|