@tresjs/core 1.7.0 → 1.8.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/dist/tres.js CHANGED
@@ -1,32 +1,30 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v1.7.0
3
+ * version: v1.8.0
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";
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;
8
+ import { watch as j, toRef as Oe, ref as M, inject as de, defineComponent as Q, onUnmounted as ge, shallowRef as ee, shallowReactive as Ae, computed as he, toRefs as we, provide as b, onBeforeUnmount as Be, h as K } from "vue";
9
+ import { useEventListener as Ie, createEventHook as te, useRafFn as Fe, resolveUnref as h, useWindowSize as _e, useElementSize as Ue, useDevicePixelRatio as je, unrefElement as X } from "@vueuse/core";
10
+ import * as se from "three";
11
+ import { PerspectiveCamera as z, OrthographicCamera as ye, Vector3 as ze, Color as Y, Mesh as De, Fog as We, BufferAttribute as ke, Clock as ve, Scene as Ne, LoadingManager as Ve, TextureLoader as He, Raycaster as Ge, Vector2 as Ke, sRGBEncoding as Xe, ACESFilmicToneMapping as Ye, PCFSoftShadowMap as Je, PCFShadowMap as Ze, LinearEncoding as ce, NoToneMapping as le, WebGLRenderer as qe } from "three";
12
+ var Qe = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Qe || {});
13
+ const et = 45;
16
14
  let P;
17
- function ye() {
15
+ function Se() {
18
16
  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 || {
17
+ function o(u = "Perspective", t) {
18
+ var r, l, s;
19
+ if (u === "Perspective") {
20
+ const { near: i, far: f, fov: g } = t || {
23
21
  near: 0.1,
24
22
  far: 1e3,
25
- fov: qe
23
+ fov: et
26
24
  };
27
- P = new _(u, ((s = e.aspectRatio) == null ? void 0 : s.value) || 1, c, a), B.cameras.push(P);
25
+ P = new z(g, ((r = e.aspectRatio) == null ? void 0 : r.value) || window.innerWidth / window.innerHeight, i, f), (l = e.cameras) == null || l.push(P);
28
26
  } else {
29
- const { left: c, right: a, top: u, bottom: f, near: S, far: g } = t || {
27
+ const { left: i, right: f, top: g, bottom: v, near: p, far: m } = t || {
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
+ P = new ye(i, f, g, v, p, m), (s = e.cameras) == null || s.push(P);
38
36
  }
39
- return B.cameras.push(P), P;
37
+ return e.camera = P, n("camera", e.camera), P;
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 a() {
40
+ var u;
41
+ e.camera instanceof z && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (u = e.camera) == null || u.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 c(u) {
44
+ var t;
45
+ (t = e.cameras) == null || t.push(u), u instanceof z && e.aspectRatio && (u.aspect = e.aspectRatio.value), u.updateProjectionMatrix(), n("camera", u);
48
46
  }
49
- return e.aspectRatio && U(e.aspectRatio, i), {
50
- activeCamera: r,
47
+ function d() {
48
+ e.cameras = [];
49
+ }
50
+ return e.aspectRatio && j(e.aspectRatio, a), {
51
+ activeCamera: Oe(e, "camera"),
51
52
  createCamera: o,
52
- updateCamera: i,
53
- pushCamera: l
53
+ updateCamera: a,
54
+ pushCamera: c,
55
+ clearCameras: d
54
56
  };
55
57
  }
56
- const fe = "[TresJS ▲ ■ ●] ";
57
- function $() {
58
- function e(r, i) {
59
- console.error(`${fe} ${r}`, i || "");
58
+ const ue = "[TresJS ▲ ■ ●] ";
59
+ function I() {
60
+ function e(a, c) {
61
+ console.error(`${ue} ${a}`, c || "");
60
62
  }
61
- function n(r) {
62
- console.warn(`${fe} ${r}`);
63
+ function n(a) {
64
+ console.warn(`${ue} ${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
+ const D = M({ ...se, uuid: se.MathUtils.generateUUID() });
75
+ delete D.value.Scene;
74
76
  let O;
75
- function Se(e, n = "Tres") {
76
- const { logError: o } = $();
77
+ function Ce(e, n = "Tres") {
78
+ const { logError: o } = I();
77
79
  !O && e && (O = e);
78
- const { createComponentInstances: r } = Me(n);
80
+ const { createComponentInstances: a } = Ee(n);
79
81
  return {
80
- extend: (l) => {
81
- if (!l) {
82
+ extend: (d) => {
83
+ if (!d) {
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, d);
88
+ const u = a(M(d));
89
+ O && u.forEach(([t, r]) => {
90
+ O._context.components[t] || O.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
- return typeof e == "number" ? [e, e, e] : e instanceof je ? [e.x, e.y, e.z] : e;
96
+ const R = (e) => typeof e < "u", tt = (e) => typeof e == "function", N = (e) => !!e && e.constructor === Array;
97
+ function nt(e) {
98
+ return typeof e == "number" ? [e, e, e] : e instanceof ze ? [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 Y ? e : Array.isArray(e) ? new Y(...e) : new Y(e);
100
102
  }
101
- const tt = ["rotation", "scale", "position"];
102
- function Me(e) {
103
+ const fe = ["rotation", "scale", "position"], ot = ["X", "Y", "Z"], at = ["color"], it = ["r", "g", "b"];
104
+ function Ee(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
+ } = I();
109
+ function o(t, r) {
110
+ R(t) && R(r) && Object.entries(t).forEach(([l, s]) => {
111
+ const i = l.replace(/(-\w)/g, (f) => f[1].toUpperCase());
112
+ r.setAttribute(i, new ke(...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
+ R(t) && R(r) && Object.entries(t).forEach(([l, s]) => {
117
+ const i = l.replace(/(-\w)/g, (m) => m[1].toUpperCase());
118
+ let f, g, v, p;
119
+ if (!(i === "args" || s === void 0)) {
120
+ fe.includes(i) && s ? s = nt(s) : fe.forEach((m) => {
121
+ i.startsWith(m) && i.length === m.length + 1 && (f = m, g = i.substring(m.length), ot.includes(g) || n(
122
+ // eslint-disable-next-line max-len
123
+ `There was an error setting ${l} property, ${g} is not a valid axis for ${f}`
124
+ ));
125
+ }), at.forEach((m) => {
126
+ i.startsWith(m) && i.length === m.length + 1 && (v = m, p = i.substring(m.length).toLowerCase(), it.includes(p) || n(`There was an error setting ${l} property , ${p} is not a valid axis for ${v}`));
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] && R(r[i].set))
130
+ r[i].set(...N(s) ? s : [s]);
131
+ else if (
132
+ // Check if the property has a "setAxis" method
133
+ f && r[f]
134
+ )
135
+ R(r[f][`set${g}`]) ? r[f][`set${g}`](s) : R(r[`rotate${g}`]) && r[`rotate${g}`](s);
136
+ else if (
137
+ // Check if the instance has a "color" property
138
+ v && p && r[v] && r[v][p]
139
+ )
140
+ r[v][p] = 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 (m) {
151
+ n(`There was an error setting ${i} property`, m);
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, f;
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((g) => c(g));
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 g = t.type.name.replace(e, ""), { catalogue: v } = Ce(), p = de("catalogue") || v;
165
+ let m;
166
+ if (p)
167
+ if ((i = t.children) != null && i.default) {
168
+ const L = t.children.default().map((S) => c(S));
169
+ m = new p.value[g](...L.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
+ (f = t == null ? void 0 : t.props) != null && f.args ? p != null && p.value[g] ? m = new p.value[g](...t.props.args) : n(`There is no ${g} in the catalogue`, p == null ? void 0 : p.value.uuid) : m = new p.value[g]();
172
+ return t != null && t.props && (g === "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 d(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((f) => {
181
+ i.add(f);
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 u(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(f, { slots: g, attrs: v, ...p }) {
196
+ const { state: m } = T(), { onLoop: L } = re(), S = m.scene, F = m.raycaster, { pushCamera: V } = Se();
197
+ let y = d(l, v, g);
198
+ a(v, y), (y instanceof z || y instanceof ye) && V(y), y.isObject3D && (S == null || S.add(y));
199
+ let E = null, C = null;
200
+ if (y instanceof De) {
201
+ L(() => {
202
+ if (y && F && (S != null && S.children)) {
203
+ const $ = F.intersectObjects(S == null ? void 0 : S.children);
204
+ $.length > 0 ? (C = $[0], (E === null || E.object.uuid !== (C == null ? void 0 : C.object.uuid)) && p.emit("pointer-enter", C), p.emit("pointer-move", C)) : (C = null, E !== null && p.emit("pointer-leave", E)), E = C;
185
205
  }
186
206
  });
187
- const k = Oe(window, "click", () => {
188
- w.emit("click", M);
207
+ const _ = Ie(window, "click", () => {
208
+ p.emit("click", E);
189
209
  });
190
210
  ge(() => {
191
- k();
211
+ _();
192
212
  });
193
213
  }
194
- return h && v instanceof ze && (h.fog = v), w.expose(v), () => {
214
+ return S && y instanceof We && (S.fog = y), p.expose(y), () => {
195
215
  };
196
216
  }
197
217
  });
198
- return [a, u];
218
+ return [s, i];
199
219
  });
200
220
  }
201
221
  return {
202
- createComponentInstances: p,
203
- processProps: r,
204
- createInstanceFromVNode: i
222
+ createComponentInstances: u,
223
+ processProps: a,
224
+ createInstanceFromVNode: c
205
225
  };
206
226
  }
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(
227
+ const Re = te(), Me = te(), ne = te(), B = new ve();
228
+ let W = 0, k = 0;
229
+ const { pause: st, resume: ct, isActive: lt } = Fe(
210
230
  () => {
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 });
231
+ Re.trigger({ delta: W, elapsed: k, clock: B }), Me.trigger({ delta: W, elapsed: k, clock: B }), ne.trigger({ delta: W, elapsed: k, clock: B });
212
232
  },
213
233
  { immediate: !1 }
214
234
  );
215
235
  ne.on(() => {
216
- V = F.getDelta(), W = F.getElapsedTime();
236
+ W = B.getDelta(), k = B.getElapsedTime();
217
237
  });
218
238
  function re() {
219
239
  return {
220
- onBeforeLoop: Ce.on,
221
- onLoop: Ee.on,
240
+ onBeforeLoop: Re.on,
241
+ onLoop: Me.on,
222
242
  onAfterLoop: ne.on,
223
- pause: nt,
224
- resume: rt,
225
- isActive: ot
243
+ pause: st,
244
+ resume: ct,
245
+ isActive: lt
226
246
  };
227
247
  }
228
- const at = ee(new Ue());
229
- function st() {
248
+ const ut = ee(new Ne());
249
+ function ft() {
230
250
  return {
231
- scene: at
251
+ scene: ut
232
252
  };
233
253
  }
234
- function it(e) {
254
+ function pt(e) {
235
255
  const n = { nodes: {}, materials: {} };
236
256
  return e && e.traverse((o) => {
237
257
  o.name && (n.nodes[o.name] = o), o.material && !n.materials[o.material.name] && (n.materials[o.material.name] = o.material);
238
258
  }), n;
239
259
  }
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,
260
+ async function Ct(e, n, o, a, c) {
261
+ const { logError: d } = I(), u = new e();
262
+ c && c(u), o && o(u);
263
+ const r = (Array.isArray(n) ? n : [n]).map(
264
+ (l) => new Promise((s, i) => {
265
+ u.load(
266
+ l,
247
267
  (f) => {
248
- f.scene && Object.assign(f, it(f.scene)), a(f);
268
+ f.scene && Object.assign(f, pt(f.scene)), s(f);
249
269
  },
250
- r,
251
- (f) => u(l("[useLoader] - Failed to load resource", f))
270
+ a,
271
+ (f) => i(d("[useLoader] - Failed to load resource", f))
252
272
  );
253
273
  })
254
274
  );
255
- return G(n) ? await Promise.all(s) : await s[0];
275
+ return N(n) ? await Promise.all(r) : await r[0];
256
276
  }
257
- async function wt(e) {
258
- const n = new _e(), o = new Ne(n), r = (i) => new Promise((l, p) => {
277
+ async function Et(e) {
278
+ const n = new Ve(), o = new He(n), a = (c) => new Promise((d, u) => {
259
279
  o.load(
260
- i,
261
- (t) => l(t),
280
+ c,
281
+ (t) => d(t),
262
282
  () => null,
263
283
  () => {
264
- p(new Error("[useTextures] - Failed to load texture"));
284
+ u(new Error("[useTextures] - Failed to load texture"));
265
285
  }
266
286
  );
267
287
  });
268
- if (G(e)) {
269
- const i = await Promise.all(e.map((l) => r(l)));
270
- return e.length > 1 ? i : i[0];
288
+ if (N(e)) {
289
+ const c = await Promise.all(e.map((d) => a(d)));
290
+ return e.length > 1 ? c : c[0];
271
291
  } else {
272
- const { map: i, displacementMap: l, normalMap: p, roughnessMap: t, metalnessMap: s, aoMap: c } = e;
292
+ const { map: c, displacementMap: d, normalMap: u, roughnessMap: t, metalnessMap: r, aoMap: l } = e;
273
293
  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
294
+ map: c ? await a(c) : null,
295
+ displacementMap: d ? await a(d) : null,
296
+ normalMap: u ? await a(u) : null,
297
+ roughnessMap: t ? await a(t) : null,
298
+ metalnessMap: r ? await a(r) : null,
299
+ aoMap: l ? await a(l) : null
280
300
  };
281
301
  }
282
302
  }
283
- const D = be({});
303
+ const U = Ae({
304
+ camera: void 0,
305
+ cameras: [],
306
+ aspectRatio: he(() => window.innerWidth / window.innerHeight)
307
+ });
284
308
  function T() {
285
309
  function e(o) {
286
- return D[o];
310
+ return U[o];
287
311
  }
288
- function n(o, r) {
289
- D[o] = r;
312
+ function n(o, a) {
313
+ U[o] = a;
290
314
  }
291
315
  return {
292
- state: D,
293
- ...we(D),
316
+ state: U,
317
+ ...we(U),
294
318
  getState: e,
295
319
  setState: n
296
320
  };
297
321
  }
298
- const Y = ee(new Ve()), I = R(new We()), pe = R(null);
299
- function ct() {
322
+ const J = ee(new Ge()), A = M(new Ke()), pe = M(null);
323
+ function mt() {
300
324
  const { setState: e } = T();
301
- e("raycaster", Y.value), e("pointer", I), e("currentInstance", pe), L("raycaster", Y), L("pointer", I), L("currentInstance", pe);
325
+ e("raycaster", J.value), e("pointer", A), e("currentInstance", pe), b("raycaster", J), b("pointer", A), b("currentInstance", pe);
302
326
  function n(o) {
303
- I.value.x = o.clientX / window.innerWidth * 2 - 1, I.value.y = -(o.clientY / window.innerHeight) * 2 + 1;
327
+ A.value.x = o.clientX / window.innerWidth * 2 - 1, A.value.y = -(o.clientY / window.innerHeight) * 2 + 1;
304
328
  }
305
329
  return window.addEventListener("pointermove", n), ge(() => {
306
330
  window.removeEventListener("pointermove", n);
307
331
  }), {
308
- raycaster: Y,
309
- pointer: I
332
+ raycaster: J,
333
+ pointer: A
310
334
  };
311
335
  }
312
- const q = {
336
+ const Z = {
313
337
  realistic: {
314
- physicallyCorrectLights: !0,
315
- outputEncoding: Ge,
316
- toneMapping: He,
338
+ outputEncoding: Xe,
339
+ toneMapping: Ye,
317
340
  toneMappingExposure: 3,
318
341
  shadowMap: {
319
342
  enabled: !0,
320
- type: Ke
343
+ type: Je
321
344
  }
322
345
  }
323
- }, Re = (e, n) => {
346
+ }, Le = (e, n) => {
324
347
  for (const o of Object.keys(n))
325
- n[o] instanceof Object && Object.assign(n[o], Re(e[o], n[o]));
348
+ n[o] instanceof Object && Object.assign(n[o], Le(e[o], n[o]));
326
349
  return Object.assign(e || {}, n), e;
327
- }, d = ee(), Q = R(!1);
328
- function ut(e, n, o) {
350
+ }, w = ee(), q = M(!1);
351
+ function dt(e, n, o) {
329
352
  const {
330
- alpha: r = !0,
331
- antialias: i = !0,
332
- depth: l,
333
- logarithmicDepthBuffer: p,
353
+ alpha: a = !0,
354
+ antialias: c = !0,
355
+ depth: d,
356
+ logarithmicDepthBuffer: u,
334
357
  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)));
352
- }, se = () => {
353
- if (!d.value)
358
+ precision: r,
359
+ premultipliedAlpha: l,
360
+ stencil: s,
361
+ shadows: i = !1,
362
+ shadowMapType: f = Ze,
363
+ physicallyCorrectLights: g = !1,
364
+ useLegacyLights: v = !1,
365
+ outputEncoding: p = ce,
366
+ toneMapping: m = le,
367
+ toneMappingExposure: L = 1,
368
+ context: S = void 0,
369
+ powerPreference: F = "default",
370
+ preserveDrawingBuffer: V = !1,
371
+ clearColor: y,
372
+ windowSize: E = !1,
373
+ preset: C = void 0
374
+ } = we(o), { width: _, height: $ } = h(E) ? _e() : Ue(n), { logError: xe } = I(), { pixelRatio: oe } = je(), { pause: Pe, resume: be } = re(), H = he(() => _.value / $.value), ae = () => {
375
+ w.value && (w.value.setSize(_.value, $.value), w.value.setPixelRatio(Math.min(oe.value, 2)));
376
+ }, ie = () => {
377
+ if (!w.value)
354
378
  return;
355
- const x = m(M);
379
+ const x = h(C);
356
380
  if (x) {
357
- x in q || z("Renderer Preset must be one of these: " + Object.keys(q).join(", ")), Re(d.value, q[x]);
381
+ x in Z || xe("Renderer Preset must be one of these: " + Object.keys(Z).join(", ")), Le(w.value, Z[x]);
358
382
  return;
359
383
  }
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)
384
+ w.value.shadowMap.enabled = h(i), w.value.shadowMap.type = h(f), w.value.toneMapping = h(m) || le, w.value.toneMappingExposure = h(L), w.value.outputEncoding = h(p) || ce, y != null && y.value && w.value.setClearColor(rt(h(y))), w.value.useLegacyLights = h(v);
385
+ }, Te = () => {
386
+ const x = X(e);
387
+ if (w.value || !x)
364
388
  return;
365
- d.value = new Xe({
389
+ w.value = new qe({
366
390
  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)
391
+ alpha: h(a),
392
+ antialias: h(c),
393
+ context: h(S),
394
+ depth: h(d),
395
+ failIfMajorPerformanceCaveat: h(t),
396
+ logarithmicDepthBuffer: h(u),
397
+ powerPreference: h(F),
398
+ precision: h(r),
399
+ stencil: h(s),
400
+ preserveDrawingBuffer: h(V),
401
+ premultipliedAlpha: h(l)
378
402
  });
379
- const { setState: K } = T();
380
- K("renderer", d.value), K("clock", new ve()), K("aspectRatio", H), se(), ae(), Pe(), Q.value = !0;
381
- }, Te = () => {
382
- d.value && (d.value.dispose(), d.value = void 0, Q.value = !1, xe());
403
+ const { setState: G } = T();
404
+ G("renderer", w.value), G("clock", new ve()), G("aspectRatio", H), ie(), ae(), be(), q.value = !0;
405
+ }, $e = () => {
406
+ w.value && (w.value.dispose(), w.value = void 0, q.value = !1, Pe());
383
407
  };
384
- return U([H, oe], ae), U(
385
- [u, f, g, S, w, C, E],
386
- se
387
- ), U(
408
+ return j([H, oe], ae), j(
409
+ [i, f, p, v, m, L, y],
410
+ ie
411
+ ), j(
388
412
  () => [e, n],
389
413
  () => {
390
- J(e) && J(n) && Le();
414
+ X(e) && X(n) && Te();
391
415
  },
392
416
  { immediate: !0, deep: !0 }
393
417
  ), {
394
- renderer: d,
395
- isReady: Q,
396
- dispose: Te,
418
+ renderer: w,
419
+ isReady: q,
420
+ dispose: $e,
397
421
  aspectRatio: H
398
422
  };
399
423
  }
400
- const lt = Z({
424
+ const { logError: me, logWarning: gt } = I(), 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 = M(), c = M(), { renderer: d, dispose: u, aspectRatio: t } = dt(a, c, e);
447
+ return b("aspect-ratio", t), b("renderer", d), n.default && !n.default().some((r) => r.type.name === "Scene") && me("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
+ }) && me("Scene must contain a Camera component."), Be(() => u()), () => {
422
451
  if (n.default)
423
- return ie(
452
+ return K(
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
+ K(
468
+ "div",
469
+ {
470
+ style: {
471
+ width: "100%",
472
+ height: "100%"
473
+ }
474
+ },
475
+ [
476
+ K("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 } = T(), { scene: a } = ft(), c = de("renderer"), { activeCamera: d } = Se(), { raycaster: u, pointer: t } = mt(), { onLoop: r } = re();
498
+ return b("local-scene", a), o("scene", a.value), r(() => {
499
+ d.value && (u.value.setFromCamera(t.value, d.value), c != null && c.value && d && (a != null && a.value) && c.value.render(a == null ? void 0 : a.value, d.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 } = Ce(e, o);
510
+ e.provide("catalogue", a), e.provide("extend", c), e.provide("useTres", T());
511
+ const { createComponentInstances: d } = Ee(o);
512
+ d(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,
518
+ Qe as CameraType,
519
+ Rt as UseTresStateSymbol,
520
+ Mt as default,
521
+ pt as trasverseObjects,
522
+ Se as useCamera,
523
+ Ce as useCatalogue,
524
+ Ee as useInstanceCreator,
525
+ Ct as useLoader,
526
+ mt as useRaycaster,
483
527
  re as useRenderLoop,
484
- ut as useRenderer,
485
- st as useScene,
486
- wt as useTexture,
528
+ dt as useRenderer,
529
+ ft as useScene,
530
+ Et as useTexture,
487
531
  T as useTres
488
532
  };