UNPKG

@shopware-ag/dive

Version:

Shopware Spatial Framework

84 lines (83 loc) 3.03 kB
var h = Object.defineProperty; var a = (s, i, t) => i in s ? h(s, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[i] = t; var n = (s, i, t) => a(s, typeof i != "symbol" ? i + "" : i, t); import { AnimationMixer as p, LoopOnce as c, LoopPingPong as u, LoopRepeat as _ } from "three/webgpu"; import { A as l } from "./Animator-DHnpWRt_.mjs"; class g extends l { constructor(t, r) { super(); n(this, "_mixer"); n(this, "_actions", /* @__PURE__ */ new Map()); n(this, "_currentAction", null); n(this, "_state", "idle"); n(this, "_loop", "once"); this._mixer = new p(t); for (const e of r) { const o = this._mixer.clipAction(e); o.clampWhenFinished = !0, o.loop = c, this._actions.set(e.name, o); } this._mixer.addEventListener("finished", () => { this._state = "idle", this.dispatchEvent({ type: "complete", target: this }); }); } get state() { return this._state; } get duration() { var t; return ((t = this._currentAction) == null ? void 0 : t.getClip().duration) ?? 0; } get loop() { return this._loop; } set loop(t) { this._loop = t, this._currentAction && (this._currentAction.loop = this._resolveLoopConstant(t)); } _resolveLoopConstant(t) { switch (t) { case "repeat": return _; case "pingpong": return u; default: return c; } } get time() { var t; return ((t = this._currentAction) == null ? void 0 : t.time) ?? 0; } set time(t) { this._currentAction && (this._currentAction.time = t); } get clipNames() { return [...this._actions.keys()]; } get currentClipName() { return this._currentAction ? this._currentAction.getClip().name : null; } play(t) { const r = t ?? this._actions.keys().next().value ?? void 0; if (r === void 0) return this; const e = this._actions.get(r); return e ? (this._currentAction && this._currentAction !== e ? (this._currentAction.fadeOut(0.3), e.reset().fadeIn(0.3)) : this._state === "idle" && e.reset(), e.loop = this._resolveLoopConstant(this._loop), e.play(), this._state = "playing", this._currentAction = e, this._currentAction.paused = !1, this.dispatchEvent({ type: "play", target: this }), this) : this; } pause() { return this._state = "paused", this._currentAction && (this._currentAction.paused = !0), this.dispatchEvent({ type: "pause", target: this }), this; } resume() { return this._state = "playing", this._currentAction && (this._currentAction.paused = !1), this.dispatchEvent({ type: "resume", target: this }), this; } stop() { return this._state = "idle", this._mixer.stopAllAction(), this._currentAction = null, this.dispatchEvent({ type: "stop", target: this }), this; } update(t) { this._mixer.update(t); } dispose() { this._mixer.stopAllAction(), this._mixer.uncacheRoot(this._mixer.getRoot()), this._actions.clear(), this._currentAction = null, this._state = "idle"; } } export { g as ClipAnimator };