@tresjs/post-processing 0.4.0 → 0.5.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.
@@ -1,3 +1,3 @@
1
- import { EffectComposer } from 'postprocessing';
2
- import { InjectionKey, ShallowRef } from 'vue';
1
+ import type { EffectComposer } from 'postprocessing';
2
+ import type { InjectionKey, ShallowRef } from 'vue';
3
3
  export declare const effectComposerInjectionKey: InjectionKey<ShallowRef<EffectComposer | null>>;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import Bloom from './core/effects/Bloom.vue';
2
2
  import Glitch from './core/effects/Glitch.vue';
3
3
  import Outline from './core/effects/Outline.vue';
4
+ import Pixelation from './core/effects/Pixelation.vue';
5
+ import DepthOfField from './core/effects/DepthOfField.vue';
4
6
  import EffectComposer from './core/EffectComposer.vue';
5
- export { EffectComposer, Bloom, Outline, Glitch };
7
+ export { Bloom, Glitch, Outline, Pixelation, DepthOfField, EffectComposer, };
@@ -1,15 +1,64 @@
1
1
  /**
2
2
  * name: @tresjs/post-processing
3
- * version: v0.4.0
3
+ * version: v0.5.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 { defineComponent as _, inject as T, shallowRef as g, watchEffect as h, onUnmounted as w, computed as j, watch as F, provide as H, renderSlot as I } from "vue";
9
- import { useTresContext as P, normalizeColor as z, useRenderLoop as X } from "@tresjs/core";
10
- import { BloomEffect as O, EffectPass as M, GlitchEffect as k, GlitchMode as Y, OutlineEffect as A, EffectComposer as R, RenderPass as K, NormalPass as U, DepthDownsamplingPass as q } from "postprocessing";
11
- import { HalfFloatType as G } from "three";
12
- const x = Symbol(), ee = /* @__PURE__ */ _({
8
+ import { inject as $, shallowRef as w, watchEffect as m, onUnmounted as T, watch as _, defineComponent as f, computed as k, provide as j, renderSlot as N } from "vue";
9
+ import { EffectPass as X, BloomEffect as x, GlitchEffect as b, GlitchMode as Y, OutlineEffect as y, PixelationEffect as P, DepthOfFieldEffect as F, EffectComposer as R, RenderPass as H, NormalPass as I, DepthDownsamplingPass as U } from "postprocessing";
10
+ import { useTresContext as S, normalizeColor as C, useRenderLoop as K } from "@tresjs/core";
11
+ import { HalfFloatType as O } from "three";
12
+ const A = Symbol(), v = (a) => {
13
+ const t = $(A), e = w(null), n = w(null), { scene: o, camera: l } = S();
14
+ m(() => {
15
+ !l.value || !(n != null && n.value) || (n.value.mainCamera = l.value);
16
+ });
17
+ let s = () => {
18
+ };
19
+ return s = m(() => {
20
+ !l.value || !(t != null && t.value) || !o.value || (s(), !n.value && (n.value = a(), e.value = new X(l.value, n.value), t.value.addPass(e.value)));
21
+ }), T(() => {
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
+ }, M = /([^[.\]])+/g, q = (a, t) => {
29
+ if (!t)
30
+ return;
31
+ const e = Array.isArray(t) ? t : t.match(M);
32
+ return e == null ? void 0 : e.reduce((n, o) => n && n[o], a);
33
+ }, z = (a, t, e) => {
34
+ const n = Array.isArray(t) ? t : t.match(M);
35
+ n && n.reduce((o, l, s) => (o[l] === void 0 && (o[l] = {}), s === n.length - 1 && (o[l] = e), o[l]), a);
36
+ }, J = (a, t) => {
37
+ const e = { ...a };
38
+ return t.forEach((n) => delete e[n]), e;
39
+ }, G = (a, t, e, n, o = {}) => _(
40
+ a,
41
+ (l) => {
42
+ var s;
43
+ if (t.value)
44
+ if (l === void 0) {
45
+ const r = n();
46
+ z(t.value, e, q(r, e)), (s = r.dispose) == null || s.call(r);
47
+ } else
48
+ z(t.value, e, a());
49
+ },
50
+ o
51
+ ), E = (a, t, e) => a.map(([n, o]) => G(
52
+ n,
53
+ t,
54
+ o,
55
+ e
56
+ )), L = (a, t, e) => Object.keys(a).map((n) => G(
57
+ () => a[n],
58
+ t,
59
+ n,
60
+ e
61
+ )), te = /* @__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(f, { expose: o }) {
23
- const l = f, n = T(x), t = g(null), e = g(null);
24
- o({ pass: t, effect: e });
25
- const { camera: i } = P();
26
- let s;
27
- return s = h(() => {
28
- !i.value || !(n != null && n.value) || (s == null || s(), !e.value && (e.value = new O(l), t.value = new M(i.value, e.value), n.value.addPass(t.value)));
29
- }), h(() => {
30
- if (!e.value)
31
- return;
32
- const a = new O();
33
- e.value.intensity = l.intensity !== void 0 ? l.intensity : a.intensity, e.value.kernelSize = l.kernelSize !== void 0 ? l.kernelSize : a.kernelSize, e.value.luminanceMaterial.smoothing = l.luminanceSmoothing !== void 0 ? l.luminanceSmoothing : a.luminanceMaterial.smoothing, e.value.luminanceMaterial.threshold = l.luminanceThreshold !== void 0 ? l.luminanceThreshold : a.luminanceMaterial.threshold, a.dispose();
34
- }), w(() => {
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 } = v(() => new x(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 x()
83
+ ), (l, s) => null;
38
84
  }
39
- }), le = /* @__PURE__ */ _({
85
+ }), ne = /* @__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(f, { expose: o }) {
55
- const l = f, n = T(x), t = g(null), e = g(null);
56
- o({ pass: t, effect: e });
57
- const { camera: i } = P();
58
- let s;
59
- return s = h(() => {
60
- !i.value || !(n != null && n.value) || (s == null || s(), !e.value && (e.value = new k(l), t.value = new M(i.value, e.value), n.value.addPass(t.value)));
61
- }), h(() => {
62
- if (!e.value)
63
- return;
64
- const a = new k(), d = () => l.mode !== void 0 ? l.active === !1 ? Y.DISABLED : l.mode : a.mode;
65
- e.value.mode = d(), e.value.ratio = l.ratio !== void 0 ? l.ratio : a.ratio, e.value.delay = l.delay !== void 0 ? l.delay : a.delay, e.value.columns = l.columns !== void 0 ? l.columns : a.columns, e.value.duration = l.duration !== void 0 ? l.duration : a.duration, e.value.strength = l.strength !== void 0 ? l.strength : a.strength, e.value.perturbationMap = l.perturbationMap !== void 0 ? l.perturbationMap : a.perturbationMap, e.value.chromaticAberrationOffset = l.chromaticAberrationOffset !== void 0 ? l.chromaticAberrationOffset : a.chromaticAberrationOffset;
66
- }), w(() => {
67
- var a, d, v;
68
- 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();
69
- }), (a, d) => null;
100
+ setup(a, { expose: t }) {
101
+ const e = a, { pass: n, effect: o } = v(() => new b(e));
102
+ return t({ pass: n, effect: o }), m(() => {
103
+ const l = () => {
104
+ if (e.mode !== void 0)
105
+ return e.active === !1 ? Y.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
+ }), L(
111
+ J(e, ["active", "mode", "blendFunction"]),
112
+ o,
113
+ () => new b()
114
+ ), (l, s) => null;
70
115
  }
71
- }), ae = /* @__PURE__ */ _({
116
+ }), oe = /* @__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,120 @@ const x = Symbol(), ee = /* @__PURE__ */ _({
87
132
  hiddenEdgeColor: {},
88
133
  visibleEdgeColor: {}
89
134
  },
90
- setup(f, { expose: o }) {
91
- const l = f, n = T(x), t = g(null), e = g(null);
92
- o({ pass: t, effect: e });
93
- const i = (u) => u !== void 0 ? z(u).getHex() : void 0, s = j(() => {
94
- const {
95
- blur: u,
96
- xRay: c,
97
- kernelSize: p,
98
- pulseSpeed: r,
99
- resolutionX: m,
100
- resolutionY: S,
101
- patternScale: B,
102
- edgeStrength: C,
103
- multisampling: y,
104
- blendFunction: E,
105
- patternTexture: N,
106
- resolutionScale: D,
107
- hiddenEdgeColor: $,
108
- visibleEdgeColor: W
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 } = v(() => new y(l.value, o.value, s));
152
+ t({ pass: r, effect: i }), _(
153
+ [() => e.outlinedObjects, i],
132
154
  // watchEffect is intentionally not used here as it would result in an endless loop
133
155
  () => {
134
- var u;
135
- (u = e.value) == null || u.selection.set(l.outlinedObjects || []);
156
+ var c;
157
+ (c = i.value) == null || c.selection.set(e.outlinedObjects || []);
136
158
  },
137
159
  {
138
160
  immediate: !0
139
161
  }
140
- ), h(() => {
141
- if (!e.value)
142
- return;
143
- const u = new A(), {
144
- blur: c,
145
- xRay: p,
146
- kernelSize: r,
147
- pulseSpeed: m,
148
- patternScale: S,
149
- edgeStrength: B,
150
- multisampling: C,
151
- hiddenEdgeColor: y,
152
- visibleEdgeColor: E
153
- } = s.value;
154
- e.value.blur = c !== void 0 ? c : u.blur, e.value.xRay = p !== void 0 ? p : u.xRay, e.value.pulseSpeed = m !== void 0 ? m : u.pulseSpeed, e.value.kernelSize = r !== void 0 ? r : u.kernelSize, e.value.edgeStrength = B !== void 0 ? B : u.edgeStrength, e.value.patternScale = S !== void 0 ? S : u.patternScale, e.value.multisampling = C !== void 0 ? C : u.multisampling, e.value.hiddenEdgeColor = y !== void 0 ? z(y) : u.hiddenEdgeColor, e.value.visibleEdgeColor = E !== void 0 ? z(E) : u.visibleEdgeColor, u.dispose();
155
- }), w(() => {
156
- var u, c, p, r;
157
- (u = e.value) == null || u.selection.clear(), t.value && ((c = n == null ? void 0 : n.value) == null || c.removePass(t.value)), (p = e.value) == null || p.dispose(), (r = t.value) == null || r.dispose();
158
- }), (u, c) => null;
162
+ );
163
+ const d = k(() => ({
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 y()
188
+ ), (c, B) => null;
189
+ }
190
+ }), le = /* @__PURE__ */ f({
191
+ __name: "Pixelation",
192
+ props: {
193
+ granularity: {}
194
+ },
195
+ setup(a, { expose: t }) {
196
+ const e = a, { pass: n, effect: o } = v(() => new P(e.granularity));
197
+ return t({ pass: n, effect: o }), L(
198
+ e,
199
+ o,
200
+ () => new P()
201
+ ), (l, s) => null;
202
+ }
203
+ }), ae = /* @__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 } = v(() => new F(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 F()
232
+ ), (s, r) => null;
159
233
  }
160
234
  });
161
- let b;
162
- function L() {
163
- var f;
164
- if (b !== void 0)
165
- return b;
235
+ let p;
236
+ function D() {
237
+ var a;
238
+ if (p !== void 0)
239
+ return p;
166
240
  try {
167
- let o;
168
- const l = document.createElement("canvas");
169
- return b = !!(window.WebGL2RenderingContext && (o = l.getContext("webgl2"))), o && ((f = o.getExtension("WEBGL_lose_context")) == null || f.loseContext()), b;
241
+ let t;
242
+ const e = document.createElement("canvas");
243
+ return p = !!(window.WebGL2RenderingContext && (t = e.getContext("webgl2"))), t && ((a = t.getExtension("WEBGL_lose_context")) == null || a.loseContext()), p;
170
244
  } catch {
171
- return b = !1;
245
+ return p = !1;
172
246
  }
173
247
  }
174
- const te = /* @__PURE__ */ _({
248
+ const se = /* @__PURE__ */ f({
175
249
  __name: "EffectComposer",
176
250
  props: {
177
251
  enabled: { type: Boolean, default: !0 },
@@ -182,48 +256,56 @@ const te = /* @__PURE__ */ _({
182
256
  resolutionScale: {},
183
257
  autoClear: { type: Boolean, default: !0 },
184
258
  multisampling: { default: 0 },
185
- frameBufferType: { default: G }
259
+ frameBufferType: { default: O }
186
260
  },
187
- setup(f) {
188
- const o = f, { scene: l, camera: n, renderer: t, sizes: e } = P(), i = g(null);
189
- let s = null, a = null;
190
- H(x, i);
261
+ setup(a) {
262
+ const t = a, { scene: e, camera: n, renderer: o, sizes: l } = S(), s = w(null);
263
+ let r = null, i = null;
264
+ j(A, s);
191
265
  const d = () => {
192
- i.value && (a = new U(l.value, n.value), a.enabled = !1, i.value.addPass(a), o.resolutionScale !== void 0 && L() && (s = new q({
193
- normalBuffer: a.texture,
194
- resolutionScale: o.resolutionScale
195
- }), s.enabled = !1, i.value.addPass(s)));
266
+ s.value && (i = new I(e.value, n.value), i.enabled = !1, s.value.addPass(i), t.resolutionScale !== void 0 && D() && (r = new U({
267
+ normalBuffer: i.texture,
268
+ resolutionScale: t.resolutionScale
269
+ }), r.enabled = !1, s.value.addPass(r)));
196
270
  };
197
- h(() => {
198
- i.value && e.width.value && e.height.value && i.value.setSize(e.width.value, e.height.value);
271
+ m(() => {
272
+ s.value && l.width.value && l.height.value && s.value.setSize(l.width.value, l.height.value);
199
273
  });
200
- const v = j(() => {
201
- const r = new R(), m = {
202
- depthBuffer: o.depthBuffer !== void 0 ? o.depthBuffer : r.inputBuffer.depthBuffer,
203
- stencilBuffer: o.stencilBuffer !== void 0 ? o.stencilBuffer : r.inputBuffer.stencilBuffer,
204
- multisampling: L() ? 0 : o.multisampling !== void 0 ? o.multisampling : r.multisampling,
205
- frameBufferType: o.frameBufferType !== void 0 ? o.frameBufferType : G
274
+ const c = k(() => {
275
+ const u = new R(), g = {
276
+ depthBuffer: t.depthBuffer !== void 0 ? t.depthBuffer : u.inputBuffer.depthBuffer,
277
+ stencilBuffer: t.stencilBuffer !== void 0 ? t.stencilBuffer : u.inputBuffer.stencilBuffer,
278
+ multisampling: D() ? 0 : t.multisampling !== void 0 ? t.multisampling : u.multisampling,
279
+ frameBufferType: t.frameBufferType !== void 0 ? t.frameBufferType : O
206
280
  };
207
- return r.dispose(), m;
208
- }), u = () => {
209
- !t.value && !l.value && !n.value || (i.value = new R(t.value, v.value), i.value.addPass(new K(l.value, n.value)), o.disableNormalPass || d());
210
- }, c = F([e.height, e.width], () => {
211
- !e.height.value && !e.width.value || (h(u), c == null || c());
212
- }), { onLoop: p } = X();
213
- return p(({ delta: r }) => {
214
- if (o.enabled && t.value && i.value && e.width.value && e.height.value) {
215
- const m = t.value.autoClear;
216
- t.value.autoClear = o.autoClear, o.stencilBuffer && !o.autoClear && t.value.clearStencil(), i.value.render(r), t.value.autoClear = m;
281
+ return u.dispose(), g;
282
+ }), B = () => {
283
+ !o.value && !e.value && !n.value || (s.value = new R(o.value, c.value), s.value.addPass(new H(e.value, n.value)), t.disableNormalPass || d());
284
+ };
285
+ let h = () => {
286
+ };
287
+ h = _([l.height, l.width], () => {
288
+ !l.height.value && !l.width.value || (m(B), h == null || h());
289
+ }, {
290
+ immediate: !0
291
+ });
292
+ const { onLoop: W } = K();
293
+ return W(({ delta: u }) => {
294
+ if (t.enabled && o.value && s.value && l.width.value && l.height.value) {
295
+ const g = o.value.autoClear;
296
+ o.value.autoClear = t.autoClear, t.stencilBuffer && !t.autoClear && o.value.clearStencil(), s.value.render(u), o.value.autoClear = g;
217
297
  }
218
- }), w(() => {
219
- var r;
220
- (r = i.value) == null || r.dispose();
221
- }), (r, m) => I(r.$slots, "default");
298
+ }), T(() => {
299
+ var u;
300
+ (u = s.value) == null || u.dispose();
301
+ }), (u, g) => N(u.$slots, "default");
222
302
  }
223
303
  });
224
304
  export {
225
- ee as Bloom,
226
- te as EffectComposer,
227
- le as Glitch,
228
- ae as Outline
305
+ te as Bloom,
306
+ ae as DepthOfField,
307
+ se as EffectComposer,
308
+ ne as Glitch,
309
+ oe as Outline,
310
+ le as Pixelation
229
311
  };
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * name: @tresjs/post-processing
3
- * version: v0.4.0
3
+ * version: v0.5.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(v,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("vue"),require("@tresjs/core"),require("postprocessing"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","@tresjs/core","postprocessing","three"],l):(v=typeof globalThis<"u"?globalThis:v||self,l(v["tres-postprocessing"]={},v.Vue,v.TresjsCore,v.Postprocessing,v.Three))})(this,function(v,l,S,d,x){"use strict";const E=Symbol(),z=l.defineComponent({__name:"Bloom",props:{blendFunction:{},intensity:{},kernelSize:{},luminanceThreshold:{},luminanceSmoothing:{},mipmapBlur:{type:Boolean}},setup(h,{expose:i}){const t=h,o=l.inject(E),n=l.shallowRef(null),e=l.shallowRef(null);i({pass:n,effect:e});const{camera:r}=S.useTresContext();let f;return f=l.watchEffect(()=>{!r.value||!(o!=null&&o.value)||(f==null||f(),!e.value&&(e.value=new d.BloomEffect(t),n.value=new d.EffectPass(r.value,e.value),o.value.addPass(n.value)))}),l.watchEffect(()=>{if(!e.value)return;const a=new d.BloomEffect;e.value.intensity=t.intensity!==void 0?t.intensity:a.intensity,e.value.kernelSize=t.kernelSize!==void 0?t.kernelSize:a.kernelSize,e.value.luminanceMaterial.smoothing=t.luminanceSmoothing!==void 0?t.luminanceSmoothing:a.luminanceMaterial.smoothing,e.value.luminanceMaterial.threshold=t.luminanceThreshold!==void 0?t.luminanceThreshold:a.luminanceMaterial.threshold,a.dispose()}),l.onUnmounted(()=>{var a,c,m;n.value&&((a=o==null?void 0:o.value)==null||a.removePass(n.value)),(c=e.value)==null||c.dispose(),(m=n.value)==null||m.dispose()}),(a,c)=>null}}),R=l.defineComponent({__name:"Glitch",props:{blendFunction:{},delay:{},duration:{},strength:{},mode:{},active:{type:Boolean},ratio:{},columns:{},chromaticAberrationOffset:{},perturbationMap:{},dtSize:{}},setup(h,{expose:i}){const t=h,o=l.inject(E),n=l.shallowRef(null),e=l.shallowRef(null);i({pass:n,effect:e});const{camera:r}=S.useTresContext();let f;return f=l.watchEffect(()=>{!r.value||!(o!=null&&o.value)||(f==null||f(),!e.value&&(e.value=new d.GlitchEffect(t),n.value=new d.EffectPass(r.value,e.value),o.value.addPass(n.value)))}),l.watchEffect(()=>{if(!e.value)return;const a=new d.GlitchEffect,c=()=>t.mode!==void 0?t.active===!1?d.GlitchMode.DISABLED:t.mode:a.mode;e.value.mode=c(),e.value.ratio=t.ratio!==void 0?t.ratio:a.ratio,e.value.delay=t.delay!==void 0?t.delay:a.delay,e.value.columns=t.columns!==void 0?t.columns:a.columns,e.value.duration=t.duration!==void 0?t.duration:a.duration,e.value.strength=t.strength!==void 0?t.strength:a.strength,e.value.perturbationMap=t.perturbationMap!==void 0?t.perturbationMap:a.perturbationMap,e.value.chromaticAberrationOffset=t.chromaticAberrationOffset!==void 0?t.chromaticAberrationOffset:a.chromaticAberrationOffset}),l.onUnmounted(()=>{var a,c,m;n.value&&((a=o==null?void 0:o.value)==null||a.removePass(n.value)),(c=e.value)==null||c.dispose(),(m=n.value)==null||m.dispose()}),(a,c)=>null}}),O=l.defineComponent({__name:"Outline",props:{outlinedObjects:{},blur:{type:Boolean},xRay:{type:Boolean},kernelSize:{},pulseSpeed:{},resolutionX:{},resolutionY:{},edgeStrength:{},patternScale:{},multisampling:{},blendFunction:{},patternTexture:{},resolutionScale:{},hiddenEdgeColor:{},visibleEdgeColor:{}},setup(h,{expose:i}){const t=h,o=l.inject(E),n=l.shallowRef(null),e=l.shallowRef(null);i({pass:n,effect:e});const r=u=>u!==void 0?S.normalizeColor(u).getHex():void 0,f=l.computed(()=>{const{blur:u,xRay:p,kernelSize:g,pulseSpeed:s,resolutionX:C,resolutionY:w,patternScale:y,edgeStrength:B,multisampling:P,blendFunction:_,patternTexture:M,resolutionScale:k,hiddenEdgeColor:A,visibleEdgeColor:G}=t;return{blur:u,xRay:p,kernelSize:g,pulseSpeed:s,resolutionX:C,resolutionY:w,patternScale:y,edgeStrength:B,blendFunction:_,multisampling:P,patternTexture:M,resolutionScale:k,hiddenEdgeColor:r(A),visibleEdgeColor:r(G)}}),{camera:a,scene:c}=S.useTresContext();let m;return m=l.watchEffect(()=>{!a.value||!(o!=null&&o.value)||!c.value||(m==null||m(),!e.value&&(e.value=new d.OutlineEffect(c.value,a.value,f.value),n.value=new d.EffectPass(a.value,e.value),o.value.addPass(n.value)))}),l.watch([()=>t.outlinedObjects,e],()=>{var u;(u=e.value)==null||u.selection.set(t.outlinedObjects||[])},{immediate:!0}),l.watchEffect(()=>{if(!e.value)return;const u=new d.OutlineEffect,{blur:p,xRay:g,kernelSize:s,pulseSpeed:C,patternScale:w,edgeStrength:y,multisampling:B,hiddenEdgeColor:P,visibleEdgeColor:_}=f.value;e.value.blur=p!==void 0?p:u.blur,e.value.xRay=g!==void 0?g:u.xRay,e.value.pulseSpeed=C!==void 0?C:u.pulseSpeed,e.value.kernelSize=s!==void 0?s:u.kernelSize,e.value.edgeStrength=y!==void 0?y:u.edgeStrength,e.value.patternScale=w!==void 0?w:u.patternScale,e.value.multisampling=B!==void 0?B:u.multisampling,e.value.hiddenEdgeColor=P!==void 0?S.normalizeColor(P):u.hiddenEdgeColor,e.value.visibleEdgeColor=_!==void 0?S.normalizeColor(_):u.visibleEdgeColor,u.dispose()}),l.onUnmounted(()=>{var u,p,g,s;(u=e.value)==null||u.selection.clear(),n.value&&((p=o==null?void 0:o.value)==null||p.removePass(n.value)),(g=e.value)==null||g.dispose(),(s=n.value)==null||s.dispose()}),(u,p)=>null}});let b;function T(){var h;if(b!==void 0)return b;try{let i;const t=document.createElement("canvas");return b=!!(window.WebGL2RenderingContext&&(i=t.getContext("webgl2"))),i&&((h=i.getExtension("WEBGL_lose_context"))==null||h.loseContext()),b}catch{return b=!1}}const j=l.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:x.HalfFloatType}},setup(h){const i=h,{scene:t,camera:o,renderer:n,sizes:e}=S.useTresContext(),r=l.shallowRef(null);let f=null,a=null;l.provide(E,r);const c=()=>{r.value&&(a=new d.NormalPass(t.value,o.value),a.enabled=!1,r.value.addPass(a),i.resolutionScale!==void 0&&T()&&(f=new d.DepthDownsamplingPass({normalBuffer:a.texture,resolutionScale:i.resolutionScale}),f.enabled=!1,r.value.addPass(f)))};l.watchEffect(()=>{r.value&&e.width.value&&e.height.value&&r.value.setSize(e.width.value,e.height.value)});const m=l.computed(()=>{const s=new d.EffectComposer,C={depthBuffer:i.depthBuffer!==void 0?i.depthBuffer:s.inputBuffer.depthBuffer,stencilBuffer:i.stencilBuffer!==void 0?i.stencilBuffer:s.inputBuffer.stencilBuffer,multisampling:T()?0:i.multisampling!==void 0?i.multisampling:s.multisampling,frameBufferType:i.frameBufferType!==void 0?i.frameBufferType:x.HalfFloatType};return s.dispose(),C}),u=()=>{!n.value&&!t.value&&!o.value||(r.value=new d.EffectComposer(n.value,m.value),r.value.addPass(new d.RenderPass(t.value,o.value)),i.disableNormalPass||c())},p=l.watch([e.height,e.width],()=>{!e.height.value&&!e.width.value||(l.watchEffect(u),p==null||p())}),{onLoop:g}=S.useRenderLoop();return g(({delta:s})=>{if(i.enabled&&n.value&&r.value&&e.width.value&&e.height.value){const C=n.value.autoClear;n.value.autoClear=i.autoClear,i.stencilBuffer&&!i.autoClear&&n.value.clearStencil(),r.value.render(s),n.value.autoClear=C}}),l.onUnmounted(()=>{var s;(s=r.value)==null||s.dispose()}),(s,C)=>l.renderSlot(s.$slots,"default")}});v.Bloom=z,v.EffectComposer=j,v.Glitch=R,v.Outline=O,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
8
+ (function(c,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):(c=typeof globalThis<"u"?globalThis:c||self,i(c["tres-postprocessing"]={},c.Vue,c.Postprocessing,c.TresjsCore,c.Three))})(this,function(c,i,u,m,E){"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 s,f,h;e.value&&((s=t==null?void 0:t.value)==null||s.removePass(e.value)),(f=n.value)==null||f.dispose(),(h=e.value)==null||h.dispose()}),{pass:e,effect:n}},_=/([^[.\]])+/g,F=(a,t)=>{if(!t)return;const e=Array.isArray(t)?t:t.match(_);return e==null?void 0:e.reduce((n,l)=>n&&n[l],a)},B=(a,t,e)=>{const n=Array.isArray(t)?t:t.match(_);n&&n.reduce((l,o,r)=>(l[o]===void 0&&(l[o]={}),r===n.length-1&&(l[o]=e),l[o]),a)},O=(a,t)=>{const e={...a};return t.forEach(n=>delete e[n]),e},y=(a,t,e,n,l={})=>i.watch(a,o=>{var r;if(t.value)if(o===void 0){const s=n();B(t.value,e,F(s,e)),(r=s.dispose)==null||r.call(s)}else B(t.value,e,a())},l),S=(a,t,e)=>a.map(([n,l])=>y(n,t,l,e)),x=(a,t,e)=>Object.keys(a).map(n=>y(()=>a[n],t,n,e)),R=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}),S([[()=>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,s=r.mode;return r.dispose(),s};l.value&&(l.value.mode=o())}),x(O(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:s,effect:f}=v(()=>new u.OutlineEffect(o.value,l.value,r));t({pass:s,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 S([[()=>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,T)=>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}),x(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}),S([[()=>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,s)=>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 j=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:E.HalfFloatType}},setup(a){const t=a,{scene:e,camera:n,renderer:l,sizes:o}=m.useTresContext(),r=i.shallowRef(null);let s=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()&&(s=new u.DepthDownsamplingPass({normalBuffer:f.texture,resolutionScale:t.resolutionScale}),s.enabled=!1,r.value.addPass(s)))};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,w={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:E.HalfFloatType};return d.dispose(),w}),T=()=>{!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 g=()=>{};g=i.watch([o.height,o.width],()=>{!o.height.value&&!o.width.value||(i.watchEffect(T),g==null||g())},{immediate:!0});const{onLoop:A}=m.useRenderLoop();return A(({delta:d})=>{if(t.enabled&&l.value&&r.value&&o.width.value&&o.height.value){const w=l.value.autoClear;l.value.autoClear=t.autoClear,t.stencilBuffer&&!t.autoClear&&l.value.clearStencil(),r.value.render(d),l.value.autoClear=w}}),i.onUnmounted(()=>{var d;(d=r.value)==null||d.dispose()}),(d,w)=>i.renderSlot(d.$slots,"default")}});c.Bloom=R,c.DepthOfField=M,c.EffectComposer=j,c.Glitch=z,c.Outline=D,c.Pixelation=k,Object.defineProperty(c,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[];