@tresjs/core 0.5.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/index.d.ts +1 -1
- package/dist/core/{useCatalog → useCatalogue}/index.d.ts +1 -1
- package/dist/core/useInstanceCreator/index.d.ts +2 -2
- package/dist/env.d.ts +2 -0
- package/dist/favicon-16x16.png +0 -0
- package/dist/favicon-32x32.png +0 -0
- package/dist/favicon.ico +0 -0
- package/dist/index.d.ts +5 -1
- package/dist/logo-dark.svg +5 -0
- package/dist/tres.js +207 -200
- package/dist/tres.umd.cjs +2 -2
- package/dist/types/index.d.ts +11 -14
- package/package.json +5 -2
package/dist/core/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function useInstanceCreator(): {
|
|
2
|
-
createComponentInstances: () => (string | import("vue").DefineComponent<{}, () => void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>)[][];
|
|
1
|
+
export declare function useInstanceCreator(prefix: string): {
|
|
2
|
+
createComponentInstances: (newObjects: Record<string, any>) => (string | import("vue").DefineComponent<{}, () => void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>)[][];
|
|
3
3
|
};
|
package/dist/env.d.ts
CHANGED
|
Binary file
|
|
Binary file
|
package/dist/favicon.ico
ADDED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { App } from 'vue';
|
|
2
2
|
export * from './core';
|
|
3
3
|
export * from './keys';
|
|
4
|
+
export interface TresOptions {
|
|
5
|
+
prefix?: string;
|
|
6
|
+
extends?: Record<string, unknown>;
|
|
7
|
+
}
|
|
4
8
|
export interface TresPlugin {
|
|
5
9
|
[key: string]: any;
|
|
6
|
-
install: (app: App, options?:
|
|
10
|
+
install: (app: App, options?: TresOptions) => void;
|
|
7
11
|
}
|
|
8
12
|
declare const plugin: TresPlugin;
|
|
9
13
|
export default plugin;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg width="44" height="10" viewBox="0 0 44 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M5.14255 1.42916C5.53095 0.781817 6.46913 0.781816 6.85753 1.42915L11.0913 8.4855C11.4913 9.15203 11.0111 10 10.2338 10H1.76623C0.988935 10 0.508822 9.15203 0.908736 8.4855L5.14255 1.42916Z" fill="#82DBC5"/>
|
|
3
|
+
<rect x="19" y="1" width="9" height="9" rx="1" fill="#f2f2f2"/>
|
|
4
|
+
<circle cx="39.5" cy="5.5" r="4.5" fill="#EFAC35"/>
|
|
5
|
+
</svg>
|
package/dist/tres.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version:
|
|
3
|
+
* version: v1.0.0
|
|
4
4
|
* (c) 2022
|
|
5
5
|
* description: Declarative ThreeJS using Vue Components
|
|
6
6
|
* author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
|
|
7
7
|
*/
|
|
8
|
-
import { computed as
|
|
9
|
-
import { useWindowSize as
|
|
10
|
-
import * as
|
|
11
|
-
import { PerspectiveCamera as
|
|
8
|
+
import { computed as D, watch as O, inject as X, defineComponent as _, shallowRef as j, reactive as fe, toRefs as me, ref as F, provide as A, onBeforeUnmount as de, h as J } from "vue";
|
|
9
|
+
import { useWindowSize as Y, createEventHook as U, useRafFn as ge, useElementSize as he, useDevicePixelRatio as we, unrefElement as B, resolveUnref as S } from "@vueuse/core";
|
|
10
|
+
import * as ve from "three";
|
|
11
|
+
import { PerspectiveCamera as $, OrthographicCamera as Ce, Color as I, Vector3 as ye, Clock as Me, Scene as Se, LoadingManager as xe, TextureLoader as Ee, PCFShadowMap as Pe, LinearEncoding as Le, NoToneMapping as Te, WebGLRenderer as Re } from "three";
|
|
12
12
|
var Oe = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Oe || {});
|
|
13
|
-
const
|
|
13
|
+
const P = {
|
|
14
14
|
cameras: []
|
|
15
|
-
},
|
|
16
|
-
let
|
|
17
|
-
function
|
|
18
|
-
const { width: e, height: t } =
|
|
19
|
-
function
|
|
15
|
+
}, Ae = 45;
|
|
16
|
+
let E;
|
|
17
|
+
function Z() {
|
|
18
|
+
const { width: e, height: t } = Y(), { setState: n } = oe();
|
|
19
|
+
function a(i = "Perspective", f) {
|
|
20
20
|
if (i === "Perspective") {
|
|
21
|
-
const { near:
|
|
21
|
+
const { near: u, far: m, fov: d } = f || {
|
|
22
22
|
near: 0.1,
|
|
23
23
|
far: 1e3,
|
|
24
|
-
fov:
|
|
24
|
+
fov: Ae
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
E = new $(d, r.value, u, m), P.cameras.push(E);
|
|
27
27
|
} else {
|
|
28
|
-
const { left:
|
|
28
|
+
const { left: u, right: m, top: d, bottom: w, near: C, far: x } = f || {
|
|
29
29
|
left: -100,
|
|
30
30
|
right: 100,
|
|
31
31
|
top: 100,
|
|
@@ -33,116 +33,117 @@ function k() {
|
|
|
33
33
|
near: 0.1,
|
|
34
34
|
far: 1e3
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
E = new Ce(u, m, d, w, C, x), P.cameras.push(E);
|
|
37
37
|
}
|
|
38
|
-
return
|
|
38
|
+
return P.cameras.push(E), E;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
function
|
|
42
|
-
|
|
40
|
+
const r = D(() => e.value / t.value), o = D(() => P.cameras[0]);
|
|
41
|
+
function s() {
|
|
42
|
+
o.value instanceof $ && (o.value.aspect = r.value), o.value.updateProjectionMatrix();
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
i &&
|
|
44
|
+
function c(i) {
|
|
45
|
+
const f = X("camera");
|
|
46
|
+
i && f && (f.value = i, n("camera", f.value)), P.cameras.push(i), i instanceof $ && (i.aspect = r.value), i.updateProjectionMatrix();
|
|
47
47
|
}
|
|
48
|
-
return O(
|
|
49
|
-
activeCamera:
|
|
50
|
-
createCamera:
|
|
51
|
-
updateCamera:
|
|
52
|
-
pushCamera:
|
|
48
|
+
return O(r, s), {
|
|
49
|
+
activeCamera: o,
|
|
50
|
+
createCamera: a,
|
|
51
|
+
updateCamera: s,
|
|
52
|
+
pushCamera: c
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
let
|
|
56
|
-
delete
|
|
57
|
-
function
|
|
55
|
+
let b = { ...ve };
|
|
56
|
+
delete b.Scene;
|
|
57
|
+
function be() {
|
|
58
58
|
return {
|
|
59
59
|
extend: (t) => {
|
|
60
|
-
|
|
60
|
+
b = Object.assign(b, t);
|
|
61
61
|
},
|
|
62
|
-
catalogue:
|
|
62
|
+
catalogue: b
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
const
|
|
66
|
-
function
|
|
67
|
-
return typeof e == "number" ? [e, e, e] : e instanceof
|
|
65
|
+
const Be = (e) => typeof e < "u", V = (e) => !!e && e.constructor === Array;
|
|
66
|
+
function $e(e) {
|
|
67
|
+
return typeof e == "number" ? [e, e, e] : e instanceof ye ? [e.x, e.y, e.z] : e;
|
|
68
68
|
}
|
|
69
|
-
function
|
|
70
|
-
return e instanceof
|
|
69
|
+
function q(e) {
|
|
70
|
+
return e instanceof I ? e : Array.isArray(e) ? new I(...e) : new I(e);
|
|
71
71
|
}
|
|
72
|
-
const
|
|
72
|
+
const K = "[TresJS \u25B2 \u25A0 \u25CF] ";
|
|
73
73
|
function W() {
|
|
74
|
-
function e(a,
|
|
75
|
-
console.error(`${
|
|
74
|
+
function e(a, r) {
|
|
75
|
+
console.error(`${K} ${a}`, r || "");
|
|
76
76
|
}
|
|
77
77
|
function t(a) {
|
|
78
|
-
console.warn(`${
|
|
78
|
+
console.warn(`${K} ${a}`);
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function n(a, r) {
|
|
81
81
|
}
|
|
82
82
|
return {
|
|
83
83
|
logError: e,
|
|
84
84
|
logWarning: t,
|
|
85
|
-
logMessage:
|
|
85
|
+
logMessage: n
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
const
|
|
89
|
-
function
|
|
90
|
-
const {
|
|
91
|
-
function a() {
|
|
92
|
-
return Object.entries(
|
|
93
|
-
var
|
|
94
|
-
return (i = (
|
|
95
|
-
}).map(([
|
|
96
|
-
const
|
|
97
|
-
name:
|
|
98
|
-
setup(
|
|
99
|
-
t(
|
|
100
|
-
props:
|
|
101
|
-
slots:
|
|
102
|
-
attrs:
|
|
88
|
+
const Ie = ["rotation", "scale", "position"];
|
|
89
|
+
function ze(e) {
|
|
90
|
+
const { logMessage: t, logError: n } = W();
|
|
91
|
+
function a(r) {
|
|
92
|
+
return Object.entries(r).filter(([o, s]) => {
|
|
93
|
+
var c, i;
|
|
94
|
+
return (i = (c = s == null ? void 0 : s.prototype) == null ? void 0 : c.constructor) == null ? void 0 : i.toString().includes("class");
|
|
95
|
+
}).map(([o, s]) => {
|
|
96
|
+
const c = `${e}${o}`, i = _({
|
|
97
|
+
name: c,
|
|
98
|
+
setup(f, { slots: u, attrs: m, ...d }) {
|
|
99
|
+
t(c, {
|
|
100
|
+
props: f,
|
|
101
|
+
slots: u,
|
|
102
|
+
attrs: m,
|
|
103
103
|
ctx: d
|
|
104
104
|
});
|
|
105
|
-
let
|
|
106
|
-
const { scene:
|
|
107
|
-
function
|
|
108
|
-
if ((
|
|
109
|
-
const
|
|
110
|
-
var
|
|
111
|
-
let
|
|
112
|
-
|
|
105
|
+
let w;
|
|
106
|
+
const { scene: C } = ae(), { pushCamera: x } = Z();
|
|
107
|
+
function L() {
|
|
108
|
+
if ((u == null ? void 0 : u.default) && (u == null ? void 0 : u.default())) {
|
|
109
|
+
const y = u.default().map((l) => {
|
|
110
|
+
var h;
|
|
111
|
+
let v;
|
|
112
|
+
const g = l.type.name.replace(e, "");
|
|
113
|
+
return (h = l == null ? void 0 : l.props) != null && h.args ? v = new r[g](...l.props.args) : v = new r[g](), l != null && l.props && T(l.props, v), v;
|
|
113
114
|
});
|
|
114
|
-
|
|
115
|
+
w = new s(...y);
|
|
115
116
|
} else
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
m.args ? w = new s(...m.args) : w = new s();
|
|
118
|
+
T(m, w), c.includes("Camera") && x(w), w.isObject3D && (C == null || C.value.add(w)), t("Instance added", C), d.expose(w);
|
|
118
119
|
}
|
|
119
|
-
function
|
|
120
|
-
Object.entries(
|
|
121
|
-
const h =
|
|
120
|
+
function T(y, l) {
|
|
121
|
+
Object.entries(y).forEach(([v, g]) => {
|
|
122
|
+
const h = v.replace(/(-\w)/g, (M) => M[1].toUpperCase());
|
|
122
123
|
if (!(h === "args" || g === void 0)) {
|
|
123
|
-
|
|
124
|
+
Ie.includes(v) && g && (g = $e(g));
|
|
124
125
|
try {
|
|
125
|
-
|
|
126
|
-
} catch (
|
|
127
|
-
|
|
126
|
+
l[h] && Be(l[h].set) ? V(g) ? l[h].set(...g) : l[h].set(g) : (g === "" && (g = !0), l[h] = g);
|
|
127
|
+
} catch (M) {
|
|
128
|
+
n(`There was an error setting ${h} property`, M);
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
|
-
}),
|
|
131
|
+
}), y.ref && (y.ref = l);
|
|
131
132
|
}
|
|
132
|
-
return
|
|
133
|
+
return L(), () => {
|
|
133
134
|
};
|
|
134
135
|
}
|
|
135
136
|
});
|
|
136
|
-
return [
|
|
137
|
+
return [c, i];
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
return {
|
|
140
141
|
createComponentInstances: a
|
|
141
142
|
};
|
|
142
143
|
}
|
|
143
|
-
const ee = U(), te = U(), ne = U(),
|
|
144
|
+
const ee = U(), te = U(), ne = U(), Q = new Me(), { pause: De, resume: Fe, isActive: _e } = ge(
|
|
144
145
|
() => {
|
|
145
|
-
const e =
|
|
146
|
+
const e = Q.getElapsedTime(), t = Q.getDelta();
|
|
146
147
|
ee.trigger({ delta: t, elapsed: e }), te.trigger({ delta: t, elapsed: e }), ne.trigger({ delta: t, elapsed: e });
|
|
147
148
|
},
|
|
148
149
|
{ immediate: !1 }
|
|
@@ -152,151 +153,155 @@ function re() {
|
|
|
152
153
|
onBeforeLoop: ee.on,
|
|
153
154
|
onLoop: te.on,
|
|
154
155
|
onAfterLoop: ne.on,
|
|
155
|
-
pause:
|
|
156
|
+
pause: De,
|
|
156
157
|
resume: Fe,
|
|
157
|
-
isActive:
|
|
158
|
+
isActive: _e
|
|
158
159
|
};
|
|
159
160
|
}
|
|
160
|
-
const
|
|
161
|
+
const je = j(new Se());
|
|
161
162
|
function ae() {
|
|
162
163
|
return {
|
|
163
|
-
scene:
|
|
164
|
+
scene: je
|
|
164
165
|
};
|
|
165
166
|
}
|
|
166
|
-
function
|
|
167
|
+
function Ue(e) {
|
|
167
168
|
const t = { nodes: {}, materials: {} };
|
|
168
|
-
return e && e.traverse((
|
|
169
|
-
|
|
169
|
+
return e && e.traverse((n) => {
|
|
170
|
+
n.name && (t.nodes[n.name] = n), n.material && !t.materials[n.material.name] && (t.materials[n.material.name] = n.material);
|
|
170
171
|
}), t;
|
|
171
172
|
}
|
|
172
|
-
async function
|
|
173
|
-
const { logError: o } = W(),
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
(
|
|
180
|
-
|
|
173
|
+
async function Je(e, t, n, a, r) {
|
|
174
|
+
const { logError: o } = W(), s = new e();
|
|
175
|
+
r && r(s), n && n(e);
|
|
176
|
+
const i = (Array.isArray(t) ? t : [t]).map(
|
|
177
|
+
(f) => new Promise((u, m) => {
|
|
178
|
+
s.load(
|
|
179
|
+
f,
|
|
180
|
+
(d) => {
|
|
181
|
+
d.scene && Object.assign(d, Ue(d.scene)), u(d);
|
|
181
182
|
},
|
|
182
183
|
a,
|
|
183
|
-
(
|
|
184
|
+
(d) => m(o("[useLoader] - Failed to load resource", d))
|
|
184
185
|
);
|
|
185
186
|
})
|
|
186
187
|
);
|
|
187
|
-
return V(t) ? await Promise.all(
|
|
188
|
+
return V(t) ? await Promise.all(i) : await i[0];
|
|
188
189
|
}
|
|
189
|
-
async function
|
|
190
|
-
const t = new
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
(
|
|
190
|
+
async function qe(e) {
|
|
191
|
+
const t = new xe(), n = new Ee(t), a = (r) => new Promise((o, s) => {
|
|
192
|
+
n.load(
|
|
193
|
+
r,
|
|
194
|
+
(c) => o(c),
|
|
194
195
|
() => null,
|
|
195
196
|
() => {
|
|
196
|
-
|
|
197
|
+
s(new Error("[useTextures] - Failed to load texture"));
|
|
197
198
|
}
|
|
198
199
|
);
|
|
199
200
|
});
|
|
200
201
|
if (V(e)) {
|
|
201
|
-
const
|
|
202
|
-
return e.length > 1 ?
|
|
202
|
+
const r = await Promise.all(e.map((o) => a(o)));
|
|
203
|
+
return e.length > 1 ? r : r[0];
|
|
203
204
|
} else {
|
|
204
|
-
const { map:
|
|
205
|
+
const { map: r, displacementMap: o, normalMap: s, roughnessMap: c, metalnessMap: i, aoMap: f } = e;
|
|
205
206
|
return {
|
|
206
|
-
map:
|
|
207
|
+
map: r ? await a(r) : null,
|
|
207
208
|
displacementMap: o ? await a(o) : null,
|
|
208
|
-
normalMap:
|
|
209
|
-
roughnessMap:
|
|
210
|
-
metalnessMap:
|
|
211
|
-
aoMap:
|
|
209
|
+
normalMap: s ? await a(s) : null,
|
|
210
|
+
roughnessMap: c ? await a(c) : null,
|
|
211
|
+
metalnessMap: i ? await a(i) : null,
|
|
212
|
+
aoMap: f ? await a(f) : null
|
|
212
213
|
};
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
|
-
const
|
|
216
|
-
function
|
|
217
|
-
function e(
|
|
218
|
-
return
|
|
216
|
+
const R = fe({});
|
|
217
|
+
function oe() {
|
|
218
|
+
function e(n) {
|
|
219
|
+
return R[n];
|
|
219
220
|
}
|
|
220
|
-
function t(
|
|
221
|
-
|
|
221
|
+
function t(n, a) {
|
|
222
|
+
R[n] = a;
|
|
222
223
|
}
|
|
223
224
|
return {
|
|
224
|
-
state:
|
|
225
|
-
...
|
|
225
|
+
state: R,
|
|
226
|
+
...me(R),
|
|
226
227
|
getState: e,
|
|
227
228
|
setState: t
|
|
228
229
|
};
|
|
229
230
|
}
|
|
230
|
-
const
|
|
231
|
-
function
|
|
231
|
+
const p = j(), z = F(!1);
|
|
232
|
+
function Ve(e, t, n) {
|
|
232
233
|
const {
|
|
233
234
|
alpha: a = !1,
|
|
234
|
-
antialias:
|
|
235
|
+
antialias: r,
|
|
235
236
|
depth: o,
|
|
236
|
-
logarithmicDepthBuffer:
|
|
237
|
-
failIfMajorPerformanceCaveat:
|
|
238
|
-
precision:
|
|
239
|
-
premultipliedAlpha:
|
|
240
|
-
stencil:
|
|
241
|
-
shadows:
|
|
242
|
-
shadowMapType:
|
|
243
|
-
physicallyCorrectLights:
|
|
244
|
-
outputEncoding:
|
|
245
|
-
toneMapping:
|
|
246
|
-
toneMappingExposure:
|
|
247
|
-
context:
|
|
248
|
-
powerPreference:
|
|
249
|
-
preserveDrawingBuffer:
|
|
250
|
-
clearColor:
|
|
251
|
-
windowSize:
|
|
252
|
-
} =
|
|
253
|
-
!
|
|
254
|
-
},
|
|
255
|
-
!
|
|
256
|
-
},
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
237
|
+
logarithmicDepthBuffer: s,
|
|
238
|
+
failIfMajorPerformanceCaveat: c,
|
|
239
|
+
precision: i,
|
|
240
|
+
premultipliedAlpha: f,
|
|
241
|
+
stencil: u,
|
|
242
|
+
shadows: m = !1,
|
|
243
|
+
shadowMapType: d = Pe,
|
|
244
|
+
physicallyCorrectLights: w = !1,
|
|
245
|
+
outputEncoding: C = Le,
|
|
246
|
+
toneMapping: x = Te,
|
|
247
|
+
toneMappingExposure: L = 1,
|
|
248
|
+
context: T = void 0,
|
|
249
|
+
powerPreference: y = "default",
|
|
250
|
+
preserveDrawingBuffer: l = !1,
|
|
251
|
+
clearColor: v = q("#000000"),
|
|
252
|
+
windowSize: g = !1
|
|
253
|
+
} = n, { width: h, height: M } = g ? Y() : he(t), { pixelRatio: k } = we(), { pause: se, resume: ie } = re(), ce = D(() => h.value / M.value), N = () => {
|
|
254
|
+
!p.value || (p.value.setSize(h.value, M.value), p.value.setPixelRatio(k.value));
|
|
255
|
+
}, H = () => {
|
|
256
|
+
!p.value || (p.value.shadowMap.enabled = S(m), p.value.outputEncoding = S(C), p.value.shadowMap.type = S(d), p.value.physicallyCorrectLights = S(w), p.value.toneMapping = S(x), p.value.toneMappingExposure = S(L), p.value.setClearColor(q(S(v))));
|
|
257
|
+
}, ue = () => {
|
|
258
|
+
const G = B(e);
|
|
259
|
+
if (p.value || !G)
|
|
260
|
+
return;
|
|
261
|
+
p.value = new Re({
|
|
262
|
+
canvas: G,
|
|
260
263
|
alpha: a,
|
|
261
|
-
antialias:
|
|
262
|
-
context:
|
|
264
|
+
antialias: r,
|
|
265
|
+
context: T,
|
|
263
266
|
depth: o,
|
|
264
|
-
failIfMajorPerformanceCaveat:
|
|
265
|
-
logarithmicDepthBuffer:
|
|
266
|
-
powerPreference:
|
|
267
|
-
precision:
|
|
268
|
-
stencil:
|
|
269
|
-
preserveDrawingBuffer:
|
|
270
|
-
premultipliedAlpha:
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
|
|
267
|
+
failIfMajorPerformanceCaveat: c,
|
|
268
|
+
logarithmicDepthBuffer: s,
|
|
269
|
+
powerPreference: y,
|
|
270
|
+
precision: i,
|
|
271
|
+
stencil: u,
|
|
272
|
+
preserveDrawingBuffer: l,
|
|
273
|
+
premultipliedAlpha: f
|
|
274
|
+
});
|
|
275
|
+
const { setState: pe } = oe();
|
|
276
|
+
pe("renderer", p.value), H(), N(), ie(), z.value = !0;
|
|
277
|
+
}, le = () => {
|
|
278
|
+
!p.value || (p.value.dispose(), p.value = void 0, z.value = !1, se());
|
|
274
279
|
};
|
|
275
|
-
return O([
|
|
280
|
+
return O([h, M, k], N), O(
|
|
276
281
|
() => [
|
|
277
|
-
f,
|
|
278
282
|
m,
|
|
279
|
-
|
|
280
|
-
y,
|
|
281
|
-
E,
|
|
283
|
+
d,
|
|
282
284
|
C,
|
|
283
|
-
|
|
285
|
+
w,
|
|
286
|
+
x,
|
|
287
|
+
L,
|
|
288
|
+
v
|
|
284
289
|
],
|
|
285
|
-
|
|
290
|
+
H
|
|
286
291
|
), O(
|
|
287
292
|
() => [e, t],
|
|
288
293
|
() => {
|
|
289
|
-
B(e) && B(t) &&
|
|
294
|
+
B(e) && B(t) && ue();
|
|
290
295
|
},
|
|
291
296
|
{ immediate: !0, deep: !0 }
|
|
292
297
|
), {
|
|
293
|
-
renderer:
|
|
294
|
-
isReady:
|
|
295
|
-
dispose:
|
|
296
|
-
aspectRatio:
|
|
298
|
+
renderer: p,
|
|
299
|
+
isReady: z,
|
|
300
|
+
dispose: le,
|
|
301
|
+
aspectRatio: ce
|
|
297
302
|
};
|
|
298
303
|
}
|
|
299
|
-
const
|
|
304
|
+
const We = _({
|
|
300
305
|
name: "TresCanvas",
|
|
301
306
|
props: {
|
|
302
307
|
shadows: Boolean,
|
|
@@ -311,13 +316,14 @@ const Ue = _({
|
|
|
311
316
|
clearColor: String,
|
|
312
317
|
windowSize: Boolean
|
|
313
318
|
},
|
|
314
|
-
setup(e, { slots: t, attrs:
|
|
315
|
-
const { logError: a } = W(),
|
|
316
|
-
return
|
|
317
|
-
|
|
318
|
-
|
|
319
|
+
setup(e, { slots: t, attrs: n }) {
|
|
320
|
+
const { logError: a } = W(), r = F(), o = F(), { renderer: s, dispose: c, aspectRatio: i } = Ve(r, o, e), f = j();
|
|
321
|
+
return A("camera", f), A("renderer", s), A("aspect-ratio", i), t.default && !t.default().some((u) => u.type.name === "Scene") && a("TresCanvas must contain a Scene component."), t.default && !t.default().some((u) => {
|
|
322
|
+
var m;
|
|
323
|
+
return (m = u.type.name) == null ? void 0 : m.includes("Camera");
|
|
324
|
+
}) && a("Scene must contain a Camera component."), de(() => c()), () => {
|
|
319
325
|
if (t.default)
|
|
320
|
-
return
|
|
326
|
+
return J(
|
|
321
327
|
"div",
|
|
322
328
|
{
|
|
323
329
|
ref: o,
|
|
@@ -325,12 +331,12 @@ const Ue = _({
|
|
|
325
331
|
position: "relative",
|
|
326
332
|
width: "100%",
|
|
327
333
|
height: "100vh",
|
|
328
|
-
...
|
|
334
|
+
...n.style
|
|
329
335
|
}
|
|
330
336
|
},
|
|
331
337
|
[
|
|
332
|
-
|
|
333
|
-
ref:
|
|
338
|
+
J("canvas", {
|
|
339
|
+
ref: r,
|
|
334
340
|
style: { width: "100%", height: "100%", position: "absolute", top: 0, left: 0 }
|
|
335
341
|
}),
|
|
336
342
|
t.default()
|
|
@@ -338,23 +344,24 @@ const Ue = _({
|
|
|
338
344
|
);
|
|
339
345
|
};
|
|
340
346
|
}
|
|
341
|
-
}),
|
|
347
|
+
}), ke = _({
|
|
342
348
|
name: "Scene",
|
|
343
349
|
setup(e, { slots: t }) {
|
|
344
|
-
const { scene:
|
|
345
|
-
return
|
|
346
|
-
(a == null ? void 0 : a.value) && (
|
|
350
|
+
const { scene: n } = ae(), a = X("renderer"), { activeCamera: r } = Z(), { onLoop: o } = re();
|
|
351
|
+
return A("local-scene", n), o(() => {
|
|
352
|
+
(a == null ? void 0 : a.value) && (r == null ? void 0 : r.value) && (n == null ? void 0 : n.value) && a.value.render(n == null ? void 0 : n.value, r.value);
|
|
347
353
|
}), () => {
|
|
348
354
|
if (t.default)
|
|
349
355
|
return t.default();
|
|
350
356
|
};
|
|
351
357
|
}
|
|
352
358
|
}), Ke = Symbol("UseTresState"), Qe = {
|
|
353
|
-
install(e) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
359
|
+
install(e, t) {
|
|
360
|
+
const n = (t == null ? void 0 : t.prefix) || "Tres";
|
|
361
|
+
e.component(`${n}Canvas`, We), e.component(`${n}Scene`, ke);
|
|
362
|
+
const { catalogue: a } = be(), { createComponentInstances: r } = ze(n);
|
|
363
|
+
r(t != null && t.extends ? { ...a, ...t.extends } : a).forEach(([s, c]) => {
|
|
364
|
+
e.component(s, c);
|
|
358
365
|
});
|
|
359
366
|
}
|
|
360
367
|
};
|
|
@@ -362,14 +369,14 @@ export {
|
|
|
362
369
|
Oe as CameraType,
|
|
363
370
|
Ke as UseTresStateSymbol,
|
|
364
371
|
Qe as default,
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
372
|
+
Ue as trasverseObjects,
|
|
373
|
+
Z as useCamera,
|
|
374
|
+
be as useCatalogue,
|
|
375
|
+
ze as useInstanceCreator,
|
|
376
|
+
Je as useLoader,
|
|
370
377
|
re as useRenderLoop,
|
|
371
|
-
|
|
378
|
+
Ve as useRenderer,
|
|
372
379
|
ae as useScene,
|
|
373
|
-
|
|
374
|
-
|
|
380
|
+
qe as useTexture,
|
|
381
|
+
oe as useTres
|
|
375
382
|
};
|
package/dist/tres.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version:
|
|
3
|
+
* version: v1.0.0
|
|
4
4
|
* (c) 2022
|
|
5
5
|
* description: Declarative ThreeJS using Vue Components
|
|
6
6
|
* author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
|
|
7
7
|
*/
|
|
8
|
-
(function(u,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue"),require("@vueuse/core"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","three"],o):(u=typeof globalThis<"u"?globalThis:u||self,o(u.tres={},u.Vue,u.VueUseCore,u.Three))})(this,function(u,o,
|
|
8
|
+
(function(u,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue"),require("@vueuse/core"),require("three")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","three"],o):(u=typeof globalThis<"u"?globalThis:u||self,o(u.tres={},u.Vue,u.VueUseCore,u.Three))})(this,function(u,o,p,g){"use strict";function te(e){if(e&&e.__esModule)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ne=te(g);var V=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(V||{});const j={cameras:[]},re=45;let b;function z(){const{width:e,height:t}=p.useWindowSize(),{setState:n}=F();function r(c="Perspective",h){if(c==="Perspective"){const{near:f,far:w,fov:C}=h||{near:.1,far:1e3,fov:re};b=new g.PerspectiveCamera(C,a.value,f,w),j.cameras.push(b)}else{const{left:f,right:w,top:C,bottom:M,near:P,far:x}=h||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};b=new g.OrthographicCamera(f,w,C,M,P,x),j.cameras.push(b)}return j.cameras.push(b),b}const a=o.computed(()=>e.value/t.value),s=o.computed(()=>j.cameras[0]);function i(){s.value instanceof g.PerspectiveCamera&&(s.value.aspect=a.value),s.value.updateProjectionMatrix()}function l(c){const h=o.inject("camera");c&&h&&(h.value=c,n("camera",h.value)),j.cameras.push(c),c instanceof g.PerspectiveCamera&&(c.aspect=a.value),c.updateProjectionMatrix()}return o.watch(a,i),{activeCamera:s,createCamera:r,updateCamera:i,pushCamera:l}}let _={...ne};delete _.Scene;function k(){return{extend:t=>{_=Object.assign(_,t)},catalogue:_}}const ae=e=>typeof e<"u",B=e=>!!e&&e.constructor===Array;function oe(e){return typeof e=="number"?[e,e,e]:e instanceof g.Vector3?[e.x,e.y,e.z]:e}function W(e){return e instanceof g.Color?e:Array.isArray(e)?new g.Color(...e):new g.Color(e)}const N="[TresJS \u25B2 \u25A0 \u25CF] ";function I(){function e(r,a){console.error(`${N} ${r}`,a||"")}function t(r){console.warn(`${N} ${r}`)}function n(r,a){}return{logError:e,logWarning:t,logMessage:n}}const se=["rotation","scale","position"];function q(e){const{logMessage:t,logError:n}=I();function r(a){return Object.entries(a).filter(([s,i])=>{var l,c;return(c=(l=i==null?void 0:i.prototype)==null?void 0:l.constructor)==null?void 0:c.toString().includes("class")}).map(([s,i])=>{const l=`${e}${s}`,c=o.defineComponent({name:l,setup(h,{slots:f,attrs:w,...C}){t(l,{props:h,slots:f,attrs:w,ctx:C});let M;const{scene:P}=D(),{pushCamera:x}=z();function U(){if((f==null?void 0:f.default)&&(f==null?void 0:f.default())){const O=f.default().map(m=>{var S;let v;const y=m.type.name.replace(e,"");return(S=m==null?void 0:m.props)!=null&&S.args?v=new a[y](...m.props.args):v=new a[y],m!=null&&m.props&&A(m.props,v),v});M=new i(...O)}else w.args?M=new i(...w.args):M=new i;A(w,M),l.includes("Camera")&&x(M),M.isObject3D&&(P==null||P.value.add(M)),t("Instance added",P),C.expose(M)}function A(O,m){Object.entries(O).forEach(([v,y])=>{const S=v.replace(/(-\w)/g,L=>L[1].toUpperCase());if(!(S==="args"||y===void 0)){se.includes(v)&&y&&(y=oe(y));try{m[S]&&ae(m[S].set)?B(y)?m[S].set(...y):m[S].set(y):(y===""&&(y=!0),m[S]=y)}catch(L){n(`There was an error setting ${S} property`,L)}}}),O.ref&&(O.ref=m)}return U(),()=>{}}});return[l,c]})}return{createComponentInstances:r}}const G=p.createEventHook(),J=p.createEventHook(),K=p.createEventHook(),Q=new g.Clock,{pause:ie,resume:ce,isActive:ue}=p.useRafFn(()=>{const e=Q.getElapsedTime(),t=Q.getDelta();G.trigger({delta:t,elapsed:e}),J.trigger({delta:t,elapsed:e}),K.trigger({delta:t,elapsed:e})},{immediate:!1});function $(){return{onBeforeLoop:G.on,onLoop:J.on,onAfterLoop:K.on,pause:ie,resume:ce,isActive:ue}}const le=o.shallowRef(new g.Scene);function D(){return{scene:le}}function X(e){const t={nodes:{},materials:{}};return e&&e.traverse(n=>{n.name&&(t.nodes[n.name]=n),n.material&&!t.materials[n.material.name]&&(t.materials[n.material.name]=n.material)}),t}async function fe(e,t,n,r,a){const{logError:s}=I(),i=new e;a&&a(i),n&&n(e);const c=(Array.isArray(t)?t:[t]).map(h=>new Promise((f,w)=>{i.load(h,C=>{C.scene&&Object.assign(C,X(C.scene)),f(C)},r,C=>w(s("[useLoader] - Failed to load resource",C)))}));return B(t)?await Promise.all(c):await c[0]}async function pe(e){const t=new g.LoadingManager,n=new g.TextureLoader(t),r=a=>new Promise((s,i)=>{n.load(a,l=>s(l),()=>null,()=>{i(new Error("[useTextures] - Failed to load texture"))})});if(B(e)){const a=await Promise.all(e.map(s=>r(s)));return e.length>1?a:a[0]}else{const{map:a,displacementMap:s,normalMap:i,roughnessMap:l,metalnessMap:c,aoMap:h}=e;return{map:a?await r(a):null,displacementMap:s?await r(s):null,normalMap:i?await r(i):null,roughnessMap:l?await r(l):null,metalnessMap:c?await r(c):null,aoMap:h?await r(h):null}}}const T=o.reactive({});function F(){function e(n){return T[n]}function t(n,r){T[n]=r}return{state:T,...o.toRefs(T),getState:e,setState:t}}const d=o.shallowRef(),R=o.ref(!1);function Y(e,t,n){const{alpha:r=!1,antialias:a,depth:s,logarithmicDepthBuffer:i,failIfMajorPerformanceCaveat:l,precision:c,premultipliedAlpha:h,stencil:f,shadows:w=!1,shadowMapType:C=g.PCFShadowMap,physicallyCorrectLights:M=!1,outputEncoding:P=g.LinearEncoding,toneMapping:x=g.NoToneMapping,toneMappingExposure:U=1,context:A=void 0,powerPreference:O="default",preserveDrawingBuffer:m=!1,clearColor:v=W("#000000"),windowSize:y=!1}=n,{width:S,height:L}=y?p.useWindowSize():p.useElementSize(t),{pixelRatio:Z}=p.useDevicePixelRatio(),{pause:we,resume:Ce}=$(),ye=o.computed(()=>S.value/L.value),E=()=>{!d.value||(d.value.setSize(S.value,L.value),d.value.setPixelRatio(Z.value))},H=()=>{!d.value||(d.value.shadowMap.enabled=p.resolveUnref(w),d.value.outputEncoding=p.resolveUnref(P),d.value.shadowMap.type=p.resolveUnref(C),d.value.physicallyCorrectLights=p.resolveUnref(M),d.value.toneMapping=p.resolveUnref(x),d.value.toneMappingExposure=p.resolveUnref(U),d.value.setClearColor(W(p.resolveUnref(v))))},Se=()=>{const ee=p.unrefElement(e);if(d.value||!ee)return;d.value=new g.WebGLRenderer({canvas:ee,alpha:r,antialias:a,context:A,depth:s,failIfMajorPerformanceCaveat:l,logarithmicDepthBuffer:i,powerPreference:O,precision:c,stencil:f,preserveDrawingBuffer:m,premultipliedAlpha:h});const{setState:ve}=F();ve("renderer",d.value),H(),E(),Ce(),R.value=!0},Me=()=>{!d.value||(d.value.dispose(),d.value=void 0,R.value=!1,we())};return o.watch([S,L,Z],E),o.watch(()=>[w,C,P,M,x,U,v],H),o.watch(()=>[e,t],()=>{p.unrefElement(e)&&p.unrefElement(t)&&Se()},{immediate:!0,deep:!0}),{renderer:d,isReady:R,dispose:Me,aspectRatio:ye}}const de=o.defineComponent({name:"TresCanvas",props:{shadows:Boolean,shadowMapType:Object,physicallyCorrectLights:Boolean,outputEncoding:Object,toneMapping:Object,toneMappingExposure:Number,context:Object,powerPreference:Object,preserveDrawingBuffer:Boolean,clearColor:String,windowSize:Boolean},setup(e,{slots:t,attrs:n}){const{logError:r}=I(),a=o.ref(),s=o.ref(),{renderer:i,dispose:l,aspectRatio:c}=Y(a,s,e),h=o.shallowRef();return o.provide("camera",h),o.provide("renderer",i),o.provide("aspect-ratio",c),t.default&&!t.default().some(f=>f.type.name==="Scene")&&r("TresCanvas must contain a Scene component."),t.default&&!t.default().some(f=>{var w;return(w=f.type.name)==null?void 0:w.includes("Camera")})&&r("Scene must contain a Camera component."),o.onBeforeUnmount(()=>l()),()=>{if(t.default)return o.h("div",{ref:s,style:{position:"relative",width:"100%",height:"100vh",...n.style}},[o.h("canvas",{ref:a,style:{width:"100%",height:"100%",position:"absolute",top:0,left:0}}),t.default()])}}}),me=o.defineComponent({name:"Scene",setup(e,{slots:t}){const{scene:n}=D(),r=o.inject("renderer"),{activeCamera:a}=z(),{onLoop:s}=$();return o.provide("local-scene",n),s(()=>{(r==null?void 0:r.value)&&(a==null?void 0:a.value)&&(n==null?void 0:n.value)&&r.value.render(n==null?void 0:n.value,a.value)}),()=>{if(t.default)return t.default()}}}),ge=Symbol("UseTresState"),he={install(e,t){const n=(t==null?void 0:t.prefix)||"Tres";e.component(`${n}Canvas`,de),e.component(`${n}Scene`,me);const{catalogue:r}=k(),{createComponentInstances:a}=q(n);a(t!=null&&t.extends?{...r,...t.extends}:r).forEach(([i,l])=>{e.component(i,l)})}};u.CameraType=V,u.UseTresStateSymbol=ge,u.default=he,u.trasverseObjects=X,u.useCamera=z,u.useCatalogue=k,u.useInstanceCreator=q,u.useLoader=fe,u.useRenderLoop=$,u.useRenderer=Y,u.useScene=D,u.useTexture=pe,u.useTres=F,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { Object3D } from 'three'
|
|
2
|
-
import { VNode, VNodeTypes } from 'vue'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export
|
|
12
|
-
children?: Array<VNode>;
|
|
13
|
-
type: TresVNodeType;
|
|
14
|
-
};
|
|
1
|
+
import { Object3D } from 'three'
|
|
2
|
+
import { VNode, VNodeTypes } from 'vue'
|
|
3
|
+
|
|
4
|
+
export type TresInstance = Object3D<Event> & { [key: string]: any }
|
|
5
|
+
|
|
6
|
+
export type TresVNodeType = VNodeTypes & {
|
|
7
|
+
name?: string | Array<string>
|
|
8
|
+
__name?: string
|
|
9
|
+
setup?: (props: Readonly<any>) => void
|
|
10
|
+
}
|
|
11
|
+
export type TresVNode = VNode & { children?: Array<VNode>; type: TresVNodeType }
|
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": "0.
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
7
7
|
"files": [
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"threejs-vue"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"three": "^0.146.0",
|
|
33
34
|
"vue": "^3.2.45"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
@@ -38,7 +39,8 @@
|
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@alvarosabu/utils": "^2.2.0",
|
|
40
41
|
"@histoire/plugin-vue": "0.11.7",
|
|
41
|
-
"@tresjs/cientos": "^0.
|
|
42
|
+
"@tresjs/cientos": "^1.0.0",
|
|
43
|
+
"@types/three": "^0.146.0",
|
|
42
44
|
"@vitejs/plugin-vue": "^3.2.0",
|
|
43
45
|
"@vitest/coverage-c8": "^0.25.1",
|
|
44
46
|
"@vitest/ui": "^0.25.1",
|
|
@@ -54,6 +56,7 @@
|
|
|
54
56
|
"vite": "^3.2.3",
|
|
55
57
|
"vite-plugin-banner": "^0.6.1",
|
|
56
58
|
"vite-plugin-dts": "^1.7.0",
|
|
59
|
+
"vite-plugin-glsl": "^0.5.3",
|
|
57
60
|
"vite-plugin-require-transform": "^1.0.4",
|
|
58
61
|
"vitest": "^0.25.1",
|
|
59
62
|
"vue-demi": "^0.13.11"
|