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