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