@tresjs/core 2.0.0-alpha.4 → 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/index.d.ts +1 -0
- package/dist/composables/useRenderer/const.d.ts +3 -3
- package/dist/composables/useSeek/index.d.ts +17 -0
- package/dist/tres.js +245 -209
- 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
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seek composable return type
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @interface UseSeekReturn
|
|
6
|
+
*/
|
|
7
|
+
export interface UseSeekReturn {
|
|
8
|
+
seek: (parent: THREE.Scene | THREE.Object3D, property: string, value: string) => THREE.Object3D | null;
|
|
9
|
+
seekByName: (parent: THREE.Scene | THREE.Object3D, value: string) => THREE.Object3D | null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Composable that provides utilities to easily traverse and navigate through complex scenes and object children graphs
|
|
13
|
+
*
|
|
14
|
+
* @export
|
|
15
|
+
* @return {*} {UseSeekReturn}
|
|
16
|
+
*/
|
|
17
|
+
export declare function useSeek(): UseSeekReturn;
|
package/dist/tres.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v2.0.0-alpha.
|
|
3
|
+
* version: v2.0.0-alpha.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
|
|
12
|
-
const
|
|
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
|
|
17
|
-
const { state: e, setState: t, aspectRatio:
|
|
18
|
-
function
|
|
19
|
-
var l, p
|
|
16
|
+
function le() {
|
|
17
|
+
const { state: e, setState: t, aspectRatio: o } = L();
|
|
18
|
+
function r(a = "Perspective", s) {
|
|
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,287 +33,318 @@ function ce() {
|
|
|
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
|
-
function
|
|
48
|
+
function u() {
|
|
49
49
|
e.cameras = [];
|
|
50
50
|
}
|
|
51
|
-
return
|
|
52
|
-
|
|
51
|
+
return xe(() => {
|
|
52
|
+
o != null && o.value && n();
|
|
53
53
|
}), {
|
|
54
|
-
activeCamera:
|
|
55
|
-
createCamera:
|
|
54
|
+
activeCamera: Pe(e, "camera"),
|
|
55
|
+
createCamera: r,
|
|
56
56
|
updateCamera: n,
|
|
57
57
|
pushCamera: i,
|
|
58
|
-
clearCameras:
|
|
58
|
+
clearCameras: u
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
const
|
|
62
|
-
let
|
|
63
|
-
const { pause:
|
|
61
|
+
const fe = G(), pe = G(), N = G(), b = new ue();
|
|
62
|
+
let j = 0, B = 0;
|
|
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
|
);
|
|
69
69
|
N.on(() => {
|
|
70
|
-
|
|
70
|
+
j = b.getDelta(), B = b.getElapsedTime();
|
|
71
71
|
});
|
|
72
|
-
function
|
|
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
92
|
type: _e
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
},
|
|
96
|
-
for (const
|
|
97
|
-
t[
|
|
95
|
+
}, de = (e, t) => {
|
|
96
|
+
for (const o of Object.keys(t))
|
|
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
|
-
return e.replace(/-([a-z])/g, (t,
|
|
101
|
+
return e.replace(/-([a-z])/g, (t, o) => o.toUpperCase());
|
|
102
102
|
}
|
|
103
|
-
function
|
|
104
|
-
const
|
|
105
|
-
for (let n = 0; n <
|
|
106
|
-
r[
|
|
107
|
-
return t ? (n) => !!
|
|
103
|
+
function rt(e, t) {
|
|
104
|
+
const o = /* @__PURE__ */ Object.create(null), r = e.split(",");
|
|
105
|
+
for (let n = 0; n < r.length; n++)
|
|
106
|
+
o[r[n]] = !0;
|
|
107
|
+
return t ? (n) => !!o[n.toLowerCase()] : (n) => !!o[n];
|
|
108
108
|
}
|
|
109
|
-
const
|
|
110
|
-
function
|
|
109
|
+
const d = re(), H = M(!1);
|
|
110
|
+
function ot(e, t, o) {
|
|
111
|
+
var Q;
|
|
111
112
|
const {
|
|
112
|
-
alpha:
|
|
113
|
+
alpha: r = !0,
|
|
113
114
|
antialias: n = !0,
|
|
114
115
|
depth: i,
|
|
115
|
-
logarithmicDepthBuffer:
|
|
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:
|
|
125
|
+
outputEncoding: g = Z,
|
|
126
|
+
toneMapping: S = ee,
|
|
126
127
|
toneMappingExposure: x = 1,
|
|
127
|
-
context:
|
|
128
|
-
powerPreference:
|
|
129
|
-
preserveDrawingBuffer:
|
|
130
|
-
clearColor:
|
|
131
|
-
windowSize:
|
|
132
|
-
preset:
|
|
133
|
-
} =
|
|
134
|
-
|
|
128
|
+
context: ge = void 0,
|
|
129
|
+
powerPreference: we = "default",
|
|
130
|
+
preserveDrawingBuffer: he = !1,
|
|
131
|
+
clearColor: C,
|
|
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 =
|
|
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
|
-
alpha:
|
|
149
|
-
antialias:
|
|
150
|
-
context:
|
|
151
|
-
depth:
|
|
152
|
-
failIfMajorPerformanceCaveat:
|
|
153
|
-
logarithmicDepthBuffer: u
|
|
154
|
-
powerPreference:
|
|
155
|
-
precision:
|
|
156
|
-
stencil:
|
|
157
|
-
preserveDrawingBuffer:
|
|
158
|
-
premultipliedAlpha:
|
|
159
|
-
}),
|
|
160
|
-
},
|
|
161
|
-
|
|
152
|
+
alpha: c(r),
|
|
153
|
+
antialias: c(n),
|
|
154
|
+
context: c(ge),
|
|
155
|
+
depth: c(i),
|
|
156
|
+
failIfMajorPerformanceCaveat: c(a),
|
|
157
|
+
logarithmicDepthBuffer: c(u),
|
|
158
|
+
powerPreference: c(we),
|
|
159
|
+
precision: c(s),
|
|
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
|
-
return e && e.traverse((
|
|
183
|
-
|
|
186
|
+
return e && e.traverse((o) => {
|
|
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
|
|
187
|
-
const { logError: i } =
|
|
188
|
-
n && n(
|
|
190
|
+
async function yt(e, t, o, r, n) {
|
|
191
|
+
const { logError: i } = E(), u = new e();
|
|
192
|
+
n && n(u), o && o(u);
|
|
189
193
|
const s = (Array.isArray(t) ? t : [t]).map(
|
|
190
|
-
(
|
|
191
|
-
|
|
192
|
-
|
|
194
|
+
(f) => new Promise((l, p) => {
|
|
195
|
+
u.load(
|
|
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
|
-
|
|
197
|
-
(m) =>
|
|
200
|
+
r,
|
|
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
|
|
204
|
-
const t = new Fe(),
|
|
205
|
-
|
|
207
|
+
async function Mt(e) {
|
|
208
|
+
const t = new Fe(), o = new Ie(t), r = (n) => new Promise((i, u) => {
|
|
209
|
+
o.load(
|
|
206
210
|
n,
|
|
207
211
|
(a) => i(a),
|
|
208
212
|
() => null,
|
|
209
213
|
() => {
|
|
210
|
-
|
|
214
|
+
u(new Error("[useTextures] - Failed to load texture"));
|
|
211
215
|
}
|
|
212
216
|
);
|
|
213
217
|
});
|
|
214
|
-
if (
|
|
215
|
-
const n = await Promise.all(e.map((i) =>
|
|
218
|
+
if (me(e)) {
|
|
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
|
-
map: n ? await
|
|
221
|
-
displacementMap: i ? await
|
|
222
|
-
normalMap:
|
|
223
|
-
roughnessMap: a ? await
|
|
224
|
-
metalnessMap: s ? await
|
|
225
|
-
aoMap:
|
|
233
|
+
map: n ? await r(n) : null,
|
|
234
|
+
displacementMap: i ? await r(i) : null,
|
|
235
|
+
normalMap: u ? await r(u) : null,
|
|
236
|
+
roughnessMap: a ? await r(a) : null,
|
|
237
|
+
metalnessMap: s ? await r(s) : null,
|
|
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
|
-
function e(
|
|
238
|
-
return R[
|
|
252
|
+
function e(o) {
|
|
253
|
+
return R[o];
|
|
239
254
|
}
|
|
240
|
-
function t(
|
|
241
|
-
R[
|
|
255
|
+
function t(o, r) {
|
|
256
|
+
R[o] = r;
|
|
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",
|
|
254
|
-
function t(
|
|
255
|
-
|
|
268
|
+
e("raycaster", ne.value), e("pointer", k), e("currentInstance", ut);
|
|
269
|
+
function t(o) {
|
|
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
|
|
263
|
-
function
|
|
264
|
-
function e(
|
|
265
|
-
console.error(`${
|
|
277
|
+
const Ct = !0, ae = "[TresJS ▲ ■ ●] ";
|
|
278
|
+
function E() {
|
|
279
|
+
function e(r, n) {
|
|
280
|
+
console.error(`${ae} ${r}`, n || "");
|
|
266
281
|
}
|
|
267
|
-
function t(
|
|
268
|
-
console.warn(`${
|
|
282
|
+
function t(r) {
|
|
283
|
+
console.warn(`${ae} ${r}`);
|
|
269
284
|
}
|
|
270
|
-
function r
|
|
285
|
+
function o(r, n) {
|
|
271
286
|
}
|
|
272
287
|
return {
|
|
273
288
|
logError: e,
|
|
274
289
|
logWarning: t,
|
|
275
|
-
logMessage:
|
|
290
|
+
logMessage: o
|
|
276
291
|
};
|
|
277
292
|
}
|
|
278
|
-
|
|
279
|
-
|
|
293
|
+
function bt() {
|
|
294
|
+
const { logWarning: e } = E();
|
|
295
|
+
function t(r, n, i) {
|
|
296
|
+
let u = null;
|
|
297
|
+
return r.traverse((a) => {
|
|
298
|
+
a[n] === i && (u = a);
|
|
299
|
+
}), u || e(`Child with ${n} '${i}' not found.`), u;
|
|
300
|
+
}
|
|
301
|
+
function o(r, n) {
|
|
302
|
+
return t(r, "name", n);
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
seek: t,
|
|
306
|
+
seekByName: o
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
const { logWarning: ct } = E();
|
|
310
|
+
function lt(e) {
|
|
280
311
|
for (const t in e)
|
|
281
312
|
if (t.indexOf("on") === 0)
|
|
282
313
|
return !0;
|
|
283
314
|
return !1;
|
|
284
315
|
}
|
|
285
316
|
let A = null;
|
|
286
|
-
const
|
|
287
|
-
createElement(e, t,
|
|
288
|
-
if (e === "template" ||
|
|
317
|
+
const ft = {
|
|
318
|
+
createElement(e, t, o, r) {
|
|
319
|
+
if (e === "template" || at(e))
|
|
289
320
|
return null;
|
|
290
321
|
let n;
|
|
291
|
-
if (
|
|
292
|
-
(!(
|
|
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) {
|
|
323
|
+
(!(r != null && r.position) || r != null && r.position.every((u) => u == 0)) && ct(
|
|
293
324
|
// eslint-disable-next-line max-len
|
|
294
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 🤗"
|
|
295
326
|
);
|
|
296
|
-
const { pushCamera: i } =
|
|
327
|
+
const { pushCamera: i } = le();
|
|
297
328
|
i(n);
|
|
298
329
|
}
|
|
299
|
-
return (
|
|
330
|
+
return (r == null ? void 0 : r.attach) === void 0 && (n.isMaterial ? n.attach = "material" : n.isBufferGeometry && (n.attach = "geometry")), n;
|
|
300
331
|
},
|
|
301
|
-
insert(e, t,
|
|
332
|
+
insert(e, t, o) {
|
|
302
333
|
if (A === null && t.isScene && (A = t), t === null && (t = A), t != null && t.isObject3D && (e != null && e.isObject3D)) {
|
|
303
|
-
const a =
|
|
334
|
+
const a = o ? t.children.indexOf(o) : 0;
|
|
304
335
|
e.parent = t, t.children.splice(a, 0, e), e.dispatchEvent({ type: "added" });
|
|
305
336
|
} else
|
|
306
337
|
typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
|
|
307
|
-
const { onLoop:
|
|
338
|
+
const { onLoop: r } = U();
|
|
308
339
|
let n = null, i = null;
|
|
309
|
-
const { raycaster:
|
|
310
|
-
e && e instanceof
|
|
311
|
-
var a, s,
|
|
312
|
-
if (t != null && t.children && e &&
|
|
313
|
-
const
|
|
314
|
-
|
|
340
|
+
const { raycaster: u } = ve();
|
|
341
|
+
e && e instanceof Ge && lt(e) && (r(() => {
|
|
342
|
+
var a, s, f;
|
|
343
|
+
if (t != null && t.children && e && u) {
|
|
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;
|
|
315
346
|
}
|
|
316
|
-
}),
|
|
347
|
+
}), Je(window, "click", () => {
|
|
317
348
|
var a;
|
|
318
349
|
i !== null && ((a = e.onClick) == null || a.call(e, i));
|
|
319
350
|
}));
|
|
@@ -324,24 +355,28 @@ const ut = {
|
|
|
324
355
|
const t = e.parentNode;
|
|
325
356
|
t && t.removeChild(e);
|
|
326
357
|
},
|
|
327
|
-
patchProp(e, t,
|
|
358
|
+
patchProp(e, t, o, r) {
|
|
328
359
|
if (e) {
|
|
329
360
|
let n = e, i = t;
|
|
330
|
-
const
|
|
331
|
-
let a = n == null ? void 0 : n[
|
|
332
|
-
if (e.parent || (e.parent = A), n.type === "BufferGeometry"
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
361
|
+
const u = T(i);
|
|
362
|
+
let a = n == null ? void 0 : n[u];
|
|
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));
|
|
338
373
|
}
|
|
339
|
-
let s =
|
|
340
|
-
if (s === "" && (s = !0),
|
|
341
|
-
Array.isArray(s) ? e[
|
|
374
|
+
let s = r;
|
|
375
|
+
if (s === "" && (s = !0), te(a)) {
|
|
376
|
+
Array.isArray(s) ? e[u](...s) : e[u](s);
|
|
342
377
|
return;
|
|
343
378
|
}
|
|
344
|
-
!(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);
|
|
345
380
|
}
|
|
346
381
|
},
|
|
347
382
|
parentNode(e) {
|
|
@@ -356,15 +391,15 @@ const ut = {
|
|
|
356
391
|
setScopeId: () => void 0,
|
|
357
392
|
cloneNode: () => void 0,
|
|
358
393
|
insertStaticContent: () => void 0
|
|
359
|
-
}, { createApp:
|
|
360
|
-
const t =
|
|
361
|
-
function
|
|
394
|
+
}, { createApp: pt } = Re(ft), dt = (e) => {
|
|
395
|
+
const t = pt(o);
|
|
396
|
+
function o() {
|
|
362
397
|
return e && e.default ? e.default() : [];
|
|
363
398
|
}
|
|
364
399
|
return t;
|
|
365
400
|
};
|
|
366
|
-
se
|
|
367
|
-
const { logWarning:
|
|
401
|
+
ce(se);
|
|
402
|
+
const { logWarning: mt } = E(), vt = ke({
|
|
368
403
|
name: "TresCanvas",
|
|
369
404
|
props: [
|
|
370
405
|
"shadows",
|
|
@@ -381,31 +416,31 @@ const { logWarning: pt } = _(), dt = Re({
|
|
|
381
416
|
"windowSize",
|
|
382
417
|
"preset"
|
|
383
418
|
],
|
|
384
|
-
setup(e, { slots: t, expose:
|
|
385
|
-
e.physicallyCorrectLights === !0 &&
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
419
|
+
setup(e, { slots: t, expose: o }) {
|
|
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(() => {
|
|
423
|
+
u("renderer", null);
|
|
389
424
|
});
|
|
390
425
|
function a() {
|
|
391
|
-
const { renderer:
|
|
426
|
+
const { renderer: l } = ot(n, r, e), { activeCamera: p } = le(), { onLoop: m } = U(), { raycaster: w, pointer: v } = ve();
|
|
392
427
|
m(() => {
|
|
393
428
|
var g;
|
|
394
|
-
|
|
429
|
+
p.value && (w.value.setFromCamera(v.value, p.value), (g = l.value) == null || g.render(i, p.value));
|
|
395
430
|
});
|
|
396
431
|
}
|
|
397
432
|
O(n, a);
|
|
398
433
|
let s;
|
|
399
|
-
function
|
|
400
|
-
s =
|
|
434
|
+
function f() {
|
|
435
|
+
s = dt(t), s.provide("useTres", L()), s.provide("extend", ce), s.mount(i);
|
|
401
436
|
}
|
|
402
|
-
return
|
|
437
|
+
return f(), o({
|
|
403
438
|
scene: i
|
|
404
439
|
}), () => P(
|
|
405
440
|
P(
|
|
406
441
|
"div",
|
|
407
442
|
{
|
|
408
|
-
ref:
|
|
443
|
+
ref: r,
|
|
409
444
|
"data-scene": i.uuid,
|
|
410
445
|
key: i.uuid,
|
|
411
446
|
style: {
|
|
@@ -444,25 +479,26 @@ const { logWarning: pt } = _(), dt = Re({
|
|
|
444
479
|
)
|
|
445
480
|
);
|
|
446
481
|
}
|
|
447
|
-
}),
|
|
482
|
+
}), Lt = {
|
|
448
483
|
install(e) {
|
|
449
|
-
e.component("TresCanvas",
|
|
484
|
+
e.component("TresCanvas", vt);
|
|
450
485
|
}
|
|
451
486
|
};
|
|
452
487
|
export {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
488
|
+
Ke as CameraType,
|
|
489
|
+
vt as TresCanvas,
|
|
490
|
+
$ as catalogue,
|
|
491
|
+
Lt as default,
|
|
492
|
+
ce as extend,
|
|
493
|
+
Ct as isProd,
|
|
494
|
+
it as trasverseObjects,
|
|
495
|
+
le as useCamera,
|
|
496
|
+
yt as useLoader,
|
|
497
|
+
E as useLogger,
|
|
498
|
+
ve as useRaycaster,
|
|
499
|
+
U as useRenderLoop,
|
|
500
|
+
ot as useRenderer,
|
|
501
|
+
bt as useSeek,
|
|
502
|
+
Mt as useTexture,
|
|
467
503
|
L as useTres
|
|
468
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,c,u){"use strict";function se(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const o=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(t,a,o.get?o:{enumerable:!0,get:()=>e[a]})}}return t.default=e,Object.freeze(t)}const $=se(c),U=l.ref({uuid:c.MathUtils.generateUUID()}),I=e=>void Object.assign(U.value,e);var J=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(J||{});const ue=45;let C;function z(){const{state:e,setState:t,aspectRatio:a}=M();function o(r="Perspective",s){var d,v,g;if(r==="Perspective"){const{near:w,far:b,fov:h}=s||{near:.1,far:1e3,fov:ue};C=new c.PerspectiveCamera(h,((d=e.aspectRatio)==null?void 0:d.value)||window.innerWidth/window.innerHeight,w,b),(v=e.cameras)==null||v.push(C)}else{const{left:w,right:b,top:h,bottom:y,near:F,far:B}=s||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};C=new c.OrthographicCamera(w,b,h,y,F,B),(g=e.cameras)==null||g.push(C)}return e.camera=C,t("camera",e.camera),C}function n(){var r;e.camera instanceof c.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(r=e.camera)==null||r.updateProjectionMatrix()}function i(r){var s;(s=e.cameras)==null||s.push(r),r instanceof c.PerspectiveCamera&&e.aspectRatio&&(r.aspect=e.aspectRatio.value),r.updateProjectionMatrix(),t("camera",r)}function f(){e.cameras=[]}return l.watchEffect(()=>{a!=null&&a.value&&n()}),{activeCamera:l.toRef(e,"camera"),createCamera:o,updateCamera:n,pushCamera:i,clearCameras:f}}const K=u.createEventHook(),X=u.createEventHook(),W=u.createEventHook(),P=new c.Clock;let A=0,k=0;const{pause:le,resume:ce,isActive:fe}=u.useRafFn(()=>{K.trigger({delta:A,elapsed:k,clock:P}),X.trigger({delta:A,elapsed:k,clock:P}),W.trigger({delta:A,elapsed:k,clock:P})},{immediate:!1});W.on(()=>{A=P.getDelta(),k=P.getElapsedTime()});function j(){return{onBeforeLoop:K.on,onLoop:X.on,onAfterLoop:W.on,pause:le,resume:ce,isActive:fe}}function pe(e){return e instanceof c.Color?e:Array.isArray(e)?new c.Color(...e):new c.Color(e)}const R={realistic:{outputEncoding:c.sRGBEncoding,toneMapping:c.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:c.PCFSoftShadowMap}}},Y=(e,t)=>{for(const a of Object.keys(t))t[a]instanceof Object&&Object.assign(t[a],Y(e[a],t[a]));return Object.assign(e||{},t),e},de=me("html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot");function x(e){return e.replace(/-([a-z])/g,(t,a)=>a.toUpperCase())}function me(e,t){const a=Object.create(null),o=e.split(",");for(let n=0;n<o.length;n++)a[o[n]]=!0;return t?n=>!!a[n.toLowerCase()]:n=>!!a[n]}const m=l.shallowRef(),G=l.ref(!1);function Q(e,t,a){const{alpha:o=!0,antialias:n=!0,depth:i,logarithmicDepthBuffer:f,failIfMajorPerformanceCaveat:r,precision:s,premultipliedAlpha:d,stencil:v,shadows:g=!1,shadowMapType:w=c.PCFShadowMap,physicallyCorrectLights:b=!1,useLegacyLights:h=!1,outputEncoding:y=c.LinearEncoding,toneMapping:F=c.NoToneMapping,toneMappingExposure:B=1,context:Ue=void 0,powerPreference:Ae="default",preserveDrawingBuffer:ke=!1,clearColor:O,windowSize:je=!1,preset:xe=void 0}=l.toRefs(a),{setState:q}=M(),{width:ne,height:ae}=u.resolveUnref(je)?u.useWindowSize():u.useElementSize(t),{logError:_e}=S(),{pixelRatio:re}=u.useDevicePixelRatio(),{pause:Te,resume:De}=j(),V=l.computed(()=>ne.value/ae.value),oe=()=>{m.value&&(m.value.setSize(ne.value,ae.value),m.value.setPixelRatio(Math.min(re.value,2)))},ie=()=>{if(!m.value)return;const L=u.resolveUnref(xe);if(L){L in R||_e("Renderer Preset must be one of these: "+Object.keys(R).join(", ")),Y(m.value,R[L]);return}m.value.shadowMap.enabled=u.resolveUnref(g),m.value.shadowMap.type=u.resolveUnref(w),m.value.toneMapping=u.resolveUnref(F)||c.NoToneMapping,m.value.toneMappingExposure=u.resolveUnref(B),m.value.outputEncoding=u.resolveUnref(y)||c.LinearEncoding,O!=null&&O.value&&m.value.setClearColor(pe(u.resolveUnref(O))),m.value.useLegacyLights=u.resolveUnref(h)},Fe=()=>{const L=u.unrefElement(e);L&&(m.value=new c.WebGLRenderer({canvas:L,alpha:u.resolveUnref(o),antialias:u.resolveUnref(n),context:u.resolveUnref(Ue),depth:u.resolveUnref(i),failIfMajorPerformanceCaveat:u.resolveUnref(r),logarithmicDepthBuffer:u.resolveUnref(f),powerPreference:u.resolveUnref(Ae),precision:u.resolveUnref(s),stencil:u.resolveUnref(v),preserveDrawingBuffer:u.resolveUnref(ke),premultipliedAlpha:u.resolveUnref(d)}),q("renderer",m.value),q("clock",new c.Clock),q("aspectRatio",V),ie(),oe(),De(),G.value=!0)},Be=()=>{m.value&&(m.value.dispose(),m.value=void 0,G.value=!1,Te())};return l.watch([V,re],oe),l.watch([g,w,y,h,F,B,O],ie),l.watch(()=>[e,t],()=>{u.unrefElement(e)&&u.unrefElement(t)&&Fe()},{immediate:!0,deep:!0}),{renderer:m,isReady:G,dispose:Be,aspectRatio:V}}const Z=e=>!!e&&e.constructor===Array;function E(e){const t={nodes:{},materials:{}};return e&&e.traverse(a=>{a.name&&(t.nodes[a.name]=a),a.material&&!t.materials[a.material.name]&&(t.materials[a.material.name]=a.material)}),t}async function ve(e,t,a,o,n){const{logError:i}=S(),f=new e;n&&n(f),a&&a(f);const s=(Array.isArray(t)?t:[t]).map(d=>new Promise((v,g)=>{f.load(d,w=>{w.scene&&Object.assign(w,E(w.scene)),v(w)},o,w=>g(i("[useLoader] - Failed to load resource",w)))}));return Z(t)?await Promise.all(s):await s[0]}async function ge(e){const t=new c.LoadingManager,a=new c.TextureLoader(t),o=n=>new Promise((i,f)=>{a.load(n,r=>i(r),()=>null,()=>{f(new Error("[useTextures] - Failed to load texture"))})});if(Z(e)){const n=await Promise.all(e.map(i=>o(i)));return e.length>1?n:n[0]}else{const{map:n,displacementMap:i,normalMap:f,roughnessMap:r,metalnessMap:s,aoMap:d}=e;return{map:n?await o(n):null,displacementMap:i?await o(i):null,normalMap:f?await o(f):null,roughnessMap:r?await o(r):null,metalnessMap:s?await o(s):null,aoMap:d?await o(d):null}}}const we={camera:void 0,cameras:[],scene:void 0,renderer:void 0,aspectRatio:l.computed(()=>window.innerWidth/window.innerHeight)},_=l.shallowReactive(we);function M(){function e(a){return _[a]}function t(a,o){_[a]=o}return{state:_,...l.toRefs(_),getState:e,setState:t}}const H=l.shallowRef(new c.Raycaster),T=l.ref(new c.Vector2),he=l.ref(null);function N(){const{setState:e}=M();e("raycaster",H.value),e("pointer",T),e("currentInstance",he);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 S(){function e(o,n){console.error(`${ee} ${o}`,n||"")}function t(o){console.warn(`${ee} ${o}`)}function a(o,n){}return{logError:e,logWarning:t,logMessage:a}}const{logWarning:Ce}=S();function Me(e){for(const t in e)if(t.indexOf("on")===0)return!0;return!1}function ze(e){}let D=null;const be={createElement(e,t,a,o){if(e==="template"||de(e))return null;let n;if(o===null&&(o={}),o!=null&&o.args?n=new U.value[e.replace("Tres","")](...o.args):n=new U.value[e.replace("Tres","")],n.isCamera){(!(o!=null&&o.position)||o!=null&&o.position.every(f=>f==0))&&Ce("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}=z();i(n)}return(o==null?void 0:o.attach)===void 0&&(n.isMaterial?n.attach="material":n.isBufferGeometry&&(n.attach="geometry")),n},insert(e,t,a){if(D===null&&t.isScene&&(D=t),t===null&&(t=D),t!=null&&t.isObject3D&&(e!=null&&e.isObject3D)){const r=a?t.children.indexOf(a):0;e.parent=t,t.children.splice(r,0,e),e.dispatchEvent({type:"added"})}else typeof(e==null?void 0:e.attach)=="string"&&(e.__previousAttach=e[t==null?void 0:t.attach],t&&(t[e.attach]=e));const{onLoop:o}=j();let n=null,i=null;const{raycaster:f}=N();e&&e instanceof c.Mesh&&Me(e)&&(o(()=>{var r,s,d;if(t!=null&&t.children&&e&&f){const v=f.value.intersectObjects(t.children);v.length>0&&v[0].object.uuid===e.uuid?(i=v[0],(n===null||n.object.uuid!==(i==null?void 0:i.object.uuid))&&((r=e.onPointerEnter)==null||r.call(e,i)),(s=e.onPointerMove)==null||s.call(e,i)):(i=null,n!==null&&((d=e.onPointerLeave)==null||d.call(e,n))),n=i}}),u.useEventListener(window,"click",()=>{var r;i!==null&&((r=e.onClick)==null||r.call(e,i))}))},remove(e){if(!e)return;const t=e.parentNode;t&&t.removeChild(e)},patchProp(e,t,a,o){if(e){let n=e,i=t;const f=x(i);let r=n==null?void 0:n[f];if(e.parent||(e.parent=D),n.type==="BufferGeometry"&&(i=i.split("-").pop(),n.setAttribute(x(i),new c.BufferAttribute(...o))),i.includes("-")&&r===void 0){const d=i.split("-");r=d.reduce((v,g)=>v[x(g)],n),i=d.pop(),r!=null&&r.set||(n=d.reduce((v,g)=>v[x(g)],n))}let s=o;if(s===""&&(s=!0),u.isFunction(r)){Array.isArray(s)?e[f](...s):e[f](s);return}!(r!=null&&r.set)&&!u.isFunction(r)?n[f]=s:r.constructor===s.constructor&&(r!=null&&r.copy)?r==null||r.copy(s):Array.isArray(s)?r.set(...s):!r.isColor&&r.setScalar?r.setScalar(s):r.set(s)}},parentNode(e){return(e==null?void 0:e.parent)||null},createText:()=>void 0,createComment:()=>void 0,setText:()=>void 0,setElementText:()=>void 0,nextSibling:()=>void 0,querySelector:()=>void 0,setScopeId:()=>void 0,cloneNode:()=>void 0,insertStaticContent:()=>void 0},{createApp:Le}=l.createRenderer(be),Pe=e=>{const t=Le(a);function a(){return e&&e.default?e.default():[]}return t};I($);const{logWarning:Se}=S(),te=l.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t,expose:a}){e.physicallyCorrectLights===!0&&Se("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const o=l.ref(),n=l.ref(),i=new $.Scene,{setState:f}=M();f("scene",i),l.onUnmounted(()=>{f("renderer",null)});function r(){const{renderer:v}=Q(n,o,e),{activeCamera:g}=z(),{onLoop:w}=j(),{raycaster:b,pointer:h}=N();w(()=>{var y;g.value&&(b.value.setFromCamera(h.value,g.value),(y=v.value)==null||y.render(i,g.value))})}l.watch(n,r);let s;function d(){s=Pe(t),s.provide("useTres",M()),s.provide("extend",I),s.mount(i)}return d(),a({scene:i}),()=>l.h(l.h("div",{ref:o,"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=U,p.default=Oe,p.extend=I,p.isProd=ye,p.trasverseObjects=E,p.useCamera=z,p.useLoader=ve,p.useLogger=S,p.useRaycaster=N,p.useRenderLoop=j,p.useRenderer=Q,p.useTexture=ge,p.useTres=M,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
8
|
+
(function(p,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],l):(p=typeof globalThis<"u"?globalThis:p||self,l(p.tres={},p.Vue,p.Three,p.VueUseCore))})(this,function(p,l,f,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",
|