@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 3.1 kB
JavaScript
import{math as t}from"../../../core/math/math.js";import{AnimTrack as e}from"../../anim/evaluator/anim-track.js";import{AnimTransition as i}from"../../anim/controller/anim-transition.js";import{ANIM_LAYER_OVERWRITE as n}from"../../anim/controller/constants.js";class s{constructor(t,e,i,s=1,r=n){this._name=void 0,this._controller=void 0,this._component=void 0,this._weight=void 0,this._blendType=void 0,this._mask=null,this._blendTime=0,this._blendTimeElapsed=0,this._startingWeight=0,this._targetWeight=0,this._name=t,this._controller=e,this._component=i,this._weight=s,this._blendType=r}get name(){return this._name}set playing(t){this._controller.playing=t}get playing(){return this._controller.playing}get playable(){return this._controller.playable}get activeState(){return this._controller.activeStateName}get previousState(){return this._controller.previousStateName}get activeStateProgress(){return this._controller.activeStateProgress}get activeStateDuration(){return this._controller.activeStateDuration}set activeStateCurrentTime(t){const e=this._controller,i=e.playing;e.playing=!0,e.activeStateCurrentTime=t,i||e.update(0),e.playing=i}get activeStateCurrentTime(){return this._controller.activeStateCurrentTime}get transitioning(){return this._controller.transitioning}get transitionProgress(){return this.transitioning?this._controller.transitionProgress:null}get states(){return this._controller.states}set weight(t){this._weight=t,this._component.dirtifyTargets()}get weight(){return this._weight}set blendType(t){t!==this._blendType&&(this._blendType=t,this._controller.normalizeWeights&&this._component.rebind())}get blendType(){return this._blendType}set mask(t){this._controller.assignMask(t)&&this._component.rebind(),this._mask=t}get mask(){return this._mask}play(t){this._controller.play(t)}pause(){this._controller.pause()}reset(){this._controller.reset()}rebind(){this._controller.rebind()}update(e){this._blendTime&&(this._blendTimeElapsed<this._blendTime?(this.weight=t.lerp(this._startingWeight,this._targetWeight,this._blendTimeElapsed/this._blendTime),this._blendTimeElapsed+=e):(this.weight=this._targetWeight,this._blendTime=0,this._blendTimeElapsed=0,this._startingWeight=0,this._targetWeight=0)),this._controller.update(e)}blendToWeight(t,e){this._startingWeight=this.weight,this._targetWeight=t,this._blendTime=Math.max(0,e),this._blendTimeElapsed=0}assignMask(t){this._controller.assignMask(t)&&this._component.rebind(),this._mask=t}assignAnimation(t,n,s,r){n instanceof e&&(this._controller.assignAnimation(t,n,s,r),0===this._controller._transitions.length&&this._controller._transitions.push(new i({from:"START",to:t})),this._component.activate&&this._component.playable&&(this._component.playing=!0))}removeNodeAnimations(t){this._controller.removeNodeAnimations(t)&&(this._component.playing=!1)}getAnimationAsset(t){return this._component.animationAssets[`${this.name}:${t}`]}transition(t,e=0,n=null){this._controller.updateStateFromTransition(new i({from:this._controller.activeStateName,to:t,time:e,transitionOffset:n}))}}export{s as AnimComponentLayer};