@tresjs/core 2.0.0-alpha.4 → 2.0.0-alpha.5
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/composables/index.d.ts +1 -0
- package/dist/composables/useSeek/index.d.ts +17 -0
- package/dist/tres.js +152 -135
- package/dist/tres.umd.cjs +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seek composable return type
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @interface UseSeekReturn
|
|
6
|
+
*/
|
|
7
|
+
export interface UseSeekReturn {
|
|
8
|
+
seek: (parent: THREE.Scene | THREE.Object3D, property: string, value: string) => THREE.Object3D | null;
|
|
9
|
+
seekByName: (parent: THREE.Scene | THREE.Object3D, value: string) => THREE.Object3D | null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Composable that provides utilities to easily traverse and navigate through complex scenes and object children graphs
|
|
13
|
+
*
|
|
14
|
+
* @export
|
|
15
|
+
* @return {*} {UseSeekReturn}
|
|
16
|
+
*/
|
|
17
|
+
export declare function useSeek(): UseSeekReturn;
|
package/dist/tres.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v2.0.0-alpha.
|
|
3
|
+
* version: v2.0.0-alpha.5
|
|
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 M, watchEffect as Ee, toRef as xe, shallowRef as ne, toRefs as ae, computed as re, watch as O, shallowReactive as Pe, createRenderer as
|
|
8
|
+
import { ref as M, watchEffect as Ee, toRef as xe, shallowRef as ne, toRefs as ae, computed as re, watch as O, shallowReactive as Pe, createRenderer as Se, defineComponent as Te, onUnmounted as Re, h as S } from "vue";
|
|
9
9
|
import * as oe from "three";
|
|
10
|
-
import { MathUtils as Ae, PerspectiveCamera as F, OrthographicCamera as
|
|
11
|
-
import { createEventHook as
|
|
12
|
-
const
|
|
10
|
+
import { MathUtils as Ae, PerspectiveCamera as F, OrthographicCamera as ke, Clock as ie, Color as I, sRGBEncoding as Oe, ACESFilmicToneMapping as je, PCFSoftShadowMap as Be, PCFShadowMap as _e, LinearEncoding as Y, NoToneMapping as Q, WebGLRenderer as De, LoadingManager as Fe, TextureLoader as Ie, Raycaster as We, Vector2 as ze, Mesh as He, BufferAttribute as $e } from "three";
|
|
11
|
+
import { createEventHook as G, useRafFn as Ge, resolveUnref as c, useWindowSize as Ne, useElementSize as Ue, useDevicePixelRatio as Ve, unrefElement as W, useEventListener as qe, isFunction as Z } from "@vueuse/core";
|
|
12
|
+
const $ = M({ uuid: Ae.generateUUID() }), se = (e) => void Object.assign($.value, e);
|
|
13
13
|
var Je = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Je || {});
|
|
14
14
|
const Ke = 45;
|
|
15
15
|
let y;
|
|
16
|
-
function
|
|
17
|
-
const { state: e, setState: t, aspectRatio:
|
|
18
|
-
function
|
|
16
|
+
function ue() {
|
|
17
|
+
const { state: e, setState: t, aspectRatio: o } = L();
|
|
18
|
+
function r(a = "Perspective", s) {
|
|
19
19
|
var l, p, d;
|
|
20
20
|
if (a === "Perspective") {
|
|
21
21
|
const { near: m, far: w, fov: v } = s || {
|
|
@@ -25,7 +25,7 @@ function ce() {
|
|
|
25
25
|
};
|
|
26
26
|
y = new F(v, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, m, w), (p = e.cameras) == null || p.push(y);
|
|
27
27
|
} else {
|
|
28
|
-
const { left: m, right: w, top: v, bottom: g, near:
|
|
28
|
+
const { left: m, right: w, top: v, bottom: g, near: x, far: P } = s || {
|
|
29
29
|
left: -100,
|
|
30
30
|
right: 100,
|
|
31
31
|
top: 100,
|
|
@@ -33,7 +33,7 @@ function ce() {
|
|
|
33
33
|
near: 0.1,
|
|
34
34
|
far: 1e3
|
|
35
35
|
};
|
|
36
|
-
y = new
|
|
36
|
+
y = new ke(m, w, v, g, x, P), (d = e.cameras) == null || d.push(y);
|
|
37
37
|
}
|
|
38
38
|
return e.camera = y, t("camera", e.camera), y;
|
|
39
39
|
}
|
|
@@ -45,33 +45,33 @@ function ce() {
|
|
|
45
45
|
var s;
|
|
46
46
|
(s = e.cameras) == null || s.push(a), a instanceof F && e.aspectRatio && (a.aspect = e.aspectRatio.value), a.updateProjectionMatrix(), t("camera", a);
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function u() {
|
|
49
49
|
e.cameras = [];
|
|
50
50
|
}
|
|
51
51
|
return Ee(() => {
|
|
52
|
-
|
|
52
|
+
o != null && o.value && n();
|
|
53
53
|
}), {
|
|
54
54
|
activeCamera: xe(e, "camera"),
|
|
55
|
-
createCamera:
|
|
55
|
+
createCamera: r,
|
|
56
56
|
updateCamera: n,
|
|
57
57
|
pushCamera: i,
|
|
58
|
-
clearCameras:
|
|
58
|
+
clearCameras: u
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
const
|
|
62
|
-
let
|
|
63
|
-
const { pause: Xe, resume: Ye, isActive: Qe } =
|
|
61
|
+
const ce = G(), le = G(), N = G(), b = new ie();
|
|
62
|
+
let j = 0, B = 0;
|
|
63
|
+
const { pause: Xe, resume: Ye, isActive: Qe } = Ge(
|
|
64
64
|
() => {
|
|
65
|
-
|
|
65
|
+
ce.trigger({ delta: j, elapsed: B, clock: b }), le.trigger({ delta: j, elapsed: B, clock: b }), N.trigger({ delta: j, elapsed: B, clock: b });
|
|
66
66
|
},
|
|
67
67
|
{ immediate: !1 }
|
|
68
68
|
);
|
|
69
69
|
N.on(() => {
|
|
70
|
-
|
|
70
|
+
j = b.getDelta(), B = b.getElapsedTime();
|
|
71
71
|
});
|
|
72
|
-
function
|
|
72
|
+
function U() {
|
|
73
73
|
return {
|
|
74
|
-
onBeforeLoop:
|
|
74
|
+
onBeforeLoop: ce.on,
|
|
75
75
|
onLoop: le.on,
|
|
76
76
|
onAfterLoop: N.on,
|
|
77
77
|
pause: Xe,
|
|
@@ -84,89 +84,89 @@ function Ze(e) {
|
|
|
84
84
|
}
|
|
85
85
|
const z = {
|
|
86
86
|
realistic: {
|
|
87
|
-
outputEncoding:
|
|
87
|
+
outputEncoding: Oe,
|
|
88
88
|
toneMapping: je,
|
|
89
89
|
toneMappingExposure: 3,
|
|
90
90
|
shadowMap: {
|
|
91
91
|
enabled: !0,
|
|
92
|
-
type:
|
|
92
|
+
type: Be
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}, fe = (e, t) => {
|
|
96
|
-
for (const
|
|
97
|
-
t[
|
|
96
|
+
for (const o of Object.keys(t))
|
|
97
|
+
t[o] instanceof Object && Object.assign(t[o], fe(e[o], t[o]));
|
|
98
98
|
return Object.assign(e || {}, t), e;
|
|
99
99
|
}, et = "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", tt = /* @__PURE__ */ nt(et);
|
|
100
100
|
function T(e) {
|
|
101
|
-
return e.replace(/-([a-z])/g, (t,
|
|
101
|
+
return e.replace(/-([a-z])/g, (t, o) => o.toUpperCase());
|
|
102
102
|
}
|
|
103
103
|
function nt(e, t) {
|
|
104
|
-
const
|
|
105
|
-
for (let n = 0; n <
|
|
106
|
-
r[
|
|
107
|
-
return t ? (n) => !!
|
|
104
|
+
const o = /* @__PURE__ */ Object.create(null), r = e.split(",");
|
|
105
|
+
for (let n = 0; n < r.length; n++)
|
|
106
|
+
o[r[n]] = !0;
|
|
107
|
+
return t ? (n) => !!o[n.toLowerCase()] : (n) => !!o[n];
|
|
108
108
|
}
|
|
109
109
|
const f = ne(), H = M(!1);
|
|
110
|
-
function at(e, t,
|
|
110
|
+
function at(e, t, o) {
|
|
111
111
|
const {
|
|
112
|
-
alpha:
|
|
112
|
+
alpha: r = !0,
|
|
113
113
|
antialias: n = !0,
|
|
114
114
|
depth: i,
|
|
115
|
-
logarithmicDepthBuffer:
|
|
115
|
+
logarithmicDepthBuffer: u,
|
|
116
116
|
failIfMajorPerformanceCaveat: a,
|
|
117
117
|
precision: s,
|
|
118
118
|
premultipliedAlpha: l,
|
|
119
119
|
stencil: p,
|
|
120
120
|
shadows: d = !1,
|
|
121
|
-
shadowMapType: m =
|
|
121
|
+
shadowMapType: m = _e,
|
|
122
122
|
physicallyCorrectLights: w = !1,
|
|
123
123
|
useLegacyLights: v = !1,
|
|
124
124
|
outputEncoding: g = Y,
|
|
125
|
-
toneMapping:
|
|
126
|
-
toneMappingExposure:
|
|
125
|
+
toneMapping: x = Q,
|
|
126
|
+
toneMappingExposure: P = 1,
|
|
127
127
|
context: me = void 0,
|
|
128
128
|
powerPreference: ve = "default",
|
|
129
129
|
preserveDrawingBuffer: ge = !1,
|
|
130
|
-
clearColor:
|
|
130
|
+
clearColor: C,
|
|
131
131
|
windowSize: we = !1,
|
|
132
132
|
preset: he = void 0
|
|
133
|
-
} = ae(
|
|
133
|
+
} = ae(o), { setState: _ } = L(), { width: V, height: q } = c(we) ? Ne() : Ue(t), { logError: ye } = E(), { pixelRatio: J } = Ve(), { pause: Me, resume: Ce } = U(), D = re(() => V.value / q.value), K = () => {
|
|
134
134
|
f.value && (f.value.setSize(V.value, q.value), f.value.setPixelRatio(Math.min(J.value, 2)));
|
|
135
135
|
}, X = () => {
|
|
136
136
|
if (!f.value)
|
|
137
137
|
return;
|
|
138
|
-
const h =
|
|
138
|
+
const h = c(he);
|
|
139
139
|
if (h) {
|
|
140
140
|
h in z || ye("Renderer Preset must be one of these: " + Object.keys(z).join(", ")), fe(f.value, z[h]);
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
|
-
f.value.shadowMap.enabled =
|
|
144
|
-
},
|
|
143
|
+
f.value.shadowMap.enabled = c(d), f.value.shadowMap.type = c(m), f.value.toneMapping = c(x) || Q, f.value.toneMappingExposure = c(P), f.value.outputEncoding = c(g) || Y, C != null && C.value && f.value.setClearColor(Ze(c(C))), f.value.useLegacyLights = c(v);
|
|
144
|
+
}, be = () => {
|
|
145
145
|
const h = W(e);
|
|
146
146
|
h && (f.value = new De({
|
|
147
147
|
canvas: h,
|
|
148
|
-
alpha:
|
|
149
|
-
antialias:
|
|
150
|
-
context:
|
|
151
|
-
depth:
|
|
152
|
-
failIfMajorPerformanceCaveat:
|
|
153
|
-
logarithmicDepthBuffer: u
|
|
154
|
-
powerPreference:
|
|
155
|
-
precision:
|
|
156
|
-
stencil:
|
|
157
|
-
preserveDrawingBuffer:
|
|
158
|
-
premultipliedAlpha:
|
|
159
|
-
}),
|
|
148
|
+
alpha: c(r),
|
|
149
|
+
antialias: c(n),
|
|
150
|
+
context: c(me),
|
|
151
|
+
depth: c(i),
|
|
152
|
+
failIfMajorPerformanceCaveat: c(a),
|
|
153
|
+
logarithmicDepthBuffer: c(u),
|
|
154
|
+
powerPreference: c(ve),
|
|
155
|
+
precision: c(s),
|
|
156
|
+
stencil: c(p),
|
|
157
|
+
preserveDrawingBuffer: c(ge),
|
|
158
|
+
premultipliedAlpha: c(l)
|
|
159
|
+
}), _("renderer", f.value), _("clock", new ie()), _("aspectRatio", D), X(), K(), Ce(), H.value = !0);
|
|
160
160
|
}, Le = () => {
|
|
161
161
|
f.value && (f.value.dispose(), f.value = void 0, H.value = !1, Me());
|
|
162
162
|
};
|
|
163
163
|
return O([D, J], K), O(
|
|
164
|
-
[d, m, g, v,
|
|
164
|
+
[d, m, g, v, x, P, C],
|
|
165
165
|
X
|
|
166
166
|
), O(
|
|
167
167
|
() => [e, t],
|
|
168
168
|
() => {
|
|
169
|
-
W(e) && W(t) &&
|
|
169
|
+
W(e) && W(t) && be();
|
|
170
170
|
},
|
|
171
171
|
{ immediate: !0, deep: !0 }
|
|
172
172
|
), {
|
|
@@ -179,21 +179,21 @@ function at(e, t, r) {
|
|
|
179
179
|
const pe = (e) => !!e && e.constructor === Array;
|
|
180
180
|
function rt(e) {
|
|
181
181
|
const t = { nodes: {}, materials: {} };
|
|
182
|
-
return e && e.traverse((
|
|
183
|
-
|
|
182
|
+
return e && e.traverse((o) => {
|
|
183
|
+
o.name && (t.nodes[o.name] = o), o.material && !t.materials[o.material.name] && (t.materials[o.material.name] = o.material);
|
|
184
184
|
}), t;
|
|
185
185
|
}
|
|
186
|
-
async function wt(e, t,
|
|
187
|
-
const { logError: i } =
|
|
188
|
-
n && n(
|
|
186
|
+
async function wt(e, t, o, r, n) {
|
|
187
|
+
const { logError: i } = E(), u = new e();
|
|
188
|
+
n && n(u), o && o(u);
|
|
189
189
|
const s = (Array.isArray(t) ? t : [t]).map(
|
|
190
190
|
(l) => new Promise((p, d) => {
|
|
191
|
-
|
|
191
|
+
u.load(
|
|
192
192
|
l,
|
|
193
193
|
(m) => {
|
|
194
194
|
m.scene && Object.assign(m, rt(m.scene)), p(m);
|
|
195
195
|
},
|
|
196
|
-
|
|
196
|
+
r,
|
|
197
197
|
(m) => d(i("[useLoader] - Failed to load resource", m))
|
|
198
198
|
);
|
|
199
199
|
})
|
|
@@ -201,28 +201,28 @@ async function wt(e, t, r, o, n) {
|
|
|
201
201
|
return pe(t) ? await Promise.all(s) : await s[0];
|
|
202
202
|
}
|
|
203
203
|
async function ht(e) {
|
|
204
|
-
const t = new Fe(),
|
|
205
|
-
|
|
204
|
+
const t = new Fe(), o = new Ie(t), r = (n) => new Promise((i, u) => {
|
|
205
|
+
o.load(
|
|
206
206
|
n,
|
|
207
207
|
(a) => i(a),
|
|
208
208
|
() => null,
|
|
209
209
|
() => {
|
|
210
|
-
|
|
210
|
+
u(new Error("[useTextures] - Failed to load texture"));
|
|
211
211
|
}
|
|
212
212
|
);
|
|
213
213
|
});
|
|
214
214
|
if (pe(e)) {
|
|
215
|
-
const n = await Promise.all(e.map((i) =>
|
|
215
|
+
const n = await Promise.all(e.map((i) => r(i)));
|
|
216
216
|
return e.length > 1 ? n : n[0];
|
|
217
217
|
} else {
|
|
218
|
-
const { map: n, displacementMap: i, normalMap:
|
|
218
|
+
const { map: n, displacementMap: i, normalMap: u, roughnessMap: a, metalnessMap: s, aoMap: l } = e;
|
|
219
219
|
return {
|
|
220
|
-
map: n ? await
|
|
221
|
-
displacementMap: i ? await
|
|
222
|
-
normalMap:
|
|
223
|
-
roughnessMap: a ? await
|
|
224
|
-
metalnessMap: s ? await
|
|
225
|
-
aoMap: l ? await
|
|
220
|
+
map: n ? await r(n) : null,
|
|
221
|
+
displacementMap: i ? await r(i) : null,
|
|
222
|
+
normalMap: u ? await r(u) : null,
|
|
223
|
+
roughnessMap: a ? await r(a) : null,
|
|
224
|
+
metalnessMap: s ? await r(s) : null,
|
|
225
|
+
aoMap: l ? await r(l) : null
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
}
|
|
@@ -234,11 +234,11 @@ const ot = {
|
|
|
234
234
|
aspectRatio: re(() => window.innerWidth / window.innerHeight)
|
|
235
235
|
}, R = Pe(ot);
|
|
236
236
|
function L() {
|
|
237
|
-
function e(
|
|
238
|
-
return R[
|
|
237
|
+
function e(o) {
|
|
238
|
+
return R[o];
|
|
239
239
|
}
|
|
240
|
-
function t(
|
|
241
|
-
R[
|
|
240
|
+
function t(o, r) {
|
|
241
|
+
R[o] = r;
|
|
242
242
|
}
|
|
243
243
|
return {
|
|
244
244
|
state: R,
|
|
@@ -247,70 +247,86 @@ function L() {
|
|
|
247
247
|
setState: t
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
|
-
const ee = ne(new We()),
|
|
250
|
+
const ee = ne(new We()), A = M(new ze()), it = M(null);
|
|
251
251
|
function de() {
|
|
252
252
|
const { setState: e } = L();
|
|
253
|
-
e("raycaster", ee.value), e("pointer",
|
|
254
|
-
function t(
|
|
255
|
-
|
|
253
|
+
e("raycaster", ee.value), e("pointer", A), e("currentInstance", it);
|
|
254
|
+
function t(o) {
|
|
255
|
+
A.value.x = o.clientX / window.innerWidth * 2 - 1, A.value.y = -(o.clientY / window.innerHeight) * 2 + 1;
|
|
256
256
|
}
|
|
257
257
|
return window.addEventListener("pointermove", t), {
|
|
258
258
|
raycaster: ee,
|
|
259
|
-
pointer:
|
|
259
|
+
pointer: A
|
|
260
260
|
};
|
|
261
261
|
}
|
|
262
262
|
const yt = !0, te = "[TresJS ▲ ■ ●] ";
|
|
263
|
-
function
|
|
264
|
-
function e(
|
|
265
|
-
console.error(`${te} ${
|
|
263
|
+
function E() {
|
|
264
|
+
function e(r, n) {
|
|
265
|
+
console.error(`${te} ${r}`, n || "");
|
|
266
266
|
}
|
|
267
|
-
function t(
|
|
268
|
-
console.warn(`${te} ${
|
|
267
|
+
function t(r) {
|
|
268
|
+
console.warn(`${te} ${r}`);
|
|
269
269
|
}
|
|
270
|
-
function r
|
|
270
|
+
function o(r, n) {
|
|
271
271
|
}
|
|
272
272
|
return {
|
|
273
273
|
logError: e,
|
|
274
274
|
logWarning: t,
|
|
275
|
-
logMessage:
|
|
275
|
+
logMessage: o
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function Mt() {
|
|
279
|
+
const { logWarning: e } = E();
|
|
280
|
+
function t(r, n, i) {
|
|
281
|
+
let u = null;
|
|
282
|
+
return r.traverse((a) => {
|
|
283
|
+
a[n] === i && (u = a);
|
|
284
|
+
}), u || e(`Child with ${n} '${i}' not found.`), u;
|
|
285
|
+
}
|
|
286
|
+
function o(r, n) {
|
|
287
|
+
return t(r, "name", n);
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
seek: t,
|
|
291
|
+
seekByName: o
|
|
276
292
|
};
|
|
277
293
|
}
|
|
278
|
-
const { logWarning: st } =
|
|
279
|
-
function
|
|
294
|
+
const { logWarning: st } = E();
|
|
295
|
+
function ut(e) {
|
|
280
296
|
for (const t in e)
|
|
281
297
|
if (t.indexOf("on") === 0)
|
|
282
298
|
return !0;
|
|
283
299
|
return !1;
|
|
284
300
|
}
|
|
285
|
-
let
|
|
286
|
-
const
|
|
287
|
-
createElement(e, t,
|
|
301
|
+
let k = null;
|
|
302
|
+
const ct = {
|
|
303
|
+
createElement(e, t, o, r) {
|
|
288
304
|
if (e === "template" || tt(e))
|
|
289
305
|
return null;
|
|
290
306
|
let n;
|
|
291
|
-
if (
|
|
292
|
-
(!(
|
|
307
|
+
if (r === null && (r = {}), r != null && r.args ? n = new $.value[e.replace("Tres", "")](...r.args) : n = new $.value[e.replace("Tres", "")](), n.isCamera) {
|
|
308
|
+
(!(r != null && r.position) || r != null && r.position.every((u) => u == 0)) && st(
|
|
293
309
|
// eslint-disable-next-line max-len
|
|
294
310
|
"Camera is positioned at the center of the scene [0,0,0], if this is not intentional try setting a position if your scene seems empty 🤗"
|
|
295
311
|
);
|
|
296
|
-
const { pushCamera: i } =
|
|
312
|
+
const { pushCamera: i } = ue();
|
|
297
313
|
i(n);
|
|
298
314
|
}
|
|
299
|
-
return (
|
|
315
|
+
return (r == null ? void 0 : r.attach) === void 0 && (n.isMaterial ? n.attach = "material" : n.isBufferGeometry && (n.attach = "geometry")), n;
|
|
300
316
|
},
|
|
301
|
-
insert(e, t,
|
|
302
|
-
if (
|
|
303
|
-
const a =
|
|
317
|
+
insert(e, t, o) {
|
|
318
|
+
if (k === null && t.isScene && (k = t), t === null && (t = k), t != null && t.isObject3D && (e != null && e.isObject3D)) {
|
|
319
|
+
const a = o ? t.children.indexOf(o) : 0;
|
|
304
320
|
e.parent = t, t.children.splice(a, 0, e), e.dispatchEvent({ type: "added" });
|
|
305
321
|
} else
|
|
306
322
|
typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
|
|
307
|
-
const { onLoop:
|
|
323
|
+
const { onLoop: r } = U();
|
|
308
324
|
let n = null, i = null;
|
|
309
|
-
const { raycaster:
|
|
310
|
-
e && e instanceof He &&
|
|
325
|
+
const { raycaster: u } = de();
|
|
326
|
+
e && e instanceof He && ut(e) && (r(() => {
|
|
311
327
|
var a, s, l;
|
|
312
|
-
if (t != null && t.children && e &&
|
|
313
|
-
const p =
|
|
328
|
+
if (t != null && t.children && e && u) {
|
|
329
|
+
const p = u.value.intersectObjects(t.children);
|
|
314
330
|
p.length > 0 && p[0].object.uuid === e.uuid ? (i = p[0], (n === null || n.object.uuid !== (i == null ? void 0 : i.object.uuid)) && ((a = e.onPointerEnter) == null || a.call(e, i)), (s = e.onPointerMove) == null || s.call(e, i)) : (i = null, n !== null && ((l = e.onPointerLeave) == null || l.call(e, n))), n = i;
|
|
315
331
|
}
|
|
316
332
|
}), qe(window, "click", () => {
|
|
@@ -324,24 +340,24 @@ const ut = {
|
|
|
324
340
|
const t = e.parentNode;
|
|
325
341
|
t && t.removeChild(e);
|
|
326
342
|
},
|
|
327
|
-
patchProp(e, t,
|
|
343
|
+
patchProp(e, t, o, r) {
|
|
328
344
|
if (e) {
|
|
329
345
|
let n = e, i = t;
|
|
330
|
-
const
|
|
331
|
-
let a = n == null ? void 0 : n[
|
|
332
|
-
if (e.parent || (e.parent =
|
|
346
|
+
const u = T(i);
|
|
347
|
+
let a = n == null ? void 0 : n[u];
|
|
348
|
+
if (e.parent || (e.parent = k), n.type === "BufferGeometry" && (i = i.split("-").pop(), n.setAttribute(
|
|
333
349
|
T(i),
|
|
334
|
-
new
|
|
350
|
+
new $e(...r)
|
|
335
351
|
)), i.includes("-") && a === void 0) {
|
|
336
352
|
const l = i.split("-");
|
|
337
353
|
a = l.reduce((p, d) => p[T(d)], n), i = l.pop(), a != null && a.set || (n = l.reduce((p, d) => p[T(d)], n));
|
|
338
354
|
}
|
|
339
|
-
let s =
|
|
355
|
+
let s = r;
|
|
340
356
|
if (s === "" && (s = !0), Z(a)) {
|
|
341
|
-
Array.isArray(s) ? e[
|
|
357
|
+
Array.isArray(s) ? e[u](...s) : e[u](s);
|
|
342
358
|
return;
|
|
343
359
|
}
|
|
344
|
-
!(a != null && a.set) && !Z(a) ? n[
|
|
360
|
+
!(a != null && a.set) && !Z(a) ? n[u] = s : a.constructor === s.constructor && (a != null && a.copy) ? a == null || a.copy(s) : Array.isArray(s) ? a.set(...s) : !a.isColor && a.setScalar ? a.setScalar(s) : a.set(s);
|
|
345
361
|
}
|
|
346
362
|
},
|
|
347
363
|
parentNode(e) {
|
|
@@ -356,15 +372,15 @@ const ut = {
|
|
|
356
372
|
setScopeId: () => void 0,
|
|
357
373
|
cloneNode: () => void 0,
|
|
358
374
|
insertStaticContent: () => void 0
|
|
359
|
-
}, { createApp: lt } =
|
|
360
|
-
const t = lt(
|
|
361
|
-
function
|
|
375
|
+
}, { createApp: lt } = Se(ct), ft = (e) => {
|
|
376
|
+
const t = lt(o);
|
|
377
|
+
function o() {
|
|
362
378
|
return e && e.default ? e.default() : [];
|
|
363
379
|
}
|
|
364
380
|
return t;
|
|
365
381
|
};
|
|
366
382
|
se(oe);
|
|
367
|
-
const { logWarning: pt } =
|
|
383
|
+
const { logWarning: pt } = E(), dt = Te({
|
|
368
384
|
name: "TresCanvas",
|
|
369
385
|
props: [
|
|
370
386
|
"shadows",
|
|
@@ -381,14 +397,14 @@ const { logWarning: pt } = _(), dt = Re({
|
|
|
381
397
|
"windowSize",
|
|
382
398
|
"preset"
|
|
383
399
|
],
|
|
384
|
-
setup(e, { slots: t, expose:
|
|
400
|
+
setup(e, { slots: t, expose: o }) {
|
|
385
401
|
e.physicallyCorrectLights === !0 && pt("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
402
|
+
const r = M(), n = M(), i = new oe.Scene(), { setState: u } = L();
|
|
403
|
+
u("scene", i), Re(() => {
|
|
404
|
+
u("renderer", null);
|
|
389
405
|
});
|
|
390
406
|
function a() {
|
|
391
|
-
const { renderer: p } = at(n,
|
|
407
|
+
const { renderer: p } = at(n, r, e), { activeCamera: d } = ue(), { onLoop: m } = U(), { raycaster: w, pointer: v } = de();
|
|
392
408
|
m(() => {
|
|
393
409
|
var g;
|
|
394
410
|
d.value && (w.value.setFromCamera(v.value, d.value), (g = p.value) == null || g.render(i, d.value));
|
|
@@ -399,13 +415,13 @@ const { logWarning: pt } = _(), dt = Re({
|
|
|
399
415
|
function l() {
|
|
400
416
|
s = ft(t), s.provide("useTres", L()), s.provide("extend", se), s.mount(i);
|
|
401
417
|
}
|
|
402
|
-
return l(),
|
|
418
|
+
return l(), o({
|
|
403
419
|
scene: i
|
|
404
|
-
}), () =>
|
|
405
|
-
|
|
420
|
+
}), () => S(
|
|
421
|
+
S(
|
|
406
422
|
"div",
|
|
407
423
|
{
|
|
408
|
-
ref:
|
|
424
|
+
ref: r,
|
|
409
425
|
"data-scene": i.uuid,
|
|
410
426
|
key: i.uuid,
|
|
411
427
|
style: {
|
|
@@ -417,7 +433,7 @@ const { logWarning: pt } = _(), dt = Re({
|
|
|
417
433
|
}
|
|
418
434
|
},
|
|
419
435
|
[
|
|
420
|
-
|
|
436
|
+
S(
|
|
421
437
|
"div",
|
|
422
438
|
{
|
|
423
439
|
style: {
|
|
@@ -426,7 +442,7 @@ const { logWarning: pt } = _(), dt = Re({
|
|
|
426
442
|
}
|
|
427
443
|
},
|
|
428
444
|
[
|
|
429
|
-
|
|
445
|
+
S("canvas", {
|
|
430
446
|
ref: n,
|
|
431
447
|
"data-scene": i.uuid,
|
|
432
448
|
style: {
|
|
@@ -444,7 +460,7 @@ const { logWarning: pt } = _(), dt = Re({
|
|
|
444
460
|
)
|
|
445
461
|
);
|
|
446
462
|
}
|
|
447
|
-
}),
|
|
463
|
+
}), Ct = {
|
|
448
464
|
install(e) {
|
|
449
465
|
e.component("TresCanvas", dt);
|
|
450
466
|
}
|
|
@@ -452,17 +468,18 @@ const { logWarning: pt } = _(), dt = Re({
|
|
|
452
468
|
export {
|
|
453
469
|
Je as CameraType,
|
|
454
470
|
dt as TresCanvas,
|
|
455
|
-
|
|
456
|
-
|
|
471
|
+
$ as catalogue,
|
|
472
|
+
Ct as default,
|
|
457
473
|
se as extend,
|
|
458
474
|
yt as isProd,
|
|
459
475
|
rt as trasverseObjects,
|
|
460
|
-
|
|
476
|
+
ue as useCamera,
|
|
461
477
|
wt as useLoader,
|
|
462
|
-
|
|
478
|
+
E as useLogger,
|
|
463
479
|
de as useRaycaster,
|
|
464
|
-
|
|
480
|
+
U as useRenderLoop,
|
|
465
481
|
at as useRenderer,
|
|
482
|
+
Mt as useSeek,
|
|
466
483
|
ht as useTexture,
|
|
467
484
|
L as useTres
|
|
468
485
|
};
|
package/dist/tres.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v2.0.0-alpha.
|
|
3
|
+
* version: v2.0.0-alpha.5
|
|
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(p,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):(p=typeof globalThis<"u"?globalThis:p||self,l(p.tres={},p.Vue,p.Three,p.VueUseCore))})(this,function(p,l,c,u){"use strict";function se(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const o=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(t,a,o.get?o:{enumerable:!0,get:()=>e[a]})}}return t.default=e,Object.freeze(t)}const $=se(c),U=l.ref({uuid:c.MathUtils.generateUUID()}),I=e=>void Object.assign(U.value,e);var J=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(J||{});const ue=45;let C;function z(){const{state:e,setState:t,aspectRatio:a}=M();function o(r="Perspective",s){var d,v,g;if(r==="Perspective"){const{near:w,far:b,fov:h}=s||{near:.1,far:1e3,fov:ue};C=new c.PerspectiveCamera(h,((d=e.aspectRatio)==null?void 0:d.value)||window.innerWidth/window.innerHeight,w,b),(v=e.cameras)==null||v.push(C)}else{const{left:w,right:b,top:h,bottom:y,near:F,far:B}=s||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};C=new c.OrthographicCamera(w,b,h,y,F,B),(g=e.cameras)==null||g.push(C)}return e.camera=C,t("camera",e.camera),C}function n(){var r;e.camera instanceof c.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(r=e.camera)==null||r.updateProjectionMatrix()}function i(r){var s;(s=e.cameras)==null||s.push(r),r instanceof c.PerspectiveCamera&&e.aspectRatio&&(r.aspect=e.aspectRatio.value),r.updateProjectionMatrix(),t("camera",r)}function f(){e.cameras=[]}return l.watchEffect(()=>{a!=null&&a.value&&n()}),{activeCamera:l.toRef(e,"camera"),createCamera:o,updateCamera:n,pushCamera:i,clearCameras:f}}const K=u.createEventHook(),X=u.createEventHook(),W=u.createEventHook(),P=new c.Clock;let A=0,k=0;const{pause:le,resume:ce,isActive:fe}=u.useRafFn(()=>{K.trigger({delta:A,elapsed:k,clock:P}),X.trigger({delta:A,elapsed:k,clock:P}),W.trigger({delta:A,elapsed:k,clock:P})},{immediate:!1});W.on(()=>{A=P.getDelta(),k=P.getElapsedTime()});function j(){return{onBeforeLoop:K.on,onLoop:X.on,onAfterLoop:W.on,pause:le,resume:ce,isActive:fe}}function pe(e){return e instanceof c.Color?e:Array.isArray(e)?new c.Color(...e):new c.Color(e)}const R={realistic:{outputEncoding:c.sRGBEncoding,toneMapping:c.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:c.PCFSoftShadowMap}}},Y=(e,t)=>{for(const a of Object.keys(t))t[a]instanceof Object&&Object.assign(t[a],Y(e[a],t[a]));return Object.assign(e||{},t),e},de=me("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 x(e){return e.replace(/-([a-z])/g,(t,a)=>a.toUpperCase())}function me(e,t){const a=Object.create(null),o=e.split(",");for(let n=0;n<o.length;n++)a[o[n]]=!0;return t?n=>!!a[n.toLowerCase()]:n=>!!a[n]}const m=l.shallowRef(),G=l.ref(!1);function Q(e,t,a){const{alpha:o=!0,antialias:n=!0,depth:i,logarithmicDepthBuffer:f,failIfMajorPerformanceCaveat:r,precision:s,premultipliedAlpha:d,stencil:v,shadows:g=!1,shadowMapType:w=c.PCFShadowMap,physicallyCorrectLights:b=!1,useLegacyLights:h=!1,outputEncoding:y=c.LinearEncoding,toneMapping:F=c.NoToneMapping,toneMappingExposure:B=1,context:Ue=void 0,powerPreference:Ae="default",preserveDrawingBuffer:ke=!1,clearColor:O,windowSize:je=!1,preset:xe=void 0}=l.toRefs(a),{setState:q}=M(),{width:ne,height:ae}=u.resolveUnref(je)?u.useWindowSize():u.useElementSize(t),{logError:_e}=S(),{pixelRatio:re}=u.useDevicePixelRatio(),{pause:Te,resume:De}=j(),V=l.computed(()=>ne.value/ae.value),oe=()=>{m.value&&(m.value.setSize(ne.value,ae.value),m.value.setPixelRatio(Math.min(re.value,2)))},ie=()=>{if(!m.value)return;const L=u.resolveUnref(xe);if(L){L in R||_e("Renderer Preset must be one of these: "+Object.keys(R).join(", ")),Y(m.value,R[L]);return}m.value.shadowMap.enabled=u.resolveUnref(g),m.value.shadowMap.type=u.resolveUnref(w),m.value.toneMapping=u.resolveUnref(F)||c.NoToneMapping,m.value.toneMappingExposure=u.resolveUnref(B),m.value.outputEncoding=u.resolveUnref(y)||c.LinearEncoding,O!=null&&O.value&&m.value.setClearColor(pe(u.resolveUnref(O))),m.value.useLegacyLights=u.resolveUnref(h)},Fe=()=>{const L=u.unrefElement(e);L&&(m.value=new c.WebGLRenderer({canvas:L,alpha:u.resolveUnref(o),antialias:u.resolveUnref(n),context:u.resolveUnref(Ue),depth:u.resolveUnref(i),failIfMajorPerformanceCaveat:u.resolveUnref(r),logarithmicDepthBuffer:u.resolveUnref(f),powerPreference:u.resolveUnref(Ae),precision:u.resolveUnref(s),stencil:u.resolveUnref(v),preserveDrawingBuffer:u.resolveUnref(ke),premultipliedAlpha:u.resolveUnref(d)}),q("renderer",m.value),q("clock",new c.Clock),q("aspectRatio",V),ie(),oe(),De(),G.value=!0)},Be=()=>{m.value&&(m.value.dispose(),m.value=void 0,G.value=!1,Te())};return l.watch([V,re],oe),l.watch([g,w,y,h,F,B,O],ie),l.watch(()=>[e,t],()=>{u.unrefElement(e)&&u.unrefElement(t)&&Fe()},{immediate:!0,deep:!0}),{renderer:m,isReady:G,dispose:Be,aspectRatio:V}}const Z=e=>!!e&&e.constructor===Array;function E(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 ve(e,t,a,o,n){const{logError:i}=S(),f=new e;n&&n(f),a&&a(f);const s=(Array.isArray(t)?t:[t]).map(d=>new Promise((v,g)=>{f.load(d,w=>{w.scene&&Object.assign(w,E(w.scene)),v(w)},o,w=>g(i("[useLoader] - Failed to load resource",w)))}));return Z(t)?await Promise.all(s):await s[0]}async function ge(e){const t=new c.LoadingManager,a=new c.TextureLoader(t),o=n=>new Promise((i,f)=>{a.load(n,r=>i(r),()=>null,()=>{f(new Error("[useTextures] - Failed to load texture"))})});if(Z(e)){const n=await Promise.all(e.map(i=>o(i)));return e.length>1?n:n[0]}else{const{map:n,displacementMap:i,normalMap:f,roughnessMap:r,metalnessMap:s,aoMap:d}=e;return{map:n?await o(n):null,displacementMap:i?await o(i):null,normalMap:f?await o(f):null,roughnessMap:r?await o(r):null,metalnessMap:s?await o(s):null,aoMap:d?await o(d):null}}}const we={camera:void 0,cameras:[],scene:void 0,renderer:void 0,aspectRatio:l.computed(()=>window.innerWidth/window.innerHeight)},_=l.shallowReactive(we);function M(){function e(a){return _[a]}function t(a,o){_[a]=o}return{state:_,...l.toRefs(_),getState:e,setState:t}}const H=l.shallowRef(new c.Raycaster),T=l.ref(new c.Vector2),he=l.ref(null);function N(){const{setState:e}=M();e("raycaster",H.value),e("pointer",T),e("currentInstance",he);function t(a){T.value.x=a.clientX/window.innerWidth*2-1,T.value.y=-(a.clientY/window.innerHeight)*2+1}return window.addEventListener("pointermove",t),{raycaster:H,pointer:T}}const ye=!0,ee="[TresJS ▲ ■ ●] ";function S(){function e(o,n){console.error(`${ee} ${o}`,n||"")}function t(o){console.warn(`${ee} ${o}`)}function a(o,n){}return{logError:e,logWarning:t,logMessage:a}}const{logWarning:Ce}=S();function Me(e){for(const t in e)if(t.indexOf("on")===0)return!0;return!1}function ze(e){}let D=null;const be={createElement(e,t,a,o){if(e==="template"||de(e))return null;let n;if(o===null&&(o={}),o!=null&&o.args?n=new U.value[e.replace("Tres","")](...o.args):n=new U.value[e.replace("Tres","")],n.isCamera){(!(o!=null&&o.position)||o!=null&&o.position.every(f=>f==0))&&Ce("Camera is positioned at the center of the scene [0,0,0], if this is not intentional try setting a position if your scene seems empty 🤗");const{pushCamera:i}=z();i(n)}return(o==null?void 0:o.attach)===void 0&&(n.isMaterial?n.attach="material":n.isBufferGeometry&&(n.attach="geometry")),n},insert(e,t,a){if(D===null&&t.isScene&&(D=t),t===null&&(t=D),t!=null&&t.isObject3D&&(e!=null&&e.isObject3D)){const r=a?t.children.indexOf(a):0;e.parent=t,t.children.splice(r,0,e),e.dispatchEvent({type:"added"})}else typeof(e==null?void 0:e.attach)=="string"&&(e.__previousAttach=e[t==null?void 0:t.attach],t&&(t[e.attach]=e));const{onLoop:o}=j();let n=null,i=null;const{raycaster:f}=N();e&&e instanceof c.Mesh&&Me(e)&&(o(()=>{var r,s,d;if(t!=null&&t.children&&e&&f){const v=f.value.intersectObjects(t.children);v.length>0&&v[0].object.uuid===e.uuid?(i=v[0],(n===null||n.object.uuid!==(i==null?void 0:i.object.uuid))&&((r=e.onPointerEnter)==null||r.call(e,i)),(s=e.onPointerMove)==null||s.call(e,i)):(i=null,n!==null&&((d=e.onPointerLeave)==null||d.call(e,n))),n=i}}),u.useEventListener(window,"click",()=>{var r;i!==null&&((r=e.onClick)==null||r.call(e,i))}))},remove(e){if(!e)return;const t=e.parentNode;t&&t.removeChild(e)},patchProp(e,t,a,o){if(e){let n=e,i=t;const f=x(i);let r=n==null?void 0:n[f];if(e.parent||(e.parent=D),n.type==="BufferGeometry"&&(i=i.split("-").pop(),n.setAttribute(x(i),new c.BufferAttribute(...o))),i.includes("-")&&r===void 0){const d=i.split("-");r=d.reduce((v,g)=>v[x(g)],n),i=d.pop(),r!=null&&r.set||(n=d.reduce((v,g)=>v[x(g)],n))}let s=o;if(s===""&&(s=!0),u.isFunction(r)){Array.isArray(s)?e[f](...s):e[f](s);return}!(r!=null&&r.set)&&!u.isFunction(r)?n[f]=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:Le}=l.createRenderer(be),Pe=e=>{const t=Le(a);function a(){return e&&e.default?e.default():[]}return t};I($);const{logWarning:Se}=S(),te=l.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t,expose:a}){e.physicallyCorrectLights===!0&&Se("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const o=l.ref(),n=l.ref(),i=new $.Scene,{setState:f}=M();f("scene",i),l.onUnmounted(()=>{f("renderer",null)});function r(){const{renderer:v}=Q(n,o,e),{activeCamera:g}=z(),{onLoop:w}=j(),{raycaster:b,pointer:h}=N();w(()=>{var y;g.value&&(b.value.setFromCamera(h.value,g.value),(y=v.value)==null||y.render(i,g.value))})}l.watch(n,r);let s;function d(){s=Pe(t),s.provide("useTres",M()),s.provide("extend",I),s.mount(i)}return d(),a({scene:i}),()=>l.h(l.h("div",{ref:o,"data-scene":i.uuid,key:i.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[l.h("div",{style:{width:"100%",height:"100%"}},[l.h("canvas",{ref:n,"data-scene":i.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),Oe={install(e){e.component("TresCanvas",te)}};p.CameraType=J,p.TresCanvas=te,p.catalogue=U,p.default=Oe,p.extend=I,p.isProd=ye,p.trasverseObjects=E,p.useCamera=z,p.useLoader=ve,p.useLogger=S,p.useRaycaster=N,p.useRenderLoop=j,p.useRenderer=Q,p.useTexture=ge,p.useTres=M,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
8
|
+
(function(p,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):(p=typeof globalThis<"u"?globalThis:p||self,l(p.tres={},p.Vue,p.Three,p.VueUseCore))})(this,function(p,l,f,u){"use strict";function se(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(t,a,r.get?r:{enumerable:!0,get:()=>e[a]})}}return t.default=e,Object.freeze(t)}const V=se(f),O=l.ref({uuid:f.MathUtils.generateUUID()}),I=e=>void Object.assign(O.value,e);var J=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(J||{});const ue=45;let C;function W(){const{state:e,setState:t,aspectRatio:a}=M();function r(o="Perspective",s){var d,v,g;if(o==="Perspective"){const{near:h,far:L,fov:w}=s||{near:.1,far:1e3,fov:ue};C=new f.PerspectiveCamera(w,((d=e.aspectRatio)==null?void 0:d.value)||window.innerWidth/window.innerHeight,h,L),(v=e.cameras)==null||v.push(C)}else{const{left:h,right:L,top:w,bottom:y,near:B,far:F}=s||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};C=new f.OrthographicCamera(h,L,w,y,B,F),(g=e.cameras)==null||g.push(C)}return e.camera=C,t("camera",e.camera),C}function n(){var o;e.camera instanceof f.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(o=e.camera)==null||o.updateProjectionMatrix()}function i(o){var s;(s=e.cameras)==null||s.push(o),o instanceof f.PerspectiveCamera&&e.aspectRatio&&(o.aspect=e.aspectRatio.value),o.updateProjectionMatrix(),t("camera",o)}function c(){e.cameras=[]}return l.watchEffect(()=>{a!=null&&a.value&&n()}),{activeCamera:l.toRef(e,"camera"),createCamera:r,updateCamera:n,pushCamera:i,clearCameras:c}}const K=u.createEventHook(),X=u.createEventHook(),z=u.createEventHook(),S=new f.Clock;let U=0,A=0;const{pause:le,resume:ce,isActive:fe}=u.useRafFn(()=>{K.trigger({delta:U,elapsed:A,clock:S}),X.trigger({delta:U,elapsed:A,clock:S}),z.trigger({delta:U,elapsed:A,clock:S})},{immediate:!1});z.on(()=>{U=S.getDelta(),A=S.getElapsedTime()});function j(){return{onBeforeLoop:K.on,onLoop:X.on,onAfterLoop:z.on,pause:le,resume:ce,isActive:fe}}function pe(e){return e instanceof f.Color?e:Array.isArray(e)?new f.Color(...e):new f.Color(e)}const R={realistic:{outputEncoding:f.sRGBEncoding,toneMapping:f.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:f.PCFSoftShadowMap}}},Y=(e,t)=>{for(const a of Object.keys(t))t[a]instanceof Object&&Object.assign(t[a],Y(e[a],t[a]));return Object.assign(e||{},t),e},de=me("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 x(e){return e.replace(/-([a-z])/g,(t,a)=>a.toUpperCase())}function me(e,t){const a=Object.create(null),r=e.split(",");for(let n=0;n<r.length;n++)a[r[n]]=!0;return t?n=>!!a[n.toLowerCase()]:n=>!!a[n]}const m=l.shallowRef(),N=l.ref(!1);function Q(e,t,a){const{alpha:r=!0,antialias:n=!0,depth:i,logarithmicDepthBuffer:c,failIfMajorPerformanceCaveat:o,precision:s,premultipliedAlpha:d,stencil:v,shadows:g=!1,shadowMapType:h=f.PCFShadowMap,physicallyCorrectLights:L=!1,useLegacyLights:w=!1,outputEncoding:y=f.LinearEncoding,toneMapping:B=f.NoToneMapping,toneMappingExposure:F=1,context:Ue=void 0,powerPreference:Ae="default",preserveDrawingBuffer:je=!1,clearColor:k,windowSize:xe=!1,preset:_e=void 0}=l.toRefs(a),{setState:$}=M(),{width:ne,height:ae}=u.resolveUnref(xe)?u.useWindowSize():u.useElementSize(t),{logError:Te}=b(),{pixelRatio:re}=u.useDevicePixelRatio(),{pause:De,resume:Be}=j(),q=l.computed(()=>ne.value/ae.value),oe=()=>{m.value&&(m.value.setSize(ne.value,ae.value),m.value.setPixelRatio(Math.min(re.value,2)))},ie=()=>{if(!m.value)return;const P=u.resolveUnref(_e);if(P){P in R||Te("Renderer Preset must be one of these: "+Object.keys(R).join(", ")),Y(m.value,R[P]);return}m.value.shadowMap.enabled=u.resolveUnref(g),m.value.shadowMap.type=u.resolveUnref(h),m.value.toneMapping=u.resolveUnref(B)||f.NoToneMapping,m.value.toneMappingExposure=u.resolveUnref(F),m.value.outputEncoding=u.resolveUnref(y)||f.LinearEncoding,k!=null&&k.value&&m.value.setClearColor(pe(u.resolveUnref(k))),m.value.useLegacyLights=u.resolveUnref(w)},Fe=()=>{const P=u.unrefElement(e);P&&(m.value=new f.WebGLRenderer({canvas:P,alpha:u.resolveUnref(r),antialias:u.resolveUnref(n),context:u.resolveUnref(Ue),depth:u.resolveUnref(i),failIfMajorPerformanceCaveat:u.resolveUnref(o),logarithmicDepthBuffer:u.resolveUnref(c),powerPreference:u.resolveUnref(Ae),precision:u.resolveUnref(s),stencil:u.resolveUnref(v),preserveDrawingBuffer:u.resolveUnref(je),premultipliedAlpha:u.resolveUnref(d)}),$("renderer",m.value),$("clock",new f.Clock),$("aspectRatio",q),ie(),oe(),Be(),N.value=!0)},Ie=()=>{m.value&&(m.value.dispose(),m.value=void 0,N.value=!1,De())};return l.watch([q,re],oe),l.watch([g,h,y,w,B,F,k],ie),l.watch(()=>[e,t],()=>{u.unrefElement(e)&&u.unrefElement(t)&&Fe()},{immediate:!0,deep:!0}),{renderer:m,isReady:N,dispose:Ie,aspectRatio:q}}const Z=e=>!!e&&e.constructor===Array;function E(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 ve(e,t,a,r,n){const{logError:i}=b(),c=new e;n&&n(c),a&&a(c);const s=(Array.isArray(t)?t:[t]).map(d=>new Promise((v,g)=>{c.load(d,h=>{h.scene&&Object.assign(h,E(h.scene)),v(h)},r,h=>g(i("[useLoader] - Failed to load resource",h)))}));return Z(t)?await Promise.all(s):await s[0]}async function ge(e){const t=new f.LoadingManager,a=new f.TextureLoader(t),r=n=>new Promise((i,c)=>{a.load(n,o=>i(o),()=>null,()=>{c(new Error("[useTextures] - Failed to load texture"))})});if(Z(e)){const n=await Promise.all(e.map(i=>r(i)));return e.length>1?n:n[0]}else{const{map:n,displacementMap:i,normalMap:c,roughnessMap:o,metalnessMap:s,aoMap:d}=e;return{map:n?await r(n):null,displacementMap:i?await r(i):null,normalMap:c?await r(c):null,roughnessMap:o?await r(o):null,metalnessMap:s?await r(s):null,aoMap:d?await r(d):null}}}const he={camera:void 0,cameras:[],scene:void 0,renderer:void 0,aspectRatio:l.computed(()=>window.innerWidth/window.innerHeight)},_=l.shallowReactive(he);function M(){function e(a){return _[a]}function t(a,r){_[a]=r}return{state:_,...l.toRefs(_),getState:e,setState:t}}const H=l.shallowRef(new f.Raycaster),T=l.ref(new f.Vector2),we=l.ref(null);function G(){const{setState:e}=M();e("raycaster",H.value),e("pointer",T),e("currentInstance",we);function t(a){T.value.x=a.clientX/window.innerWidth*2-1,T.value.y=-(a.clientY/window.innerHeight)*2+1}return window.addEventListener("pointermove",t),{raycaster:H,pointer:T}}const ye=!0,ee="[TresJS ▲ ■ ●] ";function b(){function e(r,n){console.error(`${ee} ${r}`,n||"")}function t(r){console.warn(`${ee} ${r}`)}function a(r,n){}return{logError:e,logWarning:t,logMessage:a}}function Ce(){const{logWarning:e}=b();function t(r,n,i){let c=null;return r.traverse(o=>{o[n]===i&&(c=o)}),c||e(`Child with ${n} '${i}' not found.`),c}function a(r,n){return t(r,"name",n)}return{seek:t,seekByName:a}}const{logWarning:Me}=b();function be(e){for(const t in e)if(t.indexOf("on")===0)return!0;return!1}function ze(e){}let D=null;const Le={createElement(e,t,a,r){if(e==="template"||de(e))return null;let n;if(r===null&&(r={}),r!=null&&r.args?n=new O.value[e.replace("Tres","")](...r.args):n=new O.value[e.replace("Tres","")],n.isCamera){(!(r!=null&&r.position)||r!=null&&r.position.every(c=>c==0))&&Me("Camera is positioned at the center of the scene [0,0,0], if this is not intentional try setting a position if your scene seems empty 🤗");const{pushCamera:i}=W();i(n)}return(r==null?void 0:r.attach)===void 0&&(n.isMaterial?n.attach="material":n.isBufferGeometry&&(n.attach="geometry")),n},insert(e,t,a){if(D===null&&t.isScene&&(D=t),t===null&&(t=D),t!=null&&t.isObject3D&&(e!=null&&e.isObject3D)){const o=a?t.children.indexOf(a):0;e.parent=t,t.children.splice(o,0,e),e.dispatchEvent({type:"added"})}else typeof(e==null?void 0:e.attach)=="string"&&(e.__previousAttach=e[t==null?void 0:t.attach],t&&(t[e.attach]=e));const{onLoop:r}=j();let n=null,i=null;const{raycaster:c}=G();e&&e instanceof f.Mesh&&be(e)&&(r(()=>{var o,s,d;if(t!=null&&t.children&&e&&c){const v=c.value.intersectObjects(t.children);v.length>0&&v[0].object.uuid===e.uuid?(i=v[0],(n===null||n.object.uuid!==(i==null?void 0:i.object.uuid))&&((o=e.onPointerEnter)==null||o.call(e,i)),(s=e.onPointerMove)==null||s.call(e,i)):(i=null,n!==null&&((d=e.onPointerLeave)==null||d.call(e,n))),n=i}}),u.useEventListener(window,"click",()=>{var o;i!==null&&((o=e.onClick)==null||o.call(e,i))}))},remove(e){if(!e)return;const t=e.parentNode;t&&t.removeChild(e)},patchProp(e,t,a,r){if(e){let n=e,i=t;const c=x(i);let o=n==null?void 0:n[c];if(e.parent||(e.parent=D),n.type==="BufferGeometry"&&(i=i.split("-").pop(),n.setAttribute(x(i),new f.BufferAttribute(...r))),i.includes("-")&&o===void 0){const d=i.split("-");o=d.reduce((v,g)=>v[x(g)],n),i=d.pop(),o!=null&&o.set||(n=d.reduce((v,g)=>v[x(g)],n))}let s=r;if(s===""&&(s=!0),u.isFunction(o)){Array.isArray(s)?e[c](...s):e[c](s);return}!(o!=null&&o.set)&&!u.isFunction(o)?n[c]=s:o.constructor===s.constructor&&(o!=null&&o.copy)?o==null||o.copy(s):Array.isArray(s)?o.set(...s):!o.isColor&&o.setScalar?o.setScalar(s):o.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:Pe}=l.createRenderer(Le),Se=e=>{const t=Pe(a);function a(){return e&&e.default?e.default():[]}return t};I(V);const{logWarning:ke}=b(),te=l.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t,expose:a}){e.physicallyCorrectLights===!0&&ke("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const r=l.ref(),n=l.ref(),i=new V.Scene,{setState:c}=M();c("scene",i),l.onUnmounted(()=>{c("renderer",null)});function o(){const{renderer:v}=Q(n,r,e),{activeCamera:g}=W(),{onLoop:h}=j(),{raycaster:L,pointer:w}=G();h(()=>{var y;g.value&&(L.value.setFromCamera(w.value,g.value),(y=v.value)==null||y.render(i,g.value))})}l.watch(n,o);let s;function d(){s=Se(t),s.provide("useTres",M()),s.provide("extend",I),s.mount(i)}return d(),a({scene:i}),()=>l.h(l.h("div",{ref:r,"data-scene":i.uuid,key:i.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[l.h("div",{style:{width:"100%",height:"100%"}},[l.h("canvas",{ref:n,"data-scene":i.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),Oe={install(e){e.component("TresCanvas",te)}};p.CameraType=J,p.TresCanvas=te,p.catalogue=O,p.default=Oe,p.extend=I,p.isProd=ye,p.trasverseObjects=E,p.useCamera=W,p.useLoader=ve,p.useLogger=b,p.useRaycaster=G,p.useRenderLoop=j,p.useRenderer=Q,p.useSeek=Ce,p.useTexture=ge,p.useTres=M,Object.defineProperties(p,{__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.0.0-alpha.
|
|
4
|
+
"version": "2.0.0-alpha.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
7
7
|
"files": [
|