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