@tresjs/core
Advanced tools
Comparing version 1.8.0 to 1.8.1
412
dist/tres.js
/** | ||
* name: @tresjs/core | ||
* version: v1.8.0 | ||
* version: v1.8.1 | ||
* (c) 2023 | ||
@@ -8,22 +8,22 @@ * description: Declarative ThreeJS using Vue Components | ||
*/ | ||
import { watch as j, toRef as Oe, ref as M, inject as de, defineComponent as Q, onUnmounted as ge, shallowRef as ee, shallowReactive as Ae, computed as he, toRefs as we, provide as b, onBeforeUnmount as Be, h as K } from "vue"; | ||
import { useEventListener as Ie, createEventHook as te, useRafFn as Fe, resolveUnref as h, useWindowSize as _e, useElementSize as Ue, useDevicePixelRatio as je, unrefElement as X } from "@vueuse/core"; | ||
import * as se from "three"; | ||
import { PerspectiveCamera as z, OrthographicCamera as ye, Vector3 as ze, Color as Y, Mesh as De, Fog as We, BufferAttribute as ke, Clock as ve, Scene as Ne, LoadingManager as Ve, TextureLoader as He, Raycaster as Ge, Vector2 as Ke, sRGBEncoding as Xe, ACESFilmicToneMapping as Ye, PCFSoftShadowMap as Je, PCFShadowMap as Ze, LinearEncoding as ce, NoToneMapping as le, WebGLRenderer as qe } from "three"; | ||
var Qe = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Qe || {}); | ||
const et = 45; | ||
let P; | ||
import { inject as Z, watch as j, toRef as $e, ref as L, defineComponent as q, onUnmounted as ge, shallowRef as Q, shallowReactive as Oe, computed as he, toRefs as we, provide as T, onBeforeUnmount as Ae, h as H } from "vue"; | ||
import { useEventListener as Be, createEventHook as ee, useRafFn as Ie, resolveUnref as w, useWindowSize as Fe, useElementSize as _e, useDevicePixelRatio as Ue, unrefElement as G } from "@vueuse/core"; | ||
import * as ce from "three"; | ||
import { PerspectiveCamera as z, OrthographicCamera as ye, Vector3 as je, Color as K, Mesh as ze, Fog as De, BufferAttribute as We, Clock as ve, Scene as ke, LoadingManager as Ne, TextureLoader as Ve, Raycaster as He, Vector2 as Ge, sRGBEncoding as Ke, ACESFilmicToneMapping as Xe, PCFSoftShadowMap as Ye, PCFShadowMap as Je, LinearEncoding as le, NoToneMapping as ue, WebGLRenderer as Ze } from "three"; | ||
var qe = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(qe || {}); | ||
const Qe = 45; | ||
let b; | ||
function Se() { | ||
const { state: e, setState: n } = T(); | ||
function o(u = "Perspective", t) { | ||
var r, l, s; | ||
if (u === "Perspective") { | ||
const { near: i, far: f, fov: g } = t || { | ||
const { state: e, setState: n } = $(), o = Z("aspect-ratio"); | ||
function a(t = "Perspective", r) { | ||
var l, s, i; | ||
if (t === "Perspective") { | ||
const { near: u, far: d, fov: p } = r || { | ||
near: 0.1, | ||
far: 1e3, | ||
fov: et | ||
fov: Qe | ||
}; | ||
P = new z(g, ((r = e.aspectRatio) == null ? void 0 : r.value) || window.innerWidth / window.innerHeight, i, f), (l = e.cameras) == null || l.push(P); | ||
b = new z(p, ((l = e.aspectRatio) == null ? void 0 : l.value) || window.innerWidth / window.innerHeight, u, d), (s = e.cameras) == null || s.push(b); | ||
} else { | ||
const { left: i, right: f, top: g, bottom: v, near: p, far: m } = t || { | ||
const { left: u, right: d, top: p, bottom: m, near: g, far: R } = r || { | ||
left: -100, | ||
@@ -36,32 +36,32 @@ right: 100, | ||
}; | ||
P = new ye(i, f, g, v, p, m), (s = e.cameras) == null || s.push(P); | ||
b = new ye(u, d, p, m, g, R), (i = e.cameras) == null || i.push(b); | ||
} | ||
return e.camera = P, n("camera", e.camera), P; | ||
return e.camera = b, n("camera", e.camera), b; | ||
} | ||
function a() { | ||
var u; | ||
e.camera instanceof z && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (u = e.camera) == null || u.updateProjectionMatrix(); | ||
} | ||
function c(u) { | ||
function c() { | ||
var t; | ||
(t = e.cameras) == null || t.push(u), u instanceof z && e.aspectRatio && (u.aspect = e.aspectRatio.value), u.updateProjectionMatrix(), n("camera", u); | ||
e.camera instanceof z && e.aspectRatio && (e.camera.aspect = e.aspectRatio.value), (t = e.camera) == null || t.updateProjectionMatrix(); | ||
} | ||
function d() { | ||
function f(t) { | ||
var r; | ||
(r = e.cameras) == null || r.push(t), t instanceof z && e.aspectRatio && (t.aspect = e.aspectRatio.value), t.updateProjectionMatrix(), n("camera", t); | ||
} | ||
function h() { | ||
e.cameras = []; | ||
} | ||
return e.aspectRatio && j(e.aspectRatio, a), { | ||
activeCamera: Oe(e, "camera"), | ||
createCamera: o, | ||
updateCamera: a, | ||
pushCamera: c, | ||
clearCameras: d | ||
return o && j(o, c), { | ||
activeCamera: $e(e, "camera"), | ||
createCamera: a, | ||
updateCamera: c, | ||
pushCamera: f, | ||
clearCameras: h | ||
}; | ||
} | ||
const ue = "[TresJS ▲ ■ ●] "; | ||
function I() { | ||
const fe = "[TresJS ▲ ■ ●] "; | ||
function F() { | ||
function e(a, c) { | ||
console.error(`${ue} ${a}`, c || ""); | ||
console.error(`${fe} ${a}`, c || ""); | ||
} | ||
function n(a) { | ||
console.warn(`${ue} ${a}`); | ||
console.warn(`${fe} ${a}`); | ||
} | ||
@@ -76,19 +76,19 @@ function o(a, c) { | ||
} | ||
const D = M({ ...se, uuid: se.MathUtils.generateUUID() }); | ||
const D = L({ ...ce, uuid: ce.MathUtils.generateUUID() }); | ||
delete D.value.Scene; | ||
let O; | ||
function Ce(e, n = "Tres") { | ||
const { logError: o } = I(); | ||
!O && e && (O = e); | ||
const { createComponentInstances: a } = Ee(n); | ||
let A; | ||
function et(e, n = "Tres") { | ||
const { logError: o } = F(); | ||
!A && e && (A = e); | ||
const { createComponentInstances: a } = Ce(n); | ||
return { | ||
extend: (d) => { | ||
if (!d) { | ||
extend: (f) => { | ||
if (!f) { | ||
o("No objects provided to extend catalogue"); | ||
return; | ||
} | ||
D.value = Object.assign(D.value, d); | ||
const u = a(M(d)); | ||
O && u.forEach(([t, r]) => { | ||
O._context.components[t] || O.component(t, r); | ||
D.value = Object.assign(D.value, f); | ||
const h = a(L(f)); | ||
A && h.forEach(([t, r]) => { | ||
A._context.components[t] || A.component(t, r); | ||
}); | ||
@@ -99,47 +99,47 @@ }, | ||
} | ||
const R = (e) => typeof e < "u", tt = (e) => typeof e == "function", N = (e) => !!e && e.constructor === Array; | ||
const M = (e) => typeof e < "u", tt = (e) => typeof e == "function", N = (e) => !!e && e.constructor === Array; | ||
function nt(e) { | ||
return typeof e == "number" ? [e, e, e] : e instanceof ze ? [e.x, e.y, e.z] : e; | ||
return typeof e == "number" ? [e, e, e] : e instanceof je ? [e.x, e.y, e.z] : e; | ||
} | ||
function rt(e) { | ||
return e instanceof Y ? e : Array.isArray(e) ? new Y(...e) : new Y(e); | ||
return e instanceof K ? e : Array.isArray(e) ? new K(...e) : new K(e); | ||
} | ||
const fe = ["rotation", "scale", "position"], ot = ["X", "Y", "Z"], at = ["color"], it = ["r", "g", "b"]; | ||
function Ee(e) { | ||
const pe = ["rotation", "scale", "position"], ot = ["X", "Y", "Z"], at = ["color"], it = ["r", "g", "b"]; | ||
function Ce(e) { | ||
const { | ||
/* logMessage, */ | ||
logError: n | ||
} = I(); | ||
} = F(); | ||
function o(t, r) { | ||
R(t) && R(r) && Object.entries(t).forEach(([l, s]) => { | ||
const i = l.replace(/(-\w)/g, (f) => f[1].toUpperCase()); | ||
r.setAttribute(i, new ke(...s)); | ||
M(t) && M(r) && Object.entries(t).forEach(([l, s]) => { | ||
const i = l.replace(/(-\w)/g, (u) => u[1].toUpperCase()); | ||
r.setAttribute(i, new We(...s)); | ||
}); | ||
} | ||
function a(t, r) { | ||
R(t) && R(r) && Object.entries(t).forEach(([l, s]) => { | ||
const i = l.replace(/(-\w)/g, (m) => m[1].toUpperCase()); | ||
let f, g, v, p; | ||
M(t) && M(r) && Object.entries(t).forEach(([l, s]) => { | ||
const i = l.replace(/(-\w)/g, (g) => g[1].toUpperCase()); | ||
let u, d, p, m; | ||
if (!(i === "args" || s === void 0)) { | ||
fe.includes(i) && s ? s = nt(s) : fe.forEach((m) => { | ||
i.startsWith(m) && i.length === m.length + 1 && (f = m, g = i.substring(m.length), ot.includes(g) || n( | ||
pe.includes(i) && s ? s = nt(s) : pe.forEach((g) => { | ||
i.startsWith(g) && i.length === g.length + 1 && (u = g, d = i.substring(g.length), ot.includes(d) || n( | ||
// eslint-disable-next-line max-len | ||
`There was an error setting ${l} property, ${g} is not a valid axis for ${f}` | ||
`There was an error setting ${l} property, ${d} is not a valid axis for ${u}` | ||
)); | ||
}), at.forEach((m) => { | ||
i.startsWith(m) && i.length === m.length + 1 && (v = m, p = i.substring(m.length).toLowerCase(), it.includes(p) || n(`There was an error setting ${l} property , ${p} is not a valid axis for ${v}`)); | ||
}), at.forEach((g) => { | ||
i.startsWith(g) && i.length === g.length + 1 && (p = g, m = i.substring(g.length).toLowerCase(), it.includes(m) || n(`There was an error setting ${l} property , ${m} is not a valid axis for ${p}`)); | ||
}), t.ref && (t.ref = r); | ||
try { | ||
if (r[i] && R(r[i].set)) | ||
if (r[i] && M(r[i].set)) | ||
r[i].set(...N(s) ? s : [s]); | ||
else if ( | ||
// Check if the property has a "setAxis" method | ||
f && r[f] | ||
u && r[u] | ||
) | ||
R(r[f][`set${g}`]) ? r[f][`set${g}`](s) : R(r[`rotate${g}`]) && r[`rotate${g}`](s); | ||
M(r[u][`set${d}`]) ? r[u][`set${d}`](s) : M(r[`rotate${d}`]) && r[`rotate${d}`](s); | ||
else if ( | ||
// Check if the instance has a "color" property | ||
v && p && r[v] && r[v][p] | ||
p && m && r[p] && r[p][m] | ||
) | ||
r[v][p] = s; | ||
r[p][m] = s; | ||
else { | ||
@@ -154,4 +154,4 @@ if (s === "" && (s = !0), tt(r[i])) { | ||
} | ||
} catch (m) { | ||
n(`There was an error setting ${i} property`, m); | ||
} catch (g) { | ||
n(`There was an error setting ${i} property`, g); | ||
} | ||
@@ -162,21 +162,21 @@ } | ||
function c(t) { | ||
var i, f; | ||
var i, u; | ||
const r = /^Symbol\(Fragment\)$/g, l = /^Symbol\(Text\)$/g, s = /^Symbol\(Comment\)$/g; | ||
if (r.test(t.type.toString())) | ||
return t.children.map((g) => c(g)); | ||
return t.children.map((d) => c(d)); | ||
if (l.test(t.type.toString()) || s.test(t.type.toString())) | ||
return; | ||
{ | ||
const g = t.type.name.replace(e, ""), { catalogue: v } = Ce(), p = de("catalogue") || v; | ||
const d = t.type.name.replace(e, ""), p = Z("catalogue"); | ||
let m; | ||
if (p) | ||
if ((i = t.children) != null && i.default) { | ||
const L = t.children.default().map((S) => c(S)); | ||
m = new p.value[g](...L.flat().filter(Boolean)); | ||
const g = t.children.default().map((R) => c(R)); | ||
m = new p.value[d](...g.flat().filter(Boolean)); | ||
} else | ||
(f = t == null ? void 0 : t.props) != null && f.args ? p != null && p.value[g] ? m = new p.value[g](...t.props.args) : n(`There is no ${g} in the catalogue`, p == null ? void 0 : p.value.uuid) : m = new p.value[g](); | ||
return t != null && t.props && (g === "BufferGeometry" ? o(t.props, m) : a(t.props, m)), m; | ||
(u = t == null ? void 0 : t.props) != null && u.args ? p != null && p.value[d] ? m = new p.value[d](...t.props.args) : n(`There is no ${d} in the catalogue`, p == null ? void 0 : p.value.uuid) : m = new p.value[d](); | ||
return t != null && t.props && (d === "BufferGeometry" ? o(t.props, m) : a(t.props, m)), m; | ||
} | ||
} | ||
function d(t, r, l) { | ||
function f(t, r, l) { | ||
if (l.default && (l != null && l.default())) { | ||
@@ -186,4 +186,4 @@ const s = l.default().map((i) => c(i)); | ||
const i = new t(); | ||
return s.forEach((f) => { | ||
i.add(f); | ||
return s.forEach((u) => { | ||
i.add(u); | ||
}), i; | ||
@@ -195,3 +195,3 @@ } else | ||
} | ||
function u(t) { | ||
function h(t) { | ||
return Object.entries(t.value).filter(([r, l]) => { | ||
@@ -201,24 +201,28 @@ var s, i; | ||
}).map(([r, l]) => { | ||
const s = `${e}${r}`, i = Q({ | ||
const s = `${e}${r}`, i = q({ | ||
name: s, | ||
setup(f, { slots: g, attrs: v, ...p }) { | ||
const { state: m } = T(), { onLoop: L } = re(), S = m.scene, F = m.raycaster, { pushCamera: V } = Se(); | ||
let y = d(l, v, g); | ||
a(v, y), (y instanceof z || y instanceof ye) && V(y), y.isObject3D && (S == null || S.add(y)); | ||
let E = null, C = null; | ||
if (y instanceof De) { | ||
L(() => { | ||
if (y && F && (S != null && S.children)) { | ||
const $ = F.intersectObjects(S == null ? void 0 : S.children); | ||
$.length > 0 ? (C = $[0], (E === null || E.object.uuid !== (C == null ? void 0 : C.object.uuid)) && p.emit("pointer-enter", C), p.emit("pointer-move", C)) : (C = null, E !== null && p.emit("pointer-leave", E)), E = C; | ||
setup(u, { slots: d, attrs: p, ...m }) { | ||
const { state: g } = $(), { onLoop: R } = ne(), v = g.scene, _ = g.raycaster; | ||
let S = f(l, p, d); | ||
if (a(p, S), S instanceof z || S instanceof ye) { | ||
const { pushCamera: O } = Se(); | ||
O(S); | ||
} | ||
S.isObject3D && (v == null || v.add(S)); | ||
let C = null, E = null; | ||
if (S instanceof ze) { | ||
R(() => { | ||
if (S && _ && (v != null && v.children)) { | ||
const x = _.intersectObjects(v == null ? void 0 : v.children); | ||
x.length > 0 ? (E = x[0], (C === null || C.object.uuid !== (E == null ? void 0 : E.object.uuid)) && m.emit("pointer-enter", E), m.emit("pointer-move", E)) : (E = null, C !== null && m.emit("pointer-leave", C)), C = E; | ||
} | ||
}); | ||
const _ = Ie(window, "click", () => { | ||
p.emit("click", E); | ||
const O = Be(window, "click", () => { | ||
m.emit("click", C); | ||
}); | ||
ge(() => { | ||
_(); | ||
O(); | ||
}); | ||
} | ||
return S && y instanceof We && (S.fog = y), p.expose(y), () => { | ||
return v && S instanceof De && (v.fog = S), m.expose(S), () => { | ||
}; | ||
@@ -231,3 +235,3 @@ } | ||
return { | ||
createComponentInstances: u, | ||
createComponentInstances: h, | ||
processProps: a, | ||
@@ -237,18 +241,18 @@ createInstanceFromVNode: c | ||
} | ||
const Re = te(), Me = te(), ne = te(), B = new ve(); | ||
const Ee = ee(), Re = ee(), te = ee(), I = new ve(); | ||
let W = 0, k = 0; | ||
const { pause: st, resume: ct, isActive: lt } = Fe( | ||
const { pause: st, resume: ct, isActive: lt } = Ie( | ||
() => { | ||
Re.trigger({ delta: W, elapsed: k, clock: B }), Me.trigger({ delta: W, elapsed: k, clock: B }), ne.trigger({ delta: W, elapsed: k, clock: B }); | ||
Ee.trigger({ delta: W, elapsed: k, clock: I }), Re.trigger({ delta: W, elapsed: k, clock: I }), te.trigger({ delta: W, elapsed: k, clock: I }); | ||
}, | ||
{ immediate: !1 } | ||
); | ||
ne.on(() => { | ||
W = B.getDelta(), k = B.getElapsedTime(); | ||
te.on(() => { | ||
W = I.getDelta(), k = I.getElapsedTime(); | ||
}); | ||
function re() { | ||
function ne() { | ||
return { | ||
onBeforeLoop: Re.on, | ||
onLoop: Me.on, | ||
onAfterLoop: ne.on, | ||
onBeforeLoop: Ee.on, | ||
onLoop: Re.on, | ||
onAfterLoop: te.on, | ||
pause: st, | ||
@@ -259,3 +263,3 @@ resume: ct, | ||
} | ||
const ut = ee(new Ne()); | ||
const ut = Q(new ke()); | ||
function ft() { | ||
@@ -273,13 +277,13 @@ return { | ||
async function Ct(e, n, o, a, c) { | ||
const { logError: d } = I(), u = new e(); | ||
c && c(u), o && o(u); | ||
const { logError: f } = F(), h = new e(); | ||
c && c(h), o && o(h); | ||
const r = (Array.isArray(n) ? n : [n]).map( | ||
(l) => new Promise((s, i) => { | ||
u.load( | ||
h.load( | ||
l, | ||
(f) => { | ||
f.scene && Object.assign(f, pt(f.scene)), s(f); | ||
(u) => { | ||
u.scene && Object.assign(u, pt(u.scene)), s(u); | ||
}, | ||
a, | ||
(f) => i(d("[useLoader] - Failed to load resource", f)) | ||
(u) => i(f("[useLoader] - Failed to load resource", u)) | ||
); | ||
@@ -291,9 +295,9 @@ }) | ||
async function Et(e) { | ||
const n = new Ve(), o = new He(n), a = (c) => new Promise((d, u) => { | ||
const n = new Ne(), o = new Ve(n), a = (c) => new Promise((f, h) => { | ||
o.load( | ||
c, | ||
(t) => d(t), | ||
(t) => f(t), | ||
() => null, | ||
() => { | ||
u(new Error("[useTextures] - Failed to load texture")); | ||
h(new Error("[useTextures] - Failed to load texture")); | ||
} | ||
@@ -303,10 +307,10 @@ ); | ||
if (N(e)) { | ||
const c = await Promise.all(e.map((d) => a(d))); | ||
const c = await Promise.all(e.map((f) => a(f))); | ||
return e.length > 1 ? c : c[0]; | ||
} else { | ||
const { map: c, displacementMap: d, normalMap: u, roughnessMap: t, metalnessMap: r, aoMap: l } = e; | ||
const { map: c, displacementMap: f, normalMap: h, roughnessMap: t, metalnessMap: r, aoMap: l } = e; | ||
return { | ||
map: c ? await a(c) : null, | ||
displacementMap: d ? await a(d) : null, | ||
normalMap: u ? await a(u) : null, | ||
displacementMap: f ? await a(f) : null, | ||
normalMap: h ? await a(h) : null, | ||
roughnessMap: t ? await a(t) : null, | ||
@@ -318,3 +322,3 @@ metalnessMap: r ? await a(r) : null, | ||
} | ||
const U = Ae({ | ||
const U = Oe({ | ||
camera: void 0, | ||
@@ -324,3 +328,3 @@ cameras: [], | ||
}); | ||
function T() { | ||
function $() { | ||
function e(o) { | ||
@@ -339,8 +343,8 @@ return U[o]; | ||
} | ||
const J = ee(new Ge()), A = M(new Ke()), pe = M(null); | ||
const X = Q(new He()), B = L(new Ge()), me = L(null); | ||
function mt() { | ||
const { setState: e } = T(); | ||
e("raycaster", J.value), e("pointer", A), e("currentInstance", pe), b("raycaster", J), b("pointer", A), b("currentInstance", pe); | ||
const { setState: e } = $(); | ||
e("raycaster", X.value), e("pointer", B), e("currentInstance", me), T("raycaster", X), T("pointer", B), T("currentInstance", me); | ||
function n(o) { | ||
A.value.x = o.clientX / window.innerWidth * 2 - 1, A.value.y = -(o.clientY / window.innerHeight) * 2 + 1; | ||
B.value.x = o.clientX / window.innerWidth * 2 - 1, B.value.y = -(o.clientY / window.innerHeight) * 2 + 1; | ||
} | ||
@@ -350,21 +354,21 @@ return window.addEventListener("pointermove", n), ge(() => { | ||
}), { | ||
raycaster: J, | ||
pointer: A | ||
raycaster: X, | ||
pointer: B | ||
}; | ||
} | ||
const Z = { | ||
const Y = { | ||
realistic: { | ||
outputEncoding: Xe, | ||
toneMapping: Ye, | ||
outputEncoding: Ke, | ||
toneMapping: Xe, | ||
toneMappingExposure: 3, | ||
shadowMap: { | ||
enabled: !0, | ||
type: Je | ||
type: Ye | ||
} | ||
} | ||
}, Le = (e, n) => { | ||
}, Me = (e, n) => { | ||
for (const o of Object.keys(n)) | ||
n[o] instanceof Object && Object.assign(n[o], Le(e[o], n[o])); | ||
n[o] instanceof Object && Object.assign(n[o], Me(e[o], n[o])); | ||
return Object.assign(e || {}, n), e; | ||
}, w = ee(), q = M(!1); | ||
}, y = Q(), J = L(!1); | ||
function dt(e, n, o) { | ||
@@ -374,4 +378,4 @@ const { | ||
antialias: c = !0, | ||
depth: d, | ||
logarithmicDepthBuffer: u, | ||
depth: f, | ||
logarithmicDepthBuffer: h, | ||
failIfMajorPerformanceCaveat: t, | ||
@@ -382,65 +386,61 @@ precision: r, | ||
shadows: i = !1, | ||
shadowMapType: f = Ze, | ||
physicallyCorrectLights: g = !1, | ||
useLegacyLights: v = !1, | ||
outputEncoding: p = ce, | ||
toneMapping: m = le, | ||
toneMappingExposure: L = 1, | ||
context: S = void 0, | ||
powerPreference: F = "default", | ||
preserveDrawingBuffer: V = !1, | ||
clearColor: y, | ||
shadowMapType: u = Je, | ||
physicallyCorrectLights: d = !1, | ||
useLegacyLights: p = !1, | ||
outputEncoding: m = le, | ||
toneMapping: g = ue, | ||
toneMappingExposure: R = 1, | ||
context: v = void 0, | ||
powerPreference: _ = "default", | ||
preserveDrawingBuffer: S = !1, | ||
clearColor: C, | ||
windowSize: E = !1, | ||
preset: C = void 0 | ||
} = we(o), { width: _, height: $ } = h(E) ? _e() : Ue(n), { logError: xe } = I(), { pixelRatio: oe } = je(), { pause: Pe, resume: be } = re(), H = he(() => _.value / $.value), ae = () => { | ||
w.value && (w.value.setSize(_.value, $.value), w.value.setPixelRatio(Math.min(oe.value, 2))); | ||
}, ie = () => { | ||
if (!w.value) | ||
preset: O = void 0 | ||
} = we(o), { setState: x } = $(), { width: re, height: oe } = w(E) ? Fe() : _e(n), { logError: Le } = F(), { pixelRatio: ae } = Ue(), { pause: xe, resume: Pe } = ne(), V = he(() => re.value / oe.value), ie = () => { | ||
y.value && (y.value.setSize(re.value, oe.value), y.value.setPixelRatio(Math.min(ae.value, 2))); | ||
}, se = () => { | ||
if (!y.value) | ||
return; | ||
const x = h(C); | ||
if (x) { | ||
x in Z || xe("Renderer Preset must be one of these: " + Object.keys(Z).join(", ")), Le(w.value, Z[x]); | ||
const P = w(O); | ||
if (P) { | ||
P in Y || Le("Renderer Preset must be one of these: " + Object.keys(Y).join(", ")), Me(y.value, Y[P]); | ||
return; | ||
} | ||
w.value.shadowMap.enabled = h(i), w.value.shadowMap.type = h(f), w.value.toneMapping = h(m) || le, w.value.toneMappingExposure = h(L), w.value.outputEncoding = h(p) || ce, y != null && y.value && w.value.setClearColor(rt(h(y))), w.value.useLegacyLights = h(v); | ||
y.value.shadowMap.enabled = w(i), y.value.shadowMap.type = w(u), y.value.toneMapping = w(g) || ue, y.value.toneMappingExposure = w(R), y.value.outputEncoding = w(m) || le, C != null && C.value && y.value.setClearColor(rt(w(C))), y.value.useLegacyLights = w(p); | ||
}, be = () => { | ||
const P = G(e); | ||
y.value || !P || (y.value = new Ze({ | ||
canvas: P, | ||
alpha: w(a), | ||
antialias: w(c), | ||
context: w(v), | ||
depth: w(f), | ||
failIfMajorPerformanceCaveat: w(t), | ||
logarithmicDepthBuffer: w(h), | ||
powerPreference: w(_), | ||
precision: w(r), | ||
stencil: w(s), | ||
preserveDrawingBuffer: w(S), | ||
premultipliedAlpha: w(l) | ||
}), x("renderer", y.value), x("clock", new ve()), x("aspectRatio", V), se(), ie(), Pe(), J.value = !0); | ||
}, Te = () => { | ||
const x = X(e); | ||
if (w.value || !x) | ||
return; | ||
w.value = new qe({ | ||
canvas: x, | ||
alpha: h(a), | ||
antialias: h(c), | ||
context: h(S), | ||
depth: h(d), | ||
failIfMajorPerformanceCaveat: h(t), | ||
logarithmicDepthBuffer: h(u), | ||
powerPreference: h(F), | ||
precision: h(r), | ||
stencil: h(s), | ||
preserveDrawingBuffer: h(V), | ||
premultipliedAlpha: h(l) | ||
}); | ||
const { setState: G } = T(); | ||
G("renderer", w.value), G("clock", new ve()), G("aspectRatio", H), ie(), ae(), be(), q.value = !0; | ||
}, $e = () => { | ||
w.value && (w.value.dispose(), w.value = void 0, q.value = !1, Pe()); | ||
y.value && (y.value.dispose(), y.value = void 0, J.value = !1, xe()); | ||
}; | ||
return j([H, oe], ae), j( | ||
[i, f, p, v, m, L, y], | ||
ie | ||
return j([V, ae], ie), j( | ||
[i, u, m, p, g, R, C], | ||
se | ||
), j( | ||
() => [e, n], | ||
() => { | ||
X(e) && X(n) && Te(); | ||
G(e) && G(n) && be(); | ||
}, | ||
{ immediate: !0, deep: !0 } | ||
), { | ||
renderer: w, | ||
isReady: q, | ||
dispose: $e, | ||
aspectRatio: H | ||
renderer: y, | ||
isReady: J, | ||
dispose: Te, | ||
aspectRatio: V | ||
}; | ||
} | ||
const { logError: me, logWarning: gt } = I(), ht = Q({ | ||
const { logError: de, logWarning: gt } = F(), ht = q({ | ||
name: "TresCanvas", | ||
@@ -467,9 +467,9 @@ props: { | ||
setup(e, { slots: n, attrs: o }) { | ||
const a = M(), c = M(), { renderer: d, dispose: u, aspectRatio: t } = dt(a, c, e); | ||
return b("aspect-ratio", t), b("renderer", d), n.default && !n.default().some((r) => r.type.name === "Scene") && me("TresCanvas must contain a Scene component."), n.default && !n.default().some((r) => { | ||
const a = L(), c = L(), { renderer: f, dispose: h, aspectRatio: t } = dt(a, c, e); | ||
return T("aspect-ratio", t), T("renderer", f), n.default && !n.default().some((r) => r.type.name === "Scene") && de("TresCanvas must contain a Scene component."), n.default && !n.default().some((r) => { | ||
var l; | ||
return (l = r.type.name) == null ? void 0 : l.includes("Camera"); | ||
}) && me("Scene must contain a Camera component."), Be(() => u()), () => { | ||
}) && de("Scene must contain a Camera component."), Ae(() => h()), () => { | ||
if (n.default) | ||
return K( | ||
return H( | ||
"div", | ||
@@ -489,3 +489,3 @@ { | ||
[ | ||
K( | ||
H( | ||
"div", | ||
@@ -499,3 +499,3 @@ { | ||
[ | ||
K("canvas", { | ||
H("canvas", { | ||
ref: a, | ||
@@ -518,8 +518,8 @@ style: { | ||
} | ||
}), wt = Q({ | ||
}), wt = q({ | ||
name: "Scene", | ||
setup(e, { slots: n }) { | ||
const { setState: o } = T(), { scene: a } = ft(), c = de("renderer"), { activeCamera: d } = Se(), { raycaster: u, pointer: t } = mt(), { onLoop: r } = re(); | ||
return b("local-scene", a), o("scene", a.value), r(() => { | ||
d.value && (u.value.setFromCamera(t.value, d.value), c != null && c.value && d && (a != null && a.value) && c.value.render(a == null ? void 0 : a.value, d.value)); | ||
const { setState: o } = $(), { scene: a } = ft(), c = Z("renderer"), { activeCamera: f } = Se(), { raycaster: h, pointer: t } = mt(), { onLoop: r } = ne(); | ||
return T("local-scene", a), o("scene", a.value), r(() => { | ||
f.value && (h.value.setFromCamera(t.value, f.value), c != null && c.value && f && (a != null && a.value) && c.value.render(a == null ? void 0 : a.value, f.value)); | ||
}), () => { | ||
@@ -534,6 +534,6 @@ if (n.default) | ||
e.component(`${o}Canvas`, ht), e.component(`${o}Scene`, wt); | ||
const { catalogue: a, extend: c } = Ce(e, o); | ||
e.provide("catalogue", a), e.provide("extend", c), e.provide("useTres", T()); | ||
const { createComponentInstances: d } = Ee(o); | ||
d(a).forEach(([t, r]) => { | ||
const { catalogue: a, extend: c } = et(e, o); | ||
e.provide("catalogue", a), e.provide("extend", c), e.provide("useTres", $()); | ||
const { createComponentInstances: f } = Ce(o); | ||
f(a).forEach(([t, r]) => { | ||
e.component(t, r); | ||
@@ -544,3 +544,3 @@ }); | ||
export { | ||
Qe as CameraType, | ||
qe as CameraType, | ||
Rt as UseTresStateSymbol, | ||
@@ -550,11 +550,11 @@ Mt as default, | ||
Se as useCamera, | ||
Ce as useCatalogue, | ||
Ee as useInstanceCreator, | ||
et as useCatalogue, | ||
Ce as useInstanceCreator, | ||
Ct as useLoader, | ||
mt as useRaycaster, | ||
re as useRenderLoop, | ||
ne as useRenderLoop, | ||
dt as useRenderer, | ||
ft as useScene, | ||
Et as useTexture, | ||
T as useTres | ||
$ as useTres | ||
}; |
{ | ||
"name": "@tresjs/core", | ||
"description": "Declarative ThreeJS using Vue Components", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68396