@tresjs/core 1.7.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tres.js CHANGED
@@ -1,32 +1,30 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v1.7.0
3
+ * version: v1.8.1
4
4
  * (c) 2023
5
5
  * description: Declarative ThreeJS using Vue Components
6
6
  * author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
7
7
  */
8
- import { computed as me, watch as U, ref as R, inject as de, defineComponent as Z, onUnmounted as ge, shallowRef as ee, shallowReactive as be, toRefs as we, provide as L, onBeforeUnmount as Be, h as ie } from "vue";
9
- import { useEventListener as Oe, createEventHook as te, useRafFn as Ae, resolveUnref as m, useWindowSize as Ie, useElementSize as Fe, useDevicePixelRatio as $e, unrefElement as J } from "@vueuse/core";
8
+ import { inject as Z, watch as j, toRef as $e, ref as L, defineComponent as q, onUnmounted as ge, shallowRef as Q, shallowReactive as Oe, computed as he, toRefs as we, provide as T, onBeforeUnmount as Ae, h as H } from "vue";
9
+ import { useEventListener as Be, createEventHook as ee, useRafFn as Ie, resolveUnref as w, useWindowSize as Fe, useElementSize as _e, useDevicePixelRatio as Ue, unrefElement as G } from "@vueuse/core";
10
10
  import * as ce from "three";
11
- import { PerspectiveCamera as _, OrthographicCamera as he, Vector3 as je, Color as X, Mesh as ke, Fog as ze, BufferAttribute as De, Clock as ve, Scene as Ue, LoadingManager as _e, TextureLoader as Ne, Raycaster as Ve, Vector2 as We, sRGBEncoding as Ge, ACESFilmicToneMapping as He, PCFSoftShadowMap as Ke, PCFShadowMap as Je, LinearEncoding as ue, NoToneMapping as le, WebGLRenderer as Xe } from "three";
12
- var Ye = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Ye || {});
13
- const B = {
14
- cameras: []
15
- }, qe = 45;
16
- let P;
17
- function ye() {
18
- const { state: e, setState: n } = T();
19
- function o(p = "Perspective", t) {
20
- var s;
21
- if (p === "Perspective") {
22
- const { near: c, far: a, fov: u } = t || {
11
+ import { PerspectiveCamera as z, OrthographicCamera as ye, Vector3 as je, Color as K, Mesh as ze, Fog as De, BufferAttribute as We, Clock as ve, Scene as ke, LoadingManager as Ne, TextureLoader as Ve, Raycaster as He, Vector2 as Ge, sRGBEncoding as Ke, ACESFilmicToneMapping as Xe, PCFSoftShadowMap as Ye, PCFShadowMap as Je, LinearEncoding as le, NoToneMapping as ue, WebGLRenderer as Ze } from "three";
12
+ var qe = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(qe || {});
13
+ const Qe = 45;
14
+ let b;
15
+ function Se() {
16
+ const { state: e, setState: n } = $(), o = Z("aspect-ratio");
17
+ function a(t = "Perspective", r) {
18
+ var l, s, i;
19
+ if (t === "Perspective") {
20
+ const { near: u, far: d, fov: p } = r || {
23
21
  near: 0.1,
24
22
  far: 1e3,
25
- fov: qe
23
+ fov: Qe
26
24
  };
27
- P = new _(u, ((s = e.aspectRatio) == null ? void 0 : s.value) || 1, c, a), B.cameras.push(P);
25
+ b = new z(p, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, u, d), (s = e.cameras) == null || s.push(b);
28
26
  } else {
29
- const { left: c, right: a, top: u, bottom: f, near: S, far: g } = t || {
27
+ const { left: u, right: d, top: p, bottom: m, near: g, far: R } = r || {
30
28
  left: -100,
31
29
  right: 100,
32
30
  top: 100,
@@ -34,34 +32,38 @@ function ye() {
34
32
  near: 0.1,
35
33
  far: 1e3
36
34
  };
37
- P = new he(c, a, u, f, S, g), B.cameras.push(P);
35
+ b = new ye(u, d, p, m, g, R), (i = e.cameras) == null || i.push(b);
38
36
  }
39
- return B.cameras.push(P), P;
37
+ return e.camera = b, n("camera", e.camera), b;
40
38
  }
41
- const r = me(() => B.cameras[0]);
42
- n("camera", r);
43
- function i() {
44
- r.value instanceof _ && e.aspectRatio && (r.value.aspect = e.aspectRatio.value), r.value.updateProjectionMatrix();
39
+ function c() {
40
+ var t;
41
+ e.camera instanceof z && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (t = e.camera) == null || t.updateProjectionMatrix();
45
42
  }
46
- function l(p) {
47
- B.cameras.push(p), p instanceof _ && e.aspectRatio && (p.aspect = e.aspectRatio.value), p.updateProjectionMatrix();
43
+ function f(t) {
44
+ var r;
45
+ (r = e.cameras) == null || r.push(t), t instanceof z && e.aspectRatio && (t.aspect = e.aspectRatio.value), t.updateProjectionMatrix(), n("camera", t);
48
46
  }
49
- return e.aspectRatio && U(e.aspectRatio, i), {
50
- activeCamera: r,
51
- createCamera: o,
52
- updateCamera: i,
53
- pushCamera: l
47
+ function h() {
48
+ e.cameras = [];
49
+ }
50
+ return o && j(o, c), {
51
+ activeCamera: $e(e, "camera"),
52
+ createCamera: a,
53
+ updateCamera: c,
54
+ pushCamera: f,
55
+ clearCameras: h
54
56
  };
55
57
  }
56
58
  const fe = "[TresJS ▲ ■ ●] ";
57
- function $() {
58
- function e(r, i) {
59
- console.error(`${fe} ${r}`, i || "");
59
+ function F() {
60
+ function e(a, c) {
61
+ console.error(`${fe} ${a}`, c || "");
60
62
  }
61
- function n(r) {
62
- console.warn(`${fe} ${r}`);
63
+ function n(a) {
64
+ console.warn(`${fe} ${a}`);
63
65
  }
64
- function o(r, i) {
66
+ function o(a, c) {
65
67
  }
66
68
  return {
67
69
  logError: e,
@@ -69,340 +71,367 @@ function $() {
69
71
  logMessage: o
70
72
  };
71
73
  }
72
- const N = R({ ...ce, uuid: ce.MathUtils.generateUUID() });
73
- delete N.value.Scene;
74
- let O;
75
- function Se(e, n = "Tres") {
76
- const { logError: o } = $();
77
- !O && e && (O = e);
78
- const { createComponentInstances: r } = Me(n);
74
+ const D = L({ ...ce, uuid: ce.MathUtils.generateUUID() });
75
+ delete D.value.Scene;
76
+ let A;
77
+ function et(e, n = "Tres") {
78
+ const { logError: o } = F();
79
+ !A && e && (A = e);
80
+ const { createComponentInstances: a } = Ce(n);
79
81
  return {
80
- extend: (l) => {
81
- if (!l) {
82
+ extend: (f) => {
83
+ if (!f) {
82
84
  o("No objects provided to extend catalogue");
83
85
  return;
84
86
  }
85
- N.value = Object.assign(N.value, l);
86
- const p = r(R(l));
87
- O && p.forEach(([t, s]) => {
88
- O._context.components[t] || O.component(t, s);
87
+ D.value = Object.assign(D.value, f);
88
+ const h = a(L(f));
89
+ A && h.forEach(([t, r]) => {
90
+ A._context.components[t] || A.component(t, r);
89
91
  });
90
92
  },
91
- catalogue: N
93
+ catalogue: D
92
94
  };
93
95
  }
94
- const A = (e) => typeof e < "u", Qe = (e) => typeof e == "function", G = (e) => !!e && e.constructor === Array;
95
- function Ze(e) {
96
+ const M = (e) => typeof e < "u", tt = (e) => typeof e == "function", N = (e) => !!e && e.constructor === Array;
97
+ function nt(e) {
96
98
  return typeof e == "number" ? [e, e, e] : e instanceof je ? [e.x, e.y, e.z] : e;
97
99
  }
98
- function et(e) {
99
- return e instanceof X ? e : Array.isArray(e) ? new X(...e) : new X(e);
100
+ function rt(e) {
101
+ return e instanceof K ? e : Array.isArray(e) ? new K(...e) : new K(e);
100
102
  }
101
- const tt = ["rotation", "scale", "position"];
102
- function Me(e) {
103
+ const pe = ["rotation", "scale", "position"], ot = ["X", "Y", "Z"], at = ["color"], it = ["r", "g", "b"];
104
+ function Ce(e) {
103
105
  const {
104
106
  /* logMessage, */
105
107
  logError: n
106
- } = $();
107
- function o(t, s) {
108
- A(t) && A(s) && Object.entries(t).forEach(([c, a]) => {
109
- const u = c.replace(/(-\w)/g, (f) => f[1].toUpperCase());
110
- s.setAttribute(u, new De(...a));
108
+ } = F();
109
+ function o(t, r) {
110
+ M(t) && M(r) && Object.entries(t).forEach(([l, s]) => {
111
+ const i = l.replace(/(-\w)/g, (u) => u[1].toUpperCase());
112
+ r.setAttribute(i, new We(...s));
111
113
  });
112
114
  }
113
- function r(t, s) {
114
- A(t) && A(s) && Object.entries(t).forEach(([c, a]) => {
115
- const u = c.replace(/(-\w)/g, (f) => f[1].toUpperCase());
116
- if (!(u === "args" || a === void 0)) {
117
- tt.includes(u) && a && (a = Ze(a)), t.ref && (t.ref = s);
115
+ function a(t, r) {
116
+ M(t) && M(r) && Object.entries(t).forEach(([l, s]) => {
117
+ const i = l.replace(/(-\w)/g, (g) => g[1].toUpperCase());
118
+ let u, d, p, m;
119
+ if (!(i === "args" || s === void 0)) {
120
+ pe.includes(i) && s ? s = nt(s) : pe.forEach((g) => {
121
+ i.startsWith(g) && i.length === g.length + 1 && (u = g, d = i.substring(g.length), ot.includes(d) || n(
122
+ // eslint-disable-next-line max-len
123
+ `There was an error setting ${l} property, ${d} is not a valid axis for ${u}`
124
+ ));
125
+ }), at.forEach((g) => {
126
+ i.startsWith(g) && i.length === g.length + 1 && (p = g, m = i.substring(g.length).toLowerCase(), it.includes(m) || n(`There was an error setting ${l} property , ${m} is not a valid axis for ${p}`));
127
+ }), t.ref && (t.ref = r);
118
128
  try {
119
- if (s[u] && A(s[u].set))
120
- s[u].set(...G(a) ? a : [a]);
129
+ if (r[i] && M(r[i].set))
130
+ r[i].set(...N(s) ? s : [s]);
131
+ else if (
132
+ // Check if the property has a "setAxis" method
133
+ u && r[u]
134
+ )
135
+ M(r[u][`set${d}`]) ? r[u][`set${d}`](s) : M(r[`rotate${d}`]) && r[`rotate${d}`](s);
136
+ else if (
137
+ // Check if the instance has a "color" property
138
+ p && m && r[p] && r[p][m]
139
+ )
140
+ r[p][m] = s;
121
141
  else {
122
- if (a === "" && (a = !0), Qe(s[u])) {
123
- if (c === "center" && !a)
142
+ if (s === "" && (s = !0), tt(r[i])) {
143
+ if (l === "center" && !s)
124
144
  return;
125
- s[u](...G(a) ? a : [a]);
145
+ r[i](...N(s) ? s : [s]);
126
146
  return;
127
147
  }
128
- s[u] = a;
148
+ r[i] = s;
129
149
  }
130
- } catch (f) {
131
- n(`There was an error setting ${u} property`, f);
150
+ } catch (g) {
151
+ n(`There was an error setting ${i} property`, g);
132
152
  }
133
153
  }
134
154
  });
135
155
  }
136
- function i(t) {
137
- var a, u;
138
- const s = /^Symbol\(Fragment\)$/g, c = /^Symbol\(Text\)$/g;
139
- if (s.test(t.type.toString()))
140
- return t.children.map((f) => i(f));
141
- if (c.test(t.type.toString()))
156
+ function c(t) {
157
+ var i, u;
158
+ const r = /^Symbol\(Fragment\)$/g, l = /^Symbol\(Text\)$/g, s = /^Symbol\(Comment\)$/g;
159
+ if (r.test(t.type.toString()))
160
+ return t.children.map((d) => c(d));
161
+ if (l.test(t.type.toString()) || s.test(t.type.toString()))
142
162
  return;
143
163
  {
144
- const f = t.type.name.replace(e, ""), { catalogue: S } = Se(), g = de("catalogue") || S;
145
- let w;
146
- if (g)
147
- if ((a = t.children) != null && a.default) {
148
- const C = t.children.default().map((b) => i(b));
149
- w = new g.value[f](...C.flat().filter(Boolean));
164
+ const d = t.type.name.replace(e, ""), p = Z("catalogue");
165
+ let m;
166
+ if (p)
167
+ if ((i = t.children) != null && i.default) {
168
+ const g = t.children.default().map((R) => c(R));
169
+ m = new p.value[d](...g.flat().filter(Boolean));
150
170
  } else
151
- (u = t == null ? void 0 : t.props) != null && u.args ? g != null && g.value[f] ? w = new g.value[f](...t.props.args) : n(`There is no ${f} in the catalogue`, g == null ? void 0 : g.value.uuid) : w = new g.value[f]();
152
- return t != null && t.props && (f === "BufferGeometry" ? o(t.props, w) : r(t.props, w)), w;
171
+ (u = t == null ? void 0 : t.props) != null && u.args ? p != null && p.value[d] ? m = new p.value[d](...t.props.args) : n(`There is no ${d} in the catalogue`, p == null ? void 0 : p.value.uuid) : m = new p.value[d]();
172
+ return t != null && t.props && (d === "BufferGeometry" ? o(t.props, m) : a(t.props, m)), m;
153
173
  }
154
174
  }
155
- function l(t, s, c) {
156
- if (c.default && (c != null && c.default())) {
157
- const a = c.default().map((u) => i(u));
175
+ function f(t, r, l) {
176
+ if (l.default && (l != null && l.default())) {
177
+ const s = l.default().map((i) => c(i));
158
178
  if (t.name === "Group") {
159
- const u = new t();
160
- return a.forEach((f) => {
161
- u.add(f);
162
- }), u;
179
+ const i = new t();
180
+ return s.forEach((u) => {
181
+ i.add(u);
182
+ }), i;
163
183
  } else
164
- return new t(...a.flat().filter(Boolean));
184
+ return new t(...s.flat().filter(Boolean));
165
185
  } else
166
- return s.args ? new t(...s.args) : new t();
186
+ return r.args ? new t(...r.args) : new t();
167
187
  }
168
- function p(t) {
169
- return Object.entries(t.value).filter(([s, c]) => {
170
- var a, u;
171
- return (u = (a = c == null ? void 0 : c.prototype) == null ? void 0 : a.constructor) == null ? void 0 : u.toString().includes("class");
172
- }).map(([s, c]) => {
173
- const a = `${e}${s}`, u = Z({
174
- name: a,
175
- setup(f, { slots: S, attrs: g, ...w }) {
176
- const { state: C } = T(), { onLoop: b } = re(), h = C.scene, j = C.raycaster, { pushCamera: E } = ye();
177
- let v = l(c, g, S);
178
- r(g, v), (v instanceof _ || v instanceof he) && E(v), v.isObject3D && (h == null || h.add(v));
179
- let M = null, y = null;
180
- if (v instanceof ke) {
181
- b(() => {
182
- if (v && j && (h != null && h.children)) {
183
- const z = j.intersectObjects(h == null ? void 0 : h.children);
184
- z.length > 0 ? (y = z[0], (M === null || M.object.uuid !== (y == null ? void 0 : y.object.uuid)) && w.emit("pointer-enter", y), w.emit("pointer-move", y)) : (y = null, M !== null && w.emit("pointer-leave", M)), M = y;
188
+ function h(t) {
189
+ return Object.entries(t.value).filter(([r, l]) => {
190
+ var s, i;
191
+ return (i = (s = l == null ? void 0 : l.prototype) == null ? void 0 : s.constructor) == null ? void 0 : i.toString().includes("class");
192
+ }).map(([r, l]) => {
193
+ const s = `${e}${r}`, i = q({
194
+ name: s,
195
+ setup(u, { slots: d, attrs: p, ...m }) {
196
+ const { state: g } = $(), { onLoop: R } = ne(), v = g.scene, _ = g.raycaster;
197
+ let S = f(l, p, d);
198
+ if (a(p, S), S instanceof z || S instanceof ye) {
199
+ const { pushCamera: O } = Se();
200
+ O(S);
201
+ }
202
+ S.isObject3D && (v == null || v.add(S));
203
+ let C = null, E = null;
204
+ if (S instanceof ze) {
205
+ R(() => {
206
+ if (S && _ && (v != null && v.children)) {
207
+ const x = _.intersectObjects(v == null ? void 0 : v.children);
208
+ x.length > 0 ? (E = x[0], (C === null || C.object.uuid !== (E == null ? void 0 : E.object.uuid)) && m.emit("pointer-enter", E), m.emit("pointer-move", E)) : (E = null, C !== null && m.emit("pointer-leave", C)), C = E;
185
209
  }
186
210
  });
187
- const k = Oe(window, "click", () => {
188
- w.emit("click", M);
211
+ const O = Be(window, "click", () => {
212
+ m.emit("click", C);
189
213
  });
190
214
  ge(() => {
191
- k();
215
+ O();
192
216
  });
193
217
  }
194
- return h && v instanceof ze && (h.fog = v), w.expose(v), () => {
218
+ return v && S instanceof De && (v.fog = S), m.expose(S), () => {
195
219
  };
196
220
  }
197
221
  });
198
- return [a, u];
222
+ return [s, i];
199
223
  });
200
224
  }
201
225
  return {
202
- createComponentInstances: p,
203
- processProps: r,
204
- createInstanceFromVNode: i
226
+ createComponentInstances: h,
227
+ processProps: a,
228
+ createInstanceFromVNode: c
205
229
  };
206
230
  }
207
- const Ce = te(), Ee = te(), ne = te(), F = new ve();
208
- let V = 0, W = 0;
209
- const { pause: nt, resume: rt, isActive: ot } = Ae(
231
+ const Ee = ee(), Re = ee(), te = ee(), I = new ve();
232
+ let W = 0, k = 0;
233
+ const { pause: st, resume: ct, isActive: lt } = Ie(
210
234
  () => {
211
- Ce.trigger({ delta: V, elapsed: W, clock: F }), Ee.trigger({ delta: V, elapsed: W, clock: F }), ne.trigger({ delta: V, elapsed: W, clock: F });
235
+ Ee.trigger({ delta: W, elapsed: k, clock: I }), Re.trigger({ delta: W, elapsed: k, clock: I }), te.trigger({ delta: W, elapsed: k, clock: I });
212
236
  },
213
237
  { immediate: !1 }
214
238
  );
215
- ne.on(() => {
216
- V = F.getDelta(), W = F.getElapsedTime();
239
+ te.on(() => {
240
+ W = I.getDelta(), k = I.getElapsedTime();
217
241
  });
218
- function re() {
242
+ function ne() {
219
243
  return {
220
- onBeforeLoop: Ce.on,
221
- onLoop: Ee.on,
222
- onAfterLoop: ne.on,
223
- pause: nt,
224
- resume: rt,
225
- isActive: ot
244
+ onBeforeLoop: Ee.on,
245
+ onLoop: Re.on,
246
+ onAfterLoop: te.on,
247
+ pause: st,
248
+ resume: ct,
249
+ isActive: lt
226
250
  };
227
251
  }
228
- const at = ee(new Ue());
229
- function st() {
252
+ const ut = Q(new ke());
253
+ function ft() {
230
254
  return {
231
- scene: at
255
+ scene: ut
232
256
  };
233
257
  }
234
- function it(e) {
258
+ function pt(e) {
235
259
  const n = { nodes: {}, materials: {} };
236
260
  return e && e.traverse((o) => {
237
261
  o.name && (n.nodes[o.name] = o), o.material && !n.materials[o.material.name] && (n.materials[o.material.name] = o.material);
238
262
  }), n;
239
263
  }
240
- async function gt(e, n, o, r, i) {
241
- const { logError: l } = $(), p = new e();
242
- i && i(p), o && o(p);
243
- const s = (Array.isArray(n) ? n : [n]).map(
244
- (c) => new Promise((a, u) => {
245
- p.load(
246
- c,
247
- (f) => {
248
- f.scene && Object.assign(f, it(f.scene)), a(f);
264
+ async function Ct(e, n, o, a, c) {
265
+ const { logError: f } = F(), h = new e();
266
+ c && c(h), o && o(h);
267
+ const r = (Array.isArray(n) ? n : [n]).map(
268
+ (l) => new Promise((s, i) => {
269
+ h.load(
270
+ l,
271
+ (u) => {
272
+ u.scene && Object.assign(u, pt(u.scene)), s(u);
249
273
  },
250
- r,
251
- (f) => u(l("[useLoader] - Failed to load resource", f))
274
+ a,
275
+ (u) => i(f("[useLoader] - Failed to load resource", u))
252
276
  );
253
277
  })
254
278
  );
255
- return G(n) ? await Promise.all(s) : await s[0];
279
+ return N(n) ? await Promise.all(r) : await r[0];
256
280
  }
257
- async function wt(e) {
258
- const n = new _e(), o = new Ne(n), r = (i) => new Promise((l, p) => {
281
+ async function Et(e) {
282
+ const n = new Ne(), o = new Ve(n), a = (c) => new Promise((f, h) => {
259
283
  o.load(
260
- i,
261
- (t) => l(t),
284
+ c,
285
+ (t) => f(t),
262
286
  () => null,
263
287
  () => {
264
- p(new Error("[useTextures] - Failed to load texture"));
288
+ h(new Error("[useTextures] - Failed to load texture"));
265
289
  }
266
290
  );
267
291
  });
268
- if (G(e)) {
269
- const i = await Promise.all(e.map((l) => r(l)));
270
- return e.length > 1 ? i : i[0];
292
+ if (N(e)) {
293
+ const c = await Promise.all(e.map((f) => a(f)));
294
+ return e.length > 1 ? c : c[0];
271
295
  } else {
272
- const { map: i, displacementMap: l, normalMap: p, roughnessMap: t, metalnessMap: s, aoMap: c } = e;
296
+ const { map: c, displacementMap: f, normalMap: h, roughnessMap: t, metalnessMap: r, aoMap: l } = e;
273
297
  return {
274
- map: i ? await r(i) : null,
275
- displacementMap: l ? await r(l) : null,
276
- normalMap: p ? await r(p) : null,
277
- roughnessMap: t ? await r(t) : null,
278
- metalnessMap: s ? await r(s) : null,
279
- aoMap: c ? await r(c) : null
298
+ map: c ? await a(c) : null,
299
+ displacementMap: f ? await a(f) : null,
300
+ normalMap: h ? await a(h) : null,
301
+ roughnessMap: t ? await a(t) : null,
302
+ metalnessMap: r ? await a(r) : null,
303
+ aoMap: l ? await a(l) : null
280
304
  };
281
305
  }
282
306
  }
283
- const D = be({});
284
- function T() {
307
+ const U = Oe({
308
+ camera: void 0,
309
+ cameras: [],
310
+ aspectRatio: he(() => window.innerWidth / window.innerHeight)
311
+ });
312
+ function $() {
285
313
  function e(o) {
286
- return D[o];
314
+ return U[o];
287
315
  }
288
- function n(o, r) {
289
- D[o] = r;
316
+ function n(o, a) {
317
+ U[o] = a;
290
318
  }
291
319
  return {
292
- state: D,
293
- ...we(D),
320
+ state: U,
321
+ ...we(U),
294
322
  getState: e,
295
323
  setState: n
296
324
  };
297
325
  }
298
- const Y = ee(new Ve()), I = R(new We()), pe = R(null);
299
- function ct() {
300
- const { setState: e } = T();
301
- e("raycaster", Y.value), e("pointer", I), e("currentInstance", pe), L("raycaster", Y), L("pointer", I), L("currentInstance", pe);
326
+ const X = Q(new He()), B = L(new Ge()), me = L(null);
327
+ function mt() {
328
+ const { setState: e } = $();
329
+ e("raycaster", X.value), e("pointer", B), e("currentInstance", me), T("raycaster", X), T("pointer", B), T("currentInstance", me);
302
330
  function n(o) {
303
- I.value.x = o.clientX / window.innerWidth * 2 - 1, I.value.y = -(o.clientY / window.innerHeight) * 2 + 1;
331
+ B.value.x = o.clientX / window.innerWidth * 2 - 1, B.value.y = -(o.clientY / window.innerHeight) * 2 + 1;
304
332
  }
305
333
  return window.addEventListener("pointermove", n), ge(() => {
306
334
  window.removeEventListener("pointermove", n);
307
335
  }), {
308
- raycaster: Y,
309
- pointer: I
336
+ raycaster: X,
337
+ pointer: B
310
338
  };
311
339
  }
312
- const q = {
340
+ const Y = {
313
341
  realistic: {
314
- physicallyCorrectLights: !0,
315
- outputEncoding: Ge,
316
- toneMapping: He,
342
+ outputEncoding: Ke,
343
+ toneMapping: Xe,
317
344
  toneMappingExposure: 3,
318
345
  shadowMap: {
319
346
  enabled: !0,
320
- type: Ke
347
+ type: Ye
321
348
  }
322
349
  }
323
- }, Re = (e, n) => {
350
+ }, Me = (e, n) => {
324
351
  for (const o of Object.keys(n))
325
- n[o] instanceof Object && Object.assign(n[o], Re(e[o], n[o]));
352
+ n[o] instanceof Object && Object.assign(n[o], Me(e[o], n[o]));
326
353
  return Object.assign(e || {}, n), e;
327
- }, d = ee(), Q = R(!1);
328
- function ut(e, n, o) {
354
+ }, y = Q(), J = L(!1);
355
+ function dt(e, n, o) {
329
356
  const {
330
- alpha: r = !0,
331
- antialias: i = !0,
332
- depth: l,
333
- logarithmicDepthBuffer: p,
357
+ alpha: a = !0,
358
+ antialias: c = !0,
359
+ depth: f,
360
+ logarithmicDepthBuffer: h,
334
361
  failIfMajorPerformanceCaveat: t,
335
- precision: s,
336
- premultipliedAlpha: c,
337
- stencil: a,
338
- shadows: u = !1,
339
- shadowMapType: f = Je,
340
- physicallyCorrectLights: S = !1,
341
- outputEncoding: g = ue,
342
- toneMapping: w = le,
343
- toneMappingExposure: C = 1,
344
- context: b = void 0,
345
- powerPreference: h = "default",
346
- preserveDrawingBuffer: j = !1,
347
- clearColor: E,
348
- windowSize: v = !1,
349
- preset: M = void 0
350
- } = we(o), { width: y, height: k } = m(v) ? Ie() : Fe(n), { logError: z } = $(), { pixelRatio: oe } = $e(), { pause: xe, resume: Pe } = re(), H = me(() => y.value / k.value), ae = () => {
351
- d.value && (d.value.setSize(y.value, k.value), d.value.setPixelRatio(Math.min(oe.value, 2)));
362
+ precision: r,
363
+ premultipliedAlpha: l,
364
+ stencil: s,
365
+ shadows: i = !1,
366
+ shadowMapType: u = Je,
367
+ physicallyCorrectLights: d = !1,
368
+ useLegacyLights: p = !1,
369
+ outputEncoding: m = le,
370
+ toneMapping: g = ue,
371
+ toneMappingExposure: R = 1,
372
+ context: v = void 0,
373
+ powerPreference: _ = "default",
374
+ preserveDrawingBuffer: S = !1,
375
+ clearColor: C,
376
+ windowSize: E = !1,
377
+ preset: O = void 0
378
+ } = we(o), { setState: x } = $(), { width: re, height: oe } = w(E) ? Fe() : _e(n), { logError: Le } = F(), { pixelRatio: ae } = Ue(), { pause: xe, resume: Pe } = ne(), V = he(() => re.value / oe.value), ie = () => {
379
+ y.value && (y.value.setSize(re.value, oe.value), y.value.setPixelRatio(Math.min(ae.value, 2)));
352
380
  }, se = () => {
353
- if (!d.value)
381
+ if (!y.value)
354
382
  return;
355
- const x = m(M);
356
- if (x) {
357
- x in q || z("Renderer Preset must be one of these: " + Object.keys(q).join(", ")), Re(d.value, q[x]);
383
+ const P = w(O);
384
+ if (P) {
385
+ P in Y || Le("Renderer Preset must be one of these: " + Object.keys(Y).join(", ")), Me(y.value, Y[P]);
358
386
  return;
359
387
  }
360
- d.value.shadowMap.enabled = m(u), d.value.shadowMap.type = m(f), d.value.toneMapping = m(w) || le, d.value.toneMappingExposure = m(C), d.value.outputEncoding = m(g) || ue, E != null && E.value && d.value.setClearColor(et(m(E))), d.value.physicallyCorrectLights = m(S);
361
- }, Le = () => {
362
- const x = J(e);
363
- if (d.value || !x)
364
- return;
365
- d.value = new Xe({
366
- canvas: x,
367
- alpha: m(r),
368
- antialias: m(i),
369
- context: m(b),
370
- depth: m(l),
371
- failIfMajorPerformanceCaveat: m(t),
372
- logarithmicDepthBuffer: m(p),
373
- powerPreference: m(h),
374
- precision: m(s),
375
- stencil: m(a),
376
- preserveDrawingBuffer: m(j),
377
- premultipliedAlpha: m(c)
378
- });
379
- const { setState: K } = T();
380
- K("renderer", d.value), K("clock", new ve()), K("aspectRatio", H), se(), ae(), Pe(), Q.value = !0;
388
+ y.value.shadowMap.enabled = w(i), y.value.shadowMap.type = w(u), y.value.toneMapping = w(g) || ue, y.value.toneMappingExposure = w(R), y.value.outputEncoding = w(m) || le, C != null && C.value && y.value.setClearColor(rt(w(C))), y.value.useLegacyLights = w(p);
389
+ }, be = () => {
390
+ const P = G(e);
391
+ y.value || !P || (y.value = new Ze({
392
+ canvas: P,
393
+ alpha: w(a),
394
+ antialias: w(c),
395
+ context: w(v),
396
+ depth: w(f),
397
+ failIfMajorPerformanceCaveat: w(t),
398
+ logarithmicDepthBuffer: w(h),
399
+ powerPreference: w(_),
400
+ precision: w(r),
401
+ stencil: w(s),
402
+ preserveDrawingBuffer: w(S),
403
+ premultipliedAlpha: w(l)
404
+ }), x("renderer", y.value), x("clock", new ve()), x("aspectRatio", V), se(), ie(), Pe(), J.value = !0);
381
405
  }, Te = () => {
382
- d.value && (d.value.dispose(), d.value = void 0, Q.value = !1, xe());
406
+ y.value && (y.value.dispose(), y.value = void 0, J.value = !1, xe());
383
407
  };
384
- return U([H, oe], ae), U(
385
- [u, f, g, S, w, C, E],
408
+ return j([V, ae], ie), j(
409
+ [i, u, m, p, g, R, C],
386
410
  se
387
- ), U(
411
+ ), j(
388
412
  () => [e, n],
389
413
  () => {
390
- J(e) && J(n) && Le();
414
+ G(e) && G(n) && be();
391
415
  },
392
416
  { immediate: !0, deep: !0 }
393
417
  ), {
394
- renderer: d,
395
- isReady: Q,
418
+ renderer: y,
419
+ isReady: J,
396
420
  dispose: Te,
397
- aspectRatio: H
421
+ aspectRatio: V
398
422
  };
399
423
  }
400
- const lt = Z({
424
+ const { logError: de, logWarning: gt } = F(), ht = q({
401
425
  name: "TresCanvas",
402
426
  props: {
403
427
  shadows: Boolean,
404
428
  shadowMapType: Number,
405
- physicallyCorrectLights: Boolean,
429
+ physicallyCorrectLights: {
430
+ type: Boolean,
431
+ default: !1,
432
+ validator: (e) => (e && gt("physicallyCorrectLights is deprecated. Use useLegacyLights instead."), !0)
433
+ },
434
+ useLegacyLights: Boolean,
406
435
  outputEncoding: Number,
407
436
  toneMapping: Number,
408
437
  toneMappingExposure: Number,
@@ -414,75 +443,90 @@ const lt = Z({
414
443
  preset: String
415
444
  },
416
445
  setup(e, { slots: n, attrs: o }) {
417
- const { logError: r } = $(), i = R(), l = R(), { renderer: p, dispose: t, aspectRatio: s } = ut(i, l, e);
418
- return L("aspect-ratio", s), L("renderer", p), n.default && !n.default().some((c) => c.type.name === "Scene") && r("TresCanvas must contain a Scene component."), n.default && !n.default().some((c) => {
419
- var a;
420
- return (a = c.type.name) == null ? void 0 : a.includes("Camera");
421
- }) && r("Scene must contain a Camera component."), Be(() => t()), () => {
446
+ const a = L(), c = L(), { renderer: f, dispose: h, aspectRatio: t } = dt(a, c, e);
447
+ return T("aspect-ratio", t), T("renderer", f), n.default && !n.default().some((r) => r.type.name === "Scene") && de("TresCanvas must contain a Scene component."), n.default && !n.default().some((r) => {
448
+ var l;
449
+ return (l = r.type.name) == null ? void 0 : l.includes("Camera");
450
+ }) && de("Scene must contain a Camera component."), Ae(() => h()), () => {
422
451
  if (n.default)
423
- return ie(
452
+ return H(
424
453
  "div",
425
454
  {
426
- ref: l,
455
+ ref: c,
427
456
  style: {
428
457
  position: "relative",
429
458
  width: "100%",
430
- height: "100vh",
459
+ height: "100%",
460
+ overflow: "hidden",
461
+ pointerEvents: "auto",
462
+ touchAction: "none",
431
463
  ...o.style
432
464
  }
433
465
  },
434
466
  [
435
- ie("canvas", {
436
- ref: i,
437
- style: {
438
- width: "100%",
439
- height: "100%",
440
- position: e.windowSize ? "fixed" : "absolute",
441
- top: 0,
442
- left: 0
443
- }
444
- }),
445
- n.default()
467
+ H(
468
+ "div",
469
+ {
470
+ style: {
471
+ width: "100%",
472
+ height: "100%"
473
+ }
474
+ },
475
+ [
476
+ H("canvas", {
477
+ ref: a,
478
+ style: {
479
+ display: "block",
480
+ width: "100%",
481
+ height: "100%",
482
+ position: e.windowSize ? "fixed" : "absolute",
483
+ top: 0,
484
+ left: 0
485
+ }
486
+ }),
487
+ n.default()
488
+ ]
489
+ )
446
490
  ]
447
491
  );
448
492
  };
449
493
  }
450
- }), ft = Z({
494
+ }), wt = q({
451
495
  name: "Scene",
452
496
  setup(e, { slots: n }) {
453
- const { setState: o } = T(), { scene: r } = st(), i = de("renderer"), { activeCamera: l } = ye(), { raycaster: p, pointer: t } = ct(), { onLoop: s } = re();
454
- return L("local-scene", r), o("scene", r.value), s(() => {
455
- p.value.setFromCamera(t.value, l.value), i != null && i.value && (l != null && l.value) && (r != null && r.value) && i.value.render(r == null ? void 0 : r.value, l.value);
497
+ const { setState: o } = $(), { scene: a } = ft(), c = Z("renderer"), { activeCamera: f } = Se(), { raycaster: h, pointer: t } = mt(), { onLoop: r } = ne();
498
+ return T("local-scene", a), o("scene", a.value), r(() => {
499
+ f.value && (h.value.setFromCamera(t.value, f.value), c != null && c.value && f && (a != null && a.value) && c.value.render(a == null ? void 0 : a.value, f.value));
456
500
  }), () => {
457
501
  if (n.default)
458
502
  return n.default();
459
503
  };
460
504
  }
461
- }), ht = Symbol("UseTresState"), vt = {
505
+ }), Rt = Symbol("UseTresState"), Mt = {
462
506
  install(e, n) {
463
507
  const o = (n == null ? void 0 : n.prefix) || "Tres";
464
- e.component(`${o}Canvas`, lt), e.component(`${o}Scene`, ft);
465
- const { catalogue: r, extend: i } = Se(e, o);
466
- e.provide("catalogue", r), e.provide("extend", i), e.provide("useTres", T());
467
- const { createComponentInstances: l } = Me(o);
468
- l(r).forEach(([t, s]) => {
469
- e.component(t, s);
508
+ e.component(`${o}Canvas`, ht), e.component(`${o}Scene`, wt);
509
+ const { catalogue: a, extend: c } = et(e, o);
510
+ e.provide("catalogue", a), e.provide("extend", c), e.provide("useTres", $());
511
+ const { createComponentInstances: f } = Ce(o);
512
+ f(a).forEach(([t, r]) => {
513
+ e.component(t, r);
470
514
  });
471
515
  }
472
516
  };
473
517
  export {
474
- Ye as CameraType,
475
- ht as UseTresStateSymbol,
476
- vt as default,
477
- it as trasverseObjects,
478
- ye as useCamera,
479
- Se as useCatalogue,
480
- Me as useInstanceCreator,
481
- gt as useLoader,
482
- ct as useRaycaster,
483
- re as useRenderLoop,
484
- ut as useRenderer,
485
- st as useScene,
486
- wt as useTexture,
487
- T as useTres
518
+ qe as CameraType,
519
+ Rt as UseTresStateSymbol,
520
+ Mt as default,
521
+ pt as trasverseObjects,
522
+ Se as useCamera,
523
+ et as useCatalogue,
524
+ Ce as useInstanceCreator,
525
+ Ct as useLoader,
526
+ mt as useRaycaster,
527
+ ne as useRenderLoop,
528
+ dt as useRenderer,
529
+ ft as useScene,
530
+ Et as useTexture,
531
+ $ as useTres
488
532
  };