@tresjs/core 1.6.3 → 1.7.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 -0
- package/dist/core/useLoader/index.d.ts +1 -0
- package/dist/core/useRenderer/component.d.ts +2 -0
- package/dist/core/useRenderer/const.d.ts +13 -0
- package/dist/core/useRenderer/index.d.ts +2 -0
- package/dist/core/useTres/index.d.ts +22 -3
- package/dist/index.d.ts +1 -0
- package/dist/tres.js +305 -281
- package/dist/tres.umd.cjs +2 -2
- package/dist/types/index.d.ts +25 -32
- package/dist/utils/index.d.ts +2 -0
- package/package.json +14 -10
package/dist/core/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Object3D } from 'three';
|
|
2
2
|
export interface TresLoader<T> extends THREE.Loader {
|
|
3
3
|
load(url: string, onLoad?: (result: T) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): unknown;
|
|
4
|
+
loadAsync(url: string, onProgress?: (event: ProgressEvent) => void): Promise<T>;
|
|
4
5
|
}
|
|
5
6
|
export type LoaderProto<T> = new (...args: any) => TresLoader<T extends unknown ? any : T>;
|
|
6
7
|
export type LoaderReturnType<T, L extends LoaderProto<T>> = T extends unknown ? Awaited<ReturnType<InstanceType<L>['loadAsync']>> : T;
|
|
@@ -18,6 +18,7 @@ export declare const TresCanvas: import("vue").DefineComponent<{
|
|
|
18
18
|
type: BooleanConstructor;
|
|
19
19
|
default: boolean;
|
|
20
20
|
};
|
|
21
|
+
preset: PropType<"realistic">;
|
|
21
22
|
}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
22
23
|
[key: string]: any;
|
|
23
24
|
}> | undefined, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
@@ -35,6 +36,7 @@ export declare const TresCanvas: import("vue").DefineComponent<{
|
|
|
35
36
|
type: BooleanConstructor;
|
|
36
37
|
default: boolean;
|
|
37
38
|
};
|
|
39
|
+
preset: PropType<"realistic">;
|
|
38
40
|
}>>, {
|
|
39
41
|
shadows: boolean;
|
|
40
42
|
physicallyCorrectLights: boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const rendererPresets: {
|
|
2
|
+
realistic: {
|
|
3
|
+
physicallyCorrectLights: boolean;
|
|
4
|
+
outputEncoding: import("three").TextureEncoding;
|
|
5
|
+
toneMapping: import("three").ToneMapping;
|
|
6
|
+
toneMappingExposure: number;
|
|
7
|
+
shadowMap: {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
type: import("three").ShadowMapType;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type RendererPresetsType = keyof typeof rendererPresets;
|
|
@@ -2,6 +2,7 @@ import { MaybeComputedRef, MaybeElementRef } from '@vueuse/core';
|
|
|
2
2
|
import { WebGLRendererParameters, WebGLRenderer, ShadowMapType } from 'three';
|
|
3
3
|
import type { TextureEncoding, ToneMapping } from 'three';
|
|
4
4
|
import { TresColor } from '../../types';
|
|
5
|
+
import { RendererPresetsType } from './const';
|
|
5
6
|
export interface UseRendererOptions extends WebGLRendererParameters {
|
|
6
7
|
/**
|
|
7
8
|
* Enable shadows in the Renderer
|
|
@@ -70,6 +71,7 @@ export interface UseRendererOptions extends WebGLRendererParameters {
|
|
|
70
71
|
*/
|
|
71
72
|
clearColor?: MaybeComputedRef<TresColor>;
|
|
72
73
|
windowSize?: MaybeComputedRef<boolean>;
|
|
74
|
+
preset?: RendererPresetsType;
|
|
73
75
|
}
|
|
74
76
|
/**
|
|
75
77
|
* Reactive Three.js WebGLRenderer instance
|
|
@@ -1,14 +1,33 @@
|
|
|
1
|
-
import { WebGLRenderer } from 'three';
|
|
1
|
+
import { Clock, EventDispatcher, Raycaster, Scene, Vector2, WebGLRenderer } from 'three';
|
|
2
|
+
import { ComputedRef } from 'vue';
|
|
2
3
|
import { Camera } from '../../core';
|
|
3
4
|
export interface TresState {
|
|
4
|
-
camera?: Camera
|
|
5
|
+
camera?: ComputedRef<Camera>;
|
|
6
|
+
aspectRatio?: ComputedRef<number>;
|
|
5
7
|
renderer?: WebGLRenderer;
|
|
8
|
+
scene?: Scene;
|
|
9
|
+
raycaster?: Raycaster;
|
|
10
|
+
clock?: Clock;
|
|
11
|
+
pointer?: Vector2;
|
|
12
|
+
currentInstance?: any;
|
|
13
|
+
controls?: (EventDispatcher & {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
}) | null;
|
|
6
16
|
[key: string]: any;
|
|
7
17
|
}
|
|
8
18
|
export declare function useTres(): {
|
|
9
19
|
getState: (key: string) => any;
|
|
10
20
|
setState: (key: string, value: any) => void;
|
|
11
|
-
camera?: import("vue").Ref<Camera | undefined> | undefined;
|
|
21
|
+
camera?: import("vue").Ref<ComputedRef<Camera> | undefined> | undefined;
|
|
22
|
+
aspectRatio?: import("vue").Ref<ComputedRef<number> | undefined> | undefined;
|
|
12
23
|
renderer?: import("vue").Ref<WebGLRenderer | undefined> | undefined;
|
|
24
|
+
scene?: import("vue").Ref<Scene | undefined> | undefined;
|
|
25
|
+
raycaster?: import("vue").Ref<Raycaster | undefined> | undefined;
|
|
26
|
+
clock?: import("vue").Ref<Clock | undefined> | undefined;
|
|
27
|
+
pointer?: import("vue").Ref<Vector2 | undefined> | undefined;
|
|
28
|
+
currentInstance?: import("vue").Ref<any> | undefined;
|
|
29
|
+
controls?: import("vue").Ref<(EventDispatcher<import("three").Event> & {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
}) | null | undefined> | undefined;
|
|
13
32
|
state: TresState;
|
|
14
33
|
};
|
package/dist/index.d.ts
CHANGED
package/dist/tres.js
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v1.
|
|
3
|
+
* version: v1.7.0
|
|
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 {
|
|
9
|
-
import { useEventListener as
|
|
10
|
-
import * as
|
|
11
|
-
import { PerspectiveCamera as
|
|
12
|
-
var
|
|
13
|
-
const
|
|
8
|
+
import { computed as me, watch as U, ref as R, inject as de, defineComponent as Z, onUnmounted as ge, shallowRef as ee, shallowReactive as be, toRefs as we, provide as L, onBeforeUnmount as Be, h as ie } from "vue";
|
|
9
|
+
import { useEventListener as Oe, createEventHook as te, useRafFn as Ae, resolveUnref as m, useWindowSize as Ie, useElementSize as Fe, useDevicePixelRatio as $e, unrefElement as J } from "@vueuse/core";
|
|
10
|
+
import * as ce from "three";
|
|
11
|
+
import { PerspectiveCamera as _, OrthographicCamera as he, Vector3 as je, Color as X, Mesh as ke, Fog as ze, BufferAttribute as De, Clock as ve, Scene as Ue, LoadingManager as _e, TextureLoader as Ne, Raycaster as Ve, Vector2 as We, sRGBEncoding as Ge, ACESFilmicToneMapping as He, PCFSoftShadowMap as Ke, PCFShadowMap as Je, LinearEncoding as ue, NoToneMapping as le, WebGLRenderer as Xe } from "three";
|
|
12
|
+
var Ye = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Ye || {});
|
|
13
|
+
const B = {
|
|
14
14
|
cameras: []
|
|
15
|
-
},
|
|
16
|
-
let
|
|
17
|
-
function
|
|
18
|
-
const
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
}, qe = 45;
|
|
16
|
+
let P;
|
|
17
|
+
function ye() {
|
|
18
|
+
const { state: e, setState: n } = T();
|
|
19
|
+
function o(p = "Perspective", t) {
|
|
20
|
+
var s;
|
|
21
|
+
if (p === "Perspective") {
|
|
22
|
+
const { near: c, far: a, fov: u } = t || {
|
|
22
23
|
near: 0.1,
|
|
23
24
|
far: 1e3,
|
|
24
|
-
fov:
|
|
25
|
+
fov: qe
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
+
P = new _(u, ((s = e.aspectRatio) == null ? void 0 : s.value) || 1, c, a), B.cameras.push(P);
|
|
27
28
|
} else {
|
|
28
|
-
const { left:
|
|
29
|
+
const { left: c, right: a, top: u, bottom: f, near: S, far: g } = t || {
|
|
29
30
|
left: -100,
|
|
30
31
|
right: 100,
|
|
31
32
|
top: 100,
|
|
@@ -33,368 +34,406 @@ function we() {
|
|
|
33
34
|
near: 0.1,
|
|
34
35
|
far: 1e3
|
|
35
36
|
};
|
|
36
|
-
|
|
37
|
+
P = new he(c, a, u, f, S, g), B.cameras.push(P);
|
|
37
38
|
}
|
|
38
|
-
return
|
|
39
|
+
return B.cameras.push(P), P;
|
|
39
40
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const r = me(() => B.cameras[0]);
|
|
42
|
+
n("camera", r);
|
|
43
|
+
function i() {
|
|
44
|
+
r.value instanceof _ && e.aspectRatio && (r.value.aspect = e.aspectRatio.value), r.value.updateProjectionMatrix();
|
|
43
45
|
}
|
|
44
|
-
function p
|
|
45
|
-
|
|
46
|
-
f && t && (t.value = f, n("camera", t.value)), A.cameras.push(f), f instanceof U && e && (f.aspect = e.value), f.updateProjectionMatrix();
|
|
46
|
+
function l(p) {
|
|
47
|
+
B.cameras.push(p), p instanceof _ && e.aspectRatio && (p.aspect = e.aspectRatio.value), p.updateProjectionMatrix();
|
|
47
48
|
}
|
|
48
|
-
return e &&
|
|
49
|
-
activeCamera:
|
|
50
|
-
createCamera:
|
|
51
|
-
updateCamera:
|
|
52
|
-
pushCamera:
|
|
49
|
+
return e.aspectRatio && U(e.aspectRatio, i), {
|
|
50
|
+
activeCamera: r,
|
|
51
|
+
createCamera: o,
|
|
52
|
+
updateCamera: i,
|
|
53
|
+
pushCamera: l
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
|
-
const
|
|
56
|
-
function
|
|
57
|
-
function e(
|
|
58
|
-
console.error(`${
|
|
56
|
+
const fe = "[TresJS ▲ ■ ●] ";
|
|
57
|
+
function $() {
|
|
58
|
+
function e(r, i) {
|
|
59
|
+
console.error(`${fe} ${r}`, i || "");
|
|
59
60
|
}
|
|
60
|
-
function n(
|
|
61
|
-
console.warn(`${
|
|
61
|
+
function n(r) {
|
|
62
|
+
console.warn(`${fe} ${r}`);
|
|
62
63
|
}
|
|
63
|
-
function r
|
|
64
|
+
function o(r, i) {
|
|
64
65
|
}
|
|
65
66
|
return {
|
|
66
67
|
logError: e,
|
|
67
68
|
logWarning: n,
|
|
68
|
-
logMessage:
|
|
69
|
+
logMessage: o
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
|
-
const
|
|
72
|
-
delete
|
|
73
|
-
let
|
|
74
|
-
function
|
|
75
|
-
const { logError:
|
|
76
|
-
!
|
|
77
|
-
const { createComponentInstances:
|
|
72
|
+
const N = R({ ...ce, uuid: ce.MathUtils.generateUUID() });
|
|
73
|
+
delete N.value.Scene;
|
|
74
|
+
let O;
|
|
75
|
+
function Se(e, n = "Tres") {
|
|
76
|
+
const { logError: o } = $();
|
|
77
|
+
!O && e && (O = e);
|
|
78
|
+
const { createComponentInstances: r } = Me(n);
|
|
78
79
|
return {
|
|
79
|
-
extend: (
|
|
80
|
-
if (!
|
|
81
|
-
|
|
80
|
+
extend: (l) => {
|
|
81
|
+
if (!l) {
|
|
82
|
+
o("No objects provided to extend catalogue");
|
|
82
83
|
return;
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
N.value = Object.assign(N.value, l);
|
|
86
|
+
const p = r(R(l));
|
|
87
|
+
O && p.forEach(([t, s]) => {
|
|
88
|
+
O._context.components[t] || O.component(t, s);
|
|
88
89
|
});
|
|
89
90
|
},
|
|
90
|
-
catalogue:
|
|
91
|
+
catalogue: N
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
|
-
const
|
|
94
|
-
function
|
|
95
|
-
return typeof e == "number" ? [e, e, e] : e instanceof
|
|
94
|
+
const A = (e) => typeof e < "u", Qe = (e) => typeof e == "function", G = (e) => !!e && e.constructor === Array;
|
|
95
|
+
function Ze(e) {
|
|
96
|
+
return typeof e == "number" ? [e, e, e] : e instanceof je ? [e.x, e.y, e.z] : e;
|
|
96
97
|
}
|
|
97
|
-
function
|
|
98
|
-
return e instanceof
|
|
98
|
+
function et(e) {
|
|
99
|
+
return e instanceof X ? e : Array.isArray(e) ? new X(...e) : new X(e);
|
|
99
100
|
}
|
|
100
|
-
const
|
|
101
|
-
function
|
|
101
|
+
const tt = ["rotation", "scale", "position"];
|
|
102
|
+
function Me(e) {
|
|
102
103
|
const {
|
|
103
104
|
/* logMessage, */
|
|
104
105
|
logError: n
|
|
105
|
-
} =
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
106
|
+
} = $();
|
|
107
|
+
function o(t, s) {
|
|
108
|
+
A(t) && A(s) && Object.entries(t).forEach(([c, a]) => {
|
|
109
|
+
const u = c.replace(/(-\w)/g, (f) => f[1].toUpperCase());
|
|
110
|
+
s.setAttribute(u, new De(...a));
|
|
110
111
|
});
|
|
111
112
|
}
|
|
112
|
-
function
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
if (!(
|
|
116
|
-
|
|
113
|
+
function r(t, s) {
|
|
114
|
+
A(t) && A(s) && Object.entries(t).forEach(([c, a]) => {
|
|
115
|
+
const u = c.replace(/(-\w)/g, (f) => f[1].toUpperCase());
|
|
116
|
+
if (!(u === "args" || a === void 0)) {
|
|
117
|
+
tt.includes(u) && a && (a = Ze(a)), t.ref && (t.ref = s);
|
|
117
118
|
try {
|
|
118
|
-
if (
|
|
119
|
-
|
|
119
|
+
if (s[u] && A(s[u].set))
|
|
120
|
+
s[u].set(...G(a) ? a : [a]);
|
|
120
121
|
else {
|
|
121
|
-
if (a === "" && (a = !0),
|
|
122
|
-
if (
|
|
122
|
+
if (a === "" && (a = !0), Qe(s[u])) {
|
|
123
|
+
if (c === "center" && !a)
|
|
123
124
|
return;
|
|
124
|
-
|
|
125
|
+
s[u](...G(a) ? a : [a]);
|
|
125
126
|
return;
|
|
126
127
|
}
|
|
127
|
-
|
|
128
|
+
s[u] = a;
|
|
128
129
|
}
|
|
129
|
-
} catch (
|
|
130
|
-
n(`There was an error setting ${
|
|
130
|
+
} catch (f) {
|
|
131
|
+
n(`There was an error setting ${u} property`, f);
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
});
|
|
134
135
|
}
|
|
135
|
-
function
|
|
136
|
-
var a,
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
139
|
-
return t.children.map((
|
|
140
|
-
if (
|
|
136
|
+
function i(t) {
|
|
137
|
+
var a, u;
|
|
138
|
+
const s = /^Symbol\(Fragment\)$/g, c = /^Symbol\(Text\)$/g;
|
|
139
|
+
if (s.test(t.type.toString()))
|
|
140
|
+
return t.children.map((f) => i(f));
|
|
141
|
+
if (c.test(t.type.toString()))
|
|
141
142
|
return;
|
|
142
143
|
{
|
|
143
|
-
const
|
|
144
|
+
const f = t.type.name.replace(e, ""), { catalogue: S } = Se(), g = de("catalogue") || S;
|
|
144
145
|
let w;
|
|
145
146
|
if (g)
|
|
146
147
|
if ((a = t.children) != null && a.default) {
|
|
147
|
-
const
|
|
148
|
-
w = new g.value[
|
|
148
|
+
const C = t.children.default().map((b) => i(b));
|
|
149
|
+
w = new g.value[f](...C.flat().filter(Boolean));
|
|
149
150
|
} else
|
|
150
|
-
(
|
|
151
|
-
return t != null && t.props && (
|
|
151
|
+
(u = t == null ? void 0 : t.props) != null && u.args ? g != null && g.value[f] ? w = new g.value[f](...t.props.args) : n(`There is no ${f} in the catalogue`, g == null ? void 0 : g.value.uuid) : w = new g.value[f]();
|
|
152
|
+
return t != null && t.props && (f === "BufferGeometry" ? o(t.props, w) : r(t.props, w)), w;
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
|
-
function
|
|
155
|
-
if (
|
|
156
|
-
const a =
|
|
155
|
+
function l(t, s, c) {
|
|
156
|
+
if (c.default && (c != null && c.default())) {
|
|
157
|
+
const a = c.default().map((u) => i(u));
|
|
157
158
|
if (t.name === "Group") {
|
|
158
|
-
const
|
|
159
|
-
return a.forEach((
|
|
160
|
-
|
|
161
|
-
}),
|
|
159
|
+
const u = new t();
|
|
160
|
+
return a.forEach((f) => {
|
|
161
|
+
u.add(f);
|
|
162
|
+
}), u;
|
|
162
163
|
} else
|
|
163
164
|
return new t(...a.flat().filter(Boolean));
|
|
164
165
|
} else
|
|
165
|
-
return
|
|
166
|
+
return s.args ? new t(...s.args) : new t();
|
|
166
167
|
}
|
|
167
|
-
function
|
|
168
|
-
return Object.entries(t.value).filter(([
|
|
169
|
-
var a,
|
|
170
|
-
return (
|
|
171
|
-
}).map(([
|
|
172
|
-
const a = `${e}${
|
|
168
|
+
function p(t) {
|
|
169
|
+
return Object.entries(t.value).filter(([s, c]) => {
|
|
170
|
+
var a, u;
|
|
171
|
+
return (u = (a = c == null ? void 0 : c.prototype) == null ? void 0 : a.constructor) == null ? void 0 : u.toString().includes("class");
|
|
172
|
+
}).map(([s, c]) => {
|
|
173
|
+
const a = `${e}${s}`, u = Z({
|
|
173
174
|
name: a,
|
|
174
|
-
setup(
|
|
175
|
-
const {
|
|
176
|
-
let
|
|
177
|
-
|
|
178
|
-
let
|
|
179
|
-
if (
|
|
175
|
+
setup(f, { slots: S, attrs: g, ...w }) {
|
|
176
|
+
const { state: C } = T(), { onLoop: b } = re(), h = C.scene, j = C.raycaster, { pushCamera: E } = ye();
|
|
177
|
+
let v = l(c, g, S);
|
|
178
|
+
r(g, v), (v instanceof _ || v instanceof he) && E(v), v.isObject3D && (h == null || h.add(v));
|
|
179
|
+
let M = null, y = null;
|
|
180
|
+
if (v instanceof ke) {
|
|
180
181
|
b(() => {
|
|
181
|
-
if (
|
|
182
|
-
const
|
|
183
|
-
|
|
182
|
+
if (v && j && (h != null && h.children)) {
|
|
183
|
+
const z = j.intersectObjects(h == null ? void 0 : h.children);
|
|
184
|
+
z.length > 0 ? (y = z[0], (M === null || M.object.uuid !== (y == null ? void 0 : y.object.uuid)) && w.emit("pointer-enter", y), w.emit("pointer-move", y)) : (y = null, M !== null && w.emit("pointer-leave", M)), M = y;
|
|
184
185
|
}
|
|
185
186
|
});
|
|
186
|
-
const
|
|
187
|
-
w.emit("click",
|
|
187
|
+
const k = Oe(window, "click", () => {
|
|
188
|
+
w.emit("click", M);
|
|
188
189
|
});
|
|
189
|
-
|
|
190
|
-
|
|
190
|
+
ge(() => {
|
|
191
|
+
k();
|
|
191
192
|
});
|
|
192
193
|
}
|
|
193
|
-
return
|
|
194
|
+
return h && v instanceof ze && (h.fog = v), w.expose(v), () => {
|
|
194
195
|
};
|
|
195
196
|
}
|
|
196
197
|
});
|
|
197
|
-
return [a,
|
|
198
|
+
return [a, u];
|
|
198
199
|
});
|
|
199
200
|
}
|
|
200
201
|
return {
|
|
201
|
-
createComponentInstances:
|
|
202
|
-
processProps:
|
|
203
|
-
createInstanceFromVNode:
|
|
202
|
+
createComponentInstances: p,
|
|
203
|
+
processProps: r,
|
|
204
|
+
createInstanceFromVNode: i
|
|
204
205
|
};
|
|
205
206
|
}
|
|
206
|
-
const
|
|
207
|
-
let
|
|
208
|
-
const { pause:
|
|
207
|
+
const Ce = te(), Ee = te(), ne = te(), F = new ve();
|
|
208
|
+
let V = 0, W = 0;
|
|
209
|
+
const { pause: nt, resume: rt, isActive: ot } = Ae(
|
|
209
210
|
() => {
|
|
210
|
-
|
|
211
|
+
Ce.trigger({ delta: V, elapsed: W, clock: F }), Ee.trigger({ delta: V, elapsed: W, clock: F }), ne.trigger({ delta: V, elapsed: W, clock: F });
|
|
211
212
|
},
|
|
212
213
|
{ immediate: !1 }
|
|
213
214
|
);
|
|
214
|
-
|
|
215
|
-
|
|
215
|
+
ne.on(() => {
|
|
216
|
+
V = F.getDelta(), W = F.getElapsedTime();
|
|
216
217
|
});
|
|
217
|
-
function
|
|
218
|
+
function re() {
|
|
218
219
|
return {
|
|
219
|
-
onBeforeLoop:
|
|
220
|
-
onLoop:
|
|
221
|
-
onAfterLoop:
|
|
222
|
-
pause:
|
|
223
|
-
resume:
|
|
224
|
-
isActive:
|
|
220
|
+
onBeforeLoop: Ce.on,
|
|
221
|
+
onLoop: Ee.on,
|
|
222
|
+
onAfterLoop: ne.on,
|
|
223
|
+
pause: nt,
|
|
224
|
+
resume: rt,
|
|
225
|
+
isActive: ot
|
|
225
226
|
};
|
|
226
227
|
}
|
|
227
|
-
const
|
|
228
|
-
function
|
|
228
|
+
const at = ee(new Ue());
|
|
229
|
+
function st() {
|
|
229
230
|
return {
|
|
230
|
-
scene:
|
|
231
|
+
scene: at
|
|
231
232
|
};
|
|
232
233
|
}
|
|
233
|
-
function
|
|
234
|
+
function it(e) {
|
|
234
235
|
const n = { nodes: {}, materials: {} };
|
|
235
|
-
return e && e.traverse((
|
|
236
|
-
|
|
236
|
+
return e && e.traverse((o) => {
|
|
237
|
+
o.name && (n.nodes[o.name] = o), o.material && !n.materials[o.material.name] && (n.materials[o.material.name] = o.material);
|
|
237
238
|
}), n;
|
|
238
239
|
}
|
|
239
|
-
async function
|
|
240
|
-
const { logError:
|
|
241
|
-
|
|
242
|
-
const
|
|
243
|
-
(
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
(
|
|
247
|
-
|
|
240
|
+
async function gt(e, n, o, r, i) {
|
|
241
|
+
const { logError: l } = $(), p = new e();
|
|
242
|
+
i && i(p), o && o(p);
|
|
243
|
+
const s = (Array.isArray(n) ? n : [n]).map(
|
|
244
|
+
(c) => new Promise((a, u) => {
|
|
245
|
+
p.load(
|
|
246
|
+
c,
|
|
247
|
+
(f) => {
|
|
248
|
+
f.scene && Object.assign(f, it(f.scene)), a(f);
|
|
248
249
|
},
|
|
249
|
-
|
|
250
|
-
(
|
|
250
|
+
r,
|
|
251
|
+
(f) => u(l("[useLoader] - Failed to load resource", f))
|
|
251
252
|
);
|
|
252
253
|
})
|
|
253
254
|
);
|
|
254
|
-
return
|
|
255
|
+
return G(n) ? await Promise.all(s) : await s[0];
|
|
255
256
|
}
|
|
256
|
-
async function
|
|
257
|
-
const n = new _e(),
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
(t) =>
|
|
257
|
+
async function wt(e) {
|
|
258
|
+
const n = new _e(), o = new Ne(n), r = (i) => new Promise((l, p) => {
|
|
259
|
+
o.load(
|
|
260
|
+
i,
|
|
261
|
+
(t) => l(t),
|
|
261
262
|
() => null,
|
|
262
263
|
() => {
|
|
263
|
-
|
|
264
|
+
p(new Error("[useTextures] - Failed to load texture"));
|
|
264
265
|
}
|
|
265
266
|
);
|
|
266
267
|
});
|
|
267
|
-
if (
|
|
268
|
-
const
|
|
269
|
-
return e.length > 1 ?
|
|
268
|
+
if (G(e)) {
|
|
269
|
+
const i = await Promise.all(e.map((l) => r(l)));
|
|
270
|
+
return e.length > 1 ? i : i[0];
|
|
270
271
|
} else {
|
|
271
|
-
const { map:
|
|
272
|
+
const { map: i, displacementMap: l, normalMap: p, roughnessMap: t, metalnessMap: s, aoMap: c } = e;
|
|
272
273
|
return {
|
|
273
|
-
map:
|
|
274
|
-
displacementMap:
|
|
275
|
-
normalMap:
|
|
276
|
-
roughnessMap: t ? await
|
|
277
|
-
metalnessMap:
|
|
278
|
-
aoMap:
|
|
274
|
+
map: i ? await r(i) : null,
|
|
275
|
+
displacementMap: l ? await r(l) : null,
|
|
276
|
+
normalMap: p ? await r(p) : null,
|
|
277
|
+
roughnessMap: t ? await r(t) : null,
|
|
278
|
+
metalnessMap: s ? await r(s) : null,
|
|
279
|
+
aoMap: c ? await r(c) : null
|
|
279
280
|
};
|
|
280
281
|
}
|
|
281
282
|
}
|
|
282
|
-
const
|
|
283
|
-
function
|
|
284
|
-
function e(
|
|
285
|
-
return
|
|
283
|
+
const D = be({});
|
|
284
|
+
function T() {
|
|
285
|
+
function e(o) {
|
|
286
|
+
return D[o];
|
|
286
287
|
}
|
|
287
|
-
function n(
|
|
288
|
-
|
|
288
|
+
function n(o, r) {
|
|
289
|
+
D[o] = r;
|
|
289
290
|
}
|
|
290
291
|
return {
|
|
291
|
-
state:
|
|
292
|
-
...
|
|
292
|
+
state: D,
|
|
293
|
+
...we(D),
|
|
293
294
|
getState: e,
|
|
294
295
|
setState: n
|
|
295
296
|
};
|
|
296
297
|
}
|
|
297
|
-
const
|
|
298
|
-
function
|
|
298
|
+
const Y = ee(new Ve()), I = R(new We()), pe = R(null);
|
|
299
|
+
function ct() {
|
|
300
|
+
const { setState: e } = T();
|
|
301
|
+
e("raycaster", Y.value), e("pointer", I), e("currentInstance", pe), L("raycaster", Y), L("pointer", I), L("currentInstance", pe);
|
|
302
|
+
function n(o) {
|
|
303
|
+
I.value.x = o.clientX / window.innerWidth * 2 - 1, I.value.y = -(o.clientY / window.innerHeight) * 2 + 1;
|
|
304
|
+
}
|
|
305
|
+
return window.addEventListener("pointermove", n), ge(() => {
|
|
306
|
+
window.removeEventListener("pointermove", n);
|
|
307
|
+
}), {
|
|
308
|
+
raycaster: Y,
|
|
309
|
+
pointer: I
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
const q = {
|
|
313
|
+
realistic: {
|
|
314
|
+
physicallyCorrectLights: !0,
|
|
315
|
+
outputEncoding: Ge,
|
|
316
|
+
toneMapping: He,
|
|
317
|
+
toneMappingExposure: 3,
|
|
318
|
+
shadowMap: {
|
|
319
|
+
enabled: !0,
|
|
320
|
+
type: Ke
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}, Re = (e, n) => {
|
|
324
|
+
for (const o of Object.keys(n))
|
|
325
|
+
n[o] instanceof Object && Object.assign(n[o], Re(e[o], n[o]));
|
|
326
|
+
return Object.assign(e || {}, n), e;
|
|
327
|
+
}, d = ee(), Q = R(!1);
|
|
328
|
+
function ut(e, n, o) {
|
|
299
329
|
const {
|
|
300
|
-
alpha:
|
|
301
|
-
antialias:
|
|
302
|
-
depth:
|
|
303
|
-
logarithmicDepthBuffer:
|
|
330
|
+
alpha: r = !0,
|
|
331
|
+
antialias: i = !0,
|
|
332
|
+
depth: l,
|
|
333
|
+
logarithmicDepthBuffer: p,
|
|
304
334
|
failIfMajorPerformanceCaveat: t,
|
|
305
|
-
precision:
|
|
306
|
-
premultipliedAlpha:
|
|
335
|
+
precision: s,
|
|
336
|
+
premultipliedAlpha: c,
|
|
307
337
|
stencil: a,
|
|
308
|
-
shadows:
|
|
309
|
-
shadowMapType:
|
|
338
|
+
shadows: u = !1,
|
|
339
|
+
shadowMapType: f = Je,
|
|
310
340
|
physicallyCorrectLights: S = !1,
|
|
311
|
-
outputEncoding: g =
|
|
312
|
-
toneMapping: w =
|
|
313
|
-
toneMappingExposure:
|
|
341
|
+
outputEncoding: g = ue,
|
|
342
|
+
toneMapping: w = le,
|
|
343
|
+
toneMappingExposure: C = 1,
|
|
314
344
|
context: b = void 0,
|
|
315
|
-
powerPreference:
|
|
316
|
-
preserveDrawingBuffer:
|
|
317
|
-
clearColor:
|
|
318
|
-
windowSize:
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
345
|
+
powerPreference: h = "default",
|
|
346
|
+
preserveDrawingBuffer: j = !1,
|
|
347
|
+
clearColor: E,
|
|
348
|
+
windowSize: v = !1,
|
|
349
|
+
preset: M = void 0
|
|
350
|
+
} = we(o), { width: y, height: k } = m(v) ? Ie() : Fe(n), { logError: z } = $(), { pixelRatio: oe } = $e(), { pause: xe, resume: Pe } = re(), H = me(() => y.value / k.value), ae = () => {
|
|
351
|
+
d.value && (d.value.setSize(y.value, k.value), d.value.setPixelRatio(Math.min(oe.value, 2)));
|
|
352
|
+
}, se = () => {
|
|
353
|
+
if (!d.value)
|
|
354
|
+
return;
|
|
355
|
+
const x = m(M);
|
|
356
|
+
if (x) {
|
|
357
|
+
x in q || z("Renderer Preset must be one of these: " + Object.keys(q).join(", ")), Re(d.value, q[x]);
|
|
326
358
|
return;
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
359
|
+
}
|
|
360
|
+
d.value.shadowMap.enabled = m(u), d.value.shadowMap.type = m(f), d.value.toneMapping = m(w) || le, d.value.toneMappingExposure = m(C), d.value.outputEncoding = m(g) || ue, E != null && E.value && d.value.setClearColor(et(m(E))), d.value.physicallyCorrectLights = m(S);
|
|
361
|
+
}, Le = () => {
|
|
362
|
+
const x = J(e);
|
|
363
|
+
if (d.value || !x)
|
|
364
|
+
return;
|
|
365
|
+
d.value = new Xe({
|
|
366
|
+
canvas: x,
|
|
367
|
+
alpha: m(r),
|
|
368
|
+
antialias: m(i),
|
|
331
369
|
context: m(b),
|
|
332
|
-
depth: m(
|
|
370
|
+
depth: m(l),
|
|
333
371
|
failIfMajorPerformanceCaveat: m(t),
|
|
334
|
-
logarithmicDepthBuffer: m(
|
|
335
|
-
powerPreference: m(
|
|
336
|
-
precision: m(
|
|
372
|
+
logarithmicDepthBuffer: m(p),
|
|
373
|
+
powerPreference: m(h),
|
|
374
|
+
precision: m(s),
|
|
337
375
|
stencil: m(a),
|
|
338
|
-
preserveDrawingBuffer: m(
|
|
339
|
-
premultipliedAlpha: m(
|
|
376
|
+
preserveDrawingBuffer: m(j),
|
|
377
|
+
premultipliedAlpha: m(c)
|
|
340
378
|
});
|
|
341
|
-
const { setState:
|
|
342
|
-
|
|
343
|
-
},
|
|
344
|
-
d.value && (d.value.dispose(), d.value = void 0,
|
|
379
|
+
const { setState: K } = T();
|
|
380
|
+
K("renderer", d.value), K("clock", new ve()), K("aspectRatio", H), se(), ae(), Pe(), Q.value = !0;
|
|
381
|
+
}, Te = () => {
|
|
382
|
+
d.value && (d.value.dispose(), d.value = void 0, Q.value = !1, xe());
|
|
345
383
|
};
|
|
346
|
-
return
|
|
347
|
-
[
|
|
348
|
-
|
|
349
|
-
),
|
|
384
|
+
return U([H, oe], ae), U(
|
|
385
|
+
[u, f, g, S, w, C, E],
|
|
386
|
+
se
|
|
387
|
+
), U(
|
|
350
388
|
() => [e, n],
|
|
351
389
|
() => {
|
|
352
|
-
|
|
390
|
+
J(e) && J(n) && Le();
|
|
353
391
|
},
|
|
354
392
|
{ immediate: !0, deep: !0 }
|
|
355
393
|
), {
|
|
356
394
|
renderer: d,
|
|
357
|
-
isReady:
|
|
358
|
-
dispose:
|
|
359
|
-
aspectRatio:
|
|
395
|
+
isReady: Q,
|
|
396
|
+
dispose: Te,
|
|
397
|
+
aspectRatio: H
|
|
360
398
|
};
|
|
361
399
|
}
|
|
362
|
-
const
|
|
400
|
+
const lt = Z({
|
|
363
401
|
name: "TresCanvas",
|
|
364
402
|
props: {
|
|
365
403
|
shadows: Boolean,
|
|
366
|
-
shadowMapType:
|
|
404
|
+
shadowMapType: Number,
|
|
367
405
|
physicallyCorrectLights: Boolean,
|
|
368
|
-
outputEncoding:
|
|
369
|
-
toneMapping:
|
|
406
|
+
outputEncoding: Number,
|
|
407
|
+
toneMapping: Number,
|
|
370
408
|
toneMappingExposure: Number,
|
|
371
409
|
context: Object,
|
|
372
|
-
powerPreference:
|
|
410
|
+
powerPreference: String,
|
|
373
411
|
preserveDrawingBuffer: Boolean,
|
|
374
412
|
clearColor: String,
|
|
375
|
-
windowSize: { type: Boolean, default: !1 }
|
|
413
|
+
windowSize: { type: Boolean, default: !1 },
|
|
414
|
+
preset: String
|
|
376
415
|
},
|
|
377
|
-
setup(e, { slots: n, attrs:
|
|
378
|
-
const { logError:
|
|
379
|
-
return
|
|
380
|
-
var
|
|
381
|
-
return (
|
|
382
|
-
}) &&
|
|
416
|
+
setup(e, { slots: n, attrs: o }) {
|
|
417
|
+
const { logError: r } = $(), i = R(), l = R(), { renderer: p, dispose: t, aspectRatio: s } = ut(i, l, e);
|
|
418
|
+
return L("aspect-ratio", s), L("renderer", p), n.default && !n.default().some((c) => c.type.name === "Scene") && r("TresCanvas must contain a Scene component."), n.default && !n.default().some((c) => {
|
|
419
|
+
var a;
|
|
420
|
+
return (a = c.type.name) == null ? void 0 : a.includes("Camera");
|
|
421
|
+
}) && r("Scene must contain a Camera component."), Be(() => t()), () => {
|
|
383
422
|
if (n.default)
|
|
384
|
-
return
|
|
423
|
+
return ie(
|
|
385
424
|
"div",
|
|
386
425
|
{
|
|
387
|
-
ref:
|
|
426
|
+
ref: l,
|
|
388
427
|
style: {
|
|
389
428
|
position: "relative",
|
|
390
429
|
width: "100%",
|
|
391
430
|
height: "100vh",
|
|
392
|
-
...
|
|
431
|
+
...o.style
|
|
393
432
|
}
|
|
394
433
|
},
|
|
395
434
|
[
|
|
396
|
-
|
|
397
|
-
ref:
|
|
435
|
+
ie("canvas", {
|
|
436
|
+
ref: i,
|
|
398
437
|
style: {
|
|
399
438
|
width: "100%",
|
|
400
439
|
height: "100%",
|
|
@@ -408,57 +447,42 @@ const Ze = X({
|
|
|
408
447
|
);
|
|
409
448
|
};
|
|
410
449
|
}
|
|
411
|
-
}),
|
|
412
|
-
function tt() {
|
|
413
|
-
x("raycaster", le), x("pointer", D), x("currentInstance", et);
|
|
414
|
-
function e(n) {
|
|
415
|
-
D.value.x = n.clientX / window.innerWidth * 2 - 1, D.value.y = -(n.clientY / window.innerHeight) * 2 + 1;
|
|
416
|
-
}
|
|
417
|
-
return window.addEventListener("pointermove", e), pe(() => {
|
|
418
|
-
window.removeEventListener("pointermove", e);
|
|
419
|
-
}), {
|
|
420
|
-
raycaster: le,
|
|
421
|
-
pointer: D
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
const nt = X({
|
|
450
|
+
}), ft = Z({
|
|
425
451
|
name: "Scene",
|
|
426
452
|
setup(e, { slots: n }) {
|
|
427
|
-
const { scene: r } =
|
|
428
|
-
return
|
|
429
|
-
p.value.setFromCamera(
|
|
453
|
+
const { setState: o } = T(), { scene: r } = st(), i = de("renderer"), { activeCamera: l } = ye(), { raycaster: p, pointer: t } = ct(), { onLoop: s } = re();
|
|
454
|
+
return L("local-scene", r), o("scene", r.value), s(() => {
|
|
455
|
+
p.value.setFromCamera(t.value, l.value), i != null && i.value && (l != null && l.value) && (r != null && r.value) && i.value.render(r == null ? void 0 : r.value, l.value);
|
|
430
456
|
}), () => {
|
|
431
457
|
if (n.default)
|
|
432
458
|
return n.default();
|
|
433
459
|
};
|
|
434
460
|
}
|
|
435
|
-
}),
|
|
461
|
+
}), ht = Symbol("UseTresState"), vt = {
|
|
436
462
|
install(e, n) {
|
|
437
|
-
const
|
|
438
|
-
e.component(`${
|
|
439
|
-
const { catalogue:
|
|
440
|
-
e.provide("catalogue",
|
|
441
|
-
const { createComponentInstances:
|
|
442
|
-
|
|
443
|
-
e.component(t,
|
|
444
|
-
})
|
|
445
|
-
app: e,
|
|
446
|
-
version: rt
|
|
447
|
-
};
|
|
463
|
+
const o = (n == null ? void 0 : n.prefix) || "Tres";
|
|
464
|
+
e.component(`${o}Canvas`, lt), e.component(`${o}Scene`, ft);
|
|
465
|
+
const { catalogue: r, extend: i } = Se(e, o);
|
|
466
|
+
e.provide("catalogue", r), e.provide("extend", i), e.provide("useTres", T());
|
|
467
|
+
const { createComponentInstances: l } = Me(o);
|
|
468
|
+
l(r).forEach(([t, s]) => {
|
|
469
|
+
e.component(t, s);
|
|
470
|
+
});
|
|
448
471
|
}
|
|
449
472
|
};
|
|
450
473
|
export {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
474
|
+
Ye as CameraType,
|
|
475
|
+
ht as UseTresStateSymbol,
|
|
476
|
+
vt as default,
|
|
477
|
+
it as trasverseObjects,
|
|
478
|
+
ye as useCamera,
|
|
479
|
+
Se as useCatalogue,
|
|
480
|
+
Me as useInstanceCreator,
|
|
481
|
+
gt as useLoader,
|
|
482
|
+
ct as useRaycaster,
|
|
483
|
+
re as useRenderLoop,
|
|
484
|
+
ut as useRenderer,
|
|
485
|
+
st as useScene,
|
|
486
|
+
wt as useTexture,
|
|
487
|
+
T as useTres
|
|
464
488
|
};
|
package/dist/tres.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v1.
|
|
3
|
+
* version: v1.7.0
|
|
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(h,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):(h=typeof globalThis<"u"?globalThis:h||self,o(h.tres={},h.Vue,h.VueUseCore,h.Three))})(this,function(h,o,f,m){"use strict";function ue(e){const n=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(n,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return n.default=e,Object.freeze(n)}const Z=ue(m);var E=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(E||{});const j={cameras:[]},fe=45;let O;function G(){const e=o.inject("aspect-ratio"),{setState:n}=N();function r(d="Perspective",t){if(d==="Perspective"){const{near:s,far:u,fov:i}=t||{near:.1,far:1e3,fov:fe};O=new m.PerspectiveCamera(i,(e==null?void 0:e.value)||1,s,u),j.cameras.push(O)}else{const{left:s,right:u,top:i,bottom:l,near:p,far:U}=t||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};O=new m.OrthographicCamera(s,u,i,l,p,U),j.cameras.push(O)}return j.cameras.push(O),O}const a=o.computed(()=>j.cameras[0]);function c(){a.value instanceof m.PerspectiveCamera&&e&&(a.value.aspect=e.value),a.value.updateProjectionMatrix()}function g(d){const t=o.inject("camera");d&&t&&(t.value=d,n("camera",t.value)),j.cameras.push(d),d instanceof m.PerspectiveCamera&&e&&(d.aspect=e.value),d.updateProjectionMatrix()}return e&&o.watch(e,c),{activeCamera:a,createCamera:r,updateCamera:c,pushCamera:g}}const H="[TresJS ▲ ■ ●] ";function D(){function e(a,c){console.error(`${H} ${a}`,c||"")}function n(a){console.warn(`${H} ${a}`)}function r(a,c){}return{logError:e,logWarning:n,logMessage:r}}const $=o.ref({...Z,uuid:Z.MathUtils.generateUUID()});delete $.value.Scene;let _;function K(e,n="Tres"){const{logError:r}=D();!_&&e&&(_=e);const{createComponentInstances:a}=J(n);return{extend:g=>{if(!g){r("No objects provided to extend catalogue");return}$.value=Object.assign($.value,g);const d=a(o.ref(g));_&&d.forEach(([t,s])=>{_._context.components[t]||_.component(t,s)})},catalogue:$}}const A=e=>typeof e<"u",pe=e=>typeof e=="function",k=e=>!!e&&e.constructor===Array;function de(e){return typeof e=="number"?[e,e,e]:e instanceof m.Vector3?[e.x,e.y,e.z]:e}function me(e){return e instanceof m.Color?e:Array.isArray(e)?new m.Color(...e):new m.Color(e)}const ge=["rotation","scale","position"];function J(e){const{logError:n}=D();function r(t,s){A(t)&&A(s)&&Object.entries(t).forEach(([u,i])=>{const l=u.replace(/(-\w)/g,p=>p[1].toUpperCase());s.setAttribute(l,new m.BufferAttribute(...i))})}function a(t,s){A(t)&&A(s)&&Object.entries(t).forEach(([u,i])=>{const l=u.replace(/(-\w)/g,p=>p[1].toUpperCase());if(!(l==="args"||i===void 0)){ge.includes(l)&&i&&(i=de(i)),t.ref&&(t.ref=s);try{if(s[l]&&A(s[l].set))s[l].set(...k(i)?i:[i]);else{if(i===""&&(i=!0),pe(s[l])){if(u==="center"&&!i)return;s[l](...k(i)?i:[i]);return}s[l]=i}}catch(p){n(`There was an error setting ${l} property`,p)}}})}function c(t){var i,l;const s=/^Symbol\(Fragment\)$/g,u=/^Symbol\(Text\)$/g;if(s.test(t.type.toString()))return t.children.map(p=>c(p));if(u.test(t.type.toString()))return;{const p=t.type.name.replace(e,""),{catalogue:U}=K(),v=o.inject("catalogue")||U;let y;if(v)if((i=t.children)!=null&&i.default){const x=t.children.default().map(I=>c(I));y=new v.value[p](...x.flat().filter(Boolean))}else(l=t==null?void 0:t.props)!=null&&l.args?v!=null&&v.value[p]?y=new v.value[p](...t.props.args):n(`There is no ${p} in the catalogue`,v==null?void 0:v.value.uuid):y=new v.value[p];return t!=null&&t.props&&(p==="BufferGeometry"?r(t.props,y):a(t.props,y)),y}}function g(t,s,u){if(u.default&&(u!=null&&u.default())){const i=u.default().map(l=>c(l));if(t.name==="Group"){const l=new t;return i.forEach(p=>{l.add(p)}),l}else return new t(...i.flat().filter(Boolean))}else return s.args?new t(...s.args):new t}function d(t){return Object.entries(t.value).filter(([s,u])=>{var i,l;return(l=(i=u==null?void 0:u.prototype)==null?void 0:i.constructor)==null?void 0:l.toString().includes("class")}).map(([s,u])=>{const i=`${e}${s}`,l=o.defineComponent({name:i,setup(p,{slots:U,attrs:v,...y}){const{scene:x}=Y(),{onLoop:I}=T(),M=o.inject("local-scene")||x,L=o.inject("raycaster"),{pushCamera:b}=G();let C=g(u,v,U);a(v,C),(C instanceof m.PerspectiveCamera||C instanceof m.OrthographicCamera)&&b(C),C.isObject3D&&(M==null||M.value.add(C));let P=null,S=null;if(C.isMesh){I(()=>{if(C&&(L!=null&&L.value)){const q=L==null?void 0:L.value.intersectObjects(M.value.children);q.length>0?(S=q[0],(P===null||P.object.uuid!==(S==null?void 0:S.object.uuid))&&y.emit("pointer-enter",S),y.emit("pointer-move",S)):(S=null,P!==null&&y.emit("pointer-leave",P)),P=S}});const W=f.useEventListener(window,"click",()=>{y.emit("click",P)});o.onUnmounted(()=>{W()})}return M!=null&&M.value&&C.isFog&&(M.value.fog=C),y.expose(C),()=>{}}});return[i,l]})}return{createComponentInstances:d,processProps:a,createInstanceFromVNode:c}}const ee=f.createEventHook(),te=f.createEventHook(),X=f.createEventHook(),B=new m.Clock;let F=0,z=0;const{pause:he,resume:we,isActive:ve}=f.useRafFn(()=>{ee.trigger({delta:F,elapsed:z,clock:B}),te.trigger({delta:F,elapsed:z,clock:B}),X.trigger({delta:F,elapsed:z,clock:B})},{immediate:!1});X.on(()=>{F=B.getDelta(),z=B.getElapsedTime()});function T(){return{onBeforeLoop:ee.on,onLoop:te.on,onAfterLoop:X.on,pause:he,resume:we,isActive:ve}}const ye=o.shallowRef(new m.Scene);function Y(){return{scene:ye}}function ne(e){const n={nodes:{},materials:{}};return e&&e.traverse(r=>{r.name&&(n.nodes[r.name]=r),r.material&&!n.materials[r.material.name]&&(n.materials[r.material.name]=r.material)}),n}async function Ce(e,n,r,a,c){const{logError:g}=D(),d=new e;c&&c(d),r&&r(d);const s=(Array.isArray(n)?n:[n]).map(u=>new Promise((i,l)=>{d.load(u,p=>{p.scene&&Object.assign(p,ne(p.scene)),i(p)},a,p=>l(g("[useLoader] - Failed to load resource",p)))}));return k(n)?await Promise.all(s):await s[0]}async function Se(e){const n=new m.LoadingManager,r=new m.TextureLoader(n),a=c=>new Promise((g,d)=>{r.load(c,t=>g(t),()=>null,()=>{d(new Error("[useTextures] - Failed to load texture"))})});if(k(e)){const c=await Promise.all(e.map(g=>a(g)));return e.length>1?c:c[0]}else{const{map:c,displacementMap:g,normalMap:d,roughnessMap:t,metalnessMap:s,aoMap:u}=e;return{map:c?await a(c):null,displacementMap:g?await a(g):null,normalMap:d?await a(d):null,roughnessMap:t?await a(t):null,metalnessMap:s?await a(s):null,aoMap:u?await a(u):null}}}const V=o.shallowReactive({});function N(){function e(r){return V[r]}function n(r,a){V[r]=a}return{state:V,...o.toRefs(V),getState:e,setState:n}}const w=o.shallowRef(),Q=o.ref(!1);function re(e,n,r){const{alpha:a=!0,antialias:c=!0,depth:g,logarithmicDepthBuffer:d,failIfMajorPerformanceCaveat:t,precision:s,premultipliedAlpha:u,stencil:i,shadows:l=!1,shadowMapType:p=m.PCFShadowMap,physicallyCorrectLights:U=!1,outputEncoding:v=m.LinearEncoding,toneMapping:y=m.NoToneMapping,toneMappingExposure:x=1,context:I=void 0,powerPreference:M="default",preserveDrawingBuffer:L=!1,clearColor:b,windowSize:C=!1}=o.toRefs(r),{width:P,height:S}=f.resolveUnref(C)?f.useWindowSize():f.useElementSize(n),{pixelRatio:W}=f.useDevicePixelRatio(),{pause:q,resume:je}=T(),ae=o.computed(()=>P.value/S.value),ie=()=>{w.value&&(w.value.setSize(P.value,S.value),w.value.setPixelRatio(Math.min(W.value,2)))},se=()=>{w.value&&(w.value.shadowMap.enabled=f.resolveUnref(l),w.value.shadowMap.type=f.resolveUnref(p),w.value.toneMapping=f.resolveUnref(y)||m.NoToneMapping,w.value.toneMappingExposure=f.resolveUnref(x),w.value.outputEncoding=f.resolveUnref(v)||m.LinearEncoding,b!=null&&b.value&&w.value.setClearColor(me(f.resolveUnref(b))),w.value.physicallyCorrectLights=f.resolveUnref(U))},_e=()=>{const ce=f.unrefElement(e);if(w.value||!ce)return;w.value=new m.WebGLRenderer({canvas:ce,alpha:f.resolveUnref(a),antialias:f.resolveUnref(c),context:f.resolveUnref(I),depth:f.resolveUnref(g),failIfMajorPerformanceCaveat:f.resolveUnref(t),logarithmicDepthBuffer:f.resolveUnref(d),powerPreference:f.resolveUnref(M),precision:f.resolveUnref(s),stencil:f.resolveUnref(i),preserveDrawingBuffer:f.resolveUnref(L),premultipliedAlpha:f.resolveUnref(u)});const{setState:le}=N();le("renderer",w.value),le("clock",new m.Clock),se(),ie(),je(),Q.value=!0},Ae=()=>{w.value&&(w.value.dispose(),w.value=void 0,Q.value=!1,q())};return o.watch([ae,W],ie),o.watch([l,p,v,U,y,x,b],se),o.watch(()=>[e,n],()=>{f.unrefElement(e)&&f.unrefElement(n)&&_e()},{immediate:!0,deep:!0}),{renderer:w,isReady:Q,dispose:Ae,aspectRatio:ae}}const Me=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:{type:Boolean,default:!1}},setup(e,{slots:n,attrs:r}){const{logError:a}=D(),c=o.ref(),g=o.ref(),{renderer:d,dispose:t,aspectRatio:s}=re(c,g,e),u=o.shallowRef();return o.provide("aspect-ratio",s),o.provide("renderer",d),o.provide("camera",u),n.default&&!n.default().some(i=>i.type.name==="Scene")&&a("TresCanvas must contain a Scene component."),n.default&&!n.default().some(i=>{var l;return(l=i.type.name)==null?void 0:l.includes("Camera")})&&a("Scene must contain a Camera component."),o.onBeforeUnmount(()=>t()),()=>{if(n.default)return o.h("div",{ref:g,style:{position:"relative",width:"100%",height:"100vh",...r.style}},[o.h("canvas",{ref:c,style:{width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}}),n.default()])}}}),oe=o.shallowRef(new m.Raycaster),R=o.ref(new m.Vector2),Pe=o.ref(null);function Ue(){o.provide("raycaster",oe),o.provide("pointer",R),o.provide("currentInstance",Pe);function e(n){R.value.x=n.clientX/window.innerWidth*2-1,R.value.y=-(n.clientY/window.innerHeight)*2+1}return window.addEventListener("pointermove",e),o.onUnmounted(()=>{window.removeEventListener("pointermove",e)}),{raycaster:oe,pointer:R}}const Le=o.defineComponent({name:"Scene",setup(e,{slots:n}){const{scene:r}=Y(),a=o.inject("renderer"),{activeCamera:c}=G(),{raycaster:g,pointer:d}=Ue(),{onLoop:t}=T();return o.provide("local-scene",r),t(()=>{g.value.setFromCamera(d.value,c.value),a!=null&&a.value&&(c!=null&&c.value)&&(r!=null&&r.value)&&a.value.render(r==null?void 0:r.value,c.value)}),()=>{if(n.default)return n.default()}}}),be=Symbol("UseTresState"),Oe="1.6.3",xe={install(e,n){const r=(n==null?void 0:n.prefix)||"Tres";e.component(`${r}Canvas`,Me),e.component(`${r}Scene`,Le);const{catalogue:a,extend:c}=K(e,r);e.provide("catalogue",a),e.provide("extend",c),e.provide("useTres",N());const{createComponentInstances:g}=J(r);g(a).forEach(([t,s])=>{e.component(t,s)}),window.__TRES__={app:e,version:Oe}}};h.CameraType=E,h.UseTresStateSymbol=be,h.default=xe,h.trasverseObjects=ne,h.useCamera=G,h.useCatalogue=K,h.useInstanceCreator=J,h.useLoader=Ce,h.useRenderLoop=T,h.useRenderer=re,h.useScene=Y,h.useTexture=Se,h.useTres=N,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
8
|
+
(function(h,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):(h=typeof globalThis<"u"?globalThis:h||self,o(h.tres={},h.Vue,h.VueUseCore,h.Three))})(this,function(h,o,f,p){"use strict";function ge(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 te=ge(p);var ne=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(ne||{});const B={cameras:[]},he=45;let x;function K(){const{state:e,setState:t}=U();function r(g="Perspective",n){var i;if(g==="Perspective"){const{near:l,far:s,fov:u}=n||{near:.1,far:1e3,fov:he};x=new p.PerspectiveCamera(u,((i=e.aspectRatio)==null?void 0:i.value)||1,l,s),B.cameras.push(x)}else{const{left:l,right:s,top:u,bottom:m,near:P,far:y}=n||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};x=new p.OrthographicCamera(l,s,u,m,P,y),B.cameras.push(x)}return B.cameras.push(x),x}const a=o.computed(()=>B.cameras[0]);t("camera",a);function c(){a.value instanceof p.PerspectiveCamera&&e.aspectRatio&&(a.value.aspect=e.aspectRatio.value),a.value.updateProjectionMatrix()}function d(g){B.cameras.push(g),g instanceof p.PerspectiveCamera&&e.aspectRatio&&(g.aspect=e.aspectRatio.value),g.updateProjectionMatrix()}return e.aspectRatio&&o.watch(e.aspectRatio,c),{activeCamera:a,createCamera:r,updateCamera:c,pushCamera:d}}const re="[TresJS ▲ ■ ●] ";function I(){function e(a,c){console.error(`${re} ${a}`,c||"")}function t(a){console.warn(`${re} ${a}`)}function r(a,c){}return{logError:e,logWarning:t,logMessage:r}}const $=o.ref({...te,uuid:te.MathUtils.generateUUID()});delete $.value.Scene;let A;function J(e,t="Tres"){const{logError:r}=I();!A&&e&&(A=e);const{createComponentInstances:a}=X(t);return{extend:d=>{if(!d){r("No objects provided to extend catalogue");return}$.value=Object.assign($.value,d);const g=a(o.ref(d));A&&g.forEach(([n,i])=>{A._context.components[n]||A.component(n,i)})},catalogue:$}}const k=e=>typeof e<"u",we=e=>typeof e=="function",z=e=>!!e&&e.constructor===Array;function ye(e){return typeof e=="number"?[e,e,e]:e instanceof p.Vector3?[e.x,e.y,e.z]:e}function ve(e){return e instanceof p.Color?e:Array.isArray(e)?new p.Color(...e):new p.Color(e)}const Ce=["rotation","scale","position"];function X(e){const{logError:t}=I();function r(n,i){k(n)&&k(i)&&Object.entries(n).forEach(([l,s])=>{const u=l.replace(/(-\w)/g,m=>m[1].toUpperCase());i.setAttribute(u,new p.BufferAttribute(...s))})}function a(n,i){k(n)&&k(i)&&Object.entries(n).forEach(([l,s])=>{const u=l.replace(/(-\w)/g,m=>m[1].toUpperCase());if(!(u==="args"||s===void 0)){Ce.includes(u)&&s&&(s=ye(s)),n.ref&&(n.ref=i);try{if(i[u]&&k(i[u].set))i[u].set(...z(s)?s:[s]);else{if(s===""&&(s=!0),we(i[u])){if(l==="center"&&!s)return;i[u](...z(s)?s:[s]);return}i[u]=s}}catch(m){t(`There was an error setting ${u} property`,m)}}})}function c(n){var s,u;const i=/^Symbol\(Fragment\)$/g,l=/^Symbol\(Text\)$/g;if(i.test(n.type.toString()))return n.children.map(m=>c(m));if(l.test(n.type.toString()))return;{const m=n.type.name.replace(e,""),{catalogue:P}=J(),y=o.inject("catalogue")||P;let v;if(y)if((s=n.children)!=null&&s.default){const L=n.children.default().map(D=>c(D));v=new y.value[m](...L.flat().filter(Boolean))}else(u=n==null?void 0:n.props)!=null&&u.args?y!=null&&y.value[m]?v=new y.value[m](...n.props.args):t(`There is no ${m} in the catalogue`,y==null?void 0:y.value.uuid):v=new y.value[m];return n!=null&&n.props&&(m==="BufferGeometry"?r(n.props,v):a(n.props,v)),v}}function d(n,i,l){if(l.default&&(l!=null&&l.default())){const s=l.default().map(u=>c(u));if(n.name==="Group"){const u=new n;return s.forEach(m=>{u.add(m)}),u}else return new n(...s.flat().filter(Boolean))}else return i.args?new n(...i.args):new n}function g(n){return Object.entries(n.value).filter(([i,l])=>{var s,u;return(u=(s=l==null?void 0:l.prototype)==null?void 0:s.constructor)==null?void 0:u.toString().includes("class")}).map(([i,l])=>{const s=`${e}${i}`,u=o.defineComponent({name:s,setup(m,{slots:P,attrs:y,...v}){const{state:L}=U(),{onLoop:D}=V(),C=L.scene,W=L.raycaster,{pushCamera:O}=K();let S=d(l,y,P);a(y,S),(S instanceof p.PerspectiveCamera||S instanceof p.OrthographicCamera)&&O(S),S.isObject3D&&(C==null||C.add(S));let b=null,M=null;if(S instanceof p.Mesh){D(()=>{if(S&&W&&(C!=null&&C.children)){const q=W.intersectObjects(C==null?void 0:C.children);q.length>0?(M=q[0],(b===null||b.object.uuid!==(M==null?void 0:M.object.uuid))&&v.emit("pointer-enter",M),v.emit("pointer-move",M)):(M=null,b!==null&&v.emit("pointer-leave",b)),b=M}});const G=f.useEventListener(window,"click",()=>{v.emit("click",b)});o.onUnmounted(()=>{G()})}return C&&S instanceof p.Fog&&(C.fog=S),v.expose(S),()=>{}}});return[s,u]})}return{createComponentInstances:g,processProps:a,createInstanceFromVNode:c}}const ae=f.createEventHook(),oe=f.createEventHook(),Y=f.createEventHook(),_=new p.Clock;let N=0,R=0;const{pause:Se,resume:Me,isActive:Pe}=f.useRafFn(()=>{ae.trigger({delta:N,elapsed:R,clock:_}),oe.trigger({delta:N,elapsed:R,clock:_}),Y.trigger({delta:N,elapsed:R,clock:_})},{immediate:!1});Y.on(()=>{N=_.getDelta(),R=_.getElapsedTime()});function V(){return{onBeforeLoop:ae.on,onLoop:oe.on,onAfterLoop:Y.on,pause:Se,resume:Me,isActive:Pe}}const be=o.shallowRef(new p.Scene);function se(){return{scene:be}}function ie(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 Ue(e,t,r,a,c){const{logError:d}=I(),g=new e;c&&c(g),r&&r(g);const i=(Array.isArray(t)?t:[t]).map(l=>new Promise((s,u)=>{g.load(l,m=>{m.scene&&Object.assign(m,ie(m.scene)),s(m)},a,m=>u(d("[useLoader] - Failed to load resource",m)))}));return z(t)?await Promise.all(i):await i[0]}async function Le(e){const t=new p.LoadingManager,r=new p.TextureLoader(t),a=c=>new Promise((d,g)=>{r.load(c,n=>d(n),()=>null,()=>{g(new Error("[useTextures] - Failed to load texture"))})});if(z(e)){const c=await Promise.all(e.map(d=>a(d)));return e.length>1?c:c[0]}else{const{map:c,displacementMap:d,normalMap:g,roughnessMap:n,metalnessMap:i,aoMap:l}=e;return{map:c?await a(c):null,displacementMap:d?await a(d):null,normalMap:g?await a(g):null,roughnessMap:n?await a(n):null,metalnessMap:i?await a(i):null,aoMap:l?await a(l):null}}}const T=o.shallowReactive({});function U(){function e(r){return T[r]}function t(r,a){T[r]=a}return{state:T,...o.toRefs(T),getState:e,setState:t}}const Q=o.shallowRef(new p.Raycaster),F=o.ref(new p.Vector2),ce=o.ref(null);function le(){const{setState:e}=U();e("raycaster",Q.value),e("pointer",F),e("currentInstance",ce),o.provide("raycaster",Q),o.provide("pointer",F),o.provide("currentInstance",ce);function t(r){F.value.x=r.clientX/window.innerWidth*2-1,F.value.y=-(r.clientY/window.innerHeight)*2+1}return window.addEventListener("pointermove",t),o.onUnmounted(()=>{window.removeEventListener("pointermove",t)}),{raycaster:Q,pointer:F}}const Z={realistic:{physicallyCorrectLights:!0,outputEncoding:p.sRGBEncoding,toneMapping:p.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:p.PCFSoftShadowMap}}},ue=(e,t)=>{for(const r of Object.keys(t))t[r]instanceof Object&&Object.assign(t[r],ue(e[r],t[r]));return Object.assign(e||{},t),e},w=o.shallowRef(),E=o.ref(!1);function fe(e,t,r){const{alpha:a=!0,antialias:c=!0,depth:d,logarithmicDepthBuffer:g,failIfMajorPerformanceCaveat:n,precision:i,premultipliedAlpha:l,stencil:s,shadows:u=!1,shadowMapType:m=p.PCFShadowMap,physicallyCorrectLights:P=!1,outputEncoding:y=p.LinearEncoding,toneMapping:v=p.NoToneMapping,toneMappingExposure:L=1,context:D=void 0,powerPreference:C="default",preserveDrawingBuffer:W=!1,clearColor:O,windowSize:S=!1,preset:b=void 0}=o.toRefs(r),{width:M,height:G}=f.resolveUnref(S)?f.useWindowSize():f.useElementSize(t),{logError:q}=I(),{pixelRatio:pe}=f.useDevicePixelRatio(),{pause:Ie,resume:Ae}=V(),H=o.computed(()=>M.value/G.value),de=()=>{w.value&&(w.value.setSize(M.value,G.value),w.value.setPixelRatio(Math.min(pe.value,2)))},me=()=>{if(!w.value)return;const j=f.resolveUnref(b);if(j){j in Z||q("Renderer Preset must be one of these: "+Object.keys(Z).join(", ")),ue(w.value,Z[j]);return}w.value.shadowMap.enabled=f.resolveUnref(u),w.value.shadowMap.type=f.resolveUnref(m),w.value.toneMapping=f.resolveUnref(v)||p.NoToneMapping,w.value.toneMappingExposure=f.resolveUnref(L),w.value.outputEncoding=f.resolveUnref(y)||p.LinearEncoding,O!=null&&O.value&&w.value.setClearColor(ve(f.resolveUnref(O))),w.value.physicallyCorrectLights=f.resolveUnref(P)},ke=()=>{const j=f.unrefElement(e);if(w.value||!j)return;w.value=new p.WebGLRenderer({canvas:j,alpha:f.resolveUnref(a),antialias:f.resolveUnref(c),context:f.resolveUnref(D),depth:f.resolveUnref(d),failIfMajorPerformanceCaveat:f.resolveUnref(n),logarithmicDepthBuffer:f.resolveUnref(g),powerPreference:f.resolveUnref(C),precision:f.resolveUnref(i),stencil:f.resolveUnref(s),preserveDrawingBuffer:f.resolveUnref(W),premultipliedAlpha:f.resolveUnref(l)});const{setState:ee}=U();ee("renderer",w.value),ee("clock",new p.Clock),ee("aspectRatio",H),me(),de(),Ae(),E.value=!0},_e=()=>{w.value&&(w.value.dispose(),w.value=void 0,E.value=!1,Ie())};return o.watch([H,pe],de),o.watch([u,m,y,P,v,L,O],me),o.watch(()=>[e,t],()=>{f.unrefElement(e)&&f.unrefElement(t)&&ke()},{immediate:!0,deep:!0}),{renderer:w,isReady:E,dispose:_e,aspectRatio:H}}const Oe=o.defineComponent({name:"TresCanvas",props:{shadows:Boolean,shadowMapType:Number,physicallyCorrectLights:Boolean,outputEncoding:Number,toneMapping:Number,toneMappingExposure:Number,context:Object,powerPreference:String,preserveDrawingBuffer:Boolean,clearColor:String,windowSize:{type:Boolean,default:!1},preset:String},setup(e,{slots:t,attrs:r}){const{logError:a}=I(),c=o.ref(),d=o.ref(),{renderer:g,dispose:n,aspectRatio:i}=fe(c,d,e);return o.provide("aspect-ratio",i),o.provide("renderer",g),t.default&&!t.default().some(l=>l.type.name==="Scene")&&a("TresCanvas must contain a Scene component."),t.default&&!t.default().some(l=>{var s;return(s=l.type.name)==null?void 0:s.includes("Camera")})&&a("Scene must contain a Camera component."),o.onBeforeUnmount(()=>n()),()=>{if(t.default)return o.h("div",{ref:d,style:{position:"relative",width:"100%",height:"100vh",...r.style}},[o.h("canvas",{ref:c,style:{width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}}),t.default()])}}}),xe=o.defineComponent({name:"Scene",setup(e,{slots:t}){const{setState:r}=U(),{scene:a}=se(),c=o.inject("renderer"),{activeCamera:d}=K(),{raycaster:g,pointer:n}=le(),{onLoop:i}=V();return o.provide("local-scene",a),r("scene",a.value),i(()=>{g.value.setFromCamera(n.value,d.value),c!=null&&c.value&&(d!=null&&d.value)&&(a!=null&&a.value)&&c.value.render(a==null?void 0:a.value,d.value)}),()=>{if(t.default)return t.default()}}}),je=Symbol("UseTresState"),Be={install(e,t){const r=(t==null?void 0:t.prefix)||"Tres";e.component(`${r}Canvas`,Oe),e.component(`${r}Scene`,xe);const{catalogue:a,extend:c}=J(e,r);e.provide("catalogue",a),e.provide("extend",c),e.provide("useTres",U());const{createComponentInstances:d}=X(r);d(a).forEach(([n,i])=>{e.component(n,i)})}};h.CameraType=ne,h.UseTresStateSymbol=je,h.default=Be,h.trasverseObjects=ie,h.useCamera=K,h.useCatalogue=J,h.useInstanceCreator=X,h.useLoader=Ue,h.useRaycaster=le,h.useRenderLoop=V,h.useRenderer=fe,h.useScene=se,h.useTexture=Le,h.useTres=U,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
import { Object3D } from 'three'
|
|
2
|
-
import { VNode, VNodeTypes } from 'vue'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export type TresCatalogue = Record<string, any
|
|
1
|
+
import { Color, Intersection, Object3D, Vector2, Vector3, Event } from 'three';
|
|
2
|
+
import { VNode, VNodeTypes } from 'vue';
|
|
3
|
+
export type TresInstance = Object3D<Event> & {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
};
|
|
6
|
+
export type TresCatalogue = Record<string, any>;
|
|
7
7
|
export type TresVNodeType = VNodeTypes & {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
export type TresVNode = VNode & {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
name?: string | Array<string>;
|
|
9
|
+
__name?: string;
|
|
10
|
+
setup?: (props: Readonly<any>) => void;
|
|
11
|
+
};
|
|
12
|
+
export type TresVNode = VNode & {
|
|
13
|
+
children?: Array<VNode | {
|
|
14
|
+
default: any;
|
|
15
|
+
}>;
|
|
16
|
+
type: TresVNodeType;
|
|
17
|
+
};
|
|
18
|
+
export type TresAttributes = Record<string, any> & {
|
|
19
|
+
args?: number[];
|
|
20
|
+
};
|
|
21
|
+
export type TresColor = string | number | Color | number[];
|
|
17
22
|
export interface TresEvent extends Intersection<Object3D<Event>> {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
uv?: Vector2
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
declare global {
|
|
27
|
-
// Define the window interface, with type annotations for the properties and methods of the window object
|
|
28
|
-
interface Window {
|
|
29
|
-
// Define the location property, with a type of Location
|
|
30
|
-
__TRES__: {
|
|
31
|
-
app: App
|
|
32
|
-
version: string
|
|
33
|
-
}
|
|
34
|
-
}
|
|
23
|
+
object: Object3D;
|
|
24
|
+
distance: number;
|
|
25
|
+
faceIndex?: number | undefined;
|
|
26
|
+
point: Vector3;
|
|
27
|
+
uv?: Vector2;
|
|
35
28
|
}
|
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": "1.
|
|
4
|
+
"version": "1.7.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
7
7
|
"files": [
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"import": "./dist/tres.js",
|
|
17
17
|
"require": "./dist/tres.umd.cjs"
|
|
18
18
|
},
|
|
19
|
+
"./types": {
|
|
20
|
+
"require": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.d.ts"
|
|
22
|
+
},
|
|
19
23
|
"./styles": "./dist/style.css",
|
|
20
24
|
"./*": "./dist/tres.js"
|
|
21
25
|
},
|
|
@@ -30,15 +34,15 @@
|
|
|
30
34
|
"threejs-vue"
|
|
31
35
|
],
|
|
32
36
|
"peerDependencies": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
37
|
+
"three": "latest",
|
|
38
|
+
"vue": "^3.2.47"
|
|
35
39
|
},
|
|
36
40
|
"dependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
41
|
+
"@alvarosabu/utils": "^2.3.0",
|
|
42
|
+
"@vueuse/core": "^9.13.0"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
41
|
-
"@tresjs/cientos": "^1.
|
|
45
|
+
"@tresjs/cientos": "^1.7.0",
|
|
42
46
|
"@types/three": "latest",
|
|
43
47
|
"@vitejs/plugin-vue": "^4.0.0",
|
|
44
48
|
"@vitest/coverage-c8": "^0.28.4",
|
|
@@ -47,14 +51,14 @@
|
|
|
47
51
|
"happy-dom": "^8.2.6",
|
|
48
52
|
"kolorist": "^1.7.0",
|
|
49
53
|
"pathe": "^1.1.0",
|
|
50
|
-
"release-it": "^15.6.0",
|
|
51
54
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
52
55
|
"rollup-plugin-visualizer": "^5.9.0",
|
|
53
|
-
"
|
|
54
|
-
"vite": "^4.1.
|
|
56
|
+
"three": "latest",
|
|
57
|
+
"vite": "^4.1.2",
|
|
55
58
|
"vite-plugin-banner": "^0.7.0",
|
|
56
|
-
"vite-plugin-dts": "
|
|
59
|
+
"vite-plugin-dts": "2.0.0-beta.1",
|
|
57
60
|
"vite-plugin-glsl": "^1.1.2",
|
|
61
|
+
"vite-plugin-inspect": "^0.7.15",
|
|
58
62
|
"vite-plugin-require-transform": "^1.0.9",
|
|
59
63
|
"vitest": "^0.28.4",
|
|
60
64
|
"vue-demi": "^0.13.11"
|