@tresjs/core 2.0.0-beta.0 → 2.0.0-beta.1
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/tres.js +72 -67
- package/dist/tres.umd.cjs +3 -3
- package/package.json +17 -17
package/dist/tres.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v2.0.0-beta.
|
|
3
|
+
* version: v2.0.0-beta.1
|
|
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 oe, toRef as
|
|
9
|
-
import * as
|
|
10
|
-
import { MathUtils as De, PerspectiveCamera as O, OrthographicCamera as ze, Clock as
|
|
8
|
+
import { ref as M, watchEffect as oe, toRef as ke, shallowRef as ie, toRefs as se, computed as ce, watch as z, shallowReactive as ue, provide as Ae, inject as Oe, createRenderer as je, defineComponent as fe, onMounted as _e, onUnmounted as Be, h as L } from "vue";
|
|
9
|
+
import * as le from "three";
|
|
10
|
+
import { MathUtils as De, PerspectiveCamera as O, OrthographicCamera as ze, Clock as de, Color as W, sRGBEncoding as We, ACESFilmicToneMapping as Fe, PCFSoftShadowMap as Ie, PCFShadowMap as He, LinearEncoding as ee, NoToneMapping as te, WebGLRenderer as Ue, LoadingManager as $e, TextureLoader as Ge, Raycaster as Ne, Vector2 as Ve, Mesh as qe, BufferAttribute as Ye } from "three";
|
|
11
11
|
import { createEventHook as $, useRafFn as Ke, resolveUnref as f, useWindowSize as Xe, useElementSize as Je, useDevicePixelRatio as Qe, unrefElement as F, useEventListener as Ze, isFunction as ne } from "@vueuse/core";
|
|
12
|
-
const H = M({ uuid: De.generateUUID() }),
|
|
12
|
+
const H = M({ uuid: De.generateUUID() }), pe = (e) => void Object.assign(H.value, e);
|
|
13
13
|
var et = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(et || {});
|
|
14
14
|
const tt = 45;
|
|
15
15
|
let x;
|
|
16
16
|
function U() {
|
|
17
|
-
const { state: e, setState: t, aspectRatio: r } =
|
|
17
|
+
const { state: e, setState: t, aspectRatio: r } = S();
|
|
18
18
|
function a(o = "Perspective", c) {
|
|
19
19
|
var u, l, p;
|
|
20
20
|
if (o === "Perspective") {
|
|
@@ -51,28 +51,28 @@ function U() {
|
|
|
51
51
|
return oe(() => {
|
|
52
52
|
r != null && r.value && n();
|
|
53
53
|
}), {
|
|
54
|
-
activeCamera:
|
|
54
|
+
activeCamera: ke(e, "camera"),
|
|
55
55
|
createCamera: a,
|
|
56
56
|
updateCamera: n,
|
|
57
57
|
pushCamera: i,
|
|
58
58
|
clearCameras: s
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
const
|
|
61
|
+
const me = $(), ve = $(), G = $(), E = new de();
|
|
62
62
|
let j = 0, _ = 0;
|
|
63
63
|
const { pause: nt, resume: at, isActive: rt } = Ke(
|
|
64
64
|
() => {
|
|
65
|
-
|
|
65
|
+
me.trigger({ delta: j, elapsed: _, clock: E }), ve.trigger({ delta: j, elapsed: _, clock: E }), G.trigger({ delta: j, elapsed: _, clock: E });
|
|
66
66
|
},
|
|
67
67
|
{ immediate: !1 }
|
|
68
68
|
);
|
|
69
69
|
G.on(() => {
|
|
70
|
-
j =
|
|
70
|
+
j = E.getDelta(), _ = E.getElapsedTime();
|
|
71
71
|
});
|
|
72
72
|
function N() {
|
|
73
73
|
return {
|
|
74
|
-
onBeforeLoop:
|
|
75
|
-
onLoop:
|
|
74
|
+
onBeforeLoop: me.on,
|
|
75
|
+
onLoop: ve.on,
|
|
76
76
|
onAfterLoop: G.on,
|
|
77
77
|
pause: nt,
|
|
78
78
|
resume: at,
|
|
@@ -92,9 +92,9 @@ const I = {
|
|
|
92
92
|
type: Ie
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
},
|
|
95
|
+
}, ge = (e, t) => {
|
|
96
96
|
for (const r of Object.keys(t))
|
|
97
|
-
t[r] instanceof Object && Object.assign(t[r],
|
|
97
|
+
t[r] instanceof Object && Object.assign(t[r], ge(e[r], t[r]));
|
|
98
98
|
return Object.assign(e || {}, t), e;
|
|
99
99
|
}, it = "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", st = /* @__PURE__ */ ct(it);
|
|
100
100
|
function R(e) {
|
|
@@ -124,62 +124,62 @@ function ut(e) {
|
|
|
124
124
|
outputEncoding: b = ee,
|
|
125
125
|
toneMapping: g = te,
|
|
126
126
|
toneMappingExposure: P = 1,
|
|
127
|
-
context:
|
|
128
|
-
powerPreference:
|
|
129
|
-
preserveDrawingBuffer:
|
|
130
|
-
clearColor:
|
|
127
|
+
context: ye = void 0,
|
|
128
|
+
powerPreference: xe = "default",
|
|
129
|
+
preserveDrawingBuffer: Me = !1,
|
|
130
|
+
clearColor: C,
|
|
131
131
|
windowSize: V = !1,
|
|
132
|
-
preset:
|
|
133
|
-
} = se(e), { state: h, setState: B } =
|
|
134
|
-
!f(V) && ((Z = (Q = h.container) == null ? void 0 : Q.value) == null ? void 0 : Z.offsetHeight) === 0 &&
|
|
132
|
+
preset: Ce = void 0
|
|
133
|
+
} = se(e), { state: h, setState: B } = S(), { width: q, height: Y } = f(V) ? Xe() : Je(h.container), { logError: Le, logWarning: Ee } = T(), { pixelRatio: K } = Qe(), { pause: Se, resume: Te } = N(), D = ce(() => q.value / Y.value);
|
|
134
|
+
!f(V) && ((Z = (Q = h.container) == null ? void 0 : Q.value) == null ? void 0 : Z.offsetHeight) === 0 && Ee(`Oops... Seems like your canvas height is currently 0px, by default it takes the height of it's parent, so make sure it has some height with CSS.
|
|
135
135
|
You could set windowSize=true to force the canvas to be the size of the window.`);
|
|
136
136
|
const X = () => {
|
|
137
137
|
t.value && (t.value.setSize(q.value, Y.value), t.value.setPixelRatio(Math.min(K.value, 2)));
|
|
138
138
|
}, J = () => {
|
|
139
139
|
if (!t.value)
|
|
140
140
|
return;
|
|
141
|
-
const y = f(
|
|
141
|
+
const y = f(Ce);
|
|
142
142
|
if (y) {
|
|
143
|
-
y in I ||
|
|
143
|
+
y in I || Le("Renderer Preset must be one of these: " + Object.keys(I).join(", ")), ge(t.value, I[y]);
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
146
|
-
t.value.shadowMap.enabled = f(p), t.value.shadowMap.type = f(d), t.value.toneMapping = f(g) || te, t.value.toneMappingExposure = f(P), t.value.outputEncoding = f(b) || ee,
|
|
147
|
-
},
|
|
146
|
+
t.value.shadowMap.enabled = f(p), t.value.shadowMap.type = f(d), t.value.toneMapping = f(g) || te, t.value.toneMappingExposure = f(P), t.value.outputEncoding = f(b) || ee, C != null && C.value && t.value.setClearColor(ot(f(C))), t.value.useLegacyLights = f(v);
|
|
147
|
+
}, Pe = () => {
|
|
148
148
|
const y = F(h.canvas);
|
|
149
149
|
y && (t.value = new Ue({
|
|
150
150
|
canvas: y,
|
|
151
151
|
alpha: f(a),
|
|
152
152
|
antialias: f(n),
|
|
153
|
-
context: f(
|
|
153
|
+
context: f(ye),
|
|
154
154
|
depth: f(i),
|
|
155
155
|
failIfMajorPerformanceCaveat: f(o),
|
|
156
156
|
logarithmicDepthBuffer: f(s),
|
|
157
|
-
powerPreference: f(
|
|
157
|
+
powerPreference: f(xe),
|
|
158
158
|
precision: f(c),
|
|
159
159
|
stencil: f(l),
|
|
160
|
-
preserveDrawingBuffer: f(
|
|
160
|
+
preserveDrawingBuffer: f(Me),
|
|
161
161
|
premultipliedAlpha: f(u)
|
|
162
|
-
}), B("renderer", t.value), B("clock", new
|
|
163
|
-
},
|
|
164
|
-
t.value && (t.value.dispose(), t.value = void 0, r.value = !1,
|
|
162
|
+
}), B("renderer", t.value), B("clock", new de()), B("aspectRatio", D), J(), X(), Te(), r.value = !0);
|
|
163
|
+
}, Re = () => {
|
|
164
|
+
t.value && (t.value.dispose(), t.value = void 0, r.value = !1, Se());
|
|
165
165
|
};
|
|
166
166
|
return z([D, K], X), z(
|
|
167
|
-
[p, d, b, v, g, P,
|
|
167
|
+
[p, d, b, v, g, P, C],
|
|
168
168
|
J
|
|
169
169
|
), z(
|
|
170
170
|
() => [h.canvas, h.container],
|
|
171
171
|
() => {
|
|
172
|
-
F(h.canvas) && F(h.container) &&
|
|
172
|
+
F(h.canvas) && F(h.container) && Pe();
|
|
173
173
|
},
|
|
174
174
|
{ immediate: !0, deep: !0 }
|
|
175
175
|
), {
|
|
176
176
|
renderer: t,
|
|
177
177
|
isReady: r,
|
|
178
|
-
dispose:
|
|
178
|
+
dispose: Re,
|
|
179
179
|
aspectRatio: D
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
|
-
const
|
|
182
|
+
const he = (e) => !!e && e.constructor === Array;
|
|
183
183
|
function ft(e) {
|
|
184
184
|
const t = { nodes: {}, materials: {} };
|
|
185
185
|
return e && e.traverse((r) => {
|
|
@@ -187,7 +187,7 @@ function ft(e) {
|
|
|
187
187
|
}), t;
|
|
188
188
|
}
|
|
189
189
|
async function Et(e, t, r, a, n) {
|
|
190
|
-
const { logError: i } =
|
|
190
|
+
const { logError: i } = T(), s = new e();
|
|
191
191
|
n && n(s), r && r(s);
|
|
192
192
|
const c = (Array.isArray(t) ? t : [t]).map(
|
|
193
193
|
(u) => new Promise((l, p) => {
|
|
@@ -201,7 +201,7 @@ async function Et(e, t, r, a, n) {
|
|
|
201
201
|
);
|
|
202
202
|
})
|
|
203
203
|
);
|
|
204
|
-
return
|
|
204
|
+
return he(t) ? await Promise.all(c) : await c[0];
|
|
205
205
|
}
|
|
206
206
|
async function St(e) {
|
|
207
207
|
const t = new $e(), r = new Ge(t), a = (n) => new Promise((i, s) => {
|
|
@@ -214,7 +214,7 @@ async function St(e) {
|
|
|
214
214
|
}
|
|
215
215
|
);
|
|
216
216
|
});
|
|
217
|
-
if (
|
|
217
|
+
if (he(e)) {
|
|
218
218
|
const n = await Promise.all(e.map((i) => a(i)));
|
|
219
219
|
return e.length > 1 ? n : n[0];
|
|
220
220
|
} else {
|
|
@@ -245,9 +245,9 @@ function lt() {
|
|
|
245
245
|
const e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, r = Math.random() * 4294967295 | 0, a = Math.random() * 4294967295 | 0;
|
|
246
246
|
return (m[e & 255] + m[e >> 8 & 255] + m[e >> 16 & 255] + m[e >> 24 & 255] + "-" + m[t & 255] + m[t >> 8 & 255] + "-" + m[t >> 16 & 15 | 64] + m[t >> 24 & 255] + "-" + m[r & 63 | 128] + m[r >> 8 & 255] + "-" + m[r >> 16 & 255] + m[r >> 24 & 255] + m[a & 255] + m[a >> 8 & 255] + m[a >> 16 & 255] + m[a >> 24 & 255]).toLowerCase();
|
|
247
247
|
}
|
|
248
|
-
const
|
|
248
|
+
const we = Symbol();
|
|
249
249
|
function dt() {
|
|
250
|
-
const e =
|
|
250
|
+
const e = ue({
|
|
251
251
|
uuid: lt(),
|
|
252
252
|
camera: void 0,
|
|
253
253
|
cameras: [],
|
|
@@ -267,14 +267,18 @@ function dt() {
|
|
|
267
267
|
getState: t,
|
|
268
268
|
setState: r
|
|
269
269
|
};
|
|
270
|
-
return Ae(
|
|
270
|
+
return Ae(we, a), a;
|
|
271
271
|
}
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
272
|
+
const S = () => Oe(we, {
|
|
273
|
+
state: ue({
|
|
274
|
+
camera: void 0,
|
|
275
|
+
cameras: [],
|
|
276
|
+
scene: void 0,
|
|
277
|
+
renderer: void 0
|
|
278
|
+
})
|
|
279
|
+
}), ae = ie(new Ne()), k = M(new Ve()), pt = M(null);
|
|
280
|
+
function be() {
|
|
281
|
+
const { setState: e } = S();
|
|
278
282
|
e("raycaster", ae.value), e("pointer", k), e("currentInstance", pt);
|
|
279
283
|
function t(r) {
|
|
280
284
|
k.value.x = r.clientX / window.innerWidth * 2 - 1, k.value.y = -(r.clientY / window.innerHeight) * 2 + 1;
|
|
@@ -285,7 +289,7 @@ function we() {
|
|
|
285
289
|
};
|
|
286
290
|
}
|
|
287
291
|
const Tt = !0, re = "[TresJS ▲ ■ ●] ";
|
|
288
|
-
function
|
|
292
|
+
function T() {
|
|
289
293
|
function e(a, n) {
|
|
290
294
|
console.error(`${re} ${a}`, n || "");
|
|
291
295
|
}
|
|
@@ -301,7 +305,7 @@ function C() {
|
|
|
301
305
|
};
|
|
302
306
|
}
|
|
303
307
|
function Pt() {
|
|
304
|
-
const { logWarning: e } =
|
|
308
|
+
const { logWarning: e } = T();
|
|
305
309
|
function t(a, n, i) {
|
|
306
310
|
let s = null;
|
|
307
311
|
return a.traverse((o) => {
|
|
@@ -316,7 +320,7 @@ function Pt() {
|
|
|
316
320
|
seekByName: r
|
|
317
321
|
};
|
|
318
322
|
}
|
|
319
|
-
const { logWarning: mt } =
|
|
323
|
+
const { logWarning: mt } = T();
|
|
320
324
|
function vt(e) {
|
|
321
325
|
for (const t in e)
|
|
322
326
|
if (t.indexOf("on") === 0)
|
|
@@ -348,7 +352,7 @@ const gt = {
|
|
|
348
352
|
const { onLoop: a } = N();
|
|
349
353
|
let n = null, i = null;
|
|
350
354
|
if (e && e instanceof qe && vt(e)) {
|
|
351
|
-
const { raycaster: s } =
|
|
355
|
+
const { raycaster: s } = be();
|
|
352
356
|
a(() => {
|
|
353
357
|
var o, c, u;
|
|
354
358
|
if (t != null && t.children && e && s) {
|
|
@@ -410,8 +414,8 @@ const gt = {
|
|
|
410
414
|
}
|
|
411
415
|
return t;
|
|
412
416
|
};
|
|
413
|
-
|
|
414
|
-
const { logWarning: bt } =
|
|
417
|
+
pe(le);
|
|
418
|
+
const { logWarning: bt } = T(), yt = fe({
|
|
415
419
|
name: "TresScene",
|
|
416
420
|
props: [
|
|
417
421
|
"shadows",
|
|
@@ -430,7 +434,7 @@ const { logWarning: bt } = C(), yt = ue({
|
|
|
430
434
|
],
|
|
431
435
|
setup(e, { slots: t, expose: r }) {
|
|
432
436
|
e.physicallyCorrectLights === !0 && bt("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
|
|
433
|
-
const a = M(), n = M(), i = new
|
|
437
|
+
const a = M(), n = M(), i = new le.Scene(), { setState: s } = S();
|
|
434
438
|
s("scene", i), s("canvas", n), s("container", a);
|
|
435
439
|
const { pushCamera: o } = U();
|
|
436
440
|
o(new O()), _e(() => {
|
|
@@ -439,7 +443,7 @@ const { logWarning: bt } = C(), yt = ue({
|
|
|
439
443
|
s("renderer", null);
|
|
440
444
|
});
|
|
441
445
|
function c() {
|
|
442
|
-
const { renderer: p } = ut(e), { activeCamera: d } = U(), { onLoop: w } = N(), { raycaster: v, pointer: b } =
|
|
446
|
+
const { renderer: p } = ut(e), { activeCamera: d } = U(), { onLoop: w } = N(), { raycaster: v, pointer: b } = be();
|
|
443
447
|
oe(() => {
|
|
444
448
|
d.value && v.value.setFromCamera(b.value, d.value);
|
|
445
449
|
}), w(() => {
|
|
@@ -449,12 +453,12 @@ const { logWarning: bt } = C(), yt = ue({
|
|
|
449
453
|
}
|
|
450
454
|
let u;
|
|
451
455
|
function l() {
|
|
452
|
-
u = wt(t), u.provide("useTres",
|
|
456
|
+
u = wt(t), u.provide("useTres", S()), u.provide("extend", pe), u.mount(i);
|
|
453
457
|
}
|
|
454
458
|
return l(), r({
|
|
455
459
|
scene: i
|
|
456
|
-
}), () =>
|
|
457
|
-
|
|
460
|
+
}), () => L(
|
|
461
|
+
L(
|
|
458
462
|
"div",
|
|
459
463
|
{
|
|
460
464
|
ref: a,
|
|
@@ -469,7 +473,7 @@ const { logWarning: bt } = C(), yt = ue({
|
|
|
469
473
|
}
|
|
470
474
|
},
|
|
471
475
|
[
|
|
472
|
-
|
|
476
|
+
L(
|
|
473
477
|
"div",
|
|
474
478
|
{
|
|
475
479
|
style: {
|
|
@@ -478,7 +482,7 @@ const { logWarning: bt } = C(), yt = ue({
|
|
|
478
482
|
}
|
|
479
483
|
},
|
|
480
484
|
[
|
|
481
|
-
|
|
485
|
+
L("canvas", {
|
|
482
486
|
ref: n,
|
|
483
487
|
"data-scene": i.uuid,
|
|
484
488
|
style: {
|
|
@@ -496,7 +500,7 @@ const { logWarning: bt } = C(), yt = ue({
|
|
|
496
500
|
)
|
|
497
501
|
);
|
|
498
502
|
}
|
|
499
|
-
}), xt =
|
|
503
|
+
}), xt = fe({
|
|
500
504
|
name: "TresCanvas",
|
|
501
505
|
props: [
|
|
502
506
|
"shadows",
|
|
@@ -513,8 +517,9 @@ const { logWarning: bt } = C(), yt = ue({
|
|
|
513
517
|
"windowSize",
|
|
514
518
|
"preset"
|
|
515
519
|
],
|
|
516
|
-
setup(e, { slots: t }) {
|
|
517
|
-
|
|
520
|
+
setup(e, { slots: t, expose: r }) {
|
|
521
|
+
const a = dt();
|
|
522
|
+
return r(a), () => L(yt, e, t);
|
|
518
523
|
}
|
|
519
524
|
}), Rt = {
|
|
520
525
|
install(e) {
|
|
@@ -526,17 +531,17 @@ export {
|
|
|
526
531
|
xt as TresCanvas,
|
|
527
532
|
H as catalogue,
|
|
528
533
|
Rt as default,
|
|
529
|
-
|
|
534
|
+
pe as extend,
|
|
530
535
|
Tt as isProd,
|
|
531
536
|
ft as trasverseObjects,
|
|
532
537
|
U as useCamera,
|
|
533
538
|
Et as useLoader,
|
|
534
|
-
|
|
535
|
-
|
|
539
|
+
T as useLogger,
|
|
540
|
+
be as useRaycaster,
|
|
536
541
|
N as useRenderLoop,
|
|
537
542
|
ut as useRenderer,
|
|
538
543
|
Pt as useSeek,
|
|
539
544
|
St as useTexture,
|
|
540
|
-
|
|
545
|
+
S as useTres,
|
|
541
546
|
dt as useTresProvider
|
|
542
547
|
};
|
package/dist/tres.umd.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v2.0.0-beta.
|
|
3
|
+
* version: v2.0.0-beta.1
|
|
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(d,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d.tres={},d.Vue,d.Three,d.VueUseCore))})(this,function(d,i,l,c){"use strict";function le(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const q=le(l),U=i.ref({uuid:l.MathUtils.generateUUID()}),W=e=>void Object.assign(U.value,e);var V=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(V||{});const de=45;let
|
|
9
|
-
You could set windowSize=true to force the canvas to be the size of the window.`);const ie=()=>{t.value&&(t.value.setSize(re.value,oe.value),t.value.setPixelRatio(Math.min(se.value,2)))},ce=()=>{if(!t.value)return;const P=c.resolveUnref(Be);if(P){P in R||Fe("Renderer Preset must be one of these: "+Object.keys(R).join(", ")),X(t.value,R[P]);return}t.value.shadowMap.enabled=c.resolveUnref(h),t.value.shadowMap.type=c.resolveUnref(g),t.value.toneMapping=c.resolveUnref(y)||l.NoToneMapping,t.value.toneMappingExposure=c.resolveUnref(F),t.value.outputEncoding=c.resolveUnref(S)||l.LinearEncoding,O!=null&&O.value&&t.value.setClearColor(ve(c.resolveUnref(O))),t.value.useLegacyLights=c.resolveUnref(w)},Ne=()=>{const P=c.unrefElement(C.canvas);P&&(t.value=new l.WebGLRenderer({canvas:P,alpha:c.resolveUnref(a),antialias:c.resolveUnref(n),context:c.resolveUnref(_e),depth:c.resolveUnref(s),failIfMajorPerformanceCaveat:c.resolveUnref(o),logarithmicDepthBuffer:c.resolveUnref(f),powerPreference:c.resolveUnref(De),precision:c.resolveUnref(u),stencil:c.resolveUnref(m),preserveDrawingBuffer:c.resolveUnref(ze),premultipliedAlpha:c.resolveUnref(p)}),G("renderer",t.value),G("clock",new l.Clock),G("aspectRatio",$),ce(),ie(),Re(),r.value=!0)},Ge=()=>{t.value&&(t.value.dispose(),t.value=void 0,r.value=!1,Ie())};return i.watch([$,se],ie),i.watch([h,g,S,w,y,F,O],ce),i.watch(()=>[C.canvas,C.container],()=>{c.unrefElement(C.canvas)&&c.unrefElement(C.container)&&Ne()},{immediate:!0,deep:!0}),{renderer:t,isReady:r,dispose:Ge,aspectRatio:$}}const Q=e=>!!e&&e.constructor===Array;function Z(e){const t={nodes:{},materials:{}};return e&&e.traverse(r=>{r.name&&(t.nodes[r.name]=r),r.material&&!t.materials[r.material.name]&&(t.materials[r.material.name]=r.material)}),t}async function be(e,t,r,a,n){const{logError:s}=b(),f=new e;n&&n(f),r&&r(f);const u=(Array.isArray(t)?t:[t]).map(p=>new Promise((m,h)=>{f.load(p,g=>{g.scene&&Object.assign(g,Z(g.scene)),m(g)},a,g=>h(s("[useLoader] - Failed to load resource",g)))}));return Q(t)?await Promise.all(u):await u[0]}async function ye(e){const t=new l.LoadingManager,r=new l.TextureLoader(t),a=n=>new Promise((s,f)=>{r.load(n,o=>s(o),()=>null,()=>{f(new Error("[useTextures] - Failed to load texture"))})});if(Q(e)){const n=await Promise.all(e.map(s=>a(s)));return e.length>1?n:n[0]}else{const{map:n,displacementMap:s,normalMap:f,roughnessMap:o,metalnessMap:u,aoMap:p,alphaMap:m,matcap:h}=e;return{map:n?await a(n):null,displacementMap:s?await a(s):null,normalMap:f?await a(f):null,roughnessMap:o?await a(o):null,metalnessMap:u?await a(u):null,aoMap:p?await a(p):null,alphaMap:m?await a(m):null,matcap:h?await a(h):null}}}const v=["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 Ce(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0,a=Math.random()*4294967295|0;return(v[e&255]+v[e>>8&255]+v[e>>16&255]+v[e>>24&255]+"-"+v[t&255]+v[t>>8&255]+"-"+v[t>>16&15|64]+v[t>>24&255]+"-"+v[r&63|128]+v[r>>8&255]+"-"+v[r>>16&255]+v[r>>24&255]+v[a&255]+v[a>>8&255]+v[a>>16&255]+v[a>>24&255]).toLowerCase()}const E=Symbol();function H(){const e=i.shallowReactive({uuid:Ce(),camera:void 0,cameras:[],scene:void 0,renderer:void 0,aspectRatio:i.computed(()=>window.innerWidth/window.innerHeight)});function t(n){return e[n]}function r(n,s){e[n]=s}const a={state:e,...i.toRefs(e),getState:t,setState:r};return i.provide(E,a),a}const L=()=>{const e=i.inject(E),{logError:t}=b();return e||t("useTres must be used together with useTresProvider"),e},ee=i.shallowRef(new l.Raycaster),z=i.ref(new l.Vector2),Me=i.ref(null);function N(){const{setState:e}=L();e("raycaster",ee.value),e("pointer",z),e("currentInstance",Me);function t(r){z.value.x=r.clientX/window.innerWidth*2-1,z.value.y=-(r.clientY/window.innerHeight)*2+1}return window.addEventListener("pointermove",t),{raycaster:ee,pointer:z}}const Le=!0,te="[TresJS ▲ ■ ●] ";function b(){function e(a,n){console.error(`${te} ${a}`,n||"")}function t(a){console.warn(`${te} ${a}`)}function r(a,n){}return{logError:e,logWarning:t,logMessage:r}}function xe(){const{logWarning:e}=b();function t(a,n,s){let f=null;return a.traverse(o=>{o[n]===s&&(f=o)}),f||e(`Child with ${n} '${s}' not found.`),f}function r(a,n){return t(a,"name",n)}return{seek:t,seekByName:r}}const{logWarning:Se}=b();function Pe(e){for(const t in e)if(t.indexOf("on")===0)return!0;return!1}function qe(e){}let B=null;const ke={createElement(e,t,r,a){if(e==="template"||he(e))return null;let n;if(a===null&&(a={}),a!=null&&a.args?n=new U.value[e.replace("Tres","")](...a.args):n=new U.value[e.replace("Tres","")],n.isCamera){(!(a!=null&&a.position)||a!=null&&a.position.every(f=>f==0))&&Se("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:s}=A();s(n)}return(a==null?void 0:a.attach)===void 0&&(n.isMaterial?n.attach="material":n.isBufferGeometry&&(n.attach="geometry")),n},insert(e,t,r){if(B===null&&t.isScene&&(B=t),t===null&&(t=B),t!=null&&t.isObject3D&&(e!=null&&e.isObject3D)){const f=r?t.children.indexOf(r):0;e.parent=t,t.children.splice(f,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:a}=_();let n=null,s=null;if(e&&e instanceof l.Mesh&&Pe(e)){const{raycaster:f}=N();a(()=>{var o,u,p;if(t!=null&&t.children&&e&&f){const m=f.value.intersectObjects(t.children);m.length>0&&m[0].object.uuid===e.uuid?(s=m[0],(n===null||n.object.uuid!==(s==null?void 0:s.object.uuid))&&((o=e.onPointerEnter)==null||o.call(e,s)),(u=e.onPointerMove)==null||u.call(e,s)):(s=null,n!==null&&((p=e.onPointerLeave)==null||p.call(e,n))),n=s}}),c.useEventListener(window,"click",()=>{var o;s!==null&&((o=e.onClick)==null||o.call(e,s))})}},remove(e){if(!e)return;const t=e.parentNode;t&&t.removeChild(e)},patchProp(e,t,r,a){if(e){let n=e,s=t;const f=D(s);let o=n==null?void 0:n[f];if(e.parent||(e.parent=B),n.type==="BufferGeometry"){n.setAttribute(D(s),new l.BufferAttribute(...a));return}if(s.includes("-")&&o===void 0){const p=s.split("-");o=p.reduce((m,h)=>m[D(h)],n),s=p.pop(),o!=null&&o.set||(n=p.reduce((m,h)=>m[D(h)],n))}let u=a;if(u===""&&(u=!0),c.isFunction(o)){Array.isArray(u)?e[f](...u):e[f](u);return}!(o!=null&&o.set)&&!c.isFunction(o)?n[f]=u:o.constructor===u.constructor&&(o!=null&&o.copy)?o==null||o.copy(u):Array.isArray(u)?o.set(...u):!o.isColor&&o.setScalar?o.setScalar(u):o.set(u)}},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:Oe}=i.createRenderer(ke),Ue=e=>{const t=Oe(r);function r(){return e&&e.default?e.default():[]}return t};W(q);const{logWarning:Ae}=b(),Te=i.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t,expose:r}){e.physicallyCorrectLights===!0&&Ae("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const a=i.ref(),n=i.ref(),s=new q.Scene,{setState:f}=L();f("scene",s),f("canvas",n),f("container",a);const{pushCamera:o}=A();o(new l.PerspectiveCamera),i.onMounted(()=>{u()}),i.onUnmounted(()=>{f("renderer",null)});function u(){const{renderer:h}=J(e),{activeCamera:g}=A(),{onLoop:x}=_(),{raycaster:w,pointer:S}=N();i.watchEffect(()=>{g.value&&w.value.setFromCamera(S.value,g.value)}),x(()=>{var y;g.value&&((y=h.value)==null||y.render(s,g.value))})}let p;function m(){p=Ue(t),p.provide("useTres",L()),p.provide("extend",W),p.mount(s)}return m(),r({scene:s}),()=>i.h(i.h("div",{ref:a,"data-scene":s.uuid,key:s.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[i.h("div",{style:{width:"100%",height:"100%"}},[i.h("canvas",{ref:n,"data-scene":s.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),ne=i.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t}){return H(),()=>i.h(Te,e,t)}}),je={install(e){e.component("TresCanvas",ne)}};d.CameraType=V,d.TresCanvas=ne,d.catalogue=U,d.default=je,d.extend=W,d.isProd=Le,d.trasverseObjects=Z,d.useCamera=A,d.useLoader=be,d.useLogger=b,d.useRaycaster=N,d.useRenderLoop=_,d.useRenderer=J,d.useSeek=xe,d.useTexture=ye,d.useTres=L,d.useTresProvider=H,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
8
|
+
(function(d,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d.tres={},d.Vue,d.Three,d.VueUseCore))})(this,function(d,i,l,c){"use strict";function le(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const q=le(l),U=i.ref({uuid:l.MathUtils.generateUUID()}),W=e=>void Object.assign(U.value,e);var V=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(V||{});const de=45;let C;function A(){const{state:e,setState:t,aspectRatio:r}=M();function a(o="Perspective",u){var p,m,h;if(o==="Perspective"){const{near:v,far:x,fov:w}=u||{near:.1,far:1e3,fov:de};C=new l.PerspectiveCamera(w,((p=e.aspectRatio)==null?void 0:p.value)||window.innerWidth/window.innerHeight,v,x),(m=e.cameras)==null||m.push(C)}else{const{left:v,right:x,top:w,bottom:S,near:b,far:F}=u||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};C=new l.OrthographicCamera(v,x,w,S,b,F),(h=e.cameras)==null||h.push(C)}return e.camera=C,t("camera",e.camera),C}function n(){var o;e.camera instanceof l.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(o=e.camera)==null||o.updateProjectionMatrix()}function s(o){var u;(u=e.cameras)==null||u.push(o),o instanceof l.PerspectiveCamera&&e.aspectRatio&&(o.aspect=e.aspectRatio.value),o.updateProjectionMatrix(),t("camera",o)}function f(){e.cameras=[]}return i.watchEffect(()=>{r!=null&&r.value&&n()}),{activeCamera:i.toRef(e,"camera"),createCamera:a,updateCamera:n,pushCamera:s,clearCameras:f}}const Y=c.createEventHook(),K=c.createEventHook(),I=c.createEventHook(),k=new l.Clock;let j=0,T=0;const{pause:pe,resume:me,isActive:ve}=c.useRafFn(()=>{Y.trigger({delta:j,elapsed:T,clock:k}),K.trigger({delta:j,elapsed:T,clock:k}),I.trigger({delta:j,elapsed:T,clock:k})},{immediate:!1});I.on(()=>{j=k.getDelta(),T=k.getElapsedTime()});function _(){return{onBeforeLoop:Y.on,onLoop:K.on,onAfterLoop:I.on,pause:pe,resume:me,isActive:ve}}function ge(e){return e instanceof l.Color?e:Array.isArray(e)?new l.Color(...e):new l.Color(e)}const R={realistic:{outputEncoding:l.sRGBEncoding,toneMapping:l.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:l.PCFSoftShadowMap}}},X=(e,t)=>{for(const r of Object.keys(t))t[r]instanceof Object&&Object.assign(t[r],X(e[r],t[r]));return Object.assign(e||{},t),e},he=we("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 D(e){return e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase())}function we(e,t){const r=Object.create(null),a=e.split(",");for(let n=0;n<a.length;n++)r[a[n]]=!0;return t?n=>!!r[n.toLowerCase()]:n=>!!r[n]}function J(e){var fe,ue;const t=i.shallowRef(),r=i.ref(!1),{alpha:a=!0,antialias:n=!0,depth:s,logarithmicDepthBuffer:f,failIfMajorPerformanceCaveat:o,precision:u,premultipliedAlpha:p,stencil:m,shadows:h=!1,shadowMapType:v=l.PCFShadowMap,physicallyCorrectLights:x=!1,useLegacyLights:w=!1,outputEncoding:S=l.LinearEncoding,toneMapping:b=l.NoToneMapping,toneMappingExposure:F=1,context:_e=void 0,powerPreference:De="default",preserveDrawingBuffer:ze=!1,clearColor:O,windowSize:ae=!1,preset:Be=void 0}=i.toRefs(e),{state:y,setState:G}=M(),{width:re,height:oe}=c.resolveUnref(ae)?c.useWindowSize():c.useElementSize(y.container),{logError:Fe,logWarning:We}=L(),{pixelRatio:se}=c.useDevicePixelRatio(),{pause:Ie,resume:Re}=_(),$=i.computed(()=>re.value/oe.value);!c.resolveUnref(ae)&&((ue=(fe=y.container)==null?void 0:fe.value)==null?void 0:ue.offsetHeight)===0&&We(`Oops... Seems like your canvas height is currently 0px, by default it takes the height of it's parent, so make sure it has some height with CSS.
|
|
9
|
+
You could set windowSize=true to force the canvas to be the size of the window.`);const ie=()=>{t.value&&(t.value.setSize(re.value,oe.value),t.value.setPixelRatio(Math.min(se.value,2)))},ce=()=>{if(!t.value)return;const P=c.resolveUnref(Be);if(P){P in R||Fe("Renderer Preset must be one of these: "+Object.keys(R).join(", ")),X(t.value,R[P]);return}t.value.shadowMap.enabled=c.resolveUnref(h),t.value.shadowMap.type=c.resolveUnref(v),t.value.toneMapping=c.resolveUnref(b)||l.NoToneMapping,t.value.toneMappingExposure=c.resolveUnref(F),t.value.outputEncoding=c.resolveUnref(S)||l.LinearEncoding,O!=null&&O.value&&t.value.setClearColor(ge(c.resolveUnref(O))),t.value.useLegacyLights=c.resolveUnref(w)},Ne=()=>{const P=c.unrefElement(y.canvas);P&&(t.value=new l.WebGLRenderer({canvas:P,alpha:c.resolveUnref(a),antialias:c.resolveUnref(n),context:c.resolveUnref(_e),depth:c.resolveUnref(s),failIfMajorPerformanceCaveat:c.resolveUnref(o),logarithmicDepthBuffer:c.resolveUnref(f),powerPreference:c.resolveUnref(De),precision:c.resolveUnref(u),stencil:c.resolveUnref(m),preserveDrawingBuffer:c.resolveUnref(ze),premultipliedAlpha:c.resolveUnref(p)}),G("renderer",t.value),G("clock",new l.Clock),G("aspectRatio",$),ce(),ie(),Re(),r.value=!0)},Ge=()=>{t.value&&(t.value.dispose(),t.value=void 0,r.value=!1,Ie())};return i.watch([$,se],ie),i.watch([h,v,S,w,b,F,O],ce),i.watch(()=>[y.canvas,y.container],()=>{c.unrefElement(y.canvas)&&c.unrefElement(y.container)&&Ne()},{immediate:!0,deep:!0}),{renderer:t,isReady:r,dispose:Ge,aspectRatio:$}}const Q=e=>!!e&&e.constructor===Array;function Z(e){const t={nodes:{},materials:{}};return e&&e.traverse(r=>{r.name&&(t.nodes[r.name]=r),r.material&&!t.materials[r.material.name]&&(t.materials[r.material.name]=r.material)}),t}async function be(e,t,r,a,n){const{logError:s}=L(),f=new e;n&&n(f),r&&r(f);const u=(Array.isArray(t)?t:[t]).map(p=>new Promise((m,h)=>{f.load(p,v=>{v.scene&&Object.assign(v,Z(v.scene)),m(v)},a,v=>h(s("[useLoader] - Failed to load resource",v)))}));return Q(t)?await Promise.all(u):await u[0]}async function ye(e){const t=new l.LoadingManager,r=new l.TextureLoader(t),a=n=>new Promise((s,f)=>{r.load(n,o=>s(o),()=>null,()=>{f(new Error("[useTextures] - Failed to load texture"))})});if(Q(e)){const n=await Promise.all(e.map(s=>a(s)));return e.length>1?n:n[0]}else{const{map:n,displacementMap:s,normalMap:f,roughnessMap:o,metalnessMap:u,aoMap:p,alphaMap:m,matcap:h}=e;return{map:n?await a(n):null,displacementMap:s?await a(s):null,normalMap:f?await a(f):null,roughnessMap:o?await a(o):null,metalnessMap:u?await a(u):null,aoMap:p?await a(p):null,alphaMap:m?await a(m):null,matcap:h?await a(h):null}}}const g=["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 Ce(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0,a=Math.random()*4294967295|0;return(g[e&255]+g[e>>8&255]+g[e>>16&255]+g[e>>24&255]+"-"+g[t&255]+g[t>>8&255]+"-"+g[t>>16&15|64]+g[t>>24&255]+"-"+g[r&63|128]+g[r>>8&255]+"-"+g[r>>16&255]+g[r>>24&255]+g[a&255]+g[a>>8&255]+g[a>>16&255]+g[a>>24&255]).toLowerCase()}const E=Symbol();function H(){const e=i.shallowReactive({uuid:Ce(),camera:void 0,cameras:[],scene:void 0,renderer:void 0,aspectRatio:i.computed(()=>window.innerWidth/window.innerHeight)});function t(n){return e[n]}function r(n,s){e[n]=s}const a={state:e,...i.toRefs(e),getState:t,setState:r};return i.provide(E,a),a}const M=()=>i.inject(E,{state:i.shallowReactive({camera:void 0,cameras:[],scene:void 0,renderer:void 0})}),ee=i.shallowRef(new l.Raycaster),z=i.ref(new l.Vector2),Me=i.ref(null);function N(){const{setState:e}=M();e("raycaster",ee.value),e("pointer",z),e("currentInstance",Me);function t(r){z.value.x=r.clientX/window.innerWidth*2-1,z.value.y=-(r.clientY/window.innerHeight)*2+1}return window.addEventListener("pointermove",t),{raycaster:ee,pointer:z}}const Le=!0,te="[TresJS ▲ ■ ●] ";function L(){function e(a,n){console.error(`${te} ${a}`,n||"")}function t(a){console.warn(`${te} ${a}`)}function r(a,n){}return{logError:e,logWarning:t,logMessage:r}}function xe(){const{logWarning:e}=L();function t(a,n,s){let f=null;return a.traverse(o=>{o[n]===s&&(f=o)}),f||e(`Child with ${n} '${s}' not found.`),f}function r(a,n){return t(a,"name",n)}return{seek:t,seekByName:r}}const{logWarning:Se}=L();function Pe(e){for(const t in e)if(t.indexOf("on")===0)return!0;return!1}function qe(e){}let B=null;const ke={createElement(e,t,r,a){if(e==="template"||he(e))return null;let n;if(a===null&&(a={}),a!=null&&a.args?n=new U.value[e.replace("Tres","")](...a.args):n=new U.value[e.replace("Tres","")],n.isCamera){(!(a!=null&&a.position)||a!=null&&a.position.every(f=>f==0))&&Se("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:s}=A();s(n)}return(a==null?void 0:a.attach)===void 0&&(n.isMaterial?n.attach="material":n.isBufferGeometry&&(n.attach="geometry")),n},insert(e,t,r){if(B===null&&t.isScene&&(B=t),t===null&&(t=B),t!=null&&t.isObject3D&&(e!=null&&e.isObject3D)){const f=r?t.children.indexOf(r):0;e.parent=t,t.children.splice(f,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:a}=_();let n=null,s=null;if(e&&e instanceof l.Mesh&&Pe(e)){const{raycaster:f}=N();a(()=>{var o,u,p;if(t!=null&&t.children&&e&&f){const m=f.value.intersectObjects(t.children);m.length>0&&m[0].object.uuid===e.uuid?(s=m[0],(n===null||n.object.uuid!==(s==null?void 0:s.object.uuid))&&((o=e.onPointerEnter)==null||o.call(e,s)),(u=e.onPointerMove)==null||u.call(e,s)):(s=null,n!==null&&((p=e.onPointerLeave)==null||p.call(e,n))),n=s}}),c.useEventListener(window,"click",()=>{var o;s!==null&&((o=e.onClick)==null||o.call(e,s))})}},remove(e){if(!e)return;const t=e.parentNode;t&&t.removeChild(e)},patchProp(e,t,r,a){if(e){let n=e,s=t;const f=D(s);let o=n==null?void 0:n[f];if(e.parent||(e.parent=B),n.type==="BufferGeometry"){n.setAttribute(D(s),new l.BufferAttribute(...a));return}if(s.includes("-")&&o===void 0){const p=s.split("-");o=p.reduce((m,h)=>m[D(h)],n),s=p.pop(),o!=null&&o.set||(n=p.reduce((m,h)=>m[D(h)],n))}let u=a;if(u===""&&(u=!0),c.isFunction(o)){Array.isArray(u)?e[f](...u):e[f](u);return}!(o!=null&&o.set)&&!c.isFunction(o)?n[f]=u:o.constructor===u.constructor&&(o!=null&&o.copy)?o==null||o.copy(u):Array.isArray(u)?o.set(...u):!o.isColor&&o.setScalar?o.setScalar(u):o.set(u)}},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:Oe}=i.createRenderer(ke),Ue=e=>{const t=Oe(r);function r(){return e&&e.default?e.default():[]}return t};W(q);const{logWarning:Ae}=L(),je=i.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t,expose:r}){e.physicallyCorrectLights===!0&&Ae("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const a=i.ref(),n=i.ref(),s=new q.Scene,{setState:f}=M();f("scene",s),f("canvas",n),f("container",a);const{pushCamera:o}=A();o(new l.PerspectiveCamera),i.onMounted(()=>{u()}),i.onUnmounted(()=>{f("renderer",null)});function u(){const{renderer:h}=J(e),{activeCamera:v}=A(),{onLoop:x}=_(),{raycaster:w,pointer:S}=N();i.watchEffect(()=>{v.value&&w.value.setFromCamera(S.value,v.value)}),x(()=>{var b;v.value&&((b=h.value)==null||b.render(s,v.value))})}let p;function m(){p=Ue(t),p.provide("useTres",M()),p.provide("extend",W),p.mount(s)}return m(),r({scene:s}),()=>i.h(i.h("div",{ref:a,"data-scene":s.uuid,key:s.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[i.h("div",{style:{width:"100%",height:"100%"}},[i.h("canvas",{ref:n,"data-scene":s.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),ne=i.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t,expose:r}){const a=H();return r(a),()=>i.h(je,e,t)}}),Te={install(e){e.component("TresCanvas",ne)}};d.CameraType=V,d.TresCanvas=ne,d.catalogue=U,d.default=Te,d.extend=W,d.isProd=Le,d.trasverseObjects=Z,d.useCamera=A,d.useLoader=be,d.useLogger=L,d.useRaycaster=N,d.useRenderLoop=_,d.useRenderer=J,d.useSeek=xe,d.useTexture=ye,d.useTres=M,d.useTresProvider=H,Object.defineProperties(d,{__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-beta.
|
|
4
|
+
"version": "2.0.0-beta.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
7
7
|
"files": [
|
|
@@ -67,37 +67,37 @@
|
|
|
67
67
|
"@stackblitz/sdk": "^1.8.1",
|
|
68
68
|
"@tresjs/cientos": "2.0.0-alpha.5",
|
|
69
69
|
"@types/three": "latest",
|
|
70
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
71
|
-
"@typescript-eslint/parser": "^5.
|
|
72
|
-
"@vitejs/plugin-vue": "^4.
|
|
73
|
-
"@vitest/coverage-c8": "^0.29.
|
|
70
|
+
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
71
|
+
"@typescript-eslint/parser": "^5.57.1",
|
|
72
|
+
"@vitejs/plugin-vue": "^4.1.0",
|
|
73
|
+
"@vitest/coverage-c8": "^0.29.8",
|
|
74
74
|
"@vitest/ui": "^0.29.2",
|
|
75
|
-
"@vue/test-utils": "^2.3.
|
|
76
|
-
"eslint": "^8.
|
|
75
|
+
"@vue/test-utils": "^2.3.2",
|
|
76
|
+
"eslint": "^8.37.0",
|
|
77
77
|
"eslint-config-prettier": "^8.5.0",
|
|
78
|
-
"eslint-plugin-vue": "^9.
|
|
78
|
+
"eslint-plugin-vue": "^9.10.0",
|
|
79
79
|
"gsap": "^3.11.4",
|
|
80
80
|
"happy-dom": "^8.7.1",
|
|
81
81
|
"jsdom": "^21.1.0",
|
|
82
82
|
"kolorist": "^1.7.0",
|
|
83
83
|
"pathe": "^1.1.0",
|
|
84
|
-
"prettier": "^2.8.
|
|
85
|
-
"release-it": "^15.
|
|
84
|
+
"prettier": "^2.8.7",
|
|
85
|
+
"release-it": "^15.10.1",
|
|
86
86
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
87
87
|
"rollup-plugin-copy": "^3.4.0",
|
|
88
88
|
"rollup-plugin-visualizer": "^5.9.0",
|
|
89
89
|
"three": "latest",
|
|
90
|
-
"unocss": "^0.
|
|
90
|
+
"unocss": "^0.50.6",
|
|
91
91
|
"unplugin": "^1.3.1",
|
|
92
92
|
"unplugin-vue-components": "^0.24.1",
|
|
93
|
-
"vite": "^4.1
|
|
93
|
+
"vite": "^4.2.1",
|
|
94
94
|
"vite-plugin-banner": "^0.7.0",
|
|
95
|
-
"vite-plugin-dts": "2.
|
|
96
|
-
"vite-plugin-inspect": "^0.7.
|
|
97
|
-
"vite-plugin-require-transform": "^1.0.
|
|
95
|
+
"vite-plugin-dts": "2.2.0",
|
|
96
|
+
"vite-plugin-inspect": "^0.7.18",
|
|
97
|
+
"vite-plugin-require-transform": "^1.0.12",
|
|
98
98
|
"vite-svg-loader": "^4.0.0",
|
|
99
|
-
"vitepress": "1.0.0-alpha.
|
|
100
|
-
"vitest": "^0.29.
|
|
99
|
+
"vitepress": "1.0.0-alpha.65",
|
|
100
|
+
"vitest": "^0.29.8",
|
|
101
101
|
"vue-demi": "^0.13.11"
|
|
102
102
|
}
|
|
103
103
|
}
|