@tresjs/core 1.8.1 → 2.0.0-alpha.1

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