@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 2.52 kB
JavaScript
import{AnimTrack as t}from"../evaluator/anim-track.js";import{AnimBlendTree1D as i}from"./anim-blend-tree-1d.js";import{AnimBlendTreeCartesian2D as e}from"./anim-blend-tree-2d-cartesian.js";import{AnimBlendTreeDirectional2D as n}from"./anim-blend-tree-2d-directional.js";import{AnimBlendTreeDirect as a}from"./anim-blend-tree-direct.js";import{AnimNode as s}from"./anim-node.js";import{ANIM_BLEND_DIRECT as r,ANIM_BLEND_2D_DIRECTIONAL as o,ANIM_BLEND_2D_CARTESIAN as m,ANIM_BLEND_1D as h,ANIM_CONTROL_STATES as l}from"./constants.js";class d{constructor(t,i,e=1,n=!0,a){this._animations={},this._animationList=[],this._controller=t,this._name=i,this._speed=e,this._loop=n,this._hasAnimations=!1,this._blendTree=a?this._createTree(a.type,this,null,i,1,a.parameter?[a.parameter]:a.parameters,a.children,a.syncAnimations,this._createTree,this._controller.findParameter):new s(this,null,i,1,e)}_createTree(t,s,l,d,_,c,u,p,g,f){switch(t){case h:return new i(s,l,d,_,c,u,p,g,f);case m:return new e(s,l,d,_,c,u,p,g,f);case o:return new n(s,l,d,_,c,u,p,g,f);case r:return new a(s,l,d,_,c,u,p,g,f)}}_getNodeFromPath(t){let i=this._blendTree;for(let e=1;e<t.length;e++)i=i.getChild(t[e]);return i}addAnimation(t,i){const e=t.join("."),n=this._animationList.findIndex((t=>t.path===e));if(n>=0)this._animationList[n].animTrack=i;else{const e=this._getNodeFromPath(t);e.animTrack=i,this._animationList.push(e)}this._updateHasAnimations()}_updateHasAnimations(){this._hasAnimations=this._animationList.length>0&&this._animationList.every((i=>i.animTrack&&i.animTrack!==t.EMPTY))}get name(){return this._name}set animations(t){this._animationList=t,this._updateHasAnimations()}get animations(){return this._animationList}get hasAnimations(){return this._hasAnimations}set speed(t){this._speed=t}get speed(){return this._speed}set loop(t){this._loop=t}get loop(){return this._loop}get nodeCount(){return this._blendTree&&this._blendTree.constructor!==s?this._blendTree.getNodeCount():1}get playable(){return-1!==l.indexOf(this.name)||this.animations.length===this.nodeCount}get looping(){if(this.animations.length>0){const t=`${this.name}.${this.animations[0].animTrack.name}`,i=this._controller.animEvaluator.findClip(t);if(i)return i.loop}return!1}get totalWeight(){let t=0;for(let i=0;i<this.animations.length;i++)t+=this.animations[i].weight;return t}get timelineDuration(){let t=0;for(let i=0;i<this.animations.length;i++){const e=this.animations[i];e.animTrack.duration>t&&(t=e.animTrack.duration)}return t}}export{d as AnimState};