@tresjs/core 2.0.0-rc.2 → 2.0.0-rc.4

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
@@ -1,8 +1,8 @@
1
1
  ![repo-banner](/public/repo-banner.png)
2
2
 
3
3
  <p align="center">
4
- <a href="https://www.npmjs.com/package/@tresjs/core"><img src="https://img.shields.io/npm/v/@tresjs/core/beta?color=%2382DBCA" alt="npm package"></a>
5
- <a href="https://discord.gg/tfY9aSNT"><img src="https://img.shields.io/badge/chat-discord-purple?style=flat&logo=discord" alt="discord chat"></a>
4
+ <a href="https://www.npmjs.com/package/@tresjs/core"><img src="https://img.shields.io/npm/v/@tresjs/core/next?color=%2382DBCA" alt="npm package"></a>
5
+ <a href="https://discord.gg/UCr96AQmWn"><img src="https://img.shields.io/badge/chat-discord-purple?style=flat&logo=discord" alt="discord chat"></a>
6
6
  </p>
7
7
 
8
8
  # TresJS `@tresjs/core`
@@ -1,4 +1,4 @@
1
- import { ShadowMapType, TextureEncoding, ToneMapping } from 'three';
1
+ import { ColorSpace, ShadowMapType, ToneMapping } from 'three';
2
2
  import { CameraType } from '../composables';
3
3
  import { RendererPresetsType } from '../composables/useRenderer/const';
4
4
  export interface TresSceneProps {
@@ -6,7 +6,7 @@ export interface TresSceneProps {
6
6
  shadowMapType?: ShadowMapType;
7
7
  physicallyCorrectLights?: boolean;
8
8
  useLegacyLights?: boolean;
9
- outputColorSpace?: TextureEncoding;
9
+ outputColorSpace?: ColorSpace;
10
10
  toneMapping?: ToneMapping;
11
11
  toneMappingExposure?: number;
12
12
  context?: WebGLRenderingContext;
@@ -78,6 +78,7 @@ interface UseCameraReturn {
78
78
  updateCamera: () => void;
79
79
  pushCamera: (camera: Camera) => void;
80
80
  clearCameras: () => void;
81
+ setFirstCamera: (camera: Camera) => void;
81
82
  }
82
83
  /**
83
84
  * Create and update cameras
@@ -1,6 +1,6 @@
1
1
  import { MaybeRefOrGetter } from '@vueuse/core';
2
- import { WebGLRendererParameters, WebGLRenderer, ShadowMapType } from 'three';
3
- import type { TextureEncoding, ToneMapping } from 'three';
2
+ import { WebGLRendererParameters, WebGLRenderer, ShadowMapType, ColorSpace } from 'three';
3
+ import type { ToneMapping } from 'three';
4
4
  import { TresColor } from '../../types';
5
5
  import { RendererPresetsType } from './const';
6
6
  export interface UseRendererOptions extends WebGLRendererParameters {
@@ -39,7 +39,7 @@ export interface UseRendererOptions extends WebGLRendererParameters {
39
39
  *
40
40
  * @default LinearSRGBColorSpace
41
41
  */
42
- outputColorSpace?: MaybeRefOrGetter<TextureEncoding>;
42
+ outputColorSpace?: MaybeRefOrGetter<ColorSpace>;
43
43
  /**
44
44
  * Defines the tone mapping used by the renderer.
45
45
  * Can be NoToneMapping, LinearToneMapping, ReinhardToneMapping, Uncharted2ToneMapping, CineonToneMapping, ACESFilmicToneMapping, CustomToneMapping
package/dist/tres.js CHANGED
@@ -1,31 +1,31 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v2.0.0-rc.2
3
+ * version: v2.0.0-rc.4
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 E, watchEffect as le, toRef as Ae, shallowRef as de, toRefs as me, computed as pe, watch as F, shallowReactive as ve, provide as _e, inject as Oe, onUnmounted as ge, createRenderer as ke, defineComponent as he, onMounted as je, h as k } from "vue";
9
- import * as we from "three";
10
- import { MathUtils as De, PerspectiveCamera as $, OrthographicCamera as Ie, Clock as be, Color as N, SRGBColorSpace as Be, ACESFilmicToneMapping as ze, PCFSoftShadowMap as Ge, PCFShadowMap as Ve, LinearSRGBColorSpace as ne, NoToneMapping as re, WebGLRenderer as Fe, LoadingManager as We, TextureLoader as He, Raycaster as Ue, Vector2 as Ye, BufferAttribute as $e } from "three";
11
- import { createEventHook as J, useRafFn as Ne, toValue as l, useWindowSize as qe, useElementSize as Ke, useDevicePixelRatio as Je, unrefElement as q, useEventListener as Xe } from "@vueuse/core";
12
- const ye = E({ uuid: De.generateUUID() }), Me = (e) => void Object.assign(ye.value, e);
13
- var Qe = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Qe || {});
14
- const Ze = 45;
8
+ import { ref as E, watchEffect as de, toRef as _e, shallowRef as me, toRefs as pe, computed as ve, watch as W, shallowReactive as ge, provide as Oe, inject as ke, onUnmounted as he, createRenderer as je, defineComponent as we, onMounted as De, h as j } from "vue";
9
+ import * as be from "three";
10
+ import { MathUtils as Ie, PerspectiveCamera as $, OrthographicCamera as Be, Clock as ye, Color as N, SRGBColorSpace as Fe, ACESFilmicToneMapping as ze, PCFSoftShadowMap as Ge, PCFShadowMap as Ve, LinearSRGBColorSpace as ne, NoToneMapping as re, WebGLRenderer as We, LoadingManager as He, TextureLoader as Ue, Raycaster as Ye, Vector2 as $e, BufferAttribute as Ne } from "three";
11
+ import { createEventHook as J, useRafFn as qe, toValue as l, useWindowSize as Ke, useElementSize as Je, useDevicePixelRatio as Xe, unrefElement as q, useEventListener as Qe } from "@vueuse/core";
12
+ const Ce = E({ uuid: Ie.generateUUID() }), Me = (e) => void Object.assign(Ce.value, e);
13
+ var Ze = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Ze || {});
14
+ const et = 45;
15
15
  let A;
16
- function Ce() {
16
+ function xe() {
17
17
  const { state: e, setState: t, aspectRatio: o } = _();
18
- function a(i = "Perspective", s) {
19
- var u, f, m;
20
- if (i === "Perspective") {
21
- const { near: v, far: h, fov: M } = s || {
18
+ function a(s = "Perspective", f) {
19
+ var u, m, g;
20
+ if (s === "Perspective") {
21
+ const { near: w, far: C, fov: h } = f || {
22
22
  near: 0.1,
23
23
  far: 1e3,
24
- fov: Ze
24
+ fov: et
25
25
  };
26
- A = new $(M, ((u = e.aspectRatio) == null ? void 0 : u.value) || window.innerWidth / window.innerHeight, v, h), (f = e.cameras) == null || f.push(A);
26
+ A = new $(h, ((u = e.aspectRatio) == null ? void 0 : u.value) || window.innerWidth / window.innerHeight, w, C), (m = e.cameras) == null || m.push(A);
27
27
  } else {
28
- const { left: v, right: h, top: M, bottom: w, near: P, far: C } = s || {
28
+ const { left: w, right: C, top: h, bottom: P, near: M, far: O } = f || {
29
29
  left: -100,
30
30
  right: 100,
31
31
  top: 100,
@@ -33,58 +33,63 @@ function Ce() {
33
33
  near: 0.1,
34
34
  far: 1e3
35
35
  };
36
- A = new Ie(v, h, M, w, P, C), (m = e.cameras) == null || m.push(A);
36
+ A = new Be(w, C, h, P, M, O), (g = e.cameras) == null || g.push(A);
37
37
  }
38
38
  return e.camera = A, t("camera", e.camera), A;
39
39
  }
40
40
  function n() {
41
- var i;
42
- e.camera instanceof $ && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (i = e.camera) == null || i.updateProjectionMatrix();
43
- }
44
- function r(i) {
45
41
  var s;
46
- (s = e.cameras) == null || s.push(i), i instanceof $ && e.aspectRatio && (i.aspect = e.aspectRatio.value), i.updateProjectionMatrix(), t("camera", i);
42
+ e.camera instanceof $ && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (s = e.camera) == null || s.updateProjectionMatrix();
47
43
  }
48
- function c() {
44
+ function r(s) {
45
+ var f;
46
+ (f = e.cameras) == null || f.push(s), s instanceof $ && e.aspectRatio && (s.aspect = e.aspectRatio.value), s.updateProjectionMatrix(), t("camera", s);
47
+ }
48
+ function c(s) {
49
+ var f;
50
+ ((f = e.cameras) == null ? void 0 : f.length) === 0 && r(s);
51
+ }
52
+ function i() {
49
53
  e.cameras = [];
50
54
  }
51
- return le(() => {
55
+ return de(() => {
52
56
  o != null && o.value && n();
53
57
  }), {
54
- activeCamera: Ae(e, "camera"),
58
+ activeCamera: _e(e, "camera"),
55
59
  createCamera: a,
56
60
  updateCamera: n,
57
61
  pushCamera: r,
58
- clearCameras: c
62
+ clearCameras: i,
63
+ setFirstCamera: c
59
64
  };
60
65
  }
61
- const xe = J(), Re = J(), X = J(), j = new be();
62
- let W = 0, H = 0;
63
- const { pause: et, resume: tt, isActive: at } = Ne(
66
+ const Re = J(), Ee = J(), X = J(), D = new ye();
67
+ let H = 0, U = 0;
68
+ const { pause: tt, resume: at, isActive: nt } = qe(
64
69
  () => {
65
- xe.trigger({ delta: W, elapsed: H, clock: j }), Re.trigger({ delta: W, elapsed: H, clock: j }), X.trigger({ delta: W, elapsed: H, clock: j });
70
+ Re.trigger({ delta: H, elapsed: U, clock: D }), Ee.trigger({ delta: H, elapsed: U, clock: D }), X.trigger({ delta: H, elapsed: U, clock: D });
66
71
  },
67
72
  { immediate: !1 }
68
73
  );
69
74
  X.on(() => {
70
- W = j.getDelta(), H = j.getElapsedTime();
75
+ H = D.getDelta(), U = D.getElapsedTime();
71
76
  });
72
- function Ee() {
77
+ function Pe() {
73
78
  return {
74
- onBeforeLoop: xe.on,
75
- onLoop: Re.on,
79
+ onBeforeLoop: Re.on,
80
+ onLoop: Ee.on,
76
81
  onAfterLoop: X.on,
77
- pause: et,
78
- resume: tt,
79
- isActive: at
82
+ pause: tt,
83
+ resume: at,
84
+ isActive: nt
80
85
  };
81
86
  }
82
- function nt(e) {
87
+ function rt(e) {
83
88
  return e instanceof N ? e : Array.isArray(e) ? new N(...e) : new N(e);
84
89
  }
85
90
  const K = {
86
91
  realistic: {
87
- outputColorSpace: Be,
92
+ outputColorSpace: Fe,
88
93
  toneMapping: ze,
89
94
  toneMappingExposure: 3,
90
95
  shadowMap: {
@@ -92,118 +97,118 @@ const K = {
92
97
  type: Ge
93
98
  }
94
99
  }
95
- }, Pe = (e, t) => {
100
+ }, Se = (e, t) => {
96
101
  for (const o of Object.keys(t))
97
- t[o] instanceof Object && Object.assign(t[o], Pe(e[o], t[o]));
102
+ t[o] instanceof Object && Object.assign(t[o], Se(e[o], t[o]));
98
103
  return Object.assign(e || {}, t), e;
99
- }, rt = "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", ot = /* @__PURE__ */ it(rt);
104
+ }, ot = "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", it = /* @__PURE__ */ st(ot);
100
105
  function V(e) {
101
106
  return e.replace(/-([a-z])/g, (t, o) => o.toUpperCase());
102
107
  }
103
- function it(e, t) {
108
+ function st(e, t) {
104
109
  const o = /* @__PURE__ */ Object.create(null), a = e.split(",");
105
110
  for (let n = 0; n < a.length; n++)
106
111
  o[a[n]] = !0;
107
112
  return t ? (n) => !!o[n.toLowerCase()] : (n) => !!o[n];
108
113
  }
109
- function st(e) {
114
+ function ct(e) {
110
115
  var te, ae;
111
- const t = de(), o = E(!1), {
116
+ const t = me(), o = E(!1), {
112
117
  alpha: a = !0,
113
118
  antialias: n = !0,
114
119
  depth: r,
115
120
  logarithmicDepthBuffer: c,
116
121
  failIfMajorPerformanceCaveat: i,
117
122
  precision: s,
118
- premultipliedAlpha: u,
119
- stencil: f,
123
+ premultipliedAlpha: f,
124
+ stencil: u,
120
125
  shadows: m = !1,
121
- shadowMapType: v = Ve,
122
- useLegacyLights: h = !1,
123
- outputColorSpace: M = ne,
124
- toneMapping: w = re,
126
+ shadowMapType: g = Ve,
127
+ useLegacyLights: w = !1,
128
+ outputColorSpace: C = ne,
129
+ toneMapping: h = re,
125
130
  toneMappingExposure: P = 1,
126
- context: C = void 0,
127
- powerPreference: U = "default",
131
+ context: M = void 0,
132
+ powerPreference: O = "default",
128
133
  preserveDrawingBuffer: S = !1,
129
134
  clearColor: d,
130
135
  windowSize: b = !1,
131
136
  preset: y = void 0
132
- } = me(e), { state: g, setState: T } = _(), { width: O, height: x } = l(b) == !0 || l(b) === "" || l(b) === "true" ? qe() : Ke(g.container), { logError: I, logWarning: B } = D(), { pixelRatio: R } = Je(), { pause: z, resume: G } = Ee(), Y = pe(() => O.value / x.value);
133
- !l(b) && ((ae = (te = g.container) == null ? void 0 : te.value) == null ? void 0 : ae.offsetHeight) === 0 && B(`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.
137
+ } = pe(e), { state: v, setState: T } = _(), { width: k, height: x } = l(b) == !0 || l(b) === "" || l(b) === "true" ? Ke() : Je(v.container), { logError: B, logWarning: F } = I(), { pixelRatio: R } = Xe(), { pause: z, resume: G } = Pe(), Y = ve(() => k.value / x.value);
138
+ !l(b) && ((ae = (te = v.container) == null ? void 0 : te.value) == null ? void 0 : ae.offsetHeight) === 0 && F(`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.
134
139
  You could set windowSize=true to force the canvas to be the size of the window.`);
135
140
  const Z = () => {
136
- t.value && (t.value.setSize(O.value, x.value), t.value.setPixelRatio(Math.min(R.value, 2)));
141
+ t.value && (t.value.setSize(k.value, x.value), t.value.setPixelRatio(Math.min(R.value, 2)));
137
142
  }, ee = () => {
138
143
  if (!t.value)
139
144
  return;
140
145
  const L = l(y);
141
146
  if (L) {
142
- L in K || I("Renderer Preset must be one of these: " + Object.keys(K).join(", ")), Pe(t.value, K[L]);
147
+ L in K || B("Renderer Preset must be one of these: " + Object.keys(K).join(", ")), Se(t.value, K[L]);
143
148
  return;
144
149
  }
145
- t.value.shadowMap.enabled = l(m), t.value.shadowMap.type = l(v), t.value.toneMapping = l(w) || re, t.value.toneMappingExposure = l(P), t.value.outputColorSpace = l(M) || ne, d != null && d.value && t.value.setClearColor(nt(l(d))), t.value.useLegacyLights = l(h);
146
- }, Te = () => {
147
- const L = q(g.canvas);
148
- L && (t.value = new Fe({
150
+ t.value.shadowMap.enabled = l(m), t.value.shadowMap.type = l(g), t.value.toneMapping = l(h) || re, t.value.toneMappingExposure = l(P), t.value.outputColorSpace = l(C) || ne, d != null && d.value && t.value.setClearColor(rt(l(d))), t.value.useLegacyLights = l(w);
151
+ }, Le = () => {
152
+ const L = q(v.canvas);
153
+ L && (t.value = new We({
149
154
  canvas: L,
150
155
  alpha: l(a),
151
156
  antialias: l(n),
152
- context: l(C),
157
+ context: l(M),
153
158
  depth: l(r),
154
159
  failIfMajorPerformanceCaveat: l(i),
155
160
  logarithmicDepthBuffer: l(c),
156
- powerPreference: l(U),
161
+ powerPreference: l(O),
157
162
  precision: l(s),
158
- stencil: l(f),
163
+ stencil: l(u),
159
164
  preserveDrawingBuffer: l(S),
160
- premultipliedAlpha: l(u)
161
- }), T("renderer", t.value), T("clock", new be()), T("aspectRatio", Y), ee(), Z(), G(), o.value = !0);
162
- }, Le = () => {
165
+ premultipliedAlpha: l(f)
166
+ }), T("renderer", t.value), T("clock", new ye()), T("aspectRatio", Y), ee(), Z(), G(), o.value = !0);
167
+ }, Ae = () => {
163
168
  t.value && (t.value.dispose(), t.value = void 0, o.value = !1, z());
164
169
  };
165
- return F([Y, R], Z), F(
166
- [m, v, M, h, w, P, d],
170
+ return W([Y, R], Z), W(
171
+ [m, g, C, w, h, P, d],
167
172
  ee
168
- ), F(
169
- () => [g.canvas, g.container],
173
+ ), W(
174
+ () => [v.canvas, v.container],
170
175
  () => {
171
- q(g.canvas) && q(g.container) && Te();
176
+ q(v.canvas) && q(v.container) && Le();
172
177
  },
173
178
  { immediate: !0, deep: !0 }
174
179
  ), {
175
180
  renderer: t,
176
181
  isReady: o,
177
- dispose: Le,
182
+ dispose: Ae,
178
183
  aspectRatio: Y
179
184
  };
180
185
  }
181
- const oe = (e) => typeof e == "function", ct = (e) => typeof e == "string", Se = (e) => !!e && e.constructor === Array;
186
+ const oe = (e) => typeof e == "function", ft = (e) => typeof e == "string", Te = (e) => !!e && e.constructor === Array;
182
187
  function ut(e) {
183
188
  const t = { nodes: {}, materials: {} };
184
189
  return e && e.traverse((o) => {
185
190
  o.name && (t.nodes[o.name] = o), o.material && !t.materials[o.material.name] && (t.materials[o.material.name] = o.material);
186
191
  }), t;
187
192
  }
188
- async function xt(e, t, o, a, n) {
189
- const { logError: r } = D(), c = new e();
193
+ async function Rt(e, t, o, a, n) {
194
+ const { logError: r } = I(), c = new e();
190
195
  n && n(c), o && o(c);
191
196
  const s = (Array.isArray(t) ? t : [t]).map(
192
- (u) => new Promise((f, m) => {
197
+ (f) => new Promise((u, m) => {
193
198
  c.load(
194
- u,
195
- (v) => {
196
- v.scene && Object.assign(v, ut(v.scene)), f(v);
199
+ f,
200
+ (g) => {
201
+ g.scene && Object.assign(g, ut(g.scene)), u(g);
197
202
  },
198
203
  a,
199
- (v) => m(r("[useLoader] - Failed to load resource", v))
204
+ (g) => m(r("[useLoader] - Failed to load resource", g))
200
205
  );
201
206
  })
202
207
  );
203
- return Se(t) ? await Promise.all(s) : await s[0];
208
+ return Te(t) ? await Promise.all(s) : await s[0];
204
209
  }
205
- async function Rt(e) {
206
- const t = new We(), o = new He(t), a = (n) => new Promise((r, c) => {
210
+ async function Et(e) {
211
+ const t = new He(), o = new Ue(t), a = (n) => new Promise((r, c) => {
207
212
  o.load(
208
213
  n,
209
214
  (i) => r(i),
@@ -213,7 +218,7 @@ async function Rt(e) {
213
218
  }
214
219
  );
215
220
  });
216
- if (Se(e)) {
221
+ if (Te(e)) {
217
222
  const n = await Promise.all(e.map((r) => a(r)));
218
223
  return e.length > 1 ? n : n[0];
219
224
  } else {
@@ -223,8 +228,8 @@ async function Rt(e) {
223
228
  normalMap: c,
224
229
  roughnessMap: i,
225
230
  metalnessMap: s,
226
- aoMap: u,
227
- alphaMap: f,
231
+ aoMap: f,
232
+ alphaMap: u,
228
233
  matcap: m
229
234
  } = e;
230
235
  return {
@@ -233,26 +238,26 @@ async function Rt(e) {
233
238
  normalMap: c ? await a(c) : null,
234
239
  roughnessMap: i ? await a(i) : null,
235
240
  metalnessMap: s ? await a(s) : null,
236
- aoMap: u ? await a(u) : null,
237
- alphaMap: f ? await a(f) : null,
241
+ aoMap: f ? await a(f) : null,
242
+ alphaMap: u ? await a(u) : null,
238
243
  matcap: m ? await a(m) : null
239
244
  };
240
245
  }
241
246
  }
242
247
  const p = ["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"];
243
- function ft() {
248
+ function lt() {
244
249
  const e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, o = Math.random() * 4294967295 | 0, a = Math.random() * 4294967295 | 0;
245
250
  return (p[e & 255] + p[e >> 8 & 255] + p[e >> 16 & 255] + p[e >> 24 & 255] + "-" + p[t & 255] + p[t >> 8 & 255] + "-" + p[t >> 16 & 15 | 64] + p[t >> 24 & 255] + "-" + p[o & 63 | 128] + p[o >> 8 & 255] + "-" + p[o >> 16 & 255] + p[o >> 24 & 255] + p[a & 255] + p[a >> 8 & 255] + p[a >> 16 & 255] + p[a >> 24 & 255]).toLowerCase();
246
251
  }
247
252
  const Q = Symbol();
248
- function lt() {
249
- const e = ve({
250
- uuid: ft(),
253
+ function dt() {
254
+ const e = ge({
255
+ uuid: lt(),
251
256
  camera: void 0,
252
257
  cameras: [],
253
258
  scene: void 0,
254
259
  renderer: void 0,
255
- aspectRatio: pe(() => window.innerWidth / window.innerHeight)
260
+ aspectRatio: ve(() => window.innerWidth / window.innerHeight)
256
261
  });
257
262
  function t(n) {
258
263
  return e[n];
@@ -262,28 +267,28 @@ function lt() {
262
267
  }
263
268
  const a = {
264
269
  state: e,
265
- ...me(e),
270
+ ...pe(e),
266
271
  getState: t,
267
272
  setState: o
268
273
  };
269
- return _e(Q, a), a;
274
+ return Oe(Q, a), a;
270
275
  }
271
- const _ = () => Oe(Q, {
272
- state: ve({
276
+ const _ = () => ke(Q, {
277
+ state: ge({
273
278
  camera: void 0,
274
279
  cameras: [],
275
280
  scene: void 0,
276
281
  renderer: void 0
277
282
  })
278
283
  });
279
- function dt() {
284
+ function mt() {
280
285
  var c;
281
- const e = de(new Ue()), t = E(new Ye()), o = E(null), { setState: a, state: n } = _();
286
+ const e = me(new Ye()), t = E(new $e()), o = E(null), { setState: a, state: n } = _();
282
287
  a("raycaster", e.value), a("pointer", t), a("currentInstance", o);
283
288
  function r(i) {
284
289
  t.value.x = i.clientX / window.innerWidth * 2 - 1, t.value.y = -(i.clientY / window.innerHeight) * 2 + 1;
285
290
  }
286
- return (c = n == null ? void 0 : n.renderer) == null || c.domElement.addEventListener("pointermove", r), ge(() => {
291
+ return (c = n == null ? void 0 : n.renderer) == null || c.domElement.addEventListener("pointermove", r), he(() => {
287
292
  var i;
288
293
  (i = n == null ? void 0 : n.renderer) == null || i.domElement.removeEventListener("pointermove", r);
289
294
  }), {
@@ -291,8 +296,8 @@ function dt() {
291
296
  pointer: t
292
297
  };
293
298
  }
294
- const Et = !0, ie = "[TresJS ▲ ■ ●] ";
295
- function D() {
299
+ const Pt = !0, ie = "[TresJS ▲ ■ ●] ";
300
+ function I() {
296
301
  function e(a, n) {
297
302
  console.error(`${ie} ${a}`, n || "");
298
303
  }
@@ -307,8 +312,8 @@ function D() {
307
312
  logMessage: o
308
313
  };
309
314
  }
310
- function Pt() {
311
- const { logWarning: e } = D();
315
+ function St() {
316
+ const { logWarning: e } = I();
312
317
  function t(a, n, r) {
313
318
  let c = null;
314
319
  return a.traverse((i) => {
@@ -323,33 +328,35 @@ function Pt() {
323
328
  seekByName: o
324
329
  };
325
330
  }
326
- const mt = /^on[^a-z]/, pt = (e) => mt.test(e);
331
+ const pt = /^on[^a-z]/, vt = (e) => pt.test(e);
327
332
  let se = null;
328
333
  const ce = {
329
334
  GEOMETRY_VIA_PROP: "tres__geometryViaProp",
330
335
  MATERIAL_VIA_PROP: "tres__materialViaProp"
331
- }, { logError: ue } = D(), vt = {
336
+ }, { logError: fe } = I();
337
+ let ue = !0;
338
+ const gt = {
332
339
  createElement(e, t, o, a) {
333
- var s, u;
334
- if (a || (a = {}), a.args || (a.args = []), e === "template" || ot(e))
340
+ var s, f;
341
+ if (a || (a = {}), a.args || (a.args = []), e === "template" || it(e))
335
342
  return null;
336
343
  let n = e.replace("Tres", ""), r;
337
344
  if (e === "primitive") {
338
- (a == null ? void 0 : a.object) === void 0 && ue("Tres primitives need a prop 'object'");
339
- const f = a.object;
340
- n = f.type, r = Object.assign(f, { type: n, attach: a.attach, primitive: !0 });
345
+ (a == null ? void 0 : a.object) === void 0 && fe("Tres primitives need a prop 'object'");
346
+ const u = a.object;
347
+ n = u.type, r = Object.assign(u, { type: n, attach: a.attach, primitive: !0 });
341
348
  } else {
342
- const f = ye.value[n];
343
- f || ue(`${n} is not defined on the THREE namespace. Use extend to add it to the catalog.`), r = new f(...a.args);
349
+ const u = Ce.value[n];
350
+ u || fe(`${n} is not defined on the THREE namespace. Use extend to add it to the catalog.`), r = new u(...a.args);
344
351
  }
345
- if (r.isCamera) {
352
+ if (r.isCamera && ue) {
346
353
  a != null && a.position || r.position.set(3, 3, 3), a != null && a.lookAt || r.lookAt(0, 0, 0);
347
- const { pushCamera: f } = Ce();
348
- f(r);
354
+ const { setFirstCamera: u } = xe();
355
+ u(r), ue = !1;
349
356
  }
350
357
  (a == null ? void 0 : a.attach) === void 0 && (r.isMaterial ? r.attach = "material" : r.isBufferGeometry && (r.attach = "geometry"));
351
358
  const { GEOMETRY_VIA_PROP: c, MATERIAL_VIA_PROP: i } = ce;
352
- return r.isObject3D && ((s = a == null ? void 0 : a.material) != null && s.isMaterial && (r.userData[i] = !0), (u = a == null ? void 0 : a.geometry) != null && u.isBufferGeometry && (r.userData[c] = !0)), r.events = {}, r;
359
+ return r.isObject3D && ((s = a == null ? void 0 : a.material) != null && s.isMaterial && (r.userData[i] = !0), (f = a == null ? void 0 : a.geometry) != null && f.isBufferGeometry && (r.userData[c] = !0)), r.events = {}, r;
353
360
  },
354
361
  insert(e, t) {
355
362
  var o, a, n, r;
@@ -357,16 +364,16 @@ const ce = {
357
364
  se = e;
358
365
  return;
359
366
  }
360
- t || (t = se), e != null && e.isObject3D && (t != null && t.isObject3D) ? (t.add(e), e.dispatchEvent({ type: "added" })) : typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
367
+ t || (t = se), e != null && e.isObject3D && (t != null && t.isObject3D) ? (t.add(e), e.dispatchEvent({ type: "added" })) : e != null && e.isFog ? t.fog = e : typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
361
368
  },
362
369
  remove(e) {
363
370
  var t, o;
364
371
  if (e) {
365
372
  if (e.isObject3D) {
366
373
  const a = e, n = (r) => {
367
- var s, u;
374
+ var s, f;
368
375
  const { GEOMETRY_VIA_PROP: c, MATERIAL_VIA_PROP: i } = ce;
369
- r.userData[i] || (s = r.material) == null || s.dispose(), r.userData[c] || (u = r.geometry) == null || u.dispose();
376
+ r.userData[i] || (s = r.material) == null || s.dispose(), r.userData[c] || (f = r.geometry) == null || f.dispose();
370
377
  };
371
378
  a.traverse((r) => n(r)), n(a);
372
379
  }
@@ -381,15 +388,15 @@ const ce = {
381
388
  return;
382
389
  n.setAttribute(
383
390
  V(r),
384
- new $e(...a)
391
+ new Ne(...a)
385
392
  );
386
393
  return;
387
394
  }
388
395
  if (r.includes("-") && i === void 0) {
389
- const u = r.split("-");
390
- i = u.reduce((f, m) => f[V(m)], n), r = u.pop(), c = r.toLowerCase(), i != null && i.set || (n = u.reduce((f, m) => f[V(m)], n));
396
+ const f = r.split("-");
397
+ i = f.reduce((u, m) => u[V(m)], n), r = f.pop(), c = r.toLowerCase(), i != null && i.set || (n = f.reduce((u, m) => u[V(m)], n));
391
398
  }
392
- pt(r) && (e.events[r] = a);
399
+ vt(r) && (e.events[r] = a);
393
400
  let s = a;
394
401
  if (s === "" && (s = !0), oe(i)) {
395
402
  Array.isArray(s) ? e[c](...s) : e[c](s);
@@ -410,15 +417,15 @@ const ce = {
410
417
  setScopeId: () => void 0,
411
418
  cloneNode: () => void 0,
412
419
  insertStaticContent: () => void 0
413
- }, { createApp: gt } = ke(vt), ht = (e) => {
414
- const t = gt(o);
420
+ }, { createApp: ht } = je(gt), wt = (e) => {
421
+ const t = ht(o);
415
422
  function o() {
416
423
  return e && e.default ? e.default() : [];
417
424
  }
418
425
  return t;
419
426
  };
420
- Me(we);
421
- const { logWarning: fe } = D(), wt = he({
427
+ Me(be);
428
+ const { logWarning: le } = I(), bt = we({
422
429
  name: "TresScene",
423
430
  props: [
424
431
  "shadows",
@@ -438,47 +445,47 @@ const { logWarning: fe } = D(), wt = he({
438
445
  "camera"
439
446
  ],
440
447
  setup(e, { slots: t, expose: o }) {
441
- e.physicallyCorrectLights === !0 && fe("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
442
- const a = E(), n = E(), r = new we.Scene(), { setState: c } = _();
448
+ e.physicallyCorrectLights === !0 && le("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
449
+ const a = E(), n = E(), r = new be.Scene(), { setState: c } = _();
443
450
  c("scene", r), c("canvas", n), c("container", a);
444
451
  const i = E(), s = t && t.default && t.default();
445
- s && (s == null ? void 0 : s.length) > 0 && (i.value = s.some((w) => ct(w.type) && w.type.includes("Camera")) || e.camera, i.value || fe("No camera found in the scene, please add one!")), je(() => {
446
- v();
447
- }), ge(() => {
452
+ s && (s == null ? void 0 : s.length) > 0 && (i.value = s.some((h) => ft(h.type) && h.type.includes("Camera")) || e.camera, i.value || le("No camera found in the scene, please add one!")), De(() => {
453
+ g();
454
+ }), he(() => {
448
455
  c("renderer", null);
449
456
  });
450
- const { activeCamera: u, pushCamera: f, clearCameras: m } = Ce();
451
- function v() {
452
- const { renderer: w } = st(e);
453
- e.camera && f(e.camera);
454
- const { onLoop: P } = Ee(), { raycaster: C, pointer: U } = dt();
457
+ const { activeCamera: f, pushCamera: u, clearCameras: m } = xe();
458
+ function g() {
459
+ const { renderer: h } = ct(e);
460
+ e.camera && u(e.camera);
461
+ const { onLoop: P } = Pe(), { raycaster: M, pointer: O } = mt();
455
462
  let S = null, d = null;
456
- le(() => {
457
- u.value && C.value.setFromCamera(U.value, u.value);
463
+ de(() => {
464
+ f.value && M.value.setFromCamera(O.value, f.value);
458
465
  }), P(() => {
459
- var b, y, g, T, O, x, I, B, R, z;
460
- if (u.value && e.disableRender !== !0 && e.disableRender !== "" && ((b = w.value) == null || b.render(r, u.value)), C.value) {
461
- const G = C.value.intersectObjects(r.children);
462
- G.length > 0 ? (d = G[0], S === null && ((T = (g = (y = d.object) == null ? void 0 : y.events) == null ? void 0 : g.onPointerEnter) == null || T.call(g, d)), (I = (x = (O = d.object) == null ? void 0 : O.events) == null ? void 0 : x.onPointerMove) == null || I.call(x, d)) : S !== null && ((z = (R = (B = d == null ? void 0 : d.object) == null ? void 0 : B.events) == null ? void 0 : R.onPointerLeave) == null || z.call(R, S), d = null), S = d;
466
+ var b, y, v, T, k, x, B, F, R, z;
467
+ if (f.value && e.disableRender !== !0 && ((b = h.value) == null || b.render(r, f.value)), M.value) {
468
+ const G = M.value.intersectObjects(r.children);
469
+ G.length > 0 ? (d = G[0], S === null && ((T = (v = (y = d.object) == null ? void 0 : y.events) == null ? void 0 : v.onPointerEnter) == null || T.call(v, d)), (B = (x = (k = d.object) == null ? void 0 : k.events) == null ? void 0 : x.onPointerMove) == null || B.call(x, d)) : S !== null && ((z = (R = (F = d == null ? void 0 : d.object) == null ? void 0 : F.events) == null ? void 0 : R.onPointerLeave) == null || z.call(R, S), d = null), S = d;
463
470
  }
464
- }), Xe(n.value, "click", () => {
465
- var b, y, g;
466
- d !== null && ((g = (y = (b = d.object) == null ? void 0 : b.events) == null ? void 0 : y.onClick) == null || g.call(y, d));
471
+ }), Qe(n.value, "click", () => {
472
+ var b, y, v;
473
+ d !== null && ((v = (y = (b = d.object) == null ? void 0 : b.events) == null ? void 0 : y.onClick) == null || v.call(y, d));
467
474
  });
468
475
  }
469
- let h;
470
- function M() {
471
- h = ht(t), h.provide("useTres", _()), h.provide(Q, _()), h.provide("extend", Me), h.mount(r);
476
+ let w;
477
+ function C() {
478
+ w = wt(t), w.provide("useTres", _()), w.provide(Q, _()), w.provide("extend", Me), w.mount(r);
472
479
  }
473
- return M(), o({
480
+ return C(), o({
474
481
  scene: r
475
- }), F(
482
+ }), W(
476
483
  () => e.camera,
477
- (w) => {
478
- w && (m(), f(w));
484
+ (h) => {
485
+ h && (m(), u(h));
479
486
  }
480
- ), () => k(
481
- k(
487
+ ), () => j(
488
+ j(
482
489
  "div",
483
490
  {
484
491
  ref: a,
@@ -493,7 +500,7 @@ const { logWarning: fe } = D(), wt = he({
493
500
  }
494
501
  },
495
502
  [
496
- k(
503
+ j(
497
504
  "div",
498
505
  {
499
506
  style: {
@@ -502,7 +509,7 @@ const { logWarning: fe } = D(), wt = he({
502
509
  }
503
510
  },
504
511
  [
505
- k("canvas", {
512
+ j("canvas", {
506
513
  ref: n,
507
514
  "data-scene": r.uuid,
508
515
  style: {
@@ -520,7 +527,7 @@ const { logWarning: fe } = D(), wt = he({
520
527
  )
521
528
  );
522
529
  }
523
- }), bt = he({
530
+ }), yt = we({
524
531
  name: "TresCanvas",
525
532
  props: [
526
533
  "shadows",
@@ -540,31 +547,31 @@ const { logWarning: fe } = D(), wt = he({
540
547
  "camera"
541
548
  ],
542
549
  setup(e, { slots: t, expose: o }) {
543
- const a = lt();
544
- return o(a), () => k(wt, e, t);
550
+ const a = dt();
551
+ return o(a), () => j(bt, e, t);
545
552
  }
546
- }), St = {
553
+ }), Tt = {
547
554
  install(e) {
548
- e.component("TresCanvas", bt);
555
+ e.component("TresCanvas", yt);
549
556
  }
550
557
  };
551
558
  export {
552
- Qe as CameraType,
559
+ Ze as CameraType,
553
560
  Q as TRES_CONTEXT_KEY,
554
- bt as TresCanvas,
555
- ye as catalogue,
556
- St as default,
561
+ yt as TresCanvas,
562
+ Ce as catalogue,
563
+ Tt as default,
557
564
  Me as extend,
558
- Et as isProd,
565
+ Pt as isProd,
559
566
  ut as trasverseObjects,
560
- Ce as useCamera,
561
- xt as useLoader,
562
- D as useLogger,
563
- dt as useRaycaster,
564
- Ee as useRenderLoop,
565
- st as useRenderer,
566
- Pt as useSeek,
567
- Rt as useTexture,
567
+ xe as useCamera,
568
+ Rt as useLoader,
569
+ I as useLogger,
570
+ mt as useRaycaster,
571
+ Pe as useRenderLoop,
572
+ ct as useRenderer,
573
+ St as useSeek,
574
+ Et as useTexture,
568
575
  _ as useTres,
569
- lt as useTresProvider
576
+ dt as useTresProvider
570
577
  };
package/dist/tres.umd.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v2.0.0-rc.2
3
+ * version: v2.0.0-rc.4
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(l,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],s):(l=typeof globalThis<"u"?globalThis:l||self,s(l.tres={},l.Vue,l.Three,l.VueUseCore))})(this,function(l,s,d,u){"use strict";function ye(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const a=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,a.get?a:{enumerable:!0,get:()=>e[o]})}}return t.default=e,Object.freeze(t)}const H=ye(d),Y=s.ref({uuid:d.MathUtils.generateUUID()}),$=e=>void Object.assign(Y.value,e);var ee=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(ee||{});const Ce=45;let A;function q(){const{state:e,setState:t,aspectRatio:o}=L();function a(i="Perspective",c){var m,p,h;if(i==="Perspective"){const{near:w,far:y,fov:P}=c||{near:.1,far:1e3,fov:Ce};A=new d.PerspectiveCamera(P,((m=e.aspectRatio)==null?void 0:m.value)||window.innerWidth/window.innerHeight,w,y),(p=e.cameras)==null||p.push(A)}else{const{left:w,right:y,top:P,bottom:C,near:V,far:_}=c||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};A=new d.OrthographicCamera(w,y,P,C,V,_),(h=e.cameras)==null||h.push(A)}return e.camera=A,t("camera",e.camera),A}function n(){var i;e.camera instanceof d.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(i=e.camera)==null||i.updateProjectionMatrix()}function r(i){var c;(c=e.cameras)==null||c.push(i),i instanceof d.PerspectiveCamera&&e.aspectRatio&&(i.aspect=e.aspectRatio.value),i.updateProjectionMatrix(),t("camera",i)}function f(){e.cameras=[]}return s.watchEffect(()=>{o!=null&&o.value&&n()}),{activeCamera:s.toRef(e,"camera"),createCamera:a,updateCamera:n,pushCamera:r,clearCameras:f}}const te=u.createEventHook(),ae=u.createEventHook(),K=u.createEventHook(),D=new d.Clock;let B=0,G=0;const{pause:Me,resume:Se,isActive:Pe}=u.useRafFn(()=>{te.trigger({delta:B,elapsed:G,clock:D}),ae.trigger({delta:B,elapsed:G,clock:D}),K.trigger({delta:B,elapsed:G,clock:D})},{immediate:!1});K.on(()=>{B=D.getDelta(),G=D.getElapsedTime()});function X(){return{onBeforeLoop:te.on,onLoop:ae.on,onAfterLoop:K.on,pause:Me,resume:Se,isActive:Pe}}function Le(e){return e instanceof d.Color?e:Array.isArray(e)?new d.Color(...e):new d.Color(e)}const J={realistic:{outputColorSpace:d.SRGBColorSpace,toneMapping:d.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:d.PCFSoftShadowMap}}},ne=(e,t)=>{for(const o of Object.keys(t))t[o]instanceof Object&&Object.assign(t[o],ne(e[o],t[o]));return Object.assign(e||{},t),e},_e=Oe("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 z(e){return e.replace(/-([a-z])/g,(t,o)=>o.toUpperCase())}function Oe(e,t){const o=Object.create(null),a=e.split(",");for(let n=0;n<a.length;n++)o[a[n]]=!0;return t?n=>!!o[n.toLowerCase()]:n=>!!o[n]}function re(e){var we,be;const t=s.shallowRef(),o=s.ref(!1),{alpha:a=!0,antialias:n=!0,depth:r,logarithmicDepthBuffer:f,failIfMajorPerformanceCaveat:i,precision:c,premultipliedAlpha:m,stencil:p,shadows:h=!1,shadowMapType:w=d.PCFShadowMap,useLegacyLights:y=!1,outputColorSpace:P=d.LinearSRGBColorSpace,toneMapping:C=d.NoToneMapping,toneMappingExposure:V=1,context:_=void 0,powerPreference:Q="default",preserveDrawingBuffer:R=!1,clearColor:v,windowSize:M=!1,preset:S=void 0}=s.toRefs(e),{state:b,setState:k}=L(),{width:I,height:O}=u.toValue(M)==!0||u.toValue(M)===""||u.toValue(M)==="true"?u.useWindowSize():u.useElementSize(b.container),{logError:U,logWarning:W}=T(),{pixelRatio:x}=u.useDevicePixelRatio(),{pause:E,resume:N}=X(),Z=s.computed(()=>I.value/O.value);!u.toValue(M)&&((be=(we=b.container)==null?void 0:we.value)==null?void 0:be.offsetHeight)===0&&W(`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 ge=()=>{t.value&&(t.value.setSize(I.value,O.value),t.value.setPixelRatio(Math.min(x.value,2)))},he=()=>{if(!t.value)return;const j=u.toValue(S);if(j){j in J||U("Renderer Preset must be one of these: "+Object.keys(J).join(", ")),ne(t.value,J[j]);return}t.value.shadowMap.enabled=u.toValue(h),t.value.shadowMap.type=u.toValue(w),t.value.toneMapping=u.toValue(C)||d.NoToneMapping,t.value.toneMappingExposure=u.toValue(V),t.value.outputColorSpace=u.toValue(P)||d.LinearSRGBColorSpace,v!=null&&v.value&&t.value.setClearColor(Le(u.toValue(v))),t.value.useLegacyLights=u.toValue(y)},Ue=()=>{const j=u.unrefElement(b.canvas);j&&(t.value=new d.WebGLRenderer({canvas:j,alpha:u.toValue(a),antialias:u.toValue(n),context:u.toValue(_),depth:u.toValue(r),failIfMajorPerformanceCaveat:u.toValue(i),logarithmicDepthBuffer:u.toValue(f),powerPreference:u.toValue(Q),precision:u.toValue(c),stencil:u.toValue(p),preserveDrawingBuffer:u.toValue(R),premultipliedAlpha:u.toValue(m)}),k("renderer",t.value),k("clock",new d.Clock),k("aspectRatio",Z),he(),ge(),N(),o.value=!0)},We=()=>{t.value&&(t.value.dispose(),t.value=void 0,o.value=!1,E())};return s.watch([Z,x],ge),s.watch([h,w,P,y,C,V,v],he),s.watch(()=>[b.canvas,b.container],()=>{u.unrefElement(b.canvas)&&u.unrefElement(b.container)&&Ue()},{immediate:!0,deep:!0}),{renderer:t,isReady:o,dispose:We,aspectRatio:Z}}const oe=e=>typeof e=="function",xe=e=>typeof e=="string",ie=e=>!!e&&e.constructor===Array;function se(e){const t={nodes:{},materials:{}};return e&&e.traverse(o=>{o.name&&(t.nodes[o.name]=o),o.material&&!t.materials[o.material.name]&&(t.materials[o.material.name]=o.material)}),t}async function Ae(e,t,o,a,n){const{logError:r}=T(),f=new e;n&&n(f),o&&o(f);const c=(Array.isArray(t)?t:[t]).map(m=>new Promise((p,h)=>{f.load(m,w=>{w.scene&&Object.assign(w,se(w.scene)),p(w)},a,w=>h(r("[useLoader] - Failed to load resource",w)))}));return ie(t)?await Promise.all(c):await c[0]}async function Te(e){const t=new d.LoadingManager,o=new d.TextureLoader(t),a=n=>new Promise((r,f)=>{o.load(n,i=>r(i),()=>null,()=>{f(new Error("[useTextures] - Failed to load texture"))})});if(ie(e)){const n=await Promise.all(e.map(r=>a(r)));return e.length>1?n:n[0]}else{const{map:n,displacementMap:r,normalMap:f,roughnessMap:i,metalnessMap:c,aoMap:m,alphaMap:p,matcap:h}=e;return{map:n?await a(n):null,displacementMap:r?await a(r):null,normalMap:f?await a(f):null,roughnessMap:i?await a(i):null,metalnessMap:c?await a(c):null,aoMap:m?await a(m):null,alphaMap:p?await a(p):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 Ve(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,o=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[o&63|128]+g[o>>8&255]+"-"+g[o>>16&255]+g[o>>24&255]+g[a&255]+g[a>>8&255]+g[a>>16&255]+g[a>>24&255]).toLowerCase()}const F=Symbol();function ce(){const e=s.shallowReactive({uuid:Ve(),camera:void 0,cameras:[],scene:void 0,renderer:void 0,aspectRatio:s.computed(()=>window.innerWidth/window.innerHeight)});function t(n){return e[n]}function o(n,r){e[n]=r}const a={state:e,...s.toRefs(e),getState:t,setState:o};return s.provide(F,a),a}const L=()=>s.inject(F,{state:s.shallowReactive({camera:void 0,cameras:[],scene:void 0,renderer:void 0})});function ue(){var f;const e=s.shallowRef(new d.Raycaster),t=s.ref(new d.Vector2),o=s.ref(null),{setState:a,state:n}=L();a("raycaster",e.value),a("pointer",t),a("currentInstance",o);function r(i){t.value.x=i.clientX/window.innerWidth*2-1,t.value.y=-(i.clientY/window.innerHeight)*2+1}return(f=n==null?void 0:n.renderer)==null||f.domElement.addEventListener("pointermove",r),s.onUnmounted(()=>{var i;(i=n==null?void 0:n.renderer)==null||i.domElement.removeEventListener("pointermove",r)}),{raycaster:e,pointer:t}}const Re=!0,fe="[TresJS ▲ ■ ●] ";function T(){function e(a,n){console.error(`${fe} ${a}`,n||"")}function t(a){console.warn(`${fe} ${a}`)}function o(a,n){}return{logError:e,logWarning:t,logMessage:o}}function ke(){const{logWarning:e}=T();function t(a,n,r){let f=null;return a.traverse(i=>{i[n]===r&&(f=i)}),f||e(`Child with ${n} '${r}' not found.`),f}function o(a,n){return t(a,"name",n)}return{seek:t,seekByName:o}}const je=/^on[^a-z]/,De=e=>je.test(e);function Ne(e){}let le=null;const de={GEOMETRY_VIA_PROP:"tres__geometryViaProp",MATERIAL_VIA_PROP:"tres__materialViaProp"},{logError:me}=T(),Ie={createElement(e,t,o,a){var c,m;if(a||(a={}),a.args||(a.args=[]),e==="template"||_e(e))return null;let n=e.replace("Tres",""),r;if(e==="primitive"){(a==null?void 0:a.object)===void 0&&me("Tres primitives need a prop 'object'");const p=a.object;n=p.type,r=Object.assign(p,{type:n,attach:a.attach,primitive:!0})}else{const p=Y.value[n];p||me(`${n} is not defined on the THREE namespace. Use extend to add it to the catalog.`),r=new p(...a.args)}if(r.isCamera){a!=null&&a.position||r.position.set(3,3,3),a!=null&&a.lookAt||r.lookAt(0,0,0);const{pushCamera:p}=q();p(r)}(a==null?void 0:a.attach)===void 0&&(r.isMaterial?r.attach="material":r.isBufferGeometry&&(r.attach="geometry"));const{GEOMETRY_VIA_PROP:f,MATERIAL_VIA_PROP:i}=de;return r.isObject3D&&((c=a==null?void 0:a.material)!=null&&c.isMaterial&&(r.userData[i]=!0),(m=a==null?void 0:a.geometry)!=null&&m.isBufferGeometry&&(r.userData[f]=!0)),r.events={},r},insert(e,t){var o,a,n,r;if((((o=e==null?void 0:e.__vnode)==null?void 0:o.type)==="TresGroup"||((a=e==null?void 0:e.__vnode)==null?void 0:a.type)==="TresObject3D")&&t===null&&!((r=(n=e==null?void 0:e.__vnode)==null?void 0:n.ctx)!=null&&r.asyncResolved)){le=e;return}t||(t=le),e!=null&&e.isObject3D&&(t!=null&&t.isObject3D)?(t.add(e),e.dispatchEvent({type:"added"})):typeof(e==null?void 0:e.attach)=="string"&&(e.__previousAttach=e[t==null?void 0:t.attach],t&&(t[e.attach]=e))},remove(e){var t,o;if(e){if(e.isObject3D){const a=e,n=r=>{var c,m;const{GEOMETRY_VIA_PROP:f,MATERIAL_VIA_PROP:i}=de;r.userData[i]||(c=r.material)==null||c.dispose(),r.userData[f]||(m=r.geometry)==null||m.dispose()};a.traverse(r=>n(r)),n(a)}(t=e.removeFromParent)==null||t.call(e),(o=e.dispose)==null||o.call(e)}},patchProp(e,t,o,a){if(e){let n=e,r=t,f=z(r),i=n==null?void 0:n[f];if(n.type==="BufferGeometry"){if(r==="args")return;n.setAttribute(z(r),new d.BufferAttribute(...a));return}if(r.includes("-")&&i===void 0){const m=r.split("-");i=m.reduce((p,h)=>p[z(h)],n),r=m.pop(),f=r.toLowerCase(),i!=null&&i.set||(n=m.reduce((p,h)=>p[z(h)],n))}De(r)&&(e.events[r]=a);let c=a;if(c===""&&(c=!0),oe(i)){Array.isArray(c)?e[f](...c):e[f](c);return}!(i!=null&&i.set)&&!oe(i)?n[f]=c:i.constructor===c.constructor&&(i!=null&&i.copy)?i==null||i.copy(c):Array.isArray(c)?i.set(...c):!i.isColor&&i.setScalar?i.setScalar(c):i.set(c)}},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:Be}=s.createRenderer(Ie),Ge=e=>{const t=Be(o);function o(){return e&&e.default?e.default():[]}return t};$(H);const{logWarning:pe}=T(),ze=s.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:o}){e.physicallyCorrectLights===!0&&pe("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const a=s.ref(),n=s.ref(),r=new H.Scene,{setState:f}=L();f("scene",r),f("canvas",n),f("container",a);const i=s.ref(),c=t&&t.default&&t.default();c&&(c==null?void 0:c.length)>0&&(i.value=c.some(C=>xe(C.type)&&C.type.includes("Camera"))||e.camera,i.value||pe("No camera found in the scene, please add one!")),s.onMounted(()=>{w()}),s.onUnmounted(()=>{f("renderer",null)});const{activeCamera:m,pushCamera:p,clearCameras:h}=q();function w(){const{renderer:C}=re(e);e.camera&&p(e.camera);const{onLoop:V}=X(),{raycaster:_,pointer:Q}=ue();let R=null,v=null;s.watchEffect(()=>{m.value&&_.value.setFromCamera(Q.value,m.value)}),V(()=>{var M,S,b,k,I,O,U,W,x,E;if(m.value&&e.disableRender!==!0&&e.disableRender!==""&&((M=C.value)==null||M.render(r,m.value)),_.value){const N=_.value.intersectObjects(r.children);N.length>0?(v=N[0],R===null&&((k=(b=(S=v.object)==null?void 0:S.events)==null?void 0:b.onPointerEnter)==null||k.call(b,v)),(U=(O=(I=v.object)==null?void 0:I.events)==null?void 0:O.onPointerMove)==null||U.call(O,v)):R!==null&&((E=(x=(W=v==null?void 0:v.object)==null?void 0:W.events)==null?void 0:x.onPointerLeave)==null||E.call(x,R),v=null),R=v}}),u.useEventListener(n.value,"click",()=>{var M,S,b;v!==null&&((b=(S=(M=v.object)==null?void 0:M.events)==null?void 0:S.onClick)==null||b.call(S,v))})}let y;function P(){y=Ge(t),y.provide("useTres",L()),y.provide(F,L()),y.provide("extend",$),y.mount(r)}return P(),o({scene:r}),s.watch(()=>e.camera,C=>{C&&(h(),p(C))}),()=>s.h(s.h("div",{ref:a,"data-scene":r.uuid,key:r.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[s.h("div",{style:{width:"100%",height:"100%"}},[s.h("canvas",{ref:n,"data-scene":r.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),ve=s.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:o}){const a=ce();return o(a),()=>s.h(ze,e,t)}}),Fe={install(e){e.component("TresCanvas",ve)}};l.CameraType=ee,l.TRES_CONTEXT_KEY=F,l.TresCanvas=ve,l.catalogue=Y,l.default=Fe,l.extend=$,l.isProd=Re,l.trasverseObjects=se,l.useCamera=q,l.useLoader=Ae,l.useLogger=T,l.useRaycaster=ue,l.useRenderLoop=X,l.useRenderer=re,l.useSeek=ke,l.useTexture=Te,l.useTres=L,l.useTresProvider=ce,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
8
+ (function(d,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],c):(d=typeof globalThis<"u"?globalThis:d||self,c(d.tres={},d.Vue,d.Three,d.VueUseCore))})(this,function(d,c,m,u){"use strict";function Ce(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const a=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,a.get?a:{enumerable:!0,get:()=>e[o]})}}return t.default=e,Object.freeze(t)}const H=Ce(m),$=c.ref({uuid:m.MathUtils.generateUUID()}),q=e=>void Object.assign($.value,e);var ee=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(ee||{});const Me=45;let A;function K(){const{state:e,setState:t,aspectRatio:o}=L();function a(s="Perspective",l){var p,h,b;if(s==="Perspective"){const{near:C,far:P,fov:y}=l||{near:.1,far:1e3,fov:Me};A=new m.PerspectiveCamera(y,((p=e.aspectRatio)==null?void 0:p.value)||window.innerWidth/window.innerHeight,C,P),(h=e.cameras)==null||h.push(A)}else{const{left:C,right:P,top:y,bottom:V,near:_,far:I}=l||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};A=new m.OrthographicCamera(C,P,y,V,_,I),(b=e.cameras)==null||b.push(A)}return e.camera=A,t("camera",e.camera),A}function n(){var s;e.camera instanceof m.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(s=e.camera)==null||s.updateProjectionMatrix()}function r(s){var l;(l=e.cameras)==null||l.push(s),s instanceof m.PerspectiveCamera&&e.aspectRatio&&(s.aspect=e.aspectRatio.value),s.updateProjectionMatrix(),t("camera",s)}function f(s){var l;((l=e.cameras)==null?void 0:l.length)===0&&r(s)}function i(){e.cameras=[]}return c.watchEffect(()=>{o!=null&&o.value&&n()}),{activeCamera:c.toRef(e,"camera"),createCamera:a,updateCamera:n,pushCamera:r,clearCameras:i,setFirstCamera:f}}const te=u.createEventHook(),ae=u.createEventHook(),X=u.createEventHook(),D=new m.Clock;let G=0,z=0;const{pause:Se,resume:Pe,isActive:Le}=u.useRafFn(()=>{te.trigger({delta:G,elapsed:z,clock:D}),ae.trigger({delta:G,elapsed:z,clock:D}),X.trigger({delta:G,elapsed:z,clock:D})},{immediate:!1});X.on(()=>{G=D.getDelta(),z=D.getElapsedTime()});function J(){return{onBeforeLoop:te.on,onLoop:ae.on,onAfterLoop:X.on,pause:Se,resume:Pe,isActive:Le}}function _e(e){return e instanceof m.Color?e:Array.isArray(e)?new m.Color(...e):new m.Color(e)}const Q={realistic:{outputColorSpace:m.SRGBColorSpace,toneMapping:m.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:m.PCFSoftShadowMap}}},ne=(e,t)=>{for(const o of Object.keys(t))t[o]instanceof Object&&Object.assign(t[o],ne(e[o],t[o]));return Object.assign(e||{},t),e},Oe=xe("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 F(e){return e.replace(/-([a-z])/g,(t,o)=>o.toUpperCase())}function xe(e,t){const o=Object.create(null),a=e.split(",");for(let n=0;n<a.length;n++)o[a[n]]=!0;return t?n=>!!o[n.toLowerCase()]:n=>!!o[n]}function re(e){var be,ye;const t=c.shallowRef(),o=c.ref(!1),{alpha:a=!0,antialias:n=!0,depth:r,logarithmicDepthBuffer:f,failIfMajorPerformanceCaveat:i,precision:s,premultipliedAlpha:l,stencil:p,shadows:h=!1,shadowMapType:b=m.PCFShadowMap,useLegacyLights:C=!1,outputColorSpace:P=m.LinearSRGBColorSpace,toneMapping:y=m.NoToneMapping,toneMappingExposure:V=1,context:_=void 0,powerPreference:I="default",preserveDrawingBuffer:R=!1,clearColor:g,windowSize:M=!1,preset:S=void 0}=c.toRefs(e),{state:w,setState:k}=L(),{width:B,height:O}=u.toValue(M)==!0||u.toValue(M)===""||u.toValue(M)==="true"?u.useWindowSize():u.useElementSize(w.container),{logError:W,logWarning:E}=T(),{pixelRatio:x}=u.useDevicePixelRatio(),{pause:N,resume:Y}=J(),Z=c.computed(()=>B.value/O.value);!u.toValue(M)&&((ye=(be=w.container)==null?void 0:be.value)==null?void 0:ye.offsetHeight)===0&&E(`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 he=()=>{t.value&&(t.value.setSize(B.value,O.value),t.value.setPixelRatio(Math.min(x.value,2)))},we=()=>{if(!t.value)return;const j=u.toValue(S);if(j){j in Q||W("Renderer Preset must be one of these: "+Object.keys(Q).join(", ")),ne(t.value,Q[j]);return}t.value.shadowMap.enabled=u.toValue(h),t.value.shadowMap.type=u.toValue(b),t.value.toneMapping=u.toValue(y)||m.NoToneMapping,t.value.toneMappingExposure=u.toValue(V),t.value.outputColorSpace=u.toValue(P)||m.LinearSRGBColorSpace,g!=null&&g.value&&t.value.setClearColor(_e(u.toValue(g))),t.value.useLegacyLights=u.toValue(C)},We=()=>{const j=u.unrefElement(w.canvas);j&&(t.value=new m.WebGLRenderer({canvas:j,alpha:u.toValue(a),antialias:u.toValue(n),context:u.toValue(_),depth:u.toValue(r),failIfMajorPerformanceCaveat:u.toValue(i),logarithmicDepthBuffer:u.toValue(f),powerPreference:u.toValue(I),precision:u.toValue(s),stencil:u.toValue(p),preserveDrawingBuffer:u.toValue(R),premultipliedAlpha:u.toValue(l)}),k("renderer",t.value),k("clock",new m.Clock),k("aspectRatio",Z),we(),he(),Y(),o.value=!0)},Ee=()=>{t.value&&(t.value.dispose(),t.value=void 0,o.value=!1,N())};return c.watch([Z,x],he),c.watch([h,b,P,C,y,V,g],we),c.watch(()=>[w.canvas,w.container],()=>{u.unrefElement(w.canvas)&&u.unrefElement(w.container)&&We()},{immediate:!0,deep:!0}),{renderer:t,isReady:o,dispose:Ee,aspectRatio:Z}}const oe=e=>typeof e=="function",Ae=e=>typeof e=="string",ie=e=>!!e&&e.constructor===Array;function se(e){const t={nodes:{},materials:{}};return e&&e.traverse(o=>{o.name&&(t.nodes[o.name]=o),o.material&&!t.materials[o.material.name]&&(t.materials[o.material.name]=o.material)}),t}async function Te(e,t,o,a,n){const{logError:r}=T(),f=new e;n&&n(f),o&&o(f);const s=(Array.isArray(t)?t:[t]).map(l=>new Promise((p,h)=>{f.load(l,b=>{b.scene&&Object.assign(b,se(b.scene)),p(b)},a,b=>h(r("[useLoader] - Failed to load resource",b)))}));return ie(t)?await Promise.all(s):await s[0]}async function Ve(e){const t=new m.LoadingManager,o=new m.TextureLoader(t),a=n=>new Promise((r,f)=>{o.load(n,i=>r(i),()=>null,()=>{f(new Error("[useTextures] - Failed to load texture"))})});if(ie(e)){const n=await Promise.all(e.map(r=>a(r)));return e.length>1?n:n[0]}else{const{map:n,displacementMap:r,normalMap:f,roughnessMap:i,metalnessMap:s,aoMap:l,alphaMap:p,matcap:h}=e;return{map:n?await a(n):null,displacementMap:r?await a(r):null,normalMap:f?await a(f):null,roughnessMap:i?await a(i):null,metalnessMap:s?await a(s):null,aoMap:l?await a(l):null,alphaMap:p?await a(p):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 Re(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,o=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[o&63|128]+v[o>>8&255]+"-"+v[o>>16&255]+v[o>>24&255]+v[a&255]+v[a>>8&255]+v[a>>16&255]+v[a>>24&255]).toLowerCase()}const U=Symbol();function ce(){const e=c.shallowReactive({uuid:Re(),camera:void 0,cameras:[],scene:void 0,renderer:void 0,aspectRatio:c.computed(()=>window.innerWidth/window.innerHeight)});function t(n){return e[n]}function o(n,r){e[n]=r}const a={state:e,...c.toRefs(e),getState:t,setState:o};return c.provide(U,a),a}const L=()=>c.inject(U,{state:c.shallowReactive({camera:void 0,cameras:[],scene:void 0,renderer:void 0})});function ue(){var f;const e=c.shallowRef(new m.Raycaster),t=c.ref(new m.Vector2),o=c.ref(null),{setState:a,state:n}=L();a("raycaster",e.value),a("pointer",t),a("currentInstance",o);function r(i){t.value.x=i.clientX/window.innerWidth*2-1,t.value.y=-(i.clientY/window.innerHeight)*2+1}return(f=n==null?void 0:n.renderer)==null||f.domElement.addEventListener("pointermove",r),c.onUnmounted(()=>{var i;(i=n==null?void 0:n.renderer)==null||i.domElement.removeEventListener("pointermove",r)}),{raycaster:e,pointer:t}}const ke=!0,fe="[TresJS ▲ ■ ●] ";function T(){function e(a,n){console.error(`${fe} ${a}`,n||"")}function t(a){console.warn(`${fe} ${a}`)}function o(a,n){}return{logError:e,logWarning:t,logMessage:o}}function je(){const{logWarning:e}=T();function t(a,n,r){let f=null;return a.traverse(i=>{i[n]===r&&(f=i)}),f||e(`Child with ${n} '${r}' not found.`),f}function o(a,n){return t(a,"name",n)}return{seek:t,seekByName:o}}const De=/^on[^a-z]/,Ie=e=>De.test(e);function Ye(e){}let le=null;const de={GEOMETRY_VIA_PROP:"tres__geometryViaProp",MATERIAL_VIA_PROP:"tres__materialViaProp"},{logError:me}=T();let pe=!0;const Be={createElement(e,t,o,a){var s,l;if(a||(a={}),a.args||(a.args=[]),e==="template"||Oe(e))return null;let n=e.replace("Tres",""),r;if(e==="primitive"){(a==null?void 0:a.object)===void 0&&me("Tres primitives need a prop 'object'");const p=a.object;n=p.type,r=Object.assign(p,{type:n,attach:a.attach,primitive:!0})}else{const p=$.value[n];p||me(`${n} is not defined on the THREE namespace. Use extend to add it to the catalog.`),r=new p(...a.args)}if(r.isCamera&&pe){a!=null&&a.position||r.position.set(3,3,3),a!=null&&a.lookAt||r.lookAt(0,0,0);const{setFirstCamera:p}=K();p(r),pe=!1}(a==null?void 0:a.attach)===void 0&&(r.isMaterial?r.attach="material":r.isBufferGeometry&&(r.attach="geometry"));const{GEOMETRY_VIA_PROP:f,MATERIAL_VIA_PROP:i}=de;return r.isObject3D&&((s=a==null?void 0:a.material)!=null&&s.isMaterial&&(r.userData[i]=!0),(l=a==null?void 0:a.geometry)!=null&&l.isBufferGeometry&&(r.userData[f]=!0)),r.events={},r},insert(e,t){var o,a,n,r;if((((o=e==null?void 0:e.__vnode)==null?void 0:o.type)==="TresGroup"||((a=e==null?void 0:e.__vnode)==null?void 0:a.type)==="TresObject3D")&&t===null&&!((r=(n=e==null?void 0:e.__vnode)==null?void 0:n.ctx)!=null&&r.asyncResolved)){le=e;return}t||(t=le),e!=null&&e.isObject3D&&(t!=null&&t.isObject3D)?(t.add(e),e.dispatchEvent({type:"added"})):e!=null&&e.isFog?t.fog=e:typeof(e==null?void 0:e.attach)=="string"&&(e.__previousAttach=e[t==null?void 0:t.attach],t&&(t[e.attach]=e))},remove(e){var t,o;if(e){if(e.isObject3D){const a=e,n=r=>{var s,l;const{GEOMETRY_VIA_PROP:f,MATERIAL_VIA_PROP:i}=de;r.userData[i]||(s=r.material)==null||s.dispose(),r.userData[f]||(l=r.geometry)==null||l.dispose()};a.traverse(r=>n(r)),n(a)}(t=e.removeFromParent)==null||t.call(e),(o=e.dispose)==null||o.call(e)}},patchProp(e,t,o,a){if(e){let n=e,r=t,f=F(r),i=n==null?void 0:n[f];if(n.type==="BufferGeometry"){if(r==="args")return;n.setAttribute(F(r),new m.BufferAttribute(...a));return}if(r.includes("-")&&i===void 0){const l=r.split("-");i=l.reduce((p,h)=>p[F(h)],n),r=l.pop(),f=r.toLowerCase(),i!=null&&i.set||(n=l.reduce((p,h)=>p[F(h)],n))}Ie(r)&&(e.events[r]=a);let s=a;if(s===""&&(s=!0),oe(i)){Array.isArray(s)?e[f](...s):e[f](s);return}!(i!=null&&i.set)&&!oe(i)?n[f]=s:i.constructor===s.constructor&&(i!=null&&i.copy)?i==null||i.copy(s):Array.isArray(s)?i.set(...s):!i.isColor&&i.setScalar?i.setScalar(s):i.set(s)}},parentNode(e){return(e==null?void 0:e.parent)||null},createText:()=>void 0,createComment:()=>void 0,setText:()=>void 0,setElementText:()=>void 0,nextSibling:()=>void 0,querySelector:()=>void 0,setScopeId:()=>void 0,cloneNode:()=>void 0,insertStaticContent:()=>void 0},{createApp:Ge}=c.createRenderer(Be),ze=e=>{const t=Ge(o);function o(){return e&&e.default?e.default():[]}return t};q(H);const{logWarning:ge}=T(),Fe=c.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:o}){e.physicallyCorrectLights===!0&&ge("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const a=c.ref(),n=c.ref(),r=new H.Scene,{setState:f}=L();f("scene",r),f("canvas",n),f("container",a);const i=c.ref(),s=t&&t.default&&t.default();s&&(s==null?void 0:s.length)>0&&(i.value=s.some(y=>Ae(y.type)&&y.type.includes("Camera"))||e.camera,i.value||ge("No camera found in the scene, please add one!")),c.onMounted(()=>{b()}),c.onUnmounted(()=>{f("renderer",null)});const{activeCamera:l,pushCamera:p,clearCameras:h}=K();function b(){const{renderer:y}=re(e);e.camera&&p(e.camera);const{onLoop:V}=J(),{raycaster:_,pointer:I}=ue();let R=null,g=null;c.watchEffect(()=>{l.value&&_.value.setFromCamera(I.value,l.value)}),V(()=>{var M,S,w,k,B,O,W,E,x,N;if(l.value&&e.disableRender!==!0&&((M=y.value)==null||M.render(r,l.value)),_.value){const Y=_.value.intersectObjects(r.children);Y.length>0?(g=Y[0],R===null&&((k=(w=(S=g.object)==null?void 0:S.events)==null?void 0:w.onPointerEnter)==null||k.call(w,g)),(W=(O=(B=g.object)==null?void 0:B.events)==null?void 0:O.onPointerMove)==null||W.call(O,g)):R!==null&&((N=(x=(E=g==null?void 0:g.object)==null?void 0:E.events)==null?void 0:x.onPointerLeave)==null||N.call(x,R),g=null),R=g}}),u.useEventListener(n.value,"click",()=>{var M,S,w;g!==null&&((w=(S=(M=g.object)==null?void 0:M.events)==null?void 0:S.onClick)==null||w.call(S,g))})}let C;function P(){C=ze(t),C.provide("useTres",L()),C.provide(U,L()),C.provide("extend",q),C.mount(r)}return P(),o({scene:r}),c.watch(()=>e.camera,y=>{y&&(h(),p(y))}),()=>c.h(c.h("div",{ref:a,"data-scene":r.uuid,key:r.uuid,style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto",touchAction:"none"}},[c.h("div",{style:{width:"100%",height:"100%"}},[c.h("canvas",{ref:n,"data-scene":r.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),ve=c.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputColorSpace","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender","camera"],setup(e,{slots:t,expose:o}){const a=ce();return o(a),()=>c.h(Fe,e,t)}}),Ue={install(e){e.component("TresCanvas",ve)}};d.CameraType=ee,d.TRES_CONTEXT_KEY=U,d.TresCanvas=ve,d.catalogue=$,d.default=Ue,d.extend=q,d.isProd=ke,d.trasverseObjects=se,d.useCamera=K,d.useLoader=Te,d.useLogger=T,d.useRaycaster=ue,d.useRenderLoop=J,d.useRenderer=re,d.useSeek=je,d.useTexture=Ve,d.useTres=L,d.useTresProvider=ce,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -32,6 +32,7 @@ DodecahedronGeometry,
32
32
  EdgesGeometry,
33
33
  ExtrudeBufferGeometry,
34
34
  ExtrudeGeometry,
35
+ Fog,
35
36
  GridHelper,
36
37
  HemisphereLight,
37
38
  HemisphereLightHelper,
@@ -206,6 +207,7 @@ TresDodecahedronGeometry: DefineComponent<Partial<Omit<DodecahedronGeometry, Ove
206
207
  TresEdgesGeometry: DefineComponent<Partial<Omit<EdgesGeometry, OverwrittenProps > & TresModifiedObject>>
207
208
  TresExtrudeBufferGeometry: DefineComponent<Partial<Omit<ExtrudeBufferGeometry, OverwrittenProps > & TresModifiedObject>>
208
209
  TresExtrudeGeometry: DefineComponent<Partial<Omit<ExtrudeGeometry, OverwrittenProps > & TresModifiedObject>>
210
+ TresFog: DefineComponent<Partial<Omit<Fog, OverwrittenProps > & TresModifiedObject>>
209
211
  TresGridHelper: DefineComponent<Partial<Omit<GridHelper, OverwrittenProps > & TresModifiedObject>>
210
212
  TresHemisphereLight: DefineComponent<Partial<Omit<HemisphereLight, OverwrittenProps > & TresModifiedObject>>
211
213
  TresHemisphereLightHelper: DefineComponent<Partial<Omit<HemisphereLightHelper, OverwrittenProps > & TresModifiedObject>>
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-rc.2",
4
+ "version": "2.0.0-rc.4",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@8.3.1",
7
7
  "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
@@ -65,9 +65,9 @@
65
65
  "@huntersofbook/plausible-vue": "^1.0.0",
66
66
  "@release-it/conventional-changelog": "^5.1.1",
67
67
  "@stackblitz/sdk": "^1.9.0",
68
- "@tresjs/cientos": "2.0.0-beta.6",
69
- "@tresjs/core": "2.0.0-rc.1",
70
- "@types/three": "^0.151.0",
68
+ "@tresjs/cientos": "2.0.0-rc.1",
69
+ "@tresjs/core": "2.0.0-rc.2",
70
+ "@types/three": "^0.152.0",
71
71
  "@typescript-eslint/eslint-plugin": "^5.59.2",
72
72
  "@typescript-eslint/parser": "^5.59.2",
73
73
  "@vitejs/plugin-vue": "^4.2.1",