@tresjs/core 2.2.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 +3 -0
- package/dist/tres.js +275 -259
- 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
|
@@ -3,6 +3,8 @@ export * from './composables';
|
|
|
3
3
|
export * from './core/catalogue';
|
|
4
4
|
export * from './components';
|
|
5
5
|
export * from './types';
|
|
6
|
+
import { normalizeColor, normalizeVectorFlexibleParam } from './utils/normalize';
|
|
7
|
+
import templateCompilerOptions from './utils/template-compiler-options';
|
|
6
8
|
export interface TresOptions {
|
|
7
9
|
extends?: Record<string, unknown>;
|
|
8
10
|
}
|
|
@@ -12,3 +14,4 @@ export interface TresPlugin {
|
|
|
12
14
|
}
|
|
13
15
|
declare const plugin: TresPlugin;
|
|
14
16
|
export default plugin;
|
|
17
|
+
export { normalizeColor, normalizeVectorFlexibleParam, templateCompilerOptions };
|
package/dist/tres.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
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 G, shallowReactive as ce, toRefs as ue, provide 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
|
|
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
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
|
-
function
|
|
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();
|
|
16
16
|
}
|
|
17
17
|
const K = Symbol();
|
|
18
|
-
function
|
|
18
|
+
function Ze() {
|
|
19
19
|
const e = ce({
|
|
20
|
-
uuid:
|
|
20
|
+
uuid: Qe(),
|
|
21
21
|
camera: void 0,
|
|
22
22
|
cameras: [],
|
|
23
23
|
canvas: void 0,
|
|
@@ -29,8 +29,8 @@ function Qe() {
|
|
|
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 Qe() {
|
|
|
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: [],
|
|
@@ -50,22 +50,22 @@ const S = () => Le(K, {
|
|
|
50
50
|
pointerEventHandler: void 0
|
|
51
51
|
})
|
|
52
52
|
});
|
|
53
|
-
var
|
|
54
|
-
const
|
|
53
|
+
var et = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(et || {});
|
|
54
|
+
const tt = 45;
|
|
55
55
|
let x;
|
|
56
|
-
function
|
|
57
|
-
const { state: e, setState: t, aspectRatio: n } =
|
|
58
|
-
function a(
|
|
59
|
-
var l,
|
|
60
|
-
if (
|
|
61
|
-
const { near:
|
|
56
|
+
function at() {
|
|
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
|
-
fov:
|
|
64
|
+
fov: tt
|
|
65
65
|
};
|
|
66
|
-
x = new z(
|
|
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 tt() {
|
|
|
73
73
|
near: 0.1,
|
|
74
74
|
far: 1e3
|
|
75
75
|
};
|
|
76
|
-
x = new
|
|
76
|
+
x = new De(E, y, h, w, C, g), (d = e.cameras) == null || d.push(x);
|
|
77
77
|
}
|
|
78
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,68 +98,71 @@ function tt() {
|
|
|
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:
|
|
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 {
|
|
119
119
|
onBeforeLoop: we.on,
|
|
120
120
|
onLoop: be.on,
|
|
121
121
|
onAfterLoop: J.on,
|
|
122
|
-
pause:
|
|
123
|
-
resume:
|
|
124
|
-
isActive:
|
|
122
|
+
pause: nt,
|
|
123
|
+
resume: rt,
|
|
124
|
+
isActive: ot
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function Rt(e) {
|
|
128
|
+
return typeof e == "number" ? [e, e, e] : e instanceof je ? [e.x, e.y, e.z] : e;
|
|
129
|
+
}
|
|
130
|
+
function it(e) {
|
|
128
131
|
return e instanceof W ? e : Array.isArray(e) ? new W(...e) : new W(e);
|
|
129
132
|
}
|
|
130
|
-
const
|
|
133
|
+
const U = {
|
|
131
134
|
realistic: {
|
|
132
|
-
outputColorSpace:
|
|
133
|
-
toneMapping:
|
|
135
|
+
outputColorSpace: Ie,
|
|
136
|
+
toneMapping: Be,
|
|
134
137
|
toneMappingExposure: 3,
|
|
135
138
|
shadowMap: {
|
|
136
139
|
enabled: !0,
|
|
137
|
-
type:
|
|
140
|
+
type: He
|
|
138
141
|
}
|
|
139
142
|
}
|
|
140
143
|
}, ye = (e, t) => {
|
|
141
144
|
for (const n of Object.keys(t))
|
|
142
145
|
t[n] instanceof Object && Object.assign(t[n], ye(e[n], t[n]));
|
|
143
146
|
return Object.assign(e || {}, t), e;
|
|
144
|
-
},
|
|
147
|
+
}, 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__ */ ut(st);
|
|
145
148
|
function j(e) {
|
|
146
149
|
return e.replace(/-([a-z])/g, (t, n) => n.toUpperCase());
|
|
147
150
|
}
|
|
148
|
-
function
|
|
151
|
+
function ut(e, t) {
|
|
149
152
|
const n = /* @__PURE__ */ Object.create(null), a = e.split(",");
|
|
150
153
|
for (let o = 0; o < a.length; o++)
|
|
151
154
|
n[a[o]] = !0;
|
|
152
155
|
return t ? (o) => !!n[o.toLowerCase()] : (o) => !!n[o];
|
|
153
156
|
}
|
|
154
|
-
const
|
|
157
|
+
const ft = (e, t) => {
|
|
155
158
|
const n = /* @__PURE__ */ new Set(), a = [];
|
|
156
159
|
for (const o of e) {
|
|
157
|
-
const
|
|
158
|
-
n.has(
|
|
160
|
+
const s = t(o);
|
|
161
|
+
n.has(s) || (n.add(s), a.push(o));
|
|
159
162
|
}
|
|
160
163
|
return a;
|
|
161
|
-
},
|
|
162
|
-
function
|
|
164
|
+
}, Tt = !0, oe = "[TresJS ▲ ■ ●] ";
|
|
165
|
+
function D() {
|
|
163
166
|
function e(a, o) {
|
|
164
167
|
console.error(`${oe} ${a}`, o || "");
|
|
165
168
|
}
|
|
@@ -174,32 +177,32 @@ function O() {
|
|
|
174
177
|
logMessage: n
|
|
175
178
|
};
|
|
176
179
|
}
|
|
177
|
-
function
|
|
178
|
-
const t =
|
|
180
|
+
function lt(e) {
|
|
181
|
+
const t = Se(), n = G(!1), {
|
|
179
182
|
alpha: a = !0,
|
|
180
183
|
antialias: o = !0,
|
|
181
|
-
depth:
|
|
182
|
-
logarithmicDepthBuffer:
|
|
184
|
+
depth: s,
|
|
185
|
+
logarithmicDepthBuffer: c,
|
|
183
186
|
failIfMajorPerformanceCaveat: r,
|
|
184
|
-
precision:
|
|
185
|
-
premultipliedAlpha:
|
|
187
|
+
precision: i,
|
|
188
|
+
premultipliedAlpha: u,
|
|
186
189
|
stencil: l,
|
|
187
|
-
shadows:
|
|
188
|
-
shadowMapType:
|
|
189
|
-
useLegacyLights:
|
|
190
|
-
outputColorSpace:
|
|
191
|
-
toneMapping:
|
|
192
|
-
toneMappingExposure:
|
|
193
|
-
context:
|
|
194
|
-
powerPreference:
|
|
195
|
-
preserveDrawingBuffer:
|
|
196
|
-
clearColor:
|
|
197
|
-
windowSize:
|
|
198
|
-
preset:
|
|
199
|
-
} = ue(e), { state: f, setState:
|
|
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
|
+
preset: F = void 0
|
|
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);
|
|
200
203
|
setTimeout(() => {
|
|
201
204
|
var P;
|
|
202
|
-
!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.
|
|
203
206
|
You could set windowSize=true to force the canvas to be the size of the window.`);
|
|
204
207
|
}, 1e3);
|
|
205
208
|
const ee = () => {
|
|
@@ -207,156 +210,156 @@ function ft(e) {
|
|
|
207
210
|
}, te = () => {
|
|
208
211
|
if (!t.value)
|
|
209
212
|
return;
|
|
210
|
-
const P = m(
|
|
213
|
+
const P = m(F);
|
|
211
214
|
if (P) {
|
|
212
|
-
P in
|
|
215
|
+
P in U || Ee("Renderer Preset must be one of these: " + Object.keys(U).join(", ")), ye(t.value, U[P]);
|
|
213
216
|
return;
|
|
214
217
|
}
|
|
215
|
-
t.value.shadowMap.enabled = m(
|
|
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);
|
|
216
219
|
}, Re = () => {
|
|
217
|
-
const P =
|
|
220
|
+
const P = $(f.canvas);
|
|
218
221
|
P && (t.value = new Ge({
|
|
219
222
|
canvas: P,
|
|
220
223
|
alpha: m(a),
|
|
221
224
|
antialias: m(o),
|
|
222
|
-
context: m(
|
|
223
|
-
depth: m(
|
|
225
|
+
context: m(C),
|
|
226
|
+
depth: m(s),
|
|
224
227
|
failIfMajorPerformanceCaveat: m(r),
|
|
225
|
-
logarithmicDepthBuffer: m(
|
|
226
|
-
powerPreference: m(
|
|
227
|
-
precision: m(
|
|
228
|
+
logarithmicDepthBuffer: m(c),
|
|
229
|
+
powerPreference: m(g),
|
|
230
|
+
precision: m(i),
|
|
228
231
|
stencil: m(l),
|
|
229
|
-
preserveDrawingBuffer: m(
|
|
230
|
-
premultipliedAlpha: m(
|
|
231
|
-
}),
|
|
232
|
-
},
|
|
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 = () => {
|
|
233
236
|
t.value && (t.value.dispose(), t.value = void 0, n.value = !1, Pe());
|
|
234
237
|
};
|
|
235
|
-
return
|
|
236
|
-
[
|
|
238
|
+
return I([N, Z], ee), I(
|
|
239
|
+
[p, d, y, E, h, w, R],
|
|
237
240
|
te
|
|
238
|
-
),
|
|
241
|
+
), I(
|
|
239
242
|
() => [f.canvas, f.container],
|
|
240
243
|
() => {
|
|
241
|
-
|
|
244
|
+
$(f.canvas) && $(f.container) && Re();
|
|
242
245
|
},
|
|
243
246
|
{ immediate: !0, deep: !0 }
|
|
244
247
|
), {
|
|
245
248
|
renderer: t,
|
|
246
249
|
isReady: n,
|
|
247
|
-
dispose:
|
|
248
|
-
aspectRatio:
|
|
250
|
+
dispose: Te,
|
|
251
|
+
aspectRatio: N
|
|
249
252
|
};
|
|
250
253
|
}
|
|
251
|
-
function
|
|
254
|
+
function dt(e) {
|
|
252
255
|
const t = { nodes: {}, materials: {} };
|
|
253
256
|
return e && e.traverse((n) => {
|
|
254
257
|
n.name && (t.nodes[n.name] = n), n.material && !t.materials[n.material.name] && (t.materials[n.material.name] = n.material);
|
|
255
258
|
}), t;
|
|
256
259
|
}
|
|
257
|
-
async function
|
|
258
|
-
const { logError:
|
|
259
|
-
o && o(
|
|
260
|
-
const
|
|
261
|
-
(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
(
|
|
265
|
-
|
|
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);
|
|
266
269
|
},
|
|
267
270
|
a,
|
|
268
|
-
(
|
|
271
|
+
(d) => p(s("[useLoader] - Failed to load resource", d))
|
|
269
272
|
);
|
|
270
273
|
})
|
|
271
274
|
);
|
|
272
|
-
return ge(t) ? await Promise.all(
|
|
275
|
+
return ge(t) ? await Promise.all(i) : await i[0];
|
|
273
276
|
}
|
|
274
|
-
async function
|
|
275
|
-
const t = new
|
|
277
|
+
async function Lt(e) {
|
|
278
|
+
const t = new Fe(), n = new Ne(t), a = (o) => new Promise((s, c) => {
|
|
276
279
|
n.load(
|
|
277
280
|
o,
|
|
278
|
-
(r) =>
|
|
281
|
+
(r) => s(r),
|
|
279
282
|
() => null,
|
|
280
283
|
() => {
|
|
281
|
-
|
|
284
|
+
c(new Error("[useTextures] - Failed to load texture"));
|
|
282
285
|
}
|
|
283
286
|
);
|
|
284
287
|
});
|
|
285
288
|
if (ge(e)) {
|
|
286
|
-
const o = await Promise.all(e.map((
|
|
289
|
+
const o = await Promise.all(e.map((s) => a(s)));
|
|
287
290
|
return e.length > 1 ? o : o[0];
|
|
288
291
|
} else {
|
|
289
292
|
const {
|
|
290
293
|
map: o,
|
|
291
|
-
displacementMap:
|
|
292
|
-
normalMap:
|
|
294
|
+
displacementMap: s,
|
|
295
|
+
normalMap: c,
|
|
293
296
|
roughnessMap: r,
|
|
294
|
-
metalnessMap:
|
|
295
|
-
aoMap:
|
|
297
|
+
metalnessMap: i,
|
|
298
|
+
aoMap: u,
|
|
296
299
|
alphaMap: l,
|
|
297
|
-
matcap:
|
|
300
|
+
matcap: p
|
|
298
301
|
} = e;
|
|
299
302
|
return {
|
|
300
303
|
map: o ? await a(o) : null,
|
|
301
|
-
displacementMap:
|
|
302
|
-
normalMap:
|
|
304
|
+
displacementMap: s ? await a(s) : null,
|
|
305
|
+
normalMap: c ? await a(c) : null,
|
|
303
306
|
roughnessMap: r ? await a(r) : null,
|
|
304
|
-
metalnessMap:
|
|
305
|
-
aoMap:
|
|
307
|
+
metalnessMap: i ? await a(i) : null,
|
|
308
|
+
aoMap: u ? await a(u) : null,
|
|
306
309
|
alphaMap: l ? await a(l) : null,
|
|
307
|
-
matcap:
|
|
310
|
+
matcap: p ? await a(p) : null
|
|
308
311
|
};
|
|
309
312
|
}
|
|
310
313
|
}
|
|
311
|
-
const
|
|
312
|
-
const { state: t } =
|
|
314
|
+
const pt = (e) => {
|
|
315
|
+
const { state: t } = k(), n = A(() => {
|
|
313
316
|
var f;
|
|
314
317
|
return (f = t.canvas) == null ? void 0 : f.value;
|
|
315
|
-
}), { x: a, y: o } =
|
|
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 }) => {
|
|
316
319
|
if (n.value)
|
|
317
320
|
return {
|
|
318
|
-
x: (f -
|
|
319
|
-
y: -((
|
|
321
|
+
x: (f - i.value) / s.value * 2 - 1,
|
|
322
|
+
y: -((v - r.value) / c.value) * 2 + 1
|
|
320
323
|
};
|
|
321
|
-
},
|
|
324
|
+
}, p = ({ x: f, y: v }) => {
|
|
322
325
|
if (t.camera)
|
|
323
|
-
return
|
|
324
|
-
},
|
|
325
|
-
const
|
|
326
|
+
return u.setFromCamera(new We(f, v), t.camera), u.intersectObjects(e.value, !1);
|
|
327
|
+
}, d = (f) => {
|
|
328
|
+
const v = l({
|
|
326
329
|
x: (f == null ? void 0 : f.clientX) ?? a.value,
|
|
327
330
|
y: (f == null ? void 0 : f.clientY) ?? o.value
|
|
328
331
|
});
|
|
329
|
-
return
|
|
330
|
-
},
|
|
331
|
-
f.trigger({ event:
|
|
332
|
-
}, w = (f) => {
|
|
333
|
-
M(v, f);
|
|
334
|
-
};
|
|
335
|
-
let E;
|
|
336
|
-
const k = (f) => {
|
|
337
|
-
var g;
|
|
338
|
-
E = (g = p(f)[0]) == null ? void 0 : g.object;
|
|
332
|
+
return v ? p(v) || [] : [];
|
|
333
|
+
}, E = A(() => d()), y = O(), h = O(), w = (f, v) => {
|
|
334
|
+
f.trigger({ event: v, intersects: d(v) });
|
|
339
335
|
}, C = (f) => {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
336
|
+
w(h, f);
|
|
337
|
+
};
|
|
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());
|
|
344
347
|
});
|
|
345
348
|
return le(() => {
|
|
346
|
-
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));
|
|
347
350
|
}), {
|
|
348
|
-
intersects:
|
|
349
|
-
onClick: (f) =>
|
|
350
|
-
onPointerMove: (f) =>
|
|
351
|
+
intersects: E,
|
|
352
|
+
onClick: (f) => y.on(f).off,
|
|
353
|
+
onPointerMove: (f) => h.on(f).off
|
|
351
354
|
};
|
|
352
355
|
};
|
|
353
|
-
function
|
|
354
|
-
const { logWarning: e } =
|
|
355
|
-
function t(a, o,
|
|
356
|
-
let
|
|
356
|
+
function _t() {
|
|
357
|
+
const { logWarning: e } = D();
|
|
358
|
+
function t(a, o, s) {
|
|
359
|
+
let c = null;
|
|
357
360
|
return a.traverse((r) => {
|
|
358
|
-
r[o] ===
|
|
359
|
-
}),
|
|
361
|
+
r[o] === s && (c = r);
|
|
362
|
+
}), c || e(`Child with ${o} '${s}' not found.`), c;
|
|
360
363
|
}
|
|
361
364
|
function n(a, o) {
|
|
362
365
|
return t(a, "name", o);
|
|
@@ -366,84 +369,84 @@ function Rt() {
|
|
|
366
369
|
seekByName: n
|
|
367
370
|
};
|
|
368
371
|
}
|
|
369
|
-
const
|
|
370
|
-
const e =
|
|
372
|
+
const mt = () => {
|
|
373
|
+
const e = Ae({
|
|
371
374
|
click: /* @__PURE__ */ new Map(),
|
|
372
375
|
pointerMove: /* @__PURE__ */ new Map(),
|
|
373
376
|
pointerEnter: /* @__PURE__ */ new Map(),
|
|
374
377
|
pointerLeave: /* @__PURE__ */ new Map()
|
|
375
378
|
}), t = (r) => {
|
|
376
|
-
Object.values(e).forEach((
|
|
379
|
+
Object.values(e).forEach((i) => i.delete(r));
|
|
377
380
|
}, n = (r) => {
|
|
378
|
-
const { onClick:
|
|
379
|
-
|
|
380
|
-
r.traverse((
|
|
381
|
-
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);
|
|
382
385
|
}), t(r);
|
|
383
386
|
});
|
|
384
|
-
}, a =
|
|
385
|
-
() =>
|
|
387
|
+
}, a = A(
|
|
388
|
+
() => ft(
|
|
386
389
|
Object.values(e).map((r) => Array.from(r.keys())).flat(),
|
|
387
390
|
({ uuid: r }) => r
|
|
388
391
|
)
|
|
389
|
-
), { onClick: o, onPointerMove:
|
|
390
|
-
o(({ intersects: r, event:
|
|
391
|
-
var
|
|
392
|
-
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));
|
|
393
396
|
});
|
|
394
|
-
let
|
|
395
|
-
return
|
|
396
|
-
var y, h,
|
|
397
|
-
const
|
|
398
|
-
|
|
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;
|
|
399
402
|
}), {
|
|
400
403
|
registerObject: n,
|
|
401
404
|
deregisterObject: t
|
|
402
405
|
};
|
|
403
|
-
},
|
|
406
|
+
}, V = {
|
|
404
407
|
GEOMETRY_VIA_PROP: "tres__geometryViaProp",
|
|
405
408
|
MATERIAL_VIA_PROP: "tres__materialViaProp",
|
|
406
409
|
REGISTER_AT_POINTER_EVENT_HANDLER: "tres__registerAtPointerEventHandler"
|
|
407
410
|
};
|
|
408
|
-
let
|
|
409
|
-
const { logError: ie } =
|
|
411
|
+
let Y = null, L = null;
|
|
412
|
+
const { logError: ie } = D(), vt = {
|
|
410
413
|
createElement(e, t, n, a) {
|
|
411
|
-
var
|
|
412
|
-
if (a || (a = {}), a.args || (a.args = []), e === "template" ||
|
|
414
|
+
var i, u;
|
|
415
|
+
if (a || (a = {}), a.args || (a.args = []), e === "template" || ct(e))
|
|
413
416
|
return null;
|
|
414
|
-
let o = e.replace("Tres", ""),
|
|
417
|
+
let o = e.replace("Tres", ""), s;
|
|
415
418
|
if (e === "primitive") {
|
|
416
419
|
(a == null ? void 0 : a.object) === void 0 && ie("Tres primitives need a prop 'object'");
|
|
417
420
|
const l = a.object;
|
|
418
|
-
o = l.type,
|
|
421
|
+
o = l.type, s = Object.assign(l, { type: o, attach: a.attach, primitive: !0 });
|
|
419
422
|
} else {
|
|
420
423
|
const l = me.value[o];
|
|
421
|
-
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);
|
|
422
425
|
}
|
|
423
|
-
|
|
424
|
-
const { GEOMETRY_VIA_PROP:
|
|
425
|
-
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;
|
|
426
429
|
},
|
|
427
430
|
insert(e, t) {
|
|
428
|
-
var n, a, o,
|
|
429
|
-
if (t && t.isScene && (
|
|
430
|
-
|
|
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;
|
|
431
434
|
return;
|
|
432
435
|
} else
|
|
433
|
-
(
|
|
434
|
-
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));
|
|
435
438
|
},
|
|
436
439
|
remove(e) {
|
|
437
440
|
var t, n;
|
|
438
441
|
if (e) {
|
|
439
442
|
if (e.isObject3D) {
|
|
440
|
-
const a = e, o = (
|
|
441
|
-
var
|
|
442
|
-
const { GEOMETRY_VIA_PROP:
|
|
443
|
-
|
|
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();
|
|
444
447
|
};
|
|
445
|
-
a.traverse((
|
|
446
|
-
o(
|
|
448
|
+
a.traverse((s) => {
|
|
449
|
+
o(s);
|
|
447
450
|
}), o(a);
|
|
448
451
|
}
|
|
449
452
|
(t = e.removeFromParent) == null || t.call(e), (n = e.dispose) == null || n.call(e);
|
|
@@ -451,26 +454,26 @@ const { logError: ie } = O(), mt = {
|
|
|
451
454
|
},
|
|
452
455
|
patchProp(e, t, n, a) {
|
|
453
456
|
if (e) {
|
|
454
|
-
let o = e,
|
|
457
|
+
let o = e, s = t, c = j(s), r = o == null ? void 0 : o[c];
|
|
455
458
|
if (o.type === "BufferGeometry") {
|
|
456
|
-
if (
|
|
459
|
+
if (s === "args")
|
|
457
460
|
return;
|
|
458
461
|
o.setAttribute(
|
|
459
|
-
j(
|
|
460
|
-
new
|
|
462
|
+
j(s),
|
|
463
|
+
new $e(...a)
|
|
461
464
|
);
|
|
462
465
|
return;
|
|
463
466
|
}
|
|
464
|
-
if (
|
|
465
|
-
const
|
|
466
|
-
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));
|
|
467
470
|
}
|
|
468
|
-
let
|
|
469
|
-
if (
|
|
470
|
-
Array.isArray(
|
|
471
|
+
let i = a;
|
|
472
|
+
if (i === "" && (i = !0), re(r)) {
|
|
473
|
+
Array.isArray(i) ? e[c](...i) : e[c](i);
|
|
471
474
|
return;
|
|
472
475
|
}
|
|
473
|
-
!(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);
|
|
474
477
|
}
|
|
475
478
|
},
|
|
476
479
|
parentNode(e) {
|
|
@@ -485,15 +488,15 @@ const { logError: ie } = O(), mt = {
|
|
|
485
488
|
setScopeId: () => void 0,
|
|
486
489
|
cloneNode: () => void 0,
|
|
487
490
|
insertStaticContent: () => void 0
|
|
488
|
-
}, { createApp:
|
|
489
|
-
const t =
|
|
491
|
+
}, { createApp: gt } = Oe(vt), wt = (e) => {
|
|
492
|
+
const t = gt(n);
|
|
490
493
|
function n() {
|
|
491
494
|
return e && e.default ? e.default() : [];
|
|
492
495
|
}
|
|
493
496
|
return t;
|
|
494
497
|
};
|
|
495
498
|
ve(q);
|
|
496
|
-
const { logWarning: se } =
|
|
499
|
+
const { logWarning: se } = D(), bt = de({
|
|
497
500
|
name: "TresScene",
|
|
498
501
|
props: [
|
|
499
502
|
"shadows",
|
|
@@ -514,52 +517,52 @@ const { logWarning: se } = O(), wt = de({
|
|
|
514
517
|
],
|
|
515
518
|
setup(e, { slots: t, expose: n }) {
|
|
516
519
|
e.physicallyCorrectLights === !0 && se("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
|
|
517
|
-
const a =
|
|
518
|
-
|
|
519
|
-
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();
|
|
520
523
|
ke(() => {
|
|
521
524
|
h();
|
|
522
525
|
}), le(() => {
|
|
523
|
-
|
|
526
|
+
i("renderer", null);
|
|
524
527
|
});
|
|
525
|
-
const { activeCamera:
|
|
528
|
+
const { activeCamera: p, pushCamera: d, clearCameras: E } = at();
|
|
526
529
|
function y() {
|
|
527
|
-
const
|
|
528
|
-
if (
|
|
529
|
-
d(
|
|
530
|
+
const g = c.getObjectByProperty("isCamera", !0);
|
|
531
|
+
if (g)
|
|
532
|
+
d(g);
|
|
530
533
|
else {
|
|
531
534
|
se("No camera found. Creating a default perspective camera. To have full control over a camera, please add one to the scene.");
|
|
532
|
-
const
|
|
533
|
-
|
|
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);
|
|
534
537
|
}
|
|
535
538
|
}
|
|
536
539
|
function h() {
|
|
537
|
-
const { renderer:
|
|
538
|
-
e.camera && d(e.camera),
|
|
539
|
-
var
|
|
540
|
-
|
|
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));
|
|
541
544
|
});
|
|
542
545
|
}
|
|
543
|
-
let
|
|
544
|
-
function
|
|
545
|
-
|
|
546
|
-
const
|
|
547
|
-
|
|
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();
|
|
548
551
|
}
|
|
549
|
-
return
|
|
550
|
-
scene:
|
|
551
|
-
}),
|
|
552
|
+
return C(), n({
|
|
553
|
+
scene: c
|
|
554
|
+
}), I(
|
|
552
555
|
() => e.camera,
|
|
553
|
-
(
|
|
554
|
-
|
|
556
|
+
(g) => {
|
|
557
|
+
g && (E(), d(g));
|
|
555
558
|
}
|
|
556
|
-
), () =>
|
|
557
|
-
|
|
559
|
+
), () => _(
|
|
560
|
+
_(
|
|
558
561
|
"div",
|
|
559
562
|
{
|
|
560
|
-
ref:
|
|
561
|
-
"data-scene":
|
|
562
|
-
key:
|
|
563
|
+
ref: o,
|
|
564
|
+
"data-scene": c.uuid,
|
|
565
|
+
key: c.uuid,
|
|
563
566
|
style: {
|
|
564
567
|
position: "relative",
|
|
565
568
|
width: "100%",
|
|
@@ -569,7 +572,7 @@ const { logWarning: se } = O(), wt = de({
|
|
|
569
572
|
}
|
|
570
573
|
},
|
|
571
574
|
[
|
|
572
|
-
|
|
575
|
+
_(
|
|
573
576
|
"div",
|
|
574
577
|
{
|
|
575
578
|
style: {
|
|
@@ -578,9 +581,9 @@ const { logWarning: se } = O(), wt = de({
|
|
|
578
581
|
}
|
|
579
582
|
},
|
|
580
583
|
[
|
|
581
|
-
|
|
582
|
-
ref:
|
|
583
|
-
"data-scene":
|
|
584
|
+
_("canvas", {
|
|
585
|
+
ref: s,
|
|
586
|
+
"data-scene": c.uuid,
|
|
584
587
|
style: {
|
|
585
588
|
display: "block",
|
|
586
589
|
width: "100%",
|
|
@@ -596,7 +599,7 @@ const { logWarning: se } = O(), wt = de({
|
|
|
596
599
|
)
|
|
597
600
|
);
|
|
598
601
|
}
|
|
599
|
-
}),
|
|
602
|
+
}), ht = de({
|
|
600
603
|
name: "TresCanvas",
|
|
601
604
|
props: [
|
|
602
605
|
"shadows",
|
|
@@ -616,32 +619,45 @@ const { logWarning: se } = O(), wt = de({
|
|
|
616
619
|
"camera"
|
|
617
620
|
],
|
|
618
621
|
setup(e, { slots: t, expose: n }) {
|
|
619
|
-
const a =
|
|
620
|
-
return n(a), () =>
|
|
622
|
+
const a = Ze();
|
|
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
|
+
}
|
|
621
634
|
}
|
|
622
|
-
}
|
|
635
|
+
}, St = Et, At = {
|
|
623
636
|
install(e) {
|
|
624
|
-
e.component("TresCanvas",
|
|
637
|
+
e.component("TresCanvas", ht);
|
|
625
638
|
}
|
|
626
639
|
};
|
|
627
640
|
export {
|
|
628
|
-
|
|
641
|
+
et as CameraType,
|
|
629
642
|
K as TRES_CONTEXT_KEY,
|
|
630
|
-
|
|
643
|
+
ht as TresCanvas,
|
|
631
644
|
me as catalogue,
|
|
632
|
-
|
|
645
|
+
At as default,
|
|
633
646
|
ve as extend,
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
647
|
+
Tt as isProd,
|
|
648
|
+
it as normalizeColor,
|
|
649
|
+
Rt as normalizeVectorFlexibleParam,
|
|
650
|
+
St as templateCompilerOptions,
|
|
651
|
+
dt as trasverseObjects,
|
|
652
|
+
at as useCamera,
|
|
653
|
+
xt as useLoader,
|
|
654
|
+
D as useLogger,
|
|
655
|
+
mt as usePointerEventHandler,
|
|
656
|
+
pt as useRaycaster,
|
|
641
657
|
he as useRenderLoop,
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
658
|
+
lt as useRenderer,
|
|
659
|
+
_t as useSeek,
|
|
660
|
+
Lt as useTexture,
|
|
661
|
+
k as useTres,
|
|
662
|
+
Ze as useTresProvider
|
|
647
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 me=()=>{t.value&&(t.value.setSize(le.value,de.value),t.value.setPixelRatio(Math.min(pe.value,2)))},ve=()=>{if(!t.value)return;const S=l.toValue($);if(S){S in Y||je("Renderer Preset must be one of these: "+Object.keys(Y).join(", ")),ae(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(Ce(l.toValue(O))),t.value.useLegacyLights=l.toValue(M)},Ge=()=>{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),ve(),me(),Be(),n.value=!0)},Ne=()=>{t.value&&(t.value.dispose(),t.value=void 0,n.value=!1,Ie())};return f.watch([K,pe],me),f.watch([v,h,C,M,w,L,O],ve),f.watch(()=>[d.canvas,d.container],()=>{l.unrefElement(d.canvas)&&l.unrefElement(d.container)&&Ge()},{immediate:!0,deep:!0}),{renderer:t,isReady:n,dispose:Ne,aspectRatio:K}}function oe(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 Oe(e,t,n,a,o){const{logError:i}=R(),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,oe(h.scene)),p(h)},a,h=>v(i("[useLoader] - Failed to load resource",h)))}));return X(t)?await Promise.all(s):await s[0]}async function Te(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(X(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 ie=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 Ae(){const{logWarning:e}=R();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 se=()=>{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(()=>Le(Object.values(e).map(r=>Array.from(r.keys())).flat(),({uuid:r})=>r)),{onClick:o,onPointerMove:i}=ie(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 ze(e){}let q=null,k=null;const{logError:ce}=R(),Ee={createElement(e,t,n,a){var s,c;if(a||(a={}),a.args||(a.args=[]),e==="template"||Me(e))return null;let o=e.replace("Tres",""),i;if(e==="primitive"){(a==null?void 0:a.object)===void 0&&ce("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=F.value[o];p||ce(`${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),H(r)){Array.isArray(s)?e[u](...s):e[u](s);return}!(r!=null&&r.set)&&!H(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),xe=e=>{const t=Re(n);function n(){return e&&e.default?e.default():[]}return t};z(N);const{logWarning:ue}=R(),ke=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&&ue("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const a=f.ref(),o=f.ref(),i=new N.Scene,u=se(),{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{ue("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}=re(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=xe(t);const y=A();w.provide("useTres",y),w.provide(V,y),w.provide("extend",z),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}})])]))}}),fe=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(ke,e,t)}}),Ve={install(e){e.component("TresCanvas",fe)}};m.CameraType=Q,m.TRES_CONTEXT_KEY=V,m.TresCanvas=fe,m.catalogue=F,m.default=Ve,m.extend=z,m.isProd=Se,m.trasverseObjects=oe,m.useCamera=Z,m.useLoader=Oe,m.useLogger=R,m.usePointerEventHandler=se,m.useRaycaster=ie,m.useRenderLoop=U,m.useRenderer=re,m.useSeek=Ae,m.useTexture=Te,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
|
}
|