Files
cocos4/cocos/animation/blending.ts
T
ChiaNing 4bc2739786 Vmath (#4987)
* Vmath (#4895)

* vmath refactor

* value-type API change

* vmath change update

* conflict fix

* value types change

* translate modify (#4917)

* value types bug fixed (#4940)

* playground update (#4946)

* bug fixed

* bug fixed

* bug fixed

* bug fix

* util modify

* create remove & ccenum rename

* export by cc.math

* Rename value-types to math

* util funtion deprecated warn

* value-types change

* color test fix

* color API change
2019-07-29 11:50:51 +08:00

48 lines
1.6 KiB
TypeScript

/**
* @category animation
*/
import { Quat, Vec3 } from '../core/math';
import { PropertyBlendState } from './animation-blend-state';
export function additive1D (value: number, weight: number, propertyBlendState: PropertyBlendState<number>) {
if (!propertyBlendState.value) {
propertyBlendState.value = 0;
}
if (propertyBlendState.weight === 0) {
propertyBlendState.value = 0;
}
return propertyBlendState.value + value * weight;
}
export function additive3D (value: Vec3, weight: number, propertyBlendState: PropertyBlendState<Vec3>) {
if (!propertyBlendState.value) {
propertyBlendState.value = new Vec3();
}
if (propertyBlendState.weight === 0) {
Vec3.zero(propertyBlendState.value);
}
if (weight === 0) {
return propertyBlendState.value;
} else if (weight === 1) {
return Vec3.copy(propertyBlendState.value, value);
}
return Vec3.scaleAndAdd(propertyBlendState.value, propertyBlendState.value, value, weight);
}
export function additiveQuat (value: Quat, weight: number, propertyBlendState: PropertyBlendState<Quat>) {
if (!propertyBlendState.value) {
propertyBlendState.value = new Quat();
}
if (propertyBlendState.weight === 0) {
Quat.identity(propertyBlendState.value);
}
if (weight === 0) {
return propertyBlendState.value;
} else if (weight === 1) {
return Quat.copy(propertyBlendState.value, value);
}
const t = weight / (propertyBlendState.weight + weight);
return Quat.slerp(propertyBlendState.value, propertyBlendState.value, value, t);
}