import type { AnimationAction } from "three"; import { Vector2Like } from "../mescellaneous/math"; import { AnimationTree } from "./AnimationTree"; /** * Configuration for a freeform animation action in the blend tree. * Associates an animation action with Cartesian coordinates in 2D space. */ export interface FreeformAction { /** The Three.js animation action to be played */ action: AnimationAction; /** X coordinate in 2D space (finite number) */ x: number; /** Y coordinate in 2D space (finite number) */ y: number; } /** * Freeform blend tree implementation for 2D animation blending. * * Uses Delaunay triangulation to create a mesh from animation actions positioned * in 2D coordinates. Interpolates between animations using barycentric coordinates * within triangles. For points outside the mesh, uses nearest edge interpolation. * * @example * ```typescript * const actions = [ * { action: idleAction, x: 0, y: 0 }, * { action: walkAction, x: 0, y: 1 }, * { action: runAction, x: 1, y: 0 }, * { action: sprintAction, x: 1, y: 1 } * ]; * * const blendTree = new FreeformBlendTree(actions); * blendTree.setBlend(0.5, 0.8); * ``` */ export declare class FreeformBlendTree extends AnimationTree { private readonly tempAnchorMap; private readonly trackableAnchors; private readonly triangles; private readonly boundaryEdgeMap; private currentX; private currentY; /** * Creates a new freeform blend tree from animation actions positioned in 2D space. * Performs Delaunay triangulation to create a mesh for interpolation. * * @param freeformActions - Array of freeform actions defining the blend space. * Must contain at least 3 actions with unique coordinates. * @throws {Error} When fewer than 3 actions are provided * @throws {Error} When any action has non-finite coordinates * @throws {Error} When multiple actions have the same coordinates * @throws {Error} When any animation clip duration is not positive */ constructor(freeformActions: FreeformAction[]); get blendValue(): Vector2Like; /** * Sets the blend position in 2D coordinates to determine animation weights. * Recalculates weights using barycentric interpolation within triangles * or nearest edge interpolation for boundary points. * * @param x - Target X coordinate in 2D space * @param y - Target Y coordinate in 2D space * @throws {Error} When x or y coordinate is not a finite number */ setBlend(x: number, y: number): void; protected ["onEnterInternal"](): void; /** * Updates the influence for all anchors in the freeform 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 current blend position. * * Attempts barycentric interpolation if point lies within any triangle. * Falls back to nearest boundary edge interpolation for external points. */ private updateAnchors; /** * Applies barycentric weights if the blend point lies within any triangle. * * @param result - Map to store calculated weights for each anchor * @returns True if barycentric interpolation was applied, false if point is outside all triangles */ private applyBarycentricWeights; /** * Applies nearest boundary edge interpolation for points outside the mesh. * Finds the closest boundary vertex and interpolates along the nearest edge. * * @param result - Map to store calculated weights for each anchor */ private applyNearestNeighborWeight; /** * Sorts triangles by distance from their centroids to the current blend position. * Improves performance by checking closer triangles first. */ private sortTriangles; }