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