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