UNPKG

sandai-react

Version:

React components and utilities for the Sandai 3D AI Characters.

85 lines 2.86 kB
/** * Represents a Profile of all possible string values [T], * where T is a Union of string constants. * * The length of the weights array will be equal to the key count. * * !WARNING! * the key 'blendshapes' is reserved for internal use. You will see it used once you * export a profile. * * @example * ```ts * Profile<"string" | "constant" | "foo" | "bar"> //Profile.weights.length will be 4 * ``` */ export interface Profile<T extends string> { name: T | "blendshapes"; weights: number[]; scalars?: Map<T | "blendshapes", number[]>; metadata: { type: "trained" | "init" | "preset"; sampleCount: number; }; } export type ProfileNames<K extends string> = Profile<K>["name"]; /** * Manages profiles for generic input matrices that should be constrained * to certain values. The possible values are represented as a string union [T]. * * !WARNING! * the key 'blendshapes' is reserved for internal use. You will see it used once you * export a profile. * * @example * ```ts * const pm = new ProfileManager<"string" | "constant" | "foo" | "bar">(); * ``` */ export declare class ProfileManager<K extends string, T extends ProfileNames<K>> { private profiles; private currentSamples; readonly profileKeys: T[]; constructor(profilePresetOrKeys: T[] | { profiles: [T, Profile<T>][]; currentSamples: [T, [string, number][]][]; }); private initializeEmptyProfiles; private initializeDefaultProfiles; hasProfile(key: T): boolean; getProfile(key: T): Profile<T> | undefined; addSample(key: T, blendshapes: Map<string, number>): void; private weightedEuclideanDistance; private getPairwiseDistances; /** * Train profiles for all emotions with collected samples */ trainProfiles(mode?: "default" | "normalized", calculateScalars?: boolean): Promise<void>; /** * Predict T from current blendshape values */ predict(blendshapes: Map<string, number>, mode?: "default" | "normalized"): [K, number] & { all: [K, number][]; }; /** * Sigmoid function with adjustable steepness. * @param x - Input value between 0 and 1 * @param steepness - Higher values = steeper curve (default: 10) * @returns Scaled value between 0 and 1 */ sigmoidScale(x: number, steepness?: number): number; /** * Export both profiles and currentSamples to JSON. */ exportProfile(): string; /** * Import a JSON string containing both profiles and currentSamples. */ importProfile(profile: string): void; /** * Import profile and sample maps directly (usually from parsed JSON). */ importProfileMap(profileEntries: [T, Profile<T>][], sampleEntries: [T, [string, number][]][]): void; reset(): void; } //# sourceMappingURL=ProfileManager.d.ts.map