@tresjs/core 2.3.0 → 2.4.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/index.d.ts +2 -1
- package/dist/tres.js +238 -227
- package/dist/tres.umd.cjs +3 -3
- package/dist/utils/template-compiler-options.d.ts +8 -0
- package/package.json +17 -16
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './core/catalogue';
|
|
|
4
4
|
export * from './components';
|
|
5
5
|
export * from './types';
|
|
6
6
|
import { normalizeColor, normalizeVectorFlexibleParam } from './utils/normalize';
|
|
7
|
+
import templateCompilerOptions from './utils/template-compiler-options';
|
|
7
8
|
export interface TresOptions {
|
|
8
9
|
extends?: Record<string, unknown>;
|
|
9
10
|
}
|
|
@@ -13,4 +14,4 @@ export interface TresPlugin {
|
|
|
13
14
|
}
|
|
14
15
|
declare const plugin: TresPlugin;
|
|
15
16
|
export default plugin;
|
|
16
|
-
export { normalizeColor, normalizeVectorFlexibleParam };
|
|
17
|
+
export { normalizeColor, normalizeVectorFlexibleParam, templateCompilerOptions };
|
package/dist/tres.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v2.
|
|
3
|
+
* version: v2.4.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
|
|
8
|
+
import { ref as G, shallowReactive as ce, toRefs as ue, provide as xe, inject as Le, watchEffect as fe, toRef as _e, shallowRef as Se, computed as A, watch as I, onUnmounted as le, reactive as Ae, createRenderer as Oe, defineComponent as de, onMounted as ke, h as _ } from "vue";
|
|
9
9
|
import * as q from "three";
|
|
10
|
-
import { PerspectiveCamera as z, OrthographicCamera as
|
|
11
|
-
import { createEventHook as
|
|
12
|
-
const me =
|
|
10
|
+
import { PerspectiveCamera as z, OrthographicCamera as De, Clock as pe, Vector3 as je, Color as W, SRGBColorSpace as Ie, ACESFilmicToneMapping as Be, PCFSoftShadowMap as He, PCFShadowMap as Ve, LinearSRGBColorSpace as ae, NoToneMapping as ne, WebGLRenderer as Ge, LoadingManager as Fe, TextureLoader as Ne, Raycaster as ze, Vector2 as We, BufferAttribute as $e } from "three";
|
|
11
|
+
import { createEventHook as O, useRafFn as Ue, toValue as m, useWindowSize as Ye, useElementSize as qe, useDevicePixelRatio as Ke, unrefElement as $, usePointer as Je, useElementBounding as Xe } from "@vueuse/core";
|
|
12
|
+
const me = G({}), ve = (e) => void Object.assign(me.value, e), re = (e) => typeof e == "function", ge = (e) => !!e && e.constructor === Array, b = ["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
13
|
function Qe() {
|
|
14
14
|
const e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, n = Math.random() * 4294967295 | 0, a = Math.random() * 4294967295 | 0;
|
|
15
15
|
return (b[e & 255] + b[e >> 8 & 255] + b[e >> 16 & 255] + b[e >> 24 & 255] + "-" + b[t & 255] + b[t >> 8 & 255] + "-" + b[t >> 16 & 15 | 64] + b[t >> 24 & 255] + "-" + b[n & 63 | 128] + b[n >> 8 & 255] + "-" + b[n >> 16 & 255] + b[n >> 24 & 255] + b[a & 255] + b[a >> 8 & 255] + b[a >> 16 & 255] + b[a >> 24 & 255]).toLowerCase();
|
|
@@ -29,8 +29,8 @@ function Ze() {
|
|
|
29
29
|
function t(o) {
|
|
30
30
|
return e[o];
|
|
31
31
|
}
|
|
32
|
-
function n(o,
|
|
33
|
-
e[o] =
|
|
32
|
+
function n(o, s) {
|
|
33
|
+
e[o] = s;
|
|
34
34
|
}
|
|
35
35
|
const a = {
|
|
36
36
|
state: e,
|
|
@@ -38,9 +38,9 @@ function Ze() {
|
|
|
38
38
|
getState: t,
|
|
39
39
|
setState: n
|
|
40
40
|
};
|
|
41
|
-
return
|
|
41
|
+
return xe(K, a), a;
|
|
42
42
|
}
|
|
43
|
-
const
|
|
43
|
+
const k = () => Le(K, {
|
|
44
44
|
state: ce({
|
|
45
45
|
camera: void 0,
|
|
46
46
|
cameras: [],
|
|
@@ -52,20 +52,20 @@ const S = () => Le(K, {
|
|
|
52
52
|
});
|
|
53
53
|
var et = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(et || {});
|
|
54
54
|
const tt = 45;
|
|
55
|
-
let
|
|
55
|
+
let x;
|
|
56
56
|
function at() {
|
|
57
|
-
const { state: e, setState: t, aspectRatio: n } =
|
|
58
|
-
function a(
|
|
59
|
-
var l,
|
|
60
|
-
if (
|
|
61
|
-
const { near:
|
|
57
|
+
const { state: e, setState: t, aspectRatio: n } = k();
|
|
58
|
+
function a(i = "Perspective", u) {
|
|
59
|
+
var l, p, d;
|
|
60
|
+
if (i === "Perspective") {
|
|
61
|
+
const { near: E, far: y, fov: h } = u || {
|
|
62
62
|
near: 0.1,
|
|
63
63
|
far: 1e3,
|
|
64
64
|
fov: tt
|
|
65
65
|
};
|
|
66
|
-
|
|
66
|
+
x = new z(h, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, E, y), (p = e.cameras) == null || p.push(x);
|
|
67
67
|
} else {
|
|
68
|
-
const { left:
|
|
68
|
+
const { left: E, right: y, top: h, bottom: w, near: C, far: g } = u || {
|
|
69
69
|
left: -100,
|
|
70
70
|
right: 100,
|
|
71
71
|
top: 100,
|
|
@@ -73,21 +73,21 @@ function at() {
|
|
|
73
73
|
near: 0.1,
|
|
74
74
|
far: 1e3
|
|
75
75
|
};
|
|
76
|
-
|
|
76
|
+
x = new De(E, y, h, w, C, g), (d = e.cameras) == null || d.push(x);
|
|
77
77
|
}
|
|
78
|
-
return e.camera =
|
|
78
|
+
return e.camera = x, t("camera", e.camera), x;
|
|
79
79
|
}
|
|
80
80
|
function o() {
|
|
81
|
-
var
|
|
82
|
-
e.camera instanceof z && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (
|
|
81
|
+
var i;
|
|
82
|
+
e.camera instanceof z && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (i = e.camera) == null || i.updateProjectionMatrix();
|
|
83
83
|
}
|
|
84
|
-
function i
|
|
85
|
-
var
|
|
86
|
-
(
|
|
84
|
+
function s(i) {
|
|
85
|
+
var u;
|
|
86
|
+
(u = e.cameras) == null || u.push(i), i instanceof z && e.aspectRatio && (i.aspect = e.aspectRatio.value), i.updateProjectionMatrix(), t("camera", i);
|
|
87
87
|
}
|
|
88
|
-
function
|
|
89
|
-
var
|
|
90
|
-
((
|
|
88
|
+
function c(i) {
|
|
89
|
+
var u;
|
|
90
|
+
((u = e.cameras) == null ? void 0 : u.length) === 0 && s(i);
|
|
91
91
|
}
|
|
92
92
|
function r() {
|
|
93
93
|
e.cameras = [];
|
|
@@ -98,21 +98,21 @@ function at() {
|
|
|
98
98
|
activeCamera: _e(e, "camera"),
|
|
99
99
|
createCamera: a,
|
|
100
100
|
updateCamera: o,
|
|
101
|
-
pushCamera:
|
|
101
|
+
pushCamera: s,
|
|
102
102
|
clearCameras: r,
|
|
103
|
-
setFirstCamera:
|
|
103
|
+
setFirstCamera: c
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
|
-
const we =
|
|
107
|
-
let
|
|
108
|
-
const { pause: nt, resume: rt, isActive: ot } =
|
|
106
|
+
const we = O(), be = O(), J = O(), S = new pe();
|
|
107
|
+
let B = 0, H = 0;
|
|
108
|
+
const { pause: nt, resume: rt, isActive: ot } = Ue(
|
|
109
109
|
() => {
|
|
110
|
-
we.trigger({ delta:
|
|
110
|
+
we.trigger({ delta: B, elapsed: H, clock: S }), be.trigger({ delta: B, elapsed: H, clock: S }), J.trigger({ delta: B, elapsed: H, clock: S });
|
|
111
111
|
},
|
|
112
112
|
{ immediate: !1 }
|
|
113
113
|
);
|
|
114
114
|
J.on(() => {
|
|
115
|
-
|
|
115
|
+
B = S.getDelta(), H = S.getElapsedTime();
|
|
116
116
|
});
|
|
117
117
|
function he() {
|
|
118
118
|
return {
|
|
@@ -124,13 +124,13 @@ function he() {
|
|
|
124
124
|
isActive: ot
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
-
function
|
|
128
|
-
return typeof e == "number" ? [e, e, e] : e instanceof
|
|
127
|
+
function Rt(e) {
|
|
128
|
+
return typeof e == "number" ? [e, e, e] : e instanceof je ? [e.x, e.y, e.z] : e;
|
|
129
129
|
}
|
|
130
130
|
function it(e) {
|
|
131
131
|
return e instanceof W ? e : Array.isArray(e) ? new W(...e) : new W(e);
|
|
132
132
|
}
|
|
133
|
-
const
|
|
133
|
+
const U = {
|
|
134
134
|
realistic: {
|
|
135
135
|
outputColorSpace: Ie,
|
|
136
136
|
toneMapping: Be,
|
|
@@ -157,12 +157,12 @@ function ut(e, t) {
|
|
|
157
157
|
const ft = (e, t) => {
|
|
158
158
|
const n = /* @__PURE__ */ new Set(), a = [];
|
|
159
159
|
for (const o of e) {
|
|
160
|
-
const
|
|
161
|
-
n.has(
|
|
160
|
+
const s = t(o);
|
|
161
|
+
n.has(s) || (n.add(s), a.push(o));
|
|
162
162
|
}
|
|
163
163
|
return a;
|
|
164
|
-
},
|
|
165
|
-
function
|
|
164
|
+
}, Tt = !0, oe = "[TresJS ▲ ■ ●] ";
|
|
165
|
+
function D() {
|
|
166
166
|
function e(a, o) {
|
|
167
167
|
console.error(`${oe} ${a}`, o || "");
|
|
168
168
|
}
|
|
@@ -178,31 +178,31 @@ function O() {
|
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
function lt(e) {
|
|
181
|
-
const t =
|
|
181
|
+
const t = Se(), n = G(!1), {
|
|
182
182
|
alpha: a = !0,
|
|
183
183
|
antialias: o = !0,
|
|
184
|
-
depth:
|
|
185
|
-
logarithmicDepthBuffer:
|
|
184
|
+
depth: s,
|
|
185
|
+
logarithmicDepthBuffer: c,
|
|
186
186
|
failIfMajorPerformanceCaveat: r,
|
|
187
|
-
precision:
|
|
188
|
-
premultipliedAlpha:
|
|
187
|
+
precision: i,
|
|
188
|
+
premultipliedAlpha: u,
|
|
189
189
|
stencil: l,
|
|
190
|
-
shadows:
|
|
191
|
-
shadowMapType:
|
|
192
|
-
useLegacyLights:
|
|
193
|
-
outputColorSpace:
|
|
194
|
-
toneMapping:
|
|
195
|
-
toneMappingExposure:
|
|
196
|
-
context:
|
|
197
|
-
powerPreference:
|
|
198
|
-
preserveDrawingBuffer:
|
|
199
|
-
clearColor:
|
|
200
|
-
windowSize:
|
|
190
|
+
shadows: p = !1,
|
|
191
|
+
shadowMapType: d = Ve,
|
|
192
|
+
useLegacyLights: E = !1,
|
|
193
|
+
outputColorSpace: y = ae,
|
|
194
|
+
toneMapping: h = ne,
|
|
195
|
+
toneMappingExposure: w = 1,
|
|
196
|
+
context: C = void 0,
|
|
197
|
+
powerPreference: g = "default",
|
|
198
|
+
preserveDrawingBuffer: M = !1,
|
|
199
|
+
clearColor: R,
|
|
200
|
+
windowSize: T = !1,
|
|
201
201
|
preset: F = void 0
|
|
202
|
-
} = ue(e), { state: f, setState:
|
|
202
|
+
} = ue(e), { state: f, setState: v } = k(), { width: X, height: Q } = m(T) == !0 || m(T) === "" || m(T) === "true" ? Ye() : qe(f.container), { logError: Ee, logWarning: Me } = D(), { pixelRatio: Z } = Ke(), { pause: Pe, resume: Ce } = he(), N = A(() => X.value / Q.value);
|
|
203
203
|
setTimeout(() => {
|
|
204
204
|
var P;
|
|
205
|
-
!m(
|
|
205
|
+
!m(T) && !((P = f.canvas) != null && P.value.offsetHeight) && Me(`Oops... Seems like your canvas height is currently 0px, it's posible that you couldn't watch your scene.
|
|
206
206
|
You could set windowSize=true to force the canvas to be the size of the window.`);
|
|
207
207
|
}, 1e3);
|
|
208
208
|
const ee = () => {
|
|
@@ -212,42 +212,42 @@ function lt(e) {
|
|
|
212
212
|
return;
|
|
213
213
|
const P = m(F);
|
|
214
214
|
if (P) {
|
|
215
|
-
P in
|
|
215
|
+
P in U || Ee("Renderer Preset must be one of these: " + Object.keys(U).join(", ")), ye(t.value, U[P]);
|
|
216
216
|
return;
|
|
217
217
|
}
|
|
218
|
-
t.value.shadowMap.enabled = m(
|
|
219
|
-
},
|
|
220
|
-
const P =
|
|
218
|
+
t.value.shadowMap.enabled = m(p), t.value.shadowMap.type = m(d), t.value.toneMapping = m(h) || ne, t.value.toneMappingExposure = m(w), t.value.outputColorSpace = m(y) || ae, R != null && R.value && t.value.setClearColor(it(m(R))), t.value.useLegacyLights = m(E);
|
|
219
|
+
}, Re = () => {
|
|
220
|
+
const P = $(f.canvas);
|
|
221
221
|
P && (t.value = new Ge({
|
|
222
222
|
canvas: P,
|
|
223
223
|
alpha: m(a),
|
|
224
224
|
antialias: m(o),
|
|
225
|
-
context: m(
|
|
226
|
-
depth: m(
|
|
225
|
+
context: m(C),
|
|
226
|
+
depth: m(s),
|
|
227
227
|
failIfMajorPerformanceCaveat: m(r),
|
|
228
|
-
logarithmicDepthBuffer: m(
|
|
229
|
-
powerPreference: m(
|
|
230
|
-
precision: m(
|
|
228
|
+
logarithmicDepthBuffer: m(c),
|
|
229
|
+
powerPreference: m(g),
|
|
230
|
+
precision: m(i),
|
|
231
231
|
stencil: m(l),
|
|
232
|
-
preserveDrawingBuffer: m(
|
|
233
|
-
premultipliedAlpha: m(
|
|
234
|
-
}),
|
|
235
|
-
},
|
|
232
|
+
preserveDrawingBuffer: m(M),
|
|
233
|
+
premultipliedAlpha: m(u)
|
|
234
|
+
}), v("renderer", t.value), v("clock", new pe()), v("aspectRatio", N), te(), ee(), Ce(), n.value = !0);
|
|
235
|
+
}, Te = () => {
|
|
236
236
|
t.value && (t.value.dispose(), t.value = void 0, n.value = !1, Pe());
|
|
237
237
|
};
|
|
238
|
-
return
|
|
239
|
-
[
|
|
238
|
+
return I([N, Z], ee), I(
|
|
239
|
+
[p, d, y, E, h, w, R],
|
|
240
240
|
te
|
|
241
|
-
),
|
|
241
|
+
), I(
|
|
242
242
|
() => [f.canvas, f.container],
|
|
243
243
|
() => {
|
|
244
|
-
|
|
244
|
+
$(f.canvas) && $(f.container) && Re();
|
|
245
245
|
},
|
|
246
246
|
{ immediate: !0, deep: !0 }
|
|
247
247
|
), {
|
|
248
248
|
renderer: t,
|
|
249
249
|
isReady: n,
|
|
250
|
-
dispose:
|
|
250
|
+
dispose: Te,
|
|
251
251
|
aspectRatio: N
|
|
252
252
|
};
|
|
253
253
|
}
|
|
@@ -257,109 +257,109 @@ function dt(e) {
|
|
|
257
257
|
n.name && (t.nodes[n.name] = n), n.material && !t.materials[n.material.name] && (t.materials[n.material.name] = n.material);
|
|
258
258
|
}), t;
|
|
259
259
|
}
|
|
260
|
-
async function
|
|
261
|
-
const { logError:
|
|
262
|
-
o && o(
|
|
263
|
-
const
|
|
264
|
-
(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
(
|
|
268
|
-
|
|
260
|
+
async function xt(e, t, n, a, o) {
|
|
261
|
+
const { logError: s } = D(), c = new e();
|
|
262
|
+
o && o(c), n && n(c);
|
|
263
|
+
const i = (Array.isArray(t) ? t : [t]).map(
|
|
264
|
+
(u) => new Promise((l, p) => {
|
|
265
|
+
c.load(
|
|
266
|
+
u,
|
|
267
|
+
(d) => {
|
|
268
|
+
d.scene && Object.assign(d, dt(d.scene)), l(d);
|
|
269
269
|
},
|
|
270
270
|
a,
|
|
271
|
-
(
|
|
271
|
+
(d) => p(s("[useLoader] - Failed to load resource", d))
|
|
272
272
|
);
|
|
273
273
|
})
|
|
274
274
|
);
|
|
275
|
-
return ge(t) ? await Promise.all(
|
|
275
|
+
return ge(t) ? await Promise.all(i) : await i[0];
|
|
276
276
|
}
|
|
277
|
-
async function
|
|
278
|
-
const t = new Fe(), n = new Ne(t), a = (o) => new Promise((
|
|
277
|
+
async function Lt(e) {
|
|
278
|
+
const t = new Fe(), n = new Ne(t), a = (o) => new Promise((s, c) => {
|
|
279
279
|
n.load(
|
|
280
280
|
o,
|
|
281
|
-
(r) =>
|
|
281
|
+
(r) => s(r),
|
|
282
282
|
() => null,
|
|
283
283
|
() => {
|
|
284
|
-
|
|
284
|
+
c(new Error("[useTextures] - Failed to load texture"));
|
|
285
285
|
}
|
|
286
286
|
);
|
|
287
287
|
});
|
|
288
288
|
if (ge(e)) {
|
|
289
|
-
const o = await Promise.all(e.map((
|
|
289
|
+
const o = await Promise.all(e.map((s) => a(s)));
|
|
290
290
|
return e.length > 1 ? o : o[0];
|
|
291
291
|
} else {
|
|
292
292
|
const {
|
|
293
293
|
map: o,
|
|
294
|
-
displacementMap:
|
|
295
|
-
normalMap:
|
|
294
|
+
displacementMap: s,
|
|
295
|
+
normalMap: c,
|
|
296
296
|
roughnessMap: r,
|
|
297
|
-
metalnessMap:
|
|
298
|
-
aoMap:
|
|
297
|
+
metalnessMap: i,
|
|
298
|
+
aoMap: u,
|
|
299
299
|
alphaMap: l,
|
|
300
|
-
matcap:
|
|
300
|
+
matcap: p
|
|
301
301
|
} = e;
|
|
302
302
|
return {
|
|
303
303
|
map: o ? await a(o) : null,
|
|
304
|
-
displacementMap:
|
|
305
|
-
normalMap:
|
|
304
|
+
displacementMap: s ? await a(s) : null,
|
|
305
|
+
normalMap: c ? await a(c) : null,
|
|
306
306
|
roughnessMap: r ? await a(r) : null,
|
|
307
|
-
metalnessMap:
|
|
308
|
-
aoMap:
|
|
307
|
+
metalnessMap: i ? await a(i) : null,
|
|
308
|
+
aoMap: u ? await a(u) : null,
|
|
309
309
|
alphaMap: l ? await a(l) : null,
|
|
310
|
-
matcap:
|
|
310
|
+
matcap: p ? await a(p) : null
|
|
311
311
|
};
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
const pt = (e) => {
|
|
315
|
-
const { state: t } =
|
|
315
|
+
const { state: t } = k(), n = A(() => {
|
|
316
316
|
var f;
|
|
317
317
|
return (f = t.canvas) == null ? void 0 : f.value;
|
|
318
|
-
}), { x: a, y: o } = Je({ target: n }), { width:
|
|
318
|
+
}), { x: a, y: o } = Je({ target: n }), { width: s, height: c, top: r, left: i } = Xe(n), u = new ze(), l = ({ x: f, y: v }) => {
|
|
319
319
|
if (n.value)
|
|
320
320
|
return {
|
|
321
|
-
x: (f -
|
|
322
|
-
y: -((
|
|
321
|
+
x: (f - i.value) / s.value * 2 - 1,
|
|
322
|
+
y: -((v - r.value) / c.value) * 2 + 1
|
|
323
323
|
};
|
|
324
|
-
},
|
|
324
|
+
}, p = ({ x: f, y: v }) => {
|
|
325
325
|
if (t.camera)
|
|
326
|
-
return
|
|
327
|
-
},
|
|
328
|
-
const
|
|
326
|
+
return u.setFromCamera(new We(f, v), t.camera), u.intersectObjects(e.value, !1);
|
|
327
|
+
}, d = (f) => {
|
|
328
|
+
const v = l({
|
|
329
329
|
x: (f == null ? void 0 : f.clientX) ?? a.value,
|
|
330
330
|
y: (f == null ? void 0 : f.clientY) ?? o.value
|
|
331
331
|
});
|
|
332
|
-
return
|
|
333
|
-
},
|
|
334
|
-
f.trigger({ event:
|
|
335
|
-
},
|
|
336
|
-
|
|
332
|
+
return v ? p(v) || [] : [];
|
|
333
|
+
}, E = A(() => d()), y = O(), h = O(), w = (f, v) => {
|
|
334
|
+
f.trigger({ event: v, intersects: d(v) });
|
|
335
|
+
}, C = (f) => {
|
|
336
|
+
w(h, f);
|
|
337
337
|
};
|
|
338
|
-
let
|
|
339
|
-
const
|
|
340
|
-
var
|
|
341
|
-
|
|
342
|
-
},
|
|
343
|
-
var
|
|
344
|
-
f instanceof PointerEvent &&
|
|
345
|
-
},
|
|
346
|
-
n != null && n.value && (n.value.addEventListener("pointerup",
|
|
338
|
+
let g;
|
|
339
|
+
const M = (f) => {
|
|
340
|
+
var v;
|
|
341
|
+
g = (v = d(f)[0]) == null ? void 0 : v.object;
|
|
342
|
+
}, R = (f) => {
|
|
343
|
+
var v;
|
|
344
|
+
f instanceof PointerEvent && g === ((v = d(f)[0]) == null ? void 0 : v.object) && w(y, f);
|
|
345
|
+
}, T = (f) => h.trigger({ event: f, intersects: [] }), F = fe(() => {
|
|
346
|
+
n != null && n.value && (n.value.addEventListener("pointerup", R), n.value.addEventListener("pointerdown", M), n.value.addEventListener("pointermove", C), n.value.addEventListener("pointerleave", T), F());
|
|
347
347
|
});
|
|
348
348
|
return le(() => {
|
|
349
|
-
n != null && n.value && (n.value.removeEventListener("pointerup",
|
|
349
|
+
n != null && n.value && (n.value.removeEventListener("pointerup", R), n.value.removeEventListener("pointerdown", M), n.value.removeEventListener("pointermove", C), n.value.removeEventListener("pointerleave", T));
|
|
350
350
|
}), {
|
|
351
|
-
intersects:
|
|
352
|
-
onClick: (f) =>
|
|
353
|
-
onPointerMove: (f) =>
|
|
351
|
+
intersects: E,
|
|
352
|
+
onClick: (f) => y.on(f).off,
|
|
353
|
+
onPointerMove: (f) => h.on(f).off
|
|
354
354
|
};
|
|
355
355
|
};
|
|
356
|
-
function
|
|
357
|
-
const { logWarning: e } =
|
|
358
|
-
function t(a, o,
|
|
359
|
-
let
|
|
356
|
+
function _t() {
|
|
357
|
+
const { logWarning: e } = D();
|
|
358
|
+
function t(a, o, s) {
|
|
359
|
+
let c = null;
|
|
360
360
|
return a.traverse((r) => {
|
|
361
|
-
r[o] ===
|
|
362
|
-
}),
|
|
361
|
+
r[o] === s && (c = r);
|
|
362
|
+
}), c || e(`Child with ${o} '${s}' not found.`), c;
|
|
363
363
|
}
|
|
364
364
|
function n(a, o) {
|
|
365
365
|
return t(a, "name", o);
|
|
@@ -370,83 +370,83 @@ function Tt() {
|
|
|
370
370
|
};
|
|
371
371
|
}
|
|
372
372
|
const mt = () => {
|
|
373
|
-
const e =
|
|
373
|
+
const e = Ae({
|
|
374
374
|
click: /* @__PURE__ */ new Map(),
|
|
375
375
|
pointerMove: /* @__PURE__ */ new Map(),
|
|
376
376
|
pointerEnter: /* @__PURE__ */ new Map(),
|
|
377
377
|
pointerLeave: /* @__PURE__ */ new Map()
|
|
378
378
|
}), t = (r) => {
|
|
379
|
-
Object.values(e).forEach((
|
|
379
|
+
Object.values(e).forEach((i) => i.delete(r));
|
|
380
380
|
}, n = (r) => {
|
|
381
|
-
const { onClick:
|
|
382
|
-
|
|
383
|
-
r.traverse((
|
|
384
|
-
t(
|
|
381
|
+
const { onClick: i, onPointerMove: u, onPointerEnter: l, onPointerLeave: p } = r;
|
|
382
|
+
i && e.click.set(r, i), u && e.pointerMove.set(r, u), l && e.pointerEnter.set(r, l), p && e.pointerLeave.set(r, p), r.addEventListener("removed", () => {
|
|
383
|
+
r.traverse((d) => {
|
|
384
|
+
t(d);
|
|
385
385
|
}), t(r);
|
|
386
386
|
});
|
|
387
|
-
}, a =
|
|
387
|
+
}, a = A(
|
|
388
388
|
() => ft(
|
|
389
389
|
Object.values(e).map((r) => Array.from(r.keys())).flat(),
|
|
390
390
|
({ uuid: r }) => r
|
|
391
391
|
)
|
|
392
|
-
), { onClick: o, onPointerMove:
|
|
393
|
-
o(({ intersects: r, event:
|
|
394
|
-
var
|
|
395
|
-
r.length && ((
|
|
392
|
+
), { onClick: o, onPointerMove: s } = pt(a);
|
|
393
|
+
o(({ intersects: r, event: i }) => {
|
|
394
|
+
var u;
|
|
395
|
+
r.length && ((u = e.click.get(r[0].object)) == null || u(r[0], i));
|
|
396
396
|
});
|
|
397
|
-
let
|
|
398
|
-
return
|
|
399
|
-
var y, h,
|
|
400
|
-
const
|
|
401
|
-
|
|
397
|
+
let c;
|
|
398
|
+
return s(({ intersects: r, event: i }) => {
|
|
399
|
+
var E, y, h, w;
|
|
400
|
+
const u = (E = r == null ? void 0 : r[0]) == null ? void 0 : E.object, { pointerLeave: l, pointerEnter: p, pointerMove: d } = e;
|
|
401
|
+
c && c !== u && ((y = l.get(c)) == null || y(c, i)), u && (c !== u && ((h = p.get(u)) == null || h(r[0], i)), (w = d.get(u)) == null || w(r[0], i)), c = u || null;
|
|
402
402
|
}), {
|
|
403
403
|
registerObject: n,
|
|
404
404
|
deregisterObject: t
|
|
405
405
|
};
|
|
406
|
-
},
|
|
406
|
+
}, V = {
|
|
407
407
|
GEOMETRY_VIA_PROP: "tres__geometryViaProp",
|
|
408
408
|
MATERIAL_VIA_PROP: "tres__materialViaProp",
|
|
409
409
|
REGISTER_AT_POINTER_EVENT_HANDLER: "tres__registerAtPointerEventHandler"
|
|
410
410
|
};
|
|
411
|
-
let
|
|
412
|
-
const { logError: ie } =
|
|
411
|
+
let Y = null, L = null;
|
|
412
|
+
const { logError: ie } = D(), vt = {
|
|
413
413
|
createElement(e, t, n, a) {
|
|
414
|
-
var
|
|
414
|
+
var i, u;
|
|
415
415
|
if (a || (a = {}), a.args || (a.args = []), e === "template" || ct(e))
|
|
416
416
|
return null;
|
|
417
|
-
let o = e.replace("Tres", ""),
|
|
417
|
+
let o = e.replace("Tres", ""), s;
|
|
418
418
|
if (e === "primitive") {
|
|
419
419
|
(a == null ? void 0 : a.object) === void 0 && ie("Tres primitives need a prop 'object'");
|
|
420
420
|
const l = a.object;
|
|
421
|
-
o = l.type,
|
|
421
|
+
o = l.type, s = Object.assign(l, { type: o, attach: a.attach, primitive: !0 });
|
|
422
422
|
} else {
|
|
423
423
|
const l = me.value[o];
|
|
424
|
-
l || ie(`${o} is not defined on the THREE namespace. Use extend to add it to the catalog.`),
|
|
424
|
+
l || ie(`${o} is not defined on the THREE namespace. Use extend to add it to the catalog.`), s = new l(...a.args);
|
|
425
425
|
}
|
|
426
|
-
|
|
427
|
-
const { GEOMETRY_VIA_PROP:
|
|
428
|
-
return
|
|
426
|
+
s.isCamera && (a != null && a.position || s.position.set(3, 3, 3), a != null && a.lookAt || s.lookAt(0, 0, 0)), (a == null ? void 0 : a.attach) === void 0 && (s.isMaterial ? s.attach = "material" : s.isBufferGeometry && (s.attach = "geometry"));
|
|
427
|
+
const { GEOMETRY_VIA_PROP: c, MATERIAL_VIA_PROP: r } = V;
|
|
428
|
+
return s.isObject3D && ((i = a == null ? void 0 : a.material) != null && i.isMaterial && (s.userData[r] = !0), (u = a == null ? void 0 : a.geometry) != null && u.isBufferGeometry && (s.userData[c] = !0)), s;
|
|
429
429
|
},
|
|
430
430
|
insert(e, t) {
|
|
431
|
-
var n, a, o,
|
|
432
|
-
if (t && t.isScene && (
|
|
433
|
-
|
|
431
|
+
var n, a, o, s, c, r, i;
|
|
432
|
+
if (t && t.isScene && (L = t), (((n = e == null ? void 0 : e.__vnode) == null ? void 0 : n.type) === "TresGroup" || ((a = e == null ? void 0 : e.__vnode) == null ? void 0 : a.type) === "TresObject3D") && t === null && !((s = (o = e == null ? void 0 : e.__vnode) == null ? void 0 : o.ctx) != null && s.asyncResolved)) {
|
|
433
|
+
Y = e;
|
|
434
434
|
return;
|
|
435
435
|
} else
|
|
436
|
-
(
|
|
437
|
-
t || (t =
|
|
436
|
+
(c = e == null ? void 0 : e.__vnode) != null && c.type.includes("Controls") && t === null && (Y = L);
|
|
437
|
+
t || (t = Y), e != null && e.isObject3D && (t != null && t.isObject3D) ? (t.add(e), e.dispatchEvent({ type: "added" }), (i = (r = L == null ? void 0 : L.userData) == null ? void 0 : r[V.REGISTER_AT_POINTER_EVENT_HANDLER]) == null || i.call(r, e)) : e != null && e.isFog ? t.fog = e : typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
|
|
438
438
|
},
|
|
439
439
|
remove(e) {
|
|
440
440
|
var t, n;
|
|
441
441
|
if (e) {
|
|
442
442
|
if (e.isObject3D) {
|
|
443
|
-
const a = e, o = (
|
|
444
|
-
var
|
|
445
|
-
const { GEOMETRY_VIA_PROP:
|
|
446
|
-
|
|
443
|
+
const a = e, o = (s) => {
|
|
444
|
+
var i, u;
|
|
445
|
+
const { GEOMETRY_VIA_PROP: c, MATERIAL_VIA_PROP: r } = V;
|
|
446
|
+
s.userData[r] || (i = s.material) == null || i.dispose(), s.userData[c] || (u = s.geometry) == null || u.dispose();
|
|
447
447
|
};
|
|
448
|
-
a.traverse((
|
|
449
|
-
o(
|
|
448
|
+
a.traverse((s) => {
|
|
449
|
+
o(s);
|
|
450
450
|
}), o(a);
|
|
451
451
|
}
|
|
452
452
|
(t = e.removeFromParent) == null || t.call(e), (n = e.dispose) == null || n.call(e);
|
|
@@ -454,26 +454,26 @@ const { logError: ie } = O(), vt = {
|
|
|
454
454
|
},
|
|
455
455
|
patchProp(e, t, n, a) {
|
|
456
456
|
if (e) {
|
|
457
|
-
let o = e,
|
|
457
|
+
let o = e, s = t, c = j(s), r = o == null ? void 0 : o[c];
|
|
458
458
|
if (o.type === "BufferGeometry") {
|
|
459
|
-
if (
|
|
459
|
+
if (s === "args")
|
|
460
460
|
return;
|
|
461
461
|
o.setAttribute(
|
|
462
|
-
j(
|
|
463
|
-
new
|
|
462
|
+
j(s),
|
|
463
|
+
new $e(...a)
|
|
464
464
|
);
|
|
465
465
|
return;
|
|
466
466
|
}
|
|
467
|
-
if (
|
|
468
|
-
const
|
|
469
|
-
r =
|
|
467
|
+
if (s.includes("-") && r === void 0) {
|
|
468
|
+
const u = s.split("-");
|
|
469
|
+
r = u.reduce((l, p) => l[j(p)], o), s = u.pop(), c = s.toLowerCase(), r != null && r.set || (o = u.reduce((l, p) => l[j(p)], o));
|
|
470
470
|
}
|
|
471
|
-
let
|
|
472
|
-
if (
|
|
473
|
-
Array.isArray(
|
|
471
|
+
let i = a;
|
|
472
|
+
if (i === "" && (i = !0), re(r)) {
|
|
473
|
+
Array.isArray(i) ? e[c](...i) : e[c](i);
|
|
474
474
|
return;
|
|
475
475
|
}
|
|
476
|
-
!(r != null && r.set) && !re(r) ? o[
|
|
476
|
+
!(r != null && r.set) && !re(r) ? o[c] = i : r.constructor === i.constructor && (r != null && r.copy) ? r == null || r.copy(i) : Array.isArray(i) ? r.set(...i) : !r.isColor && r.setScalar ? r.setScalar(i) : r.set(i);
|
|
477
477
|
}
|
|
478
478
|
},
|
|
479
479
|
parentNode(e) {
|
|
@@ -496,7 +496,7 @@ const { logError: ie } = O(), vt = {
|
|
|
496
496
|
return t;
|
|
497
497
|
};
|
|
498
498
|
ve(q);
|
|
499
|
-
const { logWarning: se } =
|
|
499
|
+
const { logWarning: se } = D(), bt = de({
|
|
500
500
|
name: "TresScene",
|
|
501
501
|
props: [
|
|
502
502
|
"shadows",
|
|
@@ -517,52 +517,52 @@ const { logWarning: se } = O(), bt = de({
|
|
|
517
517
|
],
|
|
518
518
|
setup(e, { slots: t, expose: n }) {
|
|
519
519
|
e.physicallyCorrectLights === !0 && se("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
|
|
520
|
-
const a =
|
|
521
|
-
|
|
522
|
-
const { onLoop:
|
|
520
|
+
const a = A(() => e.disableRender !== !1 && e.disableRender !== void 0), o = G(), s = G(), c = new q.Scene(), r = mt(), { setState: i } = k();
|
|
521
|
+
c.userData[V.REGISTER_AT_POINTER_EVENT_HANDLER] = r.registerObject, i("scene", c), i("canvas", s), i("container", o), i("pointerEventHandler", r);
|
|
522
|
+
const { onLoop: u, resume: l } = he();
|
|
523
523
|
ke(() => {
|
|
524
524
|
h();
|
|
525
525
|
}), le(() => {
|
|
526
|
-
|
|
526
|
+
i("renderer", null);
|
|
527
527
|
});
|
|
528
|
-
const { activeCamera:
|
|
528
|
+
const { activeCamera: p, pushCamera: d, clearCameras: E } = at();
|
|
529
529
|
function y() {
|
|
530
|
-
const
|
|
531
|
-
if (
|
|
532
|
-
d(
|
|
530
|
+
const g = c.getObjectByProperty("isCamera", !0);
|
|
531
|
+
if (g)
|
|
532
|
+
d(g);
|
|
533
533
|
else {
|
|
534
534
|
se("No camera found. Creating a default perspective camera. To have full control over a camera, please add one to the scene.");
|
|
535
|
-
const
|
|
536
|
-
|
|
535
|
+
const M = new q.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1e3);
|
|
536
|
+
M.position.set(3, 3, 3), M.lookAt(0, 0, 0), d(M);
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
539
|
function h() {
|
|
540
|
-
const { renderer:
|
|
541
|
-
e.camera && d(e.camera),
|
|
542
|
-
var
|
|
543
|
-
|
|
540
|
+
const { renderer: g } = lt(e);
|
|
541
|
+
e.camera && d(e.camera), u(() => {
|
|
542
|
+
var M;
|
|
543
|
+
p.value && !a.value && ((M = g.value) == null || M.render(c, p.value));
|
|
544
544
|
});
|
|
545
545
|
}
|
|
546
|
-
let
|
|
547
|
-
function
|
|
548
|
-
|
|
549
|
-
const
|
|
550
|
-
|
|
546
|
+
let w;
|
|
547
|
+
function C() {
|
|
548
|
+
w = wt(t);
|
|
549
|
+
const g = k();
|
|
550
|
+
w.provide("useTres", g), w.provide(K, g), w.provide("extend", ve), w.mount(c), y();
|
|
551
551
|
}
|
|
552
|
-
return
|
|
553
|
-
scene:
|
|
554
|
-
}),
|
|
552
|
+
return C(), n({
|
|
553
|
+
scene: c
|
|
554
|
+
}), I(
|
|
555
555
|
() => e.camera,
|
|
556
|
-
(
|
|
557
|
-
|
|
556
|
+
(g) => {
|
|
557
|
+
g && (E(), d(g));
|
|
558
558
|
}
|
|
559
|
-
), () =>
|
|
560
|
-
|
|
559
|
+
), () => _(
|
|
560
|
+
_(
|
|
561
561
|
"div",
|
|
562
562
|
{
|
|
563
|
-
ref:
|
|
564
|
-
"data-scene":
|
|
565
|
-
key:
|
|
563
|
+
ref: o,
|
|
564
|
+
"data-scene": c.uuid,
|
|
565
|
+
key: c.uuid,
|
|
566
566
|
style: {
|
|
567
567
|
position: "relative",
|
|
568
568
|
width: "100%",
|
|
@@ -572,7 +572,7 @@ const { logWarning: se } = O(), bt = de({
|
|
|
572
572
|
}
|
|
573
573
|
},
|
|
574
574
|
[
|
|
575
|
-
|
|
575
|
+
_(
|
|
576
576
|
"div",
|
|
577
577
|
{
|
|
578
578
|
style: {
|
|
@@ -581,9 +581,9 @@ const { logWarning: se } = O(), bt = de({
|
|
|
581
581
|
}
|
|
582
582
|
},
|
|
583
583
|
[
|
|
584
|
-
|
|
585
|
-
ref:
|
|
586
|
-
"data-scene":
|
|
584
|
+
_("canvas", {
|
|
585
|
+
ref: s,
|
|
586
|
+
"data-scene": c.uuid,
|
|
587
587
|
style: {
|
|
588
588
|
display: "block",
|
|
589
589
|
width: "100%",
|
|
@@ -620,9 +620,19 @@ const { logWarning: se } = O(), bt = de({
|
|
|
620
620
|
],
|
|
621
621
|
setup(e, { slots: t, expose: n }) {
|
|
622
622
|
const a = Ze();
|
|
623
|
-
return n(a), () =>
|
|
623
|
+
return n(a), () => _(bt, e, t);
|
|
624
|
+
}
|
|
625
|
+
}), yt = [
|
|
626
|
+
"TresCanvas",
|
|
627
|
+
"TresLeches",
|
|
628
|
+
"TresScene"
|
|
629
|
+
], Et = {
|
|
630
|
+
template: {
|
|
631
|
+
compilerOptions: {
|
|
632
|
+
isCustomElement: (e) => e.startsWith("Tres") && !yt.includes(e) || e === "primitive"
|
|
633
|
+
}
|
|
624
634
|
}
|
|
625
|
-
}
|
|
635
|
+
}, St = Et, At = {
|
|
626
636
|
install(e) {
|
|
627
637
|
e.component("TresCanvas", ht);
|
|
628
638
|
}
|
|
@@ -632,21 +642,22 @@ export {
|
|
|
632
642
|
K as TRES_CONTEXT_KEY,
|
|
633
643
|
ht as TresCanvas,
|
|
634
644
|
me as catalogue,
|
|
635
|
-
|
|
645
|
+
At as default,
|
|
636
646
|
ve as extend,
|
|
637
|
-
|
|
647
|
+
Tt as isProd,
|
|
638
648
|
it as normalizeColor,
|
|
639
|
-
|
|
649
|
+
Rt as normalizeVectorFlexibleParam,
|
|
650
|
+
St as templateCompilerOptions,
|
|
640
651
|
dt as trasverseObjects,
|
|
641
652
|
at as useCamera,
|
|
642
|
-
|
|
643
|
-
|
|
653
|
+
xt as useLoader,
|
|
654
|
+
D as useLogger,
|
|
644
655
|
mt as usePointerEventHandler,
|
|
645
656
|
pt as useRaycaster,
|
|
646
657
|
he as useRenderLoop,
|
|
647
658
|
lt as useRenderer,
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
659
|
+
_t as useSeek,
|
|
660
|
+
Lt as useTexture,
|
|
661
|
+
k as useTres,
|
|
651
662
|
Ze as useTresProvider
|
|
652
663
|
};
|
package/dist/tres.umd.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v2.
|
|
3
|
+
* version: v2.4.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
|
-
(function(m,
|
|
9
|
-
You could set windowSize=true to force the canvas to be the size of the window.`)},1e3);const ve=()=>{t.value&&(t.value.setSize(de.value,me.value),t.value.setPixelRatio(Math.min(pe.value,2)))},ge=()=>{if(!t.value)return;const S=l.toValue($);if(S){S in Y||De("Renderer Preset must be one of these: "+Object.keys(Y).join(", ")),ne(t.value,Y[S]);return}t.value.shadowMap.enabled=l.toValue(v),t.value.shadowMap.type=l.toValue(h),t.value.toneMapping=l.toValue(w)||g.NoToneMapping,t.value.toneMappingExposure=l.toValue(L),t.value.outputColorSpace=l.toValue(C)||g.LinearSRGBColorSpace,O!=null&&O.value&&t.value.setClearColor(ae(l.toValue(O))),t.value.useLegacyLights=l.toValue(M)},Ne=()=>{const S=l.unrefElement(d.canvas);S&&(t.value=new g.WebGLRenderer({canvas:S,alpha:l.toValue(a),antialias:l.toValue(o),context:l.toValue(y),depth:l.toValue(i),failIfMajorPerformanceCaveat:l.toValue(r),logarithmicDepthBuffer:l.toValue(u),powerPreference:l.toValue(_),precision:l.toValue(s),stencil:l.toValue(p),preserveDrawingBuffer:l.toValue(G),premultipliedAlpha:l.toValue(c)}),b("renderer",t.value),b("clock",new g.Clock),b("aspectRatio",K),ge(),ve(),Ge(),n.value=!0)},ze=()=>{t.value&&(t.value.dispose(),t.value=void 0,n.value=!1,Be())};return f.watch([K,pe],ve),f.watch([v,h,C,M,w,L,O],ge),f.watch(()=>[d.canvas,d.container],()=>{l.unrefElement(d.canvas)&&l.unrefElement(d.container)&&Ne()},{immediate:!0,deep:!0}),{renderer:t,isReady:n,dispose:ze,aspectRatio:K}}function ie(e){const t={nodes:{},materials:{}};return e&&e.traverse(n=>{n.name&&(t.nodes[n.name]=n),n.material&&!t.materials[n.material.name]&&(t.materials[n.material.name]=n.material)}),t}async function Te(e,t,n,a,o){const{logError:i}=E(),u=new e;o&&o(u),n&&n(u);const s=(Array.isArray(t)?t:[t]).map(c=>new Promise((p,v)=>{u.load(c,h=>{h.scene&&Object.assign(h,ie(h.scene)),p(h)},a,h=>v(i("[useLoader] - Failed to load resource",h)))}));return H(t)?await Promise.all(s):await s[0]}async function Ae(e){const t=new g.LoadingManager,n=new g.TextureLoader(t),a=o=>new Promise((i,u)=>{n.load(o,r=>i(r),()=>null,()=>{u(new Error("[useTextures] - Failed to load texture"))})});if(H(e)){const o=await Promise.all(e.map(i=>a(i)));return e.length>1?o:o[0]}else{const{map:o,displacementMap:i,normalMap:u,roughnessMap:r,metalnessMap:s,aoMap:c,alphaMap:p,matcap:v}=e;return{map:o?await a(o):null,displacementMap:i?await a(i):null,normalMap:u?await a(u):null,roughnessMap:r?await a(r):null,metalnessMap:s?await a(s):null,aoMap:c?await a(c):null,alphaMap:p?await a(p):null,matcap:v?await a(v):null}}}const se=e=>{const{state:t}=A(),n=f.computed(()=>{var d;return(d=t.canvas)==null?void 0:d.value}),{x:a,y:o}=l.usePointer({target:n}),{width:i,height:u,top:r,left:s}=l.useElementBounding(n),c=new g.Raycaster,p=({x:d,y:b})=>{if(n.value)return{x:(d-s.value)/i.value*2-1,y:-((b-r.value)/u.value)*2+1}},v=({x:d,y:b})=>{if(t.camera)return c.setFromCamera(new g.Vector2(d,b),t.camera),c.intersectObjects(e.value,!1)},h=d=>{const b=p({x:(d==null?void 0:d.clientX)??a.value,y:(d==null?void 0:d.clientY)??o.value});return b?v(b)||[]:[]},M=f.computed(()=>h()),C=l.createEventHook(),w=l.createEventHook(),L=(d,b)=>{d.trigger({event:b,intersects:h(b)})},y=d=>{L(w,d)};let _;const G=d=>{var b;_=(b=h(d)[0])==null?void 0:b.object},O=d=>{var b;d instanceof PointerEvent&&_===((b=h(d)[0])==null?void 0:b.object)&&L(C,d)},T=d=>w.trigger({event:d,intersects:[]}),$=f.watchEffect(()=>{n!=null&&n.value&&(n.value.addEventListener("pointerup",O),n.value.addEventListener("pointerdown",G),n.value.addEventListener("pointermove",y),n.value.addEventListener("pointerleave",T),$())});return f.onUnmounted(()=>{n!=null&&n.value&&(n.value.removeEventListener("pointerup",O),n.value.removeEventListener("pointerdown",G),n.value.removeEventListener("pointermove",y),n.value.removeEventListener("pointerleave",T))}),{intersects:M,onClick:d=>C.on(d).off,onPointerMove:d=>w.on(d).off}};function xe(){const{logWarning:e}=E();function t(a,o,i){let u=null;return a.traverse(r=>{r[o]===i&&(u=r)}),u||e(`Child with ${o} '${i}' not found.`),u}function n(a,o){return t(a,"name",o)}return{seek:t,seekByName:n}}const ce=()=>{const e=f.reactive({click:new Map,pointerMove:new Map,pointerEnter:new Map,pointerLeave:new Map}),t=r=>{Object.values(e).forEach(s=>s.delete(r))},n=r=>{const{onClick:s,onPointerMove:c,onPointerEnter:p,onPointerLeave:v}=r;s&&e.click.set(r,s),c&&e.pointerMove.set(r,c),p&&e.pointerEnter.set(r,p),v&&e.pointerLeave.set(r,v),r.addEventListener("removed",()=>{r.traverse(h=>{t(h)}),t(r)})},a=f.computed(()=>Se(Object.values(e).map(r=>Array.from(r.keys())).flat(),({uuid:r})=>r)),{onClick:o,onPointerMove:i}=se(a);o(({intersects:r,event:s})=>{var c;r.length&&((c=e.click.get(r[0].object))==null||c(r[0],s))});let u;return i(({intersects:r,event:s})=>{var M,C,w,L;const c=(M=r==null?void 0:r[0])==null?void 0:M.object,{pointerLeave:p,pointerEnter:v,pointerMove:h}=e;u&&u!==c&&((C=p.get(u))==null||C(u,s)),c&&(u!==c&&((w=v.get(c))==null||w(r[0],s)),(L=h.get(c))==null||L(r[0],s)),u=c||null}),{registerObject:n,deregisterObject:t}},B={GEOMETRY_VIA_PROP:"tres__geometryViaProp",MATERIAL_VIA_PROP:"tres__materialViaProp",REGISTER_AT_POINTER_EVENT_HANDLER:"tres__registerAtPointerEventHandler"};function We(e){}let q=null,k=null;const{logError:ue}=E(),Ee={createElement(e,t,n,a){var s,c;if(a||(a={}),a.args||(a.args=[]),e==="template"||_e(e))return null;let o=e.replace("Tres",""),i;if(e==="primitive"){(a==null?void 0:a.object)===void 0&&ue("Tres primitives need a prop 'object'");const p=a.object;o=p.type,i=Object.assign(p,{type:o,attach:a.attach,primitive:!0})}else{const p=z.value[o];p||ue(`${o} is not defined on the THREE namespace. Use extend to add it to the catalog.`),i=new p(...a.args)}i.isCamera&&(a!=null&&a.position||i.position.set(3,3,3),a!=null&&a.lookAt||i.lookAt(0,0,0)),(a==null?void 0:a.attach)===void 0&&(i.isMaterial?i.attach="material":i.isBufferGeometry&&(i.attach="geometry"));const{GEOMETRY_VIA_PROP:u,MATERIAL_VIA_PROP:r}=B;return i.isObject3D&&((s=a==null?void 0:a.material)!=null&&s.isMaterial&&(i.userData[r]=!0),(c=a==null?void 0:a.geometry)!=null&&c.isBufferGeometry&&(i.userData[u]=!0)),i},insert(e,t){var n,a,o,i,u,r,s;if(t&&t.isScene&&(k=t),(((n=e==null?void 0:e.__vnode)==null?void 0:n.type)==="TresGroup"||((a=e==null?void 0:e.__vnode)==null?void 0:a.type)==="TresObject3D")&&t===null&&!((i=(o=e==null?void 0:e.__vnode)==null?void 0:o.ctx)!=null&&i.asyncResolved)){q=e;return}else(u=e==null?void 0:e.__vnode)!=null&&u.type.includes("Controls")&&t===null&&(q=k);t||(t=q),e!=null&&e.isObject3D&&(t!=null&&t.isObject3D)?(t.add(e),e.dispatchEvent({type:"added"}),(s=(r=k==null?void 0:k.userData)==null?void 0:r[B.REGISTER_AT_POINTER_EVENT_HANDLER])==null||s.call(r,e)):e!=null&&e.isFog?t.fog=e:typeof(e==null?void 0:e.attach)=="string"&&(e.__previousAttach=e[t==null?void 0:t.attach],t&&(t[e.attach]=e))},remove(e){var t,n;if(e){if(e.isObject3D){const a=e,o=i=>{var s,c;const{GEOMETRY_VIA_PROP:u,MATERIAL_VIA_PROP:r}=B;i.userData[r]||(s=i.material)==null||s.dispose(),i.userData[u]||(c=i.geometry)==null||c.dispose()};a.traverse(i=>{o(i)}),o(a)}(t=e.removeFromParent)==null||t.call(e),(n=e.dispose)==null||n.call(e)}},patchProp(e,t,n,a){if(e){let o=e,i=t,u=I(i),r=o==null?void 0:o[u];if(o.type==="BufferGeometry"){if(i==="args")return;o.setAttribute(I(i),new g.BufferAttribute(...a));return}if(i.includes("-")&&r===void 0){const c=i.split("-");r=c.reduce((p,v)=>p[I(v)],o),i=c.pop(),u=i.toLowerCase(),r!=null&&r.set||(o=c.reduce((p,v)=>p[I(v)],o))}let s=a;if(s===""&&(s=!0),X(r)){Array.isArray(s)?e[u](...s):e[u](s);return}!(r!=null&&r.set)&&!X(r)?o[u]=s:r.constructor===s.constructor&&(r!=null&&r.copy)?r==null||r.copy(s):Array.isArray(s)?r.set(...s):!r.isColor&&r.setScalar?r.setScalar(s):r.set(s)}},parentNode(e){return(e==null?void 0:e.parent)||null},createText:()=>void 0,createComment:()=>void 0,setText:()=>void 0,setElementText:()=>void 0,nextSibling:()=>void 0,querySelector:()=>void 0,setScopeId:()=>void 0,cloneNode:()=>void 0,insertStaticContent:()=>void 0},{createApp:Re}=f.createRenderer(Ee),ke=e=>{const t=Re(n);function n(){return e&&e.default?e.default():[]}return t};F(N);const{logWarning:fe}=E(),Ve=f.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:n}){e.physicallyCorrectLights===!0&&fe("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const a=f.ref(),o=f.ref(),i=new N.Scene,u=ce(),{setState:r}=A();i.userData[B.REGISTER_AT_POINTER_EVENT_HANDLER]=u.registerObject,r("scene",i),r("canvas",o),r("container",a),r("pointerEventHandler",u);const{onLoop:s,resume:c}=U();f.onMounted(()=>{C()}),f.onUnmounted(()=>{r("renderer",null)});const{activeCamera:p,pushCamera:v,clearCameras:h}=Z();function M(){const y=i.getObjectByProperty("isCamera",!0);if(y)v(y);else{fe("No camera found. Creating a default perspective camera. To have full control over a camera, please add one to the scene.");const _=new N.PerspectiveCamera(45,window.innerWidth/window.innerHeight,.1,1e3);_.position.set(3,3,3),_.lookAt(0,0,0),v(_)}}function C(){const{renderer:y}=oe(e);e.camera&&v(e.camera),s(()=>{var _;p.value&&e.disableRender!==!0&&((_=y.value)==null||_.render(i,p.value))})}let w;function L(){w=ke(t);const y=A();w.provide("useTres",y),w.provide(V,y),w.provide("extend",F),w.mount(i),M()}return L(),n({scene:i}),f.watch(()=>e.camera,y=>{y&&(h(),v(y))}),()=>f.h(f.h("div",{ref:a,"data-scene":i.uuid,key:i.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[f.h("div",{style:{width:"100%",height:"100%"}},[f.h("canvas",{ref:o,"data-scene":i.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),le=f.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:n}){const a=J();return n(a),()=>f.h(Ve,e,t)}}),je={install(e){e.component("TresCanvas",le)}};m.CameraType=Q,m.TRES_CONTEXT_KEY=V,m.TresCanvas=le,m.catalogue=z,m.default=je,m.extend=F,m.isProd=Oe,m.normalizeColor=ae,m.normalizeVectorFlexibleParam=Me,m.trasverseObjects=ie,m.useCamera=Z,m.useLoader=Te,m.useLogger=E,m.usePointerEventHandler=ce,m.useRaycaster=se,m.useRenderLoop=U,m.useRenderer=oe,m.useSeek=xe,m.useTexture=Ae,m.useTres=A,m.useTresProvider=J,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
8
|
+
(function(m,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],l):(m=typeof globalThis<"u"?globalThis:m||self,l(m.tres={},m.Vue,m.Three,m.VueUseCore))})(this,function(m,l,g,f){"use strict";function he(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const n=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(t,a,n.get?n:{enumerable:!0,get:()=>e[a]})}}return t.default=e,Object.freeze(t)}const N=he(g),z=l.ref({}),F=e=>void Object.assign(z.value,e),X=e=>typeof e=="function",H=e=>!!e&&e.constructor===Array,y=["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"];function we(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,a=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(y[e&255]+y[e>>8&255]+y[e>>16&255]+y[e>>24&255]+"-"+y[t&255]+y[t>>8&255]+"-"+y[t>>16&15|64]+y[t>>24&255]+"-"+y[a&63|128]+y[a>>8&255]+"-"+y[a>>16&255]+y[a>>24&255]+y[n&255]+y[n>>8&255]+y[n>>16&255]+y[n>>24&255]).toLowerCase()}const j=Symbol();function J(){const e=l.shallowReactive({uuid:we(),camera:void 0,cameras:[],canvas:void 0,scene:void 0,renderer:void 0,aspectRatio:void 0,pointerEventHandler:void 0});function t(o){return e[o]}function a(o,s){e[o]=s}const n={state:e,...l.toRefs(e),getState:t,setState:a};return l.provide(j,n),n}const E=()=>l.inject(j,{state:l.shallowReactive({camera:void 0,cameras:[],canvas:void 0,scene:void 0,renderer:void 0,pointerEventHandler:void 0})});var Q=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(Q||{});const be=45;let R;function Z(){const{state:e,setState:t,aspectRatio:a}=E();function n(i="Perspective",u){var p,h,v;if(i==="Perspective"){const{near:L,far:M,fov:P}=u||{near:.1,far:1e3,fov:be};R=new g.PerspectiveCamera(P,((p=e.aspectRatio)==null?void 0:p.value)||window.innerWidth/window.innerHeight,L,M),(h=e.cameras)==null||h.push(R)}else{const{left:L,right:M,top:P,bottom:C,near:O,far:b}=u||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};R=new g.OrthographicCamera(L,M,P,C,O,b),(v=e.cameras)==null||v.push(R)}return e.camera=R,t("camera",e.camera),R}function o(){var i;e.camera instanceof g.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(i=e.camera)==null||i.updateProjectionMatrix()}function s(i){var u;(u=e.cameras)==null||u.push(i),i instanceof g.PerspectiveCamera&&e.aspectRatio&&(i.aspect=e.aspectRatio.value),i.updateProjectionMatrix(),t("camera",i)}function c(i){var u;((u=e.cameras)==null?void 0:u.length)===0&&s(i)}function r(){e.cameras=[]}return l.watchEffect(()=>{a!=null&&a.value&&o()}),{activeCamera:l.toRef(e,"camera"),createCamera:n,updateCamera:o,pushCamera:s,clearCameras:r,setFirstCamera:c}}const ee=f.createEventHook(),te=f.createEventHook(),W=f.createEventHook(),k=new g.Clock;let D=0,I=0;const{pause:ye,resume:Ce,isActive:Pe}=f.useRafFn(()=>{ee.trigger({delta:D,elapsed:I,clock:k}),te.trigger({delta:D,elapsed:I,clock:k}),W.trigger({delta:D,elapsed:I,clock:k})},{immediate:!1});W.on(()=>{D=k.getDelta(),I=k.getElapsedTime()});function U(){return{onBeforeLoop:ee.on,onLoop:te.on,onAfterLoop:W.on,pause:ye,resume:Ce,isActive:Pe}}function Me(e){return typeof e=="number"?[e,e,e]:e instanceof g.Vector3?[e.x,e.y,e.z]:e}function ae(e){return e instanceof g.Color?e:Array.isArray(e)?new g.Color(...e):new g.Color(e)}const Y={realistic:{outputColorSpace:g.SRGBColorSpace,toneMapping:g.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:g.PCFSoftShadowMap}}},ne=(e,t)=>{for(const a of Object.keys(t))t[a]instanceof Object&&Object.assign(t[a],ne(e[a],t[a]));return Object.assign(e||{},t),e},Le=_e("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");function B(e){return e.replace(/-([a-z])/g,(t,a)=>a.toUpperCase())}function _e(e,t){const a=Object.create(null),n=e.split(",");for(let o=0;o<n.length;o++)a[n[o]]=!0;return t?o=>!!a[o.toLowerCase()]:o=>!!a[o]}const Se=(e,t)=>{const a=new Set,n=[];for(const o of e){const s=t(o);a.has(s)||(a.add(s),n.push(o))}return n},Oe=!0,re="[TresJS ▲ ■ ●] ";function x(){function e(n,o){console.error(`${re} ${n}`,o||"")}function t(n){console.warn(`${re} ${n}`)}function a(n,o){}return{logError:e,logWarning:t,logMessage:a}}function oe(e){const t=l.shallowRef(),a=l.ref(!1),{alpha:n=!0,antialias:o=!0,depth:s,logarithmicDepthBuffer:c,failIfMajorPerformanceCaveat:r,precision:i,premultipliedAlpha:u,stencil:p,shadows:h=!1,shadowMapType:v=g.PCFShadowMap,useLegacyLights:L=!1,outputColorSpace:M=g.LinearSRGBColorSpace,toneMapping:P=g.NoToneMapping,toneMappingExposure:C=1,context:O=void 0,powerPreference:b="default",preserveDrawingBuffer:_=!1,clearColor:T,windowSize:A=!1,preset:q=void 0}=l.toRefs(e),{state:d,setState:w}=E(),{width:de,height:me}=f.toValue(A)==!0||f.toValue(A)===""||f.toValue(A)==="true"?f.useWindowSize():f.useElementSize(d.container),{logError:Be,logWarning:Ge}=x(),{pixelRatio:pe}=f.useDevicePixelRatio(),{pause:Ne,resume:ze}=U(),K=l.computed(()=>de.value/me.value);setTimeout(()=>{var S;!f.toValue(A)&&!((S=d.canvas)!=null&&S.value.offsetHeight)&&Ge(`Oops... Seems like your canvas height is currently 0px, it's posible that you couldn't watch your scene.
|
|
9
|
+
You could set windowSize=true to force the canvas to be the size of the window.`)},1e3);const ve=()=>{t.value&&(t.value.setSize(de.value,me.value),t.value.setPixelRatio(Math.min(pe.value,2)))},ge=()=>{if(!t.value)return;const S=f.toValue(q);if(S){S in Y||Be("Renderer Preset must be one of these: "+Object.keys(Y).join(", ")),ne(t.value,Y[S]);return}t.value.shadowMap.enabled=f.toValue(h),t.value.shadowMap.type=f.toValue(v),t.value.toneMapping=f.toValue(P)||g.NoToneMapping,t.value.toneMappingExposure=f.toValue(C),t.value.outputColorSpace=f.toValue(M)||g.LinearSRGBColorSpace,T!=null&&T.value&&t.value.setClearColor(ae(f.toValue(T))),t.value.useLegacyLights=f.toValue(L)},Fe=()=>{const S=f.unrefElement(d.canvas);S&&(t.value=new g.WebGLRenderer({canvas:S,alpha:f.toValue(n),antialias:f.toValue(o),context:f.toValue(O),depth:f.toValue(s),failIfMajorPerformanceCaveat:f.toValue(r),logarithmicDepthBuffer:f.toValue(c),powerPreference:f.toValue(b),precision:f.toValue(i),stencil:f.toValue(p),preserveDrawingBuffer:f.toValue(_),premultipliedAlpha:f.toValue(u)}),w("renderer",t.value),w("clock",new g.Clock),w("aspectRatio",K),ge(),ve(),ze(),a.value=!0)},We=()=>{t.value&&(t.value.dispose(),t.value=void 0,a.value=!1,Ne())};return l.watch([K,pe],ve),l.watch([h,v,M,L,P,C,T],ge),l.watch(()=>[d.canvas,d.container],()=>{f.unrefElement(d.canvas)&&f.unrefElement(d.container)&&Fe()},{immediate:!0,deep:!0}),{renderer:t,isReady:a,dispose:We,aspectRatio:K}}function ie(e){const t={nodes:{},materials:{}};return e&&e.traverse(a=>{a.name&&(t.nodes[a.name]=a),a.material&&!t.materials[a.material.name]&&(t.materials[a.material.name]=a.material)}),t}async function Te(e,t,a,n,o){const{logError:s}=x(),c=new e;o&&o(c),a&&a(c);const i=(Array.isArray(t)?t:[t]).map(u=>new Promise((p,h)=>{c.load(u,v=>{v.scene&&Object.assign(v,ie(v.scene)),p(v)},n,v=>h(s("[useLoader] - Failed to load resource",v)))}));return H(t)?await Promise.all(i):await i[0]}async function Ae(e){const t=new g.LoadingManager,a=new g.TextureLoader(t),n=o=>new Promise((s,c)=>{a.load(o,r=>s(r),()=>null,()=>{c(new Error("[useTextures] - Failed to load texture"))})});if(H(e)){const o=await Promise.all(e.map(s=>n(s)));return e.length>1?o:o[0]}else{const{map:o,displacementMap:s,normalMap:c,roughnessMap:r,metalnessMap:i,aoMap:u,alphaMap:p,matcap:h}=e;return{map:o?await n(o):null,displacementMap:s?await n(s):null,normalMap:c?await n(c):null,roughnessMap:r?await n(r):null,metalnessMap:i?await n(i):null,aoMap:u?await n(u):null,alphaMap:p?await n(p):null,matcap:h?await n(h):null}}}const se=e=>{const{state:t}=E(),a=l.computed(()=>{var d;return(d=t.canvas)==null?void 0:d.value}),{x:n,y:o}=f.usePointer({target:a}),{width:s,height:c,top:r,left:i}=f.useElementBounding(a),u=new g.Raycaster,p=({x:d,y:w})=>{if(a.value)return{x:(d-i.value)/s.value*2-1,y:-((w-r.value)/c.value)*2+1}},h=({x:d,y:w})=>{if(t.camera)return u.setFromCamera(new g.Vector2(d,w),t.camera),u.intersectObjects(e.value,!1)},v=d=>{const w=p({x:(d==null?void 0:d.clientX)??n.value,y:(d==null?void 0:d.clientY)??o.value});return w?h(w)||[]:[]},L=l.computed(()=>v()),M=f.createEventHook(),P=f.createEventHook(),C=(d,w)=>{d.trigger({event:w,intersects:v(w)})},O=d=>{C(P,d)};let b;const _=d=>{var w;b=(w=v(d)[0])==null?void 0:w.object},T=d=>{var w;d instanceof PointerEvent&&b===((w=v(d)[0])==null?void 0:w.object)&&C(M,d)},A=d=>P.trigger({event:d,intersects:[]}),q=l.watchEffect(()=>{a!=null&&a.value&&(a.value.addEventListener("pointerup",T),a.value.addEventListener("pointerdown",_),a.value.addEventListener("pointermove",O),a.value.addEventListener("pointerleave",A),q())});return l.onUnmounted(()=>{a!=null&&a.value&&(a.value.removeEventListener("pointerup",T),a.value.removeEventListener("pointerdown",_),a.value.removeEventListener("pointermove",O),a.value.removeEventListener("pointerleave",A))}),{intersects:L,onClick:d=>M.on(d).off,onPointerMove:d=>P.on(d).off}};function Ee(){const{logWarning:e}=x();function t(n,o,s){let c=null;return n.traverse(r=>{r[o]===s&&(c=r)}),c||e(`Child with ${o} '${s}' not found.`),c}function a(n,o){return t(n,"name",o)}return{seek:t,seekByName:a}}const ce=()=>{const e=l.reactive({click:new Map,pointerMove:new Map,pointerEnter:new Map,pointerLeave:new Map}),t=r=>{Object.values(e).forEach(i=>i.delete(r))},a=r=>{const{onClick:i,onPointerMove:u,onPointerEnter:p,onPointerLeave:h}=r;i&&e.click.set(r,i),u&&e.pointerMove.set(r,u),p&&e.pointerEnter.set(r,p),h&&e.pointerLeave.set(r,h),r.addEventListener("removed",()=>{r.traverse(v=>{t(v)}),t(r)})},n=l.computed(()=>Se(Object.values(e).map(r=>Array.from(r.keys())).flat(),({uuid:r})=>r)),{onClick:o,onPointerMove:s}=se(n);o(({intersects:r,event:i})=>{var u;r.length&&((u=e.click.get(r[0].object))==null||u(r[0],i))});let c;return s(({intersects:r,event:i})=>{var L,M,P,C;const u=(L=r==null?void 0:r[0])==null?void 0:L.object,{pointerLeave:p,pointerEnter:h,pointerMove:v}=e;c&&c!==u&&((M=p.get(c))==null||M(c,i)),u&&(c!==u&&((P=h.get(u))==null||P(r[0],i)),(C=v.get(u))==null||C(r[0],i)),c=u||null}),{registerObject:a,deregisterObject:t}},G={GEOMETRY_VIA_PROP:"tres__geometryViaProp",MATERIAL_VIA_PROP:"tres__materialViaProp",REGISTER_AT_POINTER_EVENT_HANDLER:"tres__registerAtPointerEventHandler"};function Ye(e){}let $=null,V=null;const{logError:ue}=x(),Re={createElement(e,t,a,n){var i,u;if(n||(n={}),n.args||(n.args=[]),e==="template"||Le(e))return null;let o=e.replace("Tres",""),s;if(e==="primitive"){(n==null?void 0:n.object)===void 0&&ue("Tres primitives need a prop 'object'");const p=n.object;o=p.type,s=Object.assign(p,{type:o,attach:n.attach,primitive:!0})}else{const p=z.value[o];p||ue(`${o} is not defined on the THREE namespace. Use extend to add it to the catalog.`),s=new p(...n.args)}s.isCamera&&(n!=null&&n.position||s.position.set(3,3,3),n!=null&&n.lookAt||s.lookAt(0,0,0)),(n==null?void 0:n.attach)===void 0&&(s.isMaterial?s.attach="material":s.isBufferGeometry&&(s.attach="geometry"));const{GEOMETRY_VIA_PROP:c,MATERIAL_VIA_PROP:r}=G;return s.isObject3D&&((i=n==null?void 0:n.material)!=null&&i.isMaterial&&(s.userData[r]=!0),(u=n==null?void 0:n.geometry)!=null&&u.isBufferGeometry&&(s.userData[c]=!0)),s},insert(e,t){var a,n,o,s,c,r,i;if(t&&t.isScene&&(V=t),(((a=e==null?void 0:e.__vnode)==null?void 0:a.type)==="TresGroup"||((n=e==null?void 0:e.__vnode)==null?void 0:n.type)==="TresObject3D")&&t===null&&!((s=(o=e==null?void 0:e.__vnode)==null?void 0:o.ctx)!=null&&s.asyncResolved)){$=e;return}else(c=e==null?void 0:e.__vnode)!=null&&c.type.includes("Controls")&&t===null&&($=V);t||(t=$),e!=null&&e.isObject3D&&(t!=null&&t.isObject3D)?(t.add(e),e.dispatchEvent({type:"added"}),(i=(r=V==null?void 0:V.userData)==null?void 0:r[G.REGISTER_AT_POINTER_EVENT_HANDLER])==null||i.call(r,e)):e!=null&&e.isFog?t.fog=e:typeof(e==null?void 0:e.attach)=="string"&&(e.__previousAttach=e[t==null?void 0:t.attach],t&&(t[e.attach]=e))},remove(e){var t,a;if(e){if(e.isObject3D){const n=e,o=s=>{var i,u;const{GEOMETRY_VIA_PROP:c,MATERIAL_VIA_PROP:r}=G;s.userData[r]||(i=s.material)==null||i.dispose(),s.userData[c]||(u=s.geometry)==null||u.dispose()};n.traverse(s=>{o(s)}),o(n)}(t=e.removeFromParent)==null||t.call(e),(a=e.dispose)==null||a.call(e)}},patchProp(e,t,a,n){if(e){let o=e,s=t,c=B(s),r=o==null?void 0:o[c];if(o.type==="BufferGeometry"){if(s==="args")return;o.setAttribute(B(s),new g.BufferAttribute(...n));return}if(s.includes("-")&&r===void 0){const u=s.split("-");r=u.reduce((p,h)=>p[B(h)],o),s=u.pop(),c=s.toLowerCase(),r!=null&&r.set||(o=u.reduce((p,h)=>p[B(h)],o))}let i=n;if(i===""&&(i=!0),X(r)){Array.isArray(i)?e[c](...i):e[c](i);return}!(r!=null&&r.set)&&!X(r)?o[c]=i:r.constructor===i.constructor&&(r!=null&&r.copy)?r==null||r.copy(i):Array.isArray(i)?r.set(...i):!r.isColor&&r.setScalar?r.setScalar(i):r.set(i)}},parentNode(e){return(e==null?void 0:e.parent)||null},createText:()=>void 0,createComment:()=>void 0,setText:()=>void 0,setElementText:()=>void 0,nextSibling:()=>void 0,querySelector:()=>void 0,setScopeId:()=>void 0,cloneNode:()=>void 0,insertStaticContent:()=>void 0},{createApp:xe}=l.createRenderer(Re),ke=e=>{const t=xe(a);function a(){return e&&e.default?e.default():[]}return t};F(N);const{logWarning:le}=x(),Ve=l.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:a}){e.physicallyCorrectLights===!0&&le("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const n=l.computed(()=>e.disableRender!==!1&&e.disableRender!==void 0),o=l.ref(),s=l.ref(),c=new N.Scene,r=ce(),{setState:i}=E();c.userData[G.REGISTER_AT_POINTER_EVENT_HANDLER]=r.registerObject,i("scene",c),i("canvas",s),i("container",o),i("pointerEventHandler",r);const{onLoop:u,resume:p}=U();l.onMounted(()=>{P()}),l.onUnmounted(()=>{i("renderer",null)});const{activeCamera:h,pushCamera:v,clearCameras:L}=Z();function M(){const b=c.getObjectByProperty("isCamera",!0);if(b)v(b);else{le("No camera found. Creating a default perspective camera. To have full control over a camera, please add one to the scene.");const _=new N.PerspectiveCamera(45,window.innerWidth/window.innerHeight,.1,1e3);_.position.set(3,3,3),_.lookAt(0,0,0),v(_)}}function P(){const{renderer:b}=oe(e);e.camera&&v(e.camera),u(()=>{var _;h.value&&!n.value&&((_=b.value)==null||_.render(c,h.value))})}let C;function O(){C=ke(t);const b=E();C.provide("useTres",b),C.provide(j,b),C.provide("extend",F),C.mount(c),M()}return O(),a({scene:c}),l.watch(()=>e.camera,b=>{b&&(L(),v(b))}),()=>l.h(l.h("div",{ref:o,"data-scene":c.uuid,key:c.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[l.h("div",{style:{width:"100%",height:"100%"}},[l.h("canvas",{ref:s,"data-scene":c.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),fe=l.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:a}){const n=J();return a(n),()=>l.h(Ve,e,t)}}),je=["TresCanvas","TresLeches","TresScene"],De={template:{compilerOptions:{isCustomElement:e=>e.startsWith("Tres")&&!je.includes(e)||e==="primitive"}}},Ie={install(e){e.component("TresCanvas",fe)}};m.CameraType=Q,m.TRES_CONTEXT_KEY=j,m.TresCanvas=fe,m.catalogue=z,m.default=Ie,m.extend=F,m.isProd=Oe,m.normalizeColor=ae,m.normalizeVectorFlexibleParam=Me,m.templateCompilerOptions=De,m.trasverseObjects=ie,m.useCamera=Z,m.useLoader=Te,m.useLogger=x,m.usePointerEventHandler=ce,m.useRaycaster=se,m.useRenderLoop=U,m.useRenderer=oe,m.useSeek=Ee,m.useTexture=Ae,m.useTres=E,m.useTresProvider=J,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tresjs/core",
|
|
3
3
|
"description": "Declarative ThreeJS using Vue Components",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@8.3.1",
|
|
7
7
|
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue",
|
|
55
55
|
"docs:dev": "vitepress dev docs",
|
|
56
56
|
"docs:build": "vitepress build docs",
|
|
57
|
-
"docs:serve": "vitepress serve docs"
|
|
57
|
+
"docs:serve": "vitepress serve docs",
|
|
58
|
+
"docs:contributors": "esno scripts/update-contributors.ts"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
61
|
"three": ">=0.133",
|
|
@@ -62,9 +63,7 @@
|
|
|
62
63
|
},
|
|
63
64
|
"dependencies": {
|
|
64
65
|
"@alvarosabu/utils": "^3.1.1",
|
|
65
|
-
"@vueuse/core": "^10.
|
|
66
|
-
"vue-zustand": "^0.5.0",
|
|
67
|
-
"zustand": "^4.3.8"
|
|
66
|
+
"@vueuse/core": "^10.2.0"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
|
70
69
|
"@alvarosabu/prettier-config": "^1.3.0",
|
|
@@ -73,18 +72,20 @@
|
|
|
73
72
|
"@stackblitz/sdk": "^1.9.0",
|
|
74
73
|
"@tresjs/cientos": "2.1.4",
|
|
75
74
|
"@types/three": "^0.152.1",
|
|
76
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
77
|
-
"@typescript-eslint/parser": "^5.
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "^5.60.0",
|
|
76
|
+
"@typescript-eslint/parser": "^5.60.0",
|
|
78
77
|
"@vitejs/plugin-vue": "^4.2.3",
|
|
79
|
-
"@vitest/coverage-c8": "^0.32.
|
|
80
|
-
"@vitest/ui": "^0.32.
|
|
81
|
-
"@vue/test-utils": "^2.
|
|
82
|
-
"eslint": "^8.
|
|
78
|
+
"@vitest/coverage-c8": "^0.32.2",
|
|
79
|
+
"@vitest/ui": "^0.32.2",
|
|
80
|
+
"@vue/test-utils": "^2.4.0",
|
|
81
|
+
"eslint": "^8.43.0",
|
|
83
82
|
"eslint-config-prettier": "^8.8.0",
|
|
84
|
-
"eslint-plugin-vue": "^9.
|
|
83
|
+
"eslint-plugin-vue": "^9.15.1",
|
|
84
|
+
"esno": "^0.16.3",
|
|
85
85
|
"gsap": "^3.12.1",
|
|
86
86
|
"jsdom": "^22.1.0",
|
|
87
87
|
"kolorist": "^1.8.0",
|
|
88
|
+
"ohmyfetch": "^0.4.21",
|
|
88
89
|
"pathe": "^1.1.1",
|
|
89
90
|
"prettier": "^2.8.8",
|
|
90
91
|
"release-it": "^15.11.0",
|
|
@@ -92,17 +93,17 @@
|
|
|
92
93
|
"rollup-plugin-copy": "^3.4.0",
|
|
93
94
|
"rollup-plugin-visualizer": "^5.9.2",
|
|
94
95
|
"three": "^0.153.0",
|
|
95
|
-
"unocss": "^0.53.
|
|
96
|
+
"unocss": "^0.53.3",
|
|
96
97
|
"unplugin": "^1.3.1",
|
|
97
98
|
"unplugin-vue-components": "^0.25.1",
|
|
98
99
|
"vite": "^4.3.9",
|
|
99
100
|
"vite-plugin-banner": "^0.7.0",
|
|
100
101
|
"vite-plugin-dts": "2.3.0",
|
|
101
|
-
"vite-plugin-inspect": "^0.7.
|
|
102
|
+
"vite-plugin-inspect": "^0.7.29",
|
|
102
103
|
"vite-plugin-require-transform": "^1.0.17",
|
|
103
104
|
"vite-svg-loader": "^4.0.0",
|
|
104
|
-
"vitepress": "1.0.0-beta.
|
|
105
|
-
"vitest": "^0.32.
|
|
105
|
+
"vitepress": "1.0.0-beta.3",
|
|
106
|
+
"vitest": "^0.32.2",
|
|
106
107
|
"vue": "^3.3.4",
|
|
107
108
|
"vue-demi": "^0.14.5"
|
|
108
109
|
}
|