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