@tresjs/core 1.8.0 → 2.0.0-alpha.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/components/TresCanvas.d.ts +19 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/composables/index.d.ts +7 -0
- package/dist/{core → composables}/useTexture/index.d.ts +1 -3
- package/dist/{core → composables}/useTres/index.d.ts +1 -1
- package/dist/core/catalogue.d.ts +9 -0
- package/dist/core/nodeOps.d.ts +3 -0
- package/dist/core/renderer.d.ts +10 -0
- package/dist/index.d.ts +3 -3
- package/dist/tres.js +376 -453
- package/dist/tres.umd.cjs +2 -2
- package/dist/types/index.d.ts +35 -0
- package/dist/types/tres-components.d.ts +270 -0
- package/dist/utils/index.d.ts +3 -0
- package/package.json +41 -19
- package/dist/core/index.d.ts +0 -10
- package/dist/core/useCatalogue/index.d.ts +0 -20
- package/dist/core/useInstanceCreator/index.d.ts +0 -14
- package/dist/core/useRenderer/component.d.ts +0 -53
- package/dist/core/useScene/component.d.ts +0 -6
- package/dist/core/useScene/index.d.ts +0 -10
- package/dist/env.d.ts +0 -11
- package/dist/keys.d.ts +0 -1
- /package/dist/{core → composables}/useCamera/index.d.ts +0 -0
- /package/dist/{core → composables}/useLoader/index.d.ts +0 -0
- /package/dist/{core → composables}/useRaycaster/index.d.ts +0 -0
- /package/dist/{core → composables}/useRenderLoop/index.d.ts +0 -0
- /package/dist/{core → composables}/useRenderer/const.d.ts +0 -0
- /package/dist/{core → composables}/useRenderer/index.d.ts +0 -0
package/dist/tres.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version:
|
|
3
|
+
* version: v2.0.0-alpha.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
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
import { ref as y, watchEffect as Ee, toRef as xe, shallowRef as ne, toRefs as ae, computed as re, watch as T, shallowReactive as Pe, createRenderer as Re, defineComponent as Se, h as x } from "vue";
|
|
9
|
+
import * as oe from "three";
|
|
10
|
+
import { MathUtils as Te, PerspectiveCamera as _, OrthographicCamera as Oe, Clock as ie, Color as W, sRGBEncoding as Ae, ACESFilmicToneMapping as ke, PCFSoftShadowMap as je, PCFShadowMap as De, LinearEncoding as Y, NoToneMapping as Q, WebGLRenderer as Fe, LoadingManager as _e, TextureLoader as We, Raycaster as ze, Vector2 as Be, Mesh as Ie } from "three";
|
|
11
|
+
import { createEventHook as U, useRafFn as He, resolveUnref as u, useWindowSize as Ge, useElementSize as Ue, useDevicePixelRatio as Ve, unrefElement as z, useEventListener as $e, isFunction as Z } from "@vueuse/core";
|
|
12
|
+
const G = y({ uuid: Te.generateUUID() }), se = (e) => void Object.assign(G.value, e);
|
|
13
|
+
var Ne = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Ne || {});
|
|
14
|
+
const qe = 45;
|
|
15
|
+
let h;
|
|
16
|
+
function ce() {
|
|
17
|
+
const { state: e, setState: t, aspectRatio: r } = k();
|
|
18
|
+
function o(a = "Perspective", s) {
|
|
19
|
+
var l, f, d;
|
|
20
|
+
if (a === "Perspective") {
|
|
21
|
+
const { near: m, far: g, fov: v } = s || {
|
|
21
22
|
near: 0.1,
|
|
22
23
|
far: 1e3,
|
|
23
|
-
fov:
|
|
24
|
+
fov: qe
|
|
24
25
|
};
|
|
25
|
-
|
|
26
|
+
h = new _(v, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, m, g), (f = e.cameras) == null || f.push(h);
|
|
26
27
|
} else {
|
|
27
|
-
const { left:
|
|
28
|
+
const { left: m, right: g, top: v, bottom: b, near: L, far: E } = s || {
|
|
28
29
|
left: -100,
|
|
29
30
|
right: 100,
|
|
30
31
|
top: 100,
|
|
@@ -32,501 +33,423 @@ function Se() {
|
|
|
32
33
|
near: 0.1,
|
|
33
34
|
far: 1e3
|
|
34
35
|
};
|
|
35
|
-
|
|
36
|
+
h = new Oe(m, g, v, b, L, E), (d = e.cameras) == null || d.push(h);
|
|
36
37
|
}
|
|
37
|
-
return e.camera =
|
|
38
|
+
return e.camera = h, t("camera", e.camera), h;
|
|
38
39
|
}
|
|
39
|
-
function
|
|
40
|
-
var
|
|
41
|
-
e.camera instanceof
|
|
40
|
+
function n() {
|
|
41
|
+
var a;
|
|
42
|
+
e.camera instanceof _ && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (a = e.camera) == null || a.updateProjectionMatrix();
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
-
var
|
|
45
|
-
(
|
|
44
|
+
function i(a) {
|
|
45
|
+
var s;
|
|
46
|
+
(s = e.cameras) == null || s.push(a), a instanceof _ && e.aspectRatio && (a.aspect = e.aspectRatio.value), a.updateProjectionMatrix(), t("camera", a);
|
|
46
47
|
}
|
|
47
|
-
function
|
|
48
|
+
function c() {
|
|
48
49
|
e.cameras = [];
|
|
49
50
|
}
|
|
50
|
-
return
|
|
51
|
-
|
|
51
|
+
return Ee(() => {
|
|
52
|
+
r != null && r.value && n();
|
|
53
|
+
}), {
|
|
54
|
+
activeCamera: xe(e, "camera"),
|
|
52
55
|
createCamera: o,
|
|
53
|
-
updateCamera:
|
|
54
|
-
pushCamera:
|
|
55
|
-
clearCameras:
|
|
56
|
+
updateCamera: n,
|
|
57
|
+
pushCamera: i,
|
|
58
|
+
clearCameras: c
|
|
56
59
|
};
|
|
57
60
|
}
|
|
58
|
-
const ue =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
const ue = U(), le = U(), V = U(), C = new ie();
|
|
62
|
+
let O = 0, A = 0;
|
|
63
|
+
const { pause: Je, resume: Ke, isActive: Xe } = He(
|
|
64
|
+
() => {
|
|
65
|
+
ue.trigger({ delta: O, elapsed: A, clock: C }), le.trigger({ delta: O, elapsed: A, clock: C }), V.trigger({ delta: O, elapsed: A, clock: C });
|
|
66
|
+
},
|
|
67
|
+
{ immediate: !1 }
|
|
68
|
+
);
|
|
69
|
+
V.on(() => {
|
|
70
|
+
O = C.getDelta(), A = C.getElapsedTime();
|
|
71
|
+
});
|
|
72
|
+
function $() {
|
|
68
73
|
return {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
onBeforeLoop: ue.on,
|
|
75
|
+
onLoop: le.on,
|
|
76
|
+
onAfterLoop: V.on,
|
|
77
|
+
pause: Je,
|
|
78
|
+
resume: Ke,
|
|
79
|
+
isActive: Xe
|
|
72
80
|
};
|
|
73
81
|
}
|
|
74
|
-
|
|
75
|
-
|
|
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);
|
|
81
|
-
return {
|
|
82
|
-
extend: (d) => {
|
|
83
|
-
if (!d) {
|
|
84
|
-
o("No objects provided to extend catalogue");
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
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);
|
|
91
|
-
});
|
|
92
|
-
},
|
|
93
|
-
catalogue: D
|
|
94
|
-
};
|
|
82
|
+
function Ye(e) {
|
|
83
|
+
return e instanceof W ? e : Array.isArray(e) ? new W(...e) : new W(e);
|
|
95
84
|
}
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
85
|
+
const B = {
|
|
86
|
+
realistic: {
|
|
87
|
+
outputEncoding: Ae,
|
|
88
|
+
toneMapping: ke,
|
|
89
|
+
toneMappingExposure: 3,
|
|
90
|
+
shadowMap: {
|
|
91
|
+
enabled: !0,
|
|
92
|
+
type: je
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, fe = (e, t) => {
|
|
96
|
+
for (const r of Object.keys(t))
|
|
97
|
+
t[r] instanceof Object && Object.assign(t[r], fe(e[r], t[r]));
|
|
98
|
+
return Object.assign(e || {}, t), e;
|
|
99
|
+
}, Qe = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot", Ze = /* @__PURE__ */ et(Qe);
|
|
100
|
+
function I(e) {
|
|
101
|
+
return e.replace(/-([a-z])/g, (t, r) => r.toUpperCase());
|
|
99
102
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
103
|
+
function et(e, t) {
|
|
104
|
+
const r = /* @__PURE__ */ Object.create(null), o = e.split(",");
|
|
105
|
+
for (let n = 0; n < o.length; n++)
|
|
106
|
+
r[o[n]] = !0;
|
|
107
|
+
return t ? (n) => !!r[n.toLowerCase()] : (n) => !!r[n];
|
|
102
108
|
}
|
|
103
|
-
const
|
|
104
|
-
function
|
|
109
|
+
const p = ne(), H = y(!1);
|
|
110
|
+
function tt(e, t, r) {
|
|
105
111
|
const {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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;
|
|
141
|
-
else {
|
|
142
|
-
if (s === "" && (s = !0), tt(r[i])) {
|
|
143
|
-
if (l === "center" && !s)
|
|
144
|
-
return;
|
|
145
|
-
r[i](...N(s) ? s : [s]);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
r[i] = s;
|
|
149
|
-
}
|
|
150
|
-
} catch (m) {
|
|
151
|
-
n(`There was an error setting ${i} property`, m);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
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()))
|
|
112
|
+
alpha: o = !0,
|
|
113
|
+
antialias: n = !0,
|
|
114
|
+
depth: i,
|
|
115
|
+
logarithmicDepthBuffer: c,
|
|
116
|
+
failIfMajorPerformanceCaveat: a,
|
|
117
|
+
precision: s,
|
|
118
|
+
premultipliedAlpha: l,
|
|
119
|
+
stencil: f,
|
|
120
|
+
shadows: d = !1,
|
|
121
|
+
shadowMapType: m = De,
|
|
122
|
+
physicallyCorrectLights: g = !1,
|
|
123
|
+
useLegacyLights: v = !1,
|
|
124
|
+
outputEncoding: b = Y,
|
|
125
|
+
toneMapping: L = Q,
|
|
126
|
+
toneMappingExposure: E = 1,
|
|
127
|
+
context: de = void 0,
|
|
128
|
+
powerPreference: ve = "default",
|
|
129
|
+
preserveDrawingBuffer: ge = !1,
|
|
130
|
+
clearColor: M,
|
|
131
|
+
windowSize: we = !1,
|
|
132
|
+
preset: he = void 0
|
|
133
|
+
} = ae(r), { setState: D } = k(), { width: N, height: q } = u(we) ? Ge() : Ue(t), { logError: ye } = j(), { pixelRatio: J } = Ve(), { pause: Me, resume: Ce } = $(), F = re(() => N.value / q.value), K = () => {
|
|
134
|
+
p.value && (p.value.setSize(N.value, q.value), p.value.setPixelRatio(Math.min(J.value, 2)));
|
|
135
|
+
}, X = () => {
|
|
136
|
+
if (!p.value)
|
|
137
|
+
return;
|
|
138
|
+
const w = u(he);
|
|
139
|
+
if (w) {
|
|
140
|
+
w in B || ye("Renderer Preset must be one of these: " + Object.keys(B).join(", ")), fe(p.value, B[w]);
|
|
162
141
|
return;
|
|
163
|
-
{
|
|
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));
|
|
170
|
-
} else
|
|
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;
|
|
173
142
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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;
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
const _ = Ie(window, "click", () => {
|
|
208
|
-
p.emit("click", E);
|
|
209
|
-
});
|
|
210
|
-
ge(() => {
|
|
211
|
-
_();
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
return S && y instanceof We && (S.fog = y), p.expose(y), () => {
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
return [s, i];
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
createComponentInstances: u,
|
|
223
|
-
processProps: a,
|
|
224
|
-
createInstanceFromVNode: c
|
|
143
|
+
p.value.shadowMap.enabled = u(d), p.value.shadowMap.type = u(m), p.value.toneMapping = u(L) || Q, p.value.toneMappingExposure = u(E), p.value.outputEncoding = u(b) || Y, M != null && M.value && p.value.setClearColor(Ye(u(M))), p.value.useLegacyLights = u(v);
|
|
144
|
+
}, be = () => {
|
|
145
|
+
const w = z(e);
|
|
146
|
+
w && (p.value = new Fe({
|
|
147
|
+
canvas: w,
|
|
148
|
+
alpha: u(o),
|
|
149
|
+
antialias: u(n),
|
|
150
|
+
context: u(de),
|
|
151
|
+
depth: u(i),
|
|
152
|
+
failIfMajorPerformanceCaveat: u(a),
|
|
153
|
+
logarithmicDepthBuffer: u(c),
|
|
154
|
+
powerPreference: u(ve),
|
|
155
|
+
precision: u(s),
|
|
156
|
+
stencil: u(f),
|
|
157
|
+
preserveDrawingBuffer: u(ge),
|
|
158
|
+
premultipliedAlpha: u(l)
|
|
159
|
+
}), D("renderer", p.value), D("clock", new ie()), D("aspectRatio", F), X(), K(), Ce(), H.value = !0);
|
|
160
|
+
}, Le = () => {
|
|
161
|
+
p.value && (p.value.dispose(), p.value = void 0, H.value = !1, Me());
|
|
225
162
|
};
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
onBeforeLoop: Re.on,
|
|
241
|
-
onLoop: Me.on,
|
|
242
|
-
onAfterLoop: ne.on,
|
|
243
|
-
pause: st,
|
|
244
|
-
resume: ct,
|
|
245
|
-
isActive: lt
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
const ut = ee(new Ne());
|
|
249
|
-
function ft() {
|
|
250
|
-
return {
|
|
251
|
-
scene: ut
|
|
163
|
+
return T([F, J], K), T(
|
|
164
|
+
[d, m, b, v, L, E, M],
|
|
165
|
+
X
|
|
166
|
+
), T(
|
|
167
|
+
() => [e, t],
|
|
168
|
+
() => {
|
|
169
|
+
z(e) && z(t) && be();
|
|
170
|
+
},
|
|
171
|
+
{ immediate: !0, deep: !0 }
|
|
172
|
+
), {
|
|
173
|
+
renderer: p,
|
|
174
|
+
isReady: H,
|
|
175
|
+
dispose: Le,
|
|
176
|
+
aspectRatio: F
|
|
252
177
|
};
|
|
253
178
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
179
|
+
const pe = (e) => !!e && e.constructor === Array;
|
|
180
|
+
function nt(e) {
|
|
181
|
+
const t = { nodes: {}, materials: {} };
|
|
182
|
+
return e && e.traverse((r) => {
|
|
183
|
+
r.name && (t.nodes[r.name] = r), r.material && !t.materials[r.material.name] && (t.materials[r.material.name] = r.material);
|
|
184
|
+
}), t;
|
|
259
185
|
}
|
|
260
|
-
async function
|
|
261
|
-
const { logError:
|
|
262
|
-
|
|
263
|
-
const
|
|
264
|
-
(l) => new Promise((
|
|
265
|
-
|
|
186
|
+
async function dt(e, t, r, o, n) {
|
|
187
|
+
const { logError: i } = j(), c = new e();
|
|
188
|
+
n && n(c), r && r(c);
|
|
189
|
+
const s = (Array.isArray(t) ? t : [t]).map(
|
|
190
|
+
(l) => new Promise((f, d) => {
|
|
191
|
+
c.load(
|
|
266
192
|
l,
|
|
267
|
-
(
|
|
268
|
-
|
|
193
|
+
(m) => {
|
|
194
|
+
m.scene && Object.assign(m, nt(m.scene)), f(m);
|
|
269
195
|
},
|
|
270
|
-
|
|
271
|
-
(
|
|
196
|
+
o,
|
|
197
|
+
(m) => d(i("[useLoader] - Failed to load resource", m))
|
|
272
198
|
);
|
|
273
199
|
})
|
|
274
200
|
);
|
|
275
|
-
return
|
|
201
|
+
return pe(t) ? await Promise.all(s) : await s[0];
|
|
276
202
|
}
|
|
277
|
-
async function
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
(
|
|
203
|
+
async function vt(e) {
|
|
204
|
+
const t = new _e(), r = new We(t), o = (n) => new Promise((i, c) => {
|
|
205
|
+
r.load(
|
|
206
|
+
n,
|
|
207
|
+
(a) => i(a),
|
|
282
208
|
() => null,
|
|
283
209
|
() => {
|
|
284
|
-
|
|
210
|
+
c(new Error("[useTextures] - Failed to load texture"));
|
|
285
211
|
}
|
|
286
212
|
);
|
|
287
213
|
});
|
|
288
|
-
if (
|
|
289
|
-
const
|
|
290
|
-
return e.length > 1 ?
|
|
214
|
+
if (pe(e)) {
|
|
215
|
+
const n = await Promise.all(e.map((i) => o(i)));
|
|
216
|
+
return e.length > 1 ? n : n[0];
|
|
291
217
|
} else {
|
|
292
|
-
const { map:
|
|
218
|
+
const { map: n, displacementMap: i, normalMap: c, roughnessMap: a, metalnessMap: s, aoMap: l } = e;
|
|
293
219
|
return {
|
|
294
|
-
map:
|
|
295
|
-
displacementMap:
|
|
296
|
-
normalMap:
|
|
297
|
-
roughnessMap:
|
|
298
|
-
metalnessMap:
|
|
299
|
-
aoMap: l ? await
|
|
220
|
+
map: n ? await o(n) : null,
|
|
221
|
+
displacementMap: i ? await o(i) : null,
|
|
222
|
+
normalMap: c ? await o(c) : null,
|
|
223
|
+
roughnessMap: a ? await o(a) : null,
|
|
224
|
+
metalnessMap: s ? await o(s) : null,
|
|
225
|
+
aoMap: l ? await o(l) : null
|
|
300
226
|
};
|
|
301
227
|
}
|
|
302
228
|
}
|
|
303
|
-
const
|
|
229
|
+
const P = Pe({
|
|
304
230
|
camera: void 0,
|
|
305
231
|
cameras: [],
|
|
306
|
-
aspectRatio:
|
|
232
|
+
aspectRatio: re(() => window.innerWidth / window.innerHeight)
|
|
307
233
|
});
|
|
308
|
-
function
|
|
309
|
-
function e(
|
|
310
|
-
return
|
|
234
|
+
function k() {
|
|
235
|
+
function e(r) {
|
|
236
|
+
return P[r];
|
|
311
237
|
}
|
|
312
|
-
function
|
|
313
|
-
|
|
238
|
+
function t(r, o) {
|
|
239
|
+
P[r] = o;
|
|
314
240
|
}
|
|
315
241
|
return {
|
|
316
|
-
state:
|
|
317
|
-
...
|
|
242
|
+
state: P,
|
|
243
|
+
...ae(P),
|
|
318
244
|
getState: e,
|
|
319
|
-
setState:
|
|
245
|
+
setState: t
|
|
320
246
|
};
|
|
321
247
|
}
|
|
322
|
-
const
|
|
323
|
-
function
|
|
324
|
-
const { setState: e } =
|
|
325
|
-
e("raycaster",
|
|
326
|
-
function
|
|
327
|
-
|
|
248
|
+
const ee = ne(new ze()), R = y(new Be()), at = y(null);
|
|
249
|
+
function me() {
|
|
250
|
+
const { setState: e } = k();
|
|
251
|
+
e("raycaster", ee.value), e("pointer", R), e("currentInstance", at);
|
|
252
|
+
function t(r) {
|
|
253
|
+
R.value.x = r.clientX / window.innerWidth * 2 - 1, R.value.y = -(r.clientY / window.innerHeight) * 2 + 1;
|
|
328
254
|
}
|
|
329
|
-
return window.addEventListener("pointermove",
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
raycaster: J,
|
|
333
|
-
pointer: A
|
|
255
|
+
return window.addEventListener("pointermove", t), {
|
|
256
|
+
raycaster: ee,
|
|
257
|
+
pointer: R
|
|
334
258
|
};
|
|
335
259
|
}
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
toneMappingExposure: 3,
|
|
341
|
-
shadowMap: {
|
|
342
|
-
enabled: !0,
|
|
343
|
-
type: Je
|
|
344
|
-
}
|
|
260
|
+
const gt = !0, te = "[TresJS ▲ ■ ●] ";
|
|
261
|
+
function j() {
|
|
262
|
+
function e(o, n) {
|
|
263
|
+
console.error(`${te} ${o}`, n || "");
|
|
345
264
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
depth: d,
|
|
356
|
-
logarithmicDepthBuffer: u,
|
|
357
|
-
failIfMajorPerformanceCaveat: t,
|
|
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)
|
|
378
|
-
return;
|
|
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)
|
|
402
|
-
});
|
|
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());
|
|
407
|
-
};
|
|
408
|
-
return j([H, oe], ae), j(
|
|
409
|
-
[i, f, p, v, m, L, y],
|
|
410
|
-
ie
|
|
411
|
-
), j(
|
|
412
|
-
() => [e, n],
|
|
413
|
-
() => {
|
|
414
|
-
X(e) && X(n) && Te();
|
|
415
|
-
},
|
|
416
|
-
{ immediate: !0, deep: !0 }
|
|
417
|
-
), {
|
|
418
|
-
renderer: w,
|
|
419
|
-
isReady: q,
|
|
420
|
-
dispose: $e,
|
|
421
|
-
aspectRatio: H
|
|
265
|
+
function t(o) {
|
|
266
|
+
console.warn(`${te} ${o}`);
|
|
267
|
+
}
|
|
268
|
+
function r(o, n) {
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
logError: e,
|
|
272
|
+
logWarning: t,
|
|
273
|
+
logMessage: r
|
|
422
274
|
};
|
|
423
275
|
}
|
|
424
|
-
const {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
276
|
+
const { logWarning: rt } = j();
|
|
277
|
+
function ot(e) {
|
|
278
|
+
for (const t in e)
|
|
279
|
+
if (t.indexOf("on") === 0)
|
|
280
|
+
return !0;
|
|
281
|
+
return !1;
|
|
282
|
+
}
|
|
283
|
+
let S = null;
|
|
284
|
+
const it = {
|
|
285
|
+
createElement(e, t, r, o) {
|
|
286
|
+
if (e === "template" || Ze(e))
|
|
287
|
+
return null;
|
|
288
|
+
let n;
|
|
289
|
+
if (o === null && (o = {}), o != null && o.args ? n = new G.value[e.replace("Tres", "")](...o.args) : n = new G.value[e.replace("Tres", "")](), n.isCamera) {
|
|
290
|
+
(!(o != null && o.position) || o != null && o.position.every((c) => c == 0)) && rt(
|
|
291
|
+
// eslint-disable-next-line max-len
|
|
292
|
+
"Camera is positioned at the center of the scene [0,0,0], if this is not intentional try setting a position if your scene seems empty 🤗"
|
|
293
|
+
);
|
|
294
|
+
const { pushCamera: i } = ce();
|
|
295
|
+
i(n);
|
|
296
|
+
}
|
|
297
|
+
return (o == null ? void 0 : o.attach) === void 0 && (n.isMaterial ? n.attach = "material" : n.isBufferGeometry && (n.attach = "geometry")), n;
|
|
298
|
+
},
|
|
299
|
+
insert(e, t, r) {
|
|
300
|
+
if (S === null && t.isScene && (S = t), t === null && (t = S), t != null && t.isObject3D && (e != null && e.isObject3D)) {
|
|
301
|
+
const a = r ? t.children.indexOf(r) : 0;
|
|
302
|
+
e.parent = t, t.children.splice(a, 0, e), e.dispatchEvent({ type: "added" });
|
|
303
|
+
} else
|
|
304
|
+
typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
|
|
305
|
+
const { onLoop: o } = $();
|
|
306
|
+
let n = null, i = null;
|
|
307
|
+
const { raycaster: c } = me();
|
|
308
|
+
e && e instanceof Ie && ot(e) && (o(() => {
|
|
309
|
+
var a, s, l;
|
|
310
|
+
if (t != null && t.children && e && c) {
|
|
311
|
+
const f = c.value.intersectObjects(t.children);
|
|
312
|
+
f.length > 0 && f[0].object.uuid === e.uuid ? (i = f[0], (n === null || n.object.uuid !== (i == null ? void 0 : i.object.uuid)) && ((a = e.onPointerEnter) == null || a.call(e, i)), (s = e.onPointerMove) == null || s.call(e, i)) : (i = null, n !== null && ((l = e.onPointerLeave) == null || l.call(e, n))), n = i;
|
|
313
|
+
}
|
|
314
|
+
}), $e(window, "click", () => {
|
|
315
|
+
var a;
|
|
316
|
+
i !== null && ((a = e.onClick) == null || a.call(e, i));
|
|
317
|
+
}));
|
|
318
|
+
},
|
|
319
|
+
remove(e) {
|
|
320
|
+
if (!e)
|
|
321
|
+
return;
|
|
322
|
+
const t = e.parentNode;
|
|
323
|
+
t && t.removeChild(e);
|
|
444
324
|
},
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
325
|
+
patchProp(e, t, r, o) {
|
|
326
|
+
if (e) {
|
|
327
|
+
let n = e, i = t;
|
|
328
|
+
const c = I(i);
|
|
329
|
+
let a = n == null ? void 0 : n[c];
|
|
330
|
+
if (e.parent || (e.parent = S), i.includes("-") && a === void 0) {
|
|
331
|
+
const l = i.split("-");
|
|
332
|
+
a = l.reduce((f, d) => f[I(d)], n), i = l.pop(), a != null && a.set || (n = l.reduce((f, d) => f[I(d)], n));
|
|
333
|
+
}
|
|
334
|
+
let s = o;
|
|
335
|
+
if (s === "" && (s = !0), Z(a))
|
|
336
|
+
return;
|
|
337
|
+
!(a != null && a.set) && !Z(a) ? n[c] = s : a.constructor === s.constructor && (a != null && a.copy) ? a == null || a.copy(s) : Array.isArray(s) ? a.set(...s) : !a.isColor && a.setScalar ? a.setScalar(s) : a.set(s);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
parentNode(e) {
|
|
341
|
+
return (e == null ? void 0 : e.parent) || null;
|
|
342
|
+
},
|
|
343
|
+
createText: () => void 0,
|
|
344
|
+
createComment: () => void 0,
|
|
345
|
+
setText: () => void 0,
|
|
346
|
+
setElementText: () => void 0,
|
|
347
|
+
nextSibling: () => void 0,
|
|
348
|
+
querySelector: () => void 0,
|
|
349
|
+
setScopeId: () => void 0,
|
|
350
|
+
cloneNode: () => void 0,
|
|
351
|
+
insertStaticContent: () => void 0
|
|
352
|
+
}, { createApp: st } = Re(it), ct = (e) => {
|
|
353
|
+
const t = st(r);
|
|
354
|
+
function r() {
|
|
355
|
+
return e && e.default ? e.default() : [];
|
|
356
|
+
}
|
|
357
|
+
return t;
|
|
358
|
+
};
|
|
359
|
+
se(oe);
|
|
360
|
+
const { logWarning: ut } = j(), lt = Se({
|
|
361
|
+
name: "TresCanvas",
|
|
362
|
+
props: [
|
|
363
|
+
"shadows",
|
|
364
|
+
"shadowMapType",
|
|
365
|
+
"physicallyCorrectLights",
|
|
366
|
+
"useLegacyLights",
|
|
367
|
+
"outputEncoding",
|
|
368
|
+
"toneMapping",
|
|
369
|
+
"toneMappingExposure",
|
|
370
|
+
"context",
|
|
371
|
+
"powerPreference",
|
|
372
|
+
"preserveDrawingBuffer",
|
|
373
|
+
"clearColor",
|
|
374
|
+
"windowSize",
|
|
375
|
+
"preset"
|
|
376
|
+
],
|
|
377
|
+
setup(e, { slots: t, expose: r }) {
|
|
378
|
+
e.physicallyCorrectLights === !0 && ut("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
|
|
379
|
+
const o = y(), n = y(), i = new oe.Scene();
|
|
380
|
+
function c() {
|
|
381
|
+
const { renderer: l } = tt(n, o, e), { activeCamera: f } = ce(), { onLoop: d } = $(), { raycaster: m, pointer: g } = me();
|
|
382
|
+
d(() => {
|
|
383
|
+
var v;
|
|
384
|
+
f.value && (m.value.setFromCamera(g.value, f.value), (v = l.value) == null || v.render(i, f.value));
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
T(n, c);
|
|
388
|
+
let a;
|
|
389
|
+
function s() {
|
|
390
|
+
a = ct(t), a.provide("useTres", k()), a.provide("extend", se), a.mount(i);
|
|
391
|
+
}
|
|
392
|
+
return s(), r({
|
|
393
|
+
scene: i
|
|
394
|
+
}), () => x(
|
|
395
|
+
x(
|
|
396
|
+
"div",
|
|
397
|
+
{
|
|
398
|
+
ref: o,
|
|
399
|
+
style: {
|
|
400
|
+
position: "relative",
|
|
401
|
+
width: "100%",
|
|
402
|
+
height: "100%",
|
|
403
|
+
pointerEvents: "auto",
|
|
404
|
+
touchAction: "none"
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
[
|
|
408
|
+
x(
|
|
409
|
+
"div",
|
|
410
|
+
{
|
|
411
|
+
style: {
|
|
412
|
+
width: "100%",
|
|
413
|
+
height: "100%"
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
[
|
|
417
|
+
x("canvas", {
|
|
418
|
+
ref: n,
|
|
470
419
|
style: {
|
|
420
|
+
display: "block",
|
|
471
421
|
width: "100%",
|
|
472
|
-
height: "100%"
|
|
422
|
+
height: "100%",
|
|
423
|
+
position: e.windowSize ? "fixed" : "absolute",
|
|
424
|
+
top: 0,
|
|
425
|
+
left: 0
|
|
473
426
|
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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
|
-
)
|
|
490
|
-
]
|
|
491
|
-
);
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
}), wt = Q({
|
|
495
|
-
name: "Scene",
|
|
496
|
-
setup(e, { slots: n }) {
|
|
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));
|
|
500
|
-
}), () => {
|
|
501
|
-
if (n.default)
|
|
502
|
-
return n.default();
|
|
503
|
-
};
|
|
427
|
+
})
|
|
428
|
+
]
|
|
429
|
+
)
|
|
430
|
+
]
|
|
431
|
+
)
|
|
432
|
+
);
|
|
504
433
|
}
|
|
505
|
-
}),
|
|
506
|
-
install(e
|
|
507
|
-
|
|
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
|
-
});
|
|
434
|
+
}), wt = {
|
|
435
|
+
install(e) {
|
|
436
|
+
e.component("TresCanvas", lt);
|
|
515
437
|
}
|
|
516
438
|
};
|
|
517
439
|
export {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
440
|
+
Ne as CameraType,
|
|
441
|
+
lt as TresCanvas,
|
|
442
|
+
G as catalogue,
|
|
443
|
+
wt as default,
|
|
444
|
+
se as extend,
|
|
445
|
+
gt as isProd,
|
|
446
|
+
nt as trasverseObjects,
|
|
447
|
+
ce as useCamera,
|
|
448
|
+
dt as useLoader,
|
|
449
|
+
j as useLogger,
|
|
450
|
+
me as useRaycaster,
|
|
451
|
+
$ as useRenderLoop,
|
|
452
|
+
tt as useRenderer,
|
|
453
|
+
vt as useTexture,
|
|
454
|
+
k as useTres
|
|
532
455
|
};
|