@tresjs/core 3.6.0 → 4.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tres.js CHANGED
@@ -1,432 +1,489 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v3.6.0
3
+ * version: v4.0.0-next.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 { ref as B, computed as b, watchEffect as D, onUnmounted as $, shallowRef as L, watch as re, reactive as pe, readonly as de, provide as V, inject as ve, createRenderer as ge, defineComponent as q, useSlots as ye, getCurrentInstance as J, onMounted as we, openBlock as Ee, createElementBlock as Ce, normalizeClass as _e, normalizeStyle as Me, h as K, Fragment as he } from "vue";
9
- import * as Pe from "three";
10
- import { PerspectiveCamera as G, OrthographicCamera as Ae, Camera as ke, Clock as be, Vector3 as De, Color as F, REVISION as Te, SRGBColorSpace as Le, ACESFilmicToneMapping as Se, PCFSoftShadowMap as Be, WebGLRenderer as I, LoadingManager as xe, TextureLoader as Oe, Vector2 as Re, Raycaster as He, BufferAttribute as Fe, Scene as je } from "three";
11
- import { createEventHook as S, useRafFn as ne, toValue as M, unrefElement as ze, useDevicePixelRatio as $e, usePointer as Ne, useElementBounding as Ie, useWindowSize as Ve, useElementSize as Ge, useFps as We, useMemory as Ue } from "@vueuse/core";
12
- const Ye = ({ sizes: e, scene: a }) => {
13
- const t = B([]), r = b(
8
+ var Me = Object.defineProperty;
9
+ var Pe = (e, r, t) => r in e ? Me(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
10
+ var G = (e, r, t) => (Pe(e, typeof r != "symbol" ? r + "" : r, t), t);
11
+ import { ref as B, computed as k, watchEffect as A, onUnmounted as U, shallowRef as D, watch as ie, reactive as le, readonly as Se, provide as Q, inject as ke, createRenderer as Te, defineComponent as Z, useSlots as Oe, getCurrentInstance as ee, onMounted as Ae, openBlock as xe, createElementBlock as De, normalizeClass as Le, normalizeStyle as Be, h as te, Fragment as je } from "vue";
12
+ import * as ue from "three";
13
+ import { PerspectiveCamera as Y, OrthographicCamera as Ie, Camera as Re, Clock as He, Vector3 as Ne, Color as N, MeshBasicMaterial as Ve, DoubleSide as $e, REVISION as Ue, SRGBColorSpace as Fe, ACESFilmicToneMapping as Ge, PCFSoftShadowMap as ze, WebGLRenderer as z, LoadingManager as We, TextureLoader as Qe, Vector2 as Ye, Raycaster as Je, BufferAttribute as Ke, Scene as qe } from "three";
14
+ import { createEventHook as L, useRafFn as ce, toValue as E, unrefElement as Xe, useDevicePixelRatio as Ze, usePointer as et, useElementBounding as tt, useWindowSize as rt, useElementSize as nt, useFps as ot, useMemory as at } from "@vueuse/core";
15
+ const st = ({ sizes: e, scene: r }) => {
16
+ const t = B([]), n = k(
14
17
  () => t.value[0]
15
- ), n = (s, l = !1) => {
16
- t.value.some(({ uuid: i }) => i === s.uuid) || (l ? c(s) : t.value.push(s));
17
- }, o = (s) => {
18
- t.value = t.value.filter(({ uuid: l }) => l !== s.uuid);
19
- }, c = (s) => {
20
- const l = s instanceof ke ? s : t.value.find((p) => p.uuid === s);
18
+ ), a = (i, l = !1) => {
19
+ t.value.some(({ uuid: c }) => c === i.uuid) || (l ? o(i) : t.value.push(i));
20
+ }, s = (i) => {
21
+ t.value = t.value.filter(({ uuid: l }) => l !== i.uuid);
22
+ }, o = (i) => {
23
+ const l = i instanceof Re ? i : t.value.find((m) => m.uuid === i);
21
24
  if (!l)
22
25
  return;
23
- const i = t.value.filter(({ uuid: p }) => p !== l.uuid);
24
- t.value = [l, ...i];
26
+ const c = t.value.filter(({ uuid: m }) => m !== l.uuid);
27
+ t.value = [l, ...c];
25
28
  };
26
- return D(() => {
27
- e.aspectRatio.value && t.value.forEach((s) => {
28
- s instanceof G && (s.aspect = e.aspectRatio.value), (s instanceof G || s instanceof Ae) && s.updateProjectionMatrix();
29
+ return A(() => {
30
+ e.aspectRatio.value && t.value.forEach((i) => {
31
+ i instanceof Y && (i.aspect = e.aspectRatio.value), (i instanceof Y || i instanceof Ie) && i.updateProjectionMatrix();
29
32
  });
30
- }), a.userData.tres__registerCamera = n, a.userData.tres__deregisterCamera = o, $(() => {
33
+ }), r.userData.tres__registerCamera = a, r.userData.tres__deregisterCamera = s, U(() => {
31
34
  t.value = [];
32
35
  }), {
33
- camera: r,
36
+ camera: n,
34
37
  cameras: t,
35
- registerCamera: n,
36
- deregisterCamera: o,
37
- setCameraActive: c
38
+ registerCamera: a,
39
+ deregisterCamera: s,
40
+ setCameraActive: o
38
41
  };
39
- }, ae = S(), oe = S(), U = S(), T = new be();
40
- let j = 0, z = 0;
41
- const { pause: qe, resume: Je, isActive: Ke } = ne(
42
+ }, fe = L(), de = L(), q = L(), x = new He();
43
+ let V = 0, $ = 0;
44
+ const { pause: it, resume: lt, isActive: ut } = ce(
42
45
  () => {
43
- ae.trigger({ delta: j, elapsed: z, clock: T }), oe.trigger({ delta: j, elapsed: z, clock: T }), U.trigger({ delta: j, elapsed: z, clock: T });
46
+ fe.trigger({ delta: V, elapsed: $, clock: x }), de.trigger({ delta: V, elapsed: $, clock: x }), q.trigger({ delta: V, elapsed: $, clock: x });
44
47
  },
45
48
  { immediate: !1 }
46
49
  );
47
- U.on(() => {
48
- j = T.getDelta(), z = T.getElapsedTime();
50
+ q.on(() => {
51
+ V = x.getDelta(), $ = x.getElapsedTime();
49
52
  });
50
- const se = () => ({
51
- onBeforeLoop: ae.on,
52
- onLoop: oe.on,
53
- onAfterLoop: U.on,
54
- pause: qe,
55
- resume: Je,
56
- isActive: Ke
57
- }), Pt = !0, X = "[TresJS ▲ ■ ●] ";
58
- function x() {
59
- function e(r, n) {
60
- console.error(`${X} ${r}`, n || "");
53
+ const me = () => ({
54
+ onBeforeLoop: fe.on,
55
+ onLoop: de.on,
56
+ onAfterLoop: q.on,
57
+ pause: it,
58
+ resume: lt,
59
+ isActive: ut
60
+ }), Zt = !0, re = "[TresJS ▲ ■ ●] ";
61
+ function j() {
62
+ function e(n, a) {
63
+ console.error(`${re} ${n}`, a || "");
61
64
  }
62
- function a(r) {
63
- console.warn(`${X} ${r}`);
65
+ function r(n) {
66
+ console.warn(`${re} ${n}`);
64
67
  }
65
- function t(r, n) {
68
+ function t(n, a) {
66
69
  }
67
70
  return {
68
71
  logError: e,
69
- logWarning: a,
72
+ logWarning: r,
70
73
  logMessage: t
71
74
  };
72
75
  }
73
- function At(e) {
74
- return typeof e == "number" ? [e, e, e] : e instanceof De ? [e.x, e.y, e.z] : e;
76
+ function er(e) {
77
+ return typeof e == "number" ? [e, e, e] : e instanceof Ne ? [e.x, e.y, e.z] : e;
75
78
  }
76
- function Xe(e) {
77
- return e instanceof F ? e : Array.isArray(e) ? new F(...e) : new F(e);
79
+ function ct(e) {
80
+ return e instanceof N ? e : Array.isArray(e) ? new N(...e) : new N(e);
78
81
  }
79
- const ie = (e, a) => {
80
- for (const t of Object.keys(a))
81
- a[t] instanceof Object && Object.assign(a[t], ie(e[t], a[t]));
82
- return Object.assign(e || {}, a), e;
83
- }, Qe = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot", Ze = /* @__PURE__ */ et(Qe);
84
- function Q(e) {
82
+ class ft extends ue.Mesh {
83
+ constructor(...t) {
84
+ super(...t);
85
+ G(this, "type", "HightlightMesh");
86
+ G(this, "createTime");
87
+ this.createTime = Date.now();
88
+ }
89
+ onBeforeRender() {
90
+ const n = (Date.now() - this.createTime) / 1e3, o = 1 + 0.07 * Math.sin(2.5 * n);
91
+ this.scale.set(o, o, o);
92
+ }
93
+ }
94
+ const pe = (e, r) => {
95
+ for (const t of Object.keys(r))
96
+ r[t] instanceof Object && Object.assign(r[t], pe(e[t], r[t]));
97
+ return Object.assign(e || {}, r), e;
98
+ }, dt = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot", mt = /* @__PURE__ */ pt(dt);
99
+ function ne(e) {
85
100
  return e && e.nodeType === 1;
86
101
  }
87
102
  function R(e) {
88
- return e.replace(/-([a-z])/g, (a, t) => t.toUpperCase());
103
+ return e.replace(/-([a-z])/g, (r, t) => t.toUpperCase());
89
104
  }
90
- function et(e, a) {
91
- const t = /* @__PURE__ */ Object.create(null), r = e.split(",");
92
- for (let n = 0; n < r.length; n++)
93
- t[r[n]] = !0;
94
- return a ? (n) => !!t[n.toLowerCase()] : (n) => !!t[n];
105
+ function pt(e, r) {
106
+ const t = /* @__PURE__ */ Object.create(null), n = e.split(",");
107
+ for (let a = 0; a < n.length; a++)
108
+ t[n[a]] = !0;
109
+ return r ? (a) => !!t[a.toLowerCase()] : (a) => !!t[a];
95
110
  }
96
- const tt = (e, a) => {
97
- const t = /* @__PURE__ */ new Set(), r = [];
98
- for (const n of e) {
99
- const o = a(n);
100
- t.has(o) || (t.add(o), r.push(n));
111
+ const gt = (e, r) => {
112
+ const t = /* @__PURE__ */ new Set(), n = [];
113
+ for (const a of e) {
114
+ const s = r(a);
115
+ t.has(s) || (t.add(s), n.push(a));
101
116
  }
102
- return r;
103
- }, Z = (e, a) => {
104
- if (!a)
117
+ return n;
118
+ }, oe = (e, r) => {
119
+ if (!r)
105
120
  return;
106
- const t = Array.isArray(a) ? a : a.match(/([^[.\]])+/g);
107
- return t == null ? void 0 : t.reduce((r, n) => r && r[n], e);
108
- }, rt = (e, a, t) => {
109
- const r = Array.isArray(a) ? a : a.match(/([^[.\]])+/g);
110
- r && r.reduce((n, o, c) => (n[o] === void 0 && (n[o] = {}), c === r.length - 1 && (n[o] = t), n[o]), e);
121
+ const t = Array.isArray(r) ? r : r.match(/([^[.\]])+/g);
122
+ return t == null ? void 0 : t.reduce((n, a) => n && n[a], e);
123
+ }, vt = (e, r, t) => {
124
+ const n = Array.isArray(r) ? r : r.match(/([^[.\]])+/g);
125
+ n && n.reduce((a, s, o) => (a[s] === void 0 && (a[s] = {}), o === n.length - 1 && (a[s] = t), a[s]), e);
111
126
  };
112
- function ue(e, a) {
113
- if (Q(e) && Q(a)) {
114
- const n = e.attributes, o = a.attributes;
115
- return n.length !== o.length ? !1 : Array.from(n).every(({ name: c, value: s }) => a.getAttribute(c) === s);
127
+ function ge(e, r) {
128
+ if (ne(e) && ne(r)) {
129
+ const a = e.attributes, s = r.attributes;
130
+ return a.length !== s.length ? !1 : Array.from(a).every(({ name: o, value: i }) => r.getAttribute(o) === i);
116
131
  }
117
- if (e === a)
132
+ if (e === r)
118
133
  return !0;
119
- if (e === null || typeof e != "object" || a === null || typeof a != "object")
134
+ if (e === null || typeof e != "object" || r === null || typeof r != "object")
120
135
  return !1;
121
- const t = Object.keys(e), r = Object.keys(a);
122
- if (t.length !== r.length)
136
+ const t = Object.keys(e), n = Object.keys(r);
137
+ if (t.length !== n.length)
123
138
  return !1;
124
- for (const n of t)
125
- if (!r.includes(n) || !ue(e[n], a[n]))
139
+ for (const a of t)
140
+ if (!n.includes(a) || !ge(e[a], r[a]))
126
141
  return !1;
127
142
  return !0;
128
143
  }
129
- function nt(e, a) {
130
- if (!Array.isArray(e) || !Array.isArray(a) || e.length !== a.length)
144
+ function ht(e, r) {
145
+ if (!Array.isArray(e) || !Array.isArray(r) || e.length !== r.length)
131
146
  return !1;
132
147
  for (let t = 0; t < e.length; t++)
133
- if (!ue(e[t], a[t]))
148
+ if (!ge(e[t], r[t]))
134
149
  return !1;
135
150
  return !0;
136
151
  }
137
- const at = Array.isArray, ot = Number.parseInt(Te.replace("dev", "")), H = {
152
+ const yt = Array.isArray;
153
+ function _t(e, r, t, n) {
154
+ const a = (l) => {
155
+ if (l.uuid === r)
156
+ return l;
157
+ for (const c of l.children) {
158
+ const m = a(c);
159
+ if (m)
160
+ return m;
161
+ }
162
+ }, s = a(e);
163
+ if (!s) {
164
+ console.warn("Object with UUID not found in the scene.");
165
+ return;
166
+ }
167
+ let o = s;
168
+ for (let l = 0; l < t.length - 1; l++)
169
+ if (o[t[l]] !== void 0)
170
+ o = o[t[l]];
171
+ else {
172
+ console.warn(`Property path is not valid: ${t.join(".")}`);
173
+ return;
174
+ }
175
+ const i = t[t.length - 1];
176
+ o[i] !== void 0 ? o[i] = n : console.warn(`Property path is not valid: ${t.join(".")}`);
177
+ }
178
+ function wt(e) {
179
+ const r = new Ve({
180
+ color: 11003607,
181
+ // Highlight color, e.g., yellow
182
+ transparent: !0,
183
+ opacity: 0.2,
184
+ depthTest: !1,
185
+ // So the highlight is always visible
186
+ side: $e
187
+ // To e
188
+ });
189
+ return new ft(e.geometry.clone(), r);
190
+ }
191
+ const bt = Number.parseInt(Ue.replace("dev", "")), H = {
138
192
  realistic: {
139
193
  shadows: !0,
140
194
  physicallyCorrectLights: !0,
141
- outputColorSpace: Le,
142
- toneMapping: Se,
195
+ outputColorSpace: Fe,
196
+ toneMapping: Ge,
143
197
  toneMappingExposure: 3,
144
198
  shadowMap: {
145
199
  enabled: !0,
146
- type: Be
200
+ type: ze
147
201
  }
148
202
  }
149
203
  };
150
- function st({
204
+ function Et({
151
205
  scene: e,
152
- canvas: a,
206
+ canvas: r,
153
207
  options: t,
154
- disableRender: r,
155
- contextParts: { sizes: n, camera: o }
208
+ disableRender: n,
209
+ contextParts: { sizes: a, camera: s }
156
210
  }) {
157
- const c = b(() => ({
158
- alpha: M(t.alpha),
159
- depth: M(t.depth),
160
- canvas: ze(a),
161
- context: M(t.context),
162
- stencil: M(t.stencil),
163
- antialias: M(t.antialias) === void 0 ? !0 : M(t.antialias),
164
- precision: M(t.precision),
165
- powerPreference: M(t.powerPreference),
166
- premultipliedAlpha: M(t.premultipliedAlpha),
167
- preserveDrawingBuffer: M(t.preserveDrawingBuffer),
168
- logarithmicDepthBuffer: M(t.logarithmicDepthBuffer),
169
- failIfMajorPerformanceCaveat: M(t.failIfMajorPerformanceCaveat)
170
- })), s = L(new I(c.value));
171
- re(c, () => {
172
- s.value.dispose(), s.value = new I(c.value);
173
- }), D(() => {
174
- s.value.setSize(n.width.value, n.height.value);
211
+ const o = k(() => ({
212
+ alpha: E(t.alpha),
213
+ depth: E(t.depth),
214
+ canvas: Xe(r),
215
+ context: E(t.context),
216
+ stencil: E(t.stencil),
217
+ antialias: E(t.antialias) === void 0 ? !0 : E(t.antialias),
218
+ precision: E(t.precision),
219
+ powerPreference: E(t.powerPreference),
220
+ premultipliedAlpha: E(t.premultipliedAlpha),
221
+ preserveDrawingBuffer: E(t.preserveDrawingBuffer),
222
+ logarithmicDepthBuffer: E(t.logarithmicDepthBuffer),
223
+ failIfMajorPerformanceCaveat: E(t.failIfMajorPerformanceCaveat)
224
+ })), i = D(new z(o.value));
225
+ ie(o, () => {
226
+ i.value.dispose(), i.value = new z(o.value);
227
+ }), A(() => {
228
+ i.value.setSize(a.width.value, a.height.value);
175
229
  });
176
- const { pixelRatio: l } = $e();
177
- D(() => {
178
- s.value.setPixelRatio(l.value);
230
+ const { pixelRatio: l } = Ze();
231
+ A(() => {
232
+ i.value.setPixelRatio(l.value);
179
233
  });
180
- const { logError: i } = x(), f = (() => {
181
- const m = new I(), w = {
234
+ const { logError: c } = j(), f = (() => {
235
+ const d = new z(), y = {
182
236
  shadowMap: {
183
- enabled: m.shadowMap.enabled,
184
- type: m.shadowMap.type
237
+ enabled: d.shadowMap.enabled,
238
+ type: d.shadowMap.type
185
239
  },
186
- toneMapping: m.toneMapping,
187
- toneMappingExposure: m.toneMappingExposure,
188
- outputColorSpace: m.outputColorSpace
240
+ toneMapping: d.toneMapping,
241
+ toneMappingExposure: d.toneMappingExposure,
242
+ outputColorSpace: d.outputColorSpace
189
243
  };
190
- return m.dispose(), w;
244
+ return d.dispose(), y;
191
245
  })();
192
- D(() => {
193
- const m = M(t.preset);
194
- m && (m in H || i(`Renderer Preset must be one of these: ${Object.keys(H).join(", ")}`), ie(s.value, H[m]));
195
- const w = (P, A) => {
196
- const C = M(P), k = () => {
197
- if (m)
198
- return Z(H[m], A);
246
+ A(() => {
247
+ const d = E(t.preset);
248
+ d && (d in H || c(`Renderer Preset must be one of these: ${Object.keys(H).join(", ")}`), pe(i.value, H[d]));
249
+ const y = (M, P) => {
250
+ const w = E(M), S = () => {
251
+ if (d)
252
+ return oe(H[d], P);
199
253
  };
200
- if (C !== void 0)
201
- return C;
202
- const g = k();
203
- return g !== void 0 ? g : Z(f, A);
204
- }, d = (P, A) => rt(s.value, A, w(P, A));
205
- d(t.shadows, "shadowMap.enabled"), d(t.toneMapping, "toneMapping"), d(t.shadowMapType, "shadowMap.type"), ot < 150 && d(!t.useLegacyLights, "physicallyCorrectLights"), d(t.outputColorSpace, "outputColorSpace"), d(t.toneMappingExposure, "toneMappingExposure");
206
- const h = w(t.clearColor, "clearColor");
207
- h && s.value.setClearColor(
208
- h ? Xe(h) : new F(0)
254
+ if (w !== void 0)
255
+ return w;
256
+ const v = S();
257
+ return v !== void 0 ? v : oe(f, P);
258
+ }, p = (M, P) => vt(i.value, P, y(M, P));
259
+ p(t.shadows, "shadowMap.enabled"), p(t.toneMapping, "toneMapping"), p(t.shadowMapType, "shadowMap.type"), bt < 150 && p(!t.useLegacyLights, "physicallyCorrectLights"), p(t.outputColorSpace, "outputColorSpace"), p(t.toneMappingExposure, "toneMappingExposure");
260
+ const C = y(t.clearColor, "clearColor");
261
+ C && i.value.setClearColor(
262
+ C ? ct(C) : new N(0)
209
263
  // default clear color is not easily/efficiently retrievable from three
210
264
  );
211
265
  });
212
- const { pause: u, resume: v, onLoop: E } = se();
213
- return E(() => {
214
- o.value && !M(r) && s.value.render(e, o.value);
215
- }), v(), $(() => {
216
- u(), s.value.dispose(), s.value.forceContextLoss();
266
+ const { pause: u, resume: g, onLoop: _ } = me();
267
+ return _(() => {
268
+ s.value && !E(n) && i.value.render(e, s.value);
269
+ }), g(), U(() => {
270
+ u(), i.value.dispose(), i.value.forceContextLoss();
217
271
  }), {
218
- renderer: s
272
+ renderer: i
219
273
  };
220
274
  }
221
- const ee = (e) => typeof e == "function", it = (e) => !!e && e.constructor === Array;
222
- function ut(e) {
223
- const a = { nodes: {}, materials: {} };
275
+ const ae = (e) => typeof e == "function", Ct = (e) => !!e && e.constructor === Array;
276
+ function Mt(e) {
277
+ const r = { nodes: {}, materials: {} };
224
278
  return e && e.traverse((t) => {
225
- t.name && (a.nodes[t.name] = t), t.material && !a.materials[t.material.name] && (a.materials[t.material.name] = t.material);
226
- }), a;
279
+ t.name && (r.nodes[t.name] = t), t.material && !r.materials[t.material.name] && (r.materials[t.material.name] = t.material);
280
+ }), r;
227
281
  }
228
- async function kt(e, a, t, r, n) {
229
- const { logError: o } = x(), c = new e();
230
- n && n(c), t && t(c);
231
- const l = (Array.isArray(a) ? a : [a]).map(
232
- (i) => new Promise((p, f) => {
233
- c.load(
234
- i,
282
+ async function tr(e, r, t, n, a) {
283
+ const { logError: s } = j(), o = new e();
284
+ a && a(o), t && t(o);
285
+ const l = (Array.isArray(r) ? r : [r]).map(
286
+ (c) => new Promise((m, f) => {
287
+ o.load(
288
+ c,
235
289
  (u) => {
236
- u.scene && Object.assign(u, ut(u.scene)), p(u);
290
+ u.scene && Object.assign(u, Mt(u.scene)), m(u);
237
291
  },
238
- r,
239
- (u) => f(o("[useLoader] - Failed to load resource", u))
292
+ n,
293
+ (u) => f(s("[useLoader] - Failed to load resource", u))
240
294
  );
241
295
  })
242
296
  );
243
- return it(a) ? await Promise.all(l) : await l[0];
297
+ return Ct(r) ? await Promise.all(l) : await l[0];
244
298
  }
245
- async function bt(e) {
246
- const a = new xe(), t = new Oe(a), r = (n) => new Promise((o, c) => {
299
+ async function rr(e) {
300
+ const r = new We(), t = new Qe(r), n = (a) => new Promise((s, o) => {
247
301
  t.load(
248
- n,
249
- (s) => o(s),
302
+ a,
303
+ (i) => s(i),
250
304
  () => null,
251
305
  () => {
252
- c(new Error("[useTextures] - Failed to load texture"));
306
+ o(new Error("[useTextures] - Failed to load texture"));
253
307
  }
254
308
  );
255
309
  });
256
- if (at(e)) {
257
- const n = await Promise.all(e.map((o) => r(o)));
258
- return e.length > 1 ? n : n[0];
310
+ if (yt(e)) {
311
+ const a = await Promise.all(e.map((s) => n(s)));
312
+ return e.length > 1 ? a : a[0];
259
313
  } else {
260
314
  const {
261
- map: n,
262
- displacementMap: o,
263
- normalMap: c,
264
- roughnessMap: s,
315
+ map: a,
316
+ displacementMap: s,
317
+ normalMap: o,
318
+ roughnessMap: i,
265
319
  metalnessMap: l,
266
- aoMap: i,
267
- alphaMap: p,
320
+ aoMap: c,
321
+ alphaMap: m,
268
322
  matcap: f
269
323
  } = e;
270
324
  return {
271
- map: n ? await r(n) : null,
272
- displacementMap: o ? await r(o) : null,
273
- normalMap: c ? await r(c) : null,
274
- roughnessMap: s ? await r(s) : null,
275
- metalnessMap: l ? await r(l) : null,
276
- aoMap: i ? await r(i) : null,
277
- alphaMap: p ? await r(p) : null,
278
- matcap: f ? await r(f) : null
325
+ map: a ? await n(a) : null,
326
+ displacementMap: s ? await n(s) : null,
327
+ normalMap: o ? await n(o) : null,
328
+ roughnessMap: i ? await n(i) : null,
329
+ metalnessMap: l ? await n(l) : null,
330
+ aoMap: c ? await n(c) : null,
331
+ alphaMap: m ? await n(m) : null,
332
+ matcap: f ? await n(f) : null
279
333
  };
280
334
  }
281
335
  }
282
- const lt = (e, { renderer: a, camera: t, raycaster: r }) => {
283
- const n = b(() => a.value.domElement), { x: o, y: c } = Ne({ target: n }), { width: s, height: l, top: i, left: p } = Ie(n), f = ({ x: g, y: _ }) => {
284
- if (n.value)
336
+ const Pt = (e, { renderer: r, camera: t, raycaster: n }) => {
337
+ const a = k(() => r.value.domElement), { x: s, y: o } = et({ target: a }), { width: i, height: l, top: c, left: m } = tt(a), f = ({ x: v, y: b }) => {
338
+ if (a.value)
285
339
  return {
286
- x: (g - p.value) / s.value * 2 - 1,
287
- y: -((_ - i.value) / l.value) * 2 + 1
340
+ x: (v - m.value) / i.value * 2 - 1,
341
+ y: -((b - c.value) / l.value) * 2 + 1
288
342
  };
289
- }, u = ({ x: g, y: _ }) => {
343
+ }, u = ({ x: v, y: b }) => {
290
344
  if (t.value)
291
- return r.value.setFromCamera(new Re(g, _), t.value), r.value.intersectObjects(e.value, !1);
292
- }, v = (g) => {
293
- const _ = f({
294
- x: (g == null ? void 0 : g.clientX) ?? o.value,
295
- y: (g == null ? void 0 : g.clientY) ?? c.value
345
+ return n.value.setFromCamera(new Ye(v, b), t.value), n.value.intersectObjects(e.value, !1);
346
+ }, g = (v) => {
347
+ const b = f({
348
+ x: (v == null ? void 0 : v.clientX) ?? s.value,
349
+ y: (v == null ? void 0 : v.clientY) ?? o.value
296
350
  });
297
- return _ ? u(_) || [] : [];
298
- }, E = b(() => v()), m = S(), w = S(), d = (g, _) => {
299
- g.trigger({ event: _, intersects: v(_) });
300
- }, h = (g) => {
301
- d(w, g);
351
+ return b ? u(b) || [] : [];
352
+ }, _ = k(() => g()), d = L(), y = L(), p = (v, b) => {
353
+ v.trigger({ event: b, intersects: g(b) });
354
+ }, C = (v) => {
355
+ p(y, v);
302
356
  };
303
- let P;
304
- const A = (g) => {
305
- var _;
306
- P = (_ = v(g)[0]) == null ? void 0 : _.object;
307
- }, C = (g) => {
308
- var _;
309
- g instanceof PointerEvent && P === ((_ = v(g)[0]) == null ? void 0 : _.object) && d(m, g);
310
- }, k = (g) => w.trigger({ event: g, intersects: [] });
311
- return n.value.addEventListener("pointerup", C), n.value.addEventListener("pointerdown", A), n.value.addEventListener("pointermove", h), n.value.addEventListener("pointerleave", k), $(() => {
312
- n != null && n.value && (n.value.removeEventListener("pointerup", C), n.value.removeEventListener("pointerdown", A), n.value.removeEventListener("pointermove", h), n.value.removeEventListener("pointerleave", k));
357
+ let M;
358
+ const P = (v) => {
359
+ var b;
360
+ M = (b = g(v)[0]) == null ? void 0 : b.object;
361
+ }, w = (v) => {
362
+ var b;
363
+ v instanceof PointerEvent && M === ((b = g(v)[0]) == null ? void 0 : b.object) && p(d, v);
364
+ }, S = (v) => y.trigger({ event: v, intersects: [] });
365
+ return a.value.addEventListener("pointerup", w), a.value.addEventListener("pointerdown", P), a.value.addEventListener("pointermove", C), a.value.addEventListener("pointerleave", S), U(() => {
366
+ a != null && a.value && (a.value.removeEventListener("pointerup", w), a.value.removeEventListener("pointerdown", P), a.value.removeEventListener("pointermove", C), a.value.removeEventListener("pointerleave", S));
313
367
  }), {
314
- intersects: E,
315
- onClick: (g) => m.on(g).off,
316
- onPointerMove: (g) => w.on(g).off
368
+ intersects: _,
369
+ onClick: (v) => d.on(v).off,
370
+ onPointerMove: (v) => y.on(v).off
317
371
  };
318
372
  };
319
- function Dt() {
320
- const { logWarning: e } = x();
321
- function a(o, c, s) {
373
+ function nr() {
374
+ const { logWarning: e } = j();
375
+ function r(s, o, i) {
322
376
  let l = null;
323
- return o.traverse((i) => {
324
- i[c] === s && (l = i);
325
- }), l || e(`Child with ${c} '${s}' not found.`), l;
377
+ return s.traverse((c) => {
378
+ c[o] === i && (l = c);
379
+ }), l || e(`Child with ${o} '${i}' not found.`), l;
326
380
  }
327
- function t(o, c, s) {
381
+ function t(s, o, i) {
328
382
  const l = [];
329
- return o.traverse((i) => {
330
- i[c].includes(s) && l.push(i);
331
- }), l.length || e(`Children with ${c} '${s}' not found.`), l;
383
+ return s.traverse((c) => {
384
+ c[o].includes(i) && l.push(c);
385
+ }), l.length || e(`Children with ${o} '${i}' not found.`), l;
332
386
  }
333
- function r(o, c) {
334
- return a(o, "name", c);
387
+ function n(s, o) {
388
+ return r(s, "name", o);
335
389
  }
336
- function n(o, c) {
337
- return t(o, "name", c);
390
+ function a(s, o) {
391
+ return t(s, "name", o);
338
392
  }
339
393
  return {
340
- seek: a,
341
- seekByName: r,
394
+ seek: r,
395
+ seekByName: n,
342
396
  seekAll: t,
343
- seekAllByName: n
397
+ seekAllByName: a
344
398
  };
345
399
  }
346
- const ct = ({ scene: e, contextParts: a }) => {
347
- const t = pe({
400
+ const St = ({ scene: e, contextParts: r }) => {
401
+ const t = le({
348
402
  click: /* @__PURE__ */ new Map(),
349
403
  pointerMove: /* @__PURE__ */ new Map(),
350
404
  pointerEnter: /* @__PURE__ */ new Map(),
351
405
  pointerLeave: /* @__PURE__ */ new Map()
352
- }), r = B(/* @__PURE__ */ new Set()), n = (u) => {
353
- r.value.add(u);
354
- }, o = (u) => {
355
- r.value.delete(u);
356
- }, c = (u) => {
357
- Object.values(t).forEach((v) => v.delete(u)), o(u);
406
+ }), n = B(/* @__PURE__ */ new Set()), a = (u) => {
407
+ n.value.add(u);
358
408
  }, s = (u) => {
359
- const { onClick: v, onPointerMove: E, onPointerEnter: m, onPointerLeave: w } = u;
360
- v && t.click.set(u, v), E && t.pointerMove.set(u, E), m && t.pointerEnter.set(u, m), w && t.pointerLeave.set(u, w);
409
+ n.value.delete(u);
410
+ }, o = (u) => {
411
+ Object.values(t).forEach((g) => g.delete(u)), s(u);
412
+ }, i = (u) => {
413
+ const { onClick: g, onPointerMove: _, onPointerEnter: d, onPointerLeave: y } = u;
414
+ g && t.click.set(u, g), _ && t.pointerMove.set(u, _), d && t.pointerEnter.set(u, d), y && t.pointerLeave.set(u, y);
361
415
  };
362
- e.userData.tres__registerAtPointerEventHandler = s, e.userData.tres__deregisterAtPointerEventHandler = c, e.userData.tres__registerBlockingObjectAtPointerEventHandler = n, e.userData.tres__deregisterBlockingObjectAtPointerEventHandler = o;
363
- const l = b(
364
- () => tt(
416
+ e.userData.tres__registerAtPointerEventHandler = i, e.userData.tres__deregisterAtPointerEventHandler = o, e.userData.tres__registerBlockingObjectAtPointerEventHandler = a, e.userData.tres__deregisterBlockingObjectAtPointerEventHandler = s;
417
+ const l = k(
418
+ () => gt(
365
419
  [
366
- ...Array.from(r.value),
420
+ ...Array.from(n.value),
367
421
  ...Object.values(t).map((u) => Array.from(u.keys())).flat()
368
422
  ],
369
423
  ({ uuid: u }) => u
370
424
  )
371
- ), { onClick: i, onPointerMove: p } = lt(l, a);
372
- i(({ intersects: u, event: v }) => {
373
- var E;
374
- u.length && ((E = t.click.get(u[0].object)) == null || E(u[0], v));
425
+ ), { onClick: c, onPointerMove: m } = Pt(l, r);
426
+ c(({ intersects: u, event: g }) => {
427
+ var _;
428
+ u.length && ((_ = t.click.get(u[0].object)) == null || _(u[0], g));
375
429
  });
376
430
  let f;
377
- return p(({ intersects: u, event: v }) => {
378
- var h, P, A, C;
379
- const E = (h = u == null ? void 0 : u[0]) == null ? void 0 : h.object, { pointerLeave: m, pointerEnter: w, pointerMove: d } = t;
380
- f && f !== E && ((P = m.get(f)) == null || P(f, v)), E && (f !== E && ((A = w.get(E)) == null || A(u[0], v)), (C = d.get(E)) == null || C(u[0], v)), f = E || null;
431
+ return m(({ intersects: u, event: g }) => {
432
+ var C, M, P, w;
433
+ const _ = (C = u == null ? void 0 : u[0]) == null ? void 0 : C.object, { pointerLeave: d, pointerEnter: y, pointerMove: p } = t;
434
+ f && f !== _ && ((M = d.get(f)) == null || M(f, g)), _ && (f !== _ && ((P = y.get(_)) == null || P(u[0], g)), (w = p.get(_)) == null || w(u[0], g)), f = _ || null;
381
435
  }), {
382
- registerObject: s,
383
- deregisterObject: c
436
+ registerObject: i,
437
+ deregisterObject: o
384
438
  };
385
439
  };
386
- function ft(e) {
387
- let a = 0;
440
+ function ve(e) {
441
+ let r = 0;
388
442
  return e.traverse((t) => {
389
443
  if (t.isMesh && t.geometry) {
390
- const r = t.geometry, n = r.attributes.position.count * 3 * Float32Array.BYTES_PER_ELEMENT, o = r.index ? r.index.count * Uint32Array.BYTES_PER_ELEMENT : 0, c = r.attributes.normal ? r.attributes.normal.count * 3 * Float32Array.BYTES_PER_ELEMENT : 0, s = r.attributes.uv ? r.attributes.uv.count * 2 * Float32Array.BYTES_PER_ELEMENT : 0, l = n + o + c + s;
391
- a += l;
444
+ const n = t.geometry, a = n.attributes.position.count * 3 * Float32Array.BYTES_PER_ELEMENT, s = n.index ? n.index.count * Uint32Array.BYTES_PER_ELEMENT : 0, o = n.attributes.normal ? n.attributes.normal.count * 3 * Float32Array.BYTES_PER_ELEMENT : 0, i = n.attributes.uv ? n.attributes.uv.count * 2 * Float32Array.BYTES_PER_ELEMENT : 0, l = a + s + o + i;
445
+ r += l;
392
446
  }
393
- }), a;
447
+ }), r;
448
+ }
449
+ function kt(e) {
450
+ return (e / 1024).toFixed(2);
394
451
  }
395
- const W = B({}), Y = (e) => Object.assign(W.value, e);
396
- function mt({
452
+ const J = B({}), X = (e) => Object.assign(J.value, e);
453
+ function Tt({
397
454
  scene: e,
398
- canvas: a,
455
+ canvas: r,
399
456
  windowSize: t,
400
- disableRender: r,
401
- rendererOptions: n
457
+ disableRender: n,
458
+ rendererOptions: a
402
459
  }) {
403
- const o = b(
404
- () => M(t) ? Ve() : Ge(M(a).parentElement)
405
- ), c = b(() => o.value.width.value), s = b(() => o.value.height.value), l = b(() => c.value / s.value), i = {
406
- height: s,
407
- width: c,
460
+ const s = k(
461
+ () => E(t) ? rt() : nt(E(r).parentElement)
462
+ ), o = k(() => s.value.width.value), i = k(() => s.value.height.value), l = k(() => o.value / i.value), c = {
463
+ height: i,
464
+ width: o,
408
465
  aspectRatio: l
409
- }, p = L(e), {
466
+ }, m = D(e), {
410
467
  camera: f,
411
468
  cameras: u,
412
- registerCamera: v,
413
- deregisterCamera: E,
414
- setCameraActive: m
415
- } = Ye({ sizes: i, scene: e }), { renderer: w } = st(
469
+ registerCamera: g,
470
+ deregisterCamera: _,
471
+ setCameraActive: d
472
+ } = st({ sizes: c, scene: e }), { renderer: y } = Et(
416
473
  {
417
474
  scene: e,
418
- canvas: a,
419
- options: n,
420
- contextParts: { sizes: i, camera: f },
421
- disableRender: r
475
+ canvas: r,
476
+ options: a,
477
+ contextParts: { sizes: c, camera: f },
478
+ disableRender: n
422
479
  }
423
- ), d = {
424
- sizes: i,
425
- scene: p,
480
+ ), p = {
481
+ sizes: c,
482
+ scene: m,
426
483
  camera: f,
427
- cameras: de(u),
428
- renderer: w,
429
- raycaster: L(new He()),
484
+ cameras: Se(u),
485
+ renderer: y,
486
+ raycaster: D(new Je()),
430
487
  controls: B(null),
431
488
  perf: {
432
489
  maxFrames: 160,
@@ -440,131 +497,136 @@ function mt({
440
497
  accumulator: []
441
498
  }
442
499
  },
443
- extend: Y,
444
- registerCamera: v,
445
- setCameraActive: m,
446
- deregisterCamera: E
500
+ extend: X,
501
+ registerCamera: g,
502
+ setCameraActive: d,
503
+ deregisterCamera: _
447
504
  };
448
- V("useTres", d);
449
- const h = 100, P = We({ every: h }), { isSupported: A, memory: C } = Ue({ interval: h }), k = 160;
450
- let g = performance.now();
451
- const _ = ({ timestamp: O }) => {
452
- d.scene.value && (d.perf.memory.allocatedMem = ft(d.scene.value)), O - g >= h && (g = O, d.perf.fps.accumulator.push(P.value), d.perf.fps.accumulator.length > k && d.perf.fps.accumulator.shift(), d.perf.fps.value = P.value, A.value && C.value && (d.perf.memory.accumulator.push(C.value.usedJSHeapSize / 1024 / 1024), d.perf.memory.accumulator.length > k && d.perf.memory.accumulator.shift(), d.perf.memory.currentMem = d.perf.memory.accumulator.reduce((fe, me) => fe + me, 0) / d.perf.memory.accumulator.length));
505
+ Q("useTres", p);
506
+ const C = 100, M = ot({ every: C }), { isSupported: P, memory: w } = at({ interval: C }), S = 160;
507
+ let v = performance.now();
508
+ const b = ({ timestamp: I }) => {
509
+ p.scene.value && (p.perf.memory.allocatedMem = ve(p.scene.value)), I - v >= C && (v = I, p.perf.fps.accumulator.push(M.value), p.perf.fps.accumulator.length > S && p.perf.fps.accumulator.shift(), p.perf.fps.value = M.value, P.value && w.value && (p.perf.memory.accumulator.push(w.value.usedJSHeapSize / 1024 / 1024), p.perf.memory.accumulator.length > S && p.perf.memory.accumulator.shift(), p.perf.memory.currentMem = p.perf.memory.accumulator.reduce((Ee, Ce) => Ee + Ce, 0) / p.perf.memory.accumulator.length));
453
510
  };
454
- let N = 0;
455
- const le = 1, { pause: ce, resume: Ct } = ne(({ delta: O }) => {
456
- window.__TRES__DEVTOOLS__ && (_({ timestamp: performance.now() }), N += O, N >= le && (window.__TRES__DEVTOOLS__.cb(d), N = 0));
511
+ let F = 0;
512
+ const we = 1, { pause: be, resume: Yt } = ce(({ delta: I }) => {
513
+ window.__TRES__DEVTOOLS__ && (b({ timestamp: performance.now() }), F += I, F >= we && (window.__TRES__DEVTOOLS__.cb(p), F = 0));
457
514
  }, { immediate: !0 });
458
- return $(() => {
459
- ce();
460
- }), d;
515
+ return U(() => {
516
+ be();
517
+ }), p;
461
518
  }
462
- function pt() {
463
- const e = ve("useTres");
519
+ function Ot() {
520
+ const e = ke("useTres");
464
521
  if (!e)
465
522
  throw new Error("useTresContext must be used together with useTresContextProvider");
466
523
  return e;
467
524
  }
468
- const Tt = pt;
469
- let y = null;
470
- const { logError: te } = x(), dt = {
471
- createElement(e, a, t, r) {
472
- var c, s;
473
- if (r || (r = {}), r.args || (r.args = []), e === "template" || Ze(e))
525
+ const or = Ot;
526
+ let h = null;
527
+ const { logError: se } = j(), W = [
528
+ "onClick",
529
+ "onPointerMove",
530
+ "onPointerEnter",
531
+ "onPointerLeave"
532
+ ], At = {
533
+ createElement(e, r, t, n) {
534
+ var o, i;
535
+ if (n || (n = {}), n.args || (n.args = []), e === "template" || mt(e))
474
536
  return null;
475
- let n = e.replace("Tres", ""), o;
537
+ let a = e.replace("Tres", ""), s;
476
538
  if (e === "primitive") {
477
- (r == null ? void 0 : r.object) === void 0 && te("Tres primitives need a prop 'object'");
478
- const l = r.object;
479
- n = l.type, o = Object.assign(l, { type: n, attach: r.attach, primitive: !0 });
539
+ (n == null ? void 0 : n.object) === void 0 && se("Tres primitives need a prop 'object'");
540
+ const l = n.object;
541
+ a = l.type, s = Object.assign(l, { type: a, attach: n.attach, primitive: !0 });
480
542
  } else {
481
- const l = W.value[n];
482
- l || te(`${n} is not defined on the THREE namespace. Use extend to add it to the catalog.`), o = new l(...r.args);
543
+ const l = J.value[a];
544
+ l || se(`${a} is not defined on the THREE namespace. Use extend to add it to the catalog.`), s = new l(...n.args);
483
545
  }
484
- return o.isCamera && (r != null && r.position || o.position.set(3, 3, 3), r != null && r.lookAt || o.lookAt(0, 0, 0)), (r == null ? void 0 : r.attach) === void 0 && (o.isMaterial ? o.attach = "material" : o.isBufferGeometry && (o.attach = "geometry")), o.isObject3D && ((c = r == null ? void 0 : r.material) != null && c.isMaterial && (o.userData.tres__materialViaProp = !0), (s = r == null ? void 0 : r.geometry) != null && s.isBufferGeometry && (o.userData.tres__geometryViaProp = !0)), o.userData = {
485
- ...o.userData,
486
- tres__name: n
487
- }, o;
546
+ return s.isCamera && (n != null && n.position || s.position.set(3, 3, 3), n != null && n.lookAt || s.lookAt(0, 0, 0)), (n == null ? void 0 : n.attach) === void 0 && (s.isMaterial ? s.attach = "material" : s.isBufferGeometry && (s.attach = "geometry")), s.isObject3D && ((o = n == null ? void 0 : n.material) != null && o.isMaterial && (s.userData.tres__materialViaProp = !0), (i = n == null ? void 0 : n.geometry) != null && i.isBufferGeometry && (s.userData.tres__geometryViaProp = !0)), s.userData = {
547
+ ...s.userData,
548
+ tres__name: a
549
+ }, s;
488
550
  },
489
- insert(e, a) {
490
- var r, n, o, c;
491
- a && a.isScene && (y = a);
492
- const t = a || y;
551
+ insert(e, r) {
552
+ var n, a, s, o;
553
+ r && r.isScene && (h = r);
554
+ const t = r || h;
493
555
  if (e != null && e.isObject3D) {
494
556
  if (e != null && e.isCamera) {
495
- if (!(y != null && y.userData.tres__registerCamera))
557
+ if (!(h != null && h.userData.tres__registerCamera))
496
558
  throw "could not find tres__registerCamera on scene's userData";
497
- (n = y == null ? void 0 : (r = y.userData).tres__registerCamera) == null || n.call(r, e);
559
+ (a = h == null ? void 0 : (n = h.userData).tres__registerCamera) == null || a.call(n, e);
498
560
  }
499
- if (e != null && e.onClick || e != null && e.onPointerMove || e != null && e.onPointerEnter || e != null && e.onPointerLeave) {
500
- if (!(y != null && y.userData.tres__registerAtPointerEventHandler))
561
+ if (e && W.some((i) => e[i])) {
562
+ if (!(h != null && h.userData.tres__registerAtPointerEventHandler))
501
563
  throw "could not find tres__registerAtPointerEventHandler on scene's userData";
502
- (c = y == null ? void 0 : (o = y.userData).tres__registerAtPointerEventHandler) == null || c.call(o, e);
564
+ (o = h == null ? void 0 : (s = h.userData).tres__registerAtPointerEventHandler) == null || o.call(s, e);
503
565
  }
504
566
  }
505
567
  e != null && e.isObject3D && (t != null && t.isObject3D) ? (t.add(e), e.dispatchEvent({ type: "added" })) : e != null && e.isFog ? t.fog = e : typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
506
568
  },
507
569
  remove(e) {
508
- var a, t;
570
+ var r, t;
509
571
  if (e) {
510
572
  if (e.isObject3D) {
511
- const r = e, n = (i) => {
573
+ const n = e, a = (c) => {
512
574
  var f, u;
513
- const p = i;
514
- i.userData.tres__materialViaProp || ((f = p.material) == null || f.dispose(), p.material = void 0), i.userData.tres__geometryViaProp || ((u = p.geometry) == null || u.dispose(), p.geometry = void 0);
515
- }, o = y == null ? void 0 : y.userData.tres__deregisterAtPointerEventHandler, c = y == null ? void 0 : y.userData.tres__deregisterBlockingObjectAtPointerEventHandler, s = (i) => {
516
- var p, f;
517
- if (!c)
575
+ const m = c;
576
+ c.userData.tres__materialViaProp || ((f = m.material) == null || f.dispose(), m.material = void 0), c.userData.tres__geometryViaProp || ((u = m.geometry) == null || u.dispose(), m.geometry = void 0);
577
+ }, s = h == null ? void 0 : h.userData.tres__deregisterAtPointerEventHandler, o = h == null ? void 0 : h.userData.tres__deregisterBlockingObjectAtPointerEventHandler, i = (c) => {
578
+ var m, f;
579
+ if (!o)
518
580
  throw "could not find tres__deregisterBlockingObjectAtPointerEventHandler on scene's userData";
519
- if ((f = y == null ? void 0 : (p = y.userData).tres__deregisterBlockingObjectAtPointerEventHandler) == null || f.call(p, i), !o)
581
+ if ((f = h == null ? void 0 : (m = h.userData).tres__deregisterBlockingObjectAtPointerEventHandler) == null || f.call(m, c), !s)
520
582
  throw "could not find tres__deregisterAtPointerEventHandler on scene's userData";
521
- (i != null && i.onClick || i != null && i.onPointerMove || i != null && i.onPointerEnter || i != null && i.onPointerLeave) && (o == null || o(i));
522
- }, l = (i) => {
523
- const p = y == null ? void 0 : y.userData.tres__deregisterCamera;
524
- if (!p)
583
+ c && W.some((u) => c[u]) && (s == null || s(c));
584
+ }, l = (c) => {
585
+ const m = h == null ? void 0 : h.userData.tres__deregisterCamera;
586
+ if (!m)
525
587
  throw "could not find tres__deregisterCamera on scene's userData";
526
- i.isCamera && (p == null || p(i));
588
+ c.isCamera && (m == null || m(c));
527
589
  };
528
- (a = e.removeFromParent) == null || a.call(e), r.traverse((i) => {
529
- n(i), l(i), s == null || s(i);
530
- }), n(r), l(r), s == null || s(r);
590
+ (r = e.removeFromParent) == null || r.call(e), n.traverse((c) => {
591
+ a(c), l(c), i == null || i(c);
592
+ }), a(n), l(n), i == null || i(n);
531
593
  }
532
594
  (t = e.dispose) == null || t.call(e);
533
595
  }
534
596
  },
535
- patchProp(e, a, t, r) {
536
- var n, o, c, s;
597
+ patchProp(e, r, t, n) {
598
+ var a, s, o, i;
537
599
  if (e) {
538
- let l = e, i = a;
539
- if (e.isObject3D && i === "blocks-pointer-events") {
540
- r || r === "" ? (o = y == null ? void 0 : (n = y.userData).tres__registerBlockingObjectAtPointerEventHandler) == null || o.call(n, e) : (s = y == null ? void 0 : (c = y.userData).tres__deregisterBlockingObjectAtPointerEventHandler) == null || s.call(c, e);
600
+ let l = e, c = r;
601
+ if (e.isObject3D && c === "blocks-pointer-events") {
602
+ n || n === "" ? (s = h == null ? void 0 : (a = h.userData).tres__registerBlockingObjectAtPointerEventHandler) == null || s.call(a, e) : (i = h == null ? void 0 : (o = h.userData).tres__deregisterBlockingObjectAtPointerEventHandler) == null || i.call(o, e);
541
603
  return;
542
604
  }
543
- let p = R(i), f = l == null ? void 0 : l[p];
544
- if (i === "args") {
545
- const v = e, E = t ?? [], m = r ?? [], w = e.userData.tres__name || e.type;
546
- w && E.length && !nt(E, m) && (l = Object.assign(v, new W.value[w](...r)));
605
+ let m = R(c), f = l == null ? void 0 : l[m];
606
+ if (c === "args") {
607
+ const g = e, _ = t ?? [], d = n ?? [], y = e.userData.tres__name || e.type;
608
+ y && _.length && !ht(_, d) && (l = Object.assign(g, new J.value[y](...n)));
547
609
  return;
548
610
  }
549
611
  if (l.type === "BufferGeometry") {
550
- if (i === "args")
612
+ if (c === "args")
551
613
  return;
552
614
  l.setAttribute(
553
- R(i),
554
- new Fe(...r)
615
+ R(c),
616
+ new Ke(...n)
555
617
  );
556
618
  return;
557
619
  }
558
- if (i.includes("-") && f === void 0) {
559
- const v = i.split("-");
560
- f = v.reduce((E, m) => E[R(m)], l), i = v.pop(), p = i.toLowerCase(), f != null && f.set || (l = v.reduce((E, m) => E[R(m)], l));
620
+ if (c.includes("-") && f === void 0) {
621
+ const g = c.split("-");
622
+ f = g.reduce((_, d) => _[R(d)], l), c = g.pop(), m = c.toLowerCase(), f != null && f.set || (l = g.reduce((_, d) => _[R(d)], l));
561
623
  }
562
- let u = r;
563
- if (u === "" && (u = !0), ee(f)) {
564
- Array.isArray(u) ? e[p](...u) : e[p](u);
624
+ let u = n;
625
+ if (u === "" && (u = !0), ae(f)) {
626
+ W.includes(r) || (Array.isArray(u) ? e[m](...u) : e[m](u));
565
627
  return;
566
628
  }
567
- !(f != null && f.set) && !ee(f) ? l[p] = u : f.constructor === u.constructor && (f != null && f.copy) ? f == null || f.copy(u) : Array.isArray(u) ? f.set(...u) : !f.isColor && f.setScalar ? f.setScalar(u) : f.set(u);
629
+ !(f != null && f.set) && !ae(f) ? l[m] = u : f.constructor === u.constructor && (f != null && f.copy) ? f == null || f.copy(u) : Array.isArray(u) ? f.set(...u) : !f.isColor && f.setScalar ? f.setScalar(u) : f.set(u);
568
630
  }
569
631
  },
570
632
  parentNode(e) {
@@ -579,9 +641,288 @@ const { logError: te } = x(), dt = {
579
641
  setScopeId: () => void 0,
580
642
  cloneNode: () => void 0,
581
643
  insertStaticContent: () => void 0
582
- }, { render: vt } = ge(dt);
583
- Y(Pe);
584
- const gt = ["data-scene"], yt = /* @__PURE__ */ q({
644
+ }, { render: xt } = Te(At);
645
+ X(ue);
646
+ function Dt() {
647
+ return he().__VUE_DEVTOOLS_GLOBAL_HOOK__;
648
+ }
649
+ function he() {
650
+ return typeof navigator < "u" && typeof window < "u" ? window : typeof global < "u" ? global : {};
651
+ }
652
+ const Lt = typeof Proxy == "function", Bt = "devtools-plugin:setup", jt = "plugin:settings:set";
653
+ let T, K;
654
+ function It() {
655
+ var e;
656
+ return T !== void 0 || (typeof window < "u" && window.performance ? (T = !0, K = window.performance) : typeof global < "u" && (!((e = global.perf_hooks) === null || e === void 0) && e.performance) ? (T = !0, K = global.perf_hooks.performance) : T = !1), T;
657
+ }
658
+ function Rt() {
659
+ return It() ? K.now() : Date.now();
660
+ }
661
+ class Ht {
662
+ constructor(r, t) {
663
+ this.target = null, this.targetQueue = [], this.onQueue = [], this.plugin = r, this.hook = t;
664
+ const n = {};
665
+ if (r.settings)
666
+ for (const o in r.settings) {
667
+ const i = r.settings[o];
668
+ n[o] = i.defaultValue;
669
+ }
670
+ const a = `__vue-devtools-plugin-settings__${r.id}`;
671
+ let s = Object.assign({}, n);
672
+ try {
673
+ const o = localStorage.getItem(a), i = JSON.parse(o);
674
+ Object.assign(s, i);
675
+ } catch {
676
+ }
677
+ this.fallbacks = {
678
+ getSettings() {
679
+ return s;
680
+ },
681
+ setSettings(o) {
682
+ try {
683
+ localStorage.setItem(a, JSON.stringify(o));
684
+ } catch {
685
+ }
686
+ s = o;
687
+ },
688
+ now() {
689
+ return Rt();
690
+ }
691
+ }, t && t.on(jt, (o, i) => {
692
+ o === this.plugin.id && this.fallbacks.setSettings(i);
693
+ }), this.proxiedOn = new Proxy({}, {
694
+ get: (o, i) => this.target ? this.target.on[i] : (...l) => {
695
+ this.onQueue.push({
696
+ method: i,
697
+ args: l
698
+ });
699
+ }
700
+ }), this.proxiedTarget = new Proxy({}, {
701
+ get: (o, i) => this.target ? this.target[i] : i === "on" ? this.proxiedOn : Object.keys(this.fallbacks).includes(i) ? (...l) => (this.targetQueue.push({
702
+ method: i,
703
+ args: l,
704
+ resolve: () => {
705
+ }
706
+ }), this.fallbacks[i](...l)) : (...l) => new Promise((c) => {
707
+ this.targetQueue.push({
708
+ method: i,
709
+ args: l,
710
+ resolve: c
711
+ });
712
+ })
713
+ });
714
+ }
715
+ async setRealTarget(r) {
716
+ this.target = r;
717
+ for (const t of this.onQueue)
718
+ this.target.on[t.method](...t.args);
719
+ for (const t of this.targetQueue)
720
+ t.resolve(await this.target[t.method](...t.args));
721
+ }
722
+ }
723
+ function Nt(e, r) {
724
+ const t = e, n = he(), a = Dt(), s = Lt && t.enableEarlyProxy;
725
+ if (a && (n.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !s))
726
+ a.emit(Bt, e, r);
727
+ else {
728
+ const o = s ? new Ht(t, a) : null;
729
+ (n.__VUE_DEVTOOLS_PLUGINS__ = n.__VUE_DEVTOOLS_PLUGINS__ || []).push({
730
+ pluginDescriptor: t,
731
+ setupFn: r,
732
+ proxy: o
733
+ }), o && r(o.proxiedTarget);
734
+ }
735
+ }
736
+ function Vt(e, r) {
737
+ const t = `▲ ■ ●${e}`;
738
+ typeof __VUE_DEVTOOLS_TOAST__ == "function" ? __VUE_DEVTOOLS_TOAST__(t, r) : r === "error" ? console.error(t) : r === "warn" ? console.warn(t) : console.log(t);
739
+ }
740
+ const ye = (e) => {
741
+ const r = {
742
+ id: e.uuid,
743
+ label: e.type,
744
+ children: [],
745
+ tags: []
746
+ };
747
+ e.name !== "" && r.tags.push({
748
+ label: e.name,
749
+ textColor: 5750629,
750
+ backgroundColor: 15793395
751
+ });
752
+ const t = ve(e);
753
+ return t > 0 && r.tags.push({
754
+ label: `${kt(t)} KB`,
755
+ textColor: 15707189,
756
+ backgroundColor: 16775644,
757
+ tooltip: "Memory usage"
758
+ }), e.type.includes("Light") && (r.tags.push({
759
+ label: `${e.intensity}`,
760
+ textColor: 9738662,
761
+ backgroundColor: 16316922,
762
+ tooltip: "Intensity"
763
+ }), r.tags.push({
764
+ label: `#${e.color.getHexString()}`,
765
+ textColor: 9738662,
766
+ backgroundColor: 16316922,
767
+ tooltip: "Color"
768
+ })), e.type.includes("Camera") && (r.tags.push({
769
+ label: `${e.fov}°`,
770
+ textColor: 9738662,
771
+ backgroundColor: 16316922,
772
+ tooltip: "Field of view"
773
+ }), r.tags.push({
774
+ // eslint-disable-next-line max-len
775
+ label: `x: ${Math.round(e.position.x)} y: ${Math.round(e.position.y)} z: ${Math.round(e.position.z)}`,
776
+ textColor: 9738662,
777
+ backgroundColor: 16316922,
778
+ tooltip: "Position"
779
+ })), r;
780
+ };
781
+ function _e(e, r) {
782
+ e.children.forEach((t) => {
783
+ if (t.type === "HightlightMesh")
784
+ return;
785
+ const n = ye(t);
786
+ r.children.push(n), _e(t, n);
787
+ });
788
+ }
789
+ const $t = [], O = "tres:inspector", Ut = le({
790
+ sceneGraph: null
791
+ });
792
+ function Ft(e, r) {
793
+ Nt(
794
+ {
795
+ id: "dev.esm.tres",
796
+ label: "TresJS 🪐",
797
+ logo: "https://raw.githubusercontent.com/Tresjs/tres/main/public/favicon.svg",
798
+ packageName: "tresjs",
799
+ homepage: "https://tresjs.org",
800
+ componentStateTypes: $t,
801
+ app: e
802
+ },
803
+ (t) => {
804
+ typeof t.now != "function" && Vt(
805
+ // eslint-disable-next-line max-len
806
+ "You seem to be using an outdated version of Vue Devtools. Are you still using the Beta release instead of the stable one? You can find the links at https://devtools.vuejs.org/guide/installation.html."
807
+ ), t.addInspector({
808
+ id: O,
809
+ label: "TresJS 🪐",
810
+ icon: "account_tree",
811
+ treeFilterPlaceholder: "Search instances"
812
+ }), setInterval(() => {
813
+ t.sendInspectorTree(O);
814
+ }, 1e3), setInterval(() => {
815
+ t.notifyComponentUpdate();
816
+ }, 5e3), t.on.getInspectorTree((s) => {
817
+ if (s.inspectorId === O) {
818
+ const o = ye(r.scene.value);
819
+ _e(r.scene.value, o), Ut.sceneGraph = o, s.rootNodes = [o];
820
+ }
821
+ });
822
+ let n = null, a = null;
823
+ t.on.getInspectorState((s) => {
824
+ if (s.inspectorId === O) {
825
+ const [o] = r.scene.value.getObjectsByProperty("uuid", s.nodeId);
826
+ if (!o)
827
+ return;
828
+ if (a && n && n.parent && a.remove(n), o.isMesh) {
829
+ const i = wt(o);
830
+ o.add(i), n = i, a = o;
831
+ }
832
+ s.state = {
833
+ object: [
834
+ {
835
+ key: "uuid",
836
+ editable: !0,
837
+ value: o.uuid
838
+ },
839
+ {
840
+ key: "name",
841
+ editable: !0,
842
+ value: o.name
843
+ },
844
+ {
845
+ key: "type",
846
+ editable: !0,
847
+ value: o.type
848
+ },
849
+ {
850
+ key: "position",
851
+ editable: !0,
852
+ value: o.position
853
+ },
854
+ {
855
+ key: "rotation",
856
+ editable: !0,
857
+ value: o.rotation
858
+ },
859
+ {
860
+ key: "scale",
861
+ editable: !0,
862
+ value: o.scale
863
+ },
864
+ {
865
+ key: "geometry",
866
+ value: o.geometry
867
+ },
868
+ {
869
+ key: "material",
870
+ value: o.material
871
+ },
872
+ {
873
+ key: "color",
874
+ editable: !0,
875
+ value: o.color
876
+ },
877
+ {
878
+ key: "intensity",
879
+ editable: !0,
880
+ value: o.intensity
881
+ },
882
+ {
883
+ key: "castShadow",
884
+ editable: !0,
885
+ value: o.castShadow
886
+ },
887
+ {
888
+ key: "receiveShadow",
889
+ editable: !0,
890
+ value: o.receiveShadow
891
+ },
892
+ {
893
+ key: "frustumCulled",
894
+ editable: !0,
895
+ value: o.frustumCulled
896
+ },
897
+ {
898
+ key: "matrixAutoUpdate",
899
+ editable: !0,
900
+ value: o.matrixAutoUpdate
901
+ },
902
+ {
903
+ key: "matrixWorldNeedsUpdate",
904
+ editable: !0,
905
+ value: o.matrixWorldNeedsUpdate
906
+ },
907
+ {
908
+ key: "matrixWorld",
909
+ value: o.matrixWorld
910
+ },
911
+ {
912
+ key: "visible",
913
+ editable: !0,
914
+ value: o.visible
915
+ }
916
+ ]
917
+ };
918
+ }
919
+ }), t.on.editInspectorState((s) => {
920
+ s.inspectorId === O && _t(r.scene.value, s.nodeId, s.path, s.state.value);
921
+ });
922
+ }
923
+ );
924
+ }
925
+ const Gt = ["data-scene"], zt = /* @__PURE__ */ Z({
585
926
  __name: "TresCanvas",
586
927
  props: {
587
928
  shadows: { type: Boolean, default: void 0 },
@@ -607,107 +948,107 @@ const gt = ["data-scene"], yt = /* @__PURE__ */ q({
607
948
  logarithmicDepthBuffer: { type: Boolean, default: void 0 },
608
949
  failIfMajorPerformanceCaveat: { type: Boolean, default: void 0 }
609
950
  },
610
- setup(e, { expose: a }) {
611
- var E;
612
- const t = e, { logWarning: r } = x(), n = B(), o = L(new je()), { resume: c } = se(), s = ye(), l = (E = J()) == null ? void 0 : E.appContext.app, i = (m) => q({
951
+ setup(e, { expose: r }) {
952
+ var _;
953
+ const t = e, { logWarning: n } = j(), a = B(), s = D(new qe()), { resume: o } = me(), i = Oe(), l = (_ = ee()) == null ? void 0 : _.appContext.app, c = (d) => Z({
613
954
  setup() {
614
- var d;
615
- const w = (d = J()) == null ? void 0 : d.appContext;
616
- return w && (w.app = l), V("useTres", m), V("extend", Y), () => K(he, null, s != null && s.default ? s.default() : []);
955
+ var p;
956
+ const y = (p = ee()) == null ? void 0 : p.appContext;
957
+ return y && (y.app = l), Q("useTres", d), Q("extend", X), typeof window < "u" && Ft(y.app, d), () => te(je, null, i != null && i.default ? i.default() : []);
617
958
  }
618
- }), p = (m) => {
619
- const w = i(m);
620
- vt(K(w), o.value);
621
- }, f = (m, w = !1) => {
622
- o.value.children = [], w && (m.renderer.value.dispose(), m.renderer.value.renderLists.dispose(), m.renderer.value.forceContextLoss()), p(m), c();
623
- }, u = b(() => t.disableRender), v = L(null);
624
- return a({ context: v, dispose: () => f(v.value, !0) }), we(() => {
625
- const m = n;
626
- v.value = mt({
627
- scene: o.value,
628
- canvas: m,
959
+ }), m = (d) => {
960
+ const y = c(d);
961
+ xt(te(y), s.value);
962
+ }, f = (d, y = !1) => {
963
+ s.value.children = [], y && (d.renderer.value.dispose(), d.renderer.value.renderLists.dispose(), d.renderer.value.forceContextLoss()), m(d), o();
964
+ }, u = k(() => t.disableRender), g = D(null);
965
+ return r({ context: g, dispose: () => f(g.value, !0) }), Ae(() => {
966
+ const d = a;
967
+ g.value = Tt({
968
+ scene: s.value,
969
+ canvas: d,
629
970
  windowSize: t.windowSize,
630
971
  disableRender: u,
631
972
  rendererOptions: t
632
- }), ct({ scene: o.value, contextParts: v.value });
633
- const { registerCamera: w, camera: d, cameras: h, deregisterCamera: P } = v.value;
634
- p(v.value);
635
- const A = () => {
636
- const C = new G(
973
+ }), St({ scene: s.value, contextParts: g.value });
974
+ const { registerCamera: y, camera: p, cameras: C, deregisterCamera: M } = g.value;
975
+ m(g.value);
976
+ const P = () => {
977
+ const w = new Y(
637
978
  45,
638
979
  window.innerWidth / window.innerHeight,
639
980
  0.1,
640
981
  1e3
641
982
  );
642
- C.position.set(3, 3, 3), C.lookAt(0, 0, 0), w(C);
643
- const k = D(() => {
644
- h.value.length >= 2 && (C.removeFromParent(), P(C), k == null || k());
983
+ w.position.set(3, 3, 3), w.lookAt(0, 0, 0), y(w);
984
+ const S = A(() => {
985
+ C.value.length >= 2 && (w.removeFromParent(), M(w), S == null || S());
645
986
  });
646
987
  };
647
- re(
988
+ ie(
648
989
  () => t.camera,
649
- (C, k) => {
650
- C && w(C), k && (k.removeFromParent(), P(k));
990
+ (w, S) => {
991
+ w && y(w), S && (S.removeFromParent(), M(S));
651
992
  },
652
993
  {
653
994
  immediate: !0
654
995
  }
655
- ), d.value || (r(
996
+ ), p.value || (n(
656
997
  "No camera found. Creating a default perspective camera. To have full control over a camera, please add one to the scene."
657
- ), A());
658
- }), (m, w) => (Ee(), Ce("canvas", {
998
+ ), P());
999
+ }), (d, y) => (xe(), De("canvas", {
659
1000
  ref_key: "canvas",
660
- ref: n,
661
- "data-scene": o.value.uuid,
662
- class: _e(m.$attrs.class),
663
- style: Me({
1001
+ ref: a,
1002
+ "data-scene": s.value.uuid,
1003
+ class: Le(d.$attrs.class),
1004
+ style: Be({
664
1005
  display: "block",
665
1006
  width: "100%",
666
1007
  height: "100%",
667
- position: m.windowSize ? "fixed" : "relative",
1008
+ position: d.windowSize ? "fixed" : "relative",
668
1009
  top: 0,
669
1010
  left: 0,
670
1011
  pointerEvents: "auto",
671
1012
  touchAction: "none",
672
- ...m.$attrs.style
1013
+ ...d.$attrs.style
673
1014
  })
674
- }, null, 14, gt));
1015
+ }, null, 14, Gt));
675
1016
  }
676
- }), wt = [
1017
+ }), Wt = [
677
1018
  "TresCanvas",
678
1019
  "TresLeches",
679
1020
  "TresScene"
680
- ], Et = {
1021
+ ], Qt = {
681
1022
  template: {
682
1023
  compilerOptions: {
683
- isCustomElement: (e) => e.startsWith("Tres") && !wt.includes(e) || e === "primitive"
1024
+ isCustomElement: (e) => e.startsWith("Tres") && !Wt.includes(e) || e === "primitive"
684
1025
  }
685
1026
  }
686
- }, Lt = Et, St = {
1027
+ }, ar = Qt, sr = {
687
1028
  install(e) {
688
- e.component("TresCanvas", yt);
1029
+ e.component("TresCanvas", zt);
689
1030
  }
690
1031
  };
691
1032
  export {
692
- yt as TresCanvas,
693
- W as catalogue,
694
- St as default,
695
- Y as extend,
696
- Pt as isProd,
697
- Xe as normalizeColor,
698
- At as normalizeVectorFlexibleParam,
699
- Lt as templateCompilerOptions,
700
- ut as trasverseObjects,
701
- Ye as useCamera,
702
- kt as useLoader,
703
- x as useLogger,
704
- ct as usePointerEventHandler,
705
- lt as useRaycaster,
706
- se as useRenderLoop,
707
- st as useRenderer,
708
- Dt as useSeek,
709
- bt as useTexture,
710
- Tt as useTres,
711
- pt as useTresContext,
712
- mt as useTresContextProvider
1033
+ zt as TresCanvas,
1034
+ J as catalogue,
1035
+ sr as default,
1036
+ X as extend,
1037
+ Zt as isProd,
1038
+ ct as normalizeColor,
1039
+ er as normalizeVectorFlexibleParam,
1040
+ ar as templateCompilerOptions,
1041
+ Mt as trasverseObjects,
1042
+ st as useCamera,
1043
+ tr as useLoader,
1044
+ j as useLogger,
1045
+ St as usePointerEventHandler,
1046
+ Pt as useRaycaster,
1047
+ me as useRenderLoop,
1048
+ Et as useRenderer,
1049
+ nr as useSeek,
1050
+ rr as useTexture,
1051
+ or as useTres,
1052
+ Ot as useTresContext,
1053
+ Tt as useTresContextProvider
713
1054
  };