@tresjs/core 2.0.0-alpha.0 → 2.0.0-alpha.2
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 +134 -130
- package/dist/tres.umd.cjs +2 -2
- package/package.json +3 -2
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.2
|
|
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
|
|
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 Re, defineComponent as Se, h as P } from "vue";
|
|
9
9
|
import * as oe from "three";
|
|
10
|
-
import { MathUtils as Te, PerspectiveCamera as _, OrthographicCamera as
|
|
11
|
-
import { createEventHook as U, useRafFn as
|
|
12
|
-
const G =
|
|
13
|
-
var
|
|
14
|
-
const
|
|
15
|
-
let
|
|
10
|
+
import { MathUtils as Te, PerspectiveCamera as _, OrthographicCamera as Ae, Clock as ie, Color as W, sRGBEncoding as Oe, ACESFilmicToneMapping as ke, PCFSoftShadowMap as je, PCFShadowMap as Be, LinearEncoding as Y, NoToneMapping as Q, WebGLRenderer as De, LoadingManager as Fe, TextureLoader as _e, Raycaster as We, Vector2 as ze, Mesh as Ie, BufferAttribute as He } from "three";
|
|
11
|
+
import { createEventHook as U, useRafFn as Ge, resolveUnref as u, useWindowSize as Ue, useElementSize as $e, useDevicePixelRatio as Ne, unrefElement as z, useEventListener as Ve, isFunction as Z } from "@vueuse/core";
|
|
12
|
+
const G = M({ uuid: Te.generateUUID() }), se = (e) => void Object.assign(G.value, e);
|
|
13
|
+
var qe = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(qe || {});
|
|
14
|
+
const Je = 45;
|
|
15
|
+
let y;
|
|
16
16
|
function ce() {
|
|
17
|
-
const { state: e, setState: t, aspectRatio: r } =
|
|
17
|
+
const { state: e, setState: t, aspectRatio: r } = L();
|
|
18
18
|
function o(a = "Perspective", s) {
|
|
19
|
-
var l,
|
|
19
|
+
var l, p, m;
|
|
20
20
|
if (a === "Perspective") {
|
|
21
|
-
const { near:
|
|
21
|
+
const { near: d, far: w, fov: v } = s || {
|
|
22
22
|
near: 0.1,
|
|
23
23
|
far: 1e3,
|
|
24
|
-
fov:
|
|
24
|
+
fov: Je
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
y = new _(v, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, d, w), (p = e.cameras) == null || p.push(y);
|
|
27
27
|
} else {
|
|
28
|
-
const { left:
|
|
28
|
+
const { left: d, right: w, top: v, bottom: g, near: E, far: x } = s || {
|
|
29
29
|
left: -100,
|
|
30
30
|
right: 100,
|
|
31
31
|
top: 100,
|
|
@@ -33,9 +33,9 @@ function ce() {
|
|
|
33
33
|
near: 0.1,
|
|
34
34
|
far: 1e3
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
y = new Ae(d, w, v, g, E, x), (m = e.cameras) == null || m.push(y);
|
|
37
37
|
}
|
|
38
|
-
return e.camera =
|
|
38
|
+
return e.camera = y, t("camera", e.camera), y;
|
|
39
39
|
}
|
|
40
40
|
function n() {
|
|
41
41
|
var a;
|
|
@@ -58,33 +58,33 @@ function ce() {
|
|
|
58
58
|
clearCameras: c
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
const ue = U(), le = U(),
|
|
62
|
-
let
|
|
63
|
-
const { pause:
|
|
61
|
+
const ue = U(), le = U(), $ = U(), C = new ie();
|
|
62
|
+
let k = 0, j = 0;
|
|
63
|
+
const { pause: Ke, resume: Xe, isActive: Ye } = Ge(
|
|
64
64
|
() => {
|
|
65
|
-
ue.trigger({ delta:
|
|
65
|
+
ue.trigger({ delta: k, elapsed: j, clock: C }), le.trigger({ delta: k, elapsed: j, clock: C }), $.trigger({ delta: k, elapsed: j, clock: C });
|
|
66
66
|
},
|
|
67
67
|
{ immediate: !1 }
|
|
68
68
|
);
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
$.on(() => {
|
|
70
|
+
k = C.getDelta(), j = C.getElapsedTime();
|
|
71
71
|
});
|
|
72
|
-
function
|
|
72
|
+
function N() {
|
|
73
73
|
return {
|
|
74
74
|
onBeforeLoop: ue.on,
|
|
75
75
|
onLoop: le.on,
|
|
76
|
-
onAfterLoop:
|
|
77
|
-
pause:
|
|
78
|
-
resume:
|
|
79
|
-
isActive:
|
|
76
|
+
onAfterLoop: $.on,
|
|
77
|
+
pause: Ke,
|
|
78
|
+
resume: Xe,
|
|
79
|
+
isActive: Ye
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function Qe(e) {
|
|
83
83
|
return e instanceof W ? e : Array.isArray(e) ? new W(...e) : new W(e);
|
|
84
84
|
}
|
|
85
|
-
const
|
|
85
|
+
const I = {
|
|
86
86
|
realistic: {
|
|
87
|
-
outputEncoding:
|
|
87
|
+
outputEncoding: Oe,
|
|
88
88
|
toneMapping: ke,
|
|
89
89
|
toneMappingExposure: 3,
|
|
90
90
|
shadowMap: {
|
|
@@ -96,18 +96,18 @@ const B = {
|
|
|
96
96
|
for (const r of Object.keys(t))
|
|
97
97
|
t[r] instanceof Object && Object.assign(t[r], fe(e[r], t[r]));
|
|
98
98
|
return Object.assign(e || {}, t), e;
|
|
99
|
-
},
|
|
100
|
-
function
|
|
99
|
+
}, Ze = "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", et = /* @__PURE__ */ tt(Ze);
|
|
100
|
+
function R(e) {
|
|
101
101
|
return e.replace(/-([a-z])/g, (t, r) => r.toUpperCase());
|
|
102
102
|
}
|
|
103
|
-
function
|
|
103
|
+
function tt(e, t) {
|
|
104
104
|
const r = /* @__PURE__ */ Object.create(null), o = e.split(",");
|
|
105
105
|
for (let n = 0; n < o.length; n++)
|
|
106
106
|
r[o[n]] = !0;
|
|
107
107
|
return t ? (n) => !!r[n.toLowerCase()] : (n) => !!r[n];
|
|
108
108
|
}
|
|
109
|
-
const
|
|
110
|
-
function
|
|
109
|
+
const f = ne(), H = M(!1);
|
|
110
|
+
function nt(e, t, r) {
|
|
111
111
|
const {
|
|
112
112
|
alpha: o = !0,
|
|
113
113
|
antialias: n = !0,
|
|
@@ -116,35 +116,35 @@ function tt(e, t, r) {
|
|
|
116
116
|
failIfMajorPerformanceCaveat: a,
|
|
117
117
|
precision: s,
|
|
118
118
|
premultipliedAlpha: l,
|
|
119
|
-
stencil:
|
|
120
|
-
shadows:
|
|
121
|
-
shadowMapType:
|
|
122
|
-
physicallyCorrectLights:
|
|
119
|
+
stencil: p,
|
|
120
|
+
shadows: m = !1,
|
|
121
|
+
shadowMapType: d = Be,
|
|
122
|
+
physicallyCorrectLights: w = !1,
|
|
123
123
|
useLegacyLights: v = !1,
|
|
124
|
-
outputEncoding:
|
|
125
|
-
toneMapping:
|
|
126
|
-
toneMappingExposure:
|
|
124
|
+
outputEncoding: g = Y,
|
|
125
|
+
toneMapping: E = Q,
|
|
126
|
+
toneMappingExposure: x = 1,
|
|
127
127
|
context: de = void 0,
|
|
128
128
|
powerPreference: ve = "default",
|
|
129
129
|
preserveDrawingBuffer: ge = !1,
|
|
130
|
-
clearColor:
|
|
130
|
+
clearColor: b,
|
|
131
131
|
windowSize: we = !1,
|
|
132
132
|
preset: he = void 0
|
|
133
|
-
} = ae(r), { setState: D } =
|
|
134
|
-
|
|
133
|
+
} = ae(r), { setState: D } = L(), { width: V, height: q } = u(we) ? Ue() : $e(t), { logError: ye } = B(), { pixelRatio: J } = Ne(), { pause: Me, resume: be } = N(), F = re(() => V.value / q.value), K = () => {
|
|
134
|
+
f.value && (f.value.setSize(V.value, q.value), f.value.setPixelRatio(Math.min(J.value, 2)));
|
|
135
135
|
}, X = () => {
|
|
136
|
-
if (!
|
|
136
|
+
if (!f.value)
|
|
137
137
|
return;
|
|
138
|
-
const
|
|
139
|
-
if (
|
|
140
|
-
|
|
138
|
+
const h = u(he);
|
|
139
|
+
if (h) {
|
|
140
|
+
h in I || ye("Renderer Preset must be one of these: " + Object.keys(I).join(", ")), fe(f.value, I[h]);
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
|
-
|
|
144
|
-
},
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
canvas:
|
|
143
|
+
f.value.shadowMap.enabled = u(m), f.value.shadowMap.type = u(d), f.value.toneMapping = u(E) || Q, f.value.toneMappingExposure = u(x), f.value.outputEncoding = u(g) || Y, b != null && b.value && f.value.setClearColor(Qe(u(b))), f.value.useLegacyLights = u(v);
|
|
144
|
+
}, Ce = () => {
|
|
145
|
+
const h = z(e);
|
|
146
|
+
h && (f.value = new De({
|
|
147
|
+
canvas: h,
|
|
148
148
|
alpha: u(o),
|
|
149
149
|
antialias: u(n),
|
|
150
150
|
context: u(de),
|
|
@@ -153,55 +153,55 @@ function tt(e, t, r) {
|
|
|
153
153
|
logarithmicDepthBuffer: u(c),
|
|
154
154
|
powerPreference: u(ve),
|
|
155
155
|
precision: u(s),
|
|
156
|
-
stencil: u(
|
|
156
|
+
stencil: u(p),
|
|
157
157
|
preserveDrawingBuffer: u(ge),
|
|
158
158
|
premultipliedAlpha: u(l)
|
|
159
|
-
}), D("renderer",
|
|
159
|
+
}), D("renderer", f.value), D("clock", new ie()), D("aspectRatio", F), X(), K(), be(), 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
|
|
164
|
-
[
|
|
163
|
+
return O([F, J], K), O(
|
|
164
|
+
[m, d, g, v, E, x, b],
|
|
165
165
|
X
|
|
166
|
-
),
|
|
166
|
+
), O(
|
|
167
167
|
() => [e, t],
|
|
168
168
|
() => {
|
|
169
|
-
z(e) && z(t) &&
|
|
169
|
+
z(e) && z(t) && Ce();
|
|
170
170
|
},
|
|
171
171
|
{ immediate: !0, deep: !0 }
|
|
172
172
|
), {
|
|
173
|
-
renderer:
|
|
173
|
+
renderer: f,
|
|
174
174
|
isReady: H,
|
|
175
175
|
dispose: Le,
|
|
176
176
|
aspectRatio: F
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
179
|
const pe = (e) => !!e && e.constructor === Array;
|
|
180
|
-
function
|
|
180
|
+
function at(e) {
|
|
181
181
|
const t = { nodes: {}, materials: {} };
|
|
182
182
|
return e && e.traverse((r) => {
|
|
183
183
|
r.name && (t.nodes[r.name] = r), r.material && !t.materials[r.material.name] && (t.materials[r.material.name] = r.material);
|
|
184
184
|
}), t;
|
|
185
185
|
}
|
|
186
|
-
async function
|
|
187
|
-
const { logError: i } =
|
|
186
|
+
async function vt(e, t, r, o, n) {
|
|
187
|
+
const { logError: i } = B(), c = new e();
|
|
188
188
|
n && n(c), r && r(c);
|
|
189
189
|
const s = (Array.isArray(t) ? t : [t]).map(
|
|
190
|
-
(l) => new Promise((
|
|
190
|
+
(l) => new Promise((p, m) => {
|
|
191
191
|
c.load(
|
|
192
192
|
l,
|
|
193
|
-
(
|
|
194
|
-
|
|
193
|
+
(d) => {
|
|
194
|
+
d.scene && Object.assign(d, at(d.scene)), p(d);
|
|
195
195
|
},
|
|
196
196
|
o,
|
|
197
|
-
(
|
|
197
|
+
(d) => m(i("[useLoader] - Failed to load resource", d))
|
|
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
|
|
203
|
+
async function gt(e) {
|
|
204
|
+
const t = new Fe(), r = new _e(t), o = (n) => new Promise((i, c) => {
|
|
205
205
|
r.load(
|
|
206
206
|
n,
|
|
207
207
|
(a) => i(a),
|
|
@@ -226,39 +226,39 @@ async function vt(e) {
|
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
-
const
|
|
229
|
+
const S = Pe({
|
|
230
230
|
camera: void 0,
|
|
231
231
|
cameras: [],
|
|
232
232
|
aspectRatio: re(() => window.innerWidth / window.innerHeight)
|
|
233
233
|
});
|
|
234
|
-
function
|
|
234
|
+
function L() {
|
|
235
235
|
function e(r) {
|
|
236
|
-
return
|
|
236
|
+
return S[r];
|
|
237
237
|
}
|
|
238
238
|
function t(r, o) {
|
|
239
|
-
|
|
239
|
+
S[r] = o;
|
|
240
240
|
}
|
|
241
241
|
return {
|
|
242
|
-
state:
|
|
243
|
-
...ae(
|
|
242
|
+
state: S,
|
|
243
|
+
...ae(S),
|
|
244
244
|
getState: e,
|
|
245
245
|
setState: t
|
|
246
246
|
};
|
|
247
247
|
}
|
|
248
|
-
const ee = ne(new
|
|
248
|
+
const ee = ne(new We()), T = M(new ze()), rt = M(null);
|
|
249
249
|
function me() {
|
|
250
|
-
const { setState: e } =
|
|
251
|
-
e("raycaster", ee.value), e("pointer",
|
|
250
|
+
const { setState: e } = L();
|
|
251
|
+
e("raycaster", ee.value), e("pointer", T), e("currentInstance", rt);
|
|
252
252
|
function t(r) {
|
|
253
|
-
|
|
253
|
+
T.value.x = r.clientX / window.innerWidth * 2 - 1, T.value.y = -(r.clientY / window.innerHeight) * 2 + 1;
|
|
254
254
|
}
|
|
255
255
|
return window.addEventListener("pointermove", t), {
|
|
256
256
|
raycaster: ee,
|
|
257
|
-
pointer:
|
|
257
|
+
pointer: T
|
|
258
258
|
};
|
|
259
259
|
}
|
|
260
|
-
const
|
|
261
|
-
function
|
|
260
|
+
const wt = !0, te = "[TresJS ▲ ■ ●] ";
|
|
261
|
+
function B() {
|
|
262
262
|
function e(o, n) {
|
|
263
263
|
console.error(`${te} ${o}`, n || "");
|
|
264
264
|
}
|
|
@@ -273,21 +273,21 @@ function j() {
|
|
|
273
273
|
logMessage: r
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
|
-
const { logWarning:
|
|
277
|
-
function
|
|
276
|
+
const { logWarning: ot } = B();
|
|
277
|
+
function it(e) {
|
|
278
278
|
for (const t in e)
|
|
279
279
|
if (t.indexOf("on") === 0)
|
|
280
280
|
return !0;
|
|
281
281
|
return !1;
|
|
282
282
|
}
|
|
283
|
-
let
|
|
284
|
-
const
|
|
283
|
+
let A = null;
|
|
284
|
+
const st = {
|
|
285
285
|
createElement(e, t, r, o) {
|
|
286
|
-
if (e === "template" ||
|
|
286
|
+
if (e === "template" || et(e))
|
|
287
287
|
return null;
|
|
288
288
|
let n;
|
|
289
289
|
if (o === null && (o = {}), o != null && o.args ? n = new G.value[e.replace("Tres", "")](...o.args) : n = new G.value[e.replace("Tres", "")](), n.isCamera) {
|
|
290
|
-
(!(o != null && o.position) || o != null && o.position.every((c) => c == 0)) &&
|
|
290
|
+
(!(o != null && o.position) || o != null && o.position.every((c) => c == 0)) && ot(
|
|
291
291
|
// eslint-disable-next-line max-len
|
|
292
292
|
"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
293
|
);
|
|
@@ -297,21 +297,21 @@ const it = {
|
|
|
297
297
|
return (o == null ? void 0 : o.attach) === void 0 && (n.isMaterial ? n.attach = "material" : n.isBufferGeometry && (n.attach = "geometry")), n;
|
|
298
298
|
},
|
|
299
299
|
insert(e, t, r) {
|
|
300
|
-
if (
|
|
300
|
+
if (A === null && t.isScene && (A = t), t === null && (t = A), t != null && t.isObject3D && (e != null && e.isObject3D)) {
|
|
301
301
|
const a = r ? t.children.indexOf(r) : 0;
|
|
302
302
|
e.parent = t, t.children.splice(a, 0, e), e.dispatchEvent({ type: "added" });
|
|
303
303
|
} else
|
|
304
304
|
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: o } =
|
|
305
|
+
const { onLoop: o } = N();
|
|
306
306
|
let n = null, i = null;
|
|
307
307
|
const { raycaster: c } = me();
|
|
308
|
-
e && e instanceof Ie &&
|
|
308
|
+
e && e instanceof Ie && it(e) && (o(() => {
|
|
309
309
|
var a, s, l;
|
|
310
310
|
if (t != null && t.children && e && c) {
|
|
311
|
-
const
|
|
312
|
-
|
|
311
|
+
const p = c.value.intersectObjects(t.children);
|
|
312
|
+
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
313
|
}
|
|
314
|
-
}),
|
|
314
|
+
}), Ve(window, "click", () => {
|
|
315
315
|
var a;
|
|
316
316
|
i !== null && ((a = e.onClick) == null || a.call(e, i));
|
|
317
317
|
}));
|
|
@@ -325,11 +325,14 @@ const it = {
|
|
|
325
325
|
patchProp(e, t, r, o) {
|
|
326
326
|
if (e) {
|
|
327
327
|
let n = e, i = t;
|
|
328
|
-
const c =
|
|
328
|
+
const c = R(i);
|
|
329
329
|
let a = n == null ? void 0 : n[c];
|
|
330
|
-
if (e.parent || (e.parent =
|
|
330
|
+
if (e.parent || (e.parent = A), n.type === "BufferGeometry" && (i = i.split("-").pop(), n.setAttribute(
|
|
331
|
+
R(i),
|
|
332
|
+
new He(...o)
|
|
333
|
+
)), i.includes("-") && a === void 0) {
|
|
331
334
|
const l = i.split("-");
|
|
332
|
-
a = l.reduce((
|
|
335
|
+
a = l.reduce((p, m) => p[R(m)], n), i = l.pop(), a != null && a.set || (n = l.reduce((p, m) => p[R(m)], n));
|
|
333
336
|
}
|
|
334
337
|
let s = o;
|
|
335
338
|
if (s === "" && (s = !0), Z(a))
|
|
@@ -349,15 +352,15 @@ const it = {
|
|
|
349
352
|
setScopeId: () => void 0,
|
|
350
353
|
cloneNode: () => void 0,
|
|
351
354
|
insertStaticContent: () => void 0
|
|
352
|
-
}, { createApp:
|
|
353
|
-
const t =
|
|
355
|
+
}, { createApp: ct } = Re(st), ut = (e) => {
|
|
356
|
+
const t = ct(r);
|
|
354
357
|
function r() {
|
|
355
358
|
return e && e.default ? e.default() : [];
|
|
356
359
|
}
|
|
357
360
|
return t;
|
|
358
361
|
};
|
|
359
362
|
se(oe);
|
|
360
|
-
const { logWarning:
|
|
363
|
+
const { logWarning: lt } = B(), ft = Se({
|
|
361
364
|
name: "TresCanvas",
|
|
362
365
|
props: [
|
|
363
366
|
"shadows",
|
|
@@ -375,24 +378,25 @@ const { logWarning: ut } = j(), lt = Se({
|
|
|
375
378
|
"preset"
|
|
376
379
|
],
|
|
377
380
|
setup(e, { slots: t, expose: r }) {
|
|
378
|
-
e.physicallyCorrectLights === !0 &&
|
|
379
|
-
const o =
|
|
380
|
-
|
|
381
|
-
|
|
381
|
+
e.physicallyCorrectLights === !0 && lt("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
|
|
382
|
+
const o = M(), n = M(), i = new oe.Scene(), { setState: c } = L();
|
|
383
|
+
c("scene", i);
|
|
384
|
+
function a() {
|
|
385
|
+
const { renderer: p } = nt(n, o, e), { activeCamera: m } = ce(), { onLoop: d } = N(), { raycaster: w, pointer: v } = me();
|
|
382
386
|
d(() => {
|
|
383
|
-
var
|
|
384
|
-
|
|
387
|
+
var g;
|
|
388
|
+
m.value && (w.value.setFromCamera(v.value, m.value), (g = p.value) == null || g.render(i, m.value));
|
|
385
389
|
});
|
|
386
390
|
}
|
|
387
|
-
|
|
388
|
-
let
|
|
389
|
-
function
|
|
390
|
-
|
|
391
|
+
O(n, a);
|
|
392
|
+
let s;
|
|
393
|
+
function l() {
|
|
394
|
+
s = ut(t), s.provide("useTres", L()), s.provide("extend", se), s.mount(i);
|
|
391
395
|
}
|
|
392
|
-
return
|
|
396
|
+
return l(), r({
|
|
393
397
|
scene: i
|
|
394
|
-
}), () =>
|
|
395
|
-
|
|
398
|
+
}), () => P(
|
|
399
|
+
P(
|
|
396
400
|
"div",
|
|
397
401
|
{
|
|
398
402
|
ref: o,
|
|
@@ -405,7 +409,7 @@ const { logWarning: ut } = j(), lt = Se({
|
|
|
405
409
|
}
|
|
406
410
|
},
|
|
407
411
|
[
|
|
408
|
-
|
|
412
|
+
P(
|
|
409
413
|
"div",
|
|
410
414
|
{
|
|
411
415
|
style: {
|
|
@@ -414,7 +418,7 @@ const { logWarning: ut } = j(), lt = Se({
|
|
|
414
418
|
}
|
|
415
419
|
},
|
|
416
420
|
[
|
|
417
|
-
|
|
421
|
+
P("canvas", {
|
|
418
422
|
ref: n,
|
|
419
423
|
style: {
|
|
420
424
|
display: "block",
|
|
@@ -431,25 +435,25 @@ const { logWarning: ut } = j(), lt = Se({
|
|
|
431
435
|
)
|
|
432
436
|
);
|
|
433
437
|
}
|
|
434
|
-
}),
|
|
438
|
+
}), ht = {
|
|
435
439
|
install(e) {
|
|
436
|
-
e.component("TresCanvas",
|
|
440
|
+
e.component("TresCanvas", ft);
|
|
437
441
|
}
|
|
438
442
|
};
|
|
439
443
|
export {
|
|
440
|
-
|
|
441
|
-
|
|
444
|
+
qe as CameraType,
|
|
445
|
+
ft as TresCanvas,
|
|
442
446
|
G as catalogue,
|
|
443
|
-
|
|
447
|
+
ht as default,
|
|
444
448
|
se as extend,
|
|
445
|
-
|
|
446
|
-
|
|
449
|
+
wt as isProd,
|
|
450
|
+
at as trasverseObjects,
|
|
447
451
|
ce as useCamera,
|
|
448
|
-
|
|
449
|
-
|
|
452
|
+
vt as useLoader,
|
|
453
|
+
B as useLogger,
|
|
450
454
|
me as useRaycaster,
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
+
N as useRenderLoop,
|
|
456
|
+
nt as useRenderer,
|
|
457
|
+
gt as useTexture,
|
|
458
|
+
L as useTres
|
|
455
459
|
};
|
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.2
|
|
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(f,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],u):(f=typeof globalThis<"u"?globalThis:f||self,u(f.tres={},f.Vue,f.Three,f.VueUseCore))})(this,function(f,u,c,s){"use strict";function se(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const $=se(c),O=u.ref({uuid:c.MathUtils.generateUUID()}),z=e=>void Object.assign(O.value,e);var J=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(J||{});const ue=45;let y;function R(){const{state:e,setState:t,aspectRatio:r}=L();function o(a="Perspective",l){var m,v,w;if(a==="Perspective"){const{near:g,far:C,fov:h}=l||{near:.1,far:1e3,fov:ue};y=new c.PerspectiveCamera(h,((m=e.aspectRatio)==null?void 0:m.value)||window.innerWidth/window.innerHeight,g,C),(v=e.cameras)==null||v.push(y)}else{const{left:g,right:C,top:h,bottom:T,near:D,far:F}=l||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};y=new c.OrthographicCamera(g,C,h,T,D,F),(w=e.cameras)==null||w.push(y)}return e.camera=y,t("camera",e.camera),y}function n(){var a;e.camera instanceof c.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(a=e.camera)==null||a.updateProjectionMatrix()}function i(a){var l;(l=e.cameras)==null||l.push(a),a instanceof c.PerspectiveCamera&&e.aspectRatio&&(a.aspect=e.aspectRatio.value),a.updateProjectionMatrix(),t("camera",a)}function p(){e.cameras=[]}return u.watchEffect(()=>{r!=null&&r.value&&n()}),{activeCamera:u.toRef(e,"camera"),createCamera:o,updateCamera:n,pushCamera:i,clearCameras:p}}const K=s.createEventHook(),X=s.createEventHook(),W=s.createEventHook(),b=new c.Clock;let U=0,k=0;const{pause:le,resume:ce,isActive:fe}=s.useRafFn(()=>{K.trigger({delta:U,elapsed:k,clock:b}),X.trigger({delta:U,elapsed:k,clock:b}),W.trigger({delta:U,elapsed:k,clock:b})},{immediate:!1});W.on(()=>{U=b.getDelta(),k=b.getElapsedTime()});function j(){return{onBeforeLoop:K.on,onLoop:X.on,onAfterLoop:W.on,pause:le,resume:ce,isActive:fe}}function pe(e){return e instanceof c.Color?e:Array.isArray(e)?new c.Color(...e):new c.Color(e)}const B={realistic:{outputEncoding:c.sRGBEncoding,toneMapping:c.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:c.PCFSoftShadowMap}}},Y=(e,t)=>{for(const r of Object.keys(t))t[r]instanceof Object&&Object.assign(t[r],Y(e[r],t[r]));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 I(e){return e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase())}function me(e,t){const r=Object.create(null),o=e.split(",");for(let n=0;n<o.length;n++)r[o[n]]=!0;return t?n=>!!r[n.toLowerCase()]:n=>!!r[n]}const d=u.shallowRef(),V=u.ref(!1);function Q(e,t,r){const{alpha:o=!0,antialias:n=!0,depth:i,logarithmicDepthBuffer:p,failIfMajorPerformanceCaveat:a,precision:l,premultipliedAlpha:m,stencil:v,shadows:w=!1,shadowMapType:g=c.PCFShadowMap,physicallyCorrectLights:C=!1,useLegacyLights:h=!1,outputEncoding:T=c.LinearEncoding,toneMapping:D=c.NoToneMapping,toneMappingExposure:F=1,context:Oe=void 0,powerPreference:Ue="default",preserveDrawingBuffer:ke=!1,clearColor:S,windowSize:je=!1,preset:xe=void 0}=u.toRefs(r),{setState:G}=L(),{width:ne,height:ae}=s.resolveUnref(je)?s.useWindowSize():s.useElementSize(t),{logError:Ae}=P(),{pixelRatio:re}=s.useDevicePixelRatio(),{pause:_e,resume:Te}=j(),N=u.computed(()=>ne.value/ae.value),oe=()=>{d.value&&(d.value.setSize(ne.value,ae.value),d.value.setPixelRatio(Math.min(re.value,2)))},ie=()=>{if(!d.value)return;const M=s.resolveUnref(xe);if(M){M in B||Ae("Renderer Preset must be one of these: "+Object.keys(B).join(", ")),Y(d.value,B[M]);return}d.value.shadowMap.enabled=s.resolveUnref(w),d.value.shadowMap.type=s.resolveUnref(g),d.value.toneMapping=s.resolveUnref(D)||c.NoToneMapping,d.value.toneMappingExposure=s.resolveUnref(F),d.value.outputEncoding=s.resolveUnref(T)||c.LinearEncoding,S!=null&&S.value&&d.value.setClearColor(pe(s.resolveUnref(S))),d.value.useLegacyLights=s.resolveUnref(h)},De=()=>{const M=s.unrefElement(e);M&&(d.value=new c.WebGLRenderer({canvas:M,alpha:s.resolveUnref(o),antialias:s.resolveUnref(n),context:s.resolveUnref(Oe),depth:s.resolveUnref(i),failIfMajorPerformanceCaveat:s.resolveUnref(a),logarithmicDepthBuffer:s.resolveUnref(p),powerPreference:s.resolveUnref(Ue),precision:s.resolveUnref(l),stencil:s.resolveUnref(v),preserveDrawingBuffer:s.resolveUnref(ke),premultipliedAlpha:s.resolveUnref(m)}),G("renderer",d.value),G("clock",new c.Clock),G("aspectRatio",N),ie(),oe(),Te(),V.value=!0)},Fe=()=>{d.value&&(d.value.dispose(),d.value=void 0,V.value=!1,_e())};return u.watch([N,re],oe),u.watch([w,g,T,h,D,F,S],ie),u.watch(()=>[e,t],()=>{s.unrefElement(e)&&s.unrefElement(t)&&De()},{immediate:!0,deep:!0}),{renderer:d,isReady:V,dispose:Fe,aspectRatio:N}}const Z=e=>!!e&&e.constructor===Array;function E(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 ve(e,t,r,o,n){const{logError:i}=P(),p=new e;n&&n(p),r&&r(p);const l=(Array.isArray(t)?t:[t]).map(m=>new Promise((v,w)=>{p.load(m,g=>{g.scene&&Object.assign(g,E(g.scene)),v(g)},o,g=>w(i("[useLoader] - Failed to load resource",g)))}));return Z(t)?await Promise.all(l):await l[0]}async function ge(e){const t=new c.LoadingManager,r=new c.TextureLoader(t),o=n=>new Promise((i,p)=>{r.load(n,a=>i(a),()=>null,()=>{p(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:p,roughnessMap:a,metalnessMap:l,aoMap:m}=e;return{map:n?await o(n):null,displacementMap:i?await o(i):null,normalMap:p?await o(p):null,roughnessMap:a?await o(a):null,metalnessMap:l?await o(l):null,aoMap:m?await o(m):null}}}const x=u.shallowReactive({camera:void 0,cameras:[],aspectRatio:u.computed(()=>window.innerWidth/window.innerHeight)});function L(){function e(r){return x[r]}function t(r,o){x[r]=o}return{state:x,...u.toRefs(x),getState:e,setState:t}}const H=u.shallowRef(new c.Raycaster),A=u.ref(new c.Vector2),we=u.ref(null);function q(){const{setState:e}=L();e("raycaster",H.value),e("pointer",A),e("currentInstance",we);function t(r){A.value.x=r.clientX/window.innerWidth*2-1,A.value.y=-(r.clientY/window.innerHeight)*2+1}return window.addEventListener("pointermove",t),{raycaster:H,pointer:A}}const he=!0,ee="[TresJS ▲ ■ ●] ";function P(){function e(o,n){console.error(`${ee} ${o}`,n||"")}function t(o){console.warn(`${ee} ${o}`)}function r(o,n){}return{logError:e,logWarning:t,logMessage:r}}const{logWarning:ye}=P();function Ce(e){for(const t in e)if(t.indexOf("on")===0)return!0;return!1}function Re(e){}let _=null;const Me={createElement(e,t,r,o){if(e==="template"||de(e))return null;let n;if(o===null&&(o={}),o!=null&&o.args?n=new O.value[e.replace("Tres","")](...o.args):n=new O.value[e.replace("Tres","")],n.isCamera){(!(o!=null&&o.position)||o!=null&&o.position.every(p=>p==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}=R();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,r){if(_===null&&t.isScene&&(_=t),t===null&&(t=_),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));const{onLoop:o}=j();let n=null,i=null;const{raycaster:p}=q();e&&e instanceof c.Mesh&&Ce(e)&&(o(()=>{var a,l,m;if(t!=null&&t.children&&e&&p){const v=p.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))&&((a=e.onPointerEnter)==null||a.call(e,i)),(l=e.onPointerMove)==null||l.call(e,i)):(i=null,n!==null&&((m=e.onPointerLeave)==null||m.call(e,n))),n=i}}),s.useEventListener(window,"click",()=>{var a;i!==null&&((a=e.onClick)==null||a.call(e,i))}))},remove(e){if(!e)return;const t=e.parentNode;t&&t.removeChild(e)},patchProp(e,t,r,o){if(e){let n=e,i=t;const p=I(i);let a=n==null?void 0:n[p];if(e.parent||(e.parent=_),i.includes("-")&&a===void 0){const m=i.split("-");a=m.reduce((v,w)=>v[I(w)],n),i=m.pop(),a!=null&&a.set||(n=m.reduce((v,w)=>v[I(w)],n))}let l=o;if(l===""&&(l=!0),s.isFunction(a))return;!(a!=null&&a.set)&&!s.isFunction(a)?n[p]=l:a.constructor===l.constructor&&(a!=null&&a.copy)?a==null||a.copy(l):Array.isArray(l)?a.set(...l):!a.isColor&&a.setScalar?a.setScalar(l):a.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:be}=u.createRenderer(Me),Le=e=>{const t=be(r);function r(){return e&&e.default?e.default():[]}return t};z($);const{logWarning:Pe}=P(),te=u.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t,expose:r}){e.physicallyCorrectLights===!0&&Pe("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const o=u.ref(),n=u.ref(),i=new $.Scene;function p(){const{renderer:m}=Q(n,o,e),{activeCamera:v}=R(),{onLoop:w}=j(),{raycaster:g,pointer:C}=q();w(()=>{var h;v.value&&(g.value.setFromCamera(C.value,v.value),(h=m.value)==null||h.render(i,v.value))})}u.watch(n,p);let a;function l(){a=Le(t),a.provide("useTres",L()),a.provide("extend",z),a.mount(i)}return l(),r({scene:i}),()=>u.h(u.h("div",{ref:o,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[u.h("div",{style:{width:"100%",height:"100%"}},[u.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)}};f.CameraType=J,f.TresCanvas=te,f.catalogue=O,f.default=Se,f.extend=z,f.isProd=he,f.trasverseObjects=E,f.useCamera=R,f.useLoader=ve,f.useLogger=P,f.useRaycaster=q,f.useRenderLoop=j,f.useRenderer=Q,f.useTexture=ge,f.useTres=L,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
8
|
+
(function(f,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):(f=typeof globalThis<"u"?globalThis:f||self,l(f.tres={},f.Vue,f.Three,f.VueUseCore))})(this,function(f,l,c,s){"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",u){var d,v,g;if(r==="Perspective"){const{near:w,far:b,fov:h}=u||{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}=u||{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 u;(u=e.cameras)==null||u.push(r),r instanceof c.PerspectiveCamera&&e.aspectRatio&&(r.aspect=e.aspectRatio.value),r.updateProjectionMatrix(),t("camera",r)}function p(){e.cameras=[]}return l.watchEffect(()=>{a!=null&&a.value&&n()}),{activeCamera:l.toRef(e,"camera"),createCamera:o,updateCamera:n,pushCamera:i,clearCameras:p}}const K=s.createEventHook(),X=s.createEventHook(),I=s.createEventHook(),P=new c.Clock;let k=0,A=0;const{pause:le,resume:ce,isActive:fe}=s.useRafFn(()=>{K.trigger({delta:k,elapsed:A,clock:P}),X.trigger({delta:k,elapsed:A,clock:P}),I.trigger({delta:k,elapsed:A,clock:P})},{immediate:!1});I.on(()=>{k=P.getDelta(),A=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:p,failIfMajorPerformanceCaveat:r,precision:u,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:ke=!1,clearColor:O,windowSize:Ae=!1,preset:je=void 0}=l.toRefs(a),{setState:N}=M(),{width:ne,height:ae}=s.resolveUnref(Ae)?s.useWindowSize():s.useElementSize(t),{logError:xe}=S(),{pixelRatio:re}=s.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=s.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=s.resolveUnref(g),m.value.shadowMap.type=s.resolveUnref(w),m.value.toneMapping=s.resolveUnref(F)||c.NoToneMapping,m.value.toneMappingExposure=s.resolveUnref(B),m.value.outputEncoding=s.resolveUnref(y)||c.LinearEncoding,O!=null&&O.value&&m.value.setClearColor(pe(s.resolveUnref(O))),m.value.useLegacyLights=s.resolveUnref(h)},De=()=>{const L=s.unrefElement(e);L&&(m.value=new c.WebGLRenderer({canvas:L,alpha:s.resolveUnref(o),antialias:s.resolveUnref(n),context:s.resolveUnref(Oe),depth:s.resolveUnref(i),failIfMajorPerformanceCaveat:s.resolveUnref(r),logarithmicDepthBuffer:s.resolveUnref(p),powerPreference:s.resolveUnref(Ue),precision:s.resolveUnref(u),stencil:s.resolveUnref(v),preserveDrawingBuffer:s.resolveUnref(ke),premultipliedAlpha:s.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],()=>{s.unrefElement(e)&&s.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(),p=new e;n&&n(p),a&&a(p);const u=(Array.isArray(t)?t:[t]).map(d=>new Promise((v,g)=>{p.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(u):await u[0]}async function ge(e){const t=new c.LoadingManager,a=new c.TextureLoader(t),o=n=>new Promise((i,p)=>{a.load(n,r=>i(r),()=>null,()=>{p(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:p,roughnessMap:r,metalnessMap:u,aoMap:d}=e;return{map:n?await o(n):null,displacementMap:i?await o(i):null,normalMap:p?await o(p):null,roughnessMap:r?await o(r):null,metalnessMap:u?await o(u):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(p=>p==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:p}=q();e&&e instanceof c.Mesh&&Ce(e)&&(o(()=>{var r,u,d;if(t!=null&&t.children&&e&&p){const v=p.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)),(u=e.onPointerMove)==null||u.call(e,i)):(i=null,n!==null&&((d=e.onPointerLeave)==null||d.call(e,n))),n=i}}),s.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 p=x(i);let r=n==null?void 0:n[p];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 u=o;if(u===""&&(u=!0),s.isFunction(r))return;!(r!=null&&r.set)&&!s.isFunction(r)?n[p]=u:r.constructor===u.constructor&&(r!=null&&r.copy)?r==null||r.copy(u):Array.isArray(u)?r.set(...u):!r.isColor&&r.setScalar?r.setScalar(u):r.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: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:p}=M();p("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 u;function d(){u=Le(t),u.provide("useTres",M()),u.provide("extend",z),u.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)}};f.CameraType=J,f.TresCanvas=te,f.catalogue=U,f.default=Se,f.extend=z,f.isProd=he,f.trasverseObjects=E,f.useCamera=W,f.useLoader=ve,f.useLogger=S,f.useRaycaster=q,f.useRenderLoop=j,f.useRenderer=Q,f.useTexture=ge,f.useTres=M,Object.defineProperties(f,{__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.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
7
7
|
"files": [
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"dev": "vite",
|
|
41
41
|
"build": "vite build",
|
|
42
42
|
"preview": "vite preview",
|
|
43
|
+
"playground": "cd playground && nr dev",
|
|
43
44
|
"test": "vitest",
|
|
44
45
|
"test:ci": "vitest run",
|
|
45
46
|
"test:ui": "vitest --ui",
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
"@alvarosabu/prettier-config": "^1.2.0",
|
|
63
64
|
"@release-it/conventional-changelog": "^5.1.1",
|
|
64
65
|
"@stackblitz/sdk": "^1.8.1",
|
|
65
|
-
"@tresjs/cientos": "
|
|
66
|
+
"@tresjs/cientos": "2.0.0-alpha.1",
|
|
66
67
|
"@types/three": "latest",
|
|
67
68
|
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
68
69
|
"@typescript-eslint/parser": "^5.42.0",
|