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