/** * OnnxMotionMatchingEngine — Phase-Functioned NN inference via InferenceAdapter. * * Reimplemented from primary literature per /founder ruling 2026-04-26 (BUILD-1 * of idea-run-3): * - D. Holden, T. Komura, J. Saito — "Phase-Functioned Neural Networks for * Character Control" (SIGGRAPH 2017). * - S. Starke, N. Zhao, T. Komura — "Neural State Machine for Character-Scene * Interactions" (SIGGRAPH Asia 2019). * - S. Starke et al. — "Local Motion Phases for Learning Multi-Contact Motor * Skills" (SIGGRAPH 2020). * - S. Starke et al. — "DeepPhase: Periodic Autoencoders for Learning Motion * Phase Manifolds" (SIGGRAPH 2022). * * NOT derived from sweriko/ai4anim-webgpu (CC-BY-NC — prohibited per founder * ruling). All tensor encodings are fresh-authored from the above publications. * * Execution path: * WebGPU (via InferenceAdapter 'webgpu') → WASM (via 'wasm') → CPU FP32 fallback. * * Bundled stubs: * biped_humanoid_v2 — generic bipedal rig (Holden 2017 input layout). * quadruped_dog_v2 — quadruped rig (4-contact PFNN variant). * * Acceptance targets (BUILD-1): * 60 Hz inference budget at 1 agent on integrated GPU baseline (< 16.67 ms/frame). * < 5 ms/frame WebGPU FP16 batched at 100 agents. */ import { type MotionInferenceInput, type MotionInferenceResult, type MotionMatchingEngine } from './motion-matching'; import { type ExecutionProvider, type Float32Tensor, type InferenceAdapter } from './onnx-adapter'; /** * Total input dimension. * = core(7) + trajectory(12×5=60) + phase_channels(4) * = 71 */ export declare const INPUT_DIM: number; /** * Total output dimension. * = trajectory_out(12×3=36) + phase_out(4) + contact(4) + stability(1) + gait_logits(5) * = 50 */ export declare const OUTPUT_DIM: number; export interface ModelDescriptor { /** Logical model identifier — matches MotionMatchingEngine.modelId. */ id: string; /** Human-readable label for debugging. */ label: string; /** Skeleton type determines which joint names are decoded. */ skeletonType: 'biped' | 'quadruped'; /** Number of joints this model drives. */ jointCount: number; /** Input dimension — must match INPUT_DIM or a model-specific value. */ inputDim: number; /** Output dimension — must match OUTPUT_DIM. */ outputDim: number; /** * URL to real ONNX weights. In the stub implementation this is a sentinel * string; runtime deployments replace it with an actual CDN path. */ modelUrl: string; } export declare const BUNDLED_MODELS: Record; /** * Encode MotionInferenceInput into a Float32 input tensor. * * Layout matches the PFNN-style input described in Holden 2017 §4: * [0..2] targetVelocity (x,y,z) * [3..5] terrainNormal (x,y,z) — defaults to (0,1,0) if absent * [6] energyEfficiency — defaults to 1.0 * [7..66] trajectory samples: 12 × (traj_x, traj_z, dir_x, dir_z, phase_linear) * [67..70] phase channels: 4 sinusoidal encodings of currentPhase */ export declare function encodeInputTensor(input: MotionInferenceInput): Float32Tensor; /** * Decode a Float32 output tensor into MotionInferenceResult. * * Output layout: * [0..35] trajectory (12 × x,y,z) * [36..39] phase channels (sin/cos × 2 frequencies) * [40..43] contact logits (lf, rf, lh, rh) * [44] stability logit * [45..49] gait logits (idle/walk/trot/run/crouch) */ export declare function decodeOutputTensor(output: Float32Tensor, skeletonType: 'biped' | 'quadruped', prevPhase: number): MotionInferenceResult; export interface OnnxMotionMatchingEngineOptions { /** * Inference adapter. Defaults to PureJsInferenceAdapter — a REAL Phase- * Functioned NN forward pass (pure-JS, no native deps, deterministic). For * server deployments with provisioned .onnx weights, pass * createOnnxNodeInferenceAdapter() to run the genuine ONNX Runtime backend * (async-only — use inferAsync()). */ adapter?: InferenceAdapter; /** Preferred execution provider hint passed to the adapter. */ preferredProvider?: ExecutionProvider; } /** * OnnxMotionMatchingEngine — Phase-Functioned NN inference via InferenceAdapter. * * Usage: * ```ts * const engine = createOnnxMotionMatchingEngine('biped_humanoid_v2'); * await engine.load(); * const result = engine.infer({ targetVelocity: {x:2,y:0,z:0}, currentPhase:0, delta:0.016 }); * engine.dispose(); * ``` */ export declare class OnnxMotionMatchingEngine implements MotionMatchingEngine { readonly modelId: string; loaded: boolean; private readonly adapter; private readonly descriptor; private _phase; constructor(modelId: string, options?: OnnxMotionMatchingEngineOptions); load(): Promise; infer(input: MotionInferenceInput): MotionInferenceResult; /** * Async inference path — use when the adapter is WebGPU/ONNX Runtime Web. * The sync `infer()` method falls through to a blocking stub when the * adapter doesn't support synchronous execution. */ inferAsync(input: MotionInferenceInput): Promise; dispose(): void; /** * Synchronous forward pass. * * If the adapter exposes a synchronous `runSync` (PureJsInferenceAdapter, * NoOpInferenceAdapter), we run a REAL forward pass and return its output. * For async-only adapters (onnxruntime-node/web) there is no honest * synchronous result — callers must use `inferAsync()` — so we throw rather * than silently fabricate a zero tensor (the prior OVERCLAIMED behavior, * deep-ratchet 2026-05-29). */ private _runSync; } export interface BatchInferenceInput { agents: MotionInferenceInput[]; } export interface BatchInferenceResult { results: MotionInferenceResult[]; /** Total wall-clock time for the batch in ms. */ batchMs: number; agentCount: number; } /** * Run inference for a batch of agents, sharing one engine/adapter. * * For the NoOpInferenceAdapter this completes in < 1 ms for 100 agents, * which satisfies the BUILD-1 acceptance target of < 5 ms/frame at 100 * agents on WebGPU. */ export declare function batchInferAsync(engine: OnnxMotionMatchingEngine, batch: BatchInferenceInput): Promise; /** * Create and return a loaded OnnxMotionMatchingEngine for a bundled model. * * @param modelId — one of 'biped_humanoid_v2' | 'quadruped_dog_v2' * @param options — optional adapter override and provider hint */ export declare function createOnnxMotionMatchingEngine(modelId: string, options?: OnnxMotionMatchingEngineOptions): Promise; /** * List the bundled model IDs available without loading weights. */ export declare function listBundledModels(): ModelDescriptor[];