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