@tresjs/core 1.8.0 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tres.js CHANGED
@@ -1,30 +1,31 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v1.8.0
3
+ * version: v2.0.0-alpha.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 { watch as j, toRef as Oe, ref as M, inject as de, defineComponent as Q, onUnmounted as ge, shallowRef as ee, shallowReactive as Ae, computed as he, toRefs as we, provide as b, onBeforeUnmount as Be, h as K } from "vue";
9
- import { useEventListener as Ie, createEventHook as te, useRafFn as Fe, resolveUnref as h, useWindowSize as _e, useElementSize as Ue, useDevicePixelRatio as je, unrefElement as X } from "@vueuse/core";
10
- import * as se from "three";
11
- import { PerspectiveCamera as z, OrthographicCamera as ye, Vector3 as ze, Color as Y, Mesh as De, Fog as We, BufferAttribute as ke, Clock as ve, Scene as Ne, LoadingManager as Ve, TextureLoader as He, Raycaster as Ge, Vector2 as Ke, sRGBEncoding as Xe, ACESFilmicToneMapping as Ye, PCFSoftShadowMap as Je, PCFShadowMap as Ze, LinearEncoding as ce, NoToneMapping as le, WebGLRenderer as qe } from "three";
12
- var Qe = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Qe || {});
13
- const et = 45;
14
- let P;
15
- function Se() {
16
- const { state: e, setState: n } = T();
17
- function o(u = "Perspective", t) {
18
- var r, l, s;
19
- if (u === "Perspective") {
20
- const { near: i, far: f, fov: g } = t || {
8
+ import { ref as y, watchEffect as Ee, toRef as xe, shallowRef as ne, toRefs as ae, computed as re, watch as T, shallowReactive as Pe, createRenderer as Re, defineComponent as Se, h as x } from "vue";
9
+ import * as oe from "three";
10
+ import { MathUtils as Te, PerspectiveCamera as _, OrthographicCamera as Oe, Clock as ie, Color as W, sRGBEncoding as Ae, ACESFilmicToneMapping as ke, PCFSoftShadowMap as je, PCFShadowMap as De, LinearEncoding as Y, NoToneMapping as Q, WebGLRenderer as Fe, LoadingManager as _e, TextureLoader as We, Raycaster as ze, Vector2 as Be, Mesh as Ie } from "three";
11
+ import { createEventHook as U, useRafFn as He, resolveUnref as u, useWindowSize as Ge, useElementSize as Ue, useDevicePixelRatio as Ve, unrefElement as z, useEventListener as $e, isFunction as Z } from "@vueuse/core";
12
+ const G = y({ uuid: Te.generateUUID() }), se = (e) => void Object.assign(G.value, e);
13
+ var Ne = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Ne || {});
14
+ const qe = 45;
15
+ let h;
16
+ function ce() {
17
+ const { state: e, setState: t, aspectRatio: r } = k();
18
+ function o(a = "Perspective", s) {
19
+ var l, f, d;
20
+ if (a === "Perspective") {
21
+ const { near: m, far: g, fov: v } = s || {
21
22
  near: 0.1,
22
23
  far: 1e3,
23
- fov: et
24
+ fov: qe
24
25
  };
25
- P = new z(g, ((r = e.aspectRatio) == null ? void 0 : r.value) || window.innerWidth / window.innerHeight, i, f), (l = e.cameras) == null || l.push(P);
26
+ h = new _(v, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, m, g), (f = e.cameras) == null || f.push(h);
26
27
  } else {
27
- const { left: i, right: f, top: g, bottom: v, near: p, far: m } = t || {
28
+ const { left: m, right: g, top: v, bottom: b, near: L, far: E } = s || {
28
29
  left: -100,
29
30
  right: 100,
30
31
  top: 100,
@@ -32,501 +33,423 @@ function Se() {
32
33
  near: 0.1,
33
34
  far: 1e3
34
35
  };
35
- P = new ye(i, f, g, v, p, m), (s = e.cameras) == null || s.push(P);
36
+ h = new Oe(m, g, v, b, L, E), (d = e.cameras) == null || d.push(h);
36
37
  }
37
- return e.camera = P, n("camera", e.camera), P;
38
+ return e.camera = h, t("camera", e.camera), h;
38
39
  }
39
- function a() {
40
- var u;
41
- e.camera instanceof z && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (u = e.camera) == null || u.updateProjectionMatrix();
40
+ function n() {
41
+ var a;
42
+ e.camera instanceof _ && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (a = e.camera) == null || a.updateProjectionMatrix();
42
43
  }
43
- function c(u) {
44
- var t;
45
- (t = e.cameras) == null || t.push(u), u instanceof z && e.aspectRatio && (u.aspect = e.aspectRatio.value), u.updateProjectionMatrix(), n("camera", u);
44
+ function i(a) {
45
+ var s;
46
+ (s = e.cameras) == null || s.push(a), a instanceof _ && e.aspectRatio && (a.aspect = e.aspectRatio.value), a.updateProjectionMatrix(), t("camera", a);
46
47
  }
47
- function d() {
48
+ function c() {
48
49
  e.cameras = [];
49
50
  }
50
- return e.aspectRatio && j(e.aspectRatio, a), {
51
- activeCamera: Oe(e, "camera"),
51
+ return Ee(() => {
52
+ r != null && r.value && n();
53
+ }), {
54
+ activeCamera: xe(e, "camera"),
52
55
  createCamera: o,
53
- updateCamera: a,
54
- pushCamera: c,
55
- clearCameras: d
56
+ updateCamera: n,
57
+ pushCamera: i,
58
+ clearCameras: c
56
59
  };
57
60
  }
58
- const ue = "[TresJS ▲ ■ ●] ";
59
- function I() {
60
- function e(a, c) {
61
- console.error(`${ue} ${a}`, c || "");
62
- }
63
- function n(a) {
64
- console.warn(`${ue} ${a}`);
65
- }
66
- function o(a, c) {
67
- }
61
+ const ue = U(), le = U(), V = U(), C = new ie();
62
+ let O = 0, A = 0;
63
+ const { pause: Je, resume: Ke, isActive: Xe } = He(
64
+ () => {
65
+ ue.trigger({ delta: O, elapsed: A, clock: C }), le.trigger({ delta: O, elapsed: A, clock: C }), V.trigger({ delta: O, elapsed: A, clock: C });
66
+ },
67
+ { immediate: !1 }
68
+ );
69
+ V.on(() => {
70
+ O = C.getDelta(), A = C.getElapsedTime();
71
+ });
72
+ function $() {
68
73
  return {
69
- logError: e,
70
- logWarning: n,
71
- logMessage: o
74
+ onBeforeLoop: ue.on,
75
+ onLoop: le.on,
76
+ onAfterLoop: V.on,
77
+ pause: Je,
78
+ resume: Ke,
79
+ isActive: Xe
72
80
  };
73
81
  }
74
- const D = M({ ...se, uuid: se.MathUtils.generateUUID() });
75
- delete D.value.Scene;
76
- let O;
77
- function Ce(e, n = "Tres") {
78
- const { logError: o } = I();
79
- !O && e && (O = e);
80
- const { createComponentInstances: a } = Ee(n);
81
- return {
82
- extend: (d) => {
83
- if (!d) {
84
- o("No objects provided to extend catalogue");
85
- return;
86
- }
87
- D.value = Object.assign(D.value, d);
88
- const u = a(M(d));
89
- O && u.forEach(([t, r]) => {
90
- O._context.components[t] || O.component(t, r);
91
- });
92
- },
93
- catalogue: D
94
- };
82
+ function Ye(e) {
83
+ return e instanceof W ? e : Array.isArray(e) ? new W(...e) : new W(e);
95
84
  }
96
- const R = (e) => typeof e < "u", tt = (e) => typeof e == "function", N = (e) => !!e && e.constructor === Array;
97
- function nt(e) {
98
- return typeof e == "number" ? [e, e, e] : e instanceof ze ? [e.x, e.y, e.z] : e;
85
+ const B = {
86
+ realistic: {
87
+ outputEncoding: Ae,
88
+ toneMapping: ke,
89
+ toneMappingExposure: 3,
90
+ shadowMap: {
91
+ enabled: !0,
92
+ type: je
93
+ }
94
+ }
95
+ }, fe = (e, t) => {
96
+ for (const r of Object.keys(t))
97
+ t[r] instanceof Object && Object.assign(t[r], fe(e[r], t[r]));
98
+ return Object.assign(e || {}, t), e;
99
+ }, Qe = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot", Ze = /* @__PURE__ */ et(Qe);
100
+ function I(e) {
101
+ return e.replace(/-([a-z])/g, (t, r) => r.toUpperCase());
99
102
  }
100
- function rt(e) {
101
- return e instanceof Y ? e : Array.isArray(e) ? new Y(...e) : new Y(e);
103
+ function et(e, t) {
104
+ const r = /* @__PURE__ */ Object.create(null), o = e.split(",");
105
+ for (let n = 0; n < o.length; n++)
106
+ r[o[n]] = !0;
107
+ return t ? (n) => !!r[n.toLowerCase()] : (n) => !!r[n];
102
108
  }
103
- const fe = ["rotation", "scale", "position"], ot = ["X", "Y", "Z"], at = ["color"], it = ["r", "g", "b"];
104
- function Ee(e) {
109
+ const p = ne(), H = y(!1);
110
+ function tt(e, t, r) {
105
111
  const {
106
- /* logMessage, */
107
- logError: n
108
- } = I();
109
- function o(t, r) {
110
- R(t) && R(r) && Object.entries(t).forEach(([l, s]) => {
111
- const i = l.replace(/(-\w)/g, (f) => f[1].toUpperCase());
112
- r.setAttribute(i, new ke(...s));
113
- });
114
- }
115
- function a(t, r) {
116
- R(t) && R(r) && Object.entries(t).forEach(([l, s]) => {
117
- const i = l.replace(/(-\w)/g, (m) => m[1].toUpperCase());
118
- let f, g, v, p;
119
- if (!(i === "args" || s === void 0)) {
120
- fe.includes(i) && s ? s = nt(s) : fe.forEach((m) => {
121
- i.startsWith(m) && i.length === m.length + 1 && (f = m, g = i.substring(m.length), ot.includes(g) || n(
122
- // eslint-disable-next-line max-len
123
- `There was an error setting ${l} property, ${g} is not a valid axis for ${f}`
124
- ));
125
- }), at.forEach((m) => {
126
- i.startsWith(m) && i.length === m.length + 1 && (v = m, p = i.substring(m.length).toLowerCase(), it.includes(p) || n(`There was an error setting ${l} property , ${p} is not a valid axis for ${v}`));
127
- }), t.ref && (t.ref = r);
128
- try {
129
- if (r[i] && R(r[i].set))
130
- r[i].set(...N(s) ? s : [s]);
131
- else if (
132
- // Check if the property has a "setAxis" method
133
- f && r[f]
134
- )
135
- R(r[f][`set${g}`]) ? r[f][`set${g}`](s) : R(r[`rotate${g}`]) && r[`rotate${g}`](s);
136
- else if (
137
- // Check if the instance has a "color" property
138
- v && p && r[v] && r[v][p]
139
- )
140
- r[v][p] = s;
141
- else {
142
- if (s === "" && (s = !0), tt(r[i])) {
143
- if (l === "center" && !s)
144
- return;
145
- r[i](...N(s) ? s : [s]);
146
- return;
147
- }
148
- r[i] = s;
149
- }
150
- } catch (m) {
151
- n(`There was an error setting ${i} property`, m);
152
- }
153
- }
154
- });
155
- }
156
- function c(t) {
157
- var i, f;
158
- const r = /^Symbol\(Fragment\)$/g, l = /^Symbol\(Text\)$/g, s = /^Symbol\(Comment\)$/g;
159
- if (r.test(t.type.toString()))
160
- return t.children.map((g) => c(g));
161
- if (l.test(t.type.toString()) || s.test(t.type.toString()))
112
+ alpha: o = !0,
113
+ antialias: n = !0,
114
+ depth: i,
115
+ logarithmicDepthBuffer: c,
116
+ failIfMajorPerformanceCaveat: a,
117
+ precision: s,
118
+ premultipliedAlpha: l,
119
+ stencil: f,
120
+ shadows: d = !1,
121
+ shadowMapType: m = De,
122
+ physicallyCorrectLights: g = !1,
123
+ useLegacyLights: v = !1,
124
+ outputEncoding: b = Y,
125
+ toneMapping: L = Q,
126
+ toneMappingExposure: E = 1,
127
+ context: de = void 0,
128
+ powerPreference: ve = "default",
129
+ preserveDrawingBuffer: ge = !1,
130
+ clearColor: M,
131
+ windowSize: we = !1,
132
+ preset: he = void 0
133
+ } = ae(r), { setState: D } = k(), { width: N, height: q } = u(we) ? Ge() : Ue(t), { logError: ye } = j(), { pixelRatio: J } = Ve(), { pause: Me, resume: Ce } = $(), F = re(() => N.value / q.value), K = () => {
134
+ p.value && (p.value.setSize(N.value, q.value), p.value.setPixelRatio(Math.min(J.value, 2)));
135
+ }, X = () => {
136
+ if (!p.value)
137
+ return;
138
+ const w = u(he);
139
+ if (w) {
140
+ w in B || ye("Renderer Preset must be one of these: " + Object.keys(B).join(", ")), fe(p.value, B[w]);
162
141
  return;
163
- {
164
- const g = t.type.name.replace(e, ""), { catalogue: v } = Ce(), p = de("catalogue") || v;
165
- let m;
166
- if (p)
167
- if ((i = t.children) != null && i.default) {
168
- const L = t.children.default().map((S) => c(S));
169
- m = new p.value[g](...L.flat().filter(Boolean));
170
- } else
171
- (f = t == null ? void 0 : t.props) != null && f.args ? p != null && p.value[g] ? m = new p.value[g](...t.props.args) : n(`There is no ${g} in the catalogue`, p == null ? void 0 : p.value.uuid) : m = new p.value[g]();
172
- return t != null && t.props && (g === "BufferGeometry" ? o(t.props, m) : a(t.props, m)), m;
173
142
  }
174
- }
175
- function d(t, r, l) {
176
- if (l.default && (l != null && l.default())) {
177
- const s = l.default().map((i) => c(i));
178
- if (t.name === "Group") {
179
- const i = new t();
180
- return s.forEach((f) => {
181
- i.add(f);
182
- }), i;
183
- } else
184
- return new t(...s.flat().filter(Boolean));
185
- } else
186
- return r.args ? new t(...r.args) : new t();
187
- }
188
- function u(t) {
189
- return Object.entries(t.value).filter(([r, l]) => {
190
- var s, i;
191
- return (i = (s = l == null ? void 0 : l.prototype) == null ? void 0 : s.constructor) == null ? void 0 : i.toString().includes("class");
192
- }).map(([r, l]) => {
193
- const s = `${e}${r}`, i = Q({
194
- name: s,
195
- setup(f, { slots: g, attrs: v, ...p }) {
196
- const { state: m } = T(), { onLoop: L } = re(), S = m.scene, F = m.raycaster, { pushCamera: V } = Se();
197
- let y = d(l, v, g);
198
- a(v, y), (y instanceof z || y instanceof ye) && V(y), y.isObject3D && (S == null || S.add(y));
199
- let E = null, C = null;
200
- if (y instanceof De) {
201
- L(() => {
202
- if (y && F && (S != null && S.children)) {
203
- const $ = F.intersectObjects(S == null ? void 0 : S.children);
204
- $.length > 0 ? (C = $[0], (E === null || E.object.uuid !== (C == null ? void 0 : C.object.uuid)) && p.emit("pointer-enter", C), p.emit("pointer-move", C)) : (C = null, E !== null && p.emit("pointer-leave", E)), E = C;
205
- }
206
- });
207
- const _ = Ie(window, "click", () => {
208
- p.emit("click", E);
209
- });
210
- ge(() => {
211
- _();
212
- });
213
- }
214
- return S && y instanceof We && (S.fog = y), p.expose(y), () => {
215
- };
216
- }
217
- });
218
- return [s, i];
219
- });
220
- }
221
- return {
222
- createComponentInstances: u,
223
- processProps: a,
224
- createInstanceFromVNode: c
143
+ p.value.shadowMap.enabled = u(d), p.value.shadowMap.type = u(m), p.value.toneMapping = u(L) || Q, p.value.toneMappingExposure = u(E), p.value.outputEncoding = u(b) || Y, M != null && M.value && p.value.setClearColor(Ye(u(M))), p.value.useLegacyLights = u(v);
144
+ }, be = () => {
145
+ const w = z(e);
146
+ w && (p.value = new Fe({
147
+ canvas: w,
148
+ alpha: u(o),
149
+ antialias: u(n),
150
+ context: u(de),
151
+ depth: u(i),
152
+ failIfMajorPerformanceCaveat: u(a),
153
+ logarithmicDepthBuffer: u(c),
154
+ powerPreference: u(ve),
155
+ precision: u(s),
156
+ stencil: u(f),
157
+ preserveDrawingBuffer: u(ge),
158
+ premultipliedAlpha: u(l)
159
+ }), D("renderer", p.value), D("clock", new ie()), D("aspectRatio", F), X(), K(), Ce(), H.value = !0);
160
+ }, Le = () => {
161
+ p.value && (p.value.dispose(), p.value = void 0, H.value = !1, Me());
225
162
  };
226
- }
227
- const Re = te(), Me = te(), ne = te(), B = new ve();
228
- let W = 0, k = 0;
229
- const { pause: st, resume: ct, isActive: lt } = Fe(
230
- () => {
231
- Re.trigger({ delta: W, elapsed: k, clock: B }), Me.trigger({ delta: W, elapsed: k, clock: B }), ne.trigger({ delta: W, elapsed: k, clock: B });
232
- },
233
- { immediate: !1 }
234
- );
235
- ne.on(() => {
236
- W = B.getDelta(), k = B.getElapsedTime();
237
- });
238
- function re() {
239
- return {
240
- onBeforeLoop: Re.on,
241
- onLoop: Me.on,
242
- onAfterLoop: ne.on,
243
- pause: st,
244
- resume: ct,
245
- isActive: lt
246
- };
247
- }
248
- const ut = ee(new Ne());
249
- function ft() {
250
- return {
251
- scene: ut
163
+ return T([F, J], K), T(
164
+ [d, m, b, v, L, E, M],
165
+ X
166
+ ), T(
167
+ () => [e, t],
168
+ () => {
169
+ z(e) && z(t) && be();
170
+ },
171
+ { immediate: !0, deep: !0 }
172
+ ), {
173
+ renderer: p,
174
+ isReady: H,
175
+ dispose: Le,
176
+ aspectRatio: F
252
177
  };
253
178
  }
254
- function pt(e) {
255
- const n = { nodes: {}, materials: {} };
256
- return e && e.traverse((o) => {
257
- o.name && (n.nodes[o.name] = o), o.material && !n.materials[o.material.name] && (n.materials[o.material.name] = o.material);
258
- }), n;
179
+ const pe = (e) => !!e && e.constructor === Array;
180
+ function nt(e) {
181
+ const t = { nodes: {}, materials: {} };
182
+ return e && e.traverse((r) => {
183
+ r.name && (t.nodes[r.name] = r), r.material && !t.materials[r.material.name] && (t.materials[r.material.name] = r.material);
184
+ }), t;
259
185
  }
260
- async function Ct(e, n, o, a, c) {
261
- const { logError: d } = I(), u = new e();
262
- c && c(u), o && o(u);
263
- const r = (Array.isArray(n) ? n : [n]).map(
264
- (l) => new Promise((s, i) => {
265
- u.load(
186
+ async function dt(e, t, r, o, n) {
187
+ const { logError: i } = j(), c = new e();
188
+ n && n(c), r && r(c);
189
+ const s = (Array.isArray(t) ? t : [t]).map(
190
+ (l) => new Promise((f, d) => {
191
+ c.load(
266
192
  l,
267
- (f) => {
268
- f.scene && Object.assign(f, pt(f.scene)), s(f);
193
+ (m) => {
194
+ m.scene && Object.assign(m, nt(m.scene)), f(m);
269
195
  },
270
- a,
271
- (f) => i(d("[useLoader] - Failed to load resource", f))
196
+ o,
197
+ (m) => d(i("[useLoader] - Failed to load resource", m))
272
198
  );
273
199
  })
274
200
  );
275
- return N(n) ? await Promise.all(r) : await r[0];
201
+ return pe(t) ? await Promise.all(s) : await s[0];
276
202
  }
277
- async function Et(e) {
278
- const n = new Ve(), o = new He(n), a = (c) => new Promise((d, u) => {
279
- o.load(
280
- c,
281
- (t) => d(t),
203
+ async function vt(e) {
204
+ const t = new _e(), r = new We(t), o = (n) => new Promise((i, c) => {
205
+ r.load(
206
+ n,
207
+ (a) => i(a),
282
208
  () => null,
283
209
  () => {
284
- u(new Error("[useTextures] - Failed to load texture"));
210
+ c(new Error("[useTextures] - Failed to load texture"));
285
211
  }
286
212
  );
287
213
  });
288
- if (N(e)) {
289
- const c = await Promise.all(e.map((d) => a(d)));
290
- return e.length > 1 ? c : c[0];
214
+ if (pe(e)) {
215
+ const n = await Promise.all(e.map((i) => o(i)));
216
+ return e.length > 1 ? n : n[0];
291
217
  } else {
292
- const { map: c, displacementMap: d, normalMap: u, roughnessMap: t, metalnessMap: r, aoMap: l } = e;
218
+ const { map: n, displacementMap: i, normalMap: c, roughnessMap: a, metalnessMap: s, aoMap: l } = e;
293
219
  return {
294
- map: c ? await a(c) : null,
295
- displacementMap: d ? await a(d) : null,
296
- normalMap: u ? await a(u) : null,
297
- roughnessMap: t ? await a(t) : null,
298
- metalnessMap: r ? await a(r) : null,
299
- aoMap: l ? await a(l) : null
220
+ map: n ? await o(n) : null,
221
+ displacementMap: i ? await o(i) : null,
222
+ normalMap: c ? await o(c) : null,
223
+ roughnessMap: a ? await o(a) : null,
224
+ metalnessMap: s ? await o(s) : null,
225
+ aoMap: l ? await o(l) : null
300
226
  };
301
227
  }
302
228
  }
303
- const U = Ae({
229
+ const P = Pe({
304
230
  camera: void 0,
305
231
  cameras: [],
306
- aspectRatio: he(() => window.innerWidth / window.innerHeight)
232
+ aspectRatio: re(() => window.innerWidth / window.innerHeight)
307
233
  });
308
- function T() {
309
- function e(o) {
310
- return U[o];
234
+ function k() {
235
+ function e(r) {
236
+ return P[r];
311
237
  }
312
- function n(o, a) {
313
- U[o] = a;
238
+ function t(r, o) {
239
+ P[r] = o;
314
240
  }
315
241
  return {
316
- state: U,
317
- ...we(U),
242
+ state: P,
243
+ ...ae(P),
318
244
  getState: e,
319
- setState: n
245
+ setState: t
320
246
  };
321
247
  }
322
- const J = ee(new Ge()), A = M(new Ke()), pe = M(null);
323
- function mt() {
324
- const { setState: e } = T();
325
- e("raycaster", J.value), e("pointer", A), e("currentInstance", pe), b("raycaster", J), b("pointer", A), b("currentInstance", pe);
326
- function n(o) {
327
- A.value.x = o.clientX / window.innerWidth * 2 - 1, A.value.y = -(o.clientY / window.innerHeight) * 2 + 1;
248
+ const ee = ne(new ze()), R = y(new Be()), at = y(null);
249
+ function me() {
250
+ const { setState: e } = k();
251
+ e("raycaster", ee.value), e("pointer", R), e("currentInstance", at);
252
+ function t(r) {
253
+ R.value.x = r.clientX / window.innerWidth * 2 - 1, R.value.y = -(r.clientY / window.innerHeight) * 2 + 1;
328
254
  }
329
- return window.addEventListener("pointermove", n), ge(() => {
330
- window.removeEventListener("pointermove", n);
331
- }), {
332
- raycaster: J,
333
- pointer: A
255
+ return window.addEventListener("pointermove", t), {
256
+ raycaster: ee,
257
+ pointer: R
334
258
  };
335
259
  }
336
- const Z = {
337
- realistic: {
338
- outputEncoding: Xe,
339
- toneMapping: Ye,
340
- toneMappingExposure: 3,
341
- shadowMap: {
342
- enabled: !0,
343
- type: Je
344
- }
260
+ const gt = !0, te = "[TresJS ▲ ■ ●] ";
261
+ function j() {
262
+ function e(o, n) {
263
+ console.error(`${te} ${o}`, n || "");
345
264
  }
346
- }, Le = (e, n) => {
347
- for (const o of Object.keys(n))
348
- n[o] instanceof Object && Object.assign(n[o], Le(e[o], n[o]));
349
- return Object.assign(e || {}, n), e;
350
- }, w = ee(), q = M(!1);
351
- function dt(e, n, o) {
352
- const {
353
- alpha: a = !0,
354
- antialias: c = !0,
355
- depth: d,
356
- logarithmicDepthBuffer: u,
357
- failIfMajorPerformanceCaveat: t,
358
- precision: r,
359
- premultipliedAlpha: l,
360
- stencil: s,
361
- shadows: i = !1,
362
- shadowMapType: f = Ze,
363
- physicallyCorrectLights: g = !1,
364
- useLegacyLights: v = !1,
365
- outputEncoding: p = ce,
366
- toneMapping: m = le,
367
- toneMappingExposure: L = 1,
368
- context: S = void 0,
369
- powerPreference: F = "default",
370
- preserveDrawingBuffer: V = !1,
371
- clearColor: y,
372
- windowSize: E = !1,
373
- preset: C = void 0
374
- } = we(o), { width: _, height: $ } = h(E) ? _e() : Ue(n), { logError: xe } = I(), { pixelRatio: oe } = je(), { pause: Pe, resume: be } = re(), H = he(() => _.value / $.value), ae = () => {
375
- w.value && (w.value.setSize(_.value, $.value), w.value.setPixelRatio(Math.min(oe.value, 2)));
376
- }, ie = () => {
377
- if (!w.value)
378
- return;
379
- const x = h(C);
380
- if (x) {
381
- x in Z || xe("Renderer Preset must be one of these: " + Object.keys(Z).join(", ")), Le(w.value, Z[x]);
382
- return;
383
- }
384
- w.value.shadowMap.enabled = h(i), w.value.shadowMap.type = h(f), w.value.toneMapping = h(m) || le, w.value.toneMappingExposure = h(L), w.value.outputEncoding = h(p) || ce, y != null && y.value && w.value.setClearColor(rt(h(y))), w.value.useLegacyLights = h(v);
385
- }, Te = () => {
386
- const x = X(e);
387
- if (w.value || !x)
388
- return;
389
- w.value = new qe({
390
- canvas: x,
391
- alpha: h(a),
392
- antialias: h(c),
393
- context: h(S),
394
- depth: h(d),
395
- failIfMajorPerformanceCaveat: h(t),
396
- logarithmicDepthBuffer: h(u),
397
- powerPreference: h(F),
398
- precision: h(r),
399
- stencil: h(s),
400
- preserveDrawingBuffer: h(V),
401
- premultipliedAlpha: h(l)
402
- });
403
- const { setState: G } = T();
404
- G("renderer", w.value), G("clock", new ve()), G("aspectRatio", H), ie(), ae(), be(), q.value = !0;
405
- }, $e = () => {
406
- w.value && (w.value.dispose(), w.value = void 0, q.value = !1, Pe());
407
- };
408
- return j([H, oe], ae), j(
409
- [i, f, p, v, m, L, y],
410
- ie
411
- ), j(
412
- () => [e, n],
413
- () => {
414
- X(e) && X(n) && Te();
415
- },
416
- { immediate: !0, deep: !0 }
417
- ), {
418
- renderer: w,
419
- isReady: q,
420
- dispose: $e,
421
- aspectRatio: H
265
+ function t(o) {
266
+ console.warn(`${te} ${o}`);
267
+ }
268
+ function r(o, n) {
269
+ }
270
+ return {
271
+ logError: e,
272
+ logWarning: t,
273
+ logMessage: r
422
274
  };
423
275
  }
424
- const { logError: me, logWarning: gt } = I(), ht = Q({
425
- name: "TresCanvas",
426
- props: {
427
- shadows: Boolean,
428
- shadowMapType: Number,
429
- physicallyCorrectLights: {
430
- type: Boolean,
431
- default: !1,
432
- validator: (e) => (e && gt("physicallyCorrectLights is deprecated. Use useLegacyLights instead."), !0)
433
- },
434
- useLegacyLights: Boolean,
435
- outputEncoding: Number,
436
- toneMapping: Number,
437
- toneMappingExposure: Number,
438
- context: Object,
439
- powerPreference: String,
440
- preserveDrawingBuffer: Boolean,
441
- clearColor: String,
442
- windowSize: { type: Boolean, default: !1 },
443
- preset: String
276
+ const { logWarning: rt } = j();
277
+ function ot(e) {
278
+ for (const t in e)
279
+ if (t.indexOf("on") === 0)
280
+ return !0;
281
+ return !1;
282
+ }
283
+ let S = null;
284
+ const it = {
285
+ createElement(e, t, r, o) {
286
+ if (e === "template" || Ze(e))
287
+ return null;
288
+ let n;
289
+ if (o === null && (o = {}), o != null && o.args ? n = new G.value[e.replace("Tres", "")](...o.args) : n = new G.value[e.replace("Tres", "")](), n.isCamera) {
290
+ (!(o != null && o.position) || o != null && o.position.every((c) => c == 0)) && rt(
291
+ // eslint-disable-next-line max-len
292
+ "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 🤗"
293
+ );
294
+ const { pushCamera: i } = ce();
295
+ i(n);
296
+ }
297
+ return (o == null ? void 0 : o.attach) === void 0 && (n.isMaterial ? n.attach = "material" : n.isBufferGeometry && (n.attach = "geometry")), n;
298
+ },
299
+ insert(e, t, r) {
300
+ if (S === null && t.isScene && (S = t), t === null && (t = S), t != null && t.isObject3D && (e != null && e.isObject3D)) {
301
+ const a = r ? t.children.indexOf(r) : 0;
302
+ e.parent = t, t.children.splice(a, 0, e), e.dispatchEvent({ type: "added" });
303
+ } else
304
+ typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
305
+ const { onLoop: o } = $();
306
+ let n = null, i = null;
307
+ const { raycaster: c } = me();
308
+ e && e instanceof Ie && ot(e) && (o(() => {
309
+ var a, s, l;
310
+ if (t != null && t.children && e && c) {
311
+ const f = c.value.intersectObjects(t.children);
312
+ f.length > 0 && f[0].object.uuid === e.uuid ? (i = f[0], (n === null || n.object.uuid !== (i == null ? void 0 : i.object.uuid)) && ((a = e.onPointerEnter) == null || a.call(e, i)), (s = e.onPointerMove) == null || s.call(e, i)) : (i = null, n !== null && ((l = e.onPointerLeave) == null || l.call(e, n))), n = i;
313
+ }
314
+ }), $e(window, "click", () => {
315
+ var a;
316
+ i !== null && ((a = e.onClick) == null || a.call(e, i));
317
+ }));
318
+ },
319
+ remove(e) {
320
+ if (!e)
321
+ return;
322
+ const t = e.parentNode;
323
+ t && t.removeChild(e);
444
324
  },
445
- setup(e, { slots: n, attrs: o }) {
446
- const a = M(), c = M(), { renderer: d, dispose: u, aspectRatio: t } = dt(a, c, e);
447
- return b("aspect-ratio", t), b("renderer", d), n.default && !n.default().some((r) => r.type.name === "Scene") && me("TresCanvas must contain a Scene component."), n.default && !n.default().some((r) => {
448
- var l;
449
- return (l = r.type.name) == null ? void 0 : l.includes("Camera");
450
- }) && me("Scene must contain a Camera component."), Be(() => u()), () => {
451
- if (n.default)
452
- return K(
453
- "div",
454
- {
455
- ref: c,
456
- style: {
457
- position: "relative",
458
- width: "100%",
459
- height: "100%",
460
- overflow: "hidden",
461
- pointerEvents: "auto",
462
- touchAction: "none",
463
- ...o.style
464
- }
465
- },
466
- [
467
- K(
468
- "div",
469
- {
325
+ patchProp(e, t, r, o) {
326
+ if (e) {
327
+ let n = e, i = t;
328
+ const c = I(i);
329
+ let a = n == null ? void 0 : n[c];
330
+ if (e.parent || (e.parent = S), i.includes("-") && a === void 0) {
331
+ const l = i.split("-");
332
+ a = l.reduce((f, d) => f[I(d)], n), i = l.pop(), a != null && a.set || (n = l.reduce((f, d) => f[I(d)], n));
333
+ }
334
+ let s = o;
335
+ if (s === "" && (s = !0), Z(a))
336
+ return;
337
+ !(a != null && a.set) && !Z(a) ? n[c] = s : a.constructor === s.constructor && (a != null && a.copy) ? a == null || a.copy(s) : Array.isArray(s) ? a.set(...s) : !a.isColor && a.setScalar ? a.setScalar(s) : a.set(s);
338
+ }
339
+ },
340
+ parentNode(e) {
341
+ return (e == null ? void 0 : e.parent) || null;
342
+ },
343
+ createText: () => void 0,
344
+ createComment: () => void 0,
345
+ setText: () => void 0,
346
+ setElementText: () => void 0,
347
+ nextSibling: () => void 0,
348
+ querySelector: () => void 0,
349
+ setScopeId: () => void 0,
350
+ cloneNode: () => void 0,
351
+ insertStaticContent: () => void 0
352
+ }, { createApp: st } = Re(it), ct = (e) => {
353
+ const t = st(r);
354
+ function r() {
355
+ return e && e.default ? e.default() : [];
356
+ }
357
+ return t;
358
+ };
359
+ se(oe);
360
+ const { logWarning: ut } = j(), lt = Se({
361
+ name: "TresCanvas",
362
+ props: [
363
+ "shadows",
364
+ "shadowMapType",
365
+ "physicallyCorrectLights",
366
+ "useLegacyLights",
367
+ "outputEncoding",
368
+ "toneMapping",
369
+ "toneMappingExposure",
370
+ "context",
371
+ "powerPreference",
372
+ "preserveDrawingBuffer",
373
+ "clearColor",
374
+ "windowSize",
375
+ "preset"
376
+ ],
377
+ setup(e, { slots: t, expose: r }) {
378
+ e.physicallyCorrectLights === !0 && ut("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
379
+ const o = y(), n = y(), i = new oe.Scene();
380
+ function c() {
381
+ const { renderer: l } = tt(n, o, e), { activeCamera: f } = ce(), { onLoop: d } = $(), { raycaster: m, pointer: g } = me();
382
+ d(() => {
383
+ var v;
384
+ f.value && (m.value.setFromCamera(g.value, f.value), (v = l.value) == null || v.render(i, f.value));
385
+ });
386
+ }
387
+ T(n, c);
388
+ let a;
389
+ function s() {
390
+ a = ct(t), a.provide("useTres", k()), a.provide("extend", se), a.mount(i);
391
+ }
392
+ return s(), r({
393
+ scene: i
394
+ }), () => x(
395
+ x(
396
+ "div",
397
+ {
398
+ ref: o,
399
+ style: {
400
+ position: "relative",
401
+ width: "100%",
402
+ height: "100%",
403
+ pointerEvents: "auto",
404
+ touchAction: "none"
405
+ }
406
+ },
407
+ [
408
+ x(
409
+ "div",
410
+ {
411
+ style: {
412
+ width: "100%",
413
+ height: "100%"
414
+ }
415
+ },
416
+ [
417
+ x("canvas", {
418
+ ref: n,
470
419
  style: {
420
+ display: "block",
471
421
  width: "100%",
472
- height: "100%"
422
+ height: "100%",
423
+ position: e.windowSize ? "fixed" : "absolute",
424
+ top: 0,
425
+ left: 0
473
426
  }
474
- },
475
- [
476
- K("canvas", {
477
- ref: a,
478
- style: {
479
- display: "block",
480
- width: "100%",
481
- height: "100%",
482
- position: e.windowSize ? "fixed" : "absolute",
483
- top: 0,
484
- left: 0
485
- }
486
- }),
487
- n.default()
488
- ]
489
- )
490
- ]
491
- );
492
- };
493
- }
494
- }), wt = Q({
495
- name: "Scene",
496
- setup(e, { slots: n }) {
497
- const { setState: o } = T(), { scene: a } = ft(), c = de("renderer"), { activeCamera: d } = Se(), { raycaster: u, pointer: t } = mt(), { onLoop: r } = re();
498
- return b("local-scene", a), o("scene", a.value), r(() => {
499
- d.value && (u.value.setFromCamera(t.value, d.value), c != null && c.value && d && (a != null && a.value) && c.value.render(a == null ? void 0 : a.value, d.value));
500
- }), () => {
501
- if (n.default)
502
- return n.default();
503
- };
427
+ })
428
+ ]
429
+ )
430
+ ]
431
+ )
432
+ );
504
433
  }
505
- }), Rt = Symbol("UseTresState"), Mt = {
506
- install(e, n) {
507
- const o = (n == null ? void 0 : n.prefix) || "Tres";
508
- e.component(`${o}Canvas`, ht), e.component(`${o}Scene`, wt);
509
- const { catalogue: a, extend: c } = Ce(e, o);
510
- e.provide("catalogue", a), e.provide("extend", c), e.provide("useTres", T());
511
- const { createComponentInstances: d } = Ee(o);
512
- d(a).forEach(([t, r]) => {
513
- e.component(t, r);
514
- });
434
+ }), wt = {
435
+ install(e) {
436
+ e.component("TresCanvas", lt);
515
437
  }
516
438
  };
517
439
  export {
518
- Qe as CameraType,
519
- Rt as UseTresStateSymbol,
520
- Mt as default,
521
- pt as trasverseObjects,
522
- Se as useCamera,
523
- Ce as useCatalogue,
524
- Ee as useInstanceCreator,
525
- Ct as useLoader,
526
- mt as useRaycaster,
527
- re as useRenderLoop,
528
- dt as useRenderer,
529
- ft as useScene,
530
- Et as useTexture,
531
- T as useTres
440
+ Ne as CameraType,
441
+ lt as TresCanvas,
442
+ G as catalogue,
443
+ wt as default,
444
+ se as extend,
445
+ gt as isProd,
446
+ nt as trasverseObjects,
447
+ ce as useCamera,
448
+ dt as useLoader,
449
+ j as useLogger,
450
+ me as useRaycaster,
451
+ $ as useRenderLoop,
452
+ tt as useRenderer,
453
+ vt as useTexture,
454
+ k as useTres
532
455
  };