@tresjs/core 1.0.0 → 1.1.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.
@@ -1,6 +1,6 @@
1
- export declare function useCatalogue(): {
1
+ import { App, Ref } from 'vue';
2
+ import { TresCatalogue } from '../../types';
3
+ export declare function useCatalogue(app?: App, prefix?: string): {
2
4
  extend: (objects: any) => void;
3
- catalogue: {
4
- [key: string]: any;
5
- };
5
+ catalogue: Ref<TresCatalogue>;
6
6
  };
@@ -1,3 +1,7 @@
1
+ import { Ref } from 'vue';
2
+ import { TresCatalogue, TresInstance, TresVNode } from '../../types';
1
3
  export declare function useInstanceCreator(prefix: string): {
2
- createComponentInstances: (newObjects: Record<string, any>) => (string | import("vue").DefineComponent<{}, () => void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>)[][];
4
+ createComponentInstances: (catalogue: Ref<TresCatalogue>) => (string | import("vue").DefineComponent<{}, () => void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>)[][];
5
+ processProps: (props: Record<string, any>, instance: TresInstance) => void;
6
+ createInstanceFromVNode: (vnode: TresVNode, catalogue: Ref<TresCatalogue>) => TresInstance;
3
7
  };
package/dist/tres.js CHANGED
@@ -1,31 +1,31 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v1.0.0
3
+ * version: v1.1.0
4
4
  * (c) 2022
5
5
  * description: Declarative ThreeJS using Vue Components
6
6
  * author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
7
7
  */
8
- import { computed as D, watch as O, inject as X, defineComponent as _, shallowRef as j, reactive as fe, toRefs as me, ref as F, provide as A, onBeforeUnmount as de, h as J } from "vue";
9
- import { useWindowSize as Y, createEventHook as U, useRafFn as ge, useElementSize as he, useDevicePixelRatio as we, unrefElement as B, resolveUnref as S } from "@vueuse/core";
10
- import * as ve from "three";
11
- import { PerspectiveCamera as $, OrthographicCamera as Ce, Color as I, Vector3 as ye, Clock as Me, Scene as Se, LoadingManager as xe, TextureLoader as Ee, PCFShadowMap as Pe, LinearEncoding as Le, NoToneMapping as Te, WebGLRenderer as Re } from "three";
12
- var Oe = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Oe || {});
13
- const P = {
8
+ import { computed as D, watch as x, inject as X, ref as S, defineComponent as _, shallowRef as V, reactive as he, toRefs as we, provide as P, onBeforeUnmount as ve, h as J, watchEffect as Ce } from "vue";
9
+ import { useWindowSize as Y, createEventHook as j, useRafFn as ye, useElementSize as Me, useDevicePixelRatio as Se, unrefElement as I, resolveUnref as C } from "@vueuse/core";
10
+ import * as Ee from "three";
11
+ import { PerspectiveCamera as T, OrthographicCamera as Z, Color as $, Vector3 as xe, Clock as Pe, Scene as Te, LoadingManager as Le, TextureLoader as Re, PCFShadowMap as Oe, LinearEncoding as Ae, NoToneMapping as Be, WebGLRenderer as Ie } from "three";
12
+ var $e = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))($e || {});
13
+ const M = {
14
14
  cameras: []
15
- }, Ae = 45;
16
- let E;
17
- function Z() {
18
- const { width: e, height: t } = Y(), { setState: n } = oe();
19
- function a(i = "Perspective", f) {
20
- if (i === "Perspective") {
21
- const { near: u, far: m, fov: d } = f || {
15
+ }, be = 45;
16
+ let y;
17
+ function ee() {
18
+ const { width: e, height: t } = Y(), { setState: r } = ce();
19
+ function a(o = "Perspective", u) {
20
+ if (o === "Perspective") {
21
+ const { near: n, far: i, fov: p } = u || {
22
22
  near: 0.1,
23
23
  far: 1e3,
24
- fov: Ae
24
+ fov: be
25
25
  };
26
- E = new $(d, r.value, u, m), P.cameras.push(E);
26
+ y = new T(p, s.value, n, i), M.cameras.push(y);
27
27
  } else {
28
- const { left: u, right: m, top: d, bottom: w, near: C, far: x } = f || {
28
+ const { left: n, right: i, top: p, bottom: h, near: g, far: w } = u || {
29
29
  left: -100,
30
30
  right: 100,
31
31
  top: 100,
@@ -33,275 +33,289 @@ function Z() {
33
33
  near: 0.1,
34
34
  far: 1e3
35
35
  };
36
- E = new Ce(u, m, d, w, C, x), P.cameras.push(E);
36
+ y = new Z(n, i, p, h, g, w), M.cameras.push(y);
37
37
  }
38
- return P.cameras.push(E), E;
38
+ return M.cameras.push(y), y;
39
39
  }
40
- const r = D(() => e.value / t.value), o = D(() => P.cameras[0]);
41
- function s() {
42
- o.value instanceof $ && (o.value.aspect = r.value), o.value.updateProjectionMatrix();
40
+ const s = D(() => e.value / t.value), l = D(() => M.cameras[0]);
41
+ function f() {
42
+ l.value instanceof T && (l.value.aspect = s.value), l.value.updateProjectionMatrix();
43
43
  }
44
- function c(i) {
45
- const f = X("camera");
46
- i && f && (f.value = i, n("camera", f.value)), P.cameras.push(i), i instanceof $ && (i.aspect = r.value), i.updateProjectionMatrix();
44
+ function c(o) {
45
+ const u = X("camera");
46
+ o && u && (u.value = o, r("camera", u.value)), M.cameras.push(o), o instanceof T && (o.aspect = s.value), o.updateProjectionMatrix();
47
47
  }
48
- return O(r, s), {
49
- activeCamera: o,
48
+ return x(s, f), {
49
+ activeCamera: l,
50
50
  createCamera: a,
51
- updateCamera: s,
51
+ updateCamera: f,
52
52
  pushCamera: c
53
53
  };
54
54
  }
55
- let b = { ...ve };
56
- delete b.Scene;
57
- function be() {
55
+ const L = S({ ...Ee });
56
+ delete L.value.Scene;
57
+ let b;
58
+ function Fe(e, t = "Tres") {
59
+ !b && e && (b = e);
60
+ const { createComponentInstances: r } = te(t);
58
61
  return {
59
- extend: (t) => {
60
- b = Object.assign(b, t);
62
+ extend: (s) => {
63
+ L.value = Object.assign(L.value, s), r(S(s)).forEach(([f, c]) => {
64
+ b.component(f, c);
65
+ });
61
66
  },
62
- catalogue: b
67
+ catalogue: L
63
68
  };
64
69
  }
65
- const Be = (e) => typeof e < "u", V = (e) => !!e && e.constructor === Array;
66
- function $e(e) {
67
- return typeof e == "number" ? [e, e, e] : e instanceof ye ? [e.x, e.y, e.z] : e;
70
+ const F = (e) => typeof e < "u", ze = (e) => typeof e == "function", R = (e) => !!e && e.constructor === Array;
71
+ function De(e) {
72
+ return typeof e == "number" ? [e, e, e] : e instanceof xe ? [e.x, e.y, e.z] : e;
68
73
  }
69
- function q(e) {
70
- return e instanceof I ? e : Array.isArray(e) ? new I(...e) : new I(e);
74
+ function K(e) {
75
+ return e instanceof $ ? e : Array.isArray(e) ? new $(...e) : new $(e);
71
76
  }
72
- const K = "[TresJS \u25B2 \u25A0 \u25CF] ";
73
- function W() {
74
- function e(a, r) {
75
- console.error(`${K} ${a}`, r || "");
77
+ const q = "[TresJS \u25B2 \u25A0 \u25CF] ";
78
+ function U() {
79
+ function e(a, s) {
80
+ console.error(`${q} ${a}`, s || "");
76
81
  }
77
82
  function t(a) {
78
- console.warn(`${K} ${a}`);
83
+ console.warn(`${q} ${a}`);
79
84
  }
80
- function n(a, r) {
85
+ function r(a, s) {
81
86
  }
82
87
  return {
83
88
  logError: e,
84
89
  logWarning: t,
85
- logMessage: n
90
+ logMessage: r
86
91
  };
87
92
  }
88
- const Ie = ["rotation", "scale", "position"];
89
- function ze(e) {
90
- const { logMessage: t, logError: n } = W();
91
- function a(r) {
92
- return Object.entries(r).filter(([o, s]) => {
93
- var c, i;
94
- return (i = (c = s == null ? void 0 : s.prototype) == null ? void 0 : c.constructor) == null ? void 0 : i.toString().includes("class");
95
- }).map(([o, s]) => {
96
- const c = `${e}${o}`, i = _({
97
- name: c,
98
- setup(f, { slots: u, attrs: m, ...d }) {
99
- t(c, {
100
- props: f,
101
- slots: u,
102
- attrs: m,
103
- ctx: d
104
- });
105
- let w;
106
- const { scene: C } = ae(), { pushCamera: x } = Z();
107
- function L() {
108
- if ((u == null ? void 0 : u.default) && (u == null ? void 0 : u.default())) {
109
- const y = u.default().map((l) => {
110
- var h;
111
- let v;
112
- const g = l.type.name.replace(e, "");
113
- return (h = l == null ? void 0 : l.props) != null && h.args ? v = new r[g](...l.props.args) : v = new r[g](), l != null && l.props && T(l.props, v), v;
114
- });
115
- w = new s(...y);
116
- } else
117
- m.args ? w = new s(...m.args) : w = new s();
118
- T(m, w), c.includes("Camera") && x(w), w.isObject3D && (C == null || C.value.add(w)), t("Instance added", C), d.expose(w);
119
- }
120
- function T(y, l) {
121
- Object.entries(y).forEach(([v, g]) => {
122
- const h = v.replace(/(-\w)/g, (M) => M[1].toUpperCase());
123
- if (!(h === "args" || g === void 0)) {
124
- Ie.includes(v) && g && (g = $e(g));
125
- try {
126
- l[h] && Be(l[h].set) ? V(g) ? l[h].set(...g) : l[h].set(g) : (g === "" && (g = !0), l[h] = g);
127
- } catch (M) {
128
- n(`There was an error setting ${h} property`, M);
129
- }
130
- }
131
- }), y.ref && (y.ref = l);
93
+ const _e = ["rotation", "scale", "position"];
94
+ function te(e) {
95
+ const { logMessage: t, logError: r } = U();
96
+ function a(c, o) {
97
+ !F(c) || !F(o) || Object.entries(c).forEach(([u, n]) => {
98
+ const i = u.replace(/(-\w)/g, (p) => p[1].toUpperCase());
99
+ if (!(i === "args" || n === void 0)) {
100
+ _e.includes(i) && n && (n = De(n)), c.ref && (c.ref = o);
101
+ try {
102
+ if (o[i] && F(o[i].set))
103
+ o[i].set(...R(n) ? n : [n]);
104
+ else {
105
+ if (n === "" && (n = !0), ze(o[i])) {
106
+ o[i](...R(n) ? n : [n]);
107
+ return;
108
+ }
109
+ o[i] = n;
132
110
  }
133
- return L(), () => {
111
+ } catch (p) {
112
+ r(`There was an error setting ${i} property`, p);
113
+ }
114
+ }
115
+ });
116
+ }
117
+ function s(c, o) {
118
+ var i;
119
+ const u = c.type.name.replace(e, "");
120
+ let n;
121
+ return (i = c == null ? void 0 : c.props) != null && i.args ? n = new o.value[u](...c.props.args) : n = new o.value[u](), c != null && c.props && a(c.props, n), n;
122
+ }
123
+ function l(c, o, u, n) {
124
+ if (n.default && (n == null ? void 0 : n.default())) {
125
+ const i = n.default().map((p) => s(p, c));
126
+ return new o(...i);
127
+ } else
128
+ return u.args ? new o(...u.args) : new o();
129
+ }
130
+ function f(c) {
131
+ return Object.entries(c.value).filter(([o, u]) => {
132
+ var n, i;
133
+ return (i = (n = u == null ? void 0 : u.prototype) == null ? void 0 : n.constructor) == null ? void 0 : i.toString().includes("class");
134
+ }).map(([o, u]) => {
135
+ const n = `${e}${o}`, i = _({
136
+ name: n,
137
+ setup(p, { slots: h, attrs: g, ...w }) {
138
+ const { scene: v } = se(), { pushCamera: O } = ee(), d = l(c, u, g, h);
139
+ return a(g, d), (d instanceof T || d instanceof Z) && O(d), d.isObject3D && (v == null || v.value.add(d)), w.expose(d), t(n, {
140
+ props: p,
141
+ slots: h,
142
+ attrs: g,
143
+ ctx: w,
144
+ scene: v
145
+ }), () => {
134
146
  };
135
147
  }
136
148
  });
137
- return [c, i];
149
+ return [n, i];
138
150
  });
139
151
  }
140
152
  return {
141
- createComponentInstances: a
153
+ createComponentInstances: f,
154
+ processProps: a,
155
+ createInstanceFromVNode: s
142
156
  };
143
157
  }
144
- const ee = U(), te = U(), ne = U(), Q = new Me(), { pause: De, resume: Fe, isActive: _e } = ge(
158
+ const ne = j(), re = j(), oe = j(), Q = new Pe(), { pause: Ve, resume: je, isActive: Ue } = ye(
145
159
  () => {
146
160
  const e = Q.getElapsedTime(), t = Q.getDelta();
147
- ee.trigger({ delta: t, elapsed: e }), te.trigger({ delta: t, elapsed: e }), ne.trigger({ delta: t, elapsed: e });
161
+ ne.trigger({ delta: t, elapsed: e }), re.trigger({ delta: t, elapsed: e }), oe.trigger({ delta: t, elapsed: e });
148
162
  },
149
163
  { immediate: !1 }
150
164
  );
151
- function re() {
165
+ function ae() {
152
166
  return {
153
- onBeforeLoop: ee.on,
154
- onLoop: te.on,
155
- onAfterLoop: ne.on,
156
- pause: De,
157
- resume: Fe,
158
- isActive: _e
167
+ onBeforeLoop: ne.on,
168
+ onLoop: re.on,
169
+ onAfterLoop: oe.on,
170
+ pause: Ve,
171
+ resume: je,
172
+ isActive: Ue
159
173
  };
160
174
  }
161
- const je = j(new Se());
162
- function ae() {
175
+ const ke = V(new Te());
176
+ function se() {
163
177
  return {
164
- scene: je
178
+ scene: ke
165
179
  };
166
180
  }
167
- function Ue(e) {
181
+ function Ne(e) {
168
182
  const t = { nodes: {}, materials: {} };
169
- return e && e.traverse((n) => {
170
- n.name && (t.nodes[n.name] = n), n.material && !t.materials[n.material.name] && (t.materials[n.material.name] = n.material);
183
+ return e && e.traverse((r) => {
184
+ r.name && (t.nodes[r.name] = r), r.material && !t.materials[r.material.name] && (t.materials[r.material.name] = r.material);
171
185
  }), t;
172
186
  }
173
- async function Je(e, t, n, a, r) {
174
- const { logError: o } = W(), s = new e();
175
- r && r(s), n && n(e);
176
- const i = (Array.isArray(t) ? t : [t]).map(
177
- (f) => new Promise((u, m) => {
178
- s.load(
179
- f,
180
- (d) => {
181
- d.scene && Object.assign(d, Ue(d.scene)), u(d);
187
+ async function Qe(e, t, r, a, s) {
188
+ const { logError: l } = U(), f = new e();
189
+ s && s(f), r && r(e);
190
+ const o = (Array.isArray(t) ? t : [t]).map(
191
+ (u) => new Promise((n, i) => {
192
+ f.load(
193
+ u,
194
+ (p) => {
195
+ p.scene && Object.assign(p, Ne(p.scene)), n(p);
182
196
  },
183
197
  a,
184
- (d) => m(o("[useLoader] - Failed to load resource", d))
198
+ (p) => i(l("[useLoader] - Failed to load resource", p))
185
199
  );
186
200
  })
187
201
  );
188
- return V(t) ? await Promise.all(i) : await i[0];
202
+ return R(t) ? await Promise.all(o) : await o[0];
189
203
  }
190
- async function qe(e) {
191
- const t = new xe(), n = new Ee(t), a = (r) => new Promise((o, s) => {
192
- n.load(
193
- r,
194
- (c) => o(c),
204
+ async function Xe(e) {
205
+ const t = new Le(), r = new Re(t), a = (s) => new Promise((l, f) => {
206
+ r.load(
207
+ s,
208
+ (c) => l(c),
195
209
  () => null,
196
210
  () => {
197
- s(new Error("[useTextures] - Failed to load texture"));
211
+ f(new Error("[useTextures] - Failed to load texture"));
198
212
  }
199
213
  );
200
214
  });
201
- if (V(e)) {
202
- const r = await Promise.all(e.map((o) => a(o)));
203
- return e.length > 1 ? r : r[0];
215
+ if (R(e)) {
216
+ const s = await Promise.all(e.map((l) => a(l)));
217
+ return e.length > 1 ? s : s[0];
204
218
  } else {
205
- const { map: r, displacementMap: o, normalMap: s, roughnessMap: c, metalnessMap: i, aoMap: f } = e;
219
+ const { map: s, displacementMap: l, normalMap: f, roughnessMap: c, metalnessMap: o, aoMap: u } = e;
206
220
  return {
207
- map: r ? await a(r) : null,
208
- displacementMap: o ? await a(o) : null,
209
- normalMap: s ? await a(s) : null,
221
+ map: s ? await a(s) : null,
222
+ displacementMap: l ? await a(l) : null,
223
+ normalMap: f ? await a(f) : null,
210
224
  roughnessMap: c ? await a(c) : null,
211
- metalnessMap: i ? await a(i) : null,
212
- aoMap: f ? await a(f) : null
225
+ metalnessMap: o ? await a(o) : null,
226
+ aoMap: u ? await a(u) : null
213
227
  };
214
228
  }
215
229
  }
216
- const R = fe({});
217
- function oe() {
218
- function e(n) {
219
- return R[n];
230
+ const E = he({});
231
+ function ce() {
232
+ function e(r) {
233
+ return E[r];
220
234
  }
221
- function t(n, a) {
222
- R[n] = a;
235
+ function t(r, a) {
236
+ E[r] = a;
223
237
  }
224
238
  return {
225
- state: R,
226
- ...me(R),
239
+ state: E,
240
+ ...we(E),
227
241
  getState: e,
228
242
  setState: t
229
243
  };
230
244
  }
231
- const p = j(), z = F(!1);
232
- function Ve(e, t, n) {
245
+ const m = V(), z = S(!1);
246
+ function We(e, t, r) {
233
247
  const {
234
248
  alpha: a = !1,
235
- antialias: r,
236
- depth: o,
237
- logarithmicDepthBuffer: s,
249
+ antialias: s,
250
+ depth: l,
251
+ logarithmicDepthBuffer: f,
238
252
  failIfMajorPerformanceCaveat: c,
239
- precision: i,
240
- premultipliedAlpha: f,
241
- stencil: u,
242
- shadows: m = !1,
243
- shadowMapType: d = Pe,
244
- physicallyCorrectLights: w = !1,
245
- outputEncoding: C = Le,
246
- toneMapping: x = Te,
247
- toneMappingExposure: L = 1,
248
- context: T = void 0,
249
- powerPreference: y = "default",
250
- preserveDrawingBuffer: l = !1,
251
- clearColor: v = q("#000000"),
252
- windowSize: g = !1
253
- } = n, { width: h, height: M } = g ? Y() : he(t), { pixelRatio: k } = we(), { pause: se, resume: ie } = re(), ce = D(() => h.value / M.value), N = () => {
254
- !p.value || (p.value.setSize(h.value, M.value), p.value.setPixelRatio(k.value));
253
+ precision: o,
254
+ premultipliedAlpha: u,
255
+ stencil: n,
256
+ shadows: i = !1,
257
+ shadowMapType: p = Oe,
258
+ physicallyCorrectLights: h = !1,
259
+ outputEncoding: g = Ae,
260
+ toneMapping: w = Be,
261
+ toneMappingExposure: v = 1,
262
+ context: O = void 0,
263
+ powerPreference: d = "default",
264
+ preserveDrawingBuffer: ie = !1,
265
+ clearColor: k = K("#000000"),
266
+ windowSize: ue = !1
267
+ } = r, { width: A, height: B } = ue ? Y() : Me(t), { pixelRatio: N } = Se(), { pause: le, resume: pe } = ae(), fe = D(() => A.value / B.value), W = () => {
268
+ !m.value || (m.value.setSize(A.value, B.value), m.value.setPixelRatio(N.value));
255
269
  }, H = () => {
256
- !p.value || (p.value.shadowMap.enabled = S(m), p.value.outputEncoding = S(C), p.value.shadowMap.type = S(d), p.value.physicallyCorrectLights = S(w), p.value.toneMapping = S(x), p.value.toneMappingExposure = S(L), p.value.setClearColor(q(S(v))));
257
- }, ue = () => {
258
- const G = B(e);
259
- if (p.value || !G)
270
+ !m.value || (m.value.shadowMap.enabled = C(i), m.value.outputEncoding = C(g), m.value.shadowMap.type = C(p), m.value.physicallyCorrectLights = C(h), m.value.toneMapping = C(w), m.value.toneMappingExposure = C(v), m.value.setClearColor(K(C(k))));
271
+ }, me = () => {
272
+ const G = I(e);
273
+ if (m.value || !G)
260
274
  return;
261
- p.value = new Re({
275
+ m.value = new Ie({
262
276
  canvas: G,
263
277
  alpha: a,
264
- antialias: r,
265
- context: T,
266
- depth: o,
278
+ antialias: s,
279
+ context: O,
280
+ depth: l,
267
281
  failIfMajorPerformanceCaveat: c,
268
- logarithmicDepthBuffer: s,
269
- powerPreference: y,
270
- precision: i,
271
- stencil: u,
272
- preserveDrawingBuffer: l,
273
- premultipliedAlpha: f
282
+ logarithmicDepthBuffer: f,
283
+ powerPreference: d,
284
+ precision: o,
285
+ stencil: n,
286
+ preserveDrawingBuffer: ie,
287
+ premultipliedAlpha: u
274
288
  });
275
- const { setState: pe } = oe();
276
- pe("renderer", p.value), H(), N(), ie(), z.value = !0;
277
- }, le = () => {
278
- !p.value || (p.value.dispose(), p.value = void 0, z.value = !1, se());
289
+ const { setState: ge } = ce();
290
+ ge("renderer", m.value), H(), W(), pe(), z.value = !0;
291
+ }, de = () => {
292
+ !m.value || (m.value.dispose(), m.value = void 0, z.value = !1, le());
279
293
  };
280
- return O([h, M, k], N), O(
294
+ return x([A, B, N], W), x(
281
295
  () => [
282
- m,
283
- d,
284
- C,
296
+ i,
297
+ p,
298
+ g,
299
+ h,
285
300
  w,
286
- x,
287
- L,
288
- v
301
+ v,
302
+ k
289
303
  ],
290
304
  H
291
- ), O(
305
+ ), x(
292
306
  () => [e, t],
293
307
  () => {
294
- B(e) && B(t) && ue();
308
+ I(e) && I(t) && me();
295
309
  },
296
310
  { immediate: !0, deep: !0 }
297
311
  ), {
298
- renderer: p,
312
+ renderer: m,
299
313
  isReady: z,
300
- dispose: le,
301
- aspectRatio: ce
314
+ dispose: de,
315
+ aspectRatio: fe
302
316
  };
303
317
  }
304
- const We = _({
318
+ const He = _({
305
319
  name: "TresCanvas",
306
320
  props: {
307
321
  shadows: Boolean,
@@ -316,27 +330,27 @@ const We = _({
316
330
  clearColor: String,
317
331
  windowSize: Boolean
318
332
  },
319
- setup(e, { slots: t, attrs: n }) {
320
- const { logError: a } = W(), r = F(), o = F(), { renderer: s, dispose: c, aspectRatio: i } = Ve(r, o, e), f = j();
321
- return A("camera", f), A("renderer", s), A("aspect-ratio", i), t.default && !t.default().some((u) => u.type.name === "Scene") && a("TresCanvas must contain a Scene component."), t.default && !t.default().some((u) => {
322
- var m;
323
- return (m = u.type.name) == null ? void 0 : m.includes("Camera");
324
- }) && a("Scene must contain a Camera component."), de(() => c()), () => {
333
+ setup(e, { slots: t, attrs: r }) {
334
+ const { logError: a } = U(), s = S(), l = S(), { renderer: f, dispose: c, aspectRatio: o } = We(s, l, e), u = V();
335
+ return P("camera", u), P("renderer", f), P("aspect-ratio", o), t.default && !t.default().some((n) => n.type.name === "Scene") && a("TresCanvas must contain a Scene component."), t.default && !t.default().some((n) => {
336
+ var i;
337
+ return (i = n.type.name) == null ? void 0 : i.includes("Camera");
338
+ }) && a("Scene must contain a Camera component."), ve(() => c()), () => {
325
339
  if (t.default)
326
340
  return J(
327
341
  "div",
328
342
  {
329
- ref: o,
343
+ ref: l,
330
344
  style: {
331
345
  position: "relative",
332
346
  width: "100%",
333
347
  height: "100vh",
334
- ...n.style
348
+ ...r.style
335
349
  }
336
350
  },
337
351
  [
338
352
  J("canvas", {
339
- ref: r,
353
+ ref: s,
340
354
  style: { width: "100%", height: "100%", position: "absolute", top: 0, left: 0 }
341
355
  }),
342
356
  t.default()
@@ -344,39 +358,41 @@ const We = _({
344
358
  );
345
359
  };
346
360
  }
347
- }), ke = _({
361
+ }), Ge = _({
348
362
  name: "Scene",
349
363
  setup(e, { slots: t }) {
350
- const { scene: n } = ae(), a = X("renderer"), { activeCamera: r } = Z(), { onLoop: o } = re();
351
- return A("local-scene", n), o(() => {
352
- (a == null ? void 0 : a.value) && (r == null ? void 0 : r.value) && (n == null ? void 0 : n.value) && a.value.render(n == null ? void 0 : n.value, r.value);
364
+ const { scene: r } = se(), a = X("renderer"), { activeCamera: s } = ee(), { onLoop: l } = ae();
365
+ return P("local-scene", r), l(() => {
366
+ (a == null ? void 0 : a.value) && (s == null ? void 0 : s.value) && (r == null ? void 0 : r.value) && a.value.render(r == null ? void 0 : r.value, s.value);
353
367
  }), () => {
354
368
  if (t.default)
355
369
  return t.default();
356
370
  };
357
371
  }
358
- }), Ke = Symbol("UseTresState"), Qe = {
372
+ }), Ye = Symbol("UseTresState"), Ze = {
359
373
  install(e, t) {
360
- const n = (t == null ? void 0 : t.prefix) || "Tres";
361
- e.component(`${n}Canvas`, We), e.component(`${n}Scene`, ke);
362
- const { catalogue: a } = be(), { createComponentInstances: r } = ze(n);
363
- r(t != null && t.extends ? { ...a, ...t.extends } : a).forEach(([s, c]) => {
364
- e.component(s, c);
374
+ const r = (t == null ? void 0 : t.prefix) || "Tres";
375
+ e.component(`${r}Canvas`, He), e.component(`${r}Scene`, Ge);
376
+ const { catalogue: a } = Fe(e, r), { createComponentInstances: s } = te(r);
377
+ s(a).forEach(([f, c]) => {
378
+ e.component(f, c);
379
+ }), Ce(() => {
380
+ console.log({ catalogue: a });
365
381
  });
366
382
  }
367
383
  };
368
384
  export {
369
- Oe as CameraType,
370
- Ke as UseTresStateSymbol,
371
- Qe as default,
372
- Ue as trasverseObjects,
373
- Z as useCamera,
374
- be as useCatalogue,
375
- ze as useInstanceCreator,
376
- Je as useLoader,
377
- re as useRenderLoop,
378
- Ve as useRenderer,
379
- ae as useScene,
380
- qe as useTexture,
381
- oe as useTres
385
+ $e as CameraType,
386
+ Ye as UseTresStateSymbol,
387
+ Ze as default,
388
+ Ne as trasverseObjects,
389
+ ee as useCamera,
390
+ Fe as useCatalogue,
391
+ te as useInstanceCreator,
392
+ Qe as useLoader,
393
+ ae as useRenderLoop,
394
+ We as useRenderer,
395
+ se as useScene,
396
+ Xe as useTexture,
397
+ ce as useTres
382
398
  };
package/dist/tres.umd.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v1.0.0
3
+ * version: v1.1.0
4
4
  * (c) 2022
5
5
  * description: Declarative ThreeJS using Vue Components
6
6
  * author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
7
7
  */
8
- (function(u,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue"),require("@vueuse/core"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","three"],o):(u=typeof globalThis<"u"?globalThis:u||self,o(u.tres={},u.Vue,u.VueUseCore,u.Three))})(this,function(u,o,p,g){"use strict";function te(e){if(e&&e.__esModule)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ne=te(g);var V=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(V||{});const j={cameras:[]},re=45;let b;function z(){const{width:e,height:t}=p.useWindowSize(),{setState:n}=F();function r(c="Perspective",h){if(c==="Perspective"){const{near:f,far:w,fov:C}=h||{near:.1,far:1e3,fov:re};b=new g.PerspectiveCamera(C,a.value,f,w),j.cameras.push(b)}else{const{left:f,right:w,top:C,bottom:M,near:P,far:x}=h||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};b=new g.OrthographicCamera(f,w,C,M,P,x),j.cameras.push(b)}return j.cameras.push(b),b}const a=o.computed(()=>e.value/t.value),s=o.computed(()=>j.cameras[0]);function i(){s.value instanceof g.PerspectiveCamera&&(s.value.aspect=a.value),s.value.updateProjectionMatrix()}function l(c){const h=o.inject("camera");c&&h&&(h.value=c,n("camera",h.value)),j.cameras.push(c),c instanceof g.PerspectiveCamera&&(c.aspect=a.value),c.updateProjectionMatrix()}return o.watch(a,i),{activeCamera:s,createCamera:r,updateCamera:i,pushCamera:l}}let _={...ne};delete _.Scene;function k(){return{extend:t=>{_=Object.assign(_,t)},catalogue:_}}const ae=e=>typeof e<"u",B=e=>!!e&&e.constructor===Array;function oe(e){return typeof e=="number"?[e,e,e]:e instanceof g.Vector3?[e.x,e.y,e.z]:e}function W(e){return e instanceof g.Color?e:Array.isArray(e)?new g.Color(...e):new g.Color(e)}const N="[TresJS \u25B2 \u25A0 \u25CF] ";function I(){function e(r,a){console.error(`${N} ${r}`,a||"")}function t(r){console.warn(`${N} ${r}`)}function n(r,a){}return{logError:e,logWarning:t,logMessage:n}}const se=["rotation","scale","position"];function q(e){const{logMessage:t,logError:n}=I();function r(a){return Object.entries(a).filter(([s,i])=>{var l,c;return(c=(l=i==null?void 0:i.prototype)==null?void 0:l.constructor)==null?void 0:c.toString().includes("class")}).map(([s,i])=>{const l=`${e}${s}`,c=o.defineComponent({name:l,setup(h,{slots:f,attrs:w,...C}){t(l,{props:h,slots:f,attrs:w,ctx:C});let M;const{scene:P}=D(),{pushCamera:x}=z();function U(){if((f==null?void 0:f.default)&&(f==null?void 0:f.default())){const O=f.default().map(m=>{var S;let v;const y=m.type.name.replace(e,"");return(S=m==null?void 0:m.props)!=null&&S.args?v=new a[y](...m.props.args):v=new a[y],m!=null&&m.props&&A(m.props,v),v});M=new i(...O)}else w.args?M=new i(...w.args):M=new i;A(w,M),l.includes("Camera")&&x(M),M.isObject3D&&(P==null||P.value.add(M)),t("Instance added",P),C.expose(M)}function A(O,m){Object.entries(O).forEach(([v,y])=>{const S=v.replace(/(-\w)/g,L=>L[1].toUpperCase());if(!(S==="args"||y===void 0)){se.includes(v)&&y&&(y=oe(y));try{m[S]&&ae(m[S].set)?B(y)?m[S].set(...y):m[S].set(y):(y===""&&(y=!0),m[S]=y)}catch(L){n(`There was an error setting ${S} property`,L)}}}),O.ref&&(O.ref=m)}return U(),()=>{}}});return[l,c]})}return{createComponentInstances:r}}const G=p.createEventHook(),J=p.createEventHook(),K=p.createEventHook(),Q=new g.Clock,{pause:ie,resume:ce,isActive:ue}=p.useRafFn(()=>{const e=Q.getElapsedTime(),t=Q.getDelta();G.trigger({delta:t,elapsed:e}),J.trigger({delta:t,elapsed:e}),K.trigger({delta:t,elapsed:e})},{immediate:!1});function $(){return{onBeforeLoop:G.on,onLoop:J.on,onAfterLoop:K.on,pause:ie,resume:ce,isActive:ue}}const le=o.shallowRef(new g.Scene);function D(){return{scene:le}}function X(e){const t={nodes:{},materials:{}};return e&&e.traverse(n=>{n.name&&(t.nodes[n.name]=n),n.material&&!t.materials[n.material.name]&&(t.materials[n.material.name]=n.material)}),t}async function fe(e,t,n,r,a){const{logError:s}=I(),i=new e;a&&a(i),n&&n(e);const c=(Array.isArray(t)?t:[t]).map(h=>new Promise((f,w)=>{i.load(h,C=>{C.scene&&Object.assign(C,X(C.scene)),f(C)},r,C=>w(s("[useLoader] - Failed to load resource",C)))}));return B(t)?await Promise.all(c):await c[0]}async function pe(e){const t=new g.LoadingManager,n=new g.TextureLoader(t),r=a=>new Promise((s,i)=>{n.load(a,l=>s(l),()=>null,()=>{i(new Error("[useTextures] - Failed to load texture"))})});if(B(e)){const a=await Promise.all(e.map(s=>r(s)));return e.length>1?a:a[0]}else{const{map:a,displacementMap:s,normalMap:i,roughnessMap:l,metalnessMap:c,aoMap:h}=e;return{map:a?await r(a):null,displacementMap:s?await r(s):null,normalMap:i?await r(i):null,roughnessMap:l?await r(l):null,metalnessMap:c?await r(c):null,aoMap:h?await r(h):null}}}const T=o.reactive({});function F(){function e(n){return T[n]}function t(n,r){T[n]=r}return{state:T,...o.toRefs(T),getState:e,setState:t}}const d=o.shallowRef(),R=o.ref(!1);function Y(e,t,n){const{alpha:r=!1,antialias:a,depth:s,logarithmicDepthBuffer:i,failIfMajorPerformanceCaveat:l,precision:c,premultipliedAlpha:h,stencil:f,shadows:w=!1,shadowMapType:C=g.PCFShadowMap,physicallyCorrectLights:M=!1,outputEncoding:P=g.LinearEncoding,toneMapping:x=g.NoToneMapping,toneMappingExposure:U=1,context:A=void 0,powerPreference:O="default",preserveDrawingBuffer:m=!1,clearColor:v=W("#000000"),windowSize:y=!1}=n,{width:S,height:L}=y?p.useWindowSize():p.useElementSize(t),{pixelRatio:Z}=p.useDevicePixelRatio(),{pause:we,resume:Ce}=$(),ye=o.computed(()=>S.value/L.value),E=()=>{!d.value||(d.value.setSize(S.value,L.value),d.value.setPixelRatio(Z.value))},H=()=>{!d.value||(d.value.shadowMap.enabled=p.resolveUnref(w),d.value.outputEncoding=p.resolveUnref(P),d.value.shadowMap.type=p.resolveUnref(C),d.value.physicallyCorrectLights=p.resolveUnref(M),d.value.toneMapping=p.resolveUnref(x),d.value.toneMappingExposure=p.resolveUnref(U),d.value.setClearColor(W(p.resolveUnref(v))))},Se=()=>{const ee=p.unrefElement(e);if(d.value||!ee)return;d.value=new g.WebGLRenderer({canvas:ee,alpha:r,antialias:a,context:A,depth:s,failIfMajorPerformanceCaveat:l,logarithmicDepthBuffer:i,powerPreference:O,precision:c,stencil:f,preserveDrawingBuffer:m,premultipliedAlpha:h});const{setState:ve}=F();ve("renderer",d.value),H(),E(),Ce(),R.value=!0},Me=()=>{!d.value||(d.value.dispose(),d.value=void 0,R.value=!1,we())};return o.watch([S,L,Z],E),o.watch(()=>[w,C,P,M,x,U,v],H),o.watch(()=>[e,t],()=>{p.unrefElement(e)&&p.unrefElement(t)&&Se()},{immediate:!0,deep:!0}),{renderer:d,isReady:R,dispose:Me,aspectRatio:ye}}const de=o.defineComponent({name:"TresCanvas",props:{shadows:Boolean,shadowMapType:Object,physicallyCorrectLights:Boolean,outputEncoding:Object,toneMapping:Object,toneMappingExposure:Number,context:Object,powerPreference:Object,preserveDrawingBuffer:Boolean,clearColor:String,windowSize:Boolean},setup(e,{slots:t,attrs:n}){const{logError:r}=I(),a=o.ref(),s=o.ref(),{renderer:i,dispose:l,aspectRatio:c}=Y(a,s,e),h=o.shallowRef();return o.provide("camera",h),o.provide("renderer",i),o.provide("aspect-ratio",c),t.default&&!t.default().some(f=>f.type.name==="Scene")&&r("TresCanvas must contain a Scene component."),t.default&&!t.default().some(f=>{var w;return(w=f.type.name)==null?void 0:w.includes("Camera")})&&r("Scene must contain a Camera component."),o.onBeforeUnmount(()=>l()),()=>{if(t.default)return o.h("div",{ref:s,style:{position:"relative",width:"100%",height:"100vh",...n.style}},[o.h("canvas",{ref:a,style:{width:"100%",height:"100%",position:"absolute",top:0,left:0}}),t.default()])}}}),me=o.defineComponent({name:"Scene",setup(e,{slots:t}){const{scene:n}=D(),r=o.inject("renderer"),{activeCamera:a}=z(),{onLoop:s}=$();return o.provide("local-scene",n),s(()=>{(r==null?void 0:r.value)&&(a==null?void 0:a.value)&&(n==null?void 0:n.value)&&r.value.render(n==null?void 0:n.value,a.value)}),()=>{if(t.default)return t.default()}}}),ge=Symbol("UseTresState"),he={install(e,t){const n=(t==null?void 0:t.prefix)||"Tres";e.component(`${n}Canvas`,de),e.component(`${n}Scene`,me);const{catalogue:r}=k(),{createComponentInstances:a}=q(n);a(t!=null&&t.extends?{...r,...t.extends}:r).forEach(([i,l])=>{e.component(i,l)})}};u.CameraType=V,u.UseTresStateSymbol=ge,u.default=he,u.trasverseObjects=X,u.useCamera=z,u.useCatalogue=k,u.useInstanceCreator=q,u.useLoader=fe,u.useRenderLoop=$,u.useRenderer=Y,u.useScene=D,u.useTexture=pe,u.useTres=F,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
8
+ (function(p,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue"),require("@vueuse/core"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","three"],c):(p=typeof globalThis<"u"?globalThis:p||self,c(p.tres={},p.Vue,p.VueUseCore,p.Three))})(this,function(p,c,h,g){"use strict";function te(e){if(e&&e.__esModule)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ne=te(g);var k=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(k||{});const O={cameras:[]},re=45;let P;function j(){const{width:e,height:t}=h.useWindowSize(),{setState:n}=B();function a(o="Perspective",l){if(o==="Perspective"){const{near:r,far:u,fov:m}=l||{near:.1,far:1e3,fov:re};P=new g.PerspectiveCamera(m,s.value,r,u),O.cameras.push(P)}else{const{left:r,right:u,top:m,bottom:S,near:y,far:v}=l||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};P=new g.OrthographicCamera(r,u,m,S,y,v),O.cameras.push(P)}return O.cameras.push(P),P}const s=c.computed(()=>e.value/t.value),f=c.computed(()=>O.cameras[0]);function d(){f.value instanceof g.PerspectiveCamera&&(f.value.aspect=s.value),f.value.updateProjectionMatrix()}function i(o){const l=c.inject("camera");o&&l&&(l.value=o,n("camera",l.value)),O.cameras.push(o),o instanceof g.PerspectiveCamera&&(o.aspect=s.value),o.updateProjectionMatrix()}return c.watch(s,d),{activeCamera:f,createCamera:a,updateCamera:d,pushCamera:i}}const L=c.ref({...ne});delete L.value.Scene;let x;function N(e,t="Tres"){!x&&e&&(x=e);const{createComponentInstances:n}=I(t);return{extend:s=>{L.value=Object.assign(L.value,s),n(c.ref(s)).forEach(([d,i])=>{x.component(d,i)})},catalogue:L}}const A=e=>typeof e<"u",ae=e=>typeof e=="function",b=e=>!!e&&e.constructor===Array;function oe(e){return typeof e=="number"?[e,e,e]:e instanceof g.Vector3?[e.x,e.y,e.z]:e}function R(e){return e instanceof g.Color?e:Array.isArray(e)?new g.Color(...e):new g.Color(e)}const W="[TresJS \u25B2 \u25A0 \u25CF] ";function U(){function e(a,s){console.error(`${W} ${a}`,s||"")}function t(a){console.warn(`${W} ${a}`)}function n(a,s){}return{logError:e,logWarning:t,logMessage:n}}const se=["rotation","scale","position"];function I(e){const{logMessage:t,logError:n}=U();function a(i,o){!A(i)||!A(o)||Object.entries(i).forEach(([l,r])=>{const u=l.replace(/(-\w)/g,m=>m[1].toUpperCase());if(!(u==="args"||r===void 0)){se.includes(u)&&r&&(r=oe(r)),i.ref&&(i.ref=o);try{if(o[u]&&A(o[u].set))o[u].set(...b(r)?r:[r]);else{if(r===""&&(r=!0),ae(o[u])){o[u](...b(r)?r:[r]);return}o[u]=r}}catch(m){n(`There was an error setting ${u} property`,m)}}})}function s(i,o){var u;const l=i.type.name.replace(e,"");let r;return(u=i==null?void 0:i.props)!=null&&u.args?r=new o.value[l](...i.props.args):r=new o.value[l],i!=null&&i.props&&a(i.props,r),r}function f(i,o,l,r){if(r.default&&(r==null?void 0:r.default())){const u=r.default().map(m=>s(m,i));return new o(...u)}else return l.args?new o(...l.args):new o}function d(i){return Object.entries(i.value).filter(([o,l])=>{var r,u;return(u=(r=l==null?void 0:l.prototype)==null?void 0:r.constructor)==null?void 0:u.toString().includes("class")}).map(([o,l])=>{const r=`${e}${o}`,u=c.defineComponent({name:r,setup(m,{slots:S,attrs:y,...v}){const{scene:M}=z(),{pushCamera:$}=j(),C=f(i,l,y,S);return a(y,C),(C instanceof g.PerspectiveCamera||C instanceof g.OrthographicCamera)&&$(C),C.isObject3D&&(M==null||M.value.add(C)),v.expose(C),t(r,{props:m,slots:S,attrs:y,ctx:v,scene:M}),()=>{}}});return[r,u]})}return{createComponentInstances:d,processProps:a,createInstanceFromVNode:s}}const q=h.createEventHook(),G=h.createEventHook(),J=h.createEventHook(),K=new g.Clock,{pause:ie,resume:ce,isActive:ue}=h.useRafFn(()=>{const e=K.getElapsedTime(),t=K.getDelta();q.trigger({delta:t,elapsed:e}),G.trigger({delta:t,elapsed:e}),J.trigger({delta:t,elapsed:e})},{immediate:!1});function T(){return{onBeforeLoop:q.on,onLoop:G.on,onAfterLoop:J.on,pause:ie,resume:ce,isActive:ue}}const le=c.shallowRef(new g.Scene);function z(){return{scene:le}}function Q(e){const t={nodes:{},materials:{}};return e&&e.traverse(n=>{n.name&&(t.nodes[n.name]=n),n.material&&!t.materials[n.material.name]&&(t.materials[n.material.name]=n.material)}),t}async function fe(e,t,n,a,s){const{logError:f}=U(),d=new e;s&&s(d),n&&n(e);const o=(Array.isArray(t)?t:[t]).map(l=>new Promise((r,u)=>{d.load(l,m=>{m.scene&&Object.assign(m,Q(m.scene)),r(m)},a,m=>u(f("[useLoader] - Failed to load resource",m)))}));return b(t)?await Promise.all(o):await o[0]}async function pe(e){const t=new g.LoadingManager,n=new g.TextureLoader(t),a=s=>new Promise((f,d)=>{n.load(s,i=>f(i),()=>null,()=>{d(new Error("[useTextures] - Failed to load texture"))})});if(b(e)){const s=await Promise.all(e.map(f=>a(f)));return e.length>1?s:s[0]}else{const{map:s,displacementMap:f,normalMap:d,roughnessMap:i,metalnessMap:o,aoMap:l}=e;return{map:s?await a(s):null,displacementMap:f?await a(f):null,normalMap:d?await a(d):null,roughnessMap:i?await a(i):null,metalnessMap:o?await a(o):null,aoMap:l?await a(l):null}}}const _=c.reactive({});function B(){function e(n){return _[n]}function t(n,a){_[n]=a}return{state:_,...c.toRefs(_),getState:e,setState:t}}const w=c.shallowRef(),F=c.ref(!1);function X(e,t,n){const{alpha:a=!1,antialias:s,depth:f,logarithmicDepthBuffer:d,failIfMajorPerformanceCaveat:i,precision:o,premultipliedAlpha:l,stencil:r,shadows:u=!1,shadowMapType:m=g.PCFShadowMap,physicallyCorrectLights:S=!1,outputEncoding:y=g.LinearEncoding,toneMapping:v=g.NoToneMapping,toneMappingExposure:M=1,context:$=void 0,powerPreference:C="default",preserveDrawingBuffer:we=!1,clearColor:Y=R("#000000"),windowSize:Ce=!1}=n,{width:D,height:V}=Ce?h.useWindowSize():h.useElementSize(t),{pixelRatio:Z}=h.useDevicePixelRatio(),{pause:ye,resume:Se}=T(),ve=c.computed(()=>D.value/V.value),E=()=>{!w.value||(w.value.setSize(D.value,V.value),w.value.setPixelRatio(Z.value))},H=()=>{!w.value||(w.value.shadowMap.enabled=h.resolveUnref(u),w.value.outputEncoding=h.resolveUnref(y),w.value.shadowMap.type=h.resolveUnref(m),w.value.physicallyCorrectLights=h.resolveUnref(S),w.value.toneMapping=h.resolveUnref(v),w.value.toneMappingExposure=h.resolveUnref(M),w.value.setClearColor(R(h.resolveUnref(Y))))},Me=()=>{const ee=h.unrefElement(e);if(w.value||!ee)return;w.value=new g.WebGLRenderer({canvas:ee,alpha:a,antialias:s,context:$,depth:f,failIfMajorPerformanceCaveat:i,logarithmicDepthBuffer:d,powerPreference:C,precision:o,stencil:r,preserveDrawingBuffer:we,premultipliedAlpha:l});const{setState:Oe}=B();Oe("renderer",w.value),H(),E(),Se(),F.value=!0},Pe=()=>{!w.value||(w.value.dispose(),w.value=void 0,F.value=!1,ye())};return c.watch([D,V,Z],E),c.watch(()=>[u,m,y,S,v,M,Y],H),c.watch(()=>[e,t],()=>{h.unrefElement(e)&&h.unrefElement(t)&&Me()},{immediate:!0,deep:!0}),{renderer:w,isReady:F,dispose:Pe,aspectRatio:ve}}const me=c.defineComponent({name:"TresCanvas",props:{shadows:Boolean,shadowMapType:Object,physicallyCorrectLights:Boolean,outputEncoding:Object,toneMapping:Object,toneMappingExposure:Number,context:Object,powerPreference:Object,preserveDrawingBuffer:Boolean,clearColor:String,windowSize:Boolean},setup(e,{slots:t,attrs:n}){const{logError:a}=U(),s=c.ref(),f=c.ref(),{renderer:d,dispose:i,aspectRatio:o}=X(s,f,e),l=c.shallowRef();return c.provide("camera",l),c.provide("renderer",d),c.provide("aspect-ratio",o),t.default&&!t.default().some(r=>r.type.name==="Scene")&&a("TresCanvas must contain a Scene component."),t.default&&!t.default().some(r=>{var u;return(u=r.type.name)==null?void 0:u.includes("Camera")})&&a("Scene must contain a Camera component."),c.onBeforeUnmount(()=>i()),()=>{if(t.default)return c.h("div",{ref:f,style:{position:"relative",width:"100%",height:"100vh",...n.style}},[c.h("canvas",{ref:s,style:{width:"100%",height:"100%",position:"absolute",top:0,left:0}}),t.default()])}}}),de=c.defineComponent({name:"Scene",setup(e,{slots:t}){const{scene:n}=z(),a=c.inject("renderer"),{activeCamera:s}=j(),{onLoop:f}=T();return c.provide("local-scene",n),f(()=>{(a==null?void 0:a.value)&&(s==null?void 0:s.value)&&(n==null?void 0:n.value)&&a.value.render(n==null?void 0:n.value,s.value)}),()=>{if(t.default)return t.default()}}}),ge=Symbol("UseTresState"),he={install(e,t){const n=(t==null?void 0:t.prefix)||"Tres";e.component(`${n}Canvas`,me),e.component(`${n}Scene`,de);const{catalogue:a}=N(e,n),{createComponentInstances:s}=I(n);s(a).forEach(([d,i])=>{e.component(d,i)}),c.watchEffect(()=>{console.log({catalogue:a})})}};p.CameraType=k,p.UseTresStateSymbol=ge,p.default=he,p.trasverseObjects=Q,p.useCamera=j,p.useCatalogue=N,p.useInstanceCreator=I,p.useLoader=fe,p.useRenderLoop=T,p.useRenderer=X,p.useScene=z,p.useTexture=pe,p.useTres=B,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -3,9 +3,11 @@ import { VNode, VNodeTypes } from 'vue'
3
3
 
4
4
  export type TresInstance = Object3D<Event> & { [key: string]: any }
5
5
 
6
+ export type TresCatalogue = Record<string, any>
6
7
  export type TresVNodeType = VNodeTypes & {
7
8
  name?: string | Array<string>
8
9
  __name?: string
9
10
  setup?: (props: Readonly<any>) => void
10
11
  }
11
12
  export type TresVNode = VNode & { children?: Array<VNode>; type: TresVNodeType }
13
+ export type TresAttributes = Record<string, any> & { args?: number[] }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tresjs/core",
3
3
  "description": "Declarative ThreeJS using Vue Components",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "type": "module",
6
6
  "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
7
7
  "files": [