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