@tresjs/core 2.2.0 → 2.3.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/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from './composables';
3
3
  export * from './core/catalogue';
4
4
  export * from './components';
5
5
  export * from './types';
6
+ import { normalizeColor, normalizeVectorFlexibleParam } from './utils/normalize';
6
7
  export interface TresOptions {
7
8
  extends?: Record<string, unknown>;
8
9
  }
@@ -12,3 +13,4 @@ export interface TresPlugin {
12
13
  }
13
14
  declare const plugin: TresPlugin;
14
15
  export default plugin;
16
+ export { normalizeColor, normalizeVectorFlexibleParam };
package/dist/tres.js CHANGED
@@ -1,23 +1,23 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v2.2.0
3
+ * version: v2.3.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 G, shallowReactive as ce, toRefs as ue, provide as Te, inject as Le, watchEffect as fe, toRef as _e, shallowRef as Ae, computed as V, watch as D, onUnmounted as le, reactive as Se, createRenderer as Oe, defineComponent as de, onMounted as ke, h as L } from "vue";
8
+ import { ref as V, shallowReactive as ce, toRefs as ue, provide as Te, inject as Le, watchEffect as fe, toRef as _e, shallowRef as Ae, computed as G, watch as D, onUnmounted as le, reactive as Se, createRenderer as Oe, defineComponent as de, onMounted as ke, h as L } from "vue";
9
9
  import * as q from "three";
10
- import { PerspectiveCamera as z, OrthographicCamera as je, Clock as pe, Color as W, SRGBColorSpace as De, ACESFilmicToneMapping as Ie, PCFSoftShadowMap as Be, PCFShadowMap as He, LinearSRGBColorSpace as ae, NoToneMapping as ne, WebGLRenderer as Ge, LoadingManager as Ve, TextureLoader as Ne, Raycaster as Fe, Vector2 as ze, BufferAttribute as We } from "three";
11
- import { createEventHook as A, useRafFn as Ue, toValue as m, useWindowSize as Ye, useElementSize as $e, useDevicePixelRatio as qe, unrefElement as U, usePointer as Ke, useElementBounding as Je } from "@vueuse/core";
12
- const me = G({}), ve = (e) => void Object.assign(me.value, e), re = (e) => typeof e == "function", ge = (e) => !!e && e.constructor === Array, b = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"];
13
- function Xe() {
10
+ import { PerspectiveCamera as z, OrthographicCamera as je, Clock as pe, Vector3 as De, Color as W, SRGBColorSpace as Ie, ACESFilmicToneMapping as Be, PCFSoftShadowMap as He, PCFShadowMap as Ve, LinearSRGBColorSpace as ae, NoToneMapping as ne, WebGLRenderer as Ge, LoadingManager as Fe, TextureLoader as Ne, Raycaster as ze, Vector2 as We, BufferAttribute as Ue } from "three";
11
+ import { createEventHook as A, useRafFn as Ye, toValue as m, useWindowSize as $e, useElementSize as qe, useDevicePixelRatio as Ke, unrefElement as U, usePointer as Je, useElementBounding as Xe } from "@vueuse/core";
12
+ const me = V({}), ve = (e) => void Object.assign(me.value, e), re = (e) => typeof e == "function", ge = (e) => !!e && e.constructor === Array, b = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"];
13
+ function Qe() {
14
14
  const e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, n = Math.random() * 4294967295 | 0, a = Math.random() * 4294967295 | 0;
15
15
  return (b[e & 255] + b[e >> 8 & 255] + b[e >> 16 & 255] + b[e >> 24 & 255] + "-" + b[t & 255] + b[t >> 8 & 255] + "-" + b[t >> 16 & 15 | 64] + b[t >> 24 & 255] + "-" + b[n & 63 | 128] + b[n >> 8 & 255] + "-" + b[n >> 16 & 255] + b[n >> 24 & 255] + b[a & 255] + b[a >> 8 & 255] + b[a >> 16 & 255] + b[a >> 24 & 255]).toLowerCase();
16
16
  }
17
17
  const K = Symbol();
18
- function Qe() {
18
+ function Ze() {
19
19
  const e = ce({
20
- uuid: Xe(),
20
+ uuid: Qe(),
21
21
  camera: void 0,
22
22
  cameras: [],
23
23
  canvas: void 0,
@@ -50,10 +50,10 @@ const S = () => Le(K, {
50
50
  pointerEventHandler: void 0
51
51
  })
52
52
  });
53
- var Ze = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Ze || {});
54
- const et = 45;
55
- let x;
56
- function tt() {
53
+ var et = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(et || {});
54
+ const tt = 45;
55
+ let R;
56
+ function at() {
57
57
  const { state: e, setState: t, aspectRatio: n } = S();
58
58
  function a(s = "Perspective", c) {
59
59
  var l, d, p;
@@ -61,9 +61,9 @@ function tt() {
61
61
  const { near: y, far: h, fov: v } = c || {
62
62
  near: 0.1,
63
63
  far: 1e3,
64
- fov: et
64
+ fov: tt
65
65
  };
66
- x = new z(v, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, y, h), (d = e.cameras) == null || d.push(x);
66
+ R = new z(v, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, y, h), (d = e.cameras) == null || d.push(R);
67
67
  } else {
68
68
  const { left: y, right: h, top: v, bottom: M, near: w, far: E } = c || {
69
69
  left: -100,
@@ -73,9 +73,9 @@ function tt() {
73
73
  near: 0.1,
74
74
  far: 1e3
75
75
  };
76
- x = new je(y, h, v, M, w, E), (p = e.cameras) == null || p.push(x);
76
+ R = new je(y, h, v, M, w, E), (p = e.cameras) == null || p.push(R);
77
77
  }
78
- return e.camera = x, t("camera", e.camera), x;
78
+ return e.camera = R, t("camera", e.camera), R;
79
79
  }
80
80
  function o() {
81
81
  var s;
@@ -105,7 +105,7 @@ function tt() {
105
105
  }
106
106
  const we = A(), be = A(), J = A(), _ = new pe();
107
107
  let I = 0, B = 0;
108
- const { pause: at, resume: nt, isActive: rt } = Ue(
108
+ const { pause: nt, resume: rt, isActive: ot } = Ye(
109
109
  () => {
110
110
  we.trigger({ delta: I, elapsed: B, clock: _ }), be.trigger({ delta: I, elapsed: B, clock: _ }), J.trigger({ delta: I, elapsed: B, clock: _ });
111
111
  },
@@ -119,46 +119,49 @@ function he() {
119
119
  onBeforeLoop: we.on,
120
120
  onLoop: be.on,
121
121
  onAfterLoop: J.on,
122
- pause: at,
123
- resume: nt,
124
- isActive: rt
122
+ pause: nt,
123
+ resume: rt,
124
+ isActive: ot
125
125
  };
126
126
  }
127
- function ot(e) {
127
+ function Pt(e) {
128
+ return typeof e == "number" ? [e, e, e] : e instanceof De ? [e.x, e.y, e.z] : e;
129
+ }
130
+ function it(e) {
128
131
  return e instanceof W ? e : Array.isArray(e) ? new W(...e) : new W(e);
129
132
  }
130
133
  const Y = {
131
134
  realistic: {
132
- outputColorSpace: De,
133
- toneMapping: Ie,
135
+ outputColorSpace: Ie,
136
+ toneMapping: Be,
134
137
  toneMappingExposure: 3,
135
138
  shadowMap: {
136
139
  enabled: !0,
137
- type: Be
140
+ type: He
138
141
  }
139
142
  }
140
143
  }, ye = (e, t) => {
141
144
  for (const n of Object.keys(t))
142
145
  t[n] instanceof Object && Object.assign(t[n], ye(e[n], t[n]));
143
146
  return Object.assign(e || {}, t), e;
144
- }, it = "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", st = /* @__PURE__ */ ct(it);
147
+ }, st = "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", ct = /* @__PURE__ */ ut(st);
145
148
  function j(e) {
146
149
  return e.replace(/-([a-z])/g, (t, n) => n.toUpperCase());
147
150
  }
148
- function ct(e, t) {
151
+ function ut(e, t) {
149
152
  const n = /* @__PURE__ */ Object.create(null), a = e.split(",");
150
153
  for (let o = 0; o < a.length; o++)
151
154
  n[a[o]] = !0;
152
155
  return t ? (o) => !!n[o.toLowerCase()] : (o) => !!n[o];
153
156
  }
154
- const ut = (e, t) => {
157
+ const ft = (e, t) => {
155
158
  const n = /* @__PURE__ */ new Set(), a = [];
156
159
  for (const o of e) {
157
160
  const i = t(o);
158
161
  n.has(i) || (n.add(i), a.push(o));
159
162
  }
160
163
  return a;
161
- }, Mt = !0, oe = "[TresJS ▲ ■ ●] ";
164
+ }, xt = !0, oe = "[TresJS ▲ ■ ●] ";
162
165
  function O() {
163
166
  function e(a, o) {
164
167
  console.error(`${oe} ${a}`, o || "");
@@ -174,8 +177,8 @@ function O() {
174
177
  logMessage: n
175
178
  };
176
179
  }
177
- function ft(e) {
178
- const t = Ae(), n = G(!1), {
180
+ function lt(e) {
181
+ const t = Ae(), n = V(!1), {
179
182
  alpha: a = !0,
180
183
  antialias: o = !0,
181
184
  depth: i,
@@ -185,7 +188,7 @@ function ft(e) {
185
188
  premultipliedAlpha: c,
186
189
  stencil: l,
187
190
  shadows: d = !1,
188
- shadowMapType: p = He,
191
+ shadowMapType: p = Ve,
189
192
  useLegacyLights: y = !1,
190
193
  outputColorSpace: h = ae,
191
194
  toneMapping: v = ne,
@@ -193,13 +196,13 @@ function ft(e) {
193
196
  context: w = void 0,
194
197
  powerPreference: E = "default",
195
198
  preserveDrawingBuffer: k = !1,
196
- clearColor: C,
197
- windowSize: R = !1,
198
- preset: N = void 0
199
- } = ue(e), { state: f, setState: g } = S(), { width: X, height: Q } = m(R) == !0 || m(R) === "" || m(R) === "true" ? Ye() : $e(f.container), { logError: Ee, logWarning: Me } = O(), { pixelRatio: Z } = qe(), { pause: Pe, resume: Ce } = he(), F = V(() => X.value / Q.value);
199
+ clearColor: x,
200
+ windowSize: C = !1,
201
+ preset: F = void 0
202
+ } = ue(e), { state: f, setState: g } = S(), { width: X, height: Q } = m(C) == !0 || m(C) === "" || m(C) === "true" ? $e() : qe(f.container), { logError: Ee, logWarning: Me } = O(), { pixelRatio: Z } = Ke(), { pause: Pe, resume: xe } = he(), N = G(() => X.value / Q.value);
200
203
  setTimeout(() => {
201
204
  var P;
202
- !m(R) && !((P = f.canvas) != null && P.value.offsetHeight) && Me(`Oops... Seems like your canvas height is currently 0px, it's posible that you couldn't watch your scene.
205
+ !m(C) && !((P = f.canvas) != null && P.value.offsetHeight) && Me(`Oops... Seems like your canvas height is currently 0px, it's posible that you couldn't watch your scene.
203
206
  You could set windowSize=true to force the canvas to be the size of the window.`);
204
207
  }, 1e3);
205
208
  const ee = () => {
@@ -207,13 +210,13 @@ function ft(e) {
207
210
  }, te = () => {
208
211
  if (!t.value)
209
212
  return;
210
- const P = m(N);
213
+ const P = m(F);
211
214
  if (P) {
212
215
  P in Y || Ee("Renderer Preset must be one of these: " + Object.keys(Y).join(", ")), ye(t.value, Y[P]);
213
216
  return;
214
217
  }
215
- t.value.shadowMap.enabled = m(d), t.value.shadowMap.type = m(p), t.value.toneMapping = m(v) || ne, t.value.toneMappingExposure = m(M), t.value.outputColorSpace = m(h) || ae, C != null && C.value && t.value.setClearColor(ot(m(C))), t.value.useLegacyLights = m(y);
216
- }, Re = () => {
218
+ t.value.shadowMap.enabled = m(d), t.value.shadowMap.type = m(p), t.value.toneMapping = m(v) || ne, t.value.toneMappingExposure = m(M), t.value.outputColorSpace = m(h) || ae, x != null && x.value && t.value.setClearColor(it(m(x))), t.value.useLegacyLights = m(y);
219
+ }, Ce = () => {
217
220
  const P = U(f.canvas);
218
221
  P && (t.value = new Ge({
219
222
  canvas: P,
@@ -228,33 +231,33 @@ function ft(e) {
228
231
  stencil: m(l),
229
232
  preserveDrawingBuffer: m(k),
230
233
  premultipliedAlpha: m(c)
231
- }), g("renderer", t.value), g("clock", new pe()), g("aspectRatio", F), te(), ee(), Ce(), n.value = !0);
232
- }, xe = () => {
234
+ }), g("renderer", t.value), g("clock", new pe()), g("aspectRatio", N), te(), ee(), xe(), n.value = !0);
235
+ }, Re = () => {
233
236
  t.value && (t.value.dispose(), t.value = void 0, n.value = !1, Pe());
234
237
  };
235
- return D([F, Z], ee), D(
236
- [d, p, h, y, v, M, C],
238
+ return D([N, Z], ee), D(
239
+ [d, p, h, y, v, M, x],
237
240
  te
238
241
  ), D(
239
242
  () => [f.canvas, f.container],
240
243
  () => {
241
- U(f.canvas) && U(f.container) && Re();
244
+ U(f.canvas) && U(f.container) && Ce();
242
245
  },
243
246
  { immediate: !0, deep: !0 }
244
247
  ), {
245
248
  renderer: t,
246
249
  isReady: n,
247
- dispose: xe,
248
- aspectRatio: F
250
+ dispose: Re,
251
+ aspectRatio: N
249
252
  };
250
253
  }
251
- function lt(e) {
254
+ function dt(e) {
252
255
  const t = { nodes: {}, materials: {} };
253
256
  return e && e.traverse((n) => {
254
257
  n.name && (t.nodes[n.name] = n), n.material && !t.materials[n.material.name] && (t.materials[n.material.name] = n.material);
255
258
  }), t;
256
259
  }
257
- async function Pt(e, t, n, a, o) {
260
+ async function Ct(e, t, n, a, o) {
258
261
  const { logError: i } = O(), u = new e();
259
262
  o && o(u), n && n(u);
260
263
  const s = (Array.isArray(t) ? t : [t]).map(
@@ -262,7 +265,7 @@ async function Pt(e, t, n, a, o) {
262
265
  u.load(
263
266
  c,
264
267
  (p) => {
265
- p.scene && Object.assign(p, lt(p.scene)), l(p);
268
+ p.scene && Object.assign(p, dt(p.scene)), l(p);
266
269
  },
267
270
  a,
268
271
  (p) => d(i("[useLoader] - Failed to load resource", p))
@@ -271,8 +274,8 @@ async function Pt(e, t, n, a, o) {
271
274
  );
272
275
  return ge(t) ? await Promise.all(s) : await s[0];
273
276
  }
274
- async function Ct(e) {
275
- const t = new Ve(), n = new Ne(t), a = (o) => new Promise((i, u) => {
277
+ async function Rt(e) {
278
+ const t = new Fe(), n = new Ne(t), a = (o) => new Promise((i, u) => {
276
279
  n.load(
277
280
  o,
278
281
  (r) => i(r),
@@ -308,11 +311,11 @@ async function Ct(e) {
308
311
  };
309
312
  }
310
313
  }
311
- const dt = (e) => {
312
- const { state: t } = S(), n = V(() => {
314
+ const pt = (e) => {
315
+ const { state: t } = S(), n = G(() => {
313
316
  var f;
314
317
  return (f = t.canvas) == null ? void 0 : f.value;
315
- }), { x: a, y: o } = Ke({ target: n }), { width: i, height: u, top: r, left: s } = Je(n), c = new Fe(), l = ({ x: f, y: g }) => {
318
+ }), { x: a, y: o } = Je({ target: n }), { width: i, height: u, top: r, left: s } = Xe(n), c = new ze(), l = ({ x: f, y: g }) => {
316
319
  if (n.value)
317
320
  return {
318
321
  x: (f - s.value) / i.value * 2 - 1,
@@ -320,14 +323,14 @@ const dt = (e) => {
320
323
  };
321
324
  }, d = ({ x: f, y: g }) => {
322
325
  if (t.camera)
323
- return c.setFromCamera(new ze(f, g), t.camera), c.intersectObjects(e.value, !1);
326
+ return c.setFromCamera(new We(f, g), t.camera), c.intersectObjects(e.value, !1);
324
327
  }, p = (f) => {
325
328
  const g = l({
326
329
  x: (f == null ? void 0 : f.clientX) ?? a.value,
327
330
  y: (f == null ? void 0 : f.clientY) ?? o.value
328
331
  });
329
332
  return g ? d(g) || [] : [];
330
- }, y = V(() => p()), h = A(), v = A(), M = (f, g) => {
333
+ }, y = G(() => p()), h = A(), v = A(), M = (f, g) => {
331
334
  f.trigger({ event: g, intersects: p(g) });
332
335
  }, w = (f) => {
333
336
  M(v, f);
@@ -336,21 +339,21 @@ const dt = (e) => {
336
339
  const k = (f) => {
337
340
  var g;
338
341
  E = (g = p(f)[0]) == null ? void 0 : g.object;
339
- }, C = (f) => {
342
+ }, x = (f) => {
340
343
  var g;
341
344
  f instanceof PointerEvent && E === ((g = p(f)[0]) == null ? void 0 : g.object) && M(h, f);
342
- }, R = (f) => v.trigger({ event: f, intersects: [] }), N = fe(() => {
343
- n != null && n.value && (n.value.addEventListener("pointerup", C), n.value.addEventListener("pointerdown", k), n.value.addEventListener("pointermove", w), n.value.addEventListener("pointerleave", R), N());
345
+ }, C = (f) => v.trigger({ event: f, intersects: [] }), F = fe(() => {
346
+ n != null && n.value && (n.value.addEventListener("pointerup", x), n.value.addEventListener("pointerdown", k), n.value.addEventListener("pointermove", w), n.value.addEventListener("pointerleave", C), F());
344
347
  });
345
348
  return le(() => {
346
- n != null && n.value && (n.value.removeEventListener("pointerup", C), n.value.removeEventListener("pointerdown", k), n.value.removeEventListener("pointermove", w), n.value.removeEventListener("pointerleave", R));
349
+ n != null && n.value && (n.value.removeEventListener("pointerup", x), n.value.removeEventListener("pointerdown", k), n.value.removeEventListener("pointermove", w), n.value.removeEventListener("pointerleave", C));
347
350
  }), {
348
351
  intersects: y,
349
352
  onClick: (f) => h.on(f).off,
350
353
  onPointerMove: (f) => v.on(f).off
351
354
  };
352
355
  };
353
- function Rt() {
356
+ function Tt() {
354
357
  const { logWarning: e } = O();
355
358
  function t(a, o, i) {
356
359
  let u = null;
@@ -366,7 +369,7 @@ function Rt() {
366
369
  seekByName: n
367
370
  };
368
371
  }
369
- const pt = () => {
372
+ const mt = () => {
370
373
  const e = Se({
371
374
  click: /* @__PURE__ */ new Map(),
372
375
  pointerMove: /* @__PURE__ */ new Map(),
@@ -381,12 +384,12 @@ const pt = () => {
381
384
  t(p);
382
385
  }), t(r);
383
386
  });
384
- }, a = V(
385
- () => ut(
387
+ }, a = G(
388
+ () => ft(
386
389
  Object.values(e).map((r) => Array.from(r.keys())).flat(),
387
390
  ({ uuid: r }) => r
388
391
  )
389
- ), { onClick: o, onPointerMove: i } = dt(a);
392
+ ), { onClick: o, onPointerMove: i } = pt(a);
390
393
  o(({ intersects: r, event: s }) => {
391
394
  var c;
392
395
  r.length && ((c = e.click.get(r[0].object)) == null || c(r[0], s));
@@ -406,10 +409,10 @@ const pt = () => {
406
409
  REGISTER_AT_POINTER_EVENT_HANDLER: "tres__registerAtPointerEventHandler"
407
410
  };
408
411
  let $ = null, T = null;
409
- const { logError: ie } = O(), mt = {
412
+ const { logError: ie } = O(), vt = {
410
413
  createElement(e, t, n, a) {
411
414
  var s, c;
412
- if (a || (a = {}), a.args || (a.args = []), e === "template" || st(e))
415
+ if (a || (a = {}), a.args || (a.args = []), e === "template" || ct(e))
413
416
  return null;
414
417
  let o = e.replace("Tres", ""), i;
415
418
  if (e === "primitive") {
@@ -457,7 +460,7 @@ const { logError: ie } = O(), mt = {
457
460
  return;
458
461
  o.setAttribute(
459
462
  j(i),
460
- new We(...a)
463
+ new Ue(...a)
461
464
  );
462
465
  return;
463
466
  }
@@ -485,15 +488,15 @@ const { logError: ie } = O(), mt = {
485
488
  setScopeId: () => void 0,
486
489
  cloneNode: () => void 0,
487
490
  insertStaticContent: () => void 0
488
- }, { createApp: vt } = Oe(mt), gt = (e) => {
489
- const t = vt(n);
491
+ }, { createApp: gt } = Oe(vt), wt = (e) => {
492
+ const t = gt(n);
490
493
  function n() {
491
494
  return e && e.default ? e.default() : [];
492
495
  }
493
496
  return t;
494
497
  };
495
498
  ve(q);
496
- const { logWarning: se } = O(), wt = de({
499
+ const { logWarning: se } = O(), bt = de({
497
500
  name: "TresScene",
498
501
  props: [
499
502
  "shadows",
@@ -514,7 +517,7 @@ const { logWarning: se } = O(), wt = de({
514
517
  ],
515
518
  setup(e, { slots: t, expose: n }) {
516
519
  e.physicallyCorrectLights === !0 && se("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
517
- const a = G(), o = G(), i = new q.Scene(), u = pt(), { setState: r } = S();
520
+ const a = V(), o = V(), i = new q.Scene(), u = mt(), { setState: r } = S();
518
521
  i.userData[H.REGISTER_AT_POINTER_EVENT_HANDLER] = u.registerObject, r("scene", i), r("canvas", o), r("container", a), r("pointerEventHandler", u);
519
522
  const { onLoop: s, resume: c } = he();
520
523
  ke(() => {
@@ -522,7 +525,7 @@ const { logWarning: se } = O(), wt = de({
522
525
  }), le(() => {
523
526
  r("renderer", null);
524
527
  });
525
- const { activeCamera: l, pushCamera: d, clearCameras: p } = tt();
528
+ const { activeCamera: l, pushCamera: d, clearCameras: p } = at();
526
529
  function y() {
527
530
  const w = i.getObjectByProperty("isCamera", !0);
528
531
  if (w)
@@ -534,7 +537,7 @@ const { logWarning: se } = O(), wt = de({
534
537
  }
535
538
  }
536
539
  function h() {
537
- const { renderer: w } = ft(e);
540
+ const { renderer: w } = lt(e);
538
541
  e.camera && d(e.camera), s(() => {
539
542
  var E;
540
543
  l.value && e.disableRender !== !0 && ((E = w.value) == null || E.render(i, l.value));
@@ -542,7 +545,7 @@ const { logWarning: se } = O(), wt = de({
542
545
  }
543
546
  let v;
544
547
  function M() {
545
- v = gt(t);
548
+ v = wt(t);
546
549
  const w = S();
547
550
  v.provide("useTres", w), v.provide(K, w), v.provide("extend", ve), v.mount(i), y();
548
551
  }
@@ -596,7 +599,7 @@ const { logWarning: se } = O(), wt = de({
596
599
  )
597
600
  );
598
601
  }
599
- }), bt = de({
602
+ }), ht = de({
600
603
  name: "TresCanvas",
601
604
  props: [
602
605
  "shadows",
@@ -616,32 +619,34 @@ const { logWarning: se } = O(), wt = de({
616
619
  "camera"
617
620
  ],
618
621
  setup(e, { slots: t, expose: n }) {
619
- const a = Qe();
620
- return n(a), () => L(wt, e, t);
622
+ const a = Ze();
623
+ return n(a), () => L(bt, e, t);
621
624
  }
622
- }), xt = {
625
+ }), Lt = {
623
626
  install(e) {
624
- e.component("TresCanvas", bt);
627
+ e.component("TresCanvas", ht);
625
628
  }
626
629
  };
627
630
  export {
628
- Ze as CameraType,
631
+ et as CameraType,
629
632
  K as TRES_CONTEXT_KEY,
630
- bt as TresCanvas,
633
+ ht as TresCanvas,
631
634
  me as catalogue,
632
- xt as default,
635
+ Lt as default,
633
636
  ve as extend,
634
- Mt as isProd,
635
- lt as trasverseObjects,
636
- tt as useCamera,
637
- Pt as useLoader,
637
+ xt as isProd,
638
+ it as normalizeColor,
639
+ Pt as normalizeVectorFlexibleParam,
640
+ dt as trasverseObjects,
641
+ at as useCamera,
642
+ Ct as useLoader,
638
643
  O as useLogger,
639
- pt as usePointerEventHandler,
640
- dt as useRaycaster,
644
+ mt as usePointerEventHandler,
645
+ pt as useRaycaster,
641
646
  he as useRenderLoop,
642
- ft as useRenderer,
643
- Rt as useSeek,
644
- Ct as useTexture,
647
+ lt as useRenderer,
648
+ Tt as useSeek,
649
+ Rt as useTexture,
645
650
  S as useTres,
646
- Qe as useTresProvider
651
+ Ze as useTresProvider
647
652
  };
package/dist/tres.umd.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v2.2.0
3
+ * version: v2.3.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
- (function(m,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],f):(m=typeof globalThis<"u"?globalThis:m||self,f(m.tres={},m.Vue,m.Three,m.VueUseCore))})(this,function(m,f,g,l){"use strict";function ge(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const N=ge(g),F=f.ref({}),z=e=>void Object.assign(F.value,e),H=e=>typeof e=="function",X=e=>!!e&&e.constructor===Array,P=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];function he(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0,a=Math.random()*4294967295|0;return(P[e&255]+P[e>>8&255]+P[e>>16&255]+P[e>>24&255]+"-"+P[t&255]+P[t>>8&255]+"-"+P[t>>16&15|64]+P[t>>24&255]+"-"+P[n&63|128]+P[n>>8&255]+"-"+P[n>>16&255]+P[n>>24&255]+P[a&255]+P[a>>8&255]+P[a>>16&255]+P[a>>24&255]).toLowerCase()}const V=Symbol();function J(){const e=f.shallowReactive({uuid:he(),camera:void 0,cameras:[],canvas:void 0,scene:void 0,renderer:void 0,aspectRatio:void 0,pointerEventHandler:void 0});function t(o){return e[o]}function n(o,i){e[o]=i}const a={state:e,...f.toRefs(e),getState:t,setState:n};return f.provide(V,a),a}const A=()=>f.inject(V,{state:f.shallowReactive({camera:void 0,cameras:[],canvas:void 0,scene:void 0,renderer:void 0,pointerEventHandler:void 0})});var Q=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(Q||{});const we=45;let E;function Z(){const{state:e,setState:t,aspectRatio:n}=A();function a(s="Perspective",c){var p,v,h;if(s==="Perspective"){const{near:M,far:C,fov:w}=c||{near:.1,far:1e3,fov:we};E=new g.PerspectiveCamera(w,((p=e.aspectRatio)==null?void 0:p.value)||window.innerWidth/window.innerHeight,M,C),(v=e.cameras)==null||v.push(E)}else{const{left:M,right:C,top:w,bottom:L,near:y,far:_}=c||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};E=new g.OrthographicCamera(M,C,w,L,y,_),(h=e.cameras)==null||h.push(E)}return e.camera=E,t("camera",e.camera),E}function o(){var s;e.camera instanceof g.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(s=e.camera)==null||s.updateProjectionMatrix()}function i(s){var c;(c=e.cameras)==null||c.push(s),s instanceof g.PerspectiveCamera&&e.aspectRatio&&(s.aspect=e.aspectRatio.value),s.updateProjectionMatrix(),t("camera",s)}function u(s){var c;((c=e.cameras)==null?void 0:c.length)===0&&i(s)}function r(){e.cameras=[]}return f.watchEffect(()=>{n!=null&&n.value&&o()}),{activeCamera:f.toRef(e,"camera"),createCamera:a,updateCamera:o,pushCamera:i,clearCameras:r,setFirstCamera:u}}const ee=l.createEventHook(),te=l.createEventHook(),W=l.createEventHook(),x=new g.Clock;let j=0,D=0;const{pause:be,resume:ye,isActive:Pe}=l.useRafFn(()=>{ee.trigger({delta:j,elapsed:D,clock:x}),te.trigger({delta:j,elapsed:D,clock:x}),W.trigger({delta:j,elapsed:D,clock:x})},{immediate:!1});W.on(()=>{j=x.getDelta(),D=x.getElapsedTime()});function U(){return{onBeforeLoop:ee.on,onLoop:te.on,onAfterLoop:W.on,pause:be,resume:ye,isActive:Pe}}function Ce(e){return e instanceof g.Color?e:Array.isArray(e)?new g.Color(...e):new g.Color(e)}const Y={realistic:{outputColorSpace:g.SRGBColorSpace,toneMapping:g.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:g.PCFSoftShadowMap}}},ae=(e,t)=>{for(const n of Object.keys(t))t[n]instanceof Object&&Object.assign(t[n],ae(e[n],t[n]));return Object.assign(e||{},t),e},Me=_e("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");function I(e){return e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}function _e(e,t){const n=Object.create(null),a=e.split(",");for(let o=0;o<a.length;o++)n[a[o]]=!0;return t?o=>!!n[o.toLowerCase()]:o=>!!n[o]}const Le=(e,t)=>{const n=new Set,a=[];for(const o of e){const i=t(o);n.has(i)||(n.add(i),a.push(o))}return a},Se=!0,ne="[TresJS ▲ ■ ●] ";function R(){function e(a,o){console.error(`${ne} ${a}`,o||"")}function t(a){console.warn(`${ne} ${a}`)}function n(a,o){}return{logError:e,logWarning:t,logMessage:n}}function re(e){const t=f.shallowRef(),n=f.ref(!1),{alpha:a=!0,antialias:o=!0,depth:i,logarithmicDepthBuffer:u,failIfMajorPerformanceCaveat:r,precision:s,premultipliedAlpha:c,stencil:p,shadows:v=!1,shadowMapType:h=g.PCFShadowMap,useLegacyLights:M=!1,outputColorSpace:C=g.LinearSRGBColorSpace,toneMapping:w=g.NoToneMapping,toneMappingExposure:L=1,context:y=void 0,powerPreference:_="default",preserveDrawingBuffer:G=!1,clearColor:O,windowSize:T=!1,preset:$=void 0}=f.toRefs(e),{state:d,setState:b}=A(),{width:le,height:de}=l.toValue(T)==!0||l.toValue(T)===""||l.toValue(T)==="true"?l.useWindowSize():l.useElementSize(d.container),{logError:je,logWarning:De}=R(),{pixelRatio:pe}=l.useDevicePixelRatio(),{pause:Ie,resume:Be}=U(),K=f.computed(()=>le.value/de.value);setTimeout(()=>{var S;!l.toValue(T)&&!((S=d.canvas)!=null&&S.value.offsetHeight)&&De(`Oops... Seems like your canvas height is currently 0px, it's posible that you couldn't watch your scene.
9
- You could set windowSize=true to force the canvas to be the size of the window.`)},1e3);const me=()=>{t.value&&(t.value.setSize(le.value,de.value),t.value.setPixelRatio(Math.min(pe.value,2)))},ve=()=>{if(!t.value)return;const S=l.toValue($);if(S){S in Y||je("Renderer Preset must be one of these: "+Object.keys(Y).join(", ")),ae(t.value,Y[S]);return}t.value.shadowMap.enabled=l.toValue(v),t.value.shadowMap.type=l.toValue(h),t.value.toneMapping=l.toValue(w)||g.NoToneMapping,t.value.toneMappingExposure=l.toValue(L),t.value.outputColorSpace=l.toValue(C)||g.LinearSRGBColorSpace,O!=null&&O.value&&t.value.setClearColor(Ce(l.toValue(O))),t.value.useLegacyLights=l.toValue(M)},Ge=()=>{const S=l.unrefElement(d.canvas);S&&(t.value=new g.WebGLRenderer({canvas:S,alpha:l.toValue(a),antialias:l.toValue(o),context:l.toValue(y),depth:l.toValue(i),failIfMajorPerformanceCaveat:l.toValue(r),logarithmicDepthBuffer:l.toValue(u),powerPreference:l.toValue(_),precision:l.toValue(s),stencil:l.toValue(p),preserveDrawingBuffer:l.toValue(G),premultipliedAlpha:l.toValue(c)}),b("renderer",t.value),b("clock",new g.Clock),b("aspectRatio",K),ve(),me(),Be(),n.value=!0)},Ne=()=>{t.value&&(t.value.dispose(),t.value=void 0,n.value=!1,Ie())};return f.watch([K,pe],me),f.watch([v,h,C,M,w,L,O],ve),f.watch(()=>[d.canvas,d.container],()=>{l.unrefElement(d.canvas)&&l.unrefElement(d.container)&&Ge()},{immediate:!0,deep:!0}),{renderer:t,isReady:n,dispose:Ne,aspectRatio:K}}function oe(e){const t={nodes:{},materials:{}};return e&&e.traverse(n=>{n.name&&(t.nodes[n.name]=n),n.material&&!t.materials[n.material.name]&&(t.materials[n.material.name]=n.material)}),t}async function Oe(e,t,n,a,o){const{logError:i}=R(),u=new e;o&&o(u),n&&n(u);const s=(Array.isArray(t)?t:[t]).map(c=>new Promise((p,v)=>{u.load(c,h=>{h.scene&&Object.assign(h,oe(h.scene)),p(h)},a,h=>v(i("[useLoader] - Failed to load resource",h)))}));return X(t)?await Promise.all(s):await s[0]}async function Te(e){const t=new g.LoadingManager,n=new g.TextureLoader(t),a=o=>new Promise((i,u)=>{n.load(o,r=>i(r),()=>null,()=>{u(new Error("[useTextures] - Failed to load texture"))})});if(X(e)){const o=await Promise.all(e.map(i=>a(i)));return e.length>1?o:o[0]}else{const{map:o,displacementMap:i,normalMap:u,roughnessMap:r,metalnessMap:s,aoMap:c,alphaMap:p,matcap:v}=e;return{map:o?await a(o):null,displacementMap:i?await a(i):null,normalMap:u?await a(u):null,roughnessMap:r?await a(r):null,metalnessMap:s?await a(s):null,aoMap:c?await a(c):null,alphaMap:p?await a(p):null,matcap:v?await a(v):null}}}const ie=e=>{const{state:t}=A(),n=f.computed(()=>{var d;return(d=t.canvas)==null?void 0:d.value}),{x:a,y:o}=l.usePointer({target:n}),{width:i,height:u,top:r,left:s}=l.useElementBounding(n),c=new g.Raycaster,p=({x:d,y:b})=>{if(n.value)return{x:(d-s.value)/i.value*2-1,y:-((b-r.value)/u.value)*2+1}},v=({x:d,y:b})=>{if(t.camera)return c.setFromCamera(new g.Vector2(d,b),t.camera),c.intersectObjects(e.value,!1)},h=d=>{const b=p({x:(d==null?void 0:d.clientX)??a.value,y:(d==null?void 0:d.clientY)??o.value});return b?v(b)||[]:[]},M=f.computed(()=>h()),C=l.createEventHook(),w=l.createEventHook(),L=(d,b)=>{d.trigger({event:b,intersects:h(b)})},y=d=>{L(w,d)};let _;const G=d=>{var b;_=(b=h(d)[0])==null?void 0:b.object},O=d=>{var b;d instanceof PointerEvent&&_===((b=h(d)[0])==null?void 0:b.object)&&L(C,d)},T=d=>w.trigger({event:d,intersects:[]}),$=f.watchEffect(()=>{n!=null&&n.value&&(n.value.addEventListener("pointerup",O),n.value.addEventListener("pointerdown",G),n.value.addEventListener("pointermove",y),n.value.addEventListener("pointerleave",T),$())});return f.onUnmounted(()=>{n!=null&&n.value&&(n.value.removeEventListener("pointerup",O),n.value.removeEventListener("pointerdown",G),n.value.removeEventListener("pointermove",y),n.value.removeEventListener("pointerleave",T))}),{intersects:M,onClick:d=>C.on(d).off,onPointerMove:d=>w.on(d).off}};function Ae(){const{logWarning:e}=R();function t(a,o,i){let u=null;return a.traverse(r=>{r[o]===i&&(u=r)}),u||e(`Child with ${o} '${i}' not found.`),u}function n(a,o){return t(a,"name",o)}return{seek:t,seekByName:n}}const se=()=>{const e=f.reactive({click:new Map,pointerMove:new Map,pointerEnter:new Map,pointerLeave:new Map}),t=r=>{Object.values(e).forEach(s=>s.delete(r))},n=r=>{const{onClick:s,onPointerMove:c,onPointerEnter:p,onPointerLeave:v}=r;s&&e.click.set(r,s),c&&e.pointerMove.set(r,c),p&&e.pointerEnter.set(r,p),v&&e.pointerLeave.set(r,v),r.addEventListener("removed",()=>{r.traverse(h=>{t(h)}),t(r)})},a=f.computed(()=>Le(Object.values(e).map(r=>Array.from(r.keys())).flat(),({uuid:r})=>r)),{onClick:o,onPointerMove:i}=ie(a);o(({intersects:r,event:s})=>{var c;r.length&&((c=e.click.get(r[0].object))==null||c(r[0],s))});let u;return i(({intersects:r,event:s})=>{var M,C,w,L;const c=(M=r==null?void 0:r[0])==null?void 0:M.object,{pointerLeave:p,pointerEnter:v,pointerMove:h}=e;u&&u!==c&&((C=p.get(u))==null||C(u,s)),c&&(u!==c&&((w=v.get(c))==null||w(r[0],s)),(L=h.get(c))==null||L(r[0],s)),u=c||null}),{registerObject:n,deregisterObject:t}},B={GEOMETRY_VIA_PROP:"tres__geometryViaProp",MATERIAL_VIA_PROP:"tres__materialViaProp",REGISTER_AT_POINTER_EVENT_HANDLER:"tres__registerAtPointerEventHandler"};function ze(e){}let q=null,k=null;const{logError:ce}=R(),Ee={createElement(e,t,n,a){var s,c;if(a||(a={}),a.args||(a.args=[]),e==="template"||Me(e))return null;let o=e.replace("Tres",""),i;if(e==="primitive"){(a==null?void 0:a.object)===void 0&&ce("Tres primitives need a prop 'object'");const p=a.object;o=p.type,i=Object.assign(p,{type:o,attach:a.attach,primitive:!0})}else{const p=F.value[o];p||ce(`${o} is not defined on the THREE namespace. Use extend to add it to the catalog.`),i=new p(...a.args)}i.isCamera&&(a!=null&&a.position||i.position.set(3,3,3),a!=null&&a.lookAt||i.lookAt(0,0,0)),(a==null?void 0:a.attach)===void 0&&(i.isMaterial?i.attach="material":i.isBufferGeometry&&(i.attach="geometry"));const{GEOMETRY_VIA_PROP:u,MATERIAL_VIA_PROP:r}=B;return i.isObject3D&&((s=a==null?void 0:a.material)!=null&&s.isMaterial&&(i.userData[r]=!0),(c=a==null?void 0:a.geometry)!=null&&c.isBufferGeometry&&(i.userData[u]=!0)),i},insert(e,t){var n,a,o,i,u,r,s;if(t&&t.isScene&&(k=t),(((n=e==null?void 0:e.__vnode)==null?void 0:n.type)==="TresGroup"||((a=e==null?void 0:e.__vnode)==null?void 0:a.type)==="TresObject3D")&&t===null&&!((i=(o=e==null?void 0:e.__vnode)==null?void 0:o.ctx)!=null&&i.asyncResolved)){q=e;return}else(u=e==null?void 0:e.__vnode)!=null&&u.type.includes("Controls")&&t===null&&(q=k);t||(t=q),e!=null&&e.isObject3D&&(t!=null&&t.isObject3D)?(t.add(e),e.dispatchEvent({type:"added"}),(s=(r=k==null?void 0:k.userData)==null?void 0:r[B.REGISTER_AT_POINTER_EVENT_HANDLER])==null||s.call(r,e)):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))},remove(e){var t,n;if(e){if(e.isObject3D){const a=e,o=i=>{var s,c;const{GEOMETRY_VIA_PROP:u,MATERIAL_VIA_PROP:r}=B;i.userData[r]||(s=i.material)==null||s.dispose(),i.userData[u]||(c=i.geometry)==null||c.dispose()};a.traverse(i=>{o(i)}),o(a)}(t=e.removeFromParent)==null||t.call(e),(n=e.dispose)==null||n.call(e)}},patchProp(e,t,n,a){if(e){let o=e,i=t,u=I(i),r=o==null?void 0:o[u];if(o.type==="BufferGeometry"){if(i==="args")return;o.setAttribute(I(i),new g.BufferAttribute(...a));return}if(i.includes("-")&&r===void 0){const c=i.split("-");r=c.reduce((p,v)=>p[I(v)],o),i=c.pop(),u=i.toLowerCase(),r!=null&&r.set||(o=c.reduce((p,v)=>p[I(v)],o))}let s=a;if(s===""&&(s=!0),H(r)){Array.isArray(s)?e[u](...s):e[u](s);return}!(r!=null&&r.set)&&!H(r)?o[u]=s:r.constructor===s.constructor&&(r!=null&&r.copy)?r==null||r.copy(s):Array.isArray(s)?r.set(...s):!r.isColor&&r.setScalar?r.setScalar(s):r.set(s)}},parentNode(e){return(e==null?void 0:e.parent)||null},createText:()=>void 0,createComment:()=>void 0,setText:()=>void 0,setElementText:()=>void 0,nextSibling:()=>void 0,querySelector:()=>void 0,setScopeId:()=>void 0,cloneNode:()=>void 0,insertStaticContent:()=>void 0},{createApp:Re}=f.createRenderer(Ee),xe=e=>{const t=Re(n);function n(){return e&&e.default?e.default():[]}return t};z(N);const{logWarning:ue}=R(),ke=f.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:n}){e.physicallyCorrectLights===!0&&ue("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const a=f.ref(),o=f.ref(),i=new N.Scene,u=se(),{setState:r}=A();i.userData[B.REGISTER_AT_POINTER_EVENT_HANDLER]=u.registerObject,r("scene",i),r("canvas",o),r("container",a),r("pointerEventHandler",u);const{onLoop:s,resume:c}=U();f.onMounted(()=>{C()}),f.onUnmounted(()=>{r("renderer",null)});const{activeCamera:p,pushCamera:v,clearCameras:h}=Z();function M(){const y=i.getObjectByProperty("isCamera",!0);if(y)v(y);else{ue("No camera found. Creating a default perspective camera. To have full control over a camera, please add one to the scene.");const _=new N.PerspectiveCamera(45,window.innerWidth/window.innerHeight,.1,1e3);_.position.set(3,3,3),_.lookAt(0,0,0),v(_)}}function C(){const{renderer:y}=re(e);e.camera&&v(e.camera),s(()=>{var _;p.value&&e.disableRender!==!0&&((_=y.value)==null||_.render(i,p.value))})}let w;function L(){w=xe(t);const y=A();w.provide("useTres",y),w.provide(V,y),w.provide("extend",z),w.mount(i),M()}return L(),n({scene:i}),f.watch(()=>e.camera,y=>{y&&(h(),v(y))}),()=>f.h(f.h("div",{ref:a,"data-scene":i.uuid,key:i.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[f.h("div",{style:{width:"100%",height:"100%"}},[f.h("canvas",{ref:o,"data-scene":i.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),fe=f.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:n}){const a=J();return n(a),()=>f.h(ke,e,t)}}),Ve={install(e){e.component("TresCanvas",fe)}};m.CameraType=Q,m.TRES_CONTEXT_KEY=V,m.TresCanvas=fe,m.catalogue=F,m.default=Ve,m.extend=z,m.isProd=Se,m.trasverseObjects=oe,m.useCamera=Z,m.useLoader=Oe,m.useLogger=R,m.usePointerEventHandler=se,m.useRaycaster=ie,m.useRenderLoop=U,m.useRenderer=re,m.useSeek=Ae,m.useTexture=Te,m.useTres=A,m.useTresProvider=J,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
8
+ (function(m,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],f):(m=typeof globalThis<"u"?globalThis:m||self,f(m.tres={},m.Vue,m.Three,m.VueUseCore))})(this,function(m,f,g,l){"use strict";function he(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const N=he(g),z=f.ref({}),F=e=>void Object.assign(z.value,e),X=e=>typeof e=="function",H=e=>!!e&&e.constructor===Array,P=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];function we(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0,a=Math.random()*4294967295|0;return(P[e&255]+P[e>>8&255]+P[e>>16&255]+P[e>>24&255]+"-"+P[t&255]+P[t>>8&255]+"-"+P[t>>16&15|64]+P[t>>24&255]+"-"+P[n&63|128]+P[n>>8&255]+"-"+P[n>>16&255]+P[n>>24&255]+P[a&255]+P[a>>8&255]+P[a>>16&255]+P[a>>24&255]).toLowerCase()}const V=Symbol();function J(){const e=f.shallowReactive({uuid:we(),camera:void 0,cameras:[],canvas:void 0,scene:void 0,renderer:void 0,aspectRatio:void 0,pointerEventHandler:void 0});function t(o){return e[o]}function n(o,i){e[o]=i}const a={state:e,...f.toRefs(e),getState:t,setState:n};return f.provide(V,a),a}const A=()=>f.inject(V,{state:f.shallowReactive({camera:void 0,cameras:[],canvas:void 0,scene:void 0,renderer:void 0,pointerEventHandler:void 0})});var Q=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(Q||{});const be=45;let x;function Z(){const{state:e,setState:t,aspectRatio:n}=A();function a(s="Perspective",c){var p,v,h;if(s==="Perspective"){const{near:M,far:C,fov:w}=c||{near:.1,far:1e3,fov:be};x=new g.PerspectiveCamera(w,((p=e.aspectRatio)==null?void 0:p.value)||window.innerWidth/window.innerHeight,M,C),(v=e.cameras)==null||v.push(x)}else{const{left:M,right:C,top:w,bottom:L,near:y,far:_}=c||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};x=new g.OrthographicCamera(M,C,w,L,y,_),(h=e.cameras)==null||h.push(x)}return e.camera=x,t("camera",e.camera),x}function o(){var s;e.camera instanceof g.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(s=e.camera)==null||s.updateProjectionMatrix()}function i(s){var c;(c=e.cameras)==null||c.push(s),s instanceof g.PerspectiveCamera&&e.aspectRatio&&(s.aspect=e.aspectRatio.value),s.updateProjectionMatrix(),t("camera",s)}function u(s){var c;((c=e.cameras)==null?void 0:c.length)===0&&i(s)}function r(){e.cameras=[]}return f.watchEffect(()=>{n!=null&&n.value&&o()}),{activeCamera:f.toRef(e,"camera"),createCamera:a,updateCamera:o,pushCamera:i,clearCameras:r,setFirstCamera:u}}const ee=l.createEventHook(),te=l.createEventHook(),W=l.createEventHook(),R=new g.Clock;let j=0,D=0;const{pause:ye,resume:Pe,isActive:Ce}=l.useRafFn(()=>{ee.trigger({delta:j,elapsed:D,clock:R}),te.trigger({delta:j,elapsed:D,clock:R}),W.trigger({delta:j,elapsed:D,clock:R})},{immediate:!1});W.on(()=>{j=R.getDelta(),D=R.getElapsedTime()});function U(){return{onBeforeLoop:ee.on,onLoop:te.on,onAfterLoop:W.on,pause:ye,resume:Pe,isActive:Ce}}function Me(e){return typeof e=="number"?[e,e,e]:e instanceof g.Vector3?[e.x,e.y,e.z]:e}function ae(e){return e instanceof g.Color?e:Array.isArray(e)?new g.Color(...e):new g.Color(e)}const Y={realistic:{outputColorSpace:g.SRGBColorSpace,toneMapping:g.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:g.PCFSoftShadowMap}}},ne=(e,t)=>{for(const n of Object.keys(t))t[n]instanceof Object&&Object.assign(t[n],ne(e[n],t[n]));return Object.assign(e||{},t),e},_e=Le("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");function I(e){return e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}function Le(e,t){const n=Object.create(null),a=e.split(",");for(let o=0;o<a.length;o++)n[a[o]]=!0;return t?o=>!!n[o.toLowerCase()]:o=>!!n[o]}const Se=(e,t)=>{const n=new Set,a=[];for(const o of e){const i=t(o);n.has(i)||(n.add(i),a.push(o))}return a},Oe=!0,re="[TresJS ▲ ■ ●] ";function E(){function e(a,o){console.error(`${re} ${a}`,o||"")}function t(a){console.warn(`${re} ${a}`)}function n(a,o){}return{logError:e,logWarning:t,logMessage:n}}function oe(e){const t=f.shallowRef(),n=f.ref(!1),{alpha:a=!0,antialias:o=!0,depth:i,logarithmicDepthBuffer:u,failIfMajorPerformanceCaveat:r,precision:s,premultipliedAlpha:c,stencil:p,shadows:v=!1,shadowMapType:h=g.PCFShadowMap,useLegacyLights:M=!1,outputColorSpace:C=g.LinearSRGBColorSpace,toneMapping:w=g.NoToneMapping,toneMappingExposure:L=1,context:y=void 0,powerPreference:_="default",preserveDrawingBuffer:G=!1,clearColor:O,windowSize:T=!1,preset:$=void 0}=f.toRefs(e),{state:d,setState:b}=A(),{width:de,height:me}=l.toValue(T)==!0||l.toValue(T)===""||l.toValue(T)==="true"?l.useWindowSize():l.useElementSize(d.container),{logError:De,logWarning:Ie}=E(),{pixelRatio:pe}=l.useDevicePixelRatio(),{pause:Be,resume:Ge}=U(),K=f.computed(()=>de.value/me.value);setTimeout(()=>{var S;!l.toValue(T)&&!((S=d.canvas)!=null&&S.value.offsetHeight)&&Ie(`Oops... Seems like your canvas height is currently 0px, it's posible that you couldn't watch your scene.
9
+ You could set windowSize=true to force the canvas to be the size of the window.`)},1e3);const ve=()=>{t.value&&(t.value.setSize(de.value,me.value),t.value.setPixelRatio(Math.min(pe.value,2)))},ge=()=>{if(!t.value)return;const S=l.toValue($);if(S){S in Y||De("Renderer Preset must be one of these: "+Object.keys(Y).join(", ")),ne(t.value,Y[S]);return}t.value.shadowMap.enabled=l.toValue(v),t.value.shadowMap.type=l.toValue(h),t.value.toneMapping=l.toValue(w)||g.NoToneMapping,t.value.toneMappingExposure=l.toValue(L),t.value.outputColorSpace=l.toValue(C)||g.LinearSRGBColorSpace,O!=null&&O.value&&t.value.setClearColor(ae(l.toValue(O))),t.value.useLegacyLights=l.toValue(M)},Ne=()=>{const S=l.unrefElement(d.canvas);S&&(t.value=new g.WebGLRenderer({canvas:S,alpha:l.toValue(a),antialias:l.toValue(o),context:l.toValue(y),depth:l.toValue(i),failIfMajorPerformanceCaveat:l.toValue(r),logarithmicDepthBuffer:l.toValue(u),powerPreference:l.toValue(_),precision:l.toValue(s),stencil:l.toValue(p),preserveDrawingBuffer:l.toValue(G),premultipliedAlpha:l.toValue(c)}),b("renderer",t.value),b("clock",new g.Clock),b("aspectRatio",K),ge(),ve(),Ge(),n.value=!0)},ze=()=>{t.value&&(t.value.dispose(),t.value=void 0,n.value=!1,Be())};return f.watch([K,pe],ve),f.watch([v,h,C,M,w,L,O],ge),f.watch(()=>[d.canvas,d.container],()=>{l.unrefElement(d.canvas)&&l.unrefElement(d.container)&&Ne()},{immediate:!0,deep:!0}),{renderer:t,isReady:n,dispose:ze,aspectRatio:K}}function ie(e){const t={nodes:{},materials:{}};return e&&e.traverse(n=>{n.name&&(t.nodes[n.name]=n),n.material&&!t.materials[n.material.name]&&(t.materials[n.material.name]=n.material)}),t}async function Te(e,t,n,a,o){const{logError:i}=E(),u=new e;o&&o(u),n&&n(u);const s=(Array.isArray(t)?t:[t]).map(c=>new Promise((p,v)=>{u.load(c,h=>{h.scene&&Object.assign(h,ie(h.scene)),p(h)},a,h=>v(i("[useLoader] - Failed to load resource",h)))}));return H(t)?await Promise.all(s):await s[0]}async function Ae(e){const t=new g.LoadingManager,n=new g.TextureLoader(t),a=o=>new Promise((i,u)=>{n.load(o,r=>i(r),()=>null,()=>{u(new Error("[useTextures] - Failed to load texture"))})});if(H(e)){const o=await Promise.all(e.map(i=>a(i)));return e.length>1?o:o[0]}else{const{map:o,displacementMap:i,normalMap:u,roughnessMap:r,metalnessMap:s,aoMap:c,alphaMap:p,matcap:v}=e;return{map:o?await a(o):null,displacementMap:i?await a(i):null,normalMap:u?await a(u):null,roughnessMap:r?await a(r):null,metalnessMap:s?await a(s):null,aoMap:c?await a(c):null,alphaMap:p?await a(p):null,matcap:v?await a(v):null}}}const se=e=>{const{state:t}=A(),n=f.computed(()=>{var d;return(d=t.canvas)==null?void 0:d.value}),{x:a,y:o}=l.usePointer({target:n}),{width:i,height:u,top:r,left:s}=l.useElementBounding(n),c=new g.Raycaster,p=({x:d,y:b})=>{if(n.value)return{x:(d-s.value)/i.value*2-1,y:-((b-r.value)/u.value)*2+1}},v=({x:d,y:b})=>{if(t.camera)return c.setFromCamera(new g.Vector2(d,b),t.camera),c.intersectObjects(e.value,!1)},h=d=>{const b=p({x:(d==null?void 0:d.clientX)??a.value,y:(d==null?void 0:d.clientY)??o.value});return b?v(b)||[]:[]},M=f.computed(()=>h()),C=l.createEventHook(),w=l.createEventHook(),L=(d,b)=>{d.trigger({event:b,intersects:h(b)})},y=d=>{L(w,d)};let _;const G=d=>{var b;_=(b=h(d)[0])==null?void 0:b.object},O=d=>{var b;d instanceof PointerEvent&&_===((b=h(d)[0])==null?void 0:b.object)&&L(C,d)},T=d=>w.trigger({event:d,intersects:[]}),$=f.watchEffect(()=>{n!=null&&n.value&&(n.value.addEventListener("pointerup",O),n.value.addEventListener("pointerdown",G),n.value.addEventListener("pointermove",y),n.value.addEventListener("pointerleave",T),$())});return f.onUnmounted(()=>{n!=null&&n.value&&(n.value.removeEventListener("pointerup",O),n.value.removeEventListener("pointerdown",G),n.value.removeEventListener("pointermove",y),n.value.removeEventListener("pointerleave",T))}),{intersects:M,onClick:d=>C.on(d).off,onPointerMove:d=>w.on(d).off}};function xe(){const{logWarning:e}=E();function t(a,o,i){let u=null;return a.traverse(r=>{r[o]===i&&(u=r)}),u||e(`Child with ${o} '${i}' not found.`),u}function n(a,o){return t(a,"name",o)}return{seek:t,seekByName:n}}const ce=()=>{const e=f.reactive({click:new Map,pointerMove:new Map,pointerEnter:new Map,pointerLeave:new Map}),t=r=>{Object.values(e).forEach(s=>s.delete(r))},n=r=>{const{onClick:s,onPointerMove:c,onPointerEnter:p,onPointerLeave:v}=r;s&&e.click.set(r,s),c&&e.pointerMove.set(r,c),p&&e.pointerEnter.set(r,p),v&&e.pointerLeave.set(r,v),r.addEventListener("removed",()=>{r.traverse(h=>{t(h)}),t(r)})},a=f.computed(()=>Se(Object.values(e).map(r=>Array.from(r.keys())).flat(),({uuid:r})=>r)),{onClick:o,onPointerMove:i}=se(a);o(({intersects:r,event:s})=>{var c;r.length&&((c=e.click.get(r[0].object))==null||c(r[0],s))});let u;return i(({intersects:r,event:s})=>{var M,C,w,L;const c=(M=r==null?void 0:r[0])==null?void 0:M.object,{pointerLeave:p,pointerEnter:v,pointerMove:h}=e;u&&u!==c&&((C=p.get(u))==null||C(u,s)),c&&(u!==c&&((w=v.get(c))==null||w(r[0],s)),(L=h.get(c))==null||L(r[0],s)),u=c||null}),{registerObject:n,deregisterObject:t}},B={GEOMETRY_VIA_PROP:"tres__geometryViaProp",MATERIAL_VIA_PROP:"tres__materialViaProp",REGISTER_AT_POINTER_EVENT_HANDLER:"tres__registerAtPointerEventHandler"};function We(e){}let q=null,k=null;const{logError:ue}=E(),Ee={createElement(e,t,n,a){var s,c;if(a||(a={}),a.args||(a.args=[]),e==="template"||_e(e))return null;let o=e.replace("Tres",""),i;if(e==="primitive"){(a==null?void 0:a.object)===void 0&&ue("Tres primitives need a prop 'object'");const p=a.object;o=p.type,i=Object.assign(p,{type:o,attach:a.attach,primitive:!0})}else{const p=z.value[o];p||ue(`${o} is not defined on the THREE namespace. Use extend to add it to the catalog.`),i=new p(...a.args)}i.isCamera&&(a!=null&&a.position||i.position.set(3,3,3),a!=null&&a.lookAt||i.lookAt(0,0,0)),(a==null?void 0:a.attach)===void 0&&(i.isMaterial?i.attach="material":i.isBufferGeometry&&(i.attach="geometry"));const{GEOMETRY_VIA_PROP:u,MATERIAL_VIA_PROP:r}=B;return i.isObject3D&&((s=a==null?void 0:a.material)!=null&&s.isMaterial&&(i.userData[r]=!0),(c=a==null?void 0:a.geometry)!=null&&c.isBufferGeometry&&(i.userData[u]=!0)),i},insert(e,t){var n,a,o,i,u,r,s;if(t&&t.isScene&&(k=t),(((n=e==null?void 0:e.__vnode)==null?void 0:n.type)==="TresGroup"||((a=e==null?void 0:e.__vnode)==null?void 0:a.type)==="TresObject3D")&&t===null&&!((i=(o=e==null?void 0:e.__vnode)==null?void 0:o.ctx)!=null&&i.asyncResolved)){q=e;return}else(u=e==null?void 0:e.__vnode)!=null&&u.type.includes("Controls")&&t===null&&(q=k);t||(t=q),e!=null&&e.isObject3D&&(t!=null&&t.isObject3D)?(t.add(e),e.dispatchEvent({type:"added"}),(s=(r=k==null?void 0:k.userData)==null?void 0:r[B.REGISTER_AT_POINTER_EVENT_HANDLER])==null||s.call(r,e)):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))},remove(e){var t,n;if(e){if(e.isObject3D){const a=e,o=i=>{var s,c;const{GEOMETRY_VIA_PROP:u,MATERIAL_VIA_PROP:r}=B;i.userData[r]||(s=i.material)==null||s.dispose(),i.userData[u]||(c=i.geometry)==null||c.dispose()};a.traverse(i=>{o(i)}),o(a)}(t=e.removeFromParent)==null||t.call(e),(n=e.dispose)==null||n.call(e)}},patchProp(e,t,n,a){if(e){let o=e,i=t,u=I(i),r=o==null?void 0:o[u];if(o.type==="BufferGeometry"){if(i==="args")return;o.setAttribute(I(i),new g.BufferAttribute(...a));return}if(i.includes("-")&&r===void 0){const c=i.split("-");r=c.reduce((p,v)=>p[I(v)],o),i=c.pop(),u=i.toLowerCase(),r!=null&&r.set||(o=c.reduce((p,v)=>p[I(v)],o))}let s=a;if(s===""&&(s=!0),X(r)){Array.isArray(s)?e[u](...s):e[u](s);return}!(r!=null&&r.set)&&!X(r)?o[u]=s:r.constructor===s.constructor&&(r!=null&&r.copy)?r==null||r.copy(s):Array.isArray(s)?r.set(...s):!r.isColor&&r.setScalar?r.setScalar(s):r.set(s)}},parentNode(e){return(e==null?void 0:e.parent)||null},createText:()=>void 0,createComment:()=>void 0,setText:()=>void 0,setElementText:()=>void 0,nextSibling:()=>void 0,querySelector:()=>void 0,setScopeId:()=>void 0,cloneNode:()=>void 0,insertStaticContent:()=>void 0},{createApp:Re}=f.createRenderer(Ee),ke=e=>{const t=Re(n);function n(){return e&&e.default?e.default():[]}return t};F(N);const{logWarning:fe}=E(),Ve=f.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:n}){e.physicallyCorrectLights===!0&&fe("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const a=f.ref(),o=f.ref(),i=new N.Scene,u=ce(),{setState:r}=A();i.userData[B.REGISTER_AT_POINTER_EVENT_HANDLER]=u.registerObject,r("scene",i),r("canvas",o),r("container",a),r("pointerEventHandler",u);const{onLoop:s,resume:c}=U();f.onMounted(()=>{C()}),f.onUnmounted(()=>{r("renderer",null)});const{activeCamera:p,pushCamera:v,clearCameras:h}=Z();function M(){const y=i.getObjectByProperty("isCamera",!0);if(y)v(y);else{fe("No camera found. Creating a default perspective camera. To have full control over a camera, please add one to the scene.");const _=new N.PerspectiveCamera(45,window.innerWidth/window.innerHeight,.1,1e3);_.position.set(3,3,3),_.lookAt(0,0,0),v(_)}}function C(){const{renderer:y}=oe(e);e.camera&&v(e.camera),s(()=>{var _;p.value&&e.disableRender!==!0&&((_=y.value)==null||_.render(i,p.value))})}let w;function L(){w=ke(t);const y=A();w.provide("useTres",y),w.provide(V,y),w.provide("extend",F),w.mount(i),M()}return L(),n({scene:i}),f.watch(()=>e.camera,y=>{y&&(h(),v(y))}),()=>f.h(f.h("div",{ref:a,"data-scene":i.uuid,key:i.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[f.h("div",{style:{width:"100%",height:"100%"}},[f.h("canvas",{ref:o,"data-scene":i.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),le=f.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:n}){const a=J();return n(a),()=>f.h(Ve,e,t)}}),je={install(e){e.component("TresCanvas",le)}};m.CameraType=Q,m.TRES_CONTEXT_KEY=V,m.TresCanvas=le,m.catalogue=z,m.default=je,m.extend=F,m.isProd=Oe,m.normalizeColor=ae,m.normalizeVectorFlexibleParam=Me,m.trasverseObjects=ie,m.useCamera=Z,m.useLoader=Te,m.useLogger=E,m.usePointerEventHandler=ce,m.useRaycaster=se,m.useRenderLoop=U,m.useRenderer=oe,m.useSeek=xe,m.useTexture=Ae,m.useTres=A,m.useTresProvider=J,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tresjs/core",
3
3
  "description": "Declarative ThreeJS using Vue Components",
4
- "version": "2.2.0",
4
+ "version": "2.3.0",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@8.3.1",
7
7
  "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",