@tresjs/core 2.0.0-alpha.6 → 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 +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 +310 -272
- package/dist/tres.umd.cjs +3 -3
- package/dist/utils/normalize.d.ts +2 -2
- package/package.json +5 -2
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.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
|
|
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,321 +33,333 @@ 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: 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
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
|
-
|
|
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:
|
|
131
|
-
clearColor:
|
|
124
|
+
outputEncoding: b = ee,
|
|
125
|
+
toneMapping: g = te,
|
|
126
|
+
toneMappingExposure: P = 1,
|
|
127
|
+
context: be = void 0,
|
|
128
|
+
powerPreference: ye = "default",
|
|
129
|
+
preserveDrawingBuffer: xe = !1,
|
|
130
|
+
clearColor: L,
|
|
132
131
|
windowSize: V = !1,
|
|
133
|
-
preset:
|
|
134
|
-
} =
|
|
135
|
-
!
|
|
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.
|
|
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(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]);
|
|
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, 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());
|
|
166
165
|
};
|
|
167
|
-
return
|
|
168
|
-
[p,
|
|
169
|
-
|
|
170
|
-
),
|
|
171
|
-
() => [
|
|
166
|
+
return z([D, K], X), z(
|
|
167
|
+
[p, d, b, v, g, P, L],
|
|
168
|
+
J
|
|
169
|
+
), z(
|
|
170
|
+
() => [h.canvas, h.container],
|
|
172
171
|
() => {
|
|
173
|
-
F(
|
|
172
|
+
F(h.canvas) && F(h.container) && Te();
|
|
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: Pe,
|
|
179
|
+
aspectRatio: D
|
|
181
180
|
};
|
|
182
181
|
}
|
|
183
|
-
const
|
|
184
|
-
function
|
|
182
|
+
const ge = (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 } = 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);
|
|
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 ge(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 (ge(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 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];
|
|
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(he, a), a;
|
|
264
271
|
}
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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;
|
|
271
281
|
}
|
|
272
282
|
return window.addEventListener("pointermove", t), {
|
|
273
|
-
raycaster:
|
|
283
|
+
raycaster: ae,
|
|
274
284
|
pointer: k
|
|
275
285
|
};
|
|
276
286
|
}
|
|
277
|
-
const
|
|
278
|
-
function
|
|
279
|
-
function e(
|
|
280
|
-
console.error(`${
|
|
287
|
+
const Tt = !0, re = "[TresJS ▲ ■ ●] ";
|
|
288
|
+
function C() {
|
|
289
|
+
function e(a, n) {
|
|
290
|
+
console.error(`${re} ${a}`, n || "");
|
|
281
291
|
}
|
|
282
|
-
function t(
|
|
283
|
-
console.warn(`${
|
|
292
|
+
function t(a) {
|
|
293
|
+
console.warn(`${re} ${a}`);
|
|
284
294
|
}
|
|
285
|
-
function
|
|
295
|
+
function r(a, n) {
|
|
286
296
|
}
|
|
287
297
|
return {
|
|
288
298
|
logError: e,
|
|
289
299
|
logWarning: t,
|
|
290
|
-
logMessage:
|
|
300
|
+
logMessage: r
|
|
291
301
|
};
|
|
292
302
|
}
|
|
293
|
-
function
|
|
294
|
-
const { logWarning: e } =
|
|
295
|
-
function t(
|
|
296
|
-
let
|
|
297
|
-
return
|
|
298
|
-
|
|
299
|
-
}),
|
|
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;
|
|
300
310
|
}
|
|
301
|
-
function
|
|
302
|
-
return t(
|
|
311
|
+
function r(a, n) {
|
|
312
|
+
return t(a, "name", n);
|
|
303
313
|
}
|
|
304
314
|
return {
|
|
305
315
|
seek: t,
|
|
306
|
-
seekByName:
|
|
316
|
+
seekByName: r
|
|
307
317
|
};
|
|
308
318
|
}
|
|
309
|
-
const { logWarning:
|
|
310
|
-
function
|
|
319
|
+
const { logWarning: mt } = C();
|
|
320
|
+
function vt(e) {
|
|
311
321
|
for (const t in e)
|
|
312
322
|
if (t.indexOf("on") === 0)
|
|
313
323
|
return !0;
|
|
314
324
|
return !1;
|
|
315
325
|
}
|
|
316
326
|
let A = null;
|
|
317
|
-
const
|
|
318
|
-
createElement(e, t,
|
|
319
|
-
if (e === "template" ||
|
|
327
|
+
const gt = {
|
|
328
|
+
createElement(e, t, r, a) {
|
|
329
|
+
if (e === "template" || st(e))
|
|
320
330
|
return null;
|
|
321
331
|
let n;
|
|
322
|
-
if (
|
|
323
|
-
(!(
|
|
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(
|
|
324
334
|
// eslint-disable-next-line max-len
|
|
325
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 🤗"
|
|
326
336
|
);
|
|
327
|
-
const { pushCamera: i } =
|
|
337
|
+
const { pushCamera: i } = U();
|
|
328
338
|
i(n);
|
|
329
339
|
}
|
|
330
|
-
return (
|
|
340
|
+
return (a == null ? void 0 : a.attach) === void 0 && (n.isMaterial ? n.attach = "material" : n.isBufferGeometry && (n.attach = "geometry")), n;
|
|
331
341
|
},
|
|
332
|
-
insert(e, t,
|
|
342
|
+
insert(e, t, r) {
|
|
333
343
|
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(
|
|
344
|
+
const s = r ? t.children.indexOf(r) : 0;
|
|
345
|
+
e.parent = t, t.children.splice(s, 0, e), e.dispatchEvent({ type: "added" });
|
|
336
346
|
} else
|
|
337
347
|
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:
|
|
348
|
+
const { onLoop: a } = N();
|
|
339
349
|
let n = null, i = null;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
+
}
|
|
351
363
|
},
|
|
352
364
|
remove(e) {
|
|
353
365
|
if (!e)
|
|
@@ -355,28 +367,28 @@ const ft = {
|
|
|
355
367
|
const t = e.parentNode;
|
|
356
368
|
t && t.removeChild(e);
|
|
357
369
|
},
|
|
358
|
-
patchProp(e, t,
|
|
370
|
+
patchProp(e, t, r, a) {
|
|
359
371
|
if (e) {
|
|
360
372
|
let n = e, i = t;
|
|
361
|
-
const
|
|
362
|
-
let
|
|
373
|
+
const s = R(i);
|
|
374
|
+
let o = n == null ? void 0 : n[s];
|
|
363
375
|
if (e.parent || (e.parent = A), n.type === "BufferGeometry") {
|
|
364
376
|
n.setAttribute(
|
|
365
|
-
|
|
366
|
-
new
|
|
377
|
+
R(i),
|
|
378
|
+
new Ye(...a)
|
|
367
379
|
);
|
|
368
380
|
return;
|
|
369
381
|
}
|
|
370
|
-
if (i.includes("-") &&
|
|
371
|
-
const
|
|
372
|
-
|
|
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));
|
|
373
385
|
}
|
|
374
|
-
let
|
|
375
|
-
if (
|
|
376
|
-
Array.isArray(
|
|
386
|
+
let c = a;
|
|
387
|
+
if (c === "" && (c = !0), ne(o)) {
|
|
388
|
+
Array.isArray(c) ? e[s](...c) : e[s](c);
|
|
377
389
|
return;
|
|
378
390
|
}
|
|
379
|
-
!(
|
|
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);
|
|
380
392
|
}
|
|
381
393
|
},
|
|
382
394
|
parentNode(e) {
|
|
@@ -391,16 +403,16 @@ const ft = {
|
|
|
391
403
|
setScopeId: () => void 0,
|
|
392
404
|
cloneNode: () => void 0,
|
|
393
405
|
insertStaticContent: () => void 0
|
|
394
|
-
}, { createApp:
|
|
395
|
-
const t =
|
|
396
|
-
function
|
|
406
|
+
}, { createApp: ht } = je(gt), wt = (e) => {
|
|
407
|
+
const t = ht(r);
|
|
408
|
+
function r() {
|
|
397
409
|
return e && e.default ? e.default() : [];
|
|
398
410
|
}
|
|
399
411
|
return t;
|
|
400
412
|
};
|
|
401
|
-
|
|
402
|
-
const { logWarning:
|
|
403
|
-
name: "
|
|
413
|
+
de(fe);
|
|
414
|
+
const { logWarning: bt } = C(), yt = ue({
|
|
415
|
+
name: "TresScene",
|
|
404
416
|
props: [
|
|
405
417
|
"shadows",
|
|
406
418
|
"shadowMapType",
|
|
@@ -416,31 +428,36 @@ const { logWarning: mt } = E(), vt = ke({
|
|
|
416
428
|
"windowSize",
|
|
417
429
|
"preset"
|
|
418
430
|
],
|
|
419
|
-
setup(e, { slots: t, expose:
|
|
420
|
-
e.physicallyCorrectLights === !0 &&
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
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);
|
|
424
440
|
});
|
|
425
|
-
function
|
|
426
|
-
const { renderer:
|
|
427
|
-
|
|
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(() => {
|
|
428
446
|
var g;
|
|
429
|
-
|
|
447
|
+
d.value && ((g = p.value) == null || g.render(i, d.value));
|
|
430
448
|
});
|
|
431
449
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
s = dt(t), s.provide("useTres", L()), s.provide("extend", ce), s.mount(i);
|
|
450
|
+
let u;
|
|
451
|
+
function l() {
|
|
452
|
+
u = wt(t), u.provide("useTres", T()), u.provide("extend", de), u.mount(i);
|
|
436
453
|
}
|
|
437
|
-
return
|
|
454
|
+
return l(), r({
|
|
438
455
|
scene: i
|
|
439
|
-
}), () =>
|
|
440
|
-
|
|
456
|
+
}), () => E(
|
|
457
|
+
E(
|
|
441
458
|
"div",
|
|
442
459
|
{
|
|
443
|
-
ref:
|
|
460
|
+
ref: a,
|
|
444
461
|
"data-scene": i.uuid,
|
|
445
462
|
key: i.uuid,
|
|
446
463
|
style: {
|
|
@@ -452,7 +469,7 @@ const { logWarning: mt } = E(), vt = ke({
|
|
|
452
469
|
}
|
|
453
470
|
},
|
|
454
471
|
[
|
|
455
|
-
|
|
472
|
+
E(
|
|
456
473
|
"div",
|
|
457
474
|
{
|
|
458
475
|
style: {
|
|
@@ -461,7 +478,7 @@ const { logWarning: mt } = E(), vt = ke({
|
|
|
461
478
|
}
|
|
462
479
|
},
|
|
463
480
|
[
|
|
464
|
-
|
|
481
|
+
E("canvas", {
|
|
465
482
|
ref: n,
|
|
466
483
|
"data-scene": i.uuid,
|
|
467
484
|
style: {
|
|
@@ -479,26 +496,47 @@ const { logWarning: mt } = E(), vt = ke({
|
|
|
479
496
|
)
|
|
480
497
|
);
|
|
481
498
|
}
|
|
482
|
-
}),
|
|
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 = {
|
|
483
520
|
install(e) {
|
|
484
|
-
e.component("TresCanvas",
|
|
521
|
+
e.component("TresCanvas", xt);
|
|
485
522
|
}
|
|
486
523
|
};
|
|
487
524
|
export {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
|
504
542
|
};
|
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.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(
|
|
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 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,6 +89,7 @@
|
|
|
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",
|