@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 824 B
JavaScript
class t{static dot(t,e){const l=t.length;let n=0;for(let o=0;o<l;++o)n+=t[o]*e[o];return n}static normalize(e){let l=t.dot(e,e);if(l>0){l=1/Math.sqrt(l);const t=e.length;for(let n=0;n<t;++n)e[n]*=l}}static set(e,l,n){const o=e.length;if("quaternion"===n){let n=t.dot(l,l);n>0&&(n=1/Math.sqrt(n));for(let t=0;t<o;++t)e[t]=l[t]*n}else for(let t=0;t<o;++t)e[t]=l[t]}static blendVec(t,e,l,n){const o=n?1:1-l,s=t.length;for(let n=0;n<s;++n)t[n]=t[n]*o+e[n]*l}static blendQuat(e,l,n,o){const s=e.length,r=o?1:1-n;t.dot(e,l)<0&&(n=-n);for(let t=0;t<s;++t)e[t]=e[t]*r+l[t]*n;o||t.normalize(e)}static blend(e,l,n,o,s){"quaternion"===o?t.blendQuat(e,l,n,s):t.blendVec(e,l,n,s)}static stableSort(t,e){const l=t.length;for(let n=0;n<l-1;++n)for(let o=n+1;o<l;++o)if(e(t[o],t[n])){const e=t[n];t[n]=t[o],t[o]=e}}}export{t as AnimBlend};