@tresjs/core 2.0.0-beta.0 → 2.0.0-beta.10

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.
@@ -14,6 +14,7 @@ export interface TresCanvasProps {
14
14
  clearColor?: string;
15
15
  windowSize?: boolean;
16
16
  preset?: RendererPresetsType;
17
+ disableRender?: boolean;
17
18
  }
18
19
  /**
19
20
  * Vue component for rendering a Tres component.
@@ -14,6 +14,7 @@ export interface TresSceneProps {
14
14
  clearColor?: string;
15
15
  windowSize?: boolean;
16
16
  preset?: RendererPresetsType;
17
+ disableRender?: boolean;
17
18
  }
18
19
  export declare const TresScene: import("vue").DefineComponent<TresSceneProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<TresSceneProps>, {}>;
19
20
  export default TresScene;
@@ -78,7 +78,7 @@ export interface UseRendererOptions extends WebGLRendererParameters {
78
78
  * @default 0x000000
79
79
  */
80
80
  clearColor?: MaybeComputedRef<TresColor>;
81
- windowSize?: MaybeComputedRef<boolean>;
81
+ windowSize?: MaybeComputedRef<boolean | string>;
82
82
  preset?: RendererPresetsType;
83
83
  }
84
84
  /**
@@ -95,6 +95,7 @@ export type UseTresReturn = {
95
95
  setState: (key: string, value: any) => void;
96
96
  aspectRatio: ComputedRef<number>;
97
97
  };
98
+ export declare const TRES_CONTEXT_KEY: unique symbol;
98
99
  /**
99
100
  * The Tres state.
100
101
  *
@@ -1,3 +1,4 @@
1
1
  import { RendererOptions } from 'vue';
2
2
  import { TresObject } from '../types';
3
+ export declare const isOn: (key: string) => boolean;
3
4
  export declare const nodeOps: RendererOptions<TresObject, TresObject>;
package/dist/tres.js CHANGED
@@ -1,31 +1,31 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v2.0.0-beta.0
3
+ * version: v2.0.0-beta.10
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 M, watchEffect as oe, toRef as Re, shallowRef as ie, toRefs as se, computed as ce, watch as z, shallowReactive as ke, provide as Ae, inject as Oe, createRenderer as je, defineComponent as ue, onMounted as _e, onUnmounted as Be, h as E } from "vue";
9
- import * as fe from "three";
10
- import { MathUtils as De, PerspectiveCamera as O, OrthographicCamera as ze, Clock as le, Color as W, sRGBEncoding as We, ACESFilmicToneMapping as Fe, PCFSoftShadowMap as Ie, PCFShadowMap as He, LinearEncoding as ee, NoToneMapping as te, WebGLRenderer as Ue, LoadingManager as $e, TextureLoader as Ge, Raycaster as Ne, Vector2 as Ve, Mesh as qe, BufferAttribute as Ye } from "three";
11
- import { createEventHook as $, useRafFn as Ke, resolveUnref as f, useWindowSize as Xe, useElementSize as Je, useDevicePixelRatio as Qe, unrefElement as F, useEventListener as Ze, isFunction as ne } from "@vueuse/core";
12
- const H = M({ uuid: De.generateUUID() }), de = (e) => void Object.assign(H.value, e);
13
- var et = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(et || {});
14
- const tt = 45;
15
- let x;
16
- function U() {
17
- const { state: e, setState: t, aspectRatio: r } = T();
18
- function a(o = "Perspective", c) {
19
- var u, l, p;
20
- if (o === "Perspective") {
21
- const { near: d, far: w, fov: v } = c || {
8
+ import { ref as P, watchEffect as fe, toRef as Se, shallowRef as le, toRefs as de, computed as pe, watch as W, shallowReactive as me, provide as Oe, inject as ke, onUnmounted as ve, createRenderer as je, defineComponent as ge, onMounted as De, h as k } from "vue";
9
+ import * as he from "three";
10
+ import { MathUtils as Ie, PerspectiveCamera as H, OrthographicCamera as Be, Clock as we, Color as Y, sRGBEncoding as ze, ACESFilmicToneMapping as Fe, PCFSoftShadowMap as Ge, PCFShadowMap as Ve, LinearEncoding as ae, NoToneMapping as ne, WebGLRenderer as Ue, LoadingManager as We, TextureLoader as He, Raycaster as Ye, Vector2 as $e, BufferAttribute as Ne } from "three";
11
+ import { createEventHook as q, useRafFn as qe, resolveUnref as f, useWindowSize as Ke, useElementSize as Je, useDevicePixelRatio as Xe, unrefElement as $, isFunction as re, useEventListener as Qe } from "@vueuse/core";
12
+ const be = P({ uuid: Ie.generateUUID() }), ye = (e) => void Object.assign(be.value, e);
13
+ var Ze = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Ze || {});
14
+ const et = 45;
15
+ let _;
16
+ function Me() {
17
+ const { state: e, setState: t, aspectRatio: o } = S();
18
+ function a(i = "Perspective", s) {
19
+ var l, u, p;
20
+ if (i === "Perspective") {
21
+ const { near: d, far: w, fov: M } = s || {
22
22
  near: 0.1,
23
23
  far: 1e3,
24
- fov: tt
24
+ fov: et
25
25
  };
26
- x = new O(v, ((u = e.aspectRatio) == null ? void 0 : u.value) || window.innerWidth / window.innerHeight, d, w), (l = e.cameras) == null || l.push(x);
26
+ _ = new H(M, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, d, w), (u = e.cameras) == null || u.push(_);
27
27
  } else {
28
- const { left: d, right: w, top: v, bottom: b, near: g, far: P } = c || {
28
+ const { left: d, right: w, top: M, bottom: x, near: L, far: b } = s || {
29
29
  left: -100,
30
30
  right: 100,
31
31
  top: 100,
@@ -33,362 +33,368 @@ function U() {
33
33
  near: 0.1,
34
34
  far: 1e3
35
35
  };
36
- x = new ze(d, w, v, b, g, P), (p = e.cameras) == null || p.push(x);
36
+ _ = new Be(d, w, M, x, L, b), (p = e.cameras) == null || p.push(_);
37
37
  }
38
- return e.camera = x, t("camera", e.camera), x;
38
+ return e.camera = _, t("camera", e.camera), _;
39
39
  }
40
40
  function n() {
41
- var o;
42
- e.camera instanceof O && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (o = e.camera) == null || o.updateProjectionMatrix();
41
+ var i;
42
+ e.camera instanceof H && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (i = e.camera) == null || i.updateProjectionMatrix();
43
43
  }
44
- function i(o) {
45
- var c;
46
- (c = e.cameras) == null || c.push(o), o instanceof O && e.aspectRatio && (o.aspect = e.aspectRatio.value), o.updateProjectionMatrix(), t("camera", o);
44
+ function r(i) {
45
+ var s;
46
+ (s = e.cameras) == null || s.push(i), i instanceof H && e.aspectRatio && (i.aspect = e.aspectRatio.value), i.updateProjectionMatrix(), t("camera", i);
47
47
  }
48
- function s() {
48
+ function c() {
49
49
  e.cameras = [];
50
50
  }
51
- return oe(() => {
52
- r != null && r.value && n();
51
+ return fe(() => {
52
+ o != null && o.value && n();
53
53
  }), {
54
- activeCamera: Re(e, "camera"),
54
+ activeCamera: Se(e, "camera"),
55
55
  createCamera: a,
56
56
  updateCamera: n,
57
- pushCamera: i,
58
- clearCameras: s
57
+ pushCamera: r,
58
+ clearCameras: c
59
59
  };
60
60
  }
61
- const pe = $(), me = $(), G = $(), S = new le();
62
- let j = 0, _ = 0;
63
- const { pause: nt, resume: at, isActive: rt } = Ke(
61
+ const xe = q(), Ee = q(), K = q(), j = new we();
62
+ let G = 0, V = 0;
63
+ const { pause: tt, resume: at, isActive: nt } = qe(
64
64
  () => {
65
- pe.trigger({ delta: j, elapsed: _, clock: S }), me.trigger({ delta: j, elapsed: _, clock: S }), G.trigger({ delta: j, elapsed: _, clock: S });
65
+ xe.trigger({ delta: G, elapsed: V, clock: j }), Ee.trigger({ delta: G, elapsed: V, clock: j }), K.trigger({ delta: G, elapsed: V, clock: j });
66
66
  },
67
67
  { immediate: !1 }
68
68
  );
69
- G.on(() => {
70
- j = S.getDelta(), _ = S.getElapsedTime();
69
+ K.on(() => {
70
+ G = j.getDelta(), V = j.getElapsedTime();
71
71
  });
72
- function N() {
72
+ function Ce() {
73
73
  return {
74
- onBeforeLoop: pe.on,
75
- onLoop: me.on,
76
- onAfterLoop: G.on,
77
- pause: nt,
74
+ onBeforeLoop: xe.on,
75
+ onLoop: Ee.on,
76
+ onAfterLoop: K.on,
77
+ pause: tt,
78
78
  resume: at,
79
- isActive: rt
79
+ isActive: nt
80
80
  };
81
81
  }
82
- function ot(e) {
83
- return e instanceof W ? e : Array.isArray(e) ? new W(...e) : new W(e);
82
+ function rt(e) {
83
+ return e instanceof Y ? e : Array.isArray(e) ? new Y(...e) : new Y(e);
84
84
  }
85
- const I = {
85
+ const N = {
86
86
  realistic: {
87
- outputEncoding: We,
87
+ outputEncoding: ze,
88
88
  toneMapping: Fe,
89
89
  toneMappingExposure: 3,
90
90
  shadowMap: {
91
91
  enabled: !0,
92
- type: Ie
92
+ type: Ge
93
93
  }
94
94
  }
95
- }, ve = (e, t) => {
96
- for (const r of Object.keys(t))
97
- t[r] instanceof Object && Object.assign(t[r], ve(e[r], t[r]));
95
+ }, Re = (e, t) => {
96
+ for (const o of Object.keys(t))
97
+ t[o] instanceof Object && Object.assign(t[o], Re(e[o], t[o]));
98
98
  return Object.assign(e || {}, t), e;
99
- }, 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);
100
- function R(e) {
101
- return e.replace(/-([a-z])/g, (t, r) => r.toUpperCase());
99
+ }, ot = "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", it = /* @__PURE__ */ st(ot);
100
+ function F(e) {
101
+ return e.replace(/-([a-z])/g, (t, o) => o.toUpperCase());
102
102
  }
103
- function ct(e, t) {
104
- const r = /* @__PURE__ */ Object.create(null), a = e.split(",");
103
+ function st(e, t) {
104
+ const o = /* @__PURE__ */ Object.create(null), a = e.split(",");
105
105
  for (let n = 0; n < a.length; n++)
106
- r[a[n]] = !0;
107
- return t ? (n) => !!r[n.toLowerCase()] : (n) => !!r[n];
106
+ o[a[n]] = !0;
107
+ return t ? (n) => !!o[n.toLowerCase()] : (n) => !!o[n];
108
108
  }
109
- function ut(e) {
110
- var Q, Z;
111
- const t = ie(), r = M(!1), {
109
+ function ct(e) {
110
+ var ee, te;
111
+ const t = le(), o = P(!1), {
112
112
  alpha: a = !0,
113
113
  antialias: n = !0,
114
- depth: i,
115
- logarithmicDepthBuffer: s,
116
- failIfMajorPerformanceCaveat: o,
117
- precision: c,
118
- premultipliedAlpha: u,
119
- stencil: l,
114
+ depth: r,
115
+ logarithmicDepthBuffer: c,
116
+ failIfMajorPerformanceCaveat: i,
117
+ precision: s,
118
+ premultipliedAlpha: l,
119
+ stencil: u,
120
120
  shadows: p = !1,
121
- shadowMapType: d = He,
121
+ shadowMapType: d = Ve,
122
122
  physicallyCorrectLights: w = !1,
123
- useLegacyLights: v = !1,
124
- outputEncoding: b = ee,
125
- toneMapping: g = te,
126
- toneMappingExposure: P = 1,
127
- context: be = void 0,
128
- powerPreference: ye = "default",
129
- preserveDrawingBuffer: xe = !1,
130
- clearColor: L,
131
- windowSize: V = !1,
132
- preset: Me = void 0
133
- } = se(e), { state: h, setState: B } = T(), { width: q, height: Y } = f(V) ? Xe() : Je(h.container), { logError: Ce, logWarning: Le } = C(), { pixelRatio: K } = Qe(), { pause: Ee, resume: Se } = N(), D = ce(() => q.value / Y.value);
134
- !f(V) && ((Z = (Q = h.container) == null ? void 0 : Q.value) == null ? void 0 : Z.offsetHeight) === 0 && Le(`Oops... Seems like your canvas height is currently 0px, by default it takes the height of it's parent, so make sure it has some height with CSS.
123
+ useLegacyLights: M = !1,
124
+ outputEncoding: x = ae,
125
+ toneMapping: L = ne,
126
+ toneMappingExposure: b = 1,
127
+ context: v = void 0,
128
+ powerPreference: E = "default",
129
+ preserveDrawingBuffer: y = !1,
130
+ clearColor: g,
131
+ windowSize: C = !1,
132
+ preset: I = void 0
133
+ } = de(e), { state: h, setState: T } = S(), { width: O, height: R } = f(C) == !0 || f(C) === "" || f(C) === "true" ? Ke() : Je(h.container), { logError: B, logWarning: z } = D(), { pixelRatio: X } = Xe(), { pause: Le, resume: Te } = Ce(), U = pe(() => O.value / R.value);
134
+ !f(C) && ((te = (ee = h.container) == null ? void 0 : ee.value) == null ? void 0 : te.offsetHeight) === 0 && z(`Oops... Seems like your canvas height is currently 0px, by default it takes the height of it's parent, so make sure it has some height with CSS.
135
135
  You could set windowSize=true to force the canvas to be the size of the window.`);
136
- const X = () => {
137
- t.value && (t.value.setSize(q.value, Y.value), t.value.setPixelRatio(Math.min(K.value, 2)));
138
- }, J = () => {
136
+ const Q = () => {
137
+ t.value && (t.value.setSize(O.value, R.value), t.value.setPixelRatio(Math.min(X.value, 2)));
138
+ }, Z = () => {
139
139
  if (!t.value)
140
140
  return;
141
- const y = f(Me);
142
- if (y) {
143
- y in I || Ce("Renderer Preset must be one of these: " + Object.keys(I).join(", ")), ve(t.value, I[y]);
141
+ const A = f(I);
142
+ if (A) {
143
+ A in N || B("Renderer Preset must be one of these: " + Object.keys(N).join(", ")), Re(t.value, N[A]);
144
144
  return;
145
145
  }
146
- t.value.shadowMap.enabled = f(p), t.value.shadowMap.type = f(d), t.value.toneMapping = f(g) || te, t.value.toneMappingExposure = f(P), t.value.outputEncoding = f(b) || ee, L != null && L.value && t.value.setClearColor(ot(f(L))), t.value.useLegacyLights = f(v);
147
- }, Te = () => {
148
- const y = F(h.canvas);
149
- y && (t.value = new Ue({
150
- canvas: y,
146
+ t.value.shadowMap.enabled = f(p), t.value.shadowMap.type = f(d), t.value.toneMapping = f(L) || ne, t.value.toneMappingExposure = f(b), t.value.outputEncoding = f(x) || ae, g != null && g.value && t.value.setClearColor(rt(f(g))), t.value.useLegacyLights = f(M);
147
+ }, Ae = () => {
148
+ const A = $(h.canvas);
149
+ A && (t.value = new Ue({
150
+ canvas: A,
151
151
  alpha: f(a),
152
152
  antialias: f(n),
153
- context: f(be),
154
- depth: f(i),
155
- failIfMajorPerformanceCaveat: f(o),
156
- logarithmicDepthBuffer: f(s),
157
- powerPreference: f(ye),
158
- precision: f(c),
159
- stencil: f(l),
160
- preserveDrawingBuffer: f(xe),
161
- premultipliedAlpha: f(u)
162
- }), B("renderer", t.value), B("clock", new le()), B("aspectRatio", D), J(), X(), Se(), r.value = !0);
163
- }, Pe = () => {
164
- t.value && (t.value.dispose(), t.value = void 0, r.value = !1, Ee());
153
+ context: f(v),
154
+ depth: f(r),
155
+ failIfMajorPerformanceCaveat: f(i),
156
+ logarithmicDepthBuffer: f(c),
157
+ powerPreference: f(E),
158
+ precision: f(s),
159
+ stencil: f(u),
160
+ preserveDrawingBuffer: f(y),
161
+ premultipliedAlpha: f(l)
162
+ }), T("renderer", t.value), T("clock", new we()), T("aspectRatio", U), Z(), Q(), Te(), o.value = !0);
163
+ }, _e = () => {
164
+ t.value && (t.value.dispose(), t.value = void 0, o.value = !1, Le());
165
165
  };
166
- return z([D, K], X), z(
167
- [p, d, b, v, g, P, L],
168
- J
169
- ), z(
166
+ return W([U, X], Q), W(
167
+ [p, d, x, M, L, b, g],
168
+ Z
169
+ ), W(
170
170
  () => [h.canvas, h.container],
171
171
  () => {
172
- F(h.canvas) && F(h.container) && Te();
172
+ $(h.canvas) && $(h.container) && Ae();
173
173
  },
174
174
  { immediate: !0, deep: !0 }
175
175
  ), {
176
176
  renderer: t,
177
- isReady: r,
178
- dispose: Pe,
179
- aspectRatio: D
177
+ isReady: o,
178
+ dispose: _e,
179
+ aspectRatio: U
180
180
  };
181
181
  }
182
- const ge = (e) => !!e && e.constructor === Array;
182
+ const ut = (e) => typeof e == "string", Pe = (e) => !!e && e.constructor === Array;
183
183
  function ft(e) {
184
184
  const t = { nodes: {}, materials: {} };
185
- return e && e.traverse((r) => {
186
- r.name && (t.nodes[r.name] = r), r.material && !t.materials[r.material.name] && (t.materials[r.material.name] = r.material);
185
+ return e && e.traverse((o) => {
186
+ o.name && (t.nodes[o.name] = o), o.material && !t.materials[o.material.name] && (t.materials[o.material.name] = o.material);
187
187
  }), t;
188
188
  }
189
- async function Et(e, t, r, a, n) {
190
- const { logError: i } = C(), s = new e();
191
- n && n(s), r && r(s);
192
- const c = (Array.isArray(t) ? t : [t]).map(
193
- (u) => new Promise((l, p) => {
194
- s.load(
195
- u,
189
+ async function Ct(e, t, o, a, n) {
190
+ const { logError: r } = D(), c = new e();
191
+ n && n(c), o && o(c);
192
+ const s = (Array.isArray(t) ? t : [t]).map(
193
+ (l) => new Promise((u, p) => {
194
+ c.load(
195
+ l,
196
196
  (d) => {
197
- d.scene && Object.assign(d, ft(d.scene)), l(d);
197
+ d.scene && Object.assign(d, ft(d.scene)), u(d);
198
198
  },
199
199
  a,
200
- (d) => p(i("[useLoader] - Failed to load resource", d))
200
+ (d) => p(r("[useLoader] - Failed to load resource", d))
201
201
  );
202
202
  })
203
203
  );
204
- return ge(t) ? await Promise.all(c) : await c[0];
204
+ return Pe(t) ? await Promise.all(s) : await s[0];
205
205
  }
206
- async function St(e) {
207
- const t = new $e(), r = new Ge(t), a = (n) => new Promise((i, s) => {
208
- r.load(
206
+ async function Rt(e) {
207
+ const t = new We(), o = new He(t), a = (n) => new Promise((r, c) => {
208
+ o.load(
209
209
  n,
210
- (o) => i(o),
210
+ (i) => r(i),
211
211
  () => null,
212
212
  () => {
213
- s(new Error("[useTextures] - Failed to load texture"));
213
+ c(new Error("[useTextures] - Failed to load texture"));
214
214
  }
215
215
  );
216
216
  });
217
- if (ge(e)) {
218
- const n = await Promise.all(e.map((i) => a(i)));
217
+ if (Pe(e)) {
218
+ const n = await Promise.all(e.map((r) => a(r)));
219
219
  return e.length > 1 ? n : n[0];
220
220
  } else {
221
221
  const {
222
222
  map: n,
223
- displacementMap: i,
224
- normalMap: s,
225
- roughnessMap: o,
226
- metalnessMap: c,
227
- aoMap: u,
228
- alphaMap: l,
223
+ displacementMap: r,
224
+ normalMap: c,
225
+ roughnessMap: i,
226
+ metalnessMap: s,
227
+ aoMap: l,
228
+ alphaMap: u,
229
229
  matcap: p
230
230
  } = e;
231
231
  return {
232
232
  map: n ? await a(n) : null,
233
- displacementMap: i ? await a(i) : null,
234
- normalMap: s ? await a(s) : null,
235
- roughnessMap: o ? await a(o) : null,
236
- metalnessMap: c ? await a(c) : null,
237
- aoMap: u ? await a(u) : null,
238
- alphaMap: l ? await a(l) : null,
233
+ displacementMap: r ? await a(r) : null,
234
+ normalMap: c ? await a(c) : null,
235
+ roughnessMap: i ? await a(i) : null,
236
+ metalnessMap: s ? await a(s) : null,
237
+ aoMap: l ? await a(l) : null,
238
+ alphaMap: u ? await a(u) : null,
239
239
  matcap: p ? await a(p) : null
240
240
  };
241
241
  }
242
242
  }
243
243
  const m = ["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"];
244
244
  function lt() {
245
- const e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, r = Math.random() * 4294967295 | 0, a = Math.random() * 4294967295 | 0;
246
- return (m[e & 255] + m[e >> 8 & 255] + m[e >> 16 & 255] + m[e >> 24 & 255] + "-" + m[t & 255] + m[t >> 8 & 255] + "-" + m[t >> 16 & 15 | 64] + m[t >> 24 & 255] + "-" + m[r & 63 | 128] + m[r >> 8 & 255] + "-" + m[r >> 16 & 255] + m[r >> 24 & 255] + m[a & 255] + m[a >> 8 & 255] + m[a >> 16 & 255] + m[a >> 24 & 255]).toLowerCase();
245
+ const e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, o = Math.random() * 4294967295 | 0, a = Math.random() * 4294967295 | 0;
246
+ return (m[e & 255] + m[e >> 8 & 255] + m[e >> 16 & 255] + m[e >> 24 & 255] + "-" + m[t & 255] + m[t >> 8 & 255] + "-" + m[t >> 16 & 15 | 64] + m[t >> 24 & 255] + "-" + m[o & 63 | 128] + m[o >> 8 & 255] + "-" + m[o >> 16 & 255] + m[o >> 24 & 255] + m[a & 255] + m[a >> 8 & 255] + m[a >> 16 & 255] + m[a >> 24 & 255]).toLowerCase();
247
247
  }
248
- const he = Symbol();
248
+ const J = Symbol();
249
249
  function dt() {
250
- const e = ke({
250
+ const e = me({
251
251
  uuid: lt(),
252
252
  camera: void 0,
253
253
  cameras: [],
254
254
  scene: void 0,
255
255
  renderer: void 0,
256
- aspectRatio: ce(() => window.innerWidth / window.innerHeight)
256
+ aspectRatio: pe(() => window.innerWidth / window.innerHeight)
257
257
  });
258
258
  function t(n) {
259
259
  return e[n];
260
260
  }
261
- function r(n, i) {
262
- e[n] = i;
261
+ function o(n, r) {
262
+ e[n] = r;
263
263
  }
264
264
  const a = {
265
265
  state: e,
266
- ...se(e),
266
+ ...de(e),
267
267
  getState: t,
268
- setState: r
268
+ setState: o
269
269
  };
270
- return Ae(he, a), a;
270
+ return Oe(J, a), a;
271
271
  }
272
- const T = () => {
273
- const e = Oe(he), { logError: t } = C();
274
- return e || t("useTres must be used together with useTresProvider"), e;
275
- }, ae = ie(new Ne()), k = M(new Ve()), pt = M(null);
276
- function we() {
277
- const { setState: e } = T();
278
- e("raycaster", ae.value), e("pointer", k), e("currentInstance", pt);
279
- function t(r) {
280
- k.value.x = r.clientX / window.innerWidth * 2 - 1, k.value.y = -(r.clientY / window.innerHeight) * 2 + 1;
272
+ const S = () => ke(J, {
273
+ state: me({
274
+ camera: void 0,
275
+ cameras: [],
276
+ scene: void 0,
277
+ renderer: void 0
278
+ })
279
+ });
280
+ function pt() {
281
+ var c;
282
+ const e = le(new Ye()), t = P(new $e()), o = P(null), { setState: a, state: n } = S();
283
+ a("raycaster", e.value), a("pointer", t), a("currentInstance", o);
284
+ function r(i) {
285
+ t.value.x = i.clientX / window.innerWidth * 2 - 1, t.value.y = -(i.clientY / window.innerHeight) * 2 + 1;
281
286
  }
282
- return window.addEventListener("pointermove", t), {
283
- raycaster: ae,
284
- pointer: k
287
+ return (c = n == null ? void 0 : n.renderer) == null || c.domElement.addEventListener("pointermove", r), ve(() => {
288
+ var i;
289
+ (i = n == null ? void 0 : n.renderer) == null || i.domElement.removeEventListener("pointermove", r);
290
+ }), {
291
+ raycaster: e,
292
+ pointer: t
285
293
  };
286
294
  }
287
- const Tt = !0, re = "[TresJS ▲ ■ ●] ";
288
- function C() {
295
+ const Pt = !0, oe = "[TresJS ▲ ■ ●] ";
296
+ function D() {
289
297
  function e(a, n) {
290
- console.error(`${re} ${a}`, n || "");
298
+ console.error(`${oe} ${a}`, n || "");
291
299
  }
292
300
  function t(a) {
293
- console.warn(`${re} ${a}`);
301
+ console.warn(`${oe} ${a}`);
294
302
  }
295
- function r(a, n) {
303
+ function o(a, n) {
296
304
  }
297
305
  return {
298
306
  logError: e,
299
307
  logWarning: t,
300
- logMessage: r
308
+ logMessage: o
301
309
  };
302
310
  }
303
- function Pt() {
304
- const { logWarning: e } = C();
305
- function t(a, n, i) {
306
- let s = null;
307
- return a.traverse((o) => {
308
- o[n] === i && (s = o);
309
- }), s || e(`Child with ${n} '${i}' not found.`), s;
311
+ function Lt() {
312
+ const { logWarning: e } = D();
313
+ function t(a, n, r) {
314
+ let c = null;
315
+ return a.traverse((i) => {
316
+ i[n] === r && (c = i);
317
+ }), c || e(`Child with ${n} '${r}' not found.`), c;
310
318
  }
311
- function r(a, n) {
319
+ function o(a, n) {
312
320
  return t(a, "name", n);
313
321
  }
314
322
  return {
315
323
  seek: t,
316
- seekByName: r
324
+ seekByName: o
317
325
  };
318
326
  }
319
- const { logWarning: mt } = C();
320
- function vt(e) {
321
- for (const t in e)
322
- if (t.indexOf("on") === 0)
323
- return !0;
324
- return !1;
325
- }
326
- let A = null;
327
- const gt = {
328
- createElement(e, t, r, a) {
329
- if (e === "template" || st(e))
327
+ const mt = /^on[^a-z]/, vt = (e) => mt.test(e);
328
+ let ie = null;
329
+ const se = {
330
+ GEOMETRY_VIA_PROP: "tres__geometryViaProp",
331
+ MATERIAL_VIA_PROP: "tres__materialViaProp"
332
+ }, { logError: ce } = D(), gt = {
333
+ createElement(e, t, o, a) {
334
+ var s, l;
335
+ if (a || (a = {}), a.args || (a.args = []), e === "template" || it(e))
330
336
  return null;
331
- let n;
332
- if (a === null && (a = {}), a != null && a.args ? n = new H.value[e.replace("Tres", "")](...a.args) : n = new H.value[e.replace("Tres", "")](), n.isCamera) {
333
- (!(a != null && a.position) || a != null && a.position.every((s) => s == 0)) && mt(
334
- // eslint-disable-next-line max-len
335
- "Camera is positioned at the center of the scene [0,0,0], if this is not intentional try setting a position if your scene seems empty 🤗"
336
- );
337
- const { pushCamera: i } = U();
338
- i(n);
337
+ let n = e.replace("Tres", ""), r;
338
+ if (e === "primitive") {
339
+ (a == null ? void 0 : a.object) === void 0 && ce("Tres primitives need a prop 'object'");
340
+ const u = a.object;
341
+ n = u.type, r = Object.assign(u, { type: n, attach: a.attach, primitive: !0 });
342
+ } else {
343
+ const u = be.value[n];
344
+ u || ce(`${n} is not defined on the THREE namespace. Use extend to add it to the catalog.`), r = new u(...a.args);
339
345
  }
340
- return (a == null ? void 0 : a.attach) === void 0 && (n.isMaterial ? n.attach = "material" : n.isBufferGeometry && (n.attach = "geometry")), n;
346
+ if (r.isCamera) {
347
+ a != null && a.position || r.position.set(3, 3, 3), a != null && a.lookAt || r.lookAt(0, 0, 0);
348
+ const { pushCamera: u } = Me();
349
+ u(r);
350
+ }
351
+ (a == null ? void 0 : a.attach) === void 0 && (r.isMaterial ? r.attach = "material" : r.isBufferGeometry && (r.attach = "geometry"));
352
+ const { GEOMETRY_VIA_PROP: c, MATERIAL_VIA_PROP: i } = se;
353
+ return r.isObject3D && ((s = a == null ? void 0 : a.material) != null && s.isMaterial && (r.userData[i] = !0), (l = a == null ? void 0 : a.geometry) != null && l.isBufferGeometry && (r.userData[c] = !0)), r.events = {}, r;
341
354
  },
342
- insert(e, t, r) {
343
- if (A === null && t.isScene && (A = t), t === null && (t = A), t != null && t.isObject3D && (e != null && e.isObject3D)) {
344
- const s = r ? t.children.indexOf(r) : 0;
345
- e.parent = t, t.children.splice(s, 0, e), e.dispatchEvent({ type: "added" });
346
- } else
347
- typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
348
- const { onLoop: a } = N();
349
- let n = null, i = null;
350
- if (e && e instanceof qe && vt(e)) {
351
- const { raycaster: s } = we();
352
- a(() => {
353
- var o, c, u;
354
- if (t != null && t.children && e && s) {
355
- const l = s.value.intersectObjects(t.children);
356
- l.length > 0 && l[0].object.uuid === e.uuid ? (i = l[0], (n === null || n.object.uuid !== (i == null ? void 0 : i.object.uuid)) && ((o = e.onPointerEnter) == null || o.call(e, i)), (c = e.onPointerMove) == null || c.call(e, i)) : (i = null, n !== null && ((u = e.onPointerLeave) == null || u.call(e, n))), n = i;
357
- }
358
- }), Ze(window, "click", () => {
359
- var o;
360
- i !== null && ((o = e.onClick) == null || o.call(e, i));
361
- });
355
+ insert(e, t) {
356
+ var o, a;
357
+ if (((e == null ? void 0 : e.__vnode.type) === "TresGroup" || (e == null ? void 0 : e.__vnode.type) === "TresObject3D") && t === null && !((a = (o = e == null ? void 0 : e.__vnode) == null ? void 0 : o.ctx) != null && a.asyncResolved)) {
358
+ ie = e;
359
+ return;
362
360
  }
361
+ t || (t = ie), e != null && e.isObject3D && (t != null && t.isObject3D) ? (t.add(e), e.dispatchEvent({ type: "added" })) : typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
363
362
  },
364
363
  remove(e) {
365
- if (!e)
366
- return;
367
- const t = e.parentNode;
368
- t && t.removeChild(e);
364
+ var t, o;
365
+ if (e) {
366
+ if (e.isObject3D) {
367
+ const a = e, n = (r) => {
368
+ var s, l;
369
+ const { GEOMETRY_VIA_PROP: c, MATERIAL_VIA_PROP: i } = se;
370
+ r.userData[i] || (s = r.material) == null || s.dispose(), r.userData[c] || (l = r.geometry) == null || l.dispose();
371
+ };
372
+ a.traverse((r) => n(r)), n(a);
373
+ }
374
+ (t = e.removeFromParent) == null || t.call(e), (o = e.dispose) == null || o.call(e);
375
+ }
369
376
  },
370
- patchProp(e, t, r, a) {
377
+ patchProp(e, t, o, a) {
371
378
  if (e) {
372
- let n = e, i = t;
373
- const s = R(i);
374
- let o = n == null ? void 0 : n[s];
375
- if (e.parent || (e.parent = A), n.type === "BufferGeometry") {
379
+ let n = e, r = t, c = F(r), i = n == null ? void 0 : n[c];
380
+ if (n.type === "BufferGeometry") {
376
381
  n.setAttribute(
377
- R(i),
378
- new Ye(...a)
382
+ F(r),
383
+ new Ne(...a)
379
384
  );
380
385
  return;
381
386
  }
382
- if (i.includes("-") && o === void 0) {
383
- const u = i.split("-");
384
- o = u.reduce((l, p) => l[R(p)], n), i = u.pop(), o != null && o.set || (n = u.reduce((l, p) => l[R(p)], n));
387
+ if (r.includes("-") && i === void 0) {
388
+ const l = r.split("-");
389
+ i = l.reduce((u, p) => u[F(p)], n), r = l.pop(), c = r.toLowerCase(), i != null && i.set || (n = l.reduce((u, p) => u[F(p)], n));
385
390
  }
386
- let c = a;
387
- if (c === "" && (c = !0), ne(o)) {
388
- Array.isArray(c) ? e[s](...c) : e[s](c);
391
+ vt(r) && (e.events[r] = a);
392
+ let s = a;
393
+ if (s === "" && (s = !0), re(i)) {
394
+ Array.isArray(s) ? e[c](...s) : e[c](s);
389
395
  return;
390
396
  }
391
- !(o != null && o.set) && !ne(o) ? n[s] = c : o.constructor === c.constructor && (o != null && o.copy) ? o == null || o.copy(c) : Array.isArray(c) ? o.set(...c) : !o.isColor && o.setScalar ? o.setScalar(c) : o.set(c);
397
+ !(i != null && i.set) && !re(i) ? n[c] = s : i.constructor === s.constructor && (i != null && i.copy) ? i == null || i.copy(s) : Array.isArray(s) ? i.set(...s) : !i.isColor && i.setScalar ? i.setScalar(s) : i.set(s);
392
398
  }
393
399
  },
394
400
  parentNode(e) {
@@ -404,14 +410,14 @@ const gt = {
404
410
  cloneNode: () => void 0,
405
411
  insertStaticContent: () => void 0
406
412
  }, { createApp: ht } = je(gt), wt = (e) => {
407
- const t = ht(r);
408
- function r() {
413
+ const t = ht(o);
414
+ function o() {
409
415
  return e && e.default ? e.default() : [];
410
416
  }
411
417
  return t;
412
418
  };
413
- de(fe);
414
- const { logWarning: bt } = C(), yt = ue({
419
+ ye(he);
420
+ const { logWarning: ue } = D(), bt = ge({
415
421
  name: "TresScene",
416
422
  props: [
417
423
  "shadows",
@@ -426,40 +432,48 @@ const { logWarning: bt } = C(), yt = ue({
426
432
  "preserveDrawingBuffer",
427
433
  "clearColor",
428
434
  "windowSize",
429
- "preset"
435
+ "preset",
436
+ "disableRender"
430
437
  ],
431
- setup(e, { slots: t, expose: r }) {
432
- e.physicallyCorrectLights === !0 && bt("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
433
- const a = M(), n = M(), i = new fe.Scene(), { setState: s } = T();
434
- s("scene", i), s("canvas", n), s("container", a);
435
- const { pushCamera: o } = U();
436
- o(new O()), _e(() => {
437
- c();
438
- }), Be(() => {
439
- s("renderer", null);
438
+ setup(e, { slots: t, expose: o }) {
439
+ e.physicallyCorrectLights === !0 && ue("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
440
+ const a = P(), n = P(), r = new he.Scene(), { setState: c } = S();
441
+ c("scene", r), c("canvas", n), c("container", a);
442
+ const i = P(), s = t && t.default && t.default();
443
+ (s == null ? void 0 : s.length) > 0 && (i.value = s.some((d) => ut(d.type) && d.type.includes("Camera")), i.value || ue("No camera found in the scene, please add one!")), De(() => {
444
+ l();
445
+ }), ve(() => {
446
+ c("renderer", null);
440
447
  });
441
- function c() {
442
- const { renderer: p } = ut(e), { activeCamera: d } = U(), { onLoop: w } = N(), { raycaster: v, pointer: b } = we();
443
- oe(() => {
444
- d.value && v.value.setFromCamera(b.value, d.value);
445
- }), w(() => {
446
- var g;
447
- d.value && ((g = p.value) == null || g.render(i, d.value));
448
+ function l() {
449
+ const { renderer: d } = ct(e), { activeCamera: w } = Me(), { onLoop: M } = Ce(), { raycaster: x, pointer: L } = pt();
450
+ let b = null, v = null;
451
+ fe(() => {
452
+ w.value && x.value.setFromCamera(L.value, w.value);
453
+ }), M(() => {
454
+ var E, y, g, C, I, h, T, O, R, B;
455
+ if (w.value && e.disableRender !== !0 && e.disableRender !== "" && ((E = d.value) == null || E.render(r, w.value)), x.value) {
456
+ const z = x.value.intersectObjects(r.children);
457
+ z.length > 0 ? (v = z[0], b === null && ((C = (g = (y = v.object) == null ? void 0 : y.events) == null ? void 0 : g.onPointerEnter) == null || C.call(g, v)), (T = (h = (I = v.object) == null ? void 0 : I.events) == null ? void 0 : h.onPointerMove) == null || T.call(h, v)) : b !== null && ((B = (R = (O = v == null ? void 0 : v.object) == null ? void 0 : O.events) == null ? void 0 : R.onPointerLeave) == null || B.call(R, b), v = null), b = v;
458
+ }
459
+ }), Qe(n.value, "click", () => {
460
+ var E, y, g;
461
+ v !== null && ((g = (y = (E = v.object) == null ? void 0 : E.events) == null ? void 0 : y.onClick) == null || g.call(y, v));
448
462
  });
449
463
  }
450
464
  let u;
451
- function l() {
452
- u = wt(t), u.provide("useTres", T()), u.provide("extend", de), u.mount(i);
465
+ function p() {
466
+ u = wt(t), u.provide("useTres", S()), u.provide(J, S()), u.provide("extend", ye), u.mount(r);
453
467
  }
454
- return l(), r({
455
- scene: i
456
- }), () => E(
457
- E(
468
+ return p(), o({
469
+ scene: r
470
+ }), () => k(
471
+ k(
458
472
  "div",
459
473
  {
460
474
  ref: a,
461
- "data-scene": i.uuid,
462
- key: i.uuid,
475
+ "data-scene": r.uuid,
476
+ key: r.uuid,
463
477
  style: {
464
478
  position: "relative",
465
479
  width: "100%",
@@ -469,7 +483,7 @@ const { logWarning: bt } = C(), yt = ue({
469
483
  }
470
484
  },
471
485
  [
472
- E(
486
+ k(
473
487
  "div",
474
488
  {
475
489
  style: {
@@ -478,9 +492,9 @@ const { logWarning: bt } = C(), yt = ue({
478
492
  }
479
493
  },
480
494
  [
481
- E("canvas", {
495
+ k("canvas", {
482
496
  ref: n,
483
- "data-scene": i.uuid,
497
+ "data-scene": r.uuid,
484
498
  style: {
485
499
  display: "block",
486
500
  width: "100%",
@@ -496,7 +510,7 @@ const { logWarning: bt } = C(), yt = ue({
496
510
  )
497
511
  );
498
512
  }
499
- }), xt = ue({
513
+ }), yt = ge({
500
514
  name: "TresCanvas",
501
515
  props: [
502
516
  "shadows",
@@ -511,32 +525,35 @@ const { logWarning: bt } = C(), yt = ue({
511
525
  "preserveDrawingBuffer",
512
526
  "clearColor",
513
527
  "windowSize",
514
- "preset"
528
+ "preset",
529
+ "disableRender"
515
530
  ],
516
- setup(e, { slots: t }) {
517
- return dt(), () => E(yt, e, t);
531
+ setup(e, { slots: t, expose: o }) {
532
+ const a = dt();
533
+ return o(a), () => k(bt, e, t);
518
534
  }
519
- }), Rt = {
535
+ }), Tt = {
520
536
  install(e) {
521
- e.component("TresCanvas", xt);
537
+ e.component("TresCanvas", yt);
522
538
  }
523
539
  };
524
540
  export {
525
- et as CameraType,
526
- xt as TresCanvas,
527
- H as catalogue,
528
- Rt as default,
529
- de as extend,
530
- Tt as isProd,
541
+ Ze as CameraType,
542
+ J as TRES_CONTEXT_KEY,
543
+ yt as TresCanvas,
544
+ be as catalogue,
545
+ Tt as default,
546
+ ye as extend,
547
+ Pt as isProd,
531
548
  ft as trasverseObjects,
532
- U as useCamera,
533
- Et as useLoader,
534
- C as useLogger,
535
- we as useRaycaster,
536
- N as useRenderLoop,
537
- ut as useRenderer,
538
- Pt as useSeek,
539
- St as useTexture,
540
- T as useTres,
549
+ Me as useCamera,
550
+ Ct as useLoader,
551
+ D as useLogger,
552
+ pt as useRaycaster,
553
+ Ce as useRenderLoop,
554
+ ct as useRenderer,
555
+ Lt as useSeek,
556
+ Rt as useTexture,
557
+ S as useTres,
541
558
  dt as useTresProvider
542
559
  };
package/dist/tres.umd.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v2.0.0-beta.0
3
+ * version: v2.0.0-beta.10
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(d,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d.tres={},d.Vue,d.Three,d.VueUseCore))})(this,function(d,i,l,c){"use strict";function le(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const q=le(l),U=i.ref({uuid:l.MathUtils.generateUUID()}),W=e=>void Object.assign(U.value,e);var V=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(V||{});const de=45;let M;function A(){const{state:e,setState:t,aspectRatio:r}=L();function a(o="Perspective",u){var p,m,h;if(o==="Perspective"){const{near:g,far:x,fov:w}=u||{near:.1,far:1e3,fov:de};M=new l.PerspectiveCamera(w,((p=e.aspectRatio)==null?void 0:p.value)||window.innerWidth/window.innerHeight,g,x),(m=e.cameras)==null||m.push(M)}else{const{left:g,right:x,top:w,bottom:S,near:y,far:F}=u||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};M=new l.OrthographicCamera(g,x,w,S,y,F),(h=e.cameras)==null||h.push(M)}return e.camera=M,t("camera",e.camera),M}function n(){var o;e.camera instanceof l.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(o=e.camera)==null||o.updateProjectionMatrix()}function s(o){var u;(u=e.cameras)==null||u.push(o),o instanceof l.PerspectiveCamera&&e.aspectRatio&&(o.aspect=e.aspectRatio.value),o.updateProjectionMatrix(),t("camera",o)}function f(){e.cameras=[]}return i.watchEffect(()=>{r!=null&&r.value&&n()}),{activeCamera:i.toRef(e,"camera"),createCamera:a,updateCamera:n,pushCamera:s,clearCameras:f}}const Y=c.createEventHook(),K=c.createEventHook(),I=c.createEventHook(),k=new l.Clock;let T=0,j=0;const{pause:pe,resume:me,isActive:ge}=c.useRafFn(()=>{Y.trigger({delta:T,elapsed:j,clock:k}),K.trigger({delta:T,elapsed:j,clock:k}),I.trigger({delta:T,elapsed:j,clock:k})},{immediate:!1});I.on(()=>{T=k.getDelta(),j=k.getElapsedTime()});function _(){return{onBeforeLoop:Y.on,onLoop:K.on,onAfterLoop:I.on,pause:pe,resume:me,isActive:ge}}function ve(e){return e instanceof l.Color?e:Array.isArray(e)?new l.Color(...e):new l.Color(e)}const R={realistic:{outputEncoding:l.sRGBEncoding,toneMapping:l.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:l.PCFSoftShadowMap}}},X=(e,t)=>{for(const r of Object.keys(t))t[r]instanceof Object&&Object.assign(t[r],X(e[r],t[r]));return Object.assign(e||{},t),e},he=we("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 D(e){return e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase())}function we(e,t){const r=Object.create(null),a=e.split(",");for(let n=0;n<a.length;n++)r[a[n]]=!0;return t?n=>!!r[n.toLowerCase()]:n=>!!r[n]}function J(e){var fe,ue;const t=i.shallowRef(),r=i.ref(!1),{alpha:a=!0,antialias:n=!0,depth:s,logarithmicDepthBuffer:f,failIfMajorPerformanceCaveat:o,precision:u,premultipliedAlpha:p,stencil:m,shadows:h=!1,shadowMapType:g=l.PCFShadowMap,physicallyCorrectLights:x=!1,useLegacyLights:w=!1,outputEncoding:S=l.LinearEncoding,toneMapping:y=l.NoToneMapping,toneMappingExposure:F=1,context:_e=void 0,powerPreference:De="default",preserveDrawingBuffer:ze=!1,clearColor:O,windowSize:ae=!1,preset:Be=void 0}=i.toRefs(e),{state:C,setState:G}=L(),{width:re,height:oe}=c.resolveUnref(ae)?c.useWindowSize():c.useElementSize(C.container),{logError:Fe,logWarning:We}=b(),{pixelRatio:se}=c.useDevicePixelRatio(),{pause:Ie,resume:Re}=_(),$=i.computed(()=>re.value/oe.value);!c.resolveUnref(ae)&&((ue=(fe=C.container)==null?void 0:fe.value)==null?void 0:ue.offsetHeight)===0&&We(`Oops... Seems like your canvas height is currently 0px, by default it takes the height of it's parent, so make sure it has some height with CSS.
9
- You could set windowSize=true to force the canvas to be the size of the window.`);const ie=()=>{t.value&&(t.value.setSize(re.value,oe.value),t.value.setPixelRatio(Math.min(se.value,2)))},ce=()=>{if(!t.value)return;const P=c.resolveUnref(Be);if(P){P in R||Fe("Renderer Preset must be one of these: "+Object.keys(R).join(", ")),X(t.value,R[P]);return}t.value.shadowMap.enabled=c.resolveUnref(h),t.value.shadowMap.type=c.resolveUnref(g),t.value.toneMapping=c.resolveUnref(y)||l.NoToneMapping,t.value.toneMappingExposure=c.resolveUnref(F),t.value.outputEncoding=c.resolveUnref(S)||l.LinearEncoding,O!=null&&O.value&&t.value.setClearColor(ve(c.resolveUnref(O))),t.value.useLegacyLights=c.resolveUnref(w)},Ne=()=>{const P=c.unrefElement(C.canvas);P&&(t.value=new l.WebGLRenderer({canvas:P,alpha:c.resolveUnref(a),antialias:c.resolveUnref(n),context:c.resolveUnref(_e),depth:c.resolveUnref(s),failIfMajorPerformanceCaveat:c.resolveUnref(o),logarithmicDepthBuffer:c.resolveUnref(f),powerPreference:c.resolveUnref(De),precision:c.resolveUnref(u),stencil:c.resolveUnref(m),preserveDrawingBuffer:c.resolveUnref(ze),premultipliedAlpha:c.resolveUnref(p)}),G("renderer",t.value),G("clock",new l.Clock),G("aspectRatio",$),ce(),ie(),Re(),r.value=!0)},Ge=()=>{t.value&&(t.value.dispose(),t.value=void 0,r.value=!1,Ie())};return i.watch([$,se],ie),i.watch([h,g,S,w,y,F,O],ce),i.watch(()=>[C.canvas,C.container],()=>{c.unrefElement(C.canvas)&&c.unrefElement(C.container)&&Ne()},{immediate:!0,deep:!0}),{renderer:t,isReady:r,dispose:Ge,aspectRatio:$}}const Q=e=>!!e&&e.constructor===Array;function Z(e){const t={nodes:{},materials:{}};return e&&e.traverse(r=>{r.name&&(t.nodes[r.name]=r),r.material&&!t.materials[r.material.name]&&(t.materials[r.material.name]=r.material)}),t}async function be(e,t,r,a,n){const{logError:s}=b(),f=new e;n&&n(f),r&&r(f);const u=(Array.isArray(t)?t:[t]).map(p=>new Promise((m,h)=>{f.load(p,g=>{g.scene&&Object.assign(g,Z(g.scene)),m(g)},a,g=>h(s("[useLoader] - Failed to load resource",g)))}));return Q(t)?await Promise.all(u):await u[0]}async function ye(e){const t=new l.LoadingManager,r=new l.TextureLoader(t),a=n=>new Promise((s,f)=>{r.load(n,o=>s(o),()=>null,()=>{f(new Error("[useTextures] - Failed to load texture"))})});if(Q(e)){const n=await Promise.all(e.map(s=>a(s)));return e.length>1?n:n[0]}else{const{map:n,displacementMap:s,normalMap:f,roughnessMap:o,metalnessMap:u,aoMap:p,alphaMap:m,matcap:h}=e;return{map:n?await a(n):null,displacementMap:s?await a(s):null,normalMap:f?await a(f):null,roughnessMap:o?await a(o):null,metalnessMap:u?await a(u):null,aoMap:p?await a(p):null,alphaMap:m?await a(m):null,matcap:h?await a(h):null}}}const v=["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 Ce(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0,a=Math.random()*4294967295|0;return(v[e&255]+v[e>>8&255]+v[e>>16&255]+v[e>>24&255]+"-"+v[t&255]+v[t>>8&255]+"-"+v[t>>16&15|64]+v[t>>24&255]+"-"+v[r&63|128]+v[r>>8&255]+"-"+v[r>>16&255]+v[r>>24&255]+v[a&255]+v[a>>8&255]+v[a>>16&255]+v[a>>24&255]).toLowerCase()}const E=Symbol();function H(){const e=i.shallowReactive({uuid:Ce(),camera:void 0,cameras:[],scene:void 0,renderer:void 0,aspectRatio:i.computed(()=>window.innerWidth/window.innerHeight)});function t(n){return e[n]}function r(n,s){e[n]=s}const a={state:e,...i.toRefs(e),getState:t,setState:r};return i.provide(E,a),a}const L=()=>{const e=i.inject(E),{logError:t}=b();return e||t("useTres must be used together with useTresProvider"),e},ee=i.shallowRef(new l.Raycaster),z=i.ref(new l.Vector2),Me=i.ref(null);function N(){const{setState:e}=L();e("raycaster",ee.value),e("pointer",z),e("currentInstance",Me);function t(r){z.value.x=r.clientX/window.innerWidth*2-1,z.value.y=-(r.clientY/window.innerHeight)*2+1}return window.addEventListener("pointermove",t),{raycaster:ee,pointer:z}}const Le=!0,te="[TresJS ▲ ■ ●] ";function b(){function e(a,n){console.error(`${te} ${a}`,n||"")}function t(a){console.warn(`${te} ${a}`)}function r(a,n){}return{logError:e,logWarning:t,logMessage:r}}function xe(){const{logWarning:e}=b();function t(a,n,s){let f=null;return a.traverse(o=>{o[n]===s&&(f=o)}),f||e(`Child with ${n} '${s}' not found.`),f}function r(a,n){return t(a,"name",n)}return{seek:t,seekByName:r}}const{logWarning:Se}=b();function Pe(e){for(const t in e)if(t.indexOf("on")===0)return!0;return!1}function qe(e){}let B=null;const ke={createElement(e,t,r,a){if(e==="template"||he(e))return null;let n;if(a===null&&(a={}),a!=null&&a.args?n=new U.value[e.replace("Tres","")](...a.args):n=new U.value[e.replace("Tres","")],n.isCamera){(!(a!=null&&a.position)||a!=null&&a.position.every(f=>f==0))&&Se("Camera is positioned at the center of the scene [0,0,0], if this is not intentional try setting a position if your scene seems empty 🤗");const{pushCamera:s}=A();s(n)}return(a==null?void 0:a.attach)===void 0&&(n.isMaterial?n.attach="material":n.isBufferGeometry&&(n.attach="geometry")),n},insert(e,t,r){if(B===null&&t.isScene&&(B=t),t===null&&(t=B),t!=null&&t.isObject3D&&(e!=null&&e.isObject3D)){const f=r?t.children.indexOf(r):0;e.parent=t,t.children.splice(f,0,e),e.dispatchEvent({type:"added"})}else typeof(e==null?void 0:e.attach)=="string"&&(e.__previousAttach=e[t==null?void 0:t.attach],t&&(t[e.attach]=e));const{onLoop:a}=_();let n=null,s=null;if(e&&e instanceof l.Mesh&&Pe(e)){const{raycaster:f}=N();a(()=>{var o,u,p;if(t!=null&&t.children&&e&&f){const m=f.value.intersectObjects(t.children);m.length>0&&m[0].object.uuid===e.uuid?(s=m[0],(n===null||n.object.uuid!==(s==null?void 0:s.object.uuid))&&((o=e.onPointerEnter)==null||o.call(e,s)),(u=e.onPointerMove)==null||u.call(e,s)):(s=null,n!==null&&((p=e.onPointerLeave)==null||p.call(e,n))),n=s}}),c.useEventListener(window,"click",()=>{var o;s!==null&&((o=e.onClick)==null||o.call(e,s))})}},remove(e){if(!e)return;const t=e.parentNode;t&&t.removeChild(e)},patchProp(e,t,r,a){if(e){let n=e,s=t;const f=D(s);let o=n==null?void 0:n[f];if(e.parent||(e.parent=B),n.type==="BufferGeometry"){n.setAttribute(D(s),new l.BufferAttribute(...a));return}if(s.includes("-")&&o===void 0){const p=s.split("-");o=p.reduce((m,h)=>m[D(h)],n),s=p.pop(),o!=null&&o.set||(n=p.reduce((m,h)=>m[D(h)],n))}let u=a;if(u===""&&(u=!0),c.isFunction(o)){Array.isArray(u)?e[f](...u):e[f](u);return}!(o!=null&&o.set)&&!c.isFunction(o)?n[f]=u:o.constructor===u.constructor&&(o!=null&&o.copy)?o==null||o.copy(u):Array.isArray(u)?o.set(...u):!o.isColor&&o.setScalar?o.setScalar(u):o.set(u)}},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:Oe}=i.createRenderer(ke),Ue=e=>{const t=Oe(r);function r(){return e&&e.default?e.default():[]}return t};W(q);const{logWarning:Ae}=b(),Te=i.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t,expose:r}){e.physicallyCorrectLights===!0&&Ae("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const a=i.ref(),n=i.ref(),s=new q.Scene,{setState:f}=L();f("scene",s),f("canvas",n),f("container",a);const{pushCamera:o}=A();o(new l.PerspectiveCamera),i.onMounted(()=>{u()}),i.onUnmounted(()=>{f("renderer",null)});function u(){const{renderer:h}=J(e),{activeCamera:g}=A(),{onLoop:x}=_(),{raycaster:w,pointer:S}=N();i.watchEffect(()=>{g.value&&w.value.setFromCamera(S.value,g.value)}),x(()=>{var y;g.value&&((y=h.value)==null||y.render(s,g.value))})}let p;function m(){p=Ue(t),p.provide("useTres",L()),p.provide("extend",W),p.mount(s)}return m(),r({scene:s}),()=>i.h(i.h("div",{ref:a,"data-scene":s.uuid,key:s.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[i.h("div",{style:{width:"100%",height:"100%"}},[i.h("canvas",{ref:n,"data-scene":s.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),ne=i.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t}){return H(),()=>i.h(Te,e,t)}}),je={install(e){e.component("TresCanvas",ne)}};d.CameraType=V,d.TresCanvas=ne,d.catalogue=U,d.default=je,d.extend=W,d.isProd=Le,d.trasverseObjects=Z,d.useCamera=A,d.useLoader=be,d.useLogger=b,d.useRaycaster=N,d.useRenderLoop=_,d.useRenderer=J,d.useSeek=xe,d.useTexture=ye,d.useTres=L,d.useTresProvider=H,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
8
+ (function(d,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],s):(d=typeof globalThis<"u"?globalThis:d||self,s(d.tres={},d.Vue,d.Three,d.VueUseCore))})(this,function(d,s,m,f){"use strict";function be(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const Q=be(m),N=s.ref({uuid:m.MathUtils.generateUUID()}),Y=e=>void Object.assign(N.value,e);var Z=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(Z||{});const we=45;let T;function $(){const{state:e,setState:t,aspectRatio:r}=S();function n(o="Perspective",c){var p,u,h;if(o==="Perspective"){const{near:v,far:M,fov:L}=c||{near:.1,far:1e3,fov:we};T=new m.PerspectiveCamera(L,((p=e.aspectRatio)==null?void 0:p.value)||window.innerWidth/window.innerHeight,v,M),(u=e.cameras)==null||u.push(T)}else{const{left:v,right:M,top:L,bottom:_,near:k,far:C}=c||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};T=new m.OrthographicCamera(v,M,L,_,k,C),(h=e.cameras)==null||h.push(T)}return e.camera=T,t("camera",e.camera),T}function a(){var o;e.camera instanceof m.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(o=e.camera)==null||o.updateProjectionMatrix()}function i(o){var c;(c=e.cameras)==null||c.push(o),o instanceof m.PerspectiveCamera&&e.aspectRatio&&(o.aspect=e.aspectRatio.value),o.updateProjectionMatrix(),t("camera",o)}function l(){e.cameras=[]}return s.watchEffect(()=>{r!=null&&r.value&&a()}),{activeCamera:s.toRef(e,"camera"),createCamera:n,updateCamera:a,pushCamera:i,clearCameras:l}}const H=f.createEventHook(),ee=f.createEventHook(),q=f.createEventHook(),D=new m.Clock;let E=0,B=0;const{pause:ye,resume:Me,isActive:Ce}=f.useRafFn(()=>{H.trigger({delta:E,elapsed:B,clock:D}),ee.trigger({delta:E,elapsed:B,clock:D}),q.trigger({delta:E,elapsed:B,clock:D})},{immediate:!1});q.on(()=>{E=D.getDelta(),B=D.getElapsedTime()});function K(){return{onBeforeLoop:H.on,onLoop:ee.on,onAfterLoop:q.on,pause:ye,resume:Me,isActive:Ce}}function Pe(e){return e instanceof m.Color?e:Array.isArray(e)?new m.Color(...e):new m.Color(e)}const X={realistic:{outputEncoding:m.sRGBEncoding,toneMapping:m.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:m.PCFSoftShadowMap}}},te=(e,t)=>{for(const r of Object.keys(t))t[r]instanceof Object&&Object.assign(t[r],te(e[r],t[r]));return Object.assign(e||{},t),e},Le=_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 z(e){return e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase())}function _e(e,t){const r=Object.create(null),n=e.split(",");for(let a=0;a<n.length;a++)r[n[a]]=!0;return t?a=>!!r[a.toLowerCase()]:a=>!!r[a]}function ne(e){var ge,he;const t=s.shallowRef(),r=s.ref(!1),{alpha:n=!0,antialias:a=!0,depth:i,logarithmicDepthBuffer:l,failIfMajorPerformanceCaveat:o,precision:c,premultipliedAlpha:p,stencil:u,shadows:h=!1,shadowMapType:v=m.PCFShadowMap,physicallyCorrectLights:M=!1,useLegacyLights:L=!1,outputEncoding:_=m.LinearEncoding,toneMapping:k=m.NoToneMapping,toneMappingExposure:C=1,context:b=void 0,powerPreference:O="default",preserveDrawingBuffer:P=!1,clearColor:w,windowSize:x=!1,preset:G=void 0}=s.toRefs(e),{state:y,setState:R}=S(),{width:I,height:A}=f.resolveUnref(x)==!0||f.resolveUnref(x)===""||f.resolveUnref(x)==="true"?f.useWindowSize():f.useElementSize(y.container),{logError:V,logWarning:W}=U(),{pixelRatio:me}=f.useDevicePixelRatio(),{pause:ze,resume:Fe}=K(),J=s.computed(()=>I.value/A.value);!f.resolveUnref(x)&&((he=(ge=y.container)==null?void 0:ge.value)==null?void 0:he.offsetHeight)===0&&W(`Oops... Seems like your canvas height is currently 0px, by default it takes the height of it's parent, so make sure it has some height with CSS.
9
+ You could set windowSize=true to force the canvas to be the size of the window.`);const pe=()=>{t.value&&(t.value.setSize(I.value,A.value),t.value.setPixelRatio(Math.min(me.value,2)))},ve=()=>{if(!t.value)return;const j=f.resolveUnref(G);if(j){j in X||V("Renderer Preset must be one of these: "+Object.keys(X).join(", ")),te(t.value,X[j]);return}t.value.shadowMap.enabled=f.resolveUnref(h),t.value.shadowMap.type=f.resolveUnref(v),t.value.toneMapping=f.resolveUnref(k)||m.NoToneMapping,t.value.toneMappingExposure=f.resolveUnref(C),t.value.outputEncoding=f.resolveUnref(_)||m.LinearEncoding,w!=null&&w.value&&t.value.setClearColor(Pe(f.resolveUnref(w))),t.value.useLegacyLights=f.resolveUnref(L)},Ge=()=>{const j=f.unrefElement(y.canvas);j&&(t.value=new m.WebGLRenderer({canvas:j,alpha:f.resolveUnref(n),antialias:f.resolveUnref(a),context:f.resolveUnref(b),depth:f.resolveUnref(i),failIfMajorPerformanceCaveat:f.resolveUnref(o),logarithmicDepthBuffer:f.resolveUnref(l),powerPreference:f.resolveUnref(O),precision:f.resolveUnref(c),stencil:f.resolveUnref(u),preserveDrawingBuffer:f.resolveUnref(P),premultipliedAlpha:f.resolveUnref(p)}),R("renderer",t.value),R("clock",new m.Clock),R("aspectRatio",J),ve(),pe(),Fe(),r.value=!0)},Ve=()=>{t.value&&(t.value.dispose(),t.value=void 0,r.value=!1,ze())};return s.watch([J,me],pe),s.watch([h,v,_,L,k,C,w],ve),s.watch(()=>[y.canvas,y.container],()=>{f.unrefElement(y.canvas)&&f.unrefElement(y.container)&&Ge()},{immediate:!0,deep:!0}),{renderer:t,isReady:r,dispose:Ve,aspectRatio:J}}const Se=e=>typeof e=="string",ae=e=>!!e&&e.constructor===Array;function re(e){const t={nodes:{},materials:{}};return e&&e.traverse(r=>{r.name&&(t.nodes[r.name]=r),r.material&&!t.materials[r.material.name]&&(t.materials[r.material.name]=r.material)}),t}async function Oe(e,t,r,n,a){const{logError:i}=U(),l=new e;a&&a(l),r&&r(l);const c=(Array.isArray(t)?t:[t]).map(p=>new Promise((u,h)=>{l.load(p,v=>{v.scene&&Object.assign(v,re(v.scene)),u(v)},n,v=>h(i("[useLoader] - Failed to load resource",v)))}));return ae(t)?await Promise.all(c):await c[0]}async function xe(e){const t=new m.LoadingManager,r=new m.TextureLoader(t),n=a=>new Promise((i,l)=>{r.load(a,o=>i(o),()=>null,()=>{l(new Error("[useTextures] - Failed to load texture"))})});if(ae(e)){const a=await Promise.all(e.map(i=>n(i)));return e.length>1?a:a[0]}else{const{map:a,displacementMap:i,normalMap:l,roughnessMap:o,metalnessMap:c,aoMap:p,alphaMap:u,matcap:h}=e;return{map:a?await n(a):null,displacementMap:i?await n(i):null,normalMap:l?await n(l):null,roughnessMap:o?await n(o):null,metalnessMap:c?await n(c):null,aoMap:p?await n(p):null,alphaMap:u?await n(u):null,matcap:h?await n(h):null}}}const g=["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 Ae(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(g[e&255]+g[e>>8&255]+g[e>>16&255]+g[e>>24&255]+"-"+g[t&255]+g[t>>8&255]+"-"+g[t>>16&15|64]+g[t>>24&255]+"-"+g[r&63|128]+g[r>>8&255]+"-"+g[r>>16&255]+g[r>>24&255]+g[n&255]+g[n>>8&255]+g[n>>16&255]+g[n>>24&255]).toLowerCase()}const F=Symbol();function ie(){const e=s.shallowReactive({uuid:Ae(),camera:void 0,cameras:[],scene:void 0,renderer:void 0,aspectRatio:s.computed(()=>window.innerWidth/window.innerHeight)});function t(a){return e[a]}function r(a,i){e[a]=i}const n={state:e,...s.toRefs(e),getState:t,setState:r};return s.provide(F,n),n}const S=()=>s.inject(F,{state:s.shallowReactive({camera:void 0,cameras:[],scene:void 0,renderer:void 0})});function oe(){var l;const e=s.shallowRef(new m.Raycaster),t=s.ref(new m.Vector2),r=s.ref(null),{setState:n,state:a}=S();n("raycaster",e.value),n("pointer",t),n("currentInstance",r);function i(o){t.value.x=o.clientX/window.innerWidth*2-1,t.value.y=-(o.clientY/window.innerHeight)*2+1}return(l=a==null?void 0:a.renderer)==null||l.domElement.addEventListener("pointermove",i),s.onUnmounted(()=>{var o;(o=a==null?void 0:a.renderer)==null||o.domElement.removeEventListener("pointermove",i)}),{raycaster:e,pointer:t}}const Te=!0,se="[TresJS ▲ ■ ●] ";function U(){function e(n,a){console.error(`${se} ${n}`,a||"")}function t(n){console.warn(`${se} ${n}`)}function r(n,a){}return{logError:e,logWarning:t,logMessage:r}}function Ue(){const{logWarning:e}=U();function t(n,a,i){let l=null;return n.traverse(o=>{o[a]===i&&(l=o)}),l||e(`Child with ${a} '${i}' not found.`),l}function r(n,a){return t(n,"name",a)}return{seek:t,seekByName:r}}const ke=/^on[^a-z]/,Re=e=>ke.test(e);function Ne(e){}let ce=null;const fe={GEOMETRY_VIA_PROP:"tres__geometryViaProp",MATERIAL_VIA_PROP:"tres__materialViaProp"},{logError:le}=U(),je={createElement(e,t,r,n){var c,p;if(n||(n={}),n.args||(n.args=[]),e==="template"||Le(e))return null;let a=e.replace("Tres",""),i;if(e==="primitive"){(n==null?void 0:n.object)===void 0&&le("Tres primitives need a prop 'object'");const u=n.object;a=u.type,i=Object.assign(u,{type:a,attach:n.attach,primitive:!0})}else{const u=N.value[a];u||le(`${a} is not defined on the THREE namespace. Use extend to add it to the catalog.`),i=new u(...n.args)}if(i.isCamera){n!=null&&n.position||i.position.set(3,3,3),n!=null&&n.lookAt||i.lookAt(0,0,0);const{pushCamera:u}=$();u(i)}(n==null?void 0:n.attach)===void 0&&(i.isMaterial?i.attach="material":i.isBufferGeometry&&(i.attach="geometry"));const{GEOMETRY_VIA_PROP:l,MATERIAL_VIA_PROP:o}=fe;return i.isObject3D&&((c=n==null?void 0:n.material)!=null&&c.isMaterial&&(i.userData[o]=!0),(p=n==null?void 0:n.geometry)!=null&&p.isBufferGeometry&&(i.userData[l]=!0)),i.events={},i},insert(e,t){var r,n;if(((e==null?void 0:e.__vnode.type)==="TresGroup"||(e==null?void 0:e.__vnode.type)==="TresObject3D")&&t===null&&!((n=(r=e==null?void 0:e.__vnode)==null?void 0:r.ctx)!=null&&n.asyncResolved)){ce=e;return}t||(t=ce),e!=null&&e.isObject3D&&(t!=null&&t.isObject3D)?(t.add(e),e.dispatchEvent({type:"added"})):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,r;if(e){if(e.isObject3D){const n=e,a=i=>{var c,p;const{GEOMETRY_VIA_PROP:l,MATERIAL_VIA_PROP:o}=fe;i.userData[o]||(c=i.material)==null||c.dispose(),i.userData[l]||(p=i.geometry)==null||p.dispose()};n.traverse(i=>a(i)),a(n)}(t=e.removeFromParent)==null||t.call(e),(r=e.dispose)==null||r.call(e)}},patchProp(e,t,r,n){if(e){let a=e,i=t,l=z(i),o=a==null?void 0:a[l];if(a.type==="BufferGeometry"){a.setAttribute(z(i),new m.BufferAttribute(...n));return}if(i.includes("-")&&o===void 0){const p=i.split("-");o=p.reduce((u,h)=>u[z(h)],a),i=p.pop(),l=i.toLowerCase(),o!=null&&o.set||(a=p.reduce((u,h)=>u[z(h)],a))}Re(i)&&(e.events[i]=n);let c=n;if(c===""&&(c=!0),f.isFunction(o)){Array.isArray(c)?e[l](...c):e[l](c);return}!(o!=null&&o.set)&&!f.isFunction(o)?a[l]=c:o.constructor===c.constructor&&(o!=null&&o.copy)?o==null||o.copy(c):Array.isArray(c)?o.set(...c):!o.isColor&&o.setScalar?o.setScalar(c):o.set(c)}},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:De}=s.createRenderer(je),Ie=e=>{const t=De(r);function r(){return e&&e.default?e.default():[]}return t};Y(Q);const{logWarning:ue}=U(),Ee=s.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender"],setup(e,{slots:t,expose:r}){e.physicallyCorrectLights===!0&&ue("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const n=s.ref(),a=s.ref(),i=new Q.Scene,{setState:l}=S();l("scene",i),l("canvas",a),l("container",n);const o=s.ref(),c=t&&t.default&&t.default();(c==null?void 0:c.length)>0&&(o.value=c.some(v=>Se(v.type)&&v.type.includes("Camera")),o.value||ue("No camera found in the scene, please add one!")),s.onMounted(()=>{p()}),s.onUnmounted(()=>{l("renderer",null)});function p(){const{renderer:v}=ne(e),{activeCamera:M}=$(),{onLoop:L}=K(),{raycaster:_,pointer:k}=oe();let C=null,b=null;s.watchEffect(()=>{M.value&&_.value.setFromCamera(k.value,M.value)}),L(()=>{var O,P,w,x,G,y,R,I,A,V;if(M.value&&e.disableRender!==!0&&e.disableRender!==""&&((O=v.value)==null||O.render(i,M.value)),_.value){const W=_.value.intersectObjects(i.children);W.length>0?(b=W[0],C===null&&((x=(w=(P=b.object)==null?void 0:P.events)==null?void 0:w.onPointerEnter)==null||x.call(w,b)),(R=(y=(G=b.object)==null?void 0:G.events)==null?void 0:y.onPointerMove)==null||R.call(y,b)):C!==null&&((V=(A=(I=b==null?void 0:b.object)==null?void 0:I.events)==null?void 0:A.onPointerLeave)==null||V.call(A,C),b=null),C=b}}),f.useEventListener(a.value,"click",()=>{var O,P,w;b!==null&&((w=(P=(O=b.object)==null?void 0:O.events)==null?void 0:P.onClick)==null||w.call(P,b))})}let u;function h(){u=Ie(t),u.provide("useTres",S()),u.provide(F,S()),u.provide("extend",Y),u.mount(i)}return h(),r({scene:i}),()=>s.h(s.h("div",{ref:n,"data-scene":i.uuid,key:i.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[s.h("div",{style:{width:"100%",height:"100%"}},[s.h("canvas",{ref:a,"data-scene":i.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),de=s.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender"],setup(e,{slots:t,expose:r}){const n=ie();return r(n),()=>s.h(Ee,e,t)}}),Be={install(e){e.component("TresCanvas",de)}};d.CameraType=Z,d.TRES_CONTEXT_KEY=F,d.TresCanvas=de,d.catalogue=N,d.default=Be,d.extend=Y,d.isProd=Te,d.trasverseObjects=re,d.useCamera=$,d.useLoader=Oe,d.useLogger=U,d.useRaycaster=oe,d.useRenderLoop=K,d.useRenderer=ne,d.useSeek=Ue,d.useTexture=xe,d.useTres=S,d.useTresProvider=ie,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@tresjs/core",
3
3
  "description": "Declarative ThreeJS using Vue Components",
4
- "version": "2.0.0-beta.0",
4
+ "version": "2.0.0-beta.10",
5
5
  "type": "module",
6
+ "packageManager": "pnpm@8.2.0",
6
7
  "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
7
8
  "files": [
8
9
  "dist"
@@ -56,48 +57,48 @@
56
57
  "vue": "^3.2.47"
57
58
  },
58
59
  "dependencies": {
59
- "-": "^0.0.1",
60
60
  "@alvarosabu/utils": "^2.3.0",
61
61
  "@vueuse/core": "^9.13.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@alvarosabu/prettier-config": "^1.2.0",
64
+ "@tresjs/core": "2.0.0-beta.5",
65
+ "@alvarosabu/prettier-config": "^1.3.0",
65
66
  "@huntersofbook/plausible-vue": "^1.0.0",
66
67
  "@release-it/conventional-changelog": "^5.1.1",
67
- "@stackblitz/sdk": "^1.8.1",
68
- "@tresjs/cientos": "2.0.0-alpha.5",
68
+ "@stackblitz/sdk": "^1.9.0",
69
+ "@tresjs/cientos": "2.0.0-beta.1",
69
70
  "@types/three": "latest",
70
- "@typescript-eslint/eslint-plugin": "^5.42.0",
71
- "@typescript-eslint/parser": "^5.42.0",
72
- "@vitejs/plugin-vue": "^4.0.0",
73
- "@vitest/coverage-c8": "^0.29.2",
71
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
72
+ "@typescript-eslint/parser": "^5.58.0",
73
+ "@vitejs/plugin-vue": "^4.1.0",
74
+ "@vitest/coverage-c8": "^0.30.1",
74
75
  "@vitest/ui": "^0.29.2",
75
- "@vue/test-utils": "^2.3.1",
76
- "eslint": "^8.26.0",
77
- "eslint-config-prettier": "^8.5.0",
78
- "eslint-plugin-vue": "^9.7.0",
79
- "gsap": "^3.11.4",
80
- "happy-dom": "^8.7.1",
81
- "jsdom": "^21.1.0",
76
+ "@vue/test-utils": "^2.3.2",
77
+ "eslint": "^8.38.0",
78
+ "eslint-config-prettier": "^8.8.0",
79
+ "eslint-plugin-vue": "^9.11.0",
80
+ "gsap": "^3.11.5",
81
+ "happy-dom": "^9.6.1",
82
+ "jsdom": "^21.1.1",
82
83
  "kolorist": "^1.7.0",
83
84
  "pathe": "^1.1.0",
84
- "prettier": "^2.8.6",
85
- "release-it": "^15.9.1",
85
+ "prettier": "^2.8.7",
86
+ "release-it": "^15.10.1",
86
87
  "rollup-plugin-analyzer": "^4.0.0",
87
88
  "rollup-plugin-copy": "^3.4.0",
88
89
  "rollup-plugin-visualizer": "^5.9.0",
89
- "three": "latest",
90
- "unocss": "^0.48.0",
90
+ "three": "^0.150.1",
91
+ "unocss": "^0.51.4",
91
92
  "unplugin": "^1.3.1",
92
93
  "unplugin-vue-components": "^0.24.1",
93
- "vite": "^4.1.4",
94
+ "vite": "^4.2.1",
94
95
  "vite-plugin-banner": "^0.7.0",
95
- "vite-plugin-dts": "2.1.0",
96
- "vite-plugin-inspect": "^0.7.16",
97
- "vite-plugin-require-transform": "^1.0.9",
96
+ "vite-plugin-dts": "2.2.0",
97
+ "vite-plugin-inspect": "^0.7.22",
98
+ "vite-plugin-require-transform": "^1.0.12",
98
99
  "vite-svg-loader": "^4.0.0",
99
- "vitepress": "1.0.0-alpha.38",
100
- "vitest": "^0.29.2",
101
- "vue-demi": "^0.13.11"
100
+ "vitepress": "1.0.0-alpha.65",
101
+ "vitest": "^0.30.1",
102
+ "vue-demi": "^0.14.0"
102
103
  }
103
104
  }