@tresjs/core 1.5.0 → 1.5.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/core/useRenderLoop/index.d.ts +2 -0
- package/dist/tres.js +189 -185
- package/dist/tres.umd.cjs +2 -2
- package/dist/types/index.d.ts +1 -1
- package/package.json +5 -10
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { EventHookOn, Fn } from '@vueuse/core';
|
|
2
2
|
import { Ref } from 'vue';
|
|
3
|
+
import { Clock } from 'three';
|
|
3
4
|
export interface RenderLoop {
|
|
4
5
|
delta: number;
|
|
5
6
|
elapsed: number;
|
|
7
|
+
clock: Clock;
|
|
6
8
|
}
|
|
7
9
|
export interface UseRenderLoopReturn {
|
|
8
10
|
onBeforeLoop: EventHookOn<RenderLoop>;
|
package/dist/tres.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v1.5.
|
|
3
|
+
* version: v1.5.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 M, computed as
|
|
9
|
-
import { createEventHook as
|
|
10
|
-
import * as
|
|
11
|
-
import { PerspectiveCamera as
|
|
12
|
-
var
|
|
8
|
+
import { inject as M, computed as se, watch as $, ref as B, defineComponent as N, shallowRef as W, reactive as xe, toRefs as ie, provide as I, onBeforeUnmount as Me, h as te } from "vue";
|
|
9
|
+
import { createEventHook as G, useRafFn as Ee, resolveUnref as d, useWindowSize as Pe, useElementSize as Te, useDevicePixelRatio as Le, unrefElement as k } from "@vueuse/core";
|
|
10
|
+
import * as ne from "three";
|
|
11
|
+
import { PerspectiveCamera as _, OrthographicCamera as ce, Vector3 as Re, Color as V, BufferAttribute as Ae, Clock as ue, Scene as be, LoadingManager as Be, TextureLoader as Oe, PCFShadowMap as $e, LinearEncoding as re, NoToneMapping as ae, WebGLRenderer as Ie } from "three";
|
|
12
|
+
var _e = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(_e || {});
|
|
13
13
|
const T = {
|
|
14
14
|
cameras: []
|
|
15
|
-
},
|
|
15
|
+
}, De = 45;
|
|
16
16
|
let x;
|
|
17
|
-
function
|
|
18
|
-
const e = M("aspect-ratio"), { setState:
|
|
19
|
-
function
|
|
20
|
-
if (
|
|
21
|
-
const { near: t, far: c, fov:
|
|
17
|
+
function le() {
|
|
18
|
+
const e = M("aspect-ratio"), { setState: r } = we();
|
|
19
|
+
function n(u = "Perspective", m) {
|
|
20
|
+
if (u === "Perspective") {
|
|
21
|
+
const { near: t, far: c, fov: l } = m || {
|
|
22
22
|
near: 0.1,
|
|
23
23
|
far: 1e3,
|
|
24
|
-
fov:
|
|
24
|
+
fov: De
|
|
25
25
|
};
|
|
26
|
-
x = new
|
|
26
|
+
x = new _(l, (e == null ? void 0 : e.value) || 1, t, c), T.cameras.push(x);
|
|
27
27
|
} else {
|
|
28
|
-
const { left: t, right: c, top:
|
|
28
|
+
const { left: t, right: c, top: l, bottom: a, near: s, far: p } = m || {
|
|
29
29
|
left: -100,
|
|
30
30
|
right: 100,
|
|
31
31
|
top: 100,
|
|
@@ -33,124 +33,124 @@ function oe() {
|
|
|
33
33
|
near: 0.1,
|
|
34
34
|
far: 1e3
|
|
35
35
|
};
|
|
36
|
-
x = new
|
|
36
|
+
x = new ce(t, c, l, a, s, p), T.cameras.push(x);
|
|
37
37
|
}
|
|
38
38
|
return T.cameras.push(x), x;
|
|
39
39
|
}
|
|
40
|
-
const o =
|
|
40
|
+
const o = se(() => T.cameras[0]);
|
|
41
41
|
function i() {
|
|
42
|
-
o.value instanceof
|
|
42
|
+
o.value instanceof _ && e && (o.value.aspect = e.value), o.value.updateProjectionMatrix();
|
|
43
43
|
}
|
|
44
|
-
function f(
|
|
44
|
+
function f(u) {
|
|
45
45
|
const m = M("camera");
|
|
46
|
-
|
|
46
|
+
u && m && (m.value = u, r("camera", m.value)), T.cameras.push(u), u instanceof _ && e && (u.aspect = e.value), u.updateProjectionMatrix();
|
|
47
47
|
}
|
|
48
|
-
return e &&
|
|
48
|
+
return e && $(e, i), {
|
|
49
49
|
activeCamera: o,
|
|
50
|
-
createCamera:
|
|
50
|
+
createCamera: n,
|
|
51
51
|
updateCamera: i,
|
|
52
52
|
pushCamera: f
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
const
|
|
56
|
-
function
|
|
55
|
+
const oe = "[TresJS ▲ ■ ●] ";
|
|
56
|
+
function U() {
|
|
57
57
|
function e(o, i) {
|
|
58
|
-
console.error(`${
|
|
58
|
+
console.error(`${oe} ${o}`, i || "");
|
|
59
59
|
}
|
|
60
|
-
function
|
|
61
|
-
console.warn(`${
|
|
60
|
+
function r(o) {
|
|
61
|
+
console.warn(`${oe} ${o}`);
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function n(o, i) {
|
|
64
64
|
}
|
|
65
65
|
return {
|
|
66
66
|
logError: e,
|
|
67
|
-
logWarning:
|
|
68
|
-
logMessage:
|
|
67
|
+
logWarning: r,
|
|
68
|
+
logMessage: n
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
const A =
|
|
71
|
+
const A = B({ ...ne, uuid: ne.MathUtils.generateUUID() });
|
|
72
72
|
delete A.value.Scene;
|
|
73
73
|
let L;
|
|
74
|
-
function
|
|
75
|
-
const { logMessage:
|
|
74
|
+
function fe(e, r = "Tres") {
|
|
75
|
+
const { logMessage: n, logError: o } = U();
|
|
76
76
|
!L && e && (L = e);
|
|
77
|
-
const { createComponentInstances: i } =
|
|
77
|
+
const { createComponentInstances: i } = pe(r);
|
|
78
78
|
return {
|
|
79
|
-
extend: (
|
|
80
|
-
if (!
|
|
79
|
+
extend: (u) => {
|
|
80
|
+
if (!u) {
|
|
81
81
|
o("No objects provided to extend catalogue");
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
|
-
A.value = Object.assign(A.value,
|
|
85
|
-
const m = i(
|
|
86
|
-
|
|
84
|
+
A.value = Object.assign(A.value, u);
|
|
85
|
+
const m = i(B(u));
|
|
86
|
+
n("Adding objects to catalogue", { objects: u, catalogue: A.value.uuid }), L && m.forEach(([t, c]) => {
|
|
87
87
|
L._context.components[t] || L.component(t, c);
|
|
88
88
|
});
|
|
89
89
|
},
|
|
90
90
|
catalogue: A
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
const R = (e) => typeof e < "u",
|
|
94
|
-
function
|
|
95
|
-
return typeof e == "number" ? [e, e, e] : e instanceof
|
|
93
|
+
const R = (e) => typeof e < "u", Fe = (e) => typeof e == "function", z = (e) => !!e && e.constructor === Array;
|
|
94
|
+
function ze(e) {
|
|
95
|
+
return typeof e == "number" ? [e, e, e] : e instanceof Re ? [e.x, e.y, e.z] : e;
|
|
96
96
|
}
|
|
97
|
-
function
|
|
98
|
-
return e instanceof
|
|
97
|
+
function Ue(e) {
|
|
98
|
+
return e instanceof V ? e : Array.isArray(e) ? new V(...e) : new V(e);
|
|
99
99
|
}
|
|
100
|
-
const
|
|
101
|
-
function
|
|
102
|
-
const { logMessage:
|
|
100
|
+
const ke = ["rotation", "scale", "position"];
|
|
101
|
+
function pe(e) {
|
|
102
|
+
const { logMessage: r, logError: n } = U();
|
|
103
103
|
function o(t, c) {
|
|
104
|
-
R(t) && R(c) && Object.entries(t).forEach(([
|
|
105
|
-
const s =
|
|
106
|
-
c.setAttribute(s, new
|
|
104
|
+
R(t) && R(c) && Object.entries(t).forEach(([l, a]) => {
|
|
105
|
+
const s = l.replace(/(-\w)/g, (p) => p[1].toUpperCase());
|
|
106
|
+
c.setAttribute(s, new Ae(...a));
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
function i(t, c) {
|
|
110
|
-
R(t) && R(c) && Object.entries(t).forEach(([
|
|
111
|
-
const s =
|
|
110
|
+
R(t) && R(c) && Object.entries(t).forEach(([l, a]) => {
|
|
111
|
+
const s = l.replace(/(-\w)/g, (p) => p[1].toUpperCase());
|
|
112
112
|
if (!(s === "args" || a === void 0)) {
|
|
113
|
-
|
|
113
|
+
ke.includes(s) && a && (a = ze(a)), t.ref && (t.ref = c);
|
|
114
114
|
try {
|
|
115
115
|
if (c[s] && R(c[s].set))
|
|
116
|
-
c[s].set(...
|
|
116
|
+
c[s].set(...z(a) ? a : [a]);
|
|
117
117
|
else {
|
|
118
|
-
if (a === "" && (a = !0),
|
|
119
|
-
if (
|
|
118
|
+
if (a === "" && (a = !0), Fe(c[s])) {
|
|
119
|
+
if (l === "center" && !a)
|
|
120
120
|
return;
|
|
121
|
-
c[s](...
|
|
121
|
+
c[s](...z(a) ? a : [a]);
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
124
|
c[s] = a;
|
|
125
125
|
}
|
|
126
126
|
} catch (p) {
|
|
127
|
-
|
|
127
|
+
n(`There was an error setting ${s} property`, p);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
function f(t) {
|
|
133
133
|
var a, s;
|
|
134
|
-
const c = /^Symbol\(Fragment\)$/g,
|
|
134
|
+
const c = /^Symbol\(Fragment\)$/g, l = /^Symbol\(Text\)$/g;
|
|
135
135
|
if (c.test(t.type.toString()))
|
|
136
136
|
return t.children.map((p) => f(p));
|
|
137
|
-
if (
|
|
137
|
+
if (l.test(t.type.toString()))
|
|
138
138
|
return;
|
|
139
139
|
{
|
|
140
|
-
const p = t.type.name.replace(e, ""), { catalogue: C } =
|
|
140
|
+
const p = t.type.name.replace(e, ""), { catalogue: C } = fe(), h = M("catalogue") || C;
|
|
141
141
|
let v;
|
|
142
142
|
if (h)
|
|
143
143
|
if ((a = t.children) != null && a.default) {
|
|
144
144
|
const E = t.children.default().map((w) => f(w));
|
|
145
145
|
v = new h.value[p](...E.flat().filter(Boolean));
|
|
146
146
|
} else
|
|
147
|
-
(s = t == null ? void 0 : t.props) != null && s.args ? h != null && h.value[p] ? v = new h.value[p](...t.props.args) :
|
|
148
|
-
return t != null && t.props && (p === "BufferGeometry" ? o(t.props, v) : i(t.props, v)),
|
|
147
|
+
(s = t == null ? void 0 : t.props) != null && s.args ? h != null && h.value[p] ? v = new h.value[p](...t.props.args) : n(`There is no ${p} in the catalogue`, h == null ? void 0 : h.value.uuid) : v = new h.value[p]();
|
|
148
|
+
return t != null && t.props && (p === "BufferGeometry" ? o(t.props, v) : i(t.props, v)), r(`Created ${p} instance`, v), v;
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
function
|
|
152
|
-
if (
|
|
153
|
-
const a =
|
|
151
|
+
function u(t, c, l) {
|
|
152
|
+
if (l.default && (l != null && l.default())) {
|
|
153
|
+
const a = l.default().map((s) => f(s));
|
|
154
154
|
if (t.name === "Group") {
|
|
155
155
|
const s = new t();
|
|
156
156
|
return a.forEach((p) => {
|
|
@@ -162,16 +162,16 @@ function ie(e) {
|
|
|
162
162
|
return c.args ? new t(...c.args) : new t();
|
|
163
163
|
}
|
|
164
164
|
function m(t) {
|
|
165
|
-
return Object.entries(t.value).filter(([c,
|
|
165
|
+
return Object.entries(t.value).filter(([c, l]) => {
|
|
166
166
|
var a, s;
|
|
167
|
-
return (s = (a =
|
|
168
|
-
}).map(([c,
|
|
169
|
-
const a = `${e}${c}`, s =
|
|
167
|
+
return (s = (a = l == null ? void 0 : l.prototype) == null ? void 0 : a.constructor) == null ? void 0 : s.toString().includes("class");
|
|
168
|
+
}).map(([c, l]) => {
|
|
169
|
+
const a = `${e}${c}`, s = N({
|
|
170
170
|
name: a,
|
|
171
171
|
setup(p, { slots: C, attrs: h, ...v }) {
|
|
172
|
-
const { scene: E } =
|
|
173
|
-
let y = l
|
|
174
|
-
return i(h, y), (y instanceof
|
|
172
|
+
const { scene: E } = he(), w = M("local-scene") || E, P = M("catalogue"), { pushCamera: S } = le();
|
|
173
|
+
let y = u(l, h, C);
|
|
174
|
+
return i(h, y), (y instanceof _ || y instanceof ce) && S(y), y.isObject3D && (w == null || w.value.add(y)), w != null && w.value && y.isFog && (w.value.fog = y), v.expose(y), r(a, {
|
|
175
175
|
sceneuuid: w == null ? void 0 : w.value.uuid,
|
|
176
176
|
catalogue: P == null ? void 0 : P.value.uuid,
|
|
177
177
|
props: p,
|
|
@@ -192,159 +192,163 @@ function ie(e) {
|
|
|
192
192
|
createInstanceFromVNode: f
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
|
-
const
|
|
195
|
+
const me = G(), de = G(), H = G(), b = new ue();
|
|
196
|
+
let D = 0, F = 0;
|
|
197
|
+
const { pause: Ve, resume: je, isActive: Ne } = Ee(
|
|
196
198
|
() => {
|
|
197
|
-
|
|
198
|
-
ce.trigger({ delta: n, elapsed: e }), ue.trigger({ delta: n, elapsed: e }), le.trigger({ delta: n, elapsed: e });
|
|
199
|
+
me.trigger({ delta: D, elapsed: F, clock: b }), de.trigger({ delta: D, elapsed: F, clock: b }), H.trigger({ delta: D, elapsed: F, clock: b });
|
|
199
200
|
},
|
|
200
201
|
{ immediate: !1 }
|
|
201
202
|
);
|
|
202
|
-
|
|
203
|
+
H.on(() => {
|
|
204
|
+
D = b.getDelta(), F = b.getElapsedTime();
|
|
205
|
+
});
|
|
206
|
+
function ge() {
|
|
203
207
|
return {
|
|
204
|
-
onBeforeLoop:
|
|
205
|
-
onLoop:
|
|
206
|
-
onAfterLoop:
|
|
207
|
-
pause:
|
|
208
|
-
resume:
|
|
209
|
-
isActive:
|
|
208
|
+
onBeforeLoop: me.on,
|
|
209
|
+
onLoop: de.on,
|
|
210
|
+
onAfterLoop: H.on,
|
|
211
|
+
pause: Ve,
|
|
212
|
+
resume: je,
|
|
213
|
+
isActive: Ne
|
|
210
214
|
};
|
|
211
215
|
}
|
|
212
|
-
const
|
|
213
|
-
function
|
|
216
|
+
const We = W(new be());
|
|
217
|
+
function he() {
|
|
214
218
|
return {
|
|
215
|
-
scene:
|
|
219
|
+
scene: We
|
|
216
220
|
};
|
|
217
221
|
}
|
|
218
|
-
function
|
|
219
|
-
const
|
|
220
|
-
return e && e.traverse((
|
|
221
|
-
|
|
222
|
-
}),
|
|
222
|
+
function Ge(e) {
|
|
223
|
+
const r = { nodes: {}, materials: {} };
|
|
224
|
+
return e && e.traverse((n) => {
|
|
225
|
+
n.name && (r.nodes[n.name] = n), n.material && !r.materials[n.material.name] && (r.materials[n.material.name] = n.material);
|
|
226
|
+
}), r;
|
|
223
227
|
}
|
|
224
|
-
async function
|
|
225
|
-
const { logError: f } =
|
|
226
|
-
i && i(
|
|
227
|
-
const t = (Array.isArray(
|
|
228
|
-
(c) => new Promise((
|
|
229
|
-
|
|
228
|
+
async function Ze(e, r, n, o, i) {
|
|
229
|
+
const { logError: f } = U(), u = new e();
|
|
230
|
+
i && i(u), n && n(u);
|
|
231
|
+
const t = (Array.isArray(r) ? r : [r]).map(
|
|
232
|
+
(c) => new Promise((l, a) => {
|
|
233
|
+
u.load(
|
|
230
234
|
c,
|
|
231
235
|
(s) => {
|
|
232
|
-
s.scene && Object.assign(s,
|
|
236
|
+
s.scene && Object.assign(s, Ge(s.scene)), l(s);
|
|
233
237
|
},
|
|
234
238
|
o,
|
|
235
239
|
(s) => a(f("[useLoader] - Failed to load resource", s))
|
|
236
240
|
);
|
|
237
241
|
})
|
|
238
242
|
);
|
|
239
|
-
return
|
|
243
|
+
return z(r) ? await Promise.all(t) : await t[0];
|
|
240
244
|
}
|
|
241
|
-
async function
|
|
242
|
-
const
|
|
243
|
-
|
|
245
|
+
async function et(e) {
|
|
246
|
+
const r = new Be(), n = new Oe(r), o = (i) => new Promise((f, u) => {
|
|
247
|
+
n.load(
|
|
244
248
|
i,
|
|
245
249
|
(m) => f(m),
|
|
246
250
|
() => null,
|
|
247
251
|
() => {
|
|
248
|
-
|
|
252
|
+
u(new Error("[useTextures] - Failed to load texture"));
|
|
249
253
|
}
|
|
250
254
|
);
|
|
251
255
|
});
|
|
252
|
-
if (
|
|
256
|
+
if (z(e)) {
|
|
253
257
|
const i = await Promise.all(e.map((f) => o(f)));
|
|
254
258
|
return e.length > 1 ? i : i[0];
|
|
255
259
|
} else {
|
|
256
|
-
const { map: i, displacementMap: f, normalMap:
|
|
260
|
+
const { map: i, displacementMap: f, normalMap: u, roughnessMap: m, metalnessMap: t, aoMap: c } = e;
|
|
257
261
|
return {
|
|
258
262
|
map: i ? await o(i) : null,
|
|
259
263
|
displacementMap: f ? await o(f) : null,
|
|
260
|
-
normalMap:
|
|
264
|
+
normalMap: u ? await o(u) : null,
|
|
261
265
|
roughnessMap: m ? await o(m) : null,
|
|
262
266
|
metalnessMap: t ? await o(t) : null,
|
|
263
267
|
aoMap: c ? await o(c) : null
|
|
264
268
|
};
|
|
265
269
|
}
|
|
266
270
|
}
|
|
267
|
-
const
|
|
268
|
-
function
|
|
269
|
-
function e(
|
|
270
|
-
return
|
|
271
|
+
const O = xe({});
|
|
272
|
+
function we() {
|
|
273
|
+
function e(n) {
|
|
274
|
+
return O[n];
|
|
271
275
|
}
|
|
272
|
-
function n
|
|
273
|
-
|
|
276
|
+
function r(n, o) {
|
|
277
|
+
O[n] = o;
|
|
274
278
|
}
|
|
275
279
|
return {
|
|
276
|
-
state:
|
|
277
|
-
...
|
|
280
|
+
state: O,
|
|
281
|
+
...ie(O),
|
|
278
282
|
getState: e,
|
|
279
|
-
setState:
|
|
283
|
+
setState: r
|
|
280
284
|
};
|
|
281
285
|
}
|
|
282
|
-
const g =
|
|
283
|
-
function
|
|
286
|
+
const g = W(), j = B(!1);
|
|
287
|
+
function He(e, r, n) {
|
|
284
288
|
const {
|
|
285
289
|
alpha: o = !0,
|
|
286
290
|
antialias: i = !0,
|
|
287
291
|
depth: f,
|
|
288
|
-
logarithmicDepthBuffer:
|
|
292
|
+
logarithmicDepthBuffer: u,
|
|
289
293
|
failIfMajorPerformanceCaveat: m,
|
|
290
294
|
precision: t,
|
|
291
295
|
premultipliedAlpha: c,
|
|
292
|
-
stencil:
|
|
296
|
+
stencil: l,
|
|
293
297
|
shadows: a = !1,
|
|
294
|
-
shadowMapType: s =
|
|
298
|
+
shadowMapType: s = $e,
|
|
295
299
|
physicallyCorrectLights: p = !1,
|
|
296
|
-
outputEncoding: C =
|
|
297
|
-
toneMapping: h =
|
|
300
|
+
outputEncoding: C = re,
|
|
301
|
+
toneMapping: h = ae,
|
|
298
302
|
toneMappingExposure: v = 1,
|
|
299
303
|
context: E = void 0,
|
|
300
304
|
powerPreference: w = "default",
|
|
301
305
|
preserveDrawingBuffer: P = !1,
|
|
302
306
|
clearColor: S,
|
|
303
307
|
windowSize: y = !1
|
|
304
|
-
} =
|
|
305
|
-
g.value && (g.value.setSize(
|
|
306
|
-
},
|
|
307
|
-
g.value && (g.value.shadowMap.enabled = d(a), g.value.shadowMap.type = d(s), g.value.toneMapping = d(h) ||
|
|
308
|
-
},
|
|
309
|
-
const
|
|
310
|
-
if (g.value || !
|
|
308
|
+
} = ie(n), { width: K, height: J } = d(y) ? Pe() : Te(r), { pixelRatio: q } = Le(), { pause: ve, resume: ye } = ge(), Q = se(() => K.value / J.value), X = () => {
|
|
309
|
+
g.value && (g.value.setSize(K.value, J.value), g.value.setPixelRatio(Math.min(q.value, 2)));
|
|
310
|
+
}, Y = () => {
|
|
311
|
+
g.value && (g.value.shadowMap.enabled = d(a), g.value.shadowMap.type = d(s), g.value.toneMapping = d(h) || ae, g.value.toneMappingExposure = d(v), g.value.outputEncoding = d(C) || re, S != null && S.value && g.value.setClearColor(Ue(d(S))), g.value.physicallyCorrectLights = d(p));
|
|
312
|
+
}, Ce = () => {
|
|
313
|
+
const Z = k(e);
|
|
314
|
+
if (g.value || !Z)
|
|
311
315
|
return;
|
|
312
|
-
g.value = new
|
|
313
|
-
canvas:
|
|
316
|
+
g.value = new Ie({
|
|
317
|
+
canvas: Z,
|
|
314
318
|
alpha: d(o),
|
|
315
319
|
antialias: d(i),
|
|
316
320
|
context: d(E),
|
|
317
321
|
depth: d(f),
|
|
318
322
|
failIfMajorPerformanceCaveat: d(m),
|
|
319
|
-
logarithmicDepthBuffer: d(
|
|
323
|
+
logarithmicDepthBuffer: d(u),
|
|
320
324
|
powerPreference: d(w),
|
|
321
325
|
precision: d(t),
|
|
322
|
-
stencil: d(
|
|
326
|
+
stencil: d(l),
|
|
323
327
|
preserveDrawingBuffer: d(P),
|
|
324
328
|
premultipliedAlpha: d(c)
|
|
325
329
|
});
|
|
326
|
-
const { setState:
|
|
327
|
-
|
|
328
|
-
},
|
|
329
|
-
g.value && (g.value.dispose(), g.value = void 0,
|
|
330
|
+
const { setState: ee } = we();
|
|
331
|
+
ee("renderer", g.value), ee("clock", new ue()), Y(), X(), ye(), j.value = !0;
|
|
332
|
+
}, Se = () => {
|
|
333
|
+
g.value && (g.value.dispose(), g.value = void 0, j.value = !1, ve());
|
|
330
334
|
};
|
|
331
|
-
return
|
|
335
|
+
return $([Q, q], X), $(
|
|
332
336
|
[a, s, C, p, h, v, S],
|
|
333
|
-
|
|
334
|
-
),
|
|
335
|
-
() => [e,
|
|
337
|
+
Y
|
|
338
|
+
), $(
|
|
339
|
+
() => [e, r],
|
|
336
340
|
() => {
|
|
337
|
-
|
|
341
|
+
k(e) && k(r) && Ce();
|
|
338
342
|
},
|
|
339
343
|
{ immediate: !0, deep: !0 }
|
|
340
344
|
), {
|
|
341
345
|
renderer: g,
|
|
342
|
-
isReady:
|
|
343
|
-
dispose:
|
|
344
|
-
aspectRatio:
|
|
346
|
+
isReady: j,
|
|
347
|
+
dispose: Se,
|
|
348
|
+
aspectRatio: Q
|
|
345
349
|
};
|
|
346
350
|
}
|
|
347
|
-
const
|
|
351
|
+
const Ke = N({
|
|
348
352
|
name: "TresCanvas",
|
|
349
353
|
props: {
|
|
350
354
|
shadows: Boolean,
|
|
@@ -359,16 +363,16 @@ const Ge = V({
|
|
|
359
363
|
clearColor: String,
|
|
360
364
|
windowSize: { type: Boolean, default: !1 }
|
|
361
365
|
},
|
|
362
|
-
setup(e, { slots:
|
|
363
|
-
const { logError: o } =
|
|
364
|
-
|
|
365
|
-
const c =
|
|
366
|
-
return
|
|
366
|
+
setup(e, { slots: r, attrs: n }) {
|
|
367
|
+
const { logError: o } = U(), i = B(), f = B(), { renderer: u, dispose: m, aspectRatio: t } = He(i, f, e);
|
|
368
|
+
I("aspect-ratio", t), I("renderer", u);
|
|
369
|
+
const c = W();
|
|
370
|
+
return I("camera", c), r.default && !r.default().some((l) => l.type.name === "Scene") && o("TresCanvas must contain a Scene component."), r.default && !r.default().some((l) => {
|
|
367
371
|
var a;
|
|
368
|
-
return (a =
|
|
369
|
-
}) && o("Scene must contain a Camera component."),
|
|
370
|
-
if (
|
|
371
|
-
return
|
|
372
|
+
return (a = l.type.name) == null ? void 0 : a.includes("Camera");
|
|
373
|
+
}) && o("Scene must contain a Camera component."), Me(() => m()), () => {
|
|
374
|
+
if (r.default)
|
|
375
|
+
return te(
|
|
372
376
|
"div",
|
|
373
377
|
{
|
|
374
378
|
ref: f,
|
|
@@ -376,11 +380,11 @@ const Ge = V({
|
|
|
376
380
|
position: "relative",
|
|
377
381
|
width: "100%",
|
|
378
382
|
height: "100vh",
|
|
379
|
-
...
|
|
383
|
+
...n.style
|
|
380
384
|
}
|
|
381
385
|
},
|
|
382
386
|
[
|
|
383
|
-
|
|
387
|
+
te("canvas", {
|
|
384
388
|
ref: i,
|
|
385
389
|
style: {
|
|
386
390
|
width: "100%",
|
|
@@ -390,49 +394,49 @@ const Ge = V({
|
|
|
390
394
|
left: 0
|
|
391
395
|
}
|
|
392
396
|
}),
|
|
393
|
-
|
|
397
|
+
r.default()
|
|
394
398
|
]
|
|
395
399
|
);
|
|
396
400
|
};
|
|
397
401
|
}
|
|
398
|
-
}),
|
|
402
|
+
}), Je = N({
|
|
399
403
|
name: "Scene",
|
|
400
|
-
setup(e, { slots:
|
|
401
|
-
const { scene:
|
|
402
|
-
return
|
|
403
|
-
o != null && o.value && (i != null && i.value) && (
|
|
404
|
+
setup(e, { slots: r }) {
|
|
405
|
+
const { scene: n } = he(), o = M("renderer"), { activeCamera: i } = le(), { onLoop: f } = ge();
|
|
406
|
+
return I("local-scene", n), f(({ clock: u }) => {
|
|
407
|
+
o != null && o.value && (i != null && i.value) && (n != null && n.value) && o.value.render(n == null ? void 0 : n.value, i.value);
|
|
404
408
|
}), () => {
|
|
405
|
-
if (
|
|
406
|
-
return
|
|
409
|
+
if (r.default)
|
|
410
|
+
return r.default();
|
|
407
411
|
};
|
|
408
412
|
}
|
|
409
|
-
}),
|
|
410
|
-
install(e,
|
|
411
|
-
const
|
|
412
|
-
e.component(`${
|
|
413
|
-
const { catalogue: o, extend: i } =
|
|
413
|
+
}), tt = Symbol("UseTresState"), qe = "1.5.1", nt = {
|
|
414
|
+
install(e, r) {
|
|
415
|
+
const n = (r == null ? void 0 : r.prefix) || "Tres";
|
|
416
|
+
e.component(`${n}Canvas`, Ke), e.component(`${n}Scene`, Je);
|
|
417
|
+
const { catalogue: o, extend: i } = fe(e, n);
|
|
414
418
|
e.provide("catalogue", o), e.provide("extend", i);
|
|
415
|
-
const { createComponentInstances: f } =
|
|
419
|
+
const { createComponentInstances: f } = pe(n);
|
|
416
420
|
f(o).forEach(([m, t]) => {
|
|
417
421
|
e.component(m, t);
|
|
418
422
|
}), window.__TRES__ = {
|
|
419
423
|
app: e,
|
|
420
|
-
version:
|
|
424
|
+
version: qe
|
|
421
425
|
};
|
|
422
426
|
}
|
|
423
427
|
};
|
|
424
428
|
export {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
429
|
+
_e as CameraType,
|
|
430
|
+
tt as UseTresStateSymbol,
|
|
431
|
+
nt as default,
|
|
432
|
+
Ge as trasverseObjects,
|
|
433
|
+
le as useCamera,
|
|
434
|
+
fe as useCatalogue,
|
|
435
|
+
pe as useInstanceCreator,
|
|
436
|
+
Ze as useLoader,
|
|
437
|
+
ge as useRenderLoop,
|
|
438
|
+
He as useRenderer,
|
|
439
|
+
he as useScene,
|
|
440
|
+
et as useTexture,
|
|
441
|
+
we as useTres
|
|
438
442
|
};
|
package/dist/tres.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v1.5.
|
|
3
|
+
* version: v1.5.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
|
-
(function(w,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue"),require("@vueuse/core"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","three"],s):(w=typeof globalThis<"u"?globalThis:w||self,s(w.tres={},w.Vue,w.VueUseCore,w.Three))})(this,function(w,s,f,g){"use strict";function ae(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return n.default=e,Object.freeze(n)}const R=ae(g);var W=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(W||{});const L={cameras:[]},oe=45;let b;function D(){const e=s.inject("aspect-ratio"),{setState:n}=k();function r(p="Perspective",h){if(p==="Perspective"){const{near:t,far:l,fov:u}=h||{near:.1,far:1e3,fov:oe};b=new g.PerspectiveCamera(u,(e==null?void 0:e.value)||1,t,l),L.cameras.push(b)}else{const{left:t,right:l,top:u,bottom:o,near:i,far:m}=h||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};b=new g.OrthographicCamera(t,l,u,o,i,m),L.cameras.push(b)}return L.cameras.push(b),b}const a=s.computed(()=>L.cameras[0]);function c(){a.value instanceof g.PerspectiveCamera&&e&&(a.value.aspect=e.value),a.value.updateProjectionMatrix()}function d(p){const h=s.inject("camera");p&&h&&(h.value=p,n("camera",h.value)),L.cameras.push(p),p instanceof g.PerspectiveCamera&&e&&(p.aspect=e.value),p.updateProjectionMatrix()}return e&&s.watch(e,c),{activeCamera:a,createCamera:r,updateCamera:c,pushCamera:d}}const q="[TresJS ▲ ■ ●] ";function B(){function e(a,c){console.error(`${q} ${a}`,c||"")}function n(a){console.warn(`${q} ${a}`)}function r(a,c){}return{logError:e,logWarning:n,logMessage:r}}const x=s.ref({...R,uuid:R.MathUtils.generateUUID()});delete x.value.Scene;let O;function T(e,n="Tres"){const{logMessage:r,logError:a}=B();!O&&e&&(O=e);const{createComponentInstances:c}=z(n);return{extend:p=>{if(!p){a("No objects provided to extend catalogue");return}x.value=Object.assign(x.value,p);const h=c(s.ref(p));r("Adding objects to catalogue",{objects:p,catalogue:x.value.uuid}),O&&h.forEach(([t,l])=>{O._context.components[t]||O.component(t,l)})},catalogue:x}}const j=e=>typeof e<"u",se=e=>typeof e=="function",I=e=>!!e&&e.constructor===Array;function ie(e){return typeof e=="number"?[e,e,e]:e instanceof g.Vector3?[e.x,e.y,e.z]:e}function ce(e){return e instanceof g.Color?e:Array.isArray(e)?new g.Color(...e):new g.Color(e)}const le=["rotation","scale","position"];function z(e){const{logMessage:n,logError:r}=B();function a(t,l){j(t)&&j(l)&&Object.entries(t).forEach(([u,o])=>{const i=u.replace(/(-\w)/g,m=>m[1].toUpperCase());l.setAttribute(i,new g.BufferAttribute(...o))})}function c(t,l){j(t)&&j(l)&&Object.entries(t).forEach(([u,o])=>{const i=u.replace(/(-\w)/g,m=>m[1].toUpperCase());if(!(i==="args"||o===void 0)){le.includes(i)&&o&&(o=ie(o)),t.ref&&(t.ref=l);try{if(l[i]&&j(l[i].set))l[i].set(...I(o)?o:[o]);else{if(o===""&&(o=!0),se(l[i])){if(u==="center"&&!o)return;l[i](...I(o)?o:[o]);return}l[i]=o}}catch(m){r(`There was an error setting ${i} property`,m)}}})}function d(t){var o,i;const l=/^Symbol\(Fragment\)$/g,u=/^Symbol\(Text\)$/g;if(l.test(t.type.toString()))return t.children.map(m=>d(m));if(u.test(t.type.toString()))return;{const m=t.type.name.replace(e,""),{catalogue:P}=T(),C=s.inject("catalogue")||P;let S;if(C)if((o=t.children)!=null&&o.default){const A=t.children.default().map(y=>d(y));S=new C.value[m](...A.flat().filter(Boolean))}else(i=t==null?void 0:t.props)!=null&&i.args?C!=null&&C.value[m]?S=new C.value[m](...t.props.args):r(`There is no ${m} in the catalogue`,C==null?void 0:C.value.uuid):S=new C.value[m];return t!=null&&t.props&&(m==="BufferGeometry"?a(t.props,S):c(t.props,S)),n(`Created ${m} instance`,S),S}}function p(t,l,u){if(u.default&&(u!=null&&u.default())){const o=u.default().map(i=>d(i));if(t.name==="Group"){const i=new t;return o.forEach(m=>{i.add(m)}),i}else return new t(...o.flat().filter(Boolean))}else return l.args?new t(...l.args):new t}function h(t){return Object.entries(t.value).filter(([l,u])=>{var o,i;return(i=(o=u==null?void 0:u.prototype)==null?void 0:o.constructor)==null?void 0:i.toString().includes("class")}).map(([l,u])=>{const o=`${e}${l}`,i=s.defineComponent({name:o,setup(m,{slots:P,attrs:C,...S}){const{scene:A}=V(),y=s.inject("local-scene")||A,_=s.inject("catalogue"),{pushCamera:U}=D();let M=p(u,C,P);return c(C,M),(M instanceof g.PerspectiveCamera||M instanceof g.OrthographicCamera)&&U(M),M.isObject3D&&(y==null||y.value.add(M)),y!=null&&y.value&&M.isFog&&(y.value.fog=M),S.expose(M),n(o,{sceneuuid:y==null?void 0:y.value.uuid,catalogue:_==null?void 0:_.value.uuid,props:m,slots:P.default?P.default():void 0,attrs:C,ctx:S,scene:y}),()=>{}}});return[o,i]})}return{createComponentInstances:h,processProps:c,createInstanceFromVNode:d}}const G=f.createEventHook(),K=f.createEventHook(),J=f.createEventHook(),Q=new g.Clock,{pause:ue,resume:fe,isActive:pe}=f.useRafFn(()=>{const e=Q.getElapsedTime(),n=Q.getDelta();G.trigger({delta:n,elapsed:e}),K.trigger({delta:n,elapsed:e}),J.trigger({delta:n,elapsed:e})},{immediate:!1});function F(){return{onBeforeLoop:G.on,onLoop:K.on,onAfterLoop:J.on,pause:ue,resume:fe,isActive:pe}}const de=s.shallowRef(new g.Scene);function V(){return{scene:de}}function X(e){const n={nodes:{},materials:{}};return e&&e.traverse(r=>{r.name&&(n.nodes[r.name]=r),r.material&&!n.materials[r.material.name]&&(n.materials[r.material.name]=r.material)}),n}async function me(e,n,r,a,c){const{logError:d}=B(),p=new e;c&&c(p),r&&r(p);const t=(Array.isArray(n)?n:[n]).map(l=>new Promise((u,o)=>{p.load(l,i=>{i.scene&&Object.assign(i,X(i.scene)),u(i)},a,i=>o(d("[useLoader] - Failed to load resource",i)))}));return I(n)?await Promise.all(t):await t[0]}async function ge(e){const n=new g.LoadingManager,r=new g.TextureLoader(n),a=c=>new Promise((d,p)=>{r.load(c,h=>d(h),()=>null,()=>{p(new Error("[useTextures] - Failed to load texture"))})});if(I(e)){const c=await Promise.all(e.map(d=>a(d)));return e.length>1?c:c[0]}else{const{map:c,displacementMap:d,normalMap:p,roughnessMap:h,metalnessMap:t,aoMap:l}=e;return{map:c?await a(c):null,displacementMap:d?await a(d):null,normalMap:p?await a(p):null,roughnessMap:h?await a(h):null,metalnessMap:t?await a(t):null,aoMap:l?await a(l):null}}}const $=s.reactive({});function k(){function e(r){return $[r]}function n(r,a){$[r]=a}return{state:$,...s.toRefs($),getState:e,setState:n}}const v=s.shallowRef(),N=s.ref(!1);function Y(e,n,r){const{alpha:a=!0,antialias:c=!0,depth:d,logarithmicDepthBuffer:p,failIfMajorPerformanceCaveat:h,precision:t,premultipliedAlpha:l,stencil:u,shadows:o=!1,shadowMapType:i=g.PCFShadowMap,physicallyCorrectLights:m=!1,outputEncoding:P=g.LinearEncoding,toneMapping:C=g.NoToneMapping,toneMappingExposure:S=1,context:A=void 0,powerPreference:y="default",preserveDrawingBuffer:_=!1,clearColor:U,windowSize:M=!1}=s.toRefs(r),{width:Z,height:E}=f.resolveUnref(M)?f.useWindowSize():f.useElementSize(n),{pixelRatio:H}=f.useDevicePixelRatio(),{pause:Se,resume:Me}=F(),ee=s.computed(()=>Z.value/E.value),te=()=>{v.value&&(v.value.setSize(Z.value,E.value),v.value.setPixelRatio(Math.min(H.value,2)))},ne=()=>{v.value&&(v.value.shadowMap.enabled=f.resolveUnref(o),v.value.shadowMap.type=f.resolveUnref(i),v.value.toneMapping=f.resolveUnref(C)||g.NoToneMapping,v.value.toneMappingExposure=f.resolveUnref(S),v.value.outputEncoding=f.resolveUnref(P)||g.LinearEncoding,U!=null&&U.value&&v.value.setClearColor(ce(f.resolveUnref(U))),v.value.physicallyCorrectLights=f.resolveUnref(m))},Pe=()=>{const re=f.unrefElement(e);if(v.value||!re)return;v.value=new g.WebGLRenderer({canvas:re,alpha:f.resolveUnref(a),antialias:f.resolveUnref(c),context:f.resolveUnref(A),depth:f.resolveUnref(d),failIfMajorPerformanceCaveat:f.resolveUnref(h),logarithmicDepthBuffer:f.resolveUnref(p),powerPreference:f.resolveUnref(y),precision:f.resolveUnref(t),stencil:f.resolveUnref(u),preserveDrawingBuffer:f.resolveUnref(_),premultipliedAlpha:f.resolveUnref(l)});const{setState:be}=k();be("renderer",v.value),ne(),te(),Me(),N.value=!0},Ue=()=>{v.value&&(v.value.dispose(),v.value=void 0,N.value=!1,Se())};return s.watch([ee,H],te),s.watch([o,i,P,m,C,S,U],ne),s.watch(()=>[e,n],()=>{f.unrefElement(e)&&f.unrefElement(n)&&Pe()},{immediate:!0,deep:!0}),{renderer:v,isReady:N,dispose:Ue,aspectRatio:ee}}const he=s.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:{type:Boolean,default:!1}},setup(e,{slots:n,attrs:r}){const{logError:a}=B(),c=s.ref(),d=s.ref(),{renderer:p,dispose:h,aspectRatio:t}=Y(c,d,e);s.provide("aspect-ratio",t),s.provide("renderer",p);const l=s.shallowRef();return s.provide("camera",l),n.default&&!n.default().some(u=>u.type.name==="Scene")&&a("TresCanvas must contain a Scene component."),n.default&&!n.default().some(u=>{var o;return(o=u.type.name)==null?void 0:o.includes("Camera")})&&a("Scene must contain a Camera component."),s.onBeforeUnmount(()=>h()),()=>{if(n.default)return s.h("div",{ref:d,style:{position:"relative",width:"100%",height:"100vh",...r.style}},[s.h("canvas",{ref:c,style:{width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}}),n.default()])}}}),we=s.defineComponent({name:"Scene",setup(e,{slots:n}){const{scene:r}=V(),a=s.inject("renderer"),{activeCamera:c}=D(),{onLoop:d}=F();return s.provide("local-scene",r),d(()=>{a!=null&&a.value&&(c!=null&&c.value)&&(r!=null&&r.value)&&a.value.render(r==null?void 0:r.value,c.value)}),()=>{if(n.default)return n.default()}}}),ve=Symbol("UseTresState"),Ce="1.5.0",ye={install(e,n){const r=(n==null?void 0:n.prefix)||"Tres";e.component(`${r}Canvas`,he),e.component(`${r}Scene`,we);const{catalogue:a,extend:c}=T(e,r);e.provide("catalogue",a),e.provide("extend",c);const{createComponentInstances:d}=z(r);d(a).forEach(([h,t])=>{e.component(h,t)}),window.__TRES__={app:e,version:Ce}}};w.CameraType=W,w.UseTresStateSymbol=ve,w.default=ye,w.trasverseObjects=X,w.useCamera=D,w.useCatalogue=T,w.useInstanceCreator=z,w.useLoader=me,w.useRenderLoop=F,w.useRenderer=Y,w.useScene=V,w.useTexture=ge,w.useTres=k,Object.defineProperties(w,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
8
|
+
(function(w,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue"),require("@vueuse/core"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","three"],s):(w=typeof globalThis<"u"?globalThis:w||self,s(w.tres={},w.Vue,w.VueUseCore,w.Three))})(this,function(w,s,p,g){"use strict";function ie(e){const r=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(r,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const K=ie(g);var J=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(J||{});const L={cameras:[]},ce=45;let b;function F(){const e=s.inject("aspect-ratio"),{setState:r}=G();function n(u="Perspective",h){if(u==="Perspective"){const{near:t,far:l,fov:f}=h||{near:.1,far:1e3,fov:ce};b=new g.PerspectiveCamera(f,(e==null?void 0:e.value)||1,t,l),L.cameras.push(b)}else{const{left:t,right:l,top:f,bottom:o,near:i,far:m}=h||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};b=new g.OrthographicCamera(t,l,f,o,i,m),L.cameras.push(b)}return L.cameras.push(b),b}const a=s.computed(()=>L.cameras[0]);function c(){a.value instanceof g.PerspectiveCamera&&e&&(a.value.aspect=e.value),a.value.updateProjectionMatrix()}function d(u){const h=s.inject("camera");u&&h&&(h.value=u,r("camera",h.value)),L.cameras.push(u),u instanceof g.PerspectiveCamera&&e&&(u.aspect=e.value),u.updateProjectionMatrix()}return e&&s.watch(e,c),{activeCamera:a,createCamera:n,updateCamera:c,pushCamera:d}}const Q="[TresJS ▲ ■ ●] ";function I(){function e(a,c){console.error(`${Q} ${a}`,c||"")}function r(a){console.warn(`${Q} ${a}`)}function n(a,c){}return{logError:e,logWarning:r,logMessage:n}}const x=s.ref({...K,uuid:K.MathUtils.generateUUID()});delete x.value.Scene;let O;function k(e,r="Tres"){const{logMessage:n,logError:a}=I();!O&&e&&(O=e);const{createComponentInstances:c}=V(r);return{extend:u=>{if(!u){a("No objects provided to extend catalogue");return}x.value=Object.assign(x.value,u);const h=c(s.ref(u));n("Adding objects to catalogue",{objects:u,catalogue:x.value.uuid}),O&&h.forEach(([t,l])=>{O._context.components[t]||O.component(t,l)})},catalogue:x}}const j=e=>typeof e<"u",le=e=>typeof e=="function",$=e=>!!e&&e.constructor===Array;function ue(e){return typeof e=="number"?[e,e,e]:e instanceof g.Vector3?[e.x,e.y,e.z]:e}function fe(e){return e instanceof g.Color?e:Array.isArray(e)?new g.Color(...e):new g.Color(e)}const pe=["rotation","scale","position"];function V(e){const{logMessage:r,logError:n}=I();function a(t,l){j(t)&&j(l)&&Object.entries(t).forEach(([f,o])=>{const i=f.replace(/(-\w)/g,m=>m[1].toUpperCase());l.setAttribute(i,new g.BufferAttribute(...o))})}function c(t,l){j(t)&&j(l)&&Object.entries(t).forEach(([f,o])=>{const i=f.replace(/(-\w)/g,m=>m[1].toUpperCase());if(!(i==="args"||o===void 0)){pe.includes(i)&&o&&(o=ue(o)),t.ref&&(t.ref=l);try{if(l[i]&&j(l[i].set))l[i].set(...$(o)?o:[o]);else{if(o===""&&(o=!0),le(l[i])){if(f==="center"&&!o)return;l[i](...$(o)?o:[o]);return}l[i]=o}}catch(m){n(`There was an error setting ${i} property`,m)}}})}function d(t){var o,i;const l=/^Symbol\(Fragment\)$/g,f=/^Symbol\(Text\)$/g;if(l.test(t.type.toString()))return t.children.map(m=>d(m));if(f.test(t.type.toString()))return;{const m=t.type.name.replace(e,""),{catalogue:P}=k(),C=s.inject("catalogue")||P;let S;if(C)if((o=t.children)!=null&&o.default){const _=t.children.default().map(y=>d(y));S=new C.value[m](..._.flat().filter(Boolean))}else(i=t==null?void 0:t.props)!=null&&i.args?C!=null&&C.value[m]?S=new C.value[m](...t.props.args):n(`There is no ${m} in the catalogue`,C==null?void 0:C.value.uuid):S=new C.value[m];return t!=null&&t.props&&(m==="BufferGeometry"?a(t.props,S):c(t.props,S)),r(`Created ${m} instance`,S),S}}function u(t,l,f){if(f.default&&(f!=null&&f.default())){const o=f.default().map(i=>d(i));if(t.name==="Group"){const i=new t;return o.forEach(m=>{i.add(m)}),i}else return new t(...o.flat().filter(Boolean))}else return l.args?new t(...l.args):new t}function h(t){return Object.entries(t.value).filter(([l,f])=>{var o,i;return(i=(o=f==null?void 0:f.prototype)==null?void 0:o.constructor)==null?void 0:i.toString().includes("class")}).map(([l,f])=>{const o=`${e}${l}`,i=s.defineComponent({name:o,setup(m,{slots:P,attrs:C,...S}){const{scene:_}=q(),y=s.inject("local-scene")||_,B=s.inject("catalogue"),{pushCamera:U}=F();let M=u(f,C,P);return c(C,M),(M instanceof g.PerspectiveCamera||M instanceof g.OrthographicCamera)&&U(M),M.isObject3D&&(y==null||y.value.add(M)),y!=null&&y.value&&M.isFog&&(y.value.fog=M),S.expose(M),r(o,{sceneuuid:y==null?void 0:y.value.uuid,catalogue:B==null?void 0:B.value.uuid,props:m,slots:P.default?P.default():void 0,attrs:C,ctx:S,scene:y}),()=>{}}});return[o,i]})}return{createComponentInstances:h,processProps:c,createInstanceFromVNode:d}}const X=p.createEventHook(),Y=p.createEventHook(),N=p.createEventHook(),A=new g.Clock;let D=0,T=0;const{pause:de,resume:me,isActive:ge}=p.useRafFn(()=>{X.trigger({delta:D,elapsed:T,clock:A}),Y.trigger({delta:D,elapsed:T,clock:A}),N.trigger({delta:D,elapsed:T,clock:A})},{immediate:!1});N.on(()=>{D=A.getDelta(),T=A.getElapsedTime()});function W(){return{onBeforeLoop:X.on,onLoop:Y.on,onAfterLoop:N.on,pause:de,resume:me,isActive:ge}}const he=s.shallowRef(new g.Scene);function q(){return{scene:he}}function Z(e){const r={nodes:{},materials:{}};return e&&e.traverse(n=>{n.name&&(r.nodes[n.name]=n),n.material&&!r.materials[n.material.name]&&(r.materials[n.material.name]=n.material)}),r}async function we(e,r,n,a,c){const{logError:d}=I(),u=new e;c&&c(u),n&&n(u);const t=(Array.isArray(r)?r:[r]).map(l=>new Promise((f,o)=>{u.load(l,i=>{i.scene&&Object.assign(i,Z(i.scene)),f(i)},a,i=>o(d("[useLoader] - Failed to load resource",i)))}));return $(r)?await Promise.all(t):await t[0]}async function ve(e){const r=new g.LoadingManager,n=new g.TextureLoader(r),a=c=>new Promise((d,u)=>{n.load(c,h=>d(h),()=>null,()=>{u(new Error("[useTextures] - Failed to load texture"))})});if($(e)){const c=await Promise.all(e.map(d=>a(d)));return e.length>1?c:c[0]}else{const{map:c,displacementMap:d,normalMap:u,roughnessMap:h,metalnessMap:t,aoMap:l}=e;return{map:c?await a(c):null,displacementMap:d?await a(d):null,normalMap:u?await a(u):null,roughnessMap:h?await a(h):null,metalnessMap:t?await a(t):null,aoMap:l?await a(l):null}}}const z=s.reactive({});function G(){function e(n){return z[n]}function r(n,a){z[n]=a}return{state:z,...s.toRefs(z),getState:e,setState:r}}const v=s.shallowRef(),R=s.ref(!1);function E(e,r,n){const{alpha:a=!0,antialias:c=!0,depth:d,logarithmicDepthBuffer:u,failIfMajorPerformanceCaveat:h,precision:t,premultipliedAlpha:l,stencil:f,shadows:o=!1,shadowMapType:i=g.PCFShadowMap,physicallyCorrectLights:m=!1,outputEncoding:P=g.LinearEncoding,toneMapping:C=g.NoToneMapping,toneMappingExposure:S=1,context:_=void 0,powerPreference:y="default",preserveDrawingBuffer:B=!1,clearColor:U,windowSize:M=!1}=s.toRefs(n),{width:H,height:ee}=p.resolveUnref(M)?p.useWindowSize():p.useElementSize(r),{pixelRatio:te}=p.useDevicePixelRatio(),{pause:Ue,resume:be}=W(),ne=s.computed(()=>H.value/ee.value),re=()=>{v.value&&(v.value.setSize(H.value,ee.value),v.value.setPixelRatio(Math.min(te.value,2)))},ae=()=>{v.value&&(v.value.shadowMap.enabled=p.resolveUnref(o),v.value.shadowMap.type=p.resolveUnref(i),v.value.toneMapping=p.resolveUnref(C)||g.NoToneMapping,v.value.toneMappingExposure=p.resolveUnref(S),v.value.outputEncoding=p.resolveUnref(P)||g.LinearEncoding,U!=null&&U.value&&v.value.setClearColor(fe(p.resolveUnref(U))),v.value.physicallyCorrectLights=p.resolveUnref(m))},Le=()=>{const oe=p.unrefElement(e);if(v.value||!oe)return;v.value=new g.WebGLRenderer({canvas:oe,alpha:p.resolveUnref(a),antialias:p.resolveUnref(c),context:p.resolveUnref(_),depth:p.resolveUnref(d),failIfMajorPerformanceCaveat:p.resolveUnref(h),logarithmicDepthBuffer:p.resolveUnref(u),powerPreference:p.resolveUnref(y),precision:p.resolveUnref(t),stencil:p.resolveUnref(f),preserveDrawingBuffer:p.resolveUnref(B),premultipliedAlpha:p.resolveUnref(l)});const{setState:se}=G();se("renderer",v.value),se("clock",new g.Clock),ae(),re(),be(),R.value=!0},xe=()=>{v.value&&(v.value.dispose(),v.value=void 0,R.value=!1,Ue())};return s.watch([ne,te],re),s.watch([o,i,P,m,C,S,U],ae),s.watch(()=>[e,r],()=>{p.unrefElement(e)&&p.unrefElement(r)&&Le()},{immediate:!0,deep:!0}),{renderer:v,isReady:R,dispose:xe,aspectRatio:ne}}const Ce=s.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:{type:Boolean,default:!1}},setup(e,{slots:r,attrs:n}){const{logError:a}=I(),c=s.ref(),d=s.ref(),{renderer:u,dispose:h,aspectRatio:t}=E(c,d,e);s.provide("aspect-ratio",t),s.provide("renderer",u);const l=s.shallowRef();return s.provide("camera",l),r.default&&!r.default().some(f=>f.type.name==="Scene")&&a("TresCanvas must contain a Scene component."),r.default&&!r.default().some(f=>{var o;return(o=f.type.name)==null?void 0:o.includes("Camera")})&&a("Scene must contain a Camera component."),s.onBeforeUnmount(()=>h()),()=>{if(r.default)return s.h("div",{ref:d,style:{position:"relative",width:"100%",height:"100vh",...n.style}},[s.h("canvas",{ref:c,style:{width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}}),r.default()])}}}),ye=s.defineComponent({name:"Scene",setup(e,{slots:r}){const{scene:n}=q(),a=s.inject("renderer"),{activeCamera:c}=F(),{onLoop:d}=W();return s.provide("local-scene",n),d(({clock:u})=>{a!=null&&a.value&&(c!=null&&c.value)&&(n!=null&&n.value)&&a.value.render(n==null?void 0:n.value,c.value)}),()=>{if(r.default)return r.default()}}}),Se=Symbol("UseTresState"),Me="1.5.1",Pe={install(e,r){const n=(r==null?void 0:r.prefix)||"Tres";e.component(`${n}Canvas`,Ce),e.component(`${n}Scene`,ye);const{catalogue:a,extend:c}=k(e,n);e.provide("catalogue",a),e.provide("extend",c);const{createComponentInstances:d}=V(n);d(a).forEach(([h,t])=>{e.component(h,t)}),window.__TRES__={app:e,version:Me}}};w.CameraType=J,w.UseTresStateSymbol=Se,w.default=Pe,w.trasverseObjects=Z,w.useCamera=F,w.useCatalogue=k,w.useInstanceCreator=V,w.useLoader=we,w.useRenderLoop=W,w.useRenderer=E,w.useScene=q,w.useTexture=ve,w.useTres=G,Object.defineProperties(w,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type TresVNodeType = VNodeTypes & {
|
|
|
9
9
|
__name?: string
|
|
10
10
|
setup?: (props: Readonly<any>) => void
|
|
11
11
|
}
|
|
12
|
-
export type TresVNode = VNode & { children?: Array<VNode>; type: TresVNodeType }
|
|
12
|
+
export type TresVNode = VNode & { children?: Array<VNode | { default: any }>; type: TresVNodeType }
|
|
13
13
|
export type TresAttributes = Record<string, any> & { args?: number[] }
|
|
14
14
|
|
|
15
15
|
export type TresColor = string | number | Color | 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.5.
|
|
4
|
+
"version": "1.5.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
7
7
|
"files": [
|
|
@@ -38,26 +38,24 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@alvarosabu/utils": "^2.2.0",
|
|
41
|
-
"@
|
|
42
|
-
"@tresjs/cientos": "^1.4.0",
|
|
41
|
+
"@tresjs/cientos": "^1.5.0",
|
|
43
42
|
"@types/three": "^0.148.0",
|
|
44
43
|
"@vitejs/plugin-vue": "^4.0.0",
|
|
45
44
|
"@vitest/coverage-c8": "^0.25.8",
|
|
46
45
|
"@vitest/ui": "^0.25.8",
|
|
47
|
-
"@vueuse/core": "^9.
|
|
46
|
+
"@vueuse/core": "^9.11.0",
|
|
48
47
|
"gl": "6.0.1",
|
|
49
48
|
"happy-dom": "^8.1.0",
|
|
50
|
-
"histoire": "0.11.9",
|
|
51
49
|
"kolorist": "^1.6.0",
|
|
52
50
|
"pathe": "^1.0.0",
|
|
53
51
|
"release-it": "^15.5.1",
|
|
54
52
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
55
53
|
"rollup-plugin-visualizer": "^5.8.3",
|
|
56
54
|
"unplugin-vue-components": "^0.22.12",
|
|
57
|
-
"vite": "^4.0.
|
|
55
|
+
"vite": "^4.0.4",
|
|
58
56
|
"vite-plugin-banner": "^0.7.0",
|
|
59
57
|
"vite-plugin-dts": "^1.7.1",
|
|
60
|
-
"vite-plugin-glsl": "^1.0
|
|
58
|
+
"vite-plugin-glsl": "^1.1.0",
|
|
61
59
|
"vite-plugin-require-transform": "^1.0.4",
|
|
62
60
|
"vitest": "^0.25.8",
|
|
63
61
|
"vue-demi": "^0.13.11"
|
|
@@ -70,9 +68,6 @@
|
|
|
70
68
|
"test:ci": "vitest run",
|
|
71
69
|
"test:ui": "vitest --ui",
|
|
72
70
|
"coverage": "vitest run --coverage",
|
|
73
|
-
"story:dev": "histoire dev",
|
|
74
|
-
"story:build": "histoire build",
|
|
75
|
-
"story:preview": "histoire preview",
|
|
76
71
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue",
|
|
77
72
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
|
|
78
73
|
}
|