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