@tresjs/post-processing 0.4.0 → 0.6.0-next.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 +5 -12
- package/dist/core/EffectComposer.vue.d.ts +51 -100
- package/dist/core/composables/effect.d.ts +6 -0
- package/dist/core/effects/Bloom.vue.d.ts +37 -55
- package/dist/core/effects/DepthOfField.vue.d.ts +45 -0
- package/dist/core/effects/Glitch.vue.d.ts +17 -95
- package/dist/core/effects/Noise.vue.d.ts +39 -0
- package/dist/core/effects/Outline.vue.d.ts +32 -125
- package/dist/core/effects/Pixelation.vue.d.ts +21 -0
- package/dist/core/injectionKeys.d.ts +2 -2
- package/dist/index.d.ts +4 -1
- package/dist/tres-postprocessing.js +247 -150
- package/dist/tres-postprocessing.umd.cjs +2 -2
- package/dist/util/object.d.ts +55 -0
- package/dist/util/prop.d.ts +40 -0
- package/package.json +23 -21
|
@@ -1,15 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/post-processing
|
|
3
|
-
* version: v0.
|
|
3
|
+
* version: v0.6.0-next.0
|
|
4
4
|
* (c) 2023
|
|
5
5
|
* description: Post-processing library for TresJS
|
|
6
6
|
* author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { HalfFloatType as
|
|
12
|
-
const
|
|
8
|
+
import { inject as W, shallowRef as _, watchEffect as v, onUnmounted as A, watch as w, defineComponent as f, computed as M, provide as j, renderSlot as X } from "vue";
|
|
9
|
+
import { EffectPass as Y, BloomEffect as y, GlitchEffect as b, GlitchMode as H, OutlineEffect as P, PixelationEffect as F, DepthOfFieldEffect as R, BlendFunction as I, NoiseEffect as O, EffectComposer as z, RenderPass as U, NormalPass as K, DepthDownsamplingPass as q } from "postprocessing";
|
|
10
|
+
import { useTresContext as S, normalizeColor as C, useRenderLoop as J } from "@tresjs/core";
|
|
11
|
+
import { HalfFloatType as D } from "three";
|
|
12
|
+
const N = Symbol(), p = (a) => {
|
|
13
|
+
const t = W(N), e = _(null), n = _(null), { scene: o, camera: l } = S();
|
|
14
|
+
v(() => {
|
|
15
|
+
!l.value || !(n != null && n.value) || (n.value.mainCamera = l.value);
|
|
16
|
+
});
|
|
17
|
+
let s = () => {
|
|
18
|
+
};
|
|
19
|
+
return s = v(() => {
|
|
20
|
+
!l.value || !(t != null && t.value) || !o.value || (s(), !n.value && (n.value = a(), e.value = new Y(l.value, n.value), t.value.addPass(e.value)));
|
|
21
|
+
}), A(() => {
|
|
22
|
+
var r, i, d;
|
|
23
|
+
e.value && ((r = t == null ? void 0 : t.value) == null || r.removePass(e.value)), (i = n.value) == null || i.dispose(), (d = e.value) == null || d.dispose();
|
|
24
|
+
}), {
|
|
25
|
+
pass: e,
|
|
26
|
+
effect: n
|
|
27
|
+
};
|
|
28
|
+
}, G = /([^[.\]])+/g, Q = (a, t) => {
|
|
29
|
+
if (!t)
|
|
30
|
+
return;
|
|
31
|
+
const e = Array.isArray(t) ? t : t.match(G);
|
|
32
|
+
return e == null ? void 0 : e.reduce((n, o) => n && n[o], a);
|
|
33
|
+
}, T = (a, t, e) => {
|
|
34
|
+
const n = Array.isArray(t) ? t : t.match(G);
|
|
35
|
+
n && n.reduce((o, l, s) => (o[l] === void 0 && (o[l] = {}), s === n.length - 1 && (o[l] = e), o[l]), a);
|
|
36
|
+
}, V = (a, t) => {
|
|
37
|
+
const e = { ...a };
|
|
38
|
+
return t.forEach((n) => delete e[n]), e;
|
|
39
|
+
}, L = (a, t, e, n, o = {}) => w(
|
|
40
|
+
a,
|
|
41
|
+
(l) => {
|
|
42
|
+
var s;
|
|
43
|
+
if (t.value)
|
|
44
|
+
if (l === void 0) {
|
|
45
|
+
const r = n();
|
|
46
|
+
T(t.value, e, Q(r, e)), (s = r.dispose) == null || s.call(r);
|
|
47
|
+
} else
|
|
48
|
+
T(t.value, e, a());
|
|
49
|
+
},
|
|
50
|
+
o
|
|
51
|
+
), E = (a, t, e) => a.map(([n, o]) => L(
|
|
52
|
+
n,
|
|
53
|
+
t,
|
|
54
|
+
o,
|
|
55
|
+
e
|
|
56
|
+
)), B = (a, t, e) => Object.keys(a).map((n) => L(
|
|
57
|
+
() => a[n],
|
|
58
|
+
t,
|
|
59
|
+
n,
|
|
60
|
+
e
|
|
61
|
+
)), oe = /* @__PURE__ */ f({
|
|
13
62
|
__name: "Bloom",
|
|
14
63
|
props: {
|
|
15
64
|
blendFunction: {},
|
|
@@ -17,26 +66,23 @@ const x = Symbol(), ee = /* @__PURE__ */ _({
|
|
|
17
66
|
kernelSize: {},
|
|
18
67
|
luminanceThreshold: {},
|
|
19
68
|
luminanceSmoothing: {},
|
|
20
|
-
mipmapBlur: { type: Boolean }
|
|
69
|
+
mipmapBlur: { type: Boolean, default: void 0 }
|
|
21
70
|
},
|
|
22
|
-
setup(
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var a, d, v;
|
|
36
|
-
t.value && ((a = n == null ? void 0 : n.value) == null || a.removePass(t.value)), (d = e.value) == null || d.dispose(), (v = t.value) == null || v.dispose();
|
|
37
|
-
}), (a, d) => null;
|
|
71
|
+
setup(a, { expose: t }) {
|
|
72
|
+
const e = a, { pass: n, effect: o } = p(() => new y(e));
|
|
73
|
+
return t({ pass: n, effect: o }), E(
|
|
74
|
+
[
|
|
75
|
+
// blendFunction is not updated, because it has no setter in BloomEffect
|
|
76
|
+
[() => e.intensity, "intensity"],
|
|
77
|
+
[() => e.kernelSize, "kernelSize"],
|
|
78
|
+
[() => e.luminanceSmoothing, "luminanceMaterial.smoothing"],
|
|
79
|
+
[() => e.luminanceThreshold, "luminanceMaterial.threshold"]
|
|
80
|
+
],
|
|
81
|
+
o,
|
|
82
|
+
() => new y()
|
|
83
|
+
), (l, s) => null;
|
|
38
84
|
}
|
|
39
|
-
}), le = /* @__PURE__ */
|
|
85
|
+
}), le = /* @__PURE__ */ f({
|
|
40
86
|
__name: "Glitch",
|
|
41
87
|
props: {
|
|
42
88
|
blendFunction: {},
|
|
@@ -51,29 +97,28 @@ const x = Symbol(), ee = /* @__PURE__ */ _({
|
|
|
51
97
|
perturbationMap: {},
|
|
52
98
|
dtSize: {}
|
|
53
99
|
},
|
|
54
|
-
setup(
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}), (a, d) => null;
|
|
100
|
+
setup(a, { expose: t }) {
|
|
101
|
+
const e = a, { pass: n, effect: o } = p(() => new b(e));
|
|
102
|
+
return t({ pass: n, effect: o }), v(() => {
|
|
103
|
+
const l = () => {
|
|
104
|
+
if (e.mode !== void 0)
|
|
105
|
+
return e.active === !1 ? H.DISABLED : e.mode;
|
|
106
|
+
const s = new b(), r = s.mode;
|
|
107
|
+
return s.dispose(), r;
|
|
108
|
+
};
|
|
109
|
+
o.value && (o.value.mode = l());
|
|
110
|
+
}), B(
|
|
111
|
+
V(e, ["active", "mode", "blendFunction"]),
|
|
112
|
+
o,
|
|
113
|
+
() => new b()
|
|
114
|
+
), (l, s) => null;
|
|
70
115
|
}
|
|
71
|
-
}), ae = /* @__PURE__ */
|
|
116
|
+
}), ae = /* @__PURE__ */ f({
|
|
72
117
|
__name: "Outline",
|
|
73
118
|
props: {
|
|
74
119
|
outlinedObjects: {},
|
|
75
|
-
blur: { type: Boolean },
|
|
76
|
-
xRay: { type: Boolean },
|
|
120
|
+
blur: { type: Boolean, default: void 0 },
|
|
121
|
+
xRay: { type: Boolean, default: void 0 },
|
|
77
122
|
kernelSize: {},
|
|
78
123
|
pulseSpeed: {},
|
|
79
124
|
resolutionX: {},
|
|
@@ -87,91 +132,134 @@ const x = Symbol(), ee = /* @__PURE__ */ _({
|
|
|
87
132
|
hiddenEdgeColor: {},
|
|
88
133
|
visibleEdgeColor: {}
|
|
89
134
|
},
|
|
90
|
-
setup(
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
} = l;
|
|
110
|
-
return {
|
|
111
|
-
blur: u,
|
|
112
|
-
xRay: c,
|
|
113
|
-
kernelSize: p,
|
|
114
|
-
pulseSpeed: r,
|
|
115
|
-
resolutionX: m,
|
|
116
|
-
resolutionY: S,
|
|
117
|
-
patternScale: B,
|
|
118
|
-
edgeStrength: C,
|
|
119
|
-
blendFunction: E,
|
|
120
|
-
multisampling: y,
|
|
121
|
-
patternTexture: N,
|
|
122
|
-
resolutionScale: D,
|
|
123
|
-
hiddenEdgeColor: i($),
|
|
124
|
-
visibleEdgeColor: i(W)
|
|
125
|
-
};
|
|
126
|
-
}), { camera: a, scene: d } = P();
|
|
127
|
-
let v;
|
|
128
|
-
return v = h(() => {
|
|
129
|
-
!a.value || !(n != null && n.value) || !d.value || (v == null || v(), !e.value && (e.value = new A(d.value, a.value, s.value), t.value = new M(a.value, e.value), n.value.addPass(t.value)));
|
|
130
|
-
}), F(
|
|
131
|
-
[() => l.outlinedObjects, e],
|
|
135
|
+
setup(a, { expose: t }) {
|
|
136
|
+
const e = a, n = (c) => c !== void 0 ? C(c).getHex() : void 0, { camera: o, scene: l } = S(), s = {
|
|
137
|
+
blur: e.blur,
|
|
138
|
+
xRay: e.xRay,
|
|
139
|
+
kernelSize: e.kernelSize,
|
|
140
|
+
pulseSpeed: e.pulseSpeed,
|
|
141
|
+
resolutionX: e.resolutionX,
|
|
142
|
+
resolutionY: e.resolutionY,
|
|
143
|
+
patternScale: e.patternScale,
|
|
144
|
+
edgeStrength: e.edgeStrength,
|
|
145
|
+
blendFunction: e.blendFunction,
|
|
146
|
+
multisampling: e.multisampling,
|
|
147
|
+
patternTexture: e.patternTexture,
|
|
148
|
+
resolutionScale: e.resolutionScale,
|
|
149
|
+
hiddenEdgeColor: n(e.hiddenEdgeColor),
|
|
150
|
+
visibleEdgeColor: n(e.visibleEdgeColor)
|
|
151
|
+
}, { pass: r, effect: i } = p(() => new P(l.value, o.value, s));
|
|
152
|
+
t({ pass: r, effect: i }), w(
|
|
153
|
+
[() => e.outlinedObjects, i],
|
|
132
154
|
// watchEffect is intentionally not used here as it would result in an endless loop
|
|
133
155
|
() => {
|
|
134
|
-
var
|
|
135
|
-
(
|
|
156
|
+
var c;
|
|
157
|
+
(c = i.value) == null || c.selection.set(e.outlinedObjects || []);
|
|
136
158
|
},
|
|
137
159
|
{
|
|
138
160
|
immediate: !0
|
|
139
161
|
}
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
);
|
|
163
|
+
const d = M(() => ({
|
|
164
|
+
hiddenEdgeColor: e.hiddenEdgeColor ? C(e.hiddenEdgeColor) : void 0,
|
|
165
|
+
visibleEdgeColor: e.visibleEdgeColor ? C(e.visibleEdgeColor) : void 0
|
|
166
|
+
}));
|
|
167
|
+
return E(
|
|
168
|
+
[
|
|
169
|
+
/* some properties are not updated because of different reasons:
|
|
170
|
+
resolutionX - has no setter in OutlineEffect
|
|
171
|
+
resolutionY - has no setter in OutlineEffect
|
|
172
|
+
blendFunction - has no setter in OutlineEffect
|
|
173
|
+
patternTexture - different type in constructor and in setter
|
|
174
|
+
resolutionScale - has no setter in OutlineEffect
|
|
175
|
+
*/
|
|
176
|
+
[() => e.blur, "blur"],
|
|
177
|
+
[() => e.xRay, "xRay"],
|
|
178
|
+
[() => e.pulseSpeed, "pulseSpeed"],
|
|
179
|
+
[() => e.kernelSize, "kernelSize"],
|
|
180
|
+
[() => e.edgeStrength, "edgeStrength"],
|
|
181
|
+
[() => e.patternScale, "patternScale"],
|
|
182
|
+
[() => e.multisampling, "multisampling"],
|
|
183
|
+
[() => d.value.hiddenEdgeColor, "hiddenEdgeColor"],
|
|
184
|
+
[() => d.value.visibleEdgeColor, "visibleEdgeColor"]
|
|
185
|
+
],
|
|
186
|
+
i,
|
|
187
|
+
() => new P()
|
|
188
|
+
), (c, x) => null;
|
|
189
|
+
}
|
|
190
|
+
}), se = /* @__PURE__ */ f({
|
|
191
|
+
__name: "Pixelation",
|
|
192
|
+
props: {
|
|
193
|
+
granularity: {}
|
|
194
|
+
},
|
|
195
|
+
setup(a, { expose: t }) {
|
|
196
|
+
const e = a, { pass: n, effect: o } = p(() => new F(e.granularity));
|
|
197
|
+
return t({ pass: n, effect: o }), B(
|
|
198
|
+
e,
|
|
199
|
+
o,
|
|
200
|
+
() => new F()
|
|
201
|
+
), (l, s) => null;
|
|
202
|
+
}
|
|
203
|
+
}), re = /* @__PURE__ */ f({
|
|
204
|
+
__name: "DepthOfField",
|
|
205
|
+
props: {
|
|
206
|
+
blendFunction: {},
|
|
207
|
+
worldFocusDistance: {},
|
|
208
|
+
worldFocusRange: {},
|
|
209
|
+
focusDistance: {},
|
|
210
|
+
focusRange: {},
|
|
211
|
+
bokehScale: {},
|
|
212
|
+
resolutionScale: {},
|
|
213
|
+
resolutionX: {},
|
|
214
|
+
resolutionY: {}
|
|
215
|
+
},
|
|
216
|
+
setup(a, { expose: t }) {
|
|
217
|
+
const e = a, { camera: n } = S(), { pass: o, effect: l } = p(() => new R(n.value, e));
|
|
218
|
+
return t({ pass: o, effect: l }), E(
|
|
219
|
+
[
|
|
220
|
+
// blendFunction is not updated, because it has no setter in BloomEffect
|
|
221
|
+
[() => e.worldFocusDistance, "circleOfConfusionMaterial.worldFocusDistance"],
|
|
222
|
+
[() => e.focusDistance, "circleOfConfusionMaterial.focusDistance"],
|
|
223
|
+
[() => e.worldFocusRange, "circleOfConfusionMaterial.worldFocusRange"],
|
|
224
|
+
[() => e.focusRange, "circleOfConfusionMaterial.focusRange"],
|
|
225
|
+
[() => e.bokehScale, "bokehScale"],
|
|
226
|
+
[() => e.resolutionScale, "blurPass.resolution.scale"],
|
|
227
|
+
[() => e.resolutionX, "resolution.width"],
|
|
228
|
+
[() => e.resolutionY, "resolution.height"]
|
|
229
|
+
],
|
|
230
|
+
l,
|
|
231
|
+
() => new R()
|
|
232
|
+
), (s, r) => null;
|
|
233
|
+
}
|
|
234
|
+
}), ie = /* @__PURE__ */ f({
|
|
235
|
+
__name: "Noise",
|
|
236
|
+
props: {
|
|
237
|
+
premultiply: { type: Boolean, default: !1 },
|
|
238
|
+
blendFunction: { default: I.SCREEN }
|
|
239
|
+
},
|
|
240
|
+
setup(a, { expose: t }) {
|
|
241
|
+
const e = a, { pass: n, effect: o } = p(() => new O(e));
|
|
242
|
+
return t({ pass: n, effect: o }), B(
|
|
243
|
+
e,
|
|
244
|
+
o,
|
|
245
|
+
() => new O()
|
|
246
|
+
), (l, s) => null;
|
|
159
247
|
}
|
|
160
248
|
});
|
|
161
|
-
let
|
|
162
|
-
function
|
|
163
|
-
var
|
|
164
|
-
if (
|
|
165
|
-
return
|
|
249
|
+
let m;
|
|
250
|
+
function k() {
|
|
251
|
+
var a;
|
|
252
|
+
if (m !== void 0)
|
|
253
|
+
return m;
|
|
166
254
|
try {
|
|
167
|
-
let
|
|
168
|
-
const
|
|
169
|
-
return
|
|
255
|
+
let t;
|
|
256
|
+
const e = document.createElement("canvas");
|
|
257
|
+
return m = !!(window.WebGL2RenderingContext && (t = e.getContext("webgl2"))), t && ((a = t.getExtension("WEBGL_lose_context")) == null || a.loseContext()), m;
|
|
170
258
|
} catch {
|
|
171
|
-
return
|
|
259
|
+
return m = !1;
|
|
172
260
|
}
|
|
173
261
|
}
|
|
174
|
-
const
|
|
262
|
+
const ue = /* @__PURE__ */ f({
|
|
175
263
|
__name: "EffectComposer",
|
|
176
264
|
props: {
|
|
177
265
|
enabled: { type: Boolean, default: !0 },
|
|
@@ -182,48 +270,57 @@ const te = /* @__PURE__ */ _({
|
|
|
182
270
|
resolutionScale: {},
|
|
183
271
|
autoClear: { type: Boolean, default: !0 },
|
|
184
272
|
multisampling: { default: 0 },
|
|
185
|
-
frameBufferType: { default:
|
|
273
|
+
frameBufferType: { default: D }
|
|
186
274
|
},
|
|
187
|
-
setup(
|
|
188
|
-
const
|
|
189
|
-
let
|
|
190
|
-
|
|
275
|
+
setup(a) {
|
|
276
|
+
const t = a, { scene: e, camera: n, renderer: o, sizes: l } = S(), s = _(null);
|
|
277
|
+
let r = null, i = null;
|
|
278
|
+
j(N, s);
|
|
191
279
|
const d = () => {
|
|
192
|
-
|
|
193
|
-
normalBuffer:
|
|
194
|
-
resolutionScale:
|
|
195
|
-
}),
|
|
280
|
+
s.value && (i = new K(e.value, n.value), i.enabled = !1, s.value.addPass(i), t.resolutionScale !== void 0 && k() && (r = new q({
|
|
281
|
+
normalBuffer: i.texture,
|
|
282
|
+
resolutionScale: t.resolutionScale
|
|
283
|
+
}), r.enabled = !1, s.value.addPass(r)));
|
|
196
284
|
};
|
|
197
|
-
|
|
198
|
-
|
|
285
|
+
v(() => {
|
|
286
|
+
s.value && l.width.value && l.height.value && s.value.setSize(l.width.value, l.height.value);
|
|
199
287
|
});
|
|
200
|
-
const
|
|
201
|
-
const
|
|
202
|
-
depthBuffer:
|
|
203
|
-
stencilBuffer:
|
|
204
|
-
multisampling:
|
|
205
|
-
frameBufferType:
|
|
288
|
+
const c = M(() => {
|
|
289
|
+
const u = new z(), g = {
|
|
290
|
+
depthBuffer: t.depthBuffer !== void 0 ? t.depthBuffer : u.inputBuffer.depthBuffer,
|
|
291
|
+
stencilBuffer: t.stencilBuffer !== void 0 ? t.stencilBuffer : u.inputBuffer.stencilBuffer,
|
|
292
|
+
multisampling: k() ? 0 : t.multisampling !== void 0 ? t.multisampling : u.multisampling,
|
|
293
|
+
frameBufferType: t.frameBufferType !== void 0 ? t.frameBufferType : D
|
|
206
294
|
};
|
|
207
|
-
return
|
|
208
|
-
}),
|
|
209
|
-
!
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
295
|
+
return u.dispose(), g;
|
|
296
|
+
}), x = () => {
|
|
297
|
+
!o.value && !e.value && !n.value || (s.value = new z(o.value, c.value), s.value.addPass(new U(e.value, n.value)), t.disableNormalPass || d());
|
|
298
|
+
};
|
|
299
|
+
let h = () => {
|
|
300
|
+
};
|
|
301
|
+
h = w([l.height, l.width], () => {
|
|
302
|
+
!l.height.value && !l.width.value || (v(x), h == null || h());
|
|
303
|
+
}, {
|
|
304
|
+
immediate: !0
|
|
305
|
+
});
|
|
306
|
+
const { onLoop: $ } = J();
|
|
307
|
+
return $(({ delta: u }) => {
|
|
308
|
+
if (t.enabled && o.value && s.value && l.width.value && l.height.value) {
|
|
309
|
+
const g = o.value.autoClear;
|
|
310
|
+
o.value.autoClear = t.autoClear, t.stencilBuffer && !t.autoClear && o.value.clearStencil(), s.value.render(u), o.value.autoClear = g;
|
|
217
311
|
}
|
|
218
|
-
}),
|
|
219
|
-
var
|
|
220
|
-
(
|
|
221
|
-
}), (
|
|
312
|
+
}), A(() => {
|
|
313
|
+
var u;
|
|
314
|
+
(u = s.value) == null || u.dispose();
|
|
315
|
+
}), (u, g) => X(u.$slots, "default");
|
|
222
316
|
}
|
|
223
317
|
});
|
|
224
318
|
export {
|
|
225
|
-
|
|
226
|
-
|
|
319
|
+
oe as Bloom,
|
|
320
|
+
re as DepthOfField,
|
|
321
|
+
ue as EffectComposer,
|
|
227
322
|
le as Glitch,
|
|
228
|
-
|
|
323
|
+
ie as Noise,
|
|
324
|
+
ae as Outline,
|
|
325
|
+
se as Pixelation
|
|
229
326
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/post-processing
|
|
3
|
-
* version: v0.
|
|
3
|
+
* version: v0.6.0-next.0
|
|
4
4
|
* (c) 2023
|
|
5
5
|
* description: Post-processing library for TresJS
|
|
6
6
|
* author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
|
|
7
7
|
*/
|
|
8
|
-
(function(
|
|
8
|
+
(function(s,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("postprocessing"),require("@tresjs/core"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","postprocessing","@tresjs/core","three"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s["tres-postprocessing"]={},s.Vue,s.Postprocessing,s.TresjsCore,s.Three))})(this,function(s,i,u,m,_){"use strict";const b=Symbol(),v=a=>{const t=i.inject(b),e=i.shallowRef(null),n=i.shallowRef(null),{scene:l,camera:o}=m.useTresContext();i.watchEffect(()=>{!o.value||!(n!=null&&n.value)||(n.value.mainCamera=o.value)});let r=()=>{};return r=i.watchEffect(()=>{!o.value||!(t!=null&&t.value)||!l.value||(r(),!n.value&&(n.value=a(),e.value=new u.EffectPass(o.value,n.value),t.value.addPass(e.value)))}),i.onUnmounted(()=>{var c,f,h;e.value&&((c=t==null?void 0:t.value)==null||c.removePass(e.value)),(f=n.value)==null||f.dispose(),(h=e.value)==null||h.dispose()}),{pass:e,effect:n}},B=/([^[.\]])+/g,T=(a,t)=>{if(!t)return;const e=Array.isArray(t)?t:t.match(B);return e==null?void 0:e.reduce((n,l)=>n&&n[l],a)},y=(a,t,e)=>{const n=Array.isArray(t)?t:t.match(B);n&&n.reduce((l,o,r)=>(l[o]===void 0&&(l[o]={}),r===n.length-1&&(l[o]=e),l[o]),a)},R=(a,t)=>{const e={...a};return t.forEach(n=>delete e[n]),e},x=(a,t,e,n,l={})=>i.watch(a,o=>{var r;if(t.value)if(o===void 0){const c=n();y(t.value,e,T(c,e)),(r=c.dispose)==null||r.call(c)}else y(t.value,e,a())},l),E=(a,t,e)=>a.map(([n,l])=>x(n,t,l,e)),S=(a,t,e)=>Object.keys(a).map(n=>x(()=>a[n],t,n,e)),O=i.defineComponent({__name:"Bloom",props:{blendFunction:{},intensity:{},kernelSize:{},luminanceThreshold:{},luminanceSmoothing:{},mipmapBlur:{type:Boolean,default:void 0}},setup(a,{expose:t}){const e=a,{pass:n,effect:l}=v(()=>new u.BloomEffect(e));return t({pass:n,effect:l}),E([[()=>e.intensity,"intensity"],[()=>e.kernelSize,"kernelSize"],[()=>e.luminanceSmoothing,"luminanceMaterial.smoothing"],[()=>e.luminanceThreshold,"luminanceMaterial.threshold"]],l,()=>new u.BloomEffect),(o,r)=>null}}),z=i.defineComponent({__name:"Glitch",props:{blendFunction:{},delay:{},duration:{},strength:{},mode:{},active:{type:Boolean},ratio:{},columns:{},chromaticAberrationOffset:{},perturbationMap:{},dtSize:{}},setup(a,{expose:t}){const e=a,{pass:n,effect:l}=v(()=>new u.GlitchEffect(e));return t({pass:n,effect:l}),i.watchEffect(()=>{const o=()=>{if(e.mode!==void 0)return e.active===!1?u.GlitchMode.DISABLED:e.mode;const r=new u.GlitchEffect,c=r.mode;return r.dispose(),c};l.value&&(l.value.mode=o())}),S(R(e,["active","mode","blendFunction"]),l,()=>new u.GlitchEffect),(o,r)=>null}}),D=i.defineComponent({__name:"Outline",props:{outlinedObjects:{},blur:{type:Boolean,default:void 0},xRay:{type:Boolean,default:void 0},kernelSize:{},pulseSpeed:{},resolutionX:{},resolutionY:{},edgeStrength:{},patternScale:{},multisampling:{},blendFunction:{},patternTexture:{},resolutionScale:{},hiddenEdgeColor:{},visibleEdgeColor:{}},setup(a,{expose:t}){const e=a,n=p=>p!==void 0?m.normalizeColor(p).getHex():void 0,{camera:l,scene:o}=m.useTresContext(),r={blur:e.blur,xRay:e.xRay,kernelSize:e.kernelSize,pulseSpeed:e.pulseSpeed,resolutionX:e.resolutionX,resolutionY:e.resolutionY,patternScale:e.patternScale,edgeStrength:e.edgeStrength,blendFunction:e.blendFunction,multisampling:e.multisampling,patternTexture:e.patternTexture,resolutionScale:e.resolutionScale,hiddenEdgeColor:n(e.hiddenEdgeColor),visibleEdgeColor:n(e.visibleEdgeColor)},{pass:c,effect:f}=v(()=>new u.OutlineEffect(o.value,l.value,r));t({pass:c,effect:f}),i.watch([()=>e.outlinedObjects,f],()=>{var p;(p=f.value)==null||p.selection.set(e.outlinedObjects||[])},{immediate:!0});const h=i.computed(()=>({hiddenEdgeColor:e.hiddenEdgeColor?m.normalizeColor(e.hiddenEdgeColor):void 0,visibleEdgeColor:e.visibleEdgeColor?m.normalizeColor(e.visibleEdgeColor):void 0}));return E([[()=>e.blur,"blur"],[()=>e.xRay,"xRay"],[()=>e.pulseSpeed,"pulseSpeed"],[()=>e.kernelSize,"kernelSize"],[()=>e.edgeStrength,"edgeStrength"],[()=>e.patternScale,"patternScale"],[()=>e.multisampling,"multisampling"],[()=>h.value.hiddenEdgeColor,"hiddenEdgeColor"],[()=>h.value.visibleEdgeColor,"visibleEdgeColor"]],f,()=>new u.OutlineEffect),(p,F)=>null}}),k=i.defineComponent({__name:"Pixelation",props:{granularity:{}},setup(a,{expose:t}){const e=a,{pass:n,effect:l}=v(()=>new u.PixelationEffect(e.granularity));return t({pass:n,effect:l}),S(e,l,()=>new u.PixelationEffect),(o,r)=>null}}),M=i.defineComponent({__name:"DepthOfField",props:{blendFunction:{},worldFocusDistance:{},worldFocusRange:{},focusDistance:{},focusRange:{},bokehScale:{},resolutionScale:{},resolutionX:{},resolutionY:{}},setup(a,{expose:t}){const e=a,{camera:n}=m.useTresContext(),{pass:l,effect:o}=v(()=>new u.DepthOfFieldEffect(n.value,e));return t({pass:l,effect:o}),E([[()=>e.worldFocusDistance,"circleOfConfusionMaterial.worldFocusDistance"],[()=>e.focusDistance,"circleOfConfusionMaterial.focusDistance"],[()=>e.worldFocusRange,"circleOfConfusionMaterial.worldFocusRange"],[()=>e.focusRange,"circleOfConfusionMaterial.focusRange"],[()=>e.bokehScale,"bokehScale"],[()=>e.resolutionScale,"blurPass.resolution.scale"],[()=>e.resolutionX,"resolution.width"],[()=>e.resolutionY,"resolution.height"]],o,()=>new u.DepthOfFieldEffect),(r,c)=>null}}),j=i.defineComponent({__name:"Noise",props:{premultiply:{type:Boolean,default:!1},blendFunction:{default:u.BlendFunction.SCREEN}},setup(a,{expose:t}){const e=a,{pass:n,effect:l}=v(()=>new u.NoiseEffect(e));return t({pass:n,effect:l}),S(e,l,()=>new u.NoiseEffect),(o,r)=>null}});let C;function P(){var a;if(C!==void 0)return C;try{let t;const e=document.createElement("canvas");return C=!!(window.WebGL2RenderingContext&&(t=e.getContext("webgl2"))),t&&((a=t.getExtension("WEBGL_lose_context"))==null||a.loseContext()),C}catch{return C=!1}}const A=i.defineComponent({__name:"EffectComposer",props:{enabled:{type:Boolean,default:!0},children:{},depthBuffer:{type:Boolean,default:void 0},disableNormalPass:{type:Boolean,default:!1},stencilBuffer:{type:Boolean,default:void 0},resolutionScale:{},autoClear:{type:Boolean,default:!0},multisampling:{default:0},frameBufferType:{default:_.HalfFloatType}},setup(a){const t=a,{scene:e,camera:n,renderer:l,sizes:o}=m.useTresContext(),r=i.shallowRef(null);let c=null,f=null;i.provide(b,r);const h=()=>{r.value&&(f=new u.NormalPass(e.value,n.value),f.enabled=!1,r.value.addPass(f),t.resolutionScale!==void 0&&P()&&(c=new u.DepthDownsamplingPass({normalBuffer:f.texture,resolutionScale:t.resolutionScale}),c.enabled=!1,r.value.addPass(c)))};i.watchEffect(()=>{r.value&&o.width.value&&o.height.value&&r.value.setSize(o.width.value,o.height.value)});const p=i.computed(()=>{const d=new u.EffectComposer,g={depthBuffer:t.depthBuffer!==void 0?t.depthBuffer:d.inputBuffer.depthBuffer,stencilBuffer:t.stencilBuffer!==void 0?t.stencilBuffer:d.inputBuffer.stencilBuffer,multisampling:P()?0:t.multisampling!==void 0?t.multisampling:d.multisampling,frameBufferType:t.frameBufferType!==void 0?t.frameBufferType:_.HalfFloatType};return d.dispose(),g}),F=()=>{!l.value&&!e.value&&!n.value||(r.value=new u.EffectComposer(l.value,p.value),r.value.addPass(new u.RenderPass(e.value,n.value)),t.disableNormalPass||h())};let w=()=>{};w=i.watch([o.height,o.width],()=>{!o.height.value&&!o.width.value||(i.watchEffect(F),w==null||w())},{immediate:!0});const{onLoop:N}=m.useRenderLoop();return N(({delta:d})=>{if(t.enabled&&l.value&&r.value&&o.width.value&&o.height.value){const g=l.value.autoClear;l.value.autoClear=t.autoClear,t.stencilBuffer&&!t.autoClear&&l.value.clearStencil(),r.value.render(d),l.value.autoClear=g}}),i.onUnmounted(()=>{var d;(d=r.value)==null||d.dispose()}),(d,g)=>i.renderSlot(d.$slots,"default")}});s.Bloom=O,s.DepthOfField=M,s.EffectComposer=A,s.Glitch=z,s.Noise=j,s.Outline=D,s.Pixelation=k,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the value at a given path within a provided object.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of value to be returned
|
|
5
|
+
*
|
|
6
|
+
* @param {any} obj - The object to extract value from
|
|
7
|
+
* @param {string | string[]} path - A path or an array of path where the value should be get from
|
|
8
|
+
*
|
|
9
|
+
* @returns {T | undefined} - The value at the given path in the object, or undefined if path is not found
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* const obj = { a: { b: { c: 1 } } }
|
|
14
|
+
*
|
|
15
|
+
* const result = get(obj, 'a.b.c')
|
|
16
|
+
*
|
|
17
|
+
* console.log(result) // 1
|
|
18
|
+
*/
|
|
19
|
+
export declare const get: <T>(obj: any, path: string | string[]) => T | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Sets a value at a given path within a provided object. If the path does not exist, nested objects will be created.
|
|
22
|
+
*
|
|
23
|
+
* @param {any} obj - The original object to set value in
|
|
24
|
+
* @param {string | string[]} path - A path or an array of path where the value should be set
|
|
25
|
+
* @param {any} value - The value to be set at the provided path
|
|
26
|
+
*
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const obj = { a: { b: { c: 1 } } }
|
|
31
|
+
*
|
|
32
|
+
* set(obj, 'a.b.c', 2)
|
|
33
|
+
*
|
|
34
|
+
* console.log(obj) // { a: { b: { c: 2 } } }
|
|
35
|
+
*/
|
|
36
|
+
export declare const set: (obj: any, path: string | string[], value: any) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Omits given properties from a provided object.
|
|
39
|
+
*
|
|
40
|
+
* @template T - An object with string keys and any type of values
|
|
41
|
+
*
|
|
42
|
+
* @param {T} obj - The original object to omit properties from
|
|
43
|
+
* @param {(keyof T)[]} properties - An array of property key names to omit from the base object
|
|
44
|
+
*
|
|
45
|
+
* @returns {Partial<T>} The new object with omitted properties
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const obj = { a: 1, b: 2, c: 3 }
|
|
49
|
+
* const propsToOmit = ['b', 'c']
|
|
50
|
+
*
|
|
51
|
+
* const newObj = omit(obj, propsToOmit)
|
|
52
|
+
*
|
|
53
|
+
* console.log(newObj) // { a: 1 }
|
|
54
|
+
*/
|
|
55
|
+
export declare const omit: <T extends Record<string, any>>(obj: T, properties: (keyof T)[]) => Partial<T>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Ref, WatchOptions } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a prop watcher function that monitors changes to a property and updates a target object.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of the property being watched.
|
|
6
|
+
* @template E - The type of the target object.
|
|
7
|
+
* @param {() => T} propGetter - A function that retrieves the prop value to be watched.
|
|
8
|
+
* @param {Ref<E>} target - A Ref representing the target object to be updated.
|
|
9
|
+
* @param {string} propertyPath - The dot-separated path to the property within the target object.
|
|
10
|
+
* @param {() => E & { dispose?(): void }} newPlainObjectFunction - A function that creates a new plain object to retrieve the defaults from with an optional "dispose" method for cleanup.
|
|
11
|
+
* @param {WatchOptions} watchOptions - The options for watch.
|
|
12
|
+
*/
|
|
13
|
+
export declare const makePropWatcher: <T, E>(propGetter: () => T, target: Ref<E>, propertyPath: string, newPlainObjectFunction: () => E & {
|
|
14
|
+
dispose?(): void;
|
|
15
|
+
}, watchOptions?: WatchOptions) => import("vue").WatchStopHandle;
|
|
16
|
+
/**
|
|
17
|
+
* Creates multiple prop watchers for monitoring changes to multiple properties and updating a target object.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type of the property being watched.
|
|
20
|
+
* @template E - The type of the target object.
|
|
21
|
+
* @param {(string | (() => T))[][]} propGettersAndPropertyPaths - An array of arrays containing pairs of prop getters and their corresponding property paths within the target object.
|
|
22
|
+
* @param {Ref<E>} target - A Ref representing the target object to be updated.
|
|
23
|
+
* @param {() => E & { dispose?(): void }} newPlainObjectFunction - A function that creates a new plain object to retrieve the defaults from with an optional "dispose" method for cleanup.
|
|
24
|
+
*/
|
|
25
|
+
export declare const makePropWatchers: <E>(propGettersAndPropertyPaths: (string | (() => any))[][], target: Ref<E>, newPlainObjectFunction: () => E & {
|
|
26
|
+
dispose?(): void;
|
|
27
|
+
}) => import("vue").WatchStopHandle[];
|
|
28
|
+
/**
|
|
29
|
+
* Creates multiple prop watchers via the props object for monitoring changes to multiple properties and updating a target object.
|
|
30
|
+
* Use this method in case the prop names match the names of the properties you want to set on your target object.
|
|
31
|
+
*
|
|
32
|
+
* @param props - The props object. Usually created via defineProps.
|
|
33
|
+
* @param {Ref<E>} target - A Ref representing the target object to be updated.
|
|
34
|
+
* @param {() => E & { dispose?(): void }} newPlainObjectFunction - A function that creates a new plain object to retrieve the defaults from with an optional "dispose" method for cleanup.
|
|
35
|
+
*/
|
|
36
|
+
export declare const makePropWatchersUsingAllProps: <E>(props: {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}, target: Ref<E>, newPlainObjectFunction: () => E & {
|
|
39
|
+
dispose?(): void;
|
|
40
|
+
}) => import("vue").WatchStopHandle[];
|