@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 1.06 kB
JavaScript
import{Vec2 as t}from"../../../core/math/vec2.js";import{math as e}from"../../../core/math/math.js";import{AnimBlendTree as i}from"./anim-blend-tree.js";class n extends i{pointDistanceCache(t,e){const i=`${t}${e}`;return this._pointCache[i]||(this._pointCache[i]=this._children[e].point.clone().sub(this._children[t].point)),this._pointCache[i]}calculateWeights(){if(this.updateParameterValues())return;let t,i;n._p.set(...this._parameterValues),t=0,i=0;for(let h=0;h<this._children.length;h++){const s=this._children[h],o=s.point;n._pip.set(n._p.x,n._p.y).sub(o);let r=Number.MAX_VALUE;for(let t=0;t<this._children.length;t++){if(h===t)continue;const i=this.pointDistanceCache(h,t),s=e.clamp(1-n._pip.dot(i)/i.lengthSq(),0,1);s<r&&(r=s)}s.weight=r,t+=r,this._syncAnimations&&(i+=s.animTrack.duration/s.absoluteSpeed*s.weight)}for(let e=0;e<this._children.length;e++){const n=this._children[e];n.weight=n._weight/t,this._syncAnimations&&(n.weightedSpeed=n.animTrack.duration/n.absoluteSpeed/i)}}}n._p=new t,n._pip=new t;export{n as AnimBlendTreeCartesian2D};