@tresjs/core 2.0.0-alpha.6 → 2.0.0-beta.1
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 +8 -2
- package/dist/components/TresCanvas.d.ts +3 -0
- package/dist/components/TresScene.d.ts +19 -0
- package/dist/composables/useRenderer/index.d.ts +2 -3
- package/dist/composables/useTres/index.d.ts +8 -1
- package/dist/tres.js +314 -271
- package/dist/tres.umd.cjs +3 -3
- package/dist/utils/normalize.d.ts +2 -2
- package/package.json +21 -18
package/README.md
CHANGED
|
@@ -17,11 +17,17 @@ Checkout the [docs](https://tresjs.org)
|
|
|
17
17
|
|
|
18
18
|
- [Stackblitz Collection](https://stackblitz.com/@alvarosabu/collections/tresjs)
|
|
19
19
|
|
|
20
|
+
## Ecosystem
|
|
21
|
+
|
|
22
|
+
| Package | Version |
|
|
23
|
+
| --------------------------- | :------------------------------------------------------------------------------------------------ |
|
|
24
|
+
| [Tres](packages/tres) |  |
|
|
25
|
+
| [Cientos](packages/cientos) |  |
|
|
26
|
+
|
|
20
27
|
## Contribution
|
|
21
28
|
|
|
22
29
|
We are open to contributions, please read the [contributing guide](/CONTRIBUTING.md) to get started.
|
|
23
30
|
|
|
24
|
-
|
|
25
31
|
### Setup
|
|
26
32
|
|
|
27
33
|
```
|
|
@@ -64,4 +70,4 @@ pnpm run docs:build
|
|
|
64
70
|
|
|
65
71
|
## Sponsors
|
|
66
72
|
|
|
67
|
-
Be the first to support this project [here](https://github.com/sponsors/alvarosabu) ☺️
|
|
73
|
+
Be the first to support this project [here](https://github.com/sponsors/alvarosabu) ☺️
|
|
@@ -15,5 +15,8 @@ export interface TresCanvasProps {
|
|
|
15
15
|
windowSize?: boolean;
|
|
16
16
|
preset?: RendererPresetsType;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Vue component for rendering a Tres component.
|
|
20
|
+
*/
|
|
18
21
|
export declare const TresCanvas: import("vue").DefineComponent<TresCanvasProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<TresCanvasProps>, {}>;
|
|
19
22
|
export default TresCanvas;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ShadowMapType, TextureEncoding, ToneMapping } from 'three';
|
|
2
|
+
import { RendererPresetsType } from '../composables/useRenderer/const';
|
|
3
|
+
export interface TresSceneProps {
|
|
4
|
+
shadows?: boolean;
|
|
5
|
+
shadowMapType?: ShadowMapType;
|
|
6
|
+
physicallyCorrectLights?: boolean;
|
|
7
|
+
useLegacyLights?: boolean;
|
|
8
|
+
outputEncoding?: TextureEncoding;
|
|
9
|
+
toneMapping?: ToneMapping;
|
|
10
|
+
toneMappingExposure?: number;
|
|
11
|
+
context?: WebGLRenderingContext;
|
|
12
|
+
powerPreference?: 'high-performance' | 'low-power' | 'default';
|
|
13
|
+
preserveDrawingBuffer?: boolean;
|
|
14
|
+
clearColor?: string;
|
|
15
|
+
windowSize?: boolean;
|
|
16
|
+
preset?: RendererPresetsType;
|
|
17
|
+
}
|
|
18
|
+
export declare const TresScene: import("vue").DefineComponent<TresSceneProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<TresSceneProps>, {}>;
|
|
19
|
+
export default TresScene;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MaybeComputedRef
|
|
1
|
+
import { MaybeComputedRef } 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';
|
|
@@ -85,10 +85,9 @@ export interface UseRendererOptions extends WebGLRendererParameters {
|
|
|
85
85
|
* Reactive Three.js WebGLRenderer instance
|
|
86
86
|
*
|
|
87
87
|
* @param canvas
|
|
88
|
-
* @param container
|
|
89
88
|
* @param {UseRendererOptions} [options]
|
|
90
89
|
*/
|
|
91
|
-
export declare function useRenderer(
|
|
90
|
+
export declare function useRenderer(options: UseRendererOptions): {
|
|
92
91
|
renderer: import("vue").ShallowRef<WebGLRenderer | undefined>;
|
|
93
92
|
isReady: import("vue").Ref<boolean>;
|
|
94
93
|
dispose: () => void;
|
|
@@ -89,6 +89,12 @@ export interface TresState {
|
|
|
89
89
|
}) | null;
|
|
90
90
|
[key: string]: any;
|
|
91
91
|
}
|
|
92
|
+
export type UseTresReturn = {
|
|
93
|
+
state: TresState;
|
|
94
|
+
getState: (key: string) => void;
|
|
95
|
+
setState: (key: string, value: any) => void;
|
|
96
|
+
aspectRatio: ComputedRef<number>;
|
|
97
|
+
};
|
|
92
98
|
/**
|
|
93
99
|
* The Tres state.
|
|
94
100
|
*
|
|
@@ -97,7 +103,7 @@ export interface TresState {
|
|
|
97
103
|
* @export
|
|
98
104
|
* @return {*} {TresState, getState, setState}
|
|
99
105
|
*/
|
|
100
|
-
export declare function
|
|
106
|
+
export declare function useTresProvider(): {
|
|
101
107
|
getState: (key: string) => any;
|
|
102
108
|
setState: (key: string, value: any) => void;
|
|
103
109
|
camera?: import("vue").Ref<Camera | undefined> | undefined;
|
|
@@ -114,3 +120,4 @@ export declare function useTres(): {
|
|
|
114
120
|
}) | null | undefined> | undefined;
|
|
115
121
|
state: TresState;
|
|
116
122
|
};
|
|
123
|
+
export declare const useTres: () => UseTresReturn;
|
package/dist/tres.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v2.0.0-
|
|
3
|
+
* version: v2.0.0-beta.1
|
|
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
|
|
15
|
-
let
|
|
16
|
-
function
|
|
17
|
-
const { state: e, setState: t, aspectRatio:
|
|
18
|
-
function
|
|
19
|
-
var
|
|
20
|
-
if (
|
|
21
|
-
const { near:
|
|
8
|
+
import { ref as M, watchEffect as oe, toRef as ke, shallowRef as ie, toRefs as se, computed as ce, watch as z, shallowReactive as ue, provide as Ae, inject as Oe, createRenderer as je, defineComponent as fe, onMounted as _e, onUnmounted as Be, h as L } from "vue";
|
|
9
|
+
import * as le from "three";
|
|
10
|
+
import { MathUtils as De, PerspectiveCamera as O, OrthographicCamera as ze, Clock as de, Color as W, sRGBEncoding as We, ACESFilmicToneMapping as Fe, PCFSoftShadowMap as Ie, PCFShadowMap as He, LinearEncoding as ee, NoToneMapping as te, WebGLRenderer as Ue, LoadingManager as $e, TextureLoader as Ge, Raycaster as Ne, Vector2 as Ve, Mesh as qe, BufferAttribute as Ye } from "three";
|
|
11
|
+
import { createEventHook as $, useRafFn as Ke, resolveUnref as f, useWindowSize as Xe, useElementSize as Je, useDevicePixelRatio as Qe, unrefElement as F, useEventListener as Ze, isFunction as ne } from "@vueuse/core";
|
|
12
|
+
const H = M({ uuid: De.generateUUID() }), pe = (e) => void Object.assign(H.value, e);
|
|
13
|
+
var et = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(et || {});
|
|
14
|
+
const tt = 45;
|
|
15
|
+
let x;
|
|
16
|
+
function U() {
|
|
17
|
+
const { state: e, setState: t, aspectRatio: r } = S();
|
|
18
|
+
function a(o = "Perspective", c) {
|
|
19
|
+
var u, l, p;
|
|
20
|
+
if (o === "Perspective") {
|
|
21
|
+
const { near: d, far: w, fov: v } = c || {
|
|
22
22
|
near: 0.1,
|
|
23
23
|
far: 1e3,
|
|
24
|
-
fov:
|
|
24
|
+
fov: tt
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
x = new O(v, ((u = e.aspectRatio) == null ? void 0 : u.value) || window.innerWidth / window.innerHeight, d, w), (l = e.cameras) == null || l.push(x);
|
|
27
27
|
} else {
|
|
28
|
-
const { left:
|
|
28
|
+
const { left: d, right: w, top: v, bottom: b, near: g, far: P } = c || {
|
|
29
29
|
left: -100,
|
|
30
30
|
right: 100,
|
|
31
31
|
top: 100,
|
|
@@ -33,321 +33,337 @@ function le() {
|
|
|
33
33
|
near: 0.1,
|
|
34
34
|
far: 1e3
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
x = new ze(d, w, v, b, g, P), (p = e.cameras) == null || p.push(x);
|
|
37
37
|
}
|
|
38
|
-
return e.camera =
|
|
38
|
+
return e.camera = x, t("camera", e.camera), x;
|
|
39
39
|
}
|
|
40
40
|
function n() {
|
|
41
|
-
var
|
|
42
|
-
e.camera instanceof
|
|
41
|
+
var o;
|
|
42
|
+
e.camera instanceof O && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (o = e.camera) == null || o.updateProjectionMatrix();
|
|
43
43
|
}
|
|
44
|
-
function i(
|
|
45
|
-
var
|
|
46
|
-
(
|
|
44
|
+
function i(o) {
|
|
45
|
+
var c;
|
|
46
|
+
(c = e.cameras) == null || c.push(o), o instanceof O && e.aspectRatio && (o.aspect = e.aspectRatio.value), o.updateProjectionMatrix(), t("camera", o);
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function s() {
|
|
49
49
|
e.cameras = [];
|
|
50
50
|
}
|
|
51
|
-
return
|
|
52
|
-
|
|
51
|
+
return oe(() => {
|
|
52
|
+
r != null && r.value && n();
|
|
53
53
|
}), {
|
|
54
|
-
activeCamera:
|
|
55
|
-
createCamera:
|
|
54
|
+
activeCamera: ke(e, "camera"),
|
|
55
|
+
createCamera: a,
|
|
56
56
|
updateCamera: n,
|
|
57
57
|
pushCamera: i,
|
|
58
|
-
clearCameras:
|
|
58
|
+
clearCameras: s
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
const
|
|
62
|
-
let j = 0,
|
|
63
|
-
const { pause:
|
|
61
|
+
const me = $(), ve = $(), G = $(), E = new de();
|
|
62
|
+
let j = 0, _ = 0;
|
|
63
|
+
const { pause: nt, resume: at, isActive: rt } = Ke(
|
|
64
64
|
() => {
|
|
65
|
-
|
|
65
|
+
me.trigger({ delta: j, elapsed: _, clock: E }), ve.trigger({ delta: j, elapsed: _, clock: E }), G.trigger({ delta: j, elapsed: _, clock: E });
|
|
66
66
|
},
|
|
67
67
|
{ immediate: !1 }
|
|
68
68
|
);
|
|
69
|
-
|
|
70
|
-
j =
|
|
69
|
+
G.on(() => {
|
|
70
|
+
j = E.getDelta(), _ = E.getElapsedTime();
|
|
71
71
|
});
|
|
72
|
-
function
|
|
72
|
+
function N() {
|
|
73
73
|
return {
|
|
74
|
-
onBeforeLoop:
|
|
75
|
-
onLoop:
|
|
76
|
-
onAfterLoop:
|
|
77
|
-
pause:
|
|
78
|
-
resume:
|
|
79
|
-
isActive:
|
|
74
|
+
onBeforeLoop: me.on,
|
|
75
|
+
onLoop: ve.on,
|
|
76
|
+
onAfterLoop: G.on,
|
|
77
|
+
pause: nt,
|
|
78
|
+
resume: at,
|
|
79
|
+
isActive: rt
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
function
|
|
83
|
-
return e instanceof
|
|
82
|
+
function ot(e) {
|
|
83
|
+
return e instanceof W ? e : Array.isArray(e) ? new W(...e) : new W(e);
|
|
84
84
|
}
|
|
85
85
|
const I = {
|
|
86
86
|
realistic: {
|
|
87
|
-
outputEncoding:
|
|
88
|
-
toneMapping:
|
|
87
|
+
outputEncoding: We,
|
|
88
|
+
toneMapping: Fe,
|
|
89
89
|
toneMappingExposure: 3,
|
|
90
90
|
shadowMap: {
|
|
91
91
|
enabled: !0,
|
|
92
|
-
type:
|
|
92
|
+
type: Ie
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
},
|
|
96
|
-
for (const
|
|
97
|
-
t[
|
|
95
|
+
}, ge = (e, t) => {
|
|
96
|
+
for (const r of Object.keys(t))
|
|
97
|
+
t[r] instanceof Object && Object.assign(t[r], ge(e[r], t[r]));
|
|
98
98
|
return Object.assign(e || {}, t), e;
|
|
99
|
-
},
|
|
100
|
-
function
|
|
101
|
-
return e.replace(/-([a-z])/g, (t,
|
|
99
|
+
}, it = "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", st = /* @__PURE__ */ ct(it);
|
|
100
|
+
function R(e) {
|
|
101
|
+
return e.replace(/-([a-z])/g, (t, r) => r.toUpperCase());
|
|
102
102
|
}
|
|
103
|
-
function
|
|
104
|
-
const
|
|
105
|
-
for (let n = 0; n <
|
|
106
|
-
|
|
107
|
-
return t ? (n) => !!
|
|
103
|
+
function ct(e, t) {
|
|
104
|
+
const r = /* @__PURE__ */ Object.create(null), a = e.split(",");
|
|
105
|
+
for (let n = 0; n < a.length; n++)
|
|
106
|
+
r[a[n]] = !0;
|
|
107
|
+
return t ? (n) => !!r[n.toLowerCase()] : (n) => !!r[n];
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
alpha: r = !0,
|
|
109
|
+
function ut(e) {
|
|
110
|
+
var Q, Z;
|
|
111
|
+
const t = ie(), r = M(!1), {
|
|
112
|
+
alpha: a = !0,
|
|
114
113
|
antialias: n = !0,
|
|
115
114
|
depth: i,
|
|
116
|
-
logarithmicDepthBuffer:
|
|
117
|
-
failIfMajorPerformanceCaveat:
|
|
118
|
-
precision:
|
|
119
|
-
premultipliedAlpha:
|
|
115
|
+
logarithmicDepthBuffer: s,
|
|
116
|
+
failIfMajorPerformanceCaveat: o,
|
|
117
|
+
precision: c,
|
|
118
|
+
premultipliedAlpha: u,
|
|
120
119
|
stencil: l,
|
|
121
120
|
shadows: p = !1,
|
|
122
|
-
shadowMapType:
|
|
121
|
+
shadowMapType: d = He,
|
|
123
122
|
physicallyCorrectLights: w = !1,
|
|
124
123
|
useLegacyLights: v = !1,
|
|
125
|
-
outputEncoding:
|
|
126
|
-
toneMapping:
|
|
127
|
-
toneMappingExposure:
|
|
128
|
-
context:
|
|
129
|
-
powerPreference:
|
|
130
|
-
preserveDrawingBuffer:
|
|
124
|
+
outputEncoding: b = ee,
|
|
125
|
+
toneMapping: g = te,
|
|
126
|
+
toneMappingExposure: P = 1,
|
|
127
|
+
context: ye = void 0,
|
|
128
|
+
powerPreference: xe = "default",
|
|
129
|
+
preserveDrawingBuffer: Me = !1,
|
|
131
130
|
clearColor: C,
|
|
132
131
|
windowSize: V = !1,
|
|
133
|
-
preset:
|
|
134
|
-
} =
|
|
135
|
-
!
|
|
132
|
+
preset: Ce = void 0
|
|
133
|
+
} = se(e), { state: h, setState: B } = S(), { width: q, height: Y } = f(V) ? Xe() : Je(h.container), { logError: Le, logWarning: Ee } = T(), { pixelRatio: K } = Qe(), { pause: Se, resume: Te } = N(), D = ce(() => q.value / Y.value);
|
|
134
|
+
!f(V) && ((Z = (Q = h.container) == null ? void 0 : Q.value) == null ? void 0 : Z.offsetHeight) === 0 && Ee(`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
135
|
You could set windowSize=true to force the canvas to be the size of the window.`);
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
},
|
|
140
|
-
if (!
|
|
136
|
+
const X = () => {
|
|
137
|
+
t.value && (t.value.setSize(q.value, Y.value), t.value.setPixelRatio(Math.min(K.value, 2)));
|
|
138
|
+
}, J = () => {
|
|
139
|
+
if (!t.value)
|
|
141
140
|
return;
|
|
142
|
-
const
|
|
143
|
-
if (
|
|
144
|
-
|
|
141
|
+
const y = f(Ce);
|
|
142
|
+
if (y) {
|
|
143
|
+
y in I || Le("Renderer Preset must be one of these: " + Object.keys(I).join(", ")), ge(t.value, I[y]);
|
|
145
144
|
return;
|
|
146
145
|
}
|
|
147
|
-
|
|
148
|
-
},
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
canvas:
|
|
152
|
-
alpha:
|
|
153
|
-
antialias:
|
|
154
|
-
context:
|
|
155
|
-
depth:
|
|
156
|
-
failIfMajorPerformanceCaveat:
|
|
157
|
-
logarithmicDepthBuffer:
|
|
158
|
-
powerPreference:
|
|
159
|
-
precision: c
|
|
160
|
-
stencil:
|
|
161
|
-
preserveDrawingBuffer:
|
|
162
|
-
premultipliedAlpha:
|
|
163
|
-
}),
|
|
164
|
-
},
|
|
165
|
-
|
|
146
|
+
t.value.shadowMap.enabled = f(p), t.value.shadowMap.type = f(d), t.value.toneMapping = f(g) || te, t.value.toneMappingExposure = f(P), t.value.outputEncoding = f(b) || ee, C != null && C.value && t.value.setClearColor(ot(f(C))), t.value.useLegacyLights = f(v);
|
|
147
|
+
}, Pe = () => {
|
|
148
|
+
const y = F(h.canvas);
|
|
149
|
+
y && (t.value = new Ue({
|
|
150
|
+
canvas: y,
|
|
151
|
+
alpha: f(a),
|
|
152
|
+
antialias: f(n),
|
|
153
|
+
context: f(ye),
|
|
154
|
+
depth: f(i),
|
|
155
|
+
failIfMajorPerformanceCaveat: f(o),
|
|
156
|
+
logarithmicDepthBuffer: f(s),
|
|
157
|
+
powerPreference: f(xe),
|
|
158
|
+
precision: f(c),
|
|
159
|
+
stencil: f(l),
|
|
160
|
+
preserveDrawingBuffer: f(Me),
|
|
161
|
+
premultipliedAlpha: f(u)
|
|
162
|
+
}), B("renderer", t.value), B("clock", new de()), B("aspectRatio", D), J(), X(), Te(), r.value = !0);
|
|
163
|
+
}, Re = () => {
|
|
164
|
+
t.value && (t.value.dispose(), t.value = void 0, r.value = !1, Se());
|
|
166
165
|
};
|
|
167
|
-
return
|
|
168
|
-
[p,
|
|
169
|
-
|
|
170
|
-
),
|
|
171
|
-
() => [
|
|
166
|
+
return z([D, K], X), z(
|
|
167
|
+
[p, d, b, v, g, P, C],
|
|
168
|
+
J
|
|
169
|
+
), z(
|
|
170
|
+
() => [h.canvas, h.container],
|
|
172
171
|
() => {
|
|
173
|
-
F(
|
|
172
|
+
F(h.canvas) && F(h.container) && Pe();
|
|
174
173
|
},
|
|
175
174
|
{ immediate: !0, deep: !0 }
|
|
176
175
|
), {
|
|
177
|
-
renderer:
|
|
178
|
-
isReady:
|
|
179
|
-
dispose:
|
|
180
|
-
aspectRatio:
|
|
176
|
+
renderer: t,
|
|
177
|
+
isReady: r,
|
|
178
|
+
dispose: Re,
|
|
179
|
+
aspectRatio: D
|
|
181
180
|
};
|
|
182
181
|
}
|
|
183
|
-
const
|
|
184
|
-
function
|
|
182
|
+
const he = (e) => !!e && e.constructor === Array;
|
|
183
|
+
function ft(e) {
|
|
185
184
|
const t = { nodes: {}, materials: {} };
|
|
186
|
-
return e && e.traverse((
|
|
187
|
-
|
|
185
|
+
return e && e.traverse((r) => {
|
|
186
|
+
r.name && (t.nodes[r.name] = r), r.material && !t.materials[r.material.name] && (t.materials[r.material.name] = r.material);
|
|
188
187
|
}), t;
|
|
189
188
|
}
|
|
190
|
-
async function
|
|
191
|
-
const { logError: i } =
|
|
192
|
-
n && n(
|
|
193
|
-
const
|
|
194
|
-
(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
(
|
|
198
|
-
|
|
189
|
+
async function Et(e, t, r, a, n) {
|
|
190
|
+
const { logError: i } = T(), s = new e();
|
|
191
|
+
n && n(s), r && r(s);
|
|
192
|
+
const c = (Array.isArray(t) ? t : [t]).map(
|
|
193
|
+
(u) => new Promise((l, p) => {
|
|
194
|
+
s.load(
|
|
195
|
+
u,
|
|
196
|
+
(d) => {
|
|
197
|
+
d.scene && Object.assign(d, ft(d.scene)), l(d);
|
|
199
198
|
},
|
|
200
|
-
|
|
201
|
-
(
|
|
199
|
+
a,
|
|
200
|
+
(d) => p(i("[useLoader] - Failed to load resource", d))
|
|
202
201
|
);
|
|
203
202
|
})
|
|
204
203
|
);
|
|
205
|
-
return
|
|
204
|
+
return he(t) ? await Promise.all(c) : await c[0];
|
|
206
205
|
}
|
|
207
|
-
async function
|
|
208
|
-
const t = new
|
|
209
|
-
|
|
206
|
+
async function St(e) {
|
|
207
|
+
const t = new $e(), r = new Ge(t), a = (n) => new Promise((i, s) => {
|
|
208
|
+
r.load(
|
|
210
209
|
n,
|
|
211
|
-
(
|
|
210
|
+
(o) => i(o),
|
|
212
211
|
() => null,
|
|
213
212
|
() => {
|
|
214
|
-
|
|
213
|
+
s(new Error("[useTextures] - Failed to load texture"));
|
|
215
214
|
}
|
|
216
215
|
);
|
|
217
216
|
});
|
|
218
|
-
if (
|
|
219
|
-
const n = await Promise.all(e.map((i) =>
|
|
217
|
+
if (he(e)) {
|
|
218
|
+
const n = await Promise.all(e.map((i) => a(i)));
|
|
220
219
|
return e.length > 1 ? n : n[0];
|
|
221
220
|
} else {
|
|
222
221
|
const {
|
|
223
222
|
map: n,
|
|
224
223
|
displacementMap: i,
|
|
225
|
-
normalMap:
|
|
226
|
-
roughnessMap:
|
|
227
|
-
metalnessMap:
|
|
228
|
-
aoMap:
|
|
224
|
+
normalMap: s,
|
|
225
|
+
roughnessMap: o,
|
|
226
|
+
metalnessMap: c,
|
|
227
|
+
aoMap: u,
|
|
229
228
|
alphaMap: l,
|
|
230
229
|
matcap: p
|
|
231
230
|
} = e;
|
|
232
231
|
return {
|
|
233
|
-
map: n ? await
|
|
234
|
-
displacementMap: i ? await
|
|
235
|
-
normalMap:
|
|
236
|
-
roughnessMap:
|
|
237
|
-
metalnessMap:
|
|
238
|
-
aoMap:
|
|
239
|
-
alphaMap: l ? await
|
|
240
|
-
matcap: p ? await
|
|
232
|
+
map: n ? await a(n) : null,
|
|
233
|
+
displacementMap: i ? await a(i) : null,
|
|
234
|
+
normalMap: s ? await a(s) : null,
|
|
235
|
+
roughnessMap: o ? await a(o) : null,
|
|
236
|
+
metalnessMap: c ? await a(c) : null,
|
|
237
|
+
aoMap: u ? await a(u) : null,
|
|
238
|
+
alphaMap: l ? await a(l) : null,
|
|
239
|
+
matcap: p ? await a(p) : null
|
|
241
240
|
};
|
|
242
241
|
}
|
|
243
242
|
}
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
243
|
+
const m = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"];
|
|
244
|
+
function lt() {
|
|
245
|
+
const e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, r = Math.random() * 4294967295 | 0, a = Math.random() * 4294967295 | 0;
|
|
246
|
+
return (m[e & 255] + m[e >> 8 & 255] + m[e >> 16 & 255] + m[e >> 24 & 255] + "-" + m[t & 255] + m[t >> 8 & 255] + "-" + m[t >> 16 & 15 | 64] + m[t >> 24 & 255] + "-" + m[r & 63 | 128] + m[r >> 8 & 255] + "-" + m[r >> 16 & 255] + m[r >> 24 & 255] + m[a & 255] + m[a >> 8 & 255] + m[a >> 16 & 255] + m[a >> 24 & 255]).toLowerCase();
|
|
247
|
+
}
|
|
248
|
+
const we = Symbol();
|
|
249
|
+
function dt() {
|
|
250
|
+
const e = ue({
|
|
251
|
+
uuid: lt(),
|
|
252
|
+
camera: void 0,
|
|
253
|
+
cameras: [],
|
|
254
|
+
scene: void 0,
|
|
255
|
+
renderer: void 0,
|
|
256
|
+
aspectRatio: ce(() => window.innerWidth / window.innerHeight)
|
|
257
|
+
});
|
|
258
|
+
function t(n) {
|
|
259
|
+
return e[n];
|
|
254
260
|
}
|
|
255
|
-
function
|
|
256
|
-
|
|
261
|
+
function r(n, i) {
|
|
262
|
+
e[n] = i;
|
|
257
263
|
}
|
|
258
|
-
|
|
259
|
-
state:
|
|
260
|
-
...
|
|
261
|
-
getState:
|
|
262
|
-
setState:
|
|
264
|
+
const a = {
|
|
265
|
+
state: e,
|
|
266
|
+
...se(e),
|
|
267
|
+
getState: t,
|
|
268
|
+
setState: r
|
|
263
269
|
};
|
|
270
|
+
return Ae(we, a), a;
|
|
264
271
|
}
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
272
|
+
const S = () => Oe(we, {
|
|
273
|
+
state: ue({
|
|
274
|
+
camera: void 0,
|
|
275
|
+
cameras: [],
|
|
276
|
+
scene: void 0,
|
|
277
|
+
renderer: void 0
|
|
278
|
+
})
|
|
279
|
+
}), ae = ie(new Ne()), k = M(new Ve()), pt = M(null);
|
|
280
|
+
function be() {
|
|
281
|
+
const { setState: e } = S();
|
|
282
|
+
e("raycaster", ae.value), e("pointer", k), e("currentInstance", pt);
|
|
283
|
+
function t(r) {
|
|
284
|
+
k.value.x = r.clientX / window.innerWidth * 2 - 1, k.value.y = -(r.clientY / window.innerHeight) * 2 + 1;
|
|
271
285
|
}
|
|
272
286
|
return window.addEventListener("pointermove", t), {
|
|
273
|
-
raycaster:
|
|
287
|
+
raycaster: ae,
|
|
274
288
|
pointer: k
|
|
275
289
|
};
|
|
276
290
|
}
|
|
277
|
-
const
|
|
278
|
-
function
|
|
279
|
-
function e(
|
|
280
|
-
console.error(`${
|
|
291
|
+
const Tt = !0, re = "[TresJS ▲ ■ ●] ";
|
|
292
|
+
function T() {
|
|
293
|
+
function e(a, n) {
|
|
294
|
+
console.error(`${re} ${a}`, n || "");
|
|
281
295
|
}
|
|
282
|
-
function t(
|
|
283
|
-
console.warn(`${
|
|
296
|
+
function t(a) {
|
|
297
|
+
console.warn(`${re} ${a}`);
|
|
284
298
|
}
|
|
285
|
-
function
|
|
299
|
+
function r(a, n) {
|
|
286
300
|
}
|
|
287
301
|
return {
|
|
288
302
|
logError: e,
|
|
289
303
|
logWarning: t,
|
|
290
|
-
logMessage:
|
|
304
|
+
logMessage: r
|
|
291
305
|
};
|
|
292
306
|
}
|
|
293
|
-
function
|
|
294
|
-
const { logWarning: e } =
|
|
295
|
-
function t(
|
|
296
|
-
let
|
|
297
|
-
return
|
|
298
|
-
|
|
299
|
-
}),
|
|
307
|
+
function Pt() {
|
|
308
|
+
const { logWarning: e } = T();
|
|
309
|
+
function t(a, n, i) {
|
|
310
|
+
let s = null;
|
|
311
|
+
return a.traverse((o) => {
|
|
312
|
+
o[n] === i && (s = o);
|
|
313
|
+
}), s || e(`Child with ${n} '${i}' not found.`), s;
|
|
300
314
|
}
|
|
301
|
-
function
|
|
302
|
-
return t(
|
|
315
|
+
function r(a, n) {
|
|
316
|
+
return t(a, "name", n);
|
|
303
317
|
}
|
|
304
318
|
return {
|
|
305
319
|
seek: t,
|
|
306
|
-
seekByName:
|
|
320
|
+
seekByName: r
|
|
307
321
|
};
|
|
308
322
|
}
|
|
309
|
-
const { logWarning:
|
|
310
|
-
function
|
|
323
|
+
const { logWarning: mt } = T();
|
|
324
|
+
function vt(e) {
|
|
311
325
|
for (const t in e)
|
|
312
326
|
if (t.indexOf("on") === 0)
|
|
313
327
|
return !0;
|
|
314
328
|
return !1;
|
|
315
329
|
}
|
|
316
330
|
let A = null;
|
|
317
|
-
const
|
|
318
|
-
createElement(e, t,
|
|
319
|
-
if (e === "template" ||
|
|
331
|
+
const gt = {
|
|
332
|
+
createElement(e, t, r, a) {
|
|
333
|
+
if (e === "template" || st(e))
|
|
320
334
|
return null;
|
|
321
335
|
let n;
|
|
322
|
-
if (
|
|
323
|
-
(!(
|
|
336
|
+
if (a === null && (a = {}), a != null && a.args ? n = new H.value[e.replace("Tres", "")](...a.args) : n = new H.value[e.replace("Tres", "")](), n.isCamera) {
|
|
337
|
+
(!(a != null && a.position) || a != null && a.position.every((s) => s == 0)) && mt(
|
|
324
338
|
// eslint-disable-next-line max-len
|
|
325
339
|
"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 🤗"
|
|
326
340
|
);
|
|
327
|
-
const { pushCamera: i } =
|
|
341
|
+
const { pushCamera: i } = U();
|
|
328
342
|
i(n);
|
|
329
343
|
}
|
|
330
|
-
return (
|
|
344
|
+
return (a == null ? void 0 : a.attach) === void 0 && (n.isMaterial ? n.attach = "material" : n.isBufferGeometry && (n.attach = "geometry")), n;
|
|
331
345
|
},
|
|
332
|
-
insert(e, t,
|
|
346
|
+
insert(e, t, r) {
|
|
333
347
|
if (A === null && t.isScene && (A = t), t === null && (t = A), t != null && t.isObject3D && (e != null && e.isObject3D)) {
|
|
334
|
-
const
|
|
335
|
-
e.parent = t, t.children.splice(
|
|
348
|
+
const s = r ? t.children.indexOf(r) : 0;
|
|
349
|
+
e.parent = t, t.children.splice(s, 0, e), e.dispatchEvent({ type: "added" });
|
|
336
350
|
} else
|
|
337
351
|
typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
|
|
338
|
-
const { onLoop:
|
|
352
|
+
const { onLoop: a } = N();
|
|
339
353
|
let n = null, i = null;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
354
|
+
if (e && e instanceof qe && vt(e)) {
|
|
355
|
+
const { raycaster: s } = be();
|
|
356
|
+
a(() => {
|
|
357
|
+
var o, c, u;
|
|
358
|
+
if (t != null && t.children && e && s) {
|
|
359
|
+
const l = s.value.intersectObjects(t.children);
|
|
360
|
+
l.length > 0 && l[0].object.uuid === e.uuid ? (i = l[0], (n === null || n.object.uuid !== (i == null ? void 0 : i.object.uuid)) && ((o = e.onPointerEnter) == null || o.call(e, i)), (c = e.onPointerMove) == null || c.call(e, i)) : (i = null, n !== null && ((u = e.onPointerLeave) == null || u.call(e, n))), n = i;
|
|
361
|
+
}
|
|
362
|
+
}), Ze(window, "click", () => {
|
|
363
|
+
var o;
|
|
364
|
+
i !== null && ((o = e.onClick) == null || o.call(e, i));
|
|
365
|
+
});
|
|
366
|
+
}
|
|
351
367
|
},
|
|
352
368
|
remove(e) {
|
|
353
369
|
if (!e)
|
|
@@ -355,28 +371,28 @@ const ft = {
|
|
|
355
371
|
const t = e.parentNode;
|
|
356
372
|
t && t.removeChild(e);
|
|
357
373
|
},
|
|
358
|
-
patchProp(e, t,
|
|
374
|
+
patchProp(e, t, r, a) {
|
|
359
375
|
if (e) {
|
|
360
376
|
let n = e, i = t;
|
|
361
|
-
const
|
|
362
|
-
let
|
|
377
|
+
const s = R(i);
|
|
378
|
+
let o = n == null ? void 0 : n[s];
|
|
363
379
|
if (e.parent || (e.parent = A), n.type === "BufferGeometry") {
|
|
364
380
|
n.setAttribute(
|
|
365
|
-
|
|
366
|
-
new
|
|
381
|
+
R(i),
|
|
382
|
+
new Ye(...a)
|
|
367
383
|
);
|
|
368
384
|
return;
|
|
369
385
|
}
|
|
370
|
-
if (i.includes("-") &&
|
|
371
|
-
const
|
|
372
|
-
|
|
386
|
+
if (i.includes("-") && o === void 0) {
|
|
387
|
+
const u = i.split("-");
|
|
388
|
+
o = u.reduce((l, p) => l[R(p)], n), i = u.pop(), o != null && o.set || (n = u.reduce((l, p) => l[R(p)], n));
|
|
373
389
|
}
|
|
374
|
-
let
|
|
375
|
-
if (
|
|
376
|
-
Array.isArray(
|
|
390
|
+
let c = a;
|
|
391
|
+
if (c === "" && (c = !0), ne(o)) {
|
|
392
|
+
Array.isArray(c) ? e[s](...c) : e[s](c);
|
|
377
393
|
return;
|
|
378
394
|
}
|
|
379
|
-
!(
|
|
395
|
+
!(o != null && o.set) && !ne(o) ? n[s] = c : o.constructor === c.constructor && (o != null && o.copy) ? o == null || o.copy(c) : Array.isArray(c) ? o.set(...c) : !o.isColor && o.setScalar ? o.setScalar(c) : o.set(c);
|
|
380
396
|
}
|
|
381
397
|
},
|
|
382
398
|
parentNode(e) {
|
|
@@ -391,16 +407,16 @@ const ft = {
|
|
|
391
407
|
setScopeId: () => void 0,
|
|
392
408
|
cloneNode: () => void 0,
|
|
393
409
|
insertStaticContent: () => void 0
|
|
394
|
-
}, { createApp:
|
|
395
|
-
const t =
|
|
396
|
-
function
|
|
410
|
+
}, { createApp: ht } = je(gt), wt = (e) => {
|
|
411
|
+
const t = ht(r);
|
|
412
|
+
function r() {
|
|
397
413
|
return e && e.default ? e.default() : [];
|
|
398
414
|
}
|
|
399
415
|
return t;
|
|
400
416
|
};
|
|
401
|
-
|
|
402
|
-
const { logWarning:
|
|
403
|
-
name: "
|
|
417
|
+
pe(le);
|
|
418
|
+
const { logWarning: bt } = T(), yt = fe({
|
|
419
|
+
name: "TresScene",
|
|
404
420
|
props: [
|
|
405
421
|
"shadows",
|
|
406
422
|
"shadowMapType",
|
|
@@ -416,31 +432,36 @@ const { logWarning: mt } = E(), vt = ke({
|
|
|
416
432
|
"windowSize",
|
|
417
433
|
"preset"
|
|
418
434
|
],
|
|
419
|
-
setup(e, { slots: t, expose:
|
|
420
|
-
e.physicallyCorrectLights === !0 &&
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
435
|
+
setup(e, { slots: t, expose: r }) {
|
|
436
|
+
e.physicallyCorrectLights === !0 && bt("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
|
|
437
|
+
const a = M(), n = M(), i = new le.Scene(), { setState: s } = S();
|
|
438
|
+
s("scene", i), s("canvas", n), s("container", a);
|
|
439
|
+
const { pushCamera: o } = U();
|
|
440
|
+
o(new O()), _e(() => {
|
|
441
|
+
c();
|
|
442
|
+
}), Be(() => {
|
|
443
|
+
s("renderer", null);
|
|
424
444
|
});
|
|
425
|
-
function
|
|
426
|
-
const { renderer:
|
|
427
|
-
|
|
445
|
+
function c() {
|
|
446
|
+
const { renderer: p } = ut(e), { activeCamera: d } = U(), { onLoop: w } = N(), { raycaster: v, pointer: b } = be();
|
|
447
|
+
oe(() => {
|
|
448
|
+
d.value && v.value.setFromCamera(b.value, d.value);
|
|
449
|
+
}), w(() => {
|
|
428
450
|
var g;
|
|
429
|
-
|
|
451
|
+
d.value && ((g = p.value) == null || g.render(i, d.value));
|
|
430
452
|
});
|
|
431
453
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
s = dt(t), s.provide("useTres", L()), s.provide("extend", ce), s.mount(i);
|
|
454
|
+
let u;
|
|
455
|
+
function l() {
|
|
456
|
+
u = wt(t), u.provide("useTres", S()), u.provide("extend", pe), u.mount(i);
|
|
436
457
|
}
|
|
437
|
-
return
|
|
458
|
+
return l(), r({
|
|
438
459
|
scene: i
|
|
439
|
-
}), () =>
|
|
440
|
-
|
|
460
|
+
}), () => L(
|
|
461
|
+
L(
|
|
441
462
|
"div",
|
|
442
463
|
{
|
|
443
|
-
ref:
|
|
464
|
+
ref: a,
|
|
444
465
|
"data-scene": i.uuid,
|
|
445
466
|
key: i.uuid,
|
|
446
467
|
style: {
|
|
@@ -452,7 +473,7 @@ const { logWarning: mt } = E(), vt = ke({
|
|
|
452
473
|
}
|
|
453
474
|
},
|
|
454
475
|
[
|
|
455
|
-
|
|
476
|
+
L(
|
|
456
477
|
"div",
|
|
457
478
|
{
|
|
458
479
|
style: {
|
|
@@ -461,7 +482,7 @@ const { logWarning: mt } = E(), vt = ke({
|
|
|
461
482
|
}
|
|
462
483
|
},
|
|
463
484
|
[
|
|
464
|
-
|
|
485
|
+
L("canvas", {
|
|
465
486
|
ref: n,
|
|
466
487
|
"data-scene": i.uuid,
|
|
467
488
|
style: {
|
|
@@ -479,26 +500,48 @@ const { logWarning: mt } = E(), vt = ke({
|
|
|
479
500
|
)
|
|
480
501
|
);
|
|
481
502
|
}
|
|
482
|
-
}),
|
|
503
|
+
}), xt = fe({
|
|
504
|
+
name: "TresCanvas",
|
|
505
|
+
props: [
|
|
506
|
+
"shadows",
|
|
507
|
+
"shadowMapType",
|
|
508
|
+
"physicallyCorrectLights",
|
|
509
|
+
"useLegacyLights",
|
|
510
|
+
"outputEncoding",
|
|
511
|
+
"toneMapping",
|
|
512
|
+
"toneMappingExposure",
|
|
513
|
+
"context",
|
|
514
|
+
"powerPreference",
|
|
515
|
+
"preserveDrawingBuffer",
|
|
516
|
+
"clearColor",
|
|
517
|
+
"windowSize",
|
|
518
|
+
"preset"
|
|
519
|
+
],
|
|
520
|
+
setup(e, { slots: t, expose: r }) {
|
|
521
|
+
const a = dt();
|
|
522
|
+
return r(a), () => L(yt, e, t);
|
|
523
|
+
}
|
|
524
|
+
}), Rt = {
|
|
483
525
|
install(e) {
|
|
484
|
-
e.component("TresCanvas",
|
|
526
|
+
e.component("TresCanvas", xt);
|
|
485
527
|
}
|
|
486
528
|
};
|
|
487
529
|
export {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
530
|
+
et as CameraType,
|
|
531
|
+
xt as TresCanvas,
|
|
532
|
+
H as catalogue,
|
|
533
|
+
Rt as default,
|
|
534
|
+
pe as extend,
|
|
535
|
+
Tt as isProd,
|
|
536
|
+
ft as trasverseObjects,
|
|
537
|
+
U as useCamera,
|
|
538
|
+
Et as useLoader,
|
|
539
|
+
T as useLogger,
|
|
540
|
+
be as useRaycaster,
|
|
541
|
+
N as useRenderLoop,
|
|
542
|
+
ut as useRenderer,
|
|
543
|
+
Pt as useSeek,
|
|
544
|
+
St as useTexture,
|
|
545
|
+
S as useTres,
|
|
546
|
+
dt as useTresProvider
|
|
504
547
|
};
|
package/dist/tres.umd.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @tresjs/core
|
|
3
|
-
* version: v2.0.0-
|
|
3
|
+
* version: v2.0.0-beta.1
|
|
4
4
|
* (c) 2023
|
|
5
5
|
* description: Declarative ThreeJS using Vue Components
|
|
6
6
|
* author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
|
|
7
7
|
*/
|
|
8
|
-
(function(
|
|
9
|
-
You could set windowSize=true to force the canvas to be the size of the window.`);const 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"}})});
|
|
8
|
+
(function(d,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d.tres={},d.Vue,d.Three,d.VueUseCore))})(this,function(d,i,l,c){"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 q=le(l),U=i.ref({uuid:l.MathUtils.generateUUID()}),W=e=>void Object.assign(U.value,e);var V=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(V||{});const de=45;let C;function A(){const{state:e,setState:t,aspectRatio:r}=M();function a(o="Perspective",u){var p,m,h;if(o==="Perspective"){const{near:v,far:x,fov:w}=u||{near:.1,far:1e3,fov:de};C=new l.PerspectiveCamera(w,((p=e.aspectRatio)==null?void 0:p.value)||window.innerWidth/window.innerHeight,v,x),(m=e.cameras)==null||m.push(C)}else{const{left:v,right:x,top:w,bottom:S,near:b,far:F}=u||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};C=new l.OrthographicCamera(v,x,w,S,b,F),(h=e.cameras)==null||h.push(C)}return e.camera=C,t("camera",e.camera),C}function n(){var o;e.camera instanceof l.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(o=e.camera)==null||o.updateProjectionMatrix()}function s(o){var u;(u=e.cameras)==null||u.push(o),o instanceof l.PerspectiveCamera&&e.aspectRatio&&(o.aspect=e.aspectRatio.value),o.updateProjectionMatrix(),t("camera",o)}function f(){e.cameras=[]}return i.watchEffect(()=>{r!=null&&r.value&&n()}),{activeCamera:i.toRef(e,"camera"),createCamera:a,updateCamera:n,pushCamera:s,clearCameras:f}}const Y=c.createEventHook(),K=c.createEventHook(),I=c.createEventHook(),k=new l.Clock;let j=0,T=0;const{pause:pe,resume:me,isActive:ve}=c.useRafFn(()=>{Y.trigger({delta:j,elapsed:T,clock:k}),K.trigger({delta:j,elapsed:T,clock:k}),I.trigger({delta:j,elapsed:T,clock:k})},{immediate:!1});I.on(()=>{j=k.getDelta(),T=k.getElapsedTime()});function _(){return{onBeforeLoop:Y.on,onLoop:K.on,onAfterLoop:I.on,pause:pe,resume:me,isActive:ve}}function ge(e){return e instanceof l.Color?e:Array.isArray(e)?new l.Color(...e):new l.Color(e)}const R={realistic:{outputEncoding:l.sRGBEncoding,toneMapping:l.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:l.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},he=we("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 D(e){return e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase())}function we(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]}function J(e){var fe,ue;const t=i.shallowRef(),r=i.ref(!1),{alpha:a=!0,antialias:n=!0,depth:s,logarithmicDepthBuffer:f,failIfMajorPerformanceCaveat:o,precision:u,premultipliedAlpha:p,stencil:m,shadows:h=!1,shadowMapType:v=l.PCFShadowMap,physicallyCorrectLights:x=!1,useLegacyLights:w=!1,outputEncoding:S=l.LinearEncoding,toneMapping:b=l.NoToneMapping,toneMappingExposure:F=1,context:_e=void 0,powerPreference:De="default",preserveDrawingBuffer:ze=!1,clearColor:O,windowSize:ae=!1,preset:Be=void 0}=i.toRefs(e),{state:y,setState:G}=M(),{width:re,height:oe}=c.resolveUnref(ae)?c.useWindowSize():c.useElementSize(y.container),{logError:Fe,logWarning:We}=L(),{pixelRatio:se}=c.useDevicePixelRatio(),{pause:Ie,resume:Re}=_(),$=i.computed(()=>re.value/oe.value);!c.resolveUnref(ae)&&((ue=(fe=y.container)==null?void 0:fe.value)==null?void 0:ue.offsetHeight)===0&&We(`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=()=>{t.value&&(t.value.setSize(re.value,oe.value),t.value.setPixelRatio(Math.min(se.value,2)))},ce=()=>{if(!t.value)return;const P=c.resolveUnref(Be);if(P){P in R||Fe("Renderer Preset must be one of these: "+Object.keys(R).join(", ")),X(t.value,R[P]);return}t.value.shadowMap.enabled=c.resolveUnref(h),t.value.shadowMap.type=c.resolveUnref(v),t.value.toneMapping=c.resolveUnref(b)||l.NoToneMapping,t.value.toneMappingExposure=c.resolveUnref(F),t.value.outputEncoding=c.resolveUnref(S)||l.LinearEncoding,O!=null&&O.value&&t.value.setClearColor(ge(c.resolveUnref(O))),t.value.useLegacyLights=c.resolveUnref(w)},Ne=()=>{const P=c.unrefElement(y.canvas);P&&(t.value=new l.WebGLRenderer({canvas:P,alpha:c.resolveUnref(a),antialias:c.resolveUnref(n),context:c.resolveUnref(_e),depth:c.resolveUnref(s),failIfMajorPerformanceCaveat:c.resolveUnref(o),logarithmicDepthBuffer:c.resolveUnref(f),powerPreference:c.resolveUnref(De),precision:c.resolveUnref(u),stencil:c.resolveUnref(m),preserveDrawingBuffer:c.resolveUnref(ze),premultipliedAlpha:c.resolveUnref(p)}),G("renderer",t.value),G("clock",new l.Clock),G("aspectRatio",$),ce(),ie(),Re(),r.value=!0)},Ge=()=>{t.value&&(t.value.dispose(),t.value=void 0,r.value=!1,Ie())};return i.watch([$,se],ie),i.watch([h,v,S,w,b,F,O],ce),i.watch(()=>[y.canvas,y.container],()=>{c.unrefElement(y.canvas)&&c.unrefElement(y.container)&&Ne()},{immediate:!0,deep:!0}),{renderer:t,isReady:r,dispose:Ge,aspectRatio:$}}const Q=e=>!!e&&e.constructor===Array;function Z(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 be(e,t,r,a,n){const{logError:s}=L(),f=new e;n&&n(f),r&&r(f);const u=(Array.isArray(t)?t:[t]).map(p=>new Promise((m,h)=>{f.load(p,v=>{v.scene&&Object.assign(v,Z(v.scene)),m(v)},a,v=>h(s("[useLoader] - Failed to load resource",v)))}));return Q(t)?await Promise.all(u):await u[0]}async function ye(e){const t=new l.LoadingManager,r=new l.TextureLoader(t),a=n=>new Promise((s,f)=>{r.load(n,o=>s(o),()=>null,()=>{f(new Error("[useTextures] - Failed to load texture"))})});if(Q(e)){const n=await Promise.all(e.map(s=>a(s)));return e.length>1?n:n[0]}else{const{map:n,displacementMap:s,normalMap:f,roughnessMap:o,metalnessMap:u,aoMap:p,alphaMap:m,matcap:h}=e;return{map:n?await a(n):null,displacementMap:s?await a(s):null,normalMap:f?await a(f):null,roughnessMap:o?await a(o):null,metalnessMap:u?await a(u):null,aoMap:p?await a(p):null,alphaMap:m?await a(m):null,matcap:h?await a(h):null}}}const g=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];function Ce(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0,a=Math.random()*4294967295|0;return(g[e&255]+g[e>>8&255]+g[e>>16&255]+g[e>>24&255]+"-"+g[t&255]+g[t>>8&255]+"-"+g[t>>16&15|64]+g[t>>24&255]+"-"+g[r&63|128]+g[r>>8&255]+"-"+g[r>>16&255]+g[r>>24&255]+g[a&255]+g[a>>8&255]+g[a>>16&255]+g[a>>24&255]).toLowerCase()}const E=Symbol();function H(){const e=i.shallowReactive({uuid:Ce(),camera:void 0,cameras:[],scene:void 0,renderer:void 0,aspectRatio:i.computed(()=>window.innerWidth/window.innerHeight)});function t(n){return e[n]}function r(n,s){e[n]=s}const a={state:e,...i.toRefs(e),getState:t,setState:r};return i.provide(E,a),a}const M=()=>i.inject(E,{state:i.shallowReactive({camera:void 0,cameras:[],scene:void 0,renderer:void 0})}),ee=i.shallowRef(new l.Raycaster),z=i.ref(new l.Vector2),Me=i.ref(null);function N(){const{setState:e}=M();e("raycaster",ee.value),e("pointer",z),e("currentInstance",Me);function t(r){z.value.x=r.clientX/window.innerWidth*2-1,z.value.y=-(r.clientY/window.innerHeight)*2+1}return window.addEventListener("pointermove",t),{raycaster:ee,pointer:z}}const Le=!0,te="[TresJS ▲ ■ ●] ";function L(){function e(a,n){console.error(`${te} ${a}`,n||"")}function t(a){console.warn(`${te} ${a}`)}function r(a,n){}return{logError:e,logWarning:t,logMessage:r}}function xe(){const{logWarning:e}=L();function t(a,n,s){let f=null;return a.traverse(o=>{o[n]===s&&(f=o)}),f||e(`Child with ${n} '${s}' not found.`),f}function r(a,n){return t(a,"name",n)}return{seek:t,seekByName:r}}const{logWarning:Se}=L();function Pe(e){for(const t in e)if(t.indexOf("on")===0)return!0;return!1}function qe(e){}let B=null;const ke={createElement(e,t,r,a){if(e==="template"||he(e))return null;let n;if(a===null&&(a={}),a!=null&&a.args?n=new U.value[e.replace("Tres","")](...a.args):n=new U.value[e.replace("Tres","")],n.isCamera){(!(a!=null&&a.position)||a!=null&&a.position.every(f=>f==0))&&Se("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:s}=A();s(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(B===null&&t.isScene&&(B=t),t===null&&(t=B),t!=null&&t.isObject3D&&(e!=null&&e.isObject3D)){const f=r?t.children.indexOf(r):0;e.parent=t,t.children.splice(f,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}=_();let n=null,s=null;if(e&&e instanceof l.Mesh&&Pe(e)){const{raycaster:f}=N();a(()=>{var o,u,p;if(t!=null&&t.children&&e&&f){const m=f.value.intersectObjects(t.children);m.length>0&&m[0].object.uuid===e.uuid?(s=m[0],(n===null||n.object.uuid!==(s==null?void 0:s.object.uuid))&&((o=e.onPointerEnter)==null||o.call(e,s)),(u=e.onPointerMove)==null||u.call(e,s)):(s=null,n!==null&&((p=e.onPointerLeave)==null||p.call(e,n))),n=s}}),c.useEventListener(window,"click",()=>{var o;s!==null&&((o=e.onClick)==null||o.call(e,s))})}},remove(e){if(!e)return;const t=e.parentNode;t&&t.removeChild(e)},patchProp(e,t,r,a){if(e){let n=e,s=t;const f=D(s);let o=n==null?void 0:n[f];if(e.parent||(e.parent=B),n.type==="BufferGeometry"){n.setAttribute(D(s),new l.BufferAttribute(...a));return}if(s.includes("-")&&o===void 0){const p=s.split("-");o=p.reduce((m,h)=>m[D(h)],n),s=p.pop(),o!=null&&o.set||(n=p.reduce((m,h)=>m[D(h)],n))}let u=a;if(u===""&&(u=!0),c.isFunction(o)){Array.isArray(u)?e[f](...u):e[f](u);return}!(o!=null&&o.set)&&!c.isFunction(o)?n[f]=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:Oe}=i.createRenderer(ke),Ue=e=>{const t=Oe(r);function r(){return e&&e.default?e.default():[]}return t};W(q);const{logWarning:Ae}=L(),je=i.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t,expose:r}){e.physicallyCorrectLights===!0&&Ae("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const a=i.ref(),n=i.ref(),s=new q.Scene,{setState:f}=M();f("scene",s),f("canvas",n),f("container",a);const{pushCamera:o}=A();o(new l.PerspectiveCamera),i.onMounted(()=>{u()}),i.onUnmounted(()=>{f("renderer",null)});function u(){const{renderer:h}=J(e),{activeCamera:v}=A(),{onLoop:x}=_(),{raycaster:w,pointer:S}=N();i.watchEffect(()=>{v.value&&w.value.setFromCamera(S.value,v.value)}),x(()=>{var b;v.value&&((b=h.value)==null||b.render(s,v.value))})}let p;function m(){p=Ue(t),p.provide("useTres",M()),p.provide("extend",W),p.mount(s)}return m(),r({scene:s}),()=>i.h(i.h("div",{ref:a,"data-scene":s.uuid,key:s.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[i.h("div",{style:{width:"100%",height:"100%"}},[i.h("canvas",{ref:n,"data-scene":s.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),ne=i.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset"],setup(e,{slots:t,expose:r}){const a=H();return r(a),()=>i.h(je,e,t)}}),Te={install(e){e.component("TresCanvas",ne)}};d.CameraType=V,d.TresCanvas=ne,d.catalogue=U,d.default=Te,d.extend=W,d.isProd=Le,d.trasverseObjects=Z,d.useCamera=A,d.useLoader=be,d.useLogger=L,d.useRaycaster=N,d.useRenderLoop=_,d.useRenderer=J,d.useSeek=xe,d.useTexture=ye,d.useTres=M,d.useTresProvider=H,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Vector3, Color } from 'three';
|
|
1
|
+
import { Vector3, Color, ColorRepresentation } from 'three';
|
|
2
2
|
export type SizeFlexibleParams = number[] | {
|
|
3
3
|
width: number;
|
|
4
4
|
height: number;
|
|
@@ -14,4 +14,4 @@ export interface Vector3PropInterface extends Vector2PropInterface {
|
|
|
14
14
|
}
|
|
15
15
|
export type VectorFlexibleParams = Vector3 | number[] | Vector3PropInterface | number;
|
|
16
16
|
export declare function normalizeVectorFlexibleParam(value: VectorFlexibleParams): Array<number>;
|
|
17
|
-
export declare function normalizeColor(value: Color | Array<number> | string | number): Color;
|
|
17
|
+
export declare function normalizeColor(value: Color | Array<number> | string | number | ColorRepresentation): Color;
|
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-
|
|
4
|
+
"version": "2.0.0-beta.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
|
|
7
7
|
"files": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dev": "vite",
|
|
41
41
|
"build": "vite build",
|
|
42
42
|
"preview": "vite preview",
|
|
43
|
-
"playground": "cd playground &&
|
|
43
|
+
"playground": "cd playground && npm run dev",
|
|
44
44
|
"test": "vitest",
|
|
45
45
|
"test:ci": "vitest run",
|
|
46
46
|
"test:ui": "vitest --ui",
|
|
@@ -56,45 +56,48 @@
|
|
|
56
56
|
"vue": "^3.2.47"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
+
"-": "^0.0.1",
|
|
59
60
|
"@alvarosabu/utils": "^2.3.0",
|
|
60
61
|
"@vueuse/core": "^9.13.0"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@alvarosabu/prettier-config": "^1.2.0",
|
|
65
|
+
"@huntersofbook/plausible-vue": "^1.0.0",
|
|
64
66
|
"@release-it/conventional-changelog": "^5.1.1",
|
|
65
67
|
"@stackblitz/sdk": "^1.8.1",
|
|
66
68
|
"@tresjs/cientos": "2.0.0-alpha.5",
|
|
67
69
|
"@types/three": "latest",
|
|
68
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
69
|
-
"@typescript-eslint/parser": "^5.
|
|
70
|
-
"@vitejs/plugin-vue": "^4.
|
|
71
|
-
"@vitest/coverage-c8": "^0.29.
|
|
70
|
+
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
71
|
+
"@typescript-eslint/parser": "^5.57.1",
|
|
72
|
+
"@vitejs/plugin-vue": "^4.1.0",
|
|
73
|
+
"@vitest/coverage-c8": "^0.29.8",
|
|
72
74
|
"@vitest/ui": "^0.29.2",
|
|
73
|
-
"@vue/test-utils": "^2.3.
|
|
74
|
-
"eslint": "^8.
|
|
75
|
+
"@vue/test-utils": "^2.3.2",
|
|
76
|
+
"eslint": "^8.37.0",
|
|
75
77
|
"eslint-config-prettier": "^8.5.0",
|
|
76
|
-
"eslint-plugin-vue": "^9.
|
|
78
|
+
"eslint-plugin-vue": "^9.10.0",
|
|
77
79
|
"gsap": "^3.11.4",
|
|
78
80
|
"happy-dom": "^8.7.1",
|
|
79
81
|
"jsdom": "^21.1.0",
|
|
80
82
|
"kolorist": "^1.7.0",
|
|
81
83
|
"pathe": "^1.1.0",
|
|
82
|
-
"prettier": "^2.8.
|
|
83
|
-
"release-it": "^15.
|
|
84
|
+
"prettier": "^2.8.7",
|
|
85
|
+
"release-it": "^15.10.1",
|
|
84
86
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
85
87
|
"rollup-plugin-copy": "^3.4.0",
|
|
86
88
|
"rollup-plugin-visualizer": "^5.9.0",
|
|
87
89
|
"three": "latest",
|
|
88
|
-
"unocss": "^0.
|
|
90
|
+
"unocss": "^0.50.6",
|
|
89
91
|
"unplugin": "^1.3.1",
|
|
90
|
-
"
|
|
92
|
+
"unplugin-vue-components": "^0.24.1",
|
|
93
|
+
"vite": "^4.2.1",
|
|
91
94
|
"vite-plugin-banner": "^0.7.0",
|
|
92
|
-
"vite-plugin-dts": "2.
|
|
93
|
-
"vite-plugin-inspect": "^0.7.
|
|
94
|
-
"vite-plugin-require-transform": "^1.0.
|
|
95
|
+
"vite-plugin-dts": "2.2.0",
|
|
96
|
+
"vite-plugin-inspect": "^0.7.18",
|
|
97
|
+
"vite-plugin-require-transform": "^1.0.12",
|
|
95
98
|
"vite-svg-loader": "^4.0.0",
|
|
96
|
-
"vitepress": "1.0.0-alpha.
|
|
97
|
-
"vitest": "^0.29.
|
|
99
|
+
"vitepress": "1.0.0-alpha.65",
|
|
100
|
+
"vitest": "^0.29.8",
|
|
98
101
|
"vue-demi": "^0.13.11"
|
|
99
102
|
}
|
|
100
103
|
}
|