@tresjs/core 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/useLoader/index.d.ts +12 -17
- package/dist/models/AkuAku.gltf +1177 -0
- package/dist/tres.js +205 -185
- package/dist/tres.umd.cjs +2 -2
- package/package.json +2 -2
package/dist/tres.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v0.
|
|
3
|
+
* version: v0.5.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
|
|
9
|
-
import { useWindowSize as
|
|
10
|
-
import * as
|
|
11
|
-
import { PerspectiveCamera as I, OrthographicCamera as
|
|
12
|
-
var
|
|
13
|
-
const
|
|
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 = {
|
|
14
14
|
cameras: []
|
|
15
|
-
},
|
|
16
|
-
let
|
|
17
|
-
function
|
|
18
|
-
const { width: e, height: t } =
|
|
19
|
-
function
|
|
20
|
-
if (
|
|
21
|
-
const { near:
|
|
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 || {
|
|
22
22
|
near: 0.1,
|
|
23
23
|
far: 1e3,
|
|
24
|
-
fov:
|
|
24
|
+
fov: Re
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
S = new I(f, a.value, p, d), x.cameras.push(S);
|
|
27
27
|
} else {
|
|
28
|
-
const { left:
|
|
28
|
+
const { left: p, right: d, top: f, bottom: m, near: y, far: M } = s || {
|
|
29
29
|
left: -100,
|
|
30
30
|
right: 100,
|
|
31
31
|
top: 100,
|
|
@@ -33,251 +33,270 @@ function Z() {
|
|
|
33
33
|
near: 0.1,
|
|
34
34
|
far: 1e3
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
S = new we(p, d, f, m, y, M), x.cameras.push(S);
|
|
37
37
|
}
|
|
38
|
-
return
|
|
38
|
+
return x.cameras.push(S), S;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
40
|
+
const a = j(() => e.value / t.value), n = j(() => x.cameras[0]);
|
|
41
41
|
function o() {
|
|
42
|
-
n.value instanceof I && (n.value.aspect =
|
|
42
|
+
n.value instanceof I && (n.value.aspect = a.value), n.value.updateProjectionMatrix();
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
|
|
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();
|
|
47
47
|
}
|
|
48
|
-
return
|
|
48
|
+
return O(a, o), {
|
|
49
49
|
activeCamera: n,
|
|
50
|
-
createCamera:
|
|
50
|
+
createCamera: r,
|
|
51
51
|
updateCamera: o,
|
|
52
|
-
pushCamera:
|
|
52
|
+
pushCamera: u
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
let
|
|
56
|
-
delete
|
|
57
|
-
function
|
|
55
|
+
let T = { ...he };
|
|
56
|
+
delete T.Scene;
|
|
57
|
+
function Te() {
|
|
58
58
|
return {
|
|
59
59
|
extend: (t) => {
|
|
60
|
-
|
|
60
|
+
T = Object.assign(T, t);
|
|
61
61
|
},
|
|
62
|
-
catalogue:
|
|
62
|
+
catalogue: T
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
const
|
|
66
|
-
function
|
|
67
|
-
return typeof e == "number" ? [e, e, e] : e instanceof
|
|
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;
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function K(e) {
|
|
70
70
|
return e instanceof z ? e : Array.isArray(e) ? new z(...e) : new z(e);
|
|
71
71
|
}
|
|
72
|
-
const
|
|
73
|
-
function
|
|
74
|
-
function e(
|
|
75
|
-
console.error(`${
|
|
72
|
+
const Q = "[TresJS \u25B2 \u25A0 \u25CF] ";
|
|
73
|
+
function W() {
|
|
74
|
+
function e(a, n) {
|
|
75
|
+
console.error(`${Q} ${a}`, n || "");
|
|
76
76
|
}
|
|
77
|
-
function t(
|
|
78
|
-
console.warn(`${
|
|
77
|
+
function t(a) {
|
|
78
|
+
console.warn(`${Q} ${a}`);
|
|
79
79
|
}
|
|
80
|
-
function a
|
|
80
|
+
function r(a, n) {
|
|
81
81
|
}
|
|
82
82
|
return {
|
|
83
83
|
logError: e,
|
|
84
84
|
logWarning: t,
|
|
85
|
-
logMessage:
|
|
85
|
+
logMessage: r
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
const Be = ["rotation", "scale", "position"];
|
|
89
|
-
function
|
|
90
|
-
const { catalogue: e } =
|
|
91
|
-
function
|
|
89
|
+
function Ie() {
|
|
90
|
+
const { catalogue: e } = Te(), { logMessage: t, logError: r } = W();
|
|
91
|
+
function a() {
|
|
92
92
|
return Object.entries(e).filter(([n, o]) => {
|
|
93
|
-
var
|
|
94
|
-
return (
|
|
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
95
|
}).map(([n, o]) => {
|
|
96
|
-
const
|
|
96
|
+
const u = _({
|
|
97
97
|
name: n,
|
|
98
|
-
setup(
|
|
98
|
+
setup(i, { slots: s, attrs: p, ...d }) {
|
|
99
99
|
t(n, {
|
|
100
|
-
props:
|
|
101
|
-
slots:
|
|
102
|
-
attrs:
|
|
100
|
+
props: i,
|
|
101
|
+
slots: s,
|
|
102
|
+
attrs: p,
|
|
103
103
|
ctx: d
|
|
104
104
|
});
|
|
105
|
-
let
|
|
106
|
-
const { scene:
|
|
107
|
-
function
|
|
108
|
-
if ((
|
|
109
|
-
const C =
|
|
110
|
-
var
|
|
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
111
|
let w;
|
|
112
|
-
return (
|
|
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
113
|
});
|
|
114
|
-
|
|
114
|
+
f = new o(...C);
|
|
115
115
|
} else
|
|
116
|
-
|
|
117
|
-
|
|
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
118
|
}
|
|
119
|
-
function
|
|
120
|
-
Object.entries(C).forEach(([w,
|
|
121
|
-
const
|
|
122
|
-
if (!(
|
|
123
|
-
Be.includes(w) &&
|
|
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
124
|
try {
|
|
125
|
-
c[
|
|
126
|
-
} catch (
|
|
127
|
-
|
|
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
128
|
}
|
|
129
129
|
}
|
|
130
130
|
}), C.ref && (C.ref = c);
|
|
131
131
|
}
|
|
132
|
-
return
|
|
132
|
+
return M(), () => {
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
135
|
});
|
|
136
|
-
return [n,
|
|
136
|
+
return [n, u];
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
return {
|
|
140
|
-
createComponentInstances:
|
|
140
|
+
createComponentInstances: a
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
|
-
const
|
|
143
|
+
const ee = U(), te = U(), ne = U(), X = new ve(), { pause: ze, resume: Fe, isActive: je } = me(
|
|
144
144
|
() => {
|
|
145
|
-
const e =
|
|
146
|
-
|
|
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 });
|
|
147
147
|
},
|
|
148
148
|
{ immediate: !1 }
|
|
149
149
|
);
|
|
150
|
-
function
|
|
150
|
+
function re() {
|
|
151
151
|
return {
|
|
152
|
-
onBeforeLoop:
|
|
153
|
-
onLoop:
|
|
154
|
-
onAfterLoop:
|
|
155
|
-
pause:
|
|
156
|
-
resume:
|
|
157
|
-
isActive:
|
|
152
|
+
onBeforeLoop: ee.on,
|
|
153
|
+
onLoop: te.on,
|
|
154
|
+
onAfterLoop: ne.on,
|
|
155
|
+
pause: ze,
|
|
156
|
+
resume: Fe,
|
|
157
|
+
isActive: je
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
|
-
const
|
|
161
|
-
function
|
|
160
|
+
const De = $(new ye());
|
|
161
|
+
function ae() {
|
|
162
162
|
return {
|
|
163
|
-
scene:
|
|
163
|
+
scene: De
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
|
-
function
|
|
167
|
-
const
|
|
168
|
-
return
|
|
166
|
+
function _e(e) {
|
|
167
|
+
const t = { nodes: {}, materials: {} };
|
|
168
|
+
return e && e.traverse((r) => {
|
|
169
|
+
r.name && (t.nodes[r.name] = r), r.material && !t.materials[r.material.name] && (t.materials[r.material.name] = r.material);
|
|
170
|
+
}), t;
|
|
171
|
+
}
|
|
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);
|
|
181
|
+
},
|
|
182
|
+
a,
|
|
183
|
+
(m) => f(o("[useLoader] - Failed to load resource", m))
|
|
184
|
+
);
|
|
185
|
+
})
|
|
186
|
+
);
|
|
187
|
+
return V(t) ? await Promise.all(s) : await s[0];
|
|
169
188
|
}
|
|
170
|
-
async function
|
|
171
|
-
const t = new
|
|
172
|
-
|
|
189
|
+
async function Je(e) {
|
|
190
|
+
const t = new Me(), r = new Se(t), a = (n) => new Promise((o, u) => {
|
|
191
|
+
r.load(
|
|
173
192
|
n,
|
|
174
|
-
(
|
|
193
|
+
(i) => o(i),
|
|
175
194
|
() => null,
|
|
176
195
|
() => {
|
|
177
|
-
|
|
196
|
+
u(new Error("[useTextures] - Failed to load texture"));
|
|
178
197
|
}
|
|
179
198
|
);
|
|
180
199
|
});
|
|
181
|
-
if (
|
|
182
|
-
const n = await Promise.all(e.map((o) =>
|
|
200
|
+
if (V(e)) {
|
|
201
|
+
const n = await Promise.all(e.map((o) => a(o)));
|
|
183
202
|
return e.length > 1 ? n : n[0];
|
|
184
203
|
} else {
|
|
185
|
-
const { map: n, displacementMap: o, normalMap:
|
|
204
|
+
const { map: n, displacementMap: o, normalMap: u, roughnessMap: i, metalnessMap: s, aoMap: p } = e;
|
|
186
205
|
return {
|
|
187
|
-
map: n ? await
|
|
188
|
-
displacementMap: o ? await
|
|
189
|
-
normalMap:
|
|
190
|
-
roughnessMap:
|
|
191
|
-
metalnessMap:
|
|
192
|
-
aoMap:
|
|
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
|
|
193
212
|
};
|
|
194
213
|
}
|
|
195
214
|
}
|
|
196
|
-
const L =
|
|
197
|
-
function
|
|
198
|
-
function e(
|
|
199
|
-
return L[
|
|
215
|
+
const L = pe({});
|
|
216
|
+
function qe() {
|
|
217
|
+
function e(r) {
|
|
218
|
+
return L[r];
|
|
200
219
|
}
|
|
201
|
-
function t(
|
|
202
|
-
L[
|
|
220
|
+
function t(r, a) {
|
|
221
|
+
L[r] = a;
|
|
203
222
|
}
|
|
204
223
|
return {
|
|
205
224
|
state: L,
|
|
206
|
-
...
|
|
225
|
+
...le(L),
|
|
207
226
|
getState: e,
|
|
208
227
|
setState: t
|
|
209
228
|
};
|
|
210
229
|
}
|
|
211
|
-
const
|
|
212
|
-
function
|
|
230
|
+
const l = $(), F = D(!1);
|
|
231
|
+
function $e(e, t, r) {
|
|
213
232
|
const {
|
|
214
|
-
alpha:
|
|
233
|
+
alpha: a = !1,
|
|
215
234
|
antialias: n,
|
|
216
235
|
depth: o,
|
|
217
|
-
logarithmicDepthBuffer:
|
|
218
|
-
failIfMajorPerformanceCaveat:
|
|
219
|
-
precision:
|
|
220
|
-
premultipliedAlpha:
|
|
236
|
+
logarithmicDepthBuffer: u,
|
|
237
|
+
failIfMajorPerformanceCaveat: i,
|
|
238
|
+
precision: s,
|
|
239
|
+
premultipliedAlpha: p,
|
|
221
240
|
stencil: d,
|
|
222
|
-
shadows:
|
|
223
|
-
shadowMapType:
|
|
224
|
-
physicallyCorrectLights:
|
|
225
|
-
outputEncoding:
|
|
226
|
-
toneMapping:
|
|
241
|
+
shadows: f = !1,
|
|
242
|
+
shadowMapType: m = Ee,
|
|
243
|
+
physicallyCorrectLights: y = !1,
|
|
244
|
+
outputEncoding: M = Pe,
|
|
245
|
+
toneMapping: E = xe,
|
|
227
246
|
toneMappingExposure: C = 1,
|
|
228
247
|
context: c = void 0,
|
|
229
248
|
powerPreference: w = "default",
|
|
230
|
-
preserveDrawingBuffer:
|
|
231
|
-
clearColor:
|
|
232
|
-
windowSize:
|
|
233
|
-
} =
|
|
234
|
-
!
|
|
235
|
-
},
|
|
236
|
-
!
|
|
237
|
-
},
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
canvas:
|
|
241
|
-
alpha:
|
|
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,
|
|
260
|
+
alpha: a,
|
|
242
261
|
antialias: n,
|
|
243
262
|
context: c,
|
|
244
263
|
depth: o,
|
|
245
|
-
failIfMajorPerformanceCaveat:
|
|
246
|
-
logarithmicDepthBuffer:
|
|
264
|
+
failIfMajorPerformanceCaveat: i,
|
|
265
|
+
logarithmicDepthBuffer: u,
|
|
247
266
|
powerPreference: w,
|
|
248
|
-
precision:
|
|
267
|
+
precision: s,
|
|
249
268
|
stencil: d,
|
|
250
|
-
preserveDrawingBuffer:
|
|
251
|
-
premultipliedAlpha:
|
|
252
|
-
}),
|
|
253
|
-
},
|
|
254
|
-
!
|
|
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());
|
|
255
274
|
};
|
|
256
|
-
return
|
|
275
|
+
return O([b, A, H], N), O(
|
|
257
276
|
() => [
|
|
277
|
+
f,
|
|
258
278
|
m,
|
|
259
|
-
h,
|
|
260
|
-
S,
|
|
261
279
|
M,
|
|
262
|
-
|
|
280
|
+
y,
|
|
281
|
+
E,
|
|
263
282
|
C,
|
|
264
|
-
|
|
283
|
+
h
|
|
265
284
|
],
|
|
266
|
-
|
|
267
|
-
),
|
|
285
|
+
G
|
|
286
|
+
), O(
|
|
268
287
|
() => [e, t],
|
|
269
288
|
() => {
|
|
270
|
-
|
|
289
|
+
B(e) && B(t) && ce();
|
|
271
290
|
},
|
|
272
291
|
{ immediate: !0, deep: !0 }
|
|
273
292
|
), {
|
|
274
|
-
renderer:
|
|
275
|
-
isReady:
|
|
276
|
-
dispose:
|
|
277
|
-
aspectRatio:
|
|
293
|
+
renderer: l,
|
|
294
|
+
isReady: F,
|
|
295
|
+
dispose: ue,
|
|
296
|
+
aspectRatio: ie
|
|
278
297
|
};
|
|
279
298
|
}
|
|
280
|
-
const
|
|
299
|
+
const Ue = _({
|
|
281
300
|
name: "TresCanvas",
|
|
282
301
|
props: {
|
|
283
302
|
shadows: Boolean,
|
|
@@ -292,13 +311,13 @@ const $e = _({
|
|
|
292
311
|
clearColor: String,
|
|
293
312
|
windowSize: Boolean
|
|
294
313
|
},
|
|
295
|
-
setup(e, { slots: t, attrs:
|
|
296
|
-
const { logError:
|
|
297
|
-
return
|
|
314
|
+
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(
|
|
298
317
|
(d) => d.type.name === "PerspectiveCamera" || d.type.name === "OrtographicCamera"
|
|
299
|
-
) &&
|
|
318
|
+
) && a("Scene must contain a Camera component."), fe(() => i()), () => {
|
|
300
319
|
if (t.default)
|
|
301
|
-
return
|
|
320
|
+
return q(
|
|
302
321
|
"div",
|
|
303
322
|
{
|
|
304
323
|
ref: o,
|
|
@@ -306,11 +325,11 @@ const $e = _({
|
|
|
306
325
|
position: "relative",
|
|
307
326
|
width: "100%",
|
|
308
327
|
height: "100vh",
|
|
309
|
-
...
|
|
328
|
+
...r.style
|
|
310
329
|
}
|
|
311
330
|
},
|
|
312
331
|
[
|
|
313
|
-
|
|
332
|
+
q("canvas", {
|
|
314
333
|
ref: n,
|
|
315
334
|
style: { width: "100%", height: "100%", position: "absolute", top: 0, left: 0 }
|
|
316
335
|
}),
|
|
@@ -319,37 +338,38 @@ const $e = _({
|
|
|
319
338
|
);
|
|
320
339
|
};
|
|
321
340
|
}
|
|
322
|
-
}),
|
|
341
|
+
}), Ve = _({
|
|
323
342
|
name: "Scene",
|
|
324
343
|
setup(e, { slots: t }) {
|
|
325
|
-
const { scene:
|
|
326
|
-
return
|
|
327
|
-
(
|
|
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);
|
|
328
347
|
}), () => {
|
|
329
348
|
if (t.default)
|
|
330
349
|
return t.default();
|
|
331
350
|
};
|
|
332
351
|
}
|
|
333
|
-
}),
|
|
352
|
+
}), Ke = Symbol("UseTresState"), Qe = {
|
|
334
353
|
install(e) {
|
|
335
|
-
e.component("TresCanvas",
|
|
336
|
-
const { createComponentInstances: t } =
|
|
337
|
-
t().forEach(([
|
|
338
|
-
e.component(
|
|
354
|
+
e.component("TresCanvas", Ue), e.component("Scene", Ve);
|
|
355
|
+
const { createComponentInstances: t } = Ie();
|
|
356
|
+
t().forEach(([a, n]) => {
|
|
357
|
+
e.component(a, n);
|
|
339
358
|
});
|
|
340
359
|
}
|
|
341
360
|
};
|
|
342
361
|
export {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
Je as
|
|
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
|
|
355
375
|
};
|
package/dist/tres.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v0.
|
|
3
|
+
* version: v0.5.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,
|
|
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"}})});
|
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.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
7
7
|
"files": [
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@alvarosabu/utils": "^2.2.0",
|
|
40
40
|
"@histoire/plugin-vue": "0.11.7",
|
|
41
|
-
"@tresjs/cientos": "^0.
|
|
41
|
+
"@tresjs/cientos": "^0.4.0",
|
|
42
42
|
"@vitejs/plugin-vue": "^3.2.0",
|
|
43
43
|
"@vitest/coverage-c8": "^0.25.1",
|
|
44
44
|
"@vitest/ui": "^0.25.1",
|