@tresjs/core
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,3 +6,3 @@ import { Ref } from 'vue'; | ||
processProps: (props: Record<string, any>, instance: TresInstance) => void; | ||
createInstanceFromVNode: (vnode: TresVNode, catalogue: Ref<TresCatalogue>) => TresInstance; | ||
createInstanceFromVNode: (vnode: TresVNode) => TresInstance | TresInstance[] | undefined; | ||
}; |
@@ -11,1 +11,2 @@ /// <reference types="vite/client" /> | ||
declare module '*.glsl' {} | ||
declare module '*.json' {} |
472
dist/tres.js
/** | ||
* name: @tresjs/core | ||
* version: v1.1.0 | ||
* version: v1.2.0 | ||
* (c) 2022 | ||
@@ -8,23 +8,23 @@ * description: Declarative ThreeJS using Vue Components | ||
*/ | ||
import { computed as D, watch as x, inject as X, ref as S, defineComponent as _, shallowRef as V, reactive as he, toRefs as we, provide as P, onBeforeUnmount as ve, h as J, watchEffect as Ce } from "vue"; | ||
import { useWindowSize as Y, createEventHook as j, useRafFn as ye, useElementSize as Me, useDevicePixelRatio as Se, unrefElement as I, resolveUnref as C } from "@vueuse/core"; | ||
import * as Ee from "three"; | ||
import { PerspectiveCamera as T, OrthographicCamera as Z, Color as $, Vector3 as xe, Clock as Pe, Scene as Te, LoadingManager as Le, TextureLoader as Re, PCFShadowMap as Oe, LinearEncoding as Ae, NoToneMapping as Be, WebGLRenderer as Ie } from "three"; | ||
var $e = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))($e || {}); | ||
import { computed as j, watch as O, inject as T, ref as P, defineComponent as k, shallowRef as N, reactive as ve, toRefs as ye, provide as b, onBeforeUnmount as Ce, h as q } from "vue"; | ||
import { useWindowSize as ee, createEventHook as W, useRafFn as Se, useElementSize as Me, useDevicePixelRatio as xe, unrefElement as z, resolveUnref as y } from "@vueuse/core"; | ||
import * as Q from "three"; | ||
import { PerspectiveCamera as A, OrthographicCamera as te, Color as D, Vector3 as Ee, Clock as Te, Scene as Pe, LoadingManager as Re, TextureLoader as Le, PCFShadowMap as Oe, LinearEncoding as be, NoToneMapping as Ae, WebGLRenderer as $e } from "three"; | ||
var Be = /* @__PURE__ */ ((e) => (e.Perspective = "Perspective", e.Orthographic = "Orthographic", e))(Be || {}); | ||
const M = { | ||
cameras: [] | ||
}, be = 45; | ||
let y; | ||
function ee() { | ||
const { width: e, height: t } = Y(), { setState: r } = ce(); | ||
function a(o = "Perspective", u) { | ||
if (o === "Perspective") { | ||
const { near: n, far: i, fov: p } = u || { | ||
}, Ie = 45; | ||
let C; | ||
function ne() { | ||
const { width: e, height: t } = ee(), { setState: n } = le(); | ||
function o(r = "Perspective", u) { | ||
if (r === "Perspective") { | ||
const { near: s, far: c, fov: p } = u || { | ||
near: 0.1, | ||
far: 1e3, | ||
fov: be | ||
fov: Ie | ||
}; | ||
y = new T(p, s.value, n, i), M.cameras.push(y); | ||
C = new A(p, i.value, s, c), M.cameras.push(C); | ||
} else { | ||
const { left: n, right: i, top: p, bottom: h, near: g, far: w } = u || { | ||
const { left: s, right: c, top: p, bottom: m, near: g, far: v } = u || { | ||
left: -100, | ||
@@ -37,52 +37,30 @@ right: 100, | ||
}; | ||
y = new Z(n, i, p, h, g, w), M.cameras.push(y); | ||
C = new te(s, c, p, m, g, v), M.cameras.push(C); | ||
} | ||
return M.cameras.push(y), y; | ||
return M.cameras.push(C), C; | ||
} | ||
const s = D(() => e.value / t.value), l = D(() => M.cameras[0]); | ||
const i = j(() => e.value / t.value), l = j(() => M.cameras[0]); | ||
function f() { | ||
l.value instanceof T && (l.value.aspect = s.value), l.value.updateProjectionMatrix(); | ||
l.value instanceof A && (l.value.aspect = i.value), l.value.updateProjectionMatrix(); | ||
} | ||
function c(o) { | ||
const u = X("camera"); | ||
o && u && (u.value = o, r("camera", u.value)), M.cameras.push(o), o instanceof T && (o.aspect = s.value), o.updateProjectionMatrix(); | ||
function a(r) { | ||
const u = T("camera"); | ||
r && u && (u.value = r, n("camera", u.value)), M.cameras.push(r), r instanceof A && (r.aspect = i.value), r.updateProjectionMatrix(); | ||
} | ||
return x(s, f), { | ||
return O(i, f), { | ||
activeCamera: l, | ||
createCamera: a, | ||
createCamera: o, | ||
updateCamera: f, | ||
pushCamera: c | ||
pushCamera: a | ||
}; | ||
} | ||
const L = S({ ...Ee }); | ||
delete L.value.Scene; | ||
let b; | ||
function Fe(e, t = "Tres") { | ||
!b && e && (b = e); | ||
const { createComponentInstances: r } = te(t); | ||
return { | ||
extend: (s) => { | ||
L.value = Object.assign(L.value, s), r(S(s)).forEach(([f, c]) => { | ||
b.component(f, c); | ||
}); | ||
}, | ||
catalogue: L | ||
}; | ||
} | ||
const F = (e) => typeof e < "u", ze = (e) => typeof e == "function", R = (e) => !!e && e.constructor === Array; | ||
function De(e) { | ||
return typeof e == "number" ? [e, e, e] : e instanceof xe ? [e.x, e.y, e.z] : e; | ||
} | ||
function K(e) { | ||
return e instanceof $ ? e : Array.isArray(e) ? new $(...e) : new $(e); | ||
} | ||
const q = "[TresJS \u25B2 \u25A0 \u25CF] "; | ||
function U() { | ||
function e(a, s) { | ||
console.error(`${q} ${a}`, s || ""); | ||
const X = "[TresJS \u25B2 \u25A0 \u25CF] "; | ||
function B() { | ||
function e(o, i) { | ||
console.error(`${X} ${o}`, i || ""); | ||
} | ||
function t(a) { | ||
console.warn(`${q} ${a}`); | ||
function t(o) { | ||
console.warn(`${X} ${o}`); | ||
} | ||
function r(a, s) { | ||
function n(o, i) { | ||
} | ||
@@ -92,25 +70,54 @@ return { | ||
logWarning: t, | ||
logMessage: r | ||
logMessage: n | ||
}; | ||
} | ||
const _e = ["rotation", "scale", "position"]; | ||
function te(e) { | ||
const { logMessage: t, logError: r } = U(); | ||
function a(c, o) { | ||
!F(c) || !F(o) || Object.entries(c).forEach(([u, n]) => { | ||
const i = u.replace(/(-\w)/g, (p) => p[1].toUpperCase()); | ||
if (!(i === "args" || n === void 0)) { | ||
_e.includes(i) && n && (n = De(n)), c.ref && (c.ref = o); | ||
const E = P({ ...Q, uuid: Q.MathUtils.generateUUID() }); | ||
delete E.value.Scene; | ||
let x; | ||
function re(e, t = "Tres") { | ||
const { logMessage: n, logError: o } = B(); | ||
!x && e && (x = e); | ||
const { createComponentInstances: i } = ae(t); | ||
return { | ||
extend: (f) => { | ||
if (!f) { | ||
o("No objects provided to extend catalogue"); | ||
return; | ||
} | ||
E.value = Object.assign(E.value, f); | ||
const a = i(P(f)); | ||
n("Adding objects to catalogue", { objects: f, catalogue: E.value.uuid }), x && a.forEach(([r, u]) => { | ||
x._context.components[r] || x.component(r, u); | ||
}); | ||
}, | ||
catalogue: E | ||
}; | ||
} | ||
const U = (e) => typeof e < "u", _e = (e) => typeof e == "function", $ = (e) => !!e && e.constructor === Array; | ||
function Fe(e) { | ||
return typeof e == "number" ? [e, e, e] : e instanceof Ee ? [e.x, e.y, e.z] : e; | ||
} | ||
function Y(e) { | ||
return e instanceof D ? e : Array.isArray(e) ? new D(...e) : new D(e); | ||
} | ||
const ze = ["rotation", "scale", "position"]; | ||
function ae(e) { | ||
const { logMessage: t, logError: n } = B(); | ||
function o(a, r) { | ||
!U(a) || !U(r) || Object.entries(a).forEach(([u, s]) => { | ||
const c = u.replace(/(-\w)/g, (p) => p[1].toUpperCase()); | ||
if (!(c === "args" || s === void 0)) { | ||
ze.includes(c) && s && (s = Fe(s)), a.ref && (a.ref = r); | ||
try { | ||
if (o[i] && F(o[i].set)) | ||
o[i].set(...R(n) ? n : [n]); | ||
if (r[c] && U(r[c].set)) | ||
r[c].set(...$(s) ? s : [s]); | ||
else { | ||
if (n === "" && (n = !0), ze(o[i])) { | ||
o[i](...R(n) ? n : [n]); | ||
if (s === "" && (s = !0), _e(r[c])) { | ||
r[c](...$(s) ? s : [s]); | ||
return; | ||
} | ||
o[i] = n; | ||
r[c] = s; | ||
} | ||
} catch (p) { | ||
r(`There was an error setting ${i} property`, p); | ||
n(`There was an error setting ${c} property`, p); | ||
} | ||
@@ -120,30 +127,40 @@ } | ||
} | ||
function s(c, o) { | ||
var i; | ||
const u = c.type.name.replace(e, ""); | ||
let n; | ||
return (i = c == null ? void 0 : c.props) != null && i.args ? n = new o.value[u](...c.props.args) : n = new o.value[u](), c != null && c.props && a(c.props, n), n; | ||
function i(a) { | ||
var s; | ||
const r = /^Symbol\(Fragment\)$/g, u = /^Symbol\(Text\)$/g; | ||
if (r.test(a.type.toString())) | ||
return a.children.map((c) => i(c)); | ||
if (u.test(a.type.toString())) | ||
return; | ||
{ | ||
const c = a.type.name.replace(e, ""), { catalogue: p } = re(), m = T("catalogue") || p; | ||
let g; | ||
return m && ((s = a == null ? void 0 : a.props) != null && s.args ? m != null && m.value[c] ? g = new m.value[c](...a.props.args) : n(`There is no ${c} in the catalogue`, m == null ? void 0 : m.value.uuid) : g = new m.value[c]()), a != null && a.props && o(a.props, g), g; | ||
} | ||
} | ||
function l(c, o, u, n) { | ||
if (n.default && (n == null ? void 0 : n.default())) { | ||
const i = n.default().map((p) => s(p, c)); | ||
return new o(...i); | ||
function l(a, r, u) { | ||
if (u.default && (u == null ? void 0 : u.default())) { | ||
const s = u.default().map((c) => i(c)); | ||
return new a(...s.flat().filter(Boolean)); | ||
} else | ||
return u.args ? new o(...u.args) : new o(); | ||
return r.args ? new a(...r.args) : new a(); | ||
} | ||
function f(c) { | ||
return Object.entries(c.value).filter(([o, u]) => { | ||
var n, i; | ||
return (i = (n = u == null ? void 0 : u.prototype) == null ? void 0 : n.constructor) == null ? void 0 : i.toString().includes("class"); | ||
}).map(([o, u]) => { | ||
const n = `${e}${o}`, i = _({ | ||
name: n, | ||
setup(p, { slots: h, attrs: g, ...w }) { | ||
const { scene: v } = se(), { pushCamera: O } = ee(), d = l(c, u, g, h); | ||
return a(g, d), (d instanceof T || d instanceof Z) && O(d), d.isObject3D && (v == null || v.value.add(d)), w.expose(d), t(n, { | ||
function f(a) { | ||
return Object.entries(a.value).filter(([r, u]) => { | ||
var s, c; | ||
return (c = (s = u == null ? void 0 : u.prototype) == null ? void 0 : s.constructor) == null ? void 0 : c.toString().includes("class"); | ||
}).map(([r, u]) => { | ||
const s = `${e}${r}`, c = k({ | ||
name: s, | ||
setup(p, { slots: m, attrs: g, ...v }) { | ||
const { scene: R } = ue(), w = T("local-scene") || R, S = T("catalogue"), { pushCamera: I } = ne(); | ||
let h = l(u, g, m); | ||
return o(g, h), (h instanceof A || h instanceof te) && I(h), h.isObject3D && (w == null || w.value.add(h)), v.expose(h), t(s, { | ||
sceneuuid: w == null ? void 0 : w.value.uuid, | ||
catalogue: S == null ? void 0 : S.value.uuid, | ||
props: p, | ||
slots: h, | ||
slots: m.default ? m.default() : void 0, | ||
attrs: g, | ||
ctx: w, | ||
scene: v | ||
ctx: v, | ||
scene: w | ||
}), () => { | ||
@@ -153,3 +170,3 @@ }; | ||
}); | ||
return [n, i]; | ||
return [s, c]; | ||
}); | ||
@@ -159,57 +176,57 @@ } | ||
createComponentInstances: f, | ||
processProps: a, | ||
createInstanceFromVNode: s | ||
processProps: o, | ||
createInstanceFromVNode: i | ||
}; | ||
} | ||
const ne = j(), re = j(), oe = j(), Q = new Pe(), { pause: Ve, resume: je, isActive: Ue } = ye( | ||
const oe = W(), se = W(), ie = W(), Z = new Te(), { pause: De, resume: Ue, isActive: Ve } = Se( | ||
() => { | ||
const e = Q.getElapsedTime(), t = Q.getDelta(); | ||
ne.trigger({ delta: t, elapsed: e }), re.trigger({ delta: t, elapsed: e }), oe.trigger({ delta: t, elapsed: e }); | ||
const e = Z.getElapsedTime(), t = Z.getDelta(); | ||
oe.trigger({ delta: t, elapsed: e }), se.trigger({ delta: t, elapsed: e }), ie.trigger({ delta: t, elapsed: e }); | ||
}, | ||
{ immediate: !1 } | ||
); | ||
function ae() { | ||
function ce() { | ||
return { | ||
onBeforeLoop: ne.on, | ||
onLoop: re.on, | ||
onAfterLoop: oe.on, | ||
pause: Ve, | ||
resume: je, | ||
isActive: Ue | ||
onBeforeLoop: oe.on, | ||
onLoop: se.on, | ||
onAfterLoop: ie.on, | ||
pause: De, | ||
resume: Ue, | ||
isActive: Ve | ||
}; | ||
} | ||
const ke = V(new Te()); | ||
function se() { | ||
const je = N(new Pe()); | ||
function ue() { | ||
return { | ||
scene: ke | ||
scene: je | ||
}; | ||
} | ||
function Ne(e) { | ||
function ke(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); | ||
return e && e.traverse((n) => { | ||
n.name && (t.nodes[n.name] = n), n.material && !t.materials[n.material.name] && (t.materials[n.material.name] = n.material); | ||
}), t; | ||
} | ||
async function Qe(e, t, r, a, s) { | ||
const { logError: l } = U(), f = new e(); | ||
s && s(f), r && r(e); | ||
const o = (Array.isArray(t) ? t : [t]).map( | ||
(u) => new Promise((n, i) => { | ||
async function Qe(e, t, n, o, i) { | ||
const { logError: l } = B(), f = new e(); | ||
i && i(f), n && n(e); | ||
const r = (Array.isArray(t) ? t : [t]).map( | ||
(u) => new Promise((s, c) => { | ||
f.load( | ||
u, | ||
(p) => { | ||
p.scene && Object.assign(p, Ne(p.scene)), n(p); | ||
p.scene && Object.assign(p, ke(p.scene)), s(p); | ||
}, | ||
a, | ||
(p) => i(l("[useLoader] - Failed to load resource", p)) | ||
o, | ||
(p) => c(l("[useLoader] - Failed to load resource", p)) | ||
); | ||
}) | ||
); | ||
return R(t) ? await Promise.all(o) : await o[0]; | ||
return $(t) ? await Promise.all(r) : await r[0]; | ||
} | ||
async function Xe(e) { | ||
const t = new Le(), r = new Re(t), a = (s) => new Promise((l, f) => { | ||
r.load( | ||
s, | ||
(c) => l(c), | ||
const t = new Re(), n = new Le(t), o = (i) => new Promise((l, f) => { | ||
n.load( | ||
i, | ||
(a) => l(a), | ||
() => null, | ||
@@ -221,28 +238,28 @@ () => { | ||
}); | ||
if (R(e)) { | ||
const s = await Promise.all(e.map((l) => a(l))); | ||
return e.length > 1 ? s : s[0]; | ||
if ($(e)) { | ||
const i = await Promise.all(e.map((l) => o(l))); | ||
return e.length > 1 ? i : i[0]; | ||
} else { | ||
const { map: s, displacementMap: l, normalMap: f, roughnessMap: c, metalnessMap: o, aoMap: u } = e; | ||
const { map: i, displacementMap: l, normalMap: f, roughnessMap: a, metalnessMap: r, aoMap: u } = e; | ||
return { | ||
map: s ? await a(s) : null, | ||
displacementMap: l ? await a(l) : null, | ||
normalMap: f ? await a(f) : null, | ||
roughnessMap: c ? await a(c) : null, | ||
metalnessMap: o ? await a(o) : null, | ||
aoMap: u ? await a(u) : null | ||
map: i ? await o(i) : null, | ||
displacementMap: l ? await o(l) : null, | ||
normalMap: f ? await o(f) : null, | ||
roughnessMap: a ? await o(a) : null, | ||
metalnessMap: r ? await o(r) : null, | ||
aoMap: u ? await o(u) : null | ||
}; | ||
} | ||
} | ||
const E = he({}); | ||
function ce() { | ||
function e(r) { | ||
return E[r]; | ||
const L = ve({}); | ||
function le() { | ||
function e(n) { | ||
return L[n]; | ||
} | ||
function t(r, a) { | ||
E[r] = a; | ||
function t(n, o) { | ||
L[n] = o; | ||
} | ||
return { | ||
state: E, | ||
...we(E), | ||
state: L, | ||
...ye(L), | ||
getState: e, | ||
@@ -252,76 +269,76 @@ setState: t | ||
} | ||
const m = V(), z = S(!1); | ||
function We(e, t, r) { | ||
const d = N(), V = P(!1); | ||
function Ne(e, t, n) { | ||
const { | ||
alpha: a = !1, | ||
antialias: s, | ||
alpha: o = !1, | ||
antialias: i, | ||
depth: l, | ||
logarithmicDepthBuffer: f, | ||
failIfMajorPerformanceCaveat: c, | ||
precision: o, | ||
failIfMajorPerformanceCaveat: a, | ||
precision: r, | ||
premultipliedAlpha: u, | ||
stencil: n, | ||
shadows: i = !1, | ||
stencil: s, | ||
shadows: c = !1, | ||
shadowMapType: p = Oe, | ||
physicallyCorrectLights: h = !1, | ||
outputEncoding: g = Ae, | ||
toneMapping: w = Be, | ||
toneMappingExposure: v = 1, | ||
context: O = void 0, | ||
powerPreference: d = "default", | ||
preserveDrawingBuffer: ie = !1, | ||
clearColor: k = K("#000000"), | ||
windowSize: ue = !1 | ||
} = r, { width: A, height: B } = ue ? Y() : Me(t), { pixelRatio: N } = Se(), { pause: le, resume: pe } = ae(), fe = D(() => A.value / B.value), W = () => { | ||
!m.value || (m.value.setSize(A.value, B.value), m.value.setPixelRatio(N.value)); | ||
}, H = () => { | ||
!m.value || (m.value.shadowMap.enabled = C(i), m.value.outputEncoding = C(g), m.value.shadowMap.type = C(p), m.value.physicallyCorrectLights = C(h), m.value.toneMapping = C(w), m.value.toneMappingExposure = C(v), m.value.setClearColor(K(C(k)))); | ||
}, me = () => { | ||
const G = I(e); | ||
if (m.value || !G) | ||
physicallyCorrectLights: m = !1, | ||
outputEncoding: g = be, | ||
toneMapping: v = Ae, | ||
toneMappingExposure: R = 1, | ||
context: w = void 0, | ||
powerPreference: S = "default", | ||
preserveDrawingBuffer: I = !1, | ||
clearColor: h = Y("#000000"), | ||
windowSize: fe = !1 | ||
} = n, { width: _, height: F } = fe ? ee() : Me(t), { pixelRatio: H } = xe(), { pause: pe, resume: me } = ce(), de = j(() => _.value / F.value), G = () => { | ||
!d.value || (d.value.setSize(_.value, F.value), d.value.setPixelRatio(Math.min(H.value, 2))); | ||
}, J = () => { | ||
!d.value || (d.value.shadowMap.enabled = y(c), d.value.outputEncoding = y(g), d.value.shadowMap.type = y(p), d.value.physicallyCorrectLights = y(m), d.value.toneMapping = y(v), d.value.toneMappingExposure = y(R), d.value.setClearColor(Y(y(h)))); | ||
}, ge = () => { | ||
const K = z(e); | ||
if (d.value || !K) | ||
return; | ||
m.value = new Ie({ | ||
canvas: G, | ||
alpha: a, | ||
antialias: s, | ||
context: O, | ||
d.value = new $e({ | ||
canvas: K, | ||
alpha: o, | ||
antialias: i, | ||
context: w, | ||
depth: l, | ||
failIfMajorPerformanceCaveat: c, | ||
failIfMajorPerformanceCaveat: a, | ||
logarithmicDepthBuffer: f, | ||
powerPreference: d, | ||
precision: o, | ||
stencil: n, | ||
preserveDrawingBuffer: ie, | ||
powerPreference: S, | ||
precision: r, | ||
stencil: s, | ||
preserveDrawingBuffer: I, | ||
premultipliedAlpha: u | ||
}); | ||
const { setState: ge } = ce(); | ||
ge("renderer", m.value), H(), W(), pe(), z.value = !0; | ||
}, de = () => { | ||
!m.value || (m.value.dispose(), m.value = void 0, z.value = !1, le()); | ||
const { setState: we } = le(); | ||
we("renderer", d.value), J(), G(), me(), V.value = !0; | ||
}, he = () => { | ||
!d.value || (d.value.dispose(), d.value = void 0, V.value = !1, pe()); | ||
}; | ||
return x([A, B, N], W), x( | ||
return O([_, F, H], G), O( | ||
() => [ | ||
i, | ||
c, | ||
p, | ||
g, | ||
h, | ||
w, | ||
m, | ||
v, | ||
k | ||
R, | ||
h | ||
], | ||
H | ||
), x( | ||
J | ||
), O( | ||
() => [e, t], | ||
() => { | ||
I(e) && I(t) && me(); | ||
z(e) && z(t) && ge(); | ||
}, | ||
{ immediate: !0, deep: !0 } | ||
), { | ||
renderer: m, | ||
isReady: z, | ||
dispose: de, | ||
aspectRatio: fe | ||
renderer: d, | ||
isReady: V, | ||
dispose: he, | ||
aspectRatio: de | ||
}; | ||
} | ||
const He = _({ | ||
const We = k({ | ||
name: "TresCanvas", | ||
@@ -341,10 +358,10 @@ props: { | ||
}, | ||
setup(e, { slots: t, attrs: r }) { | ||
const { logError: a } = U(), s = S(), l = S(), { renderer: f, dispose: c, aspectRatio: o } = We(s, l, e), u = V(); | ||
return P("camera", u), P("renderer", f), P("aspect-ratio", o), t.default && !t.default().some((n) => n.type.name === "Scene") && a("TresCanvas must contain a Scene component."), t.default && !t.default().some((n) => { | ||
var i; | ||
return (i = n.type.name) == null ? void 0 : i.includes("Camera"); | ||
}) && a("Scene must contain a Camera component."), ve(() => c()), () => { | ||
setup(e, { slots: t, attrs: n }) { | ||
const { logError: o } = B(), i = P(), l = P(), { renderer: f, dispose: a, aspectRatio: r } = Ne(i, l, e), u = N(); | ||
return b("camera", u), b("renderer", f), b("aspect-ratio", r), t.default && !t.default().some((s) => s.type.name === "Scene") && o("TresCanvas must contain a Scene component."), t.default && !t.default().some((s) => { | ||
var c; | ||
return (c = s.type.name) == null ? void 0 : c.includes("Camera"); | ||
}) && o("Scene must contain a Camera component."), Ce(() => a()), () => { | ||
if (t.default) | ||
return J( | ||
return q( | ||
"div", | ||
@@ -357,8 +374,8 @@ { | ||
height: "100vh", | ||
...r.style | ||
...n.style | ||
} | ||
}, | ||
[ | ||
J("canvas", { | ||
ref: s, | ||
q("canvas", { | ||
ref: i, | ||
style: { width: "100%", height: "100%", position: "absolute", top: 0, left: 0 } | ||
@@ -371,8 +388,8 @@ }), | ||
} | ||
}), Ge = _({ | ||
}), He = k({ | ||
name: "Scene", | ||
setup(e, { slots: t }) { | ||
const { scene: r } = se(), a = X("renderer"), { activeCamera: s } = ee(), { onLoop: l } = ae(); | ||
return P("local-scene", r), l(() => { | ||
(a == null ? void 0 : a.value) && (s == null ? void 0 : s.value) && (r == null ? void 0 : r.value) && a.value.render(r == null ? void 0 : r.value, s.value); | ||
const { scene: n } = ue(), o = T("renderer"), { activeCamera: i } = ne(), { onLoop: l } = ce(); | ||
return b("local-scene", n), l(() => { | ||
(o == null ? void 0 : o.value) && (i == null ? void 0 : i.value) && (n == null ? void 0 : n.value) && o.value.render(n == null ? void 0 : n.value, i.value); | ||
}), () => { | ||
@@ -383,28 +400,31 @@ if (t.default) | ||
} | ||
}), Ye = Symbol("UseTresState"), Ze = { | ||
}), Ye = Symbol("UseTresState"), Ge = "1.2.0", Ze = { | ||
install(e, t) { | ||
const r = (t == null ? void 0 : t.prefix) || "Tres"; | ||
e.component(`${r}Canvas`, He), e.component(`${r}Scene`, Ge); | ||
const { catalogue: a } = Fe(e, r), { createComponentInstances: s } = te(r); | ||
s(a).forEach(([f, c]) => { | ||
e.component(f, c); | ||
}), Ce(() => { | ||
console.log({ catalogue: a }); | ||
}); | ||
const n = (t == null ? void 0 : t.prefix) || "Tres"; | ||
e.component(`${n}Canvas`, We), e.component(`${n}Scene`, He); | ||
const { catalogue: o, extend: i } = re(e, n); | ||
e.provide("catalogue", o), e.provide("extend", i); | ||
const { createComponentInstances: l } = ae(n); | ||
l(o).forEach(([a, r]) => { | ||
e.component(a, r); | ||
}), window.__TRES__ = { | ||
app: e, | ||
version: Ge | ||
}; | ||
} | ||
}; | ||
export { | ||
$e as CameraType, | ||
Be as CameraType, | ||
Ye as UseTresStateSymbol, | ||
Ze as default, | ||
Ne as trasverseObjects, | ||
ee as useCamera, | ||
Fe as useCatalogue, | ||
te as useInstanceCreator, | ||
ke as trasverseObjects, | ||
ne as useCamera, | ||
re as useCatalogue, | ||
ae as useInstanceCreator, | ||
Qe as useLoader, | ||
ae as useRenderLoop, | ||
We as useRenderer, | ||
se as useScene, | ||
ce as useRenderLoop, | ||
Ne as useRenderer, | ||
ue as useScene, | ||
Xe as useTexture, | ||
ce as useTres | ||
le as useTres | ||
}; |
@@ -14,1 +14,12 @@ import { Object3D } from 'three' | ||
export type TresAttributes = Record<string, any> & { args?: number[] } | ||
declare global { | ||
// Define the window interface, with type annotations for the properties and methods of the window object | ||
interface Window { | ||
// Define the location property, with a type of Location | ||
__TRES__: { | ||
app: App | ||
version: string | ||
} | ||
} | ||
} |
{ | ||
"name": "@tresjs/core", | ||
"description": "Declarative ThreeJS using Vue Components", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"type": "module", | ||
@@ -42,3 +42,3 @@ "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)", | ||
"@histoire/plugin-vue": "0.11.7", | ||
"@tresjs/cientos": "^1.0.0", | ||
"@tresjs/cientos": "^1.1.0", | ||
"@types/three": "^0.146.0", | ||
@@ -45,0 +45,0 @@ "@vitejs/plugin-vue": "^3.2.0", |
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
2429774
42
769