@tresjs/core 2.0.0-rc.4 → 2.1.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/README.md +6 -6
- package/components.d.ts +1 -0
- package/composables.d.ts +1 -0
- package/dist/components/TresCanvas.d.ts +2 -2
- package/dist/components/TresScene.d.ts +1 -1
- package/dist/composables/useTres/index.d.ts +1 -1
- package/dist/tres.js +227 -222
- package/dist/tres.umd.cjs +3 -3
- package/dist/types/index.d.ts +140 -59
- package/package.json +35 -32
- package/types.d.ts +1 -0
- package/utils.d.ts +1 -0
- package/dist/types/tres-components.d.ts +0 -272
package/dist/tres.js
CHANGED
|
@@ -1,31 +1,67 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v2.
|
|
3
|
+
* version: v2.1.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 { ref as E,
|
|
8
|
+
import { ref as E, shallowReactive as de, computed as me, toRefs as pe, provide as _e, inject as Oe, watchEffect as ve, toRef as ke, shallowRef as ge, watch as H, onUnmounted as he, createRenderer as je, defineComponent as we, onMounted as De, h as D } from "vue";
|
|
9
9
|
import * as be from "three";
|
|
10
|
-
import {
|
|
11
|
-
import { createEventHook as J, useRafFn as
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
import { PerspectiveCamera as N, OrthographicCamera as Ie, Clock as ye, Color as U, SRGBColorSpace as Be, ACESFilmicToneMapping as Fe, PCFSoftShadowMap as ze, PCFShadowMap as Ge, LinearSRGBColorSpace as ne, NoToneMapping as re, WebGLRenderer as Ve, LoadingManager as He, TextureLoader as We, Raycaster as Ye, Vector2 as $e, BufferAttribute as Ne } from "three";
|
|
11
|
+
import { createEventHook as J, useRafFn as Ue, toValue as u, useWindowSize as Ke, useElementSize as qe, useDevicePixelRatio as Je, unrefElement as K, useEventListener as Xe } from "@vueuse/core";
|
|
12
|
+
const oe = (e) => typeof e == "function", Qe = (e) => typeof e == "string", Ce = (e) => !!e && e.constructor === Array, Me = E({}), xe = (e) => void Object.assign(Me.value, e), p = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"];
|
|
13
|
+
function Ze() {
|
|
14
|
+
const e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, o = Math.random() * 4294967295 | 0, a = Math.random() * 4294967295 | 0;
|
|
15
|
+
return (p[e & 255] + p[e >> 8 & 255] + p[e >> 16 & 255] + p[e >> 24 & 255] + "-" + p[t & 255] + p[t >> 8 & 255] + "-" + p[t >> 16 & 15 | 64] + p[t >> 24 & 255] + "-" + p[o & 63 | 128] + p[o >> 8 & 255] + "-" + p[o >> 16 & 255] + p[o >> 24 & 255] + p[a & 255] + p[a >> 8 & 255] + p[a >> 16 & 255] + p[a >> 24 & 255]).toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
const X = Symbol();
|
|
18
|
+
function et() {
|
|
19
|
+
const e = de({
|
|
20
|
+
uuid: Ze(),
|
|
21
|
+
camera: void 0,
|
|
22
|
+
cameras: [],
|
|
23
|
+
scene: void 0,
|
|
24
|
+
renderer: void 0,
|
|
25
|
+
aspectRatio: me(() => window.innerWidth / window.innerHeight)
|
|
26
|
+
});
|
|
27
|
+
function t(n) {
|
|
28
|
+
return e[n];
|
|
29
|
+
}
|
|
30
|
+
function o(n, r) {
|
|
31
|
+
e[n] = r;
|
|
32
|
+
}
|
|
33
|
+
const a = {
|
|
34
|
+
state: e,
|
|
35
|
+
...pe(e),
|
|
36
|
+
getState: t,
|
|
37
|
+
setState: o
|
|
38
|
+
};
|
|
39
|
+
return _e(X, a), a;
|
|
40
|
+
}
|
|
41
|
+
const B = () => Oe(X, {
|
|
42
|
+
state: de({
|
|
43
|
+
camera: void 0,
|
|
44
|
+
cameras: [],
|
|
45
|
+
scene: void 0,
|
|
46
|
+
renderer: void 0
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
var tt = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(tt || {});
|
|
50
|
+
const at = 45;
|
|
51
|
+
let _;
|
|
52
|
+
function Re() {
|
|
53
|
+
const { state: e, setState: t, aspectRatio: o } = B();
|
|
18
54
|
function a(s = "Perspective", f) {
|
|
19
|
-
var
|
|
55
|
+
var l, d, v;
|
|
20
56
|
if (s === "Perspective") {
|
|
21
|
-
const { near:
|
|
57
|
+
const { near: C, far: M, fov: w } = f || {
|
|
22
58
|
near: 0.1,
|
|
23
59
|
far: 1e3,
|
|
24
|
-
fov:
|
|
60
|
+
fov: at
|
|
25
61
|
};
|
|
26
|
-
|
|
62
|
+
_ = new N(w, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, C, M), (d = e.cameras) == null || d.push(_);
|
|
27
63
|
} else {
|
|
28
|
-
const { left:
|
|
64
|
+
const { left: C, right: M, top: w, bottom: P, near: h, far: x } = f || {
|
|
29
65
|
left: -100,
|
|
30
66
|
right: 100,
|
|
31
67
|
top: 100,
|
|
@@ -33,17 +69,17 @@ function xe() {
|
|
|
33
69
|
near: 0.1,
|
|
34
70
|
far: 1e3
|
|
35
71
|
};
|
|
36
|
-
|
|
72
|
+
_ = new Ie(C, M, w, P, h, x), (v = e.cameras) == null || v.push(_);
|
|
37
73
|
}
|
|
38
|
-
return e.camera =
|
|
74
|
+
return e.camera = _, t("camera", e.camera), _;
|
|
39
75
|
}
|
|
40
76
|
function n() {
|
|
41
77
|
var s;
|
|
42
|
-
e.camera instanceof
|
|
78
|
+
e.camera instanceof N && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (s = e.camera) == null || s.updateProjectionMatrix();
|
|
43
79
|
}
|
|
44
80
|
function r(s) {
|
|
45
81
|
var f;
|
|
46
|
-
(f = e.cameras) == null || f.push(s), s instanceof
|
|
82
|
+
(f = e.cameras) == null || f.push(s), s instanceof N && e.aspectRatio && (s.aspect = e.aspectRatio.value), s.updateProjectionMatrix(), t("camera", s);
|
|
47
83
|
}
|
|
48
84
|
function c(s) {
|
|
49
85
|
var f;
|
|
@@ -52,10 +88,10 @@ function xe() {
|
|
|
52
88
|
function i() {
|
|
53
89
|
e.cameras = [];
|
|
54
90
|
}
|
|
55
|
-
return
|
|
91
|
+
return ve(() => {
|
|
56
92
|
o != null && o.value && n();
|
|
57
93
|
}), {
|
|
58
|
-
activeCamera:
|
|
94
|
+
activeCamera: ke(e, "camera"),
|
|
59
95
|
createCamera: a,
|
|
60
96
|
updateCamera: n,
|
|
61
97
|
pushCamera: r,
|
|
@@ -63,57 +99,73 @@ function xe() {
|
|
|
63
99
|
setFirstCamera: c
|
|
64
100
|
};
|
|
65
101
|
}
|
|
66
|
-
const
|
|
67
|
-
let
|
|
68
|
-
const { pause:
|
|
102
|
+
const Ee = J(), Pe = J(), Q = J(), I = new ye();
|
|
103
|
+
let W = 0, Y = 0;
|
|
104
|
+
const { pause: nt, resume: rt, isActive: ot } = Ue(
|
|
69
105
|
() => {
|
|
70
|
-
|
|
106
|
+
Ee.trigger({ delta: W, elapsed: Y, clock: I }), Pe.trigger({ delta: W, elapsed: Y, clock: I }), Q.trigger({ delta: W, elapsed: Y, clock: I });
|
|
71
107
|
},
|
|
72
108
|
{ immediate: !1 }
|
|
73
109
|
);
|
|
74
|
-
|
|
75
|
-
|
|
110
|
+
Q.on(() => {
|
|
111
|
+
W = I.getDelta(), Y = I.getElapsedTime();
|
|
76
112
|
});
|
|
77
|
-
function
|
|
113
|
+
function Se() {
|
|
78
114
|
return {
|
|
79
|
-
onBeforeLoop:
|
|
80
|
-
onLoop:
|
|
81
|
-
onAfterLoop:
|
|
82
|
-
pause:
|
|
83
|
-
resume:
|
|
84
|
-
isActive:
|
|
115
|
+
onBeforeLoop: Ee.on,
|
|
116
|
+
onLoop: Pe.on,
|
|
117
|
+
onAfterLoop: Q.on,
|
|
118
|
+
pause: nt,
|
|
119
|
+
resume: rt,
|
|
120
|
+
isActive: ot
|
|
85
121
|
};
|
|
86
122
|
}
|
|
87
|
-
function
|
|
88
|
-
return e instanceof
|
|
123
|
+
function it(e) {
|
|
124
|
+
return e instanceof U ? e : Array.isArray(e) ? new U(...e) : new U(e);
|
|
89
125
|
}
|
|
90
|
-
const
|
|
126
|
+
const q = {
|
|
91
127
|
realistic: {
|
|
92
|
-
outputColorSpace:
|
|
93
|
-
toneMapping:
|
|
128
|
+
outputColorSpace: Be,
|
|
129
|
+
toneMapping: Fe,
|
|
94
130
|
toneMappingExposure: 3,
|
|
95
131
|
shadowMap: {
|
|
96
132
|
enabled: !0,
|
|
97
|
-
type:
|
|
133
|
+
type: ze
|
|
98
134
|
}
|
|
99
135
|
}
|
|
100
|
-
},
|
|
136
|
+
}, Te = (e, t) => {
|
|
101
137
|
for (const o of Object.keys(t))
|
|
102
|
-
t[o] instanceof Object && Object.assign(t[o],
|
|
138
|
+
t[o] instanceof Object && Object.assign(t[o], Te(e[o], t[o]));
|
|
103
139
|
return Object.assign(e || {}, t), e;
|
|
104
|
-
},
|
|
140
|
+
}, st = "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", ct = /* @__PURE__ */ ft(st);
|
|
105
141
|
function V(e) {
|
|
106
142
|
return e.replace(/-([a-z])/g, (t, o) => o.toUpperCase());
|
|
107
143
|
}
|
|
108
|
-
function
|
|
144
|
+
function ft(e, t) {
|
|
109
145
|
const o = /* @__PURE__ */ Object.create(null), a = e.split(",");
|
|
110
146
|
for (let n = 0; n < a.length; n++)
|
|
111
147
|
o[a[n]] = !0;
|
|
112
148
|
return t ? (n) => !!o[n.toLowerCase()] : (n) => !!o[n];
|
|
113
149
|
}
|
|
114
|
-
|
|
150
|
+
const xt = !0, ie = "[TresJS ▲ ■ ●] ";
|
|
151
|
+
function F() {
|
|
152
|
+
function e(a, n) {
|
|
153
|
+
console.error(`${ie} ${a}`, n || "");
|
|
154
|
+
}
|
|
155
|
+
function t(a) {
|
|
156
|
+
console.warn(`${ie} ${a}`);
|
|
157
|
+
}
|
|
158
|
+
function o(a, n) {
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
logError: e,
|
|
162
|
+
logWarning: t,
|
|
163
|
+
logMessage: o
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function ut(e) {
|
|
115
167
|
var te, ae;
|
|
116
|
-
const t =
|
|
168
|
+
const t = ge(), o = E(!1), {
|
|
117
169
|
alpha: a = !0,
|
|
118
170
|
antialias: n = !0,
|
|
119
171
|
depth: r,
|
|
@@ -121,94 +173,93 @@ function ct(e) {
|
|
|
121
173
|
failIfMajorPerformanceCaveat: i,
|
|
122
174
|
precision: s,
|
|
123
175
|
premultipliedAlpha: f,
|
|
124
|
-
stencil:
|
|
125
|
-
shadows:
|
|
126
|
-
shadowMapType:
|
|
127
|
-
useLegacyLights:
|
|
128
|
-
outputColorSpace:
|
|
129
|
-
toneMapping:
|
|
176
|
+
stencil: l,
|
|
177
|
+
shadows: d = !1,
|
|
178
|
+
shadowMapType: v = Ge,
|
|
179
|
+
useLegacyLights: C = !1,
|
|
180
|
+
outputColorSpace: M = ne,
|
|
181
|
+
toneMapping: w = re,
|
|
130
182
|
toneMappingExposure: P = 1,
|
|
131
|
-
context:
|
|
132
|
-
powerPreference:
|
|
133
|
-
preserveDrawingBuffer:
|
|
134
|
-
clearColor:
|
|
135
|
-
windowSize:
|
|
136
|
-
preset:
|
|
137
|
-
} = pe(e), { state:
|
|
138
|
-
!
|
|
183
|
+
context: h = void 0,
|
|
184
|
+
powerPreference: x = "default",
|
|
185
|
+
preserveDrawingBuffer: $ = !1,
|
|
186
|
+
clearColor: y,
|
|
187
|
+
windowSize: m = !1,
|
|
188
|
+
preset: R = void 0
|
|
189
|
+
} = pe(e), { state: g, setState: b } = B(), { width: O, height: k } = u(m) == !0 || u(m) === "" || u(m) === "true" ? Ke() : qe(g.container), { logError: S, logWarning: z } = F(), { pixelRatio: j } = Je(), { pause: T, resume: G } = Se(), L = me(() => O.value / k.value);
|
|
190
|
+
!u(m) && ((ae = (te = g.container) == null ? void 0 : te.value) == null ? void 0 : ae.offsetHeight) === 0 && z(`Oops... Seems like your canvas height is currently 0px, by default it takes the height of it's parent, so make sure it has some height with CSS.
|
|
139
191
|
You could set windowSize=true to force the canvas to be the size of the window.`);
|
|
140
192
|
const Z = () => {
|
|
141
|
-
t.value && (t.value.setSize(
|
|
193
|
+
t.value && (t.value.setSize(O.value, k.value), t.value.setPixelRatio(Math.min(j.value, 2)));
|
|
142
194
|
}, ee = () => {
|
|
143
195
|
if (!t.value)
|
|
144
196
|
return;
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
|
|
197
|
+
const A = u(R);
|
|
198
|
+
if (A) {
|
|
199
|
+
A in q || S("Renderer Preset must be one of these: " + Object.keys(q).join(", ")), Te(t.value, q[A]);
|
|
148
200
|
return;
|
|
149
201
|
}
|
|
150
|
-
t.value.shadowMap.enabled =
|
|
202
|
+
t.value.shadowMap.enabled = u(d), t.value.shadowMap.type = u(v), t.value.toneMapping = u(w) || re, t.value.toneMappingExposure = u(P), t.value.outputColorSpace = u(M) || ne, y != null && y.value && t.value.setClearColor(it(u(y))), t.value.useLegacyLights = u(C);
|
|
151
203
|
}, Le = () => {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
canvas:
|
|
155
|
-
alpha:
|
|
156
|
-
antialias:
|
|
157
|
-
context:
|
|
158
|
-
depth:
|
|
159
|
-
failIfMajorPerformanceCaveat:
|
|
160
|
-
logarithmicDepthBuffer:
|
|
161
|
-
powerPreference:
|
|
162
|
-
precision:
|
|
163
|
-
stencil: l
|
|
164
|
-
preserveDrawingBuffer:
|
|
165
|
-
premultipliedAlpha:
|
|
166
|
-
}),
|
|
204
|
+
const A = K(g.canvas);
|
|
205
|
+
A && (t.value = new Ve({
|
|
206
|
+
canvas: A,
|
|
207
|
+
alpha: u(a),
|
|
208
|
+
antialias: u(n),
|
|
209
|
+
context: u(h),
|
|
210
|
+
depth: u(r),
|
|
211
|
+
failIfMajorPerformanceCaveat: u(i),
|
|
212
|
+
logarithmicDepthBuffer: u(c),
|
|
213
|
+
powerPreference: u(x),
|
|
214
|
+
precision: u(s),
|
|
215
|
+
stencil: u(l),
|
|
216
|
+
preserveDrawingBuffer: u($),
|
|
217
|
+
premultipliedAlpha: u(f)
|
|
218
|
+
}), b("renderer", t.value), b("clock", new ye()), b("aspectRatio", L), ee(), Z(), G(), o.value = !0);
|
|
167
219
|
}, Ae = () => {
|
|
168
|
-
t.value && (t.value.dispose(), t.value = void 0, o.value = !1,
|
|
220
|
+
t.value && (t.value.dispose(), t.value = void 0, o.value = !1, T());
|
|
169
221
|
};
|
|
170
|
-
return
|
|
171
|
-
[
|
|
222
|
+
return H([L, j], Z), H(
|
|
223
|
+
[d, v, M, C, w, P, y],
|
|
172
224
|
ee
|
|
173
|
-
),
|
|
174
|
-
() => [
|
|
225
|
+
), H(
|
|
226
|
+
() => [g.canvas, g.container],
|
|
175
227
|
() => {
|
|
176
|
-
|
|
228
|
+
K(g.canvas) && K(g.container) && Le();
|
|
177
229
|
},
|
|
178
230
|
{ immediate: !0, deep: !0 }
|
|
179
231
|
), {
|
|
180
232
|
renderer: t,
|
|
181
233
|
isReady: o,
|
|
182
234
|
dispose: Ae,
|
|
183
|
-
aspectRatio:
|
|
235
|
+
aspectRatio: L
|
|
184
236
|
};
|
|
185
237
|
}
|
|
186
|
-
|
|
187
|
-
function ut(e) {
|
|
238
|
+
function lt(e) {
|
|
188
239
|
const t = { nodes: {}, materials: {} };
|
|
189
240
|
return e && e.traverse((o) => {
|
|
190
241
|
o.name && (t.nodes[o.name] = o), o.material && !t.materials[o.material.name] && (t.materials[o.material.name] = o.material);
|
|
191
242
|
}), t;
|
|
192
243
|
}
|
|
193
244
|
async function Rt(e, t, o, a, n) {
|
|
194
|
-
const { logError: r } =
|
|
245
|
+
const { logError: r } = F(), c = new e();
|
|
195
246
|
n && n(c), o && o(c);
|
|
196
247
|
const s = (Array.isArray(t) ? t : [t]).map(
|
|
197
|
-
(f) => new Promise((
|
|
248
|
+
(f) => new Promise((l, d) => {
|
|
198
249
|
c.load(
|
|
199
250
|
f,
|
|
200
|
-
(
|
|
201
|
-
|
|
251
|
+
(v) => {
|
|
252
|
+
v.scene && Object.assign(v, lt(v.scene)), l(v);
|
|
202
253
|
},
|
|
203
254
|
a,
|
|
204
|
-
(
|
|
255
|
+
(v) => d(r("[useLoader] - Failed to load resource", v))
|
|
205
256
|
);
|
|
206
257
|
})
|
|
207
258
|
);
|
|
208
|
-
return
|
|
259
|
+
return Ce(t) ? await Promise.all(s) : await s[0];
|
|
209
260
|
}
|
|
210
261
|
async function Et(e) {
|
|
211
|
-
const t = new He(), o = new
|
|
262
|
+
const t = new He(), o = new We(t), a = (n) => new Promise((r, c) => {
|
|
212
263
|
o.load(
|
|
213
264
|
n,
|
|
214
265
|
(i) => r(i),
|
|
@@ -218,7 +269,7 @@ async function Et(e) {
|
|
|
218
269
|
}
|
|
219
270
|
);
|
|
220
271
|
});
|
|
221
|
-
if (
|
|
272
|
+
if (Ce(e)) {
|
|
222
273
|
const n = await Promise.all(e.map((r) => a(r)));
|
|
223
274
|
return e.length > 1 ? n : n[0];
|
|
224
275
|
} else {
|
|
@@ -229,8 +280,8 @@ async function Et(e) {
|
|
|
229
280
|
roughnessMap: i,
|
|
230
281
|
metalnessMap: s,
|
|
231
282
|
aoMap: f,
|
|
232
|
-
alphaMap:
|
|
233
|
-
matcap:
|
|
283
|
+
alphaMap: l,
|
|
284
|
+
matcap: d
|
|
234
285
|
} = e;
|
|
235
286
|
return {
|
|
236
287
|
map: n ? await a(n) : null,
|
|
@@ -239,51 +290,14 @@ async function Et(e) {
|
|
|
239
290
|
roughnessMap: i ? await a(i) : null,
|
|
240
291
|
metalnessMap: s ? await a(s) : null,
|
|
241
292
|
aoMap: f ? await a(f) : null,
|
|
242
|
-
alphaMap:
|
|
243
|
-
matcap:
|
|
293
|
+
alphaMap: l ? await a(l) : null,
|
|
294
|
+
matcap: d ? await a(d) : null
|
|
244
295
|
};
|
|
245
296
|
}
|
|
246
297
|
}
|
|
247
|
-
const p = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"];
|
|
248
|
-
function lt() {
|
|
249
|
-
const e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, o = Math.random() * 4294967295 | 0, a = Math.random() * 4294967295 | 0;
|
|
250
|
-
return (p[e & 255] + p[e >> 8 & 255] + p[e >> 16 & 255] + p[e >> 24 & 255] + "-" + p[t & 255] + p[t >> 8 & 255] + "-" + p[t >> 16 & 15 | 64] + p[t >> 24 & 255] + "-" + p[o & 63 | 128] + p[o >> 8 & 255] + "-" + p[o >> 16 & 255] + p[o >> 24 & 255] + p[a & 255] + p[a >> 8 & 255] + p[a >> 16 & 255] + p[a >> 24 & 255]).toLowerCase();
|
|
251
|
-
}
|
|
252
|
-
const Q = Symbol();
|
|
253
298
|
function dt() {
|
|
254
|
-
const e = ge({
|
|
255
|
-
uuid: lt(),
|
|
256
|
-
camera: void 0,
|
|
257
|
-
cameras: [],
|
|
258
|
-
scene: void 0,
|
|
259
|
-
renderer: void 0,
|
|
260
|
-
aspectRatio: ve(() => window.innerWidth / window.innerHeight)
|
|
261
|
-
});
|
|
262
|
-
function t(n) {
|
|
263
|
-
return e[n];
|
|
264
|
-
}
|
|
265
|
-
function o(n, r) {
|
|
266
|
-
e[n] = r;
|
|
267
|
-
}
|
|
268
|
-
const a = {
|
|
269
|
-
state: e,
|
|
270
|
-
...pe(e),
|
|
271
|
-
getState: t,
|
|
272
|
-
setState: o
|
|
273
|
-
};
|
|
274
|
-
return Oe(Q, a), a;
|
|
275
|
-
}
|
|
276
|
-
const _ = () => ke(Q, {
|
|
277
|
-
state: ge({
|
|
278
|
-
camera: void 0,
|
|
279
|
-
cameras: [],
|
|
280
|
-
scene: void 0,
|
|
281
|
-
renderer: void 0
|
|
282
|
-
})
|
|
283
|
-
});
|
|
284
|
-
function mt() {
|
|
285
299
|
var c;
|
|
286
|
-
const e =
|
|
300
|
+
const e = ge(new Ye()), t = E(new $e()), o = E(null), { setState: a, state: n } = B();
|
|
287
301
|
a("raycaster", e.value), a("pointer", t), a("currentInstance", o);
|
|
288
302
|
function r(i) {
|
|
289
303
|
t.value.x = i.clientX / window.innerWidth * 2 - 1, t.value.y = -(i.clientY / window.innerHeight) * 2 + 1;
|
|
@@ -296,24 +310,8 @@ function mt() {
|
|
|
296
310
|
pointer: t
|
|
297
311
|
};
|
|
298
312
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
function e(a, n) {
|
|
302
|
-
console.error(`${ie} ${a}`, n || "");
|
|
303
|
-
}
|
|
304
|
-
function t(a) {
|
|
305
|
-
console.warn(`${ie} ${a}`);
|
|
306
|
-
}
|
|
307
|
-
function o(a, n) {
|
|
308
|
-
}
|
|
309
|
-
return {
|
|
310
|
-
logError: e,
|
|
311
|
-
logWarning: t,
|
|
312
|
-
logMessage: o
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
function St() {
|
|
316
|
-
const { logWarning: e } = I();
|
|
313
|
+
function Pt() {
|
|
314
|
+
const { logWarning: e } = F();
|
|
317
315
|
function t(a, n, r) {
|
|
318
316
|
let c = null;
|
|
319
317
|
return a.traverse((i) => {
|
|
@@ -328,31 +326,31 @@ function St() {
|
|
|
328
326
|
seekByName: o
|
|
329
327
|
};
|
|
330
328
|
}
|
|
331
|
-
const
|
|
329
|
+
const mt = /^on[^a-z]/, pt = (e) => mt.test(e);
|
|
332
330
|
let se = null;
|
|
333
331
|
const ce = {
|
|
334
332
|
GEOMETRY_VIA_PROP: "tres__geometryViaProp",
|
|
335
333
|
MATERIAL_VIA_PROP: "tres__materialViaProp"
|
|
336
|
-
}, { logError: fe } =
|
|
334
|
+
}, { logError: fe } = F();
|
|
337
335
|
let ue = !0;
|
|
338
|
-
const
|
|
336
|
+
const vt = {
|
|
339
337
|
createElement(e, t, o, a) {
|
|
340
338
|
var s, f;
|
|
341
|
-
if (a || (a = {}), a.args || (a.args = []), e === "template" ||
|
|
339
|
+
if (a || (a = {}), a.args || (a.args = []), e === "template" || ct(e))
|
|
342
340
|
return null;
|
|
343
341
|
let n = e.replace("Tres", ""), r;
|
|
344
342
|
if (e === "primitive") {
|
|
345
343
|
(a == null ? void 0 : a.object) === void 0 && fe("Tres primitives need a prop 'object'");
|
|
346
|
-
const
|
|
347
|
-
n =
|
|
344
|
+
const l = a.object;
|
|
345
|
+
n = l.type, r = Object.assign(l, { type: n, attach: a.attach, primitive: !0 });
|
|
348
346
|
} else {
|
|
349
|
-
const
|
|
350
|
-
|
|
347
|
+
const l = Me.value[n];
|
|
348
|
+
l || fe(`${n} is not defined on the THREE namespace. Use extend to add it to the catalog.`), r = new l(...a.args);
|
|
351
349
|
}
|
|
352
350
|
if (r.isCamera && ue) {
|
|
353
351
|
a != null && a.position || r.position.set(3, 3, 3), a != null && a.lookAt || r.lookAt(0, 0, 0);
|
|
354
|
-
const { setFirstCamera:
|
|
355
|
-
|
|
352
|
+
const { setFirstCamera: l } = Re();
|
|
353
|
+
l(r), ue = !1;
|
|
356
354
|
}
|
|
357
355
|
(a == null ? void 0 : a.attach) === void 0 && (r.isMaterial ? r.attach = "material" : r.isBufferGeometry && (r.attach = "geometry"));
|
|
358
356
|
const { GEOMETRY_VIA_PROP: c, MATERIAL_VIA_PROP: i } = ce;
|
|
@@ -394,9 +392,12 @@ const gt = {
|
|
|
394
392
|
}
|
|
395
393
|
if (r.includes("-") && i === void 0) {
|
|
396
394
|
const f = r.split("-");
|
|
397
|
-
i = f.reduce((
|
|
395
|
+
i = f.reduce((l, d) => l[V(d)], n), r = f.pop(), c = r.toLowerCase(), i != null && i.set || (n = f.reduce((l, d) => l[V(d)], n));
|
|
396
|
+
}
|
|
397
|
+
if (pt(r)) {
|
|
398
|
+
const f = r;
|
|
399
|
+
e.events[f] = a;
|
|
398
400
|
}
|
|
399
|
-
vt(r) && (e.events[r] = a);
|
|
400
401
|
let s = a;
|
|
401
402
|
if (s === "" && (s = !0), oe(i)) {
|
|
402
403
|
Array.isArray(s) ? e[c](...s) : e[c](s);
|
|
@@ -417,15 +418,15 @@ const gt = {
|
|
|
417
418
|
setScopeId: () => void 0,
|
|
418
419
|
cloneNode: () => void 0,
|
|
419
420
|
insertStaticContent: () => void 0
|
|
420
|
-
}, { createApp:
|
|
421
|
-
const t =
|
|
421
|
+
}, { createApp: gt } = je(vt), ht = (e) => {
|
|
422
|
+
const t = gt(o);
|
|
422
423
|
function o() {
|
|
423
424
|
return e && e.default ? e.default() : [];
|
|
424
425
|
}
|
|
425
426
|
return t;
|
|
426
427
|
};
|
|
427
|
-
|
|
428
|
-
const { logWarning: le } =
|
|
428
|
+
xe(be);
|
|
429
|
+
const { logWarning: le } = F(), wt = we({
|
|
429
430
|
name: "TresScene",
|
|
430
431
|
props: [
|
|
431
432
|
"shadows",
|
|
@@ -446,46 +447,50 @@ const { logWarning: le } = I(), bt = we({
|
|
|
446
447
|
],
|
|
447
448
|
setup(e, { slots: t, expose: o }) {
|
|
448
449
|
e.physicallyCorrectLights === !0 && le("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
|
|
449
|
-
const a = E(), n = E(), r = new be.Scene(), { setState: c } =
|
|
450
|
+
const a = E(), n = E(), r = new be.Scene(), { setState: c } = B();
|
|
450
451
|
c("scene", r), c("canvas", n), c("container", a);
|
|
451
452
|
const i = E(), s = t && t.default && t.default();
|
|
452
|
-
s && (s == null ? void 0 : s.length) > 0 && (i.value = s.some((h) =>
|
|
453
|
-
|
|
453
|
+
s && (s == null ? void 0 : s.length) > 0 && (i.value = s.some((h) => Qe(h.type) && h.type.includes("Camera")) || e.camera, i.value || le("No camera found in the scene, please add one!"));
|
|
454
|
+
const { onLoop: f, resume: l } = Se();
|
|
455
|
+
De(() => {
|
|
456
|
+
M();
|
|
454
457
|
}), he(() => {
|
|
455
458
|
c("renderer", null);
|
|
456
459
|
});
|
|
457
|
-
const { activeCamera:
|
|
458
|
-
function
|
|
459
|
-
const { renderer: h } =
|
|
460
|
-
e.camera &&
|
|
461
|
-
const {
|
|
462
|
-
let
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}),
|
|
466
|
-
var
|
|
467
|
-
if (
|
|
468
|
-
const
|
|
469
|
-
|
|
460
|
+
const { activeCamera: d, pushCamera: v, clearCameras: C } = Re();
|
|
461
|
+
function M() {
|
|
462
|
+
const { renderer: h } = ut(e);
|
|
463
|
+
e.camera && v(e.camera);
|
|
464
|
+
const { raycaster: x, pointer: $ } = dt();
|
|
465
|
+
let y = null, m = null;
|
|
466
|
+
ve(() => {
|
|
467
|
+
d.value && x.value.setFromCamera($.value, d.value);
|
|
468
|
+
}), f(() => {
|
|
469
|
+
var R, g, b, O, k, S, z, j, T, G;
|
|
470
|
+
if (d.value && e.disableRender !== !0 && ((R = h.value) == null || R.render(r, d.value)), x.value) {
|
|
471
|
+
const L = x.value.intersectObjects(r.children);
|
|
472
|
+
L.length > 0 ? (m = L[0], y === null && ((O = (b = (g = m.object) == null ? void 0 : g.events) == null ? void 0 : b.onPointerEnter) == null || O.call(b, m)), (z = (S = (k = m.object) == null ? void 0 : k.events) == null ? void 0 : S.onPointerMove) == null || z.call(S, m)) : y !== null && ((G = (T = (j = m == null ? void 0 : m.object) == null ? void 0 : j.events) == null ? void 0 : T.onPointerLeave) == null || G.call(T, y), m = null), y = m;
|
|
470
473
|
}
|
|
471
|
-
}),
|
|
472
|
-
var
|
|
473
|
-
|
|
474
|
+
}), Xe(n.value, "click", () => {
|
|
475
|
+
var R, g, b;
|
|
476
|
+
m !== null && ((b = (g = (R = m.object) == null ? void 0 : R.events) == null ? void 0 : g.onClick) == null || b.call(g, m));
|
|
474
477
|
});
|
|
475
478
|
}
|
|
476
479
|
let w;
|
|
477
|
-
function
|
|
478
|
-
w =
|
|
480
|
+
function P() {
|
|
481
|
+
w = ht(t);
|
|
482
|
+
const h = B();
|
|
483
|
+
w.provide("useTres", h), w.provide(X, h), w.provide("extend", xe), w.mount(r);
|
|
479
484
|
}
|
|
480
|
-
return
|
|
485
|
+
return P(), o({
|
|
481
486
|
scene: r
|
|
482
|
-
}),
|
|
487
|
+
}), H(
|
|
483
488
|
() => e.camera,
|
|
484
489
|
(h) => {
|
|
485
|
-
h && (
|
|
490
|
+
h && (C(), v(h));
|
|
486
491
|
}
|
|
487
|
-
), () =>
|
|
488
|
-
|
|
492
|
+
), () => D(
|
|
493
|
+
D(
|
|
489
494
|
"div",
|
|
490
495
|
{
|
|
491
496
|
ref: a,
|
|
@@ -500,7 +505,7 @@ const { logWarning: le } = I(), bt = we({
|
|
|
500
505
|
}
|
|
501
506
|
},
|
|
502
507
|
[
|
|
503
|
-
|
|
508
|
+
D(
|
|
504
509
|
"div",
|
|
505
510
|
{
|
|
506
511
|
style: {
|
|
@@ -509,7 +514,7 @@ const { logWarning: le } = I(), bt = we({
|
|
|
509
514
|
}
|
|
510
515
|
},
|
|
511
516
|
[
|
|
512
|
-
|
|
517
|
+
D("canvas", {
|
|
513
518
|
ref: n,
|
|
514
519
|
"data-scene": r.uuid,
|
|
515
520
|
style: {
|
|
@@ -527,7 +532,7 @@ const { logWarning: le } = I(), bt = we({
|
|
|
527
532
|
)
|
|
528
533
|
);
|
|
529
534
|
}
|
|
530
|
-
}),
|
|
535
|
+
}), bt = we({
|
|
531
536
|
name: "TresCanvas",
|
|
532
537
|
props: [
|
|
533
538
|
"shadows",
|
|
@@ -547,31 +552,31 @@ const { logWarning: le } = I(), bt = we({
|
|
|
547
552
|
"camera"
|
|
548
553
|
],
|
|
549
554
|
setup(e, { slots: t, expose: o }) {
|
|
550
|
-
const a =
|
|
551
|
-
return o(a), () =>
|
|
555
|
+
const a = et();
|
|
556
|
+
return o(a), () => D(wt, e, t);
|
|
552
557
|
}
|
|
553
|
-
}),
|
|
558
|
+
}), St = {
|
|
554
559
|
install(e) {
|
|
555
|
-
e.component("TresCanvas",
|
|
560
|
+
e.component("TresCanvas", bt);
|
|
556
561
|
}
|
|
557
562
|
};
|
|
558
563
|
export {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
564
|
+
tt as CameraType,
|
|
565
|
+
X as TRES_CONTEXT_KEY,
|
|
566
|
+
bt as TresCanvas,
|
|
567
|
+
Me as catalogue,
|
|
568
|
+
St as default,
|
|
569
|
+
xe as extend,
|
|
570
|
+
xt as isProd,
|
|
571
|
+
lt as trasverseObjects,
|
|
572
|
+
Re as useCamera,
|
|
568
573
|
Rt as useLoader,
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
+
F as useLogger,
|
|
575
|
+
dt as useRaycaster,
|
|
576
|
+
Se as useRenderLoop,
|
|
577
|
+
ut as useRenderer,
|
|
578
|
+
Pt as useSeek,
|
|
574
579
|
Et as useTexture,
|
|
575
|
-
|
|
576
|
-
|
|
580
|
+
B as useTres,
|
|
581
|
+
et as useTresProvider
|
|
577
582
|
};
|