@tresjs/core 2.0.0-beta.1 → 2.0.0-beta.11

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,13 +1,30 @@
1
- # @tresjs/core ▲ ■ ●
1
+ ![repo-banner](/public/repo-banner.png)
2
+
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>
6
+ </p>
7
+
8
+ # TresJS `@tresjs/core`
2
9
 
3
10
  > Declarative ThreeJS using Vue Components
4
11
 
5
12
  - 💡 Build 3D scene as they were Vue components
6
13
  - ⚡️ Powered by Vite
7
- - 🥰 It brings all the updated features of ThreeJS right awayregardless the version
14
+ - 🥰 It brings all the updated features of ThreeJS right away regardless the version
8
15
  - 🦾 Fully Typed
9
16
 
10
- Tres (Spanish word for "three", pronounced `/tres/` ) is a way of creating ThreeJS scenes with Vue components in a declarative fashion. Think of it as a [React-three-fiber](https://docs.pmnd.rs/react-three-fiber) or [Lunchbox](https://github.com/breakfast-studio/lunchboxjs) but without the need of a [custom Vue3 Renderer](https://vuejs.org/api/custom-renderer.html).
17
+ Tres (Spanish word for "three", pronounced `/tres/` ) is a way of creating ThreeJS scenes with Vue components in a declarative fashion.
18
+
19
+ It's build on-top of a [Vue Custom Renderer](https://vuejs.org/api/custom-renderer.html#createrenderer) and it's powered by Vite.
20
+
21
+ The goal is to provide the Vue's community an easy way of building 3D scenes with Vue, always up to date with the latest ThreeJS features and with 0-to-none mantainance.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pnpm install @tresjs/core@beta three
27
+ ```
11
28
 
12
29
  ## Docs
13
30
 
@@ -19,10 +36,10 @@ Checkout the [docs](https://tresjs.org)
19
36
 
20
37
  ## Ecosystem
21
38
 
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) |
39
+ | Package | Version |
40
+ | --------------------------- | :----------------------------------------------------------------------------------------------- |
41
+ | [Tres](packages/tres) | ![tres version](https://img.shields.io/npm/v/@tresjs/core/beta.svg?label=%20&color=%2382DBCA) |
42
+ | [Cientos](packages/cientos) | ![tres version](https://img.shields.io/npm/v/@tresjs/cientos/beta.svg?label=%20&color=%23f19b00) |
26
43
 
27
44
  ## Contribution
28
45
 
@@ -14,6 +14,7 @@ export interface TresCanvasProps {
14
14
  clearColor?: string;
15
15
  windowSize?: boolean;
16
16
  preset?: RendererPresetsType;
17
+ disableRender?: boolean;
17
18
  }
18
19
  /**
19
20
  * Vue component for rendering a Tres component.
@@ -14,6 +14,7 @@ export interface TresSceneProps {
14
14
  clearColor?: string;
15
15
  windowSize?: boolean;
16
16
  preset?: RendererPresetsType;
17
+ disableRender?: boolean;
17
18
  }
18
19
  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
20
  export default TresScene;
@@ -78,7 +78,7 @@ export interface UseRendererOptions extends WebGLRendererParameters {
78
78
  * @default 0x000000
79
79
  */
80
80
  clearColor?: MaybeComputedRef<TresColor>;
81
- windowSize?: MaybeComputedRef<boolean>;
81
+ windowSize?: MaybeComputedRef<boolean | string>;
82
82
  preset?: RendererPresetsType;
83
83
  }
84
84
  /**
@@ -95,6 +95,7 @@ export type UseTresReturn = {
95
95
  setState: (key: string, value: any) => void;
96
96
  aspectRatio: ComputedRef<number>;
97
97
  };
98
+ export declare const TRES_CONTEXT_KEY: unique symbol;
98
99
  /**
99
100
  * The Tres state.
100
101
  *
@@ -1,3 +1,4 @@
1
1
  import { RendererOptions } from 'vue';
2
2
  import { TresObject } from '../types';
3
+ export declare const isOn: (key: string) => boolean;
3
4
  export declare const nodeOps: RendererOptions<TresObject, TresObject>;
package/dist/tres.js CHANGED
@@ -1,31 +1,31 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v2.0.0-beta.1
3
+ * version: v2.0.0-beta.11
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 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 || {
8
+ import { ref as P, watchEffect as fe, toRef as Se, shallowRef as le, toRefs as de, computed as pe, watch as W, shallowReactive as me, provide as Oe, inject as ke, onUnmounted as ve, createRenderer as je, defineComponent as ge, onMounted as De, h as k } from "vue";
9
+ import * as he from "three";
10
+ import { MathUtils as Ie, PerspectiveCamera as H, OrthographicCamera as Be, Clock as we, Color as Y, sRGBEncoding as ze, ACESFilmicToneMapping as Fe, PCFSoftShadowMap as Ge, PCFShadowMap as Ve, LinearEncoding as ae, NoToneMapping as ne, WebGLRenderer as Ue, LoadingManager as We, TextureLoader as He, Raycaster as Ye, Vector2 as $e, BufferAttribute as Ne } from "three";
11
+ import { createEventHook as q, useRafFn as qe, resolveUnref as f, useWindowSize as Ke, useElementSize as Je, useDevicePixelRatio as Xe, unrefElement as $, isFunction as re, useEventListener as Qe } from "@vueuse/core";
12
+ const be = P({ uuid: Ie.generateUUID() }), ye = (e) => void Object.assign(be.value, e);
13
+ var Ze = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Ze || {});
14
+ const et = 45;
15
+ let _;
16
+ function Me() {
17
+ const { state: e, setState: t, aspectRatio: o } = S();
18
+ function a(i = "Perspective", s) {
19
+ var l, u, p;
20
+ if (i === "Perspective") {
21
+ const { near: d, far: w, fov: M } = s || {
22
22
  near: 0.1,
23
23
  far: 1e3,
24
- fov: tt
24
+ fov: et
25
25
  };
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);
26
+ _ = new H(M, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, d, w), (u = e.cameras) == null || u.push(_);
27
27
  } else {
28
- const { left: d, right: w, top: v, bottom: b, near: g, far: P } = c || {
28
+ const { left: d, right: w, top: M, bottom: x, near: L, far: b } = s || {
29
29
  left: -100,
30
30
  right: 100,
31
31
  top: 100,
@@ -33,366 +33,368 @@ function U() {
33
33
  near: 0.1,
34
34
  far: 1e3
35
35
  };
36
- x = new ze(d, w, v, b, g, P), (p = e.cameras) == null || p.push(x);
36
+ _ = new Be(d, w, M, x, L, b), (p = e.cameras) == null || p.push(_);
37
37
  }
38
- return e.camera = x, t("camera", e.camera), x;
38
+ return e.camera = _, t("camera", e.camera), _;
39
39
  }
40
40
  function n() {
41
- var o;
42
- e.camera instanceof O && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (o = e.camera) == null || o.updateProjectionMatrix();
41
+ var i;
42
+ e.camera instanceof H && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (i = e.camera) == null || i.updateProjectionMatrix();
43
43
  }
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);
44
+ function r(i) {
45
+ var s;
46
+ (s = e.cameras) == null || s.push(i), i instanceof H && e.aspectRatio && (i.aspect = e.aspectRatio.value), i.updateProjectionMatrix(), t("camera", i);
47
47
  }
48
- function s() {
48
+ function c() {
49
49
  e.cameras = [];
50
50
  }
51
- return oe(() => {
52
- r != null && r.value && n();
51
+ return fe(() => {
52
+ o != null && o.value && n();
53
53
  }), {
54
- activeCamera: ke(e, "camera"),
54
+ activeCamera: Se(e, "camera"),
55
55
  createCamera: a,
56
56
  updateCamera: n,
57
- pushCamera: i,
58
- clearCameras: s
57
+ pushCamera: r,
58
+ clearCameras: c
59
59
  };
60
60
  }
61
- const me = $(), ve = $(), G = $(), E = new de();
62
- let j = 0, _ = 0;
63
- const { pause: nt, resume: at, isActive: rt } = Ke(
61
+ const xe = q(), Ee = q(), K = q(), j = new we();
62
+ let G = 0, V = 0;
63
+ const { pause: tt, resume: at, isActive: nt } = qe(
64
64
  () => {
65
- me.trigger({ delta: j, elapsed: _, clock: E }), ve.trigger({ delta: j, elapsed: _, clock: E }), G.trigger({ delta: j, elapsed: _, clock: E });
65
+ xe.trigger({ delta: G, elapsed: V, clock: j }), Ee.trigger({ delta: G, elapsed: V, clock: j }), K.trigger({ delta: G, elapsed: V, clock: j });
66
66
  },
67
67
  { immediate: !1 }
68
68
  );
69
- G.on(() => {
70
- j = E.getDelta(), _ = E.getElapsedTime();
69
+ K.on(() => {
70
+ G = j.getDelta(), V = j.getElapsedTime();
71
71
  });
72
- function N() {
72
+ function Ce() {
73
73
  return {
74
- onBeforeLoop: me.on,
75
- onLoop: ve.on,
76
- onAfterLoop: G.on,
77
- pause: nt,
74
+ onBeforeLoop: xe.on,
75
+ onLoop: Ee.on,
76
+ onAfterLoop: K.on,
77
+ pause: tt,
78
78
  resume: at,
79
- isActive: rt
79
+ isActive: nt
80
80
  };
81
81
  }
82
- function ot(e) {
83
- return e instanceof W ? e : Array.isArray(e) ? new W(...e) : new W(e);
82
+ function rt(e) {
83
+ return e instanceof Y ? e : Array.isArray(e) ? new Y(...e) : new Y(e);
84
84
  }
85
- const I = {
85
+ const N = {
86
86
  realistic: {
87
- outputEncoding: We,
87
+ outputEncoding: ze,
88
88
  toneMapping: Fe,
89
89
  toneMappingExposure: 3,
90
90
  shadowMap: {
91
91
  enabled: !0,
92
- type: Ie
92
+ type: Ge
93
93
  }
94
94
  }
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]));
95
+ }, Re = (e, t) => {
96
+ for (const o of Object.keys(t))
97
+ t[o] instanceof Object && Object.assign(t[o], Re(e[o], t[o]));
98
98
  return Object.assign(e || {}, t), e;
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());
99
+ }, 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
+ function F(e) {
101
+ return e.replace(/-([a-z])/g, (t, o) => o.toUpperCase());
102
102
  }
103
- function ct(e, t) {
104
- const r = /* @__PURE__ */ Object.create(null), a = e.split(",");
103
+ function st(e, t) {
104
+ const o = /* @__PURE__ */ Object.create(null), a = e.split(",");
105
105
  for (let n = 0; n < a.length; n++)
106
- r[a[n]] = !0;
107
- return t ? (n) => !!r[n.toLowerCase()] : (n) => !!r[n];
106
+ o[a[n]] = !0;
107
+ return t ? (n) => !!o[n.toLowerCase()] : (n) => !!o[n];
108
108
  }
109
- function ut(e) {
110
- var Q, Z;
111
- const t = ie(), r = M(!1), {
109
+ function ct(e) {
110
+ var ee, te;
111
+ const t = le(), o = P(!1), {
112
112
  alpha: a = !0,
113
113
  antialias: n = !0,
114
- depth: i,
115
- logarithmicDepthBuffer: s,
116
- failIfMajorPerformanceCaveat: o,
117
- precision: c,
118
- premultipliedAlpha: u,
119
- stencil: l,
114
+ depth: r,
115
+ logarithmicDepthBuffer: c,
116
+ failIfMajorPerformanceCaveat: i,
117
+ precision: s,
118
+ premultipliedAlpha: l,
119
+ stencil: u,
120
120
  shadows: p = !1,
121
- shadowMapType: d = He,
121
+ shadowMapType: d = Ve,
122
122
  physicallyCorrectLights: w = !1,
123
- useLegacyLights: v = !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,
130
- clearColor: C,
131
- windowSize: V = !1,
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.
123
+ useLegacyLights: M = !1,
124
+ outputEncoding: x = ae,
125
+ toneMapping: L = ne,
126
+ toneMappingExposure: b = 1,
127
+ context: v = void 0,
128
+ powerPreference: E = "default",
129
+ preserveDrawingBuffer: y = !1,
130
+ clearColor: g,
131
+ windowSize: C = !1,
132
+ preset: I = void 0
133
+ } = de(e), { state: h, setState: T } = S(), { width: O, height: R } = f(C) == !0 || f(C) === "" || f(C) === "true" ? Ke() : Je(h.container), { logError: B, logWarning: z } = D(), { pixelRatio: X } = Xe(), { pause: Le, resume: Te } = Ce(), U = pe(() => O.value / R.value);
134
+ !f(C) && ((te = (ee = h.container) == null ? void 0 : ee.value) == null ? void 0 : te.offsetHeight) === 0 && z(`Oops... Seems like your canvas height is currently 0px, by default it takes the height of it's parent, so make sure it has some height with CSS.
135
135
  You could set windowSize=true to force the canvas to be the size of the window.`);
136
- const X = () => {
137
- t.value && (t.value.setSize(q.value, Y.value), t.value.setPixelRatio(Math.min(K.value, 2)));
138
- }, J = () => {
136
+ const Q = () => {
137
+ t.value && (t.value.setSize(O.value, R.value), t.value.setPixelRatio(Math.min(X.value, 2)));
138
+ }, Z = () => {
139
139
  if (!t.value)
140
140
  return;
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]);
141
+ const A = f(I);
142
+ if (A) {
143
+ A in N || B("Renderer Preset must be one of these: " + Object.keys(N).join(", ")), Re(t.value, N[A]);
144
144
  return;
145
145
  }
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,
146
+ t.value.shadowMap.enabled = f(p), t.value.shadowMap.type = f(d), t.value.toneMapping = f(L) || ne, t.value.toneMappingExposure = f(b), t.value.outputEncoding = f(x) || ae, g != null && g.value && t.value.setClearColor(rt(f(g))), t.value.useLegacyLights = f(M);
147
+ }, Ae = () => {
148
+ const A = $(h.canvas);
149
+ A && (t.value = new Ue({
150
+ canvas: A,
151
151
  alpha: f(a),
152
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());
153
+ context: f(v),
154
+ depth: f(r),
155
+ failIfMajorPerformanceCaveat: f(i),
156
+ logarithmicDepthBuffer: f(c),
157
+ powerPreference: f(E),
158
+ precision: f(s),
159
+ stencil: f(u),
160
+ preserveDrawingBuffer: f(y),
161
+ premultipliedAlpha: f(l)
162
+ }), T("renderer", t.value), T("clock", new we()), T("aspectRatio", U), Z(), Q(), Te(), o.value = !0);
163
+ }, _e = () => {
164
+ t.value && (t.value.dispose(), t.value = void 0, o.value = !1, Le());
165
165
  };
166
- return z([D, K], X), z(
167
- [p, d, b, v, g, P, C],
168
- J
169
- ), z(
166
+ return W([U, X], Q), W(
167
+ [p, d, x, M, L, b, g],
168
+ Z
169
+ ), W(
170
170
  () => [h.canvas, h.container],
171
171
  () => {
172
- F(h.canvas) && F(h.container) && Pe();
172
+ $(h.canvas) && $(h.container) && Ae();
173
173
  },
174
174
  { immediate: !0, deep: !0 }
175
175
  ), {
176
176
  renderer: t,
177
- isReady: r,
178
- dispose: Re,
179
- aspectRatio: D
177
+ isReady: o,
178
+ dispose: _e,
179
+ aspectRatio: U
180
180
  };
181
181
  }
182
- const he = (e) => !!e && e.constructor === Array;
182
+ const ut = (e) => typeof e == "string", Pe = (e) => !!e && e.constructor === Array;
183
183
  function ft(e) {
184
184
  const t = { nodes: {}, materials: {} };
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);
185
+ return e && e.traverse((o) => {
186
+ o.name && (t.nodes[o.name] = o), o.material && !t.materials[o.material.name] && (t.materials[o.material.name] = o.material);
187
187
  }), t;
188
188
  }
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,
189
+ async function Ct(e, t, o, a, n) {
190
+ const { logError: r } = D(), c = new e();
191
+ n && n(c), o && o(c);
192
+ const s = (Array.isArray(t) ? t : [t]).map(
193
+ (l) => new Promise((u, p) => {
194
+ c.load(
195
+ l,
196
196
  (d) => {
197
- d.scene && Object.assign(d, ft(d.scene)), l(d);
197
+ d.scene && Object.assign(d, ft(d.scene)), u(d);
198
198
  },
199
199
  a,
200
- (d) => p(i("[useLoader] - Failed to load resource", d))
200
+ (d) => p(r("[useLoader] - Failed to load resource", d))
201
201
  );
202
202
  })
203
203
  );
204
- return he(t) ? await Promise.all(c) : await c[0];
204
+ return Pe(t) ? await Promise.all(s) : await s[0];
205
205
  }
206
- async function St(e) {
207
- const t = new $e(), r = new Ge(t), a = (n) => new Promise((i, s) => {
208
- r.load(
206
+ async function Rt(e) {
207
+ const t = new We(), o = new He(t), a = (n) => new Promise((r, c) => {
208
+ o.load(
209
209
  n,
210
- (o) => i(o),
210
+ (i) => r(i),
211
211
  () => null,
212
212
  () => {
213
- s(new Error("[useTextures] - Failed to load texture"));
213
+ c(new Error("[useTextures] - Failed to load texture"));
214
214
  }
215
215
  );
216
216
  });
217
- if (he(e)) {
218
- const n = await Promise.all(e.map((i) => a(i)));
217
+ if (Pe(e)) {
218
+ const n = await Promise.all(e.map((r) => a(r)));
219
219
  return e.length > 1 ? n : n[0];
220
220
  } else {
221
221
  const {
222
222
  map: n,
223
- displacementMap: i,
224
- normalMap: s,
225
- roughnessMap: o,
226
- metalnessMap: c,
227
- aoMap: u,
228
- alphaMap: l,
223
+ displacementMap: r,
224
+ normalMap: c,
225
+ roughnessMap: i,
226
+ metalnessMap: s,
227
+ aoMap: l,
228
+ alphaMap: u,
229
229
  matcap: p
230
230
  } = e;
231
231
  return {
232
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,
233
+ displacementMap: r ? await a(r) : null,
234
+ normalMap: c ? await a(c) : null,
235
+ roughnessMap: i ? await a(i) : null,
236
+ metalnessMap: s ? await a(s) : null,
237
+ aoMap: l ? await a(l) : null,
238
+ alphaMap: u ? await a(u) : null,
239
239
  matcap: p ? await a(p) : null
240
240
  };
241
241
  }
242
242
  }
243
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
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();
245
+ const e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, o = 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[o & 63 | 128] + m[o >> 8 & 255] + "-" + m[o >> 16 & 255] + m[o >> 24 & 255] + m[a & 255] + m[a >> 8 & 255] + m[a >> 16 & 255] + m[a >> 24 & 255]).toLowerCase();
247
247
  }
248
- const we = Symbol();
248
+ const J = Symbol();
249
249
  function dt() {
250
- const e = ue({
250
+ const e = me({
251
251
  uuid: lt(),
252
252
  camera: void 0,
253
253
  cameras: [],
254
254
  scene: void 0,
255
255
  renderer: void 0,
256
- aspectRatio: ce(() => window.innerWidth / window.innerHeight)
256
+ aspectRatio: pe(() => window.innerWidth / window.innerHeight)
257
257
  });
258
258
  function t(n) {
259
259
  return e[n];
260
260
  }
261
- function r(n, i) {
262
- e[n] = i;
261
+ function o(n, r) {
262
+ e[n] = r;
263
263
  }
264
264
  const a = {
265
265
  state: e,
266
- ...se(e),
266
+ ...de(e),
267
267
  getState: t,
268
- setState: r
268
+ setState: o
269
269
  };
270
- return Ae(we, a), a;
270
+ return Oe(J, a), a;
271
271
  }
272
- const S = () => Oe(we, {
273
- state: ue({
272
+ const S = () => ke(J, {
273
+ state: me({
274
274
  camera: void 0,
275
275
  cameras: [],
276
276
  scene: void 0,
277
277
  renderer: void 0
278
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;
279
+ });
280
+ function pt() {
281
+ var c;
282
+ const e = le(new Ye()), t = P(new $e()), o = P(null), { setState: a, state: n } = S();
283
+ a("raycaster", e.value), a("pointer", t), a("currentInstance", o);
284
+ function r(i) {
285
+ t.value.x = i.clientX / window.innerWidth * 2 - 1, t.value.y = -(i.clientY / window.innerHeight) * 2 + 1;
285
286
  }
286
- return window.addEventListener("pointermove", t), {
287
- raycaster: ae,
288
- pointer: k
287
+ return (c = n == null ? void 0 : n.renderer) == null || c.domElement.addEventListener("pointermove", r), ve(() => {
288
+ var i;
289
+ (i = n == null ? void 0 : n.renderer) == null || i.domElement.removeEventListener("pointermove", r);
290
+ }), {
291
+ raycaster: e,
292
+ pointer: t
289
293
  };
290
294
  }
291
- const Tt = !0, re = "[TresJS ▲ ■ ●] ";
292
- function T() {
295
+ const Pt = !0, oe = "[TresJS ▲ ■ ●] ";
296
+ function D() {
293
297
  function e(a, n) {
294
- console.error(`${re} ${a}`, n || "");
298
+ console.error(`${oe} ${a}`, n || "");
295
299
  }
296
300
  function t(a) {
297
- console.warn(`${re} ${a}`);
301
+ console.warn(`${oe} ${a}`);
298
302
  }
299
- function r(a, n) {
303
+ function o(a, n) {
300
304
  }
301
305
  return {
302
306
  logError: e,
303
307
  logWarning: t,
304
- logMessage: r
308
+ logMessage: o
305
309
  };
306
310
  }
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;
311
+ function Lt() {
312
+ const { logWarning: e } = D();
313
+ function t(a, n, r) {
314
+ let c = null;
315
+ return a.traverse((i) => {
316
+ i[n] === r && (c = i);
317
+ }), c || e(`Child with ${n} '${r}' not found.`), c;
314
318
  }
315
- function r(a, n) {
319
+ function o(a, n) {
316
320
  return t(a, "name", n);
317
321
  }
318
322
  return {
319
323
  seek: t,
320
- seekByName: r
324
+ seekByName: o
321
325
  };
322
326
  }
323
- const { logWarning: mt } = T();
324
- function vt(e) {
325
- for (const t in e)
326
- if (t.indexOf("on") === 0)
327
- return !0;
328
- return !1;
329
- }
330
- let A = null;
331
- const gt = {
332
- createElement(e, t, r, a) {
333
- if (e === "template" || st(e))
327
+ const mt = /^on[^a-z]/, vt = (e) => mt.test(e);
328
+ let ie = null;
329
+ const se = {
330
+ GEOMETRY_VIA_PROP: "tres__geometryViaProp",
331
+ MATERIAL_VIA_PROP: "tres__materialViaProp"
332
+ }, { logError: ce } = D(), gt = {
333
+ createElement(e, t, o, a) {
334
+ var s, l;
335
+ if (a || (a = {}), a.args || (a.args = []), e === "template" || it(e))
334
336
  return null;
335
- let n;
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(
338
- // eslint-disable-next-line max-len
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 🤗"
340
- );
341
- const { pushCamera: i } = U();
342
- i(n);
337
+ let n = e.replace("Tres", ""), r;
338
+ if (e === "primitive") {
339
+ (a == null ? void 0 : a.object) === void 0 && ce("Tres primitives need a prop 'object'");
340
+ const u = a.object;
341
+ n = u.type, r = Object.assign(u, { type: n, attach: a.attach, primitive: !0 });
342
+ } else {
343
+ const u = be.value[n];
344
+ u || ce(`${n} is not defined on the THREE namespace. Use extend to add it to the catalog.`), r = new u(...a.args);
345
+ }
346
+ if (r.isCamera) {
347
+ a != null && a.position || r.position.set(3, 3, 3), a != null && a.lookAt || r.lookAt(0, 0, 0);
348
+ const { pushCamera: u } = Me();
349
+ u(r);
343
350
  }
344
- return (a == null ? void 0 : a.attach) === void 0 && (n.isMaterial ? n.attach = "material" : n.isBufferGeometry && (n.attach = "geometry")), n;
351
+ (a == null ? void 0 : a.attach) === void 0 && (r.isMaterial ? r.attach = "material" : r.isBufferGeometry && (r.attach = "geometry"));
352
+ const { GEOMETRY_VIA_PROP: c, MATERIAL_VIA_PROP: i } = se;
353
+ 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[c] = !0)), r.events = {}, r;
345
354
  },
346
- insert(e, t, r) {
347
- if (A === null && t.isScene && (A = t), t === null && (t = A), t != null && t.isObject3D && (e != null && e.isObject3D)) {
348
- const s = r ? t.children.indexOf(r) : 0;
349
- e.parent = t, t.children.splice(s, 0, e), e.dispatchEvent({ type: "added" });
350
- } else
351
- typeof (e == null ? void 0 : e.attach) == "string" && (e.__previousAttach = e[t == null ? void 0 : t.attach], t && (t[e.attach] = e));
352
- const { onLoop: a } = N();
353
- let n = null, i = null;
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
- });
355
+ insert(e, t) {
356
+ var o, a, n, r;
357
+ 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)) {
358
+ ie = e;
359
+ return;
366
360
  }
361
+ t || (t = ie), 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
362
  },
368
363
  remove(e) {
369
- if (!e)
370
- return;
371
- const t = e.parentNode;
372
- t && t.removeChild(e);
364
+ var t, o;
365
+ if (e) {
366
+ if (e.isObject3D) {
367
+ const a = e, n = (r) => {
368
+ var s, l;
369
+ const { GEOMETRY_VIA_PROP: c, MATERIAL_VIA_PROP: i } = se;
370
+ r.userData[i] || (s = r.material) == null || s.dispose(), r.userData[c] || (l = r.geometry) == null || l.dispose();
371
+ };
372
+ a.traverse((r) => n(r)), n(a);
373
+ }
374
+ (t = e.removeFromParent) == null || t.call(e), (o = e.dispose) == null || o.call(e);
375
+ }
373
376
  },
374
- patchProp(e, t, r, a) {
377
+ patchProp(e, t, o, a) {
375
378
  if (e) {
376
- let n = e, i = t;
377
- const s = R(i);
378
- let o = n == null ? void 0 : n[s];
379
- if (e.parent || (e.parent = A), n.type === "BufferGeometry") {
379
+ let n = e, r = t, c = F(r), i = n == null ? void 0 : n[c];
380
+ if (n.type === "BufferGeometry") {
380
381
  n.setAttribute(
381
- R(i),
382
- new Ye(...a)
382
+ F(r),
383
+ new Ne(...a)
383
384
  );
384
385
  return;
385
386
  }
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));
387
+ if (r.includes("-") && i === void 0) {
388
+ const l = r.split("-");
389
+ i = l.reduce((u, p) => u[F(p)], n), r = l.pop(), c = r.toLowerCase(), i != null && i.set || (n = l.reduce((u, p) => u[F(p)], n));
389
390
  }
390
- let c = a;
391
- if (c === "" && (c = !0), ne(o)) {
392
- Array.isArray(c) ? e[s](...c) : e[s](c);
391
+ vt(r) && (e.events[r] = a);
392
+ let s = a;
393
+ if (s === "" && (s = !0), re(i)) {
394
+ Array.isArray(s) ? e[c](...s) : e[c](s);
393
395
  return;
394
396
  }
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);
397
+ !(i != null && i.set) && !re(i) ? n[c] = 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);
396
398
  }
397
399
  },
398
400
  parentNode(e) {
@@ -408,14 +410,14 @@ const gt = {
408
410
  cloneNode: () => void 0,
409
411
  insertStaticContent: () => void 0
410
412
  }, { createApp: ht } = je(gt), wt = (e) => {
411
- const t = ht(r);
412
- function r() {
413
+ const t = ht(o);
414
+ function o() {
413
415
  return e && e.default ? e.default() : [];
414
416
  }
415
417
  return t;
416
418
  };
417
- pe(le);
418
- const { logWarning: bt } = T(), yt = fe({
419
+ ye(he);
420
+ const { logWarning: ue } = D(), bt = ge({
419
421
  name: "TresScene",
420
422
  props: [
421
423
  "shadows",
@@ -430,40 +432,48 @@ const { logWarning: bt } = T(), yt = fe({
430
432
  "preserveDrawingBuffer",
431
433
  "clearColor",
432
434
  "windowSize",
433
- "preset"
435
+ "preset",
436
+ "disableRender"
434
437
  ],
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);
438
+ setup(e, { slots: t, expose: o }) {
439
+ e.physicallyCorrectLights === !0 && ue("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");
440
+ const a = P(), n = P(), r = new he.Scene(), { setState: c } = S();
441
+ c("scene", r), c("canvas", n), c("container", a);
442
+ const i = P(), s = t && t.default && t.default();
443
+ (s == null ? void 0 : s.length) > 0 && (i.value = s.some((d) => ut(d.type) && d.type.includes("Camera")), i.value || ue("No camera found in the scene, please add one!")), De(() => {
444
+ l();
445
+ }), ve(() => {
446
+ c("renderer", null);
444
447
  });
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(() => {
450
- var g;
451
- d.value && ((g = p.value) == null || g.render(i, d.value));
448
+ function l() {
449
+ const { renderer: d } = ct(e), { activeCamera: w } = Me(), { onLoop: M } = Ce(), { raycaster: x, pointer: L } = pt();
450
+ let b = null, v = null;
451
+ fe(() => {
452
+ w.value && x.value.setFromCamera(L.value, w.value);
453
+ }), M(() => {
454
+ var E, y, g, C, I, h, T, O, R, B;
455
+ if (w.value && e.disableRender !== !0 && e.disableRender !== "" && ((E = d.value) == null || E.render(r, w.value)), x.value) {
456
+ const z = x.value.intersectObjects(r.children);
457
+ z.length > 0 ? (v = z[0], b === null && ((C = (g = (y = v.object) == null ? void 0 : y.events) == null ? void 0 : g.onPointerEnter) == null || C.call(g, v)), (T = (h = (I = v.object) == null ? void 0 : I.events) == null ? void 0 : h.onPointerMove) == null || T.call(h, v)) : b !== null && ((B = (R = (O = v == null ? void 0 : v.object) == null ? void 0 : O.events) == null ? void 0 : R.onPointerLeave) == null || B.call(R, b), v = null), b = v;
458
+ }
459
+ }), Qe(n.value, "click", () => {
460
+ var E, y, g;
461
+ v !== null && ((g = (y = (E = v.object) == null ? void 0 : E.events) == null ? void 0 : y.onClick) == null || g.call(y, v));
452
462
  });
453
463
  }
454
464
  let u;
455
- function l() {
456
- u = wt(t), u.provide("useTres", S()), u.provide("extend", pe), u.mount(i);
465
+ function p() {
466
+ u = wt(t), u.provide("useTres", S()), u.provide(J, S()), u.provide("extend", ye), u.mount(r);
457
467
  }
458
- return l(), r({
459
- scene: i
460
- }), () => L(
461
- L(
468
+ return p(), o({
469
+ scene: r
470
+ }), () => k(
471
+ k(
462
472
  "div",
463
473
  {
464
474
  ref: a,
465
- "data-scene": i.uuid,
466
- key: i.uuid,
475
+ "data-scene": r.uuid,
476
+ key: r.uuid,
467
477
  style: {
468
478
  position: "relative",
469
479
  width: "100%",
@@ -473,7 +483,7 @@ const { logWarning: bt } = T(), yt = fe({
473
483
  }
474
484
  },
475
485
  [
476
- L(
486
+ k(
477
487
  "div",
478
488
  {
479
489
  style: {
@@ -482,9 +492,9 @@ const { logWarning: bt } = T(), yt = fe({
482
492
  }
483
493
  },
484
494
  [
485
- L("canvas", {
495
+ k("canvas", {
486
496
  ref: n,
487
- "data-scene": i.uuid,
497
+ "data-scene": r.uuid,
488
498
  style: {
489
499
  display: "block",
490
500
  width: "100%",
@@ -500,7 +510,7 @@ const { logWarning: bt } = T(), yt = fe({
500
510
  )
501
511
  );
502
512
  }
503
- }), xt = fe({
513
+ }), yt = ge({
504
514
  name: "TresCanvas",
505
515
  props: [
506
516
  "shadows",
@@ -515,33 +525,35 @@ const { logWarning: bt } = T(), yt = fe({
515
525
  "preserveDrawingBuffer",
516
526
  "clearColor",
517
527
  "windowSize",
518
- "preset"
528
+ "preset",
529
+ "disableRender"
519
530
  ],
520
- setup(e, { slots: t, expose: r }) {
531
+ setup(e, { slots: t, expose: o }) {
521
532
  const a = dt();
522
- return r(a), () => L(yt, e, t);
533
+ return o(a), () => k(bt, e, t);
523
534
  }
524
- }), Rt = {
535
+ }), Tt = {
525
536
  install(e) {
526
- e.component("TresCanvas", xt);
537
+ e.component("TresCanvas", yt);
527
538
  }
528
539
  };
529
540
  export {
530
- et as CameraType,
531
- xt as TresCanvas,
532
- H as catalogue,
533
- Rt as default,
534
- pe as extend,
535
- Tt as isProd,
541
+ Ze as CameraType,
542
+ J as TRES_CONTEXT_KEY,
543
+ yt as TresCanvas,
544
+ be as catalogue,
545
+ Tt as default,
546
+ ye as extend,
547
+ Pt as isProd,
536
548
  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,
549
+ Me as useCamera,
550
+ Ct as useLoader,
551
+ D as useLogger,
552
+ pt as useRaycaster,
553
+ Ce as useRenderLoop,
554
+ ct as useRenderer,
555
+ Lt as useSeek,
556
+ Rt as useTexture,
545
557
  S as useTres,
546
558
  dt as useTresProvider
547
559
  };
package/dist/tres.umd.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * name: @tresjs/core
3
- * version: v2.0.0-beta.1
3
+ * version: v2.0.0-beta.11
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(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"}})});
8
+ (function(d,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):(d=typeof globalThis<"u"?globalThis:d||self,s(d.tres={},d.Vue,d.Three,d.VueUseCore))})(this,function(d,s,m,f){"use strict";function be(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const i in e)if(i!=="default"){const n=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,n.get?n:{enumerable:!0,get:()=>e[i]})}}return t.default=e,Object.freeze(t)}const Q=be(m),N=s.ref({uuid:m.MathUtils.generateUUID()}),Y=e=>void Object.assign(N.value,e);var Z=(e=>(e.Perspective="Perspective",e.Orthographic="Orthographic",e))(Z||{});const we=45;let T;function $(){const{state:e,setState:t,aspectRatio:i}=S();function n(o="Perspective",c){var p,u,h;if(o==="Perspective"){const{near:v,far:M,fov:L}=c||{near:.1,far:1e3,fov:we};T=new m.PerspectiveCamera(L,((p=e.aspectRatio)==null?void 0:p.value)||window.innerWidth/window.innerHeight,v,M),(u=e.cameras)==null||u.push(T)}else{const{left:v,right:M,top:L,bottom:_,near:k,far:C}=c||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};T=new m.OrthographicCamera(v,M,L,_,k,C),(h=e.cameras)==null||h.push(T)}return e.camera=T,t("camera",e.camera),T}function a(){var o;e.camera instanceof m.PerspectiveCamera&&e.aspectRatio&&(e.camera.aspect=e.aspectRatio.value),(o=e.camera)==null||o.updateProjectionMatrix()}function r(o){var c;(c=e.cameras)==null||c.push(o),o instanceof m.PerspectiveCamera&&e.aspectRatio&&(o.aspect=e.aspectRatio.value),o.updateProjectionMatrix(),t("camera",o)}function l(){e.cameras=[]}return s.watchEffect(()=>{i!=null&&i.value&&a()}),{activeCamera:s.toRef(e,"camera"),createCamera:n,updateCamera:a,pushCamera:r,clearCameras:l}}const H=f.createEventHook(),ee=f.createEventHook(),q=f.createEventHook(),D=new m.Clock;let E=0,B=0;const{pause:ye,resume:Me,isActive:Ce}=f.useRafFn(()=>{H.trigger({delta:E,elapsed:B,clock:D}),ee.trigger({delta:E,elapsed:B,clock:D}),q.trigger({delta:E,elapsed:B,clock:D})},{immediate:!1});q.on(()=>{E=D.getDelta(),B=D.getElapsedTime()});function K(){return{onBeforeLoop:H.on,onLoop:ee.on,onAfterLoop:q.on,pause:ye,resume:Me,isActive:Ce}}function Pe(e){return e instanceof m.Color?e:Array.isArray(e)?new m.Color(...e):new m.Color(e)}const X={realistic:{outputEncoding:m.sRGBEncoding,toneMapping:m.ACESFilmicToneMapping,toneMappingExposure:3,shadowMap:{enabled:!0,type:m.PCFSoftShadowMap}}},te=(e,t)=>{for(const i of Object.keys(t))t[i]instanceof Object&&Object.assign(t[i],te(e[i],t[i]));return Object.assign(e||{},t),e},Le=_e("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,i)=>i.toUpperCase())}function _e(e,t){const i=Object.create(null),n=e.split(",");for(let a=0;a<n.length;a++)i[n[a]]=!0;return t?a=>!!i[a.toLowerCase()]:a=>!!i[a]}function ne(e){var ge,he;const t=s.shallowRef(),i=s.ref(!1),{alpha:n=!0,antialias:a=!0,depth:r,logarithmicDepthBuffer:l,failIfMajorPerformanceCaveat:o,precision:c,premultipliedAlpha:p,stencil:u,shadows:h=!1,shadowMapType:v=m.PCFShadowMap,physicallyCorrectLights:M=!1,useLegacyLights:L=!1,outputEncoding:_=m.LinearEncoding,toneMapping:k=m.NoToneMapping,toneMappingExposure:C=1,context:b=void 0,powerPreference:O="default",preserveDrawingBuffer:P=!1,clearColor:w,windowSize:x=!1,preset:G=void 0}=s.toRefs(e),{state:y,setState:R}=S(),{width:I,height:A}=f.resolveUnref(x)==!0||f.resolveUnref(x)===""||f.resolveUnref(x)==="true"?f.useWindowSize():f.useElementSize(y.container),{logError:V,logWarning:W}=U(),{pixelRatio:me}=f.useDevicePixelRatio(),{pause:ze,resume:Fe}=K(),J=s.computed(()=>I.value/A.value);!f.resolveUnref(x)&&((he=(ge=y.container)==null?void 0:ge.value)==null?void 0:he.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 pe=()=>{t.value&&(t.value.setSize(I.value,A.value),t.value.setPixelRatio(Math.min(me.value,2)))},ve=()=>{if(!t.value)return;const j=f.resolveUnref(G);if(j){j in X||V("Renderer Preset must be one of these: "+Object.keys(X).join(", ")),te(t.value,X[j]);return}t.value.shadowMap.enabled=f.resolveUnref(h),t.value.shadowMap.type=f.resolveUnref(v),t.value.toneMapping=f.resolveUnref(k)||m.NoToneMapping,t.value.toneMappingExposure=f.resolveUnref(C),t.value.outputEncoding=f.resolveUnref(_)||m.LinearEncoding,w!=null&&w.value&&t.value.setClearColor(Pe(f.resolveUnref(w))),t.value.useLegacyLights=f.resolveUnref(L)},Ge=()=>{const j=f.unrefElement(y.canvas);j&&(t.value=new m.WebGLRenderer({canvas:j,alpha:f.resolveUnref(n),antialias:f.resolveUnref(a),context:f.resolveUnref(b),depth:f.resolveUnref(r),failIfMajorPerformanceCaveat:f.resolveUnref(o),logarithmicDepthBuffer:f.resolveUnref(l),powerPreference:f.resolveUnref(O),precision:f.resolveUnref(c),stencil:f.resolveUnref(u),preserveDrawingBuffer:f.resolveUnref(P),premultipliedAlpha:f.resolveUnref(p)}),R("renderer",t.value),R("clock",new m.Clock),R("aspectRatio",J),ve(),pe(),Fe(),i.value=!0)},Ve=()=>{t.value&&(t.value.dispose(),t.value=void 0,i.value=!1,ze())};return s.watch([J,me],pe),s.watch([h,v,_,L,k,C,w],ve),s.watch(()=>[y.canvas,y.container],()=>{f.unrefElement(y.canvas)&&f.unrefElement(y.container)&&Ge()},{immediate:!0,deep:!0}),{renderer:t,isReady:i,dispose:Ve,aspectRatio:J}}const Se=e=>typeof e=="string",ae=e=>!!e&&e.constructor===Array;function re(e){const t={nodes:{},materials:{}};return e&&e.traverse(i=>{i.name&&(t.nodes[i.name]=i),i.material&&!t.materials[i.material.name]&&(t.materials[i.material.name]=i.material)}),t}async function Oe(e,t,i,n,a){const{logError:r}=U(),l=new e;a&&a(l),i&&i(l);const c=(Array.isArray(t)?t:[t]).map(p=>new Promise((u,h)=>{l.load(p,v=>{v.scene&&Object.assign(v,re(v.scene)),u(v)},n,v=>h(r("[useLoader] - Failed to load resource",v)))}));return ae(t)?await Promise.all(c):await c[0]}async function xe(e){const t=new m.LoadingManager,i=new m.TextureLoader(t),n=a=>new Promise((r,l)=>{i.load(a,o=>r(o),()=>null,()=>{l(new Error("[useTextures] - Failed to load texture"))})});if(ae(e)){const a=await Promise.all(e.map(r=>n(r)));return e.length>1?a:a[0]}else{const{map:a,displacementMap:r,normalMap:l,roughnessMap:o,metalnessMap:c,aoMap:p,alphaMap:u,matcap:h}=e;return{map:a?await n(a):null,displacementMap:r?await n(r):null,normalMap:l?await n(l):null,roughnessMap:o?await n(o):null,metalnessMap:c?await n(c):null,aoMap:p?await n(p):null,alphaMap:u?await n(u):null,matcap:h?await n(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 Ae(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0,n=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[i&63|128]+g[i>>8&255]+"-"+g[i>>16&255]+g[i>>24&255]+g[n&255]+g[n>>8&255]+g[n>>16&255]+g[n>>24&255]).toLowerCase()}const F=Symbol();function ie(){const e=s.shallowReactive({uuid:Ae(),camera:void 0,cameras:[],scene:void 0,renderer:void 0,aspectRatio:s.computed(()=>window.innerWidth/window.innerHeight)});function t(a){return e[a]}function i(a,r){e[a]=r}const n={state:e,...s.toRefs(e),getState:t,setState:i};return s.provide(F,n),n}const S=()=>s.inject(F,{state:s.shallowReactive({camera:void 0,cameras:[],scene:void 0,renderer:void 0})});function oe(){var l;const e=s.shallowRef(new m.Raycaster),t=s.ref(new m.Vector2),i=s.ref(null),{setState:n,state:a}=S();n("raycaster",e.value),n("pointer",t),n("currentInstance",i);function r(o){t.value.x=o.clientX/window.innerWidth*2-1,t.value.y=-(o.clientY/window.innerHeight)*2+1}return(l=a==null?void 0:a.renderer)==null||l.domElement.addEventListener("pointermove",r),s.onUnmounted(()=>{var o;(o=a==null?void 0:a.renderer)==null||o.domElement.removeEventListener("pointermove",r)}),{raycaster:e,pointer:t}}const Te=!0,se="[TresJS ▲ ■ ●] ";function U(){function e(n,a){console.error(`${se} ${n}`,a||"")}function t(n){console.warn(`${se} ${n}`)}function i(n,a){}return{logError:e,logWarning:t,logMessage:i}}function Ue(){const{logWarning:e}=U();function t(n,a,r){let l=null;return n.traverse(o=>{o[a]===r&&(l=o)}),l||e(`Child with ${a} '${r}' not found.`),l}function i(n,a){return t(n,"name",a)}return{seek:t,seekByName:i}}const ke=/^on[^a-z]/,Re=e=>ke.test(e);function Ne(e){}let ce=null;const fe={GEOMETRY_VIA_PROP:"tres__geometryViaProp",MATERIAL_VIA_PROP:"tres__materialViaProp"},{logError:le}=U(),je={createElement(e,t,i,n){var c,p;if(n||(n={}),n.args||(n.args=[]),e==="template"||Le(e))return null;let a=e.replace("Tres",""),r;if(e==="primitive"){(n==null?void 0:n.object)===void 0&&le("Tres primitives need a prop 'object'");const u=n.object;a=u.type,r=Object.assign(u,{type:a,attach:n.attach,primitive:!0})}else{const u=N.value[a];u||le(`${a} is not defined on the THREE namespace. Use extend to add it to the catalog.`),r=new u(...n.args)}if(r.isCamera){n!=null&&n.position||r.position.set(3,3,3),n!=null&&n.lookAt||r.lookAt(0,0,0);const{pushCamera:u}=$();u(r)}(n==null?void 0:n.attach)===void 0&&(r.isMaterial?r.attach="material":r.isBufferGeometry&&(r.attach="geometry"));const{GEOMETRY_VIA_PROP:l,MATERIAL_VIA_PROP:o}=fe;return r.isObject3D&&((c=n==null?void 0:n.material)!=null&&c.isMaterial&&(r.userData[o]=!0),(p=n==null?void 0:n.geometry)!=null&&p.isBufferGeometry&&(r.userData[l]=!0)),r.events={},r},insert(e,t){var i,n,a,r;if((((i=e==null?void 0:e.__vnode)==null?void 0:i.type)==="TresGroup"||((n=e==null?void 0:e.__vnode)==null?void 0:n.type)==="TresObject3D")&&t===null&&!((r=(a=e==null?void 0:e.__vnode)==null?void 0:a.ctx)!=null&&r.asyncResolved)){ce=e;return}t||(t=ce),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,i;if(e){if(e.isObject3D){const n=e,a=r=>{var c,p;const{GEOMETRY_VIA_PROP:l,MATERIAL_VIA_PROP:o}=fe;r.userData[o]||(c=r.material)==null||c.dispose(),r.userData[l]||(p=r.geometry)==null||p.dispose()};n.traverse(r=>a(r)),a(n)}(t=e.removeFromParent)==null||t.call(e),(i=e.dispose)==null||i.call(e)}},patchProp(e,t,i,n){if(e){let a=e,r=t,l=z(r),o=a==null?void 0:a[l];if(a.type==="BufferGeometry"){a.setAttribute(z(r),new m.BufferAttribute(...n));return}if(r.includes("-")&&o===void 0){const p=r.split("-");o=p.reduce((u,h)=>u[z(h)],a),r=p.pop(),l=r.toLowerCase(),o!=null&&o.set||(a=p.reduce((u,h)=>u[z(h)],a))}Re(r)&&(e.events[r]=n);let c=n;if(c===""&&(c=!0),f.isFunction(o)){Array.isArray(c)?e[l](...c):e[l](c);return}!(o!=null&&o.set)&&!f.isFunction(o)?a[l]=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)}},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:De}=s.createRenderer(je),Ie=e=>{const t=De(i);function i(){return e&&e.default?e.default():[]}return t};Y(Q);const{logWarning:ue}=U(),Ee=s.defineComponent({name:"TresScene",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender"],setup(e,{slots:t,expose:i}){e.physicallyCorrectLights===!0&&ue("physicallyCorrectLights is deprecated, useLegacyLights is now false by default");const n=s.ref(),a=s.ref(),r=new Q.Scene,{setState:l}=S();l("scene",r),l("canvas",a),l("container",n);const o=s.ref(),c=t&&t.default&&t.default();(c==null?void 0:c.length)>0&&(o.value=c.some(v=>Se(v.type)&&v.type.includes("Camera")),o.value||ue("No camera found in the scene, please add one!")),s.onMounted(()=>{p()}),s.onUnmounted(()=>{l("renderer",null)});function p(){const{renderer:v}=ne(e),{activeCamera:M}=$(),{onLoop:L}=K(),{raycaster:_,pointer:k}=oe();let C=null,b=null;s.watchEffect(()=>{M.value&&_.value.setFromCamera(k.value,M.value)}),L(()=>{var O,P,w,x,G,y,R,I,A,V;if(M.value&&e.disableRender!==!0&&e.disableRender!==""&&((O=v.value)==null||O.render(r,M.value)),_.value){const W=_.value.intersectObjects(r.children);W.length>0?(b=W[0],C===null&&((x=(w=(P=b.object)==null?void 0:P.events)==null?void 0:w.onPointerEnter)==null||x.call(w,b)),(R=(y=(G=b.object)==null?void 0:G.events)==null?void 0:y.onPointerMove)==null||R.call(y,b)):C!==null&&((V=(A=(I=b==null?void 0:b.object)==null?void 0:I.events)==null?void 0:A.onPointerLeave)==null||V.call(A,C),b=null),C=b}}),f.useEventListener(a.value,"click",()=>{var O,P,w;b!==null&&((w=(P=(O=b.object)==null?void 0:O.events)==null?void 0:P.onClick)==null||w.call(P,b))})}let u;function h(){u=Ie(t),u.provide("useTres",S()),u.provide(F,S()),u.provide("extend",Y),u.mount(r)}return h(),i({scene:r}),()=>s.h(s.h("div",{ref:n,"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:a,"data-scene":r.uuid,style:{display:"block",width:"100%",height:"100%",position:e.windowSize?"fixed":"absolute",top:0,left:0}})])]))}}),de=s.defineComponent({name:"TresCanvas",props:["shadows","shadowMapType","physicallyCorrectLights","useLegacyLights","outputEncoding","toneMapping","toneMappingExposure","context","powerPreference","preserveDrawingBuffer","clearColor","windowSize","preset","disableRender"],setup(e,{slots:t,expose:i}){const n=ie();return i(n),()=>s.h(Ee,e,t)}}),Be={install(e){e.component("TresCanvas",de)}};d.CameraType=Z,d.TRES_CONTEXT_KEY=F,d.TresCanvas=de,d.catalogue=N,d.default=Be,d.extend=Y,d.isProd=Te,d.trasverseObjects=re,d.useCamera=$,d.useLoader=Oe,d.useLogger=U,d.useRaycaster=oe,d.useRenderLoop=K,d.useRenderer=ne,d.useSeek=Ue,d.useTexture=xe,d.useTres=S,d.useTresProvider=ie,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@tresjs/core",
3
3
  "description": "Declarative ThreeJS using Vue Components",
4
- "version": "2.0.0-beta.1",
4
+ "version": "2.0.0-beta.11",
5
5
  "type": "module",
6
+ "packageManager": "pnpm@8.2.0",
6
7
  "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
7
8
  "files": [
8
9
  "dist"
@@ -56,29 +57,29 @@
56
57
  "vue": "^3.2.47"
57
58
  },
58
59
  "dependencies": {
59
- "-": "^0.0.1",
60
60
  "@alvarosabu/utils": "^2.3.0",
61
61
  "@vueuse/core": "^9.13.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@alvarosabu/prettier-config": "^1.2.0",
64
+ "@tresjs/core": "2.0.0-beta.10",
65
+ "@alvarosabu/prettier-config": "^1.3.0",
65
66
  "@huntersofbook/plausible-vue": "^1.0.0",
66
67
  "@release-it/conventional-changelog": "^5.1.1",
67
- "@stackblitz/sdk": "^1.8.1",
68
- "@tresjs/cientos": "2.0.0-alpha.5",
68
+ "@stackblitz/sdk": "^1.9.0",
69
+ "@tresjs/cientos": "2.0.0-beta.3",
69
70
  "@types/three": "latest",
70
- "@typescript-eslint/eslint-plugin": "^5.57.1",
71
- "@typescript-eslint/parser": "^5.57.1",
71
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
72
+ "@typescript-eslint/parser": "^5.58.0",
72
73
  "@vitejs/plugin-vue": "^4.1.0",
73
- "@vitest/coverage-c8": "^0.29.8",
74
+ "@vitest/coverage-c8": "^0.30.1",
74
75
  "@vitest/ui": "^0.29.2",
75
76
  "@vue/test-utils": "^2.3.2",
76
- "eslint": "^8.37.0",
77
- "eslint-config-prettier": "^8.5.0",
78
- "eslint-plugin-vue": "^9.10.0",
79
- "gsap": "^3.11.4",
80
- "happy-dom": "^8.7.1",
81
- "jsdom": "^21.1.0",
77
+ "eslint": "^8.38.0",
78
+ "eslint-config-prettier": "^8.8.0",
79
+ "eslint-plugin-vue": "^9.11.0",
80
+ "gsap": "^3.11.5",
81
+ "happy-dom": "^9.6.1",
82
+ "jsdom": "^21.1.1",
82
83
  "kolorist": "^1.7.0",
83
84
  "pathe": "^1.1.0",
84
85
  "prettier": "^2.8.7",
@@ -86,18 +87,18 @@
86
87
  "rollup-plugin-analyzer": "^4.0.0",
87
88
  "rollup-plugin-copy": "^3.4.0",
88
89
  "rollup-plugin-visualizer": "^5.9.0",
89
- "three": "latest",
90
- "unocss": "^0.50.6",
90
+ "three": "^0.150.1",
91
+ "unocss": "^0.51.4",
91
92
  "unplugin": "^1.3.1",
92
93
  "unplugin-vue-components": "^0.24.1",
93
94
  "vite": "^4.2.1",
94
95
  "vite-plugin-banner": "^0.7.0",
95
96
  "vite-plugin-dts": "2.2.0",
96
- "vite-plugin-inspect": "^0.7.18",
97
+ "vite-plugin-inspect": "^0.7.22",
97
98
  "vite-plugin-require-transform": "^1.0.12",
98
99
  "vite-svg-loader": "^4.0.0",
99
100
  "vitepress": "1.0.0-alpha.65",
100
- "vitest": "^0.29.8",
101
- "vue-demi": "^0.13.11"
101
+ "vitest": "^0.30.1",
102
+ "vue-demi": "^0.14.0"
102
103
  }
103
104
  }