@shopware-ag/dive
Version:
Shopware Spatial Framework
2 lines (1 loc) • 2.49 kB
JavaScript
"use strict";var a=Object.defineProperty;var h=(s,i,t)=>i in s?a(s,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[i]=t;var n=(s,i,t)=>h(s,typeof i!="symbol"?i+"":i,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("three/webgpu"),u=require("./Animator-YDE8aFEd.cjs");class p extends u.Animator{constructor(t,o){super();n(this,"_mixer");n(this,"_actions",new Map);n(this,"_currentAction",null);n(this,"_state","idle");n(this,"_loop","once");this._mixer=new r.AnimationMixer(t);for(const e of o){const c=this._mixer.clipAction(e);c.clampWhenFinished=!0,c.loop=r.LoopOnce,this._actions.set(e.name,c)}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 r.LoopRepeat;case"pingpong":return r.LoopPingPong;default:return r.LoopOnce}}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 o=t??this._actions.keys().next().value??void 0;if(o===void 0)return this;const e=this._actions.get(o);return e?(this._currentAction&&this._currentAction!==e?(this._currentAction.fadeOut(.3),e.reset().fadeIn(.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"}}exports.ClipAnimator=p;