@tresjs/core 2.0.0-alpha.6 → 2.0.0-beta.1

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