animouse
Version:
lightweight animation state machine for three js
72 lines (71 loc) • 2.77 kB
TypeScript
import type { AnimationAction } from "three";
import { AnimationTree } from "./AnimationTree";
/**
* Configuration for a linear animation action in the blend tree.
* Associates an animation action with a position value on the linear blend axis.
*/
export interface LinearAction {
/** The animation action to be played */
action: AnimationAction;
/** Position value on the linear blend axis where this action is positioned */
value: number;
}
/**
* Linear blend tree implementation for 1D animation blending.
*
* Manages animation actions positioned along a linear axis, blending
* between adjacent animations based on a blend value. Interpolates weights
* between the two closest animations.
*
* Action values can be any finite numbers and must be unique.
*
* @example
* ```typescript
* const blendTree = new LinearBlendTree([
* { action: idleAction, value: 0 },
* { action: walkAction, value: 0.5 },
* { action: runAction, value: 1 }
* ]);
*
* blendTree.setBlend(0.3);
* ```
*/
export declare class LinearBlendTree extends AnimationTree {
private readonly anchors;
private lastLeftAnchor?;
private lastRightAnchor?;
private currentBlend;
/**
* Creates a new linear blend tree with the specified animation actions.
* Actions are sorted by their value along the linear axis.
*
* @param linearActions - Array of linear actions defining the blend space.
* Must contain at least 2 actions with unique, finite values.
* @throws {Error} When fewer than 2 actions are provided
* @throws {Error} When any action has a non-finite value
* @throws {Error} When multiple actions have the same value
* @throws {Error} When any animation clip duration is not positive
*/
constructor(linearActions: LinearAction[]);
get blendValue(): number;
/**
* Sets the blend value to determine animation weights along the linear axis.
* Recalculates weights to interpolate between the two closest actions.
* Values outside the action range give full weight to the nearest boundary action.
*
* @param value - The target blend value
* @throws {Error} When the blend value is not a finite number
*/
setBlend(value: number): void;
protected ["onEnterInternal"](): void;
/**
* Updates the influence for all anchors in the linear blend tree.
* Called when the tree's influence changes but relative weights remain the same.
*/
protected updateAnchorsInfluence(): void;
/**
* Recalculates and updates animation weights based on the current blend value.
* Performs linear interpolation between the two actions closest to the blend point.
*/
private updateAnchors;
}