import {z} from 'zod' export type Animate3DPresetModelPayload = {model: string, preset_id: string, crop_loop?: boolean | undefined, in_place?: boolean | undefined, request_id?: string | undefined, async?: boolean | undefined}; export type CreateApiAssets3dModelAnimatePresetArgs = {body: Animate3DPresetModelPayload}; export type CreateApiAssets3dModelAnimatePresetOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const animationClip = z.object({clip_name: z.string().optional(), prompt: z.string().optional(), preset_id: z.string().optional(), mode: z.enum(["rot_trans", "rot_only"]).optional(), seed: z.number().int().optional(), glb_url: z.string().optional(), preview_url: z.string().optional(), motion: z.number().optional(), fit_rmse: z.number().optional()}); export const animationCandidates = z.object({animations: z.array(animationClip).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Apply a curated animation preset to an already-rigged 3D model (retargeting). Pass the rigged GLB in `model` (URL or base64; the 3D asset file, not an AI model name) and a `preset_id` from the animation presets list (from listAnimationPresets; any preset id works). Any rig type can take a preset, though retargeting does not succeed on every model: when it does not, the job fails. The job result is one retargeted animation - a standalone animation-only GLB in `glb_url` plus an mp4 `preview_url` - in the same `animations` envelope as the animate endpoint. crop_loop trims the clip to its seamlessly-looping span (omit to follow the preset's own loop flag); in_place removes net travel so the character moves on the spot, as game-engine locomotion expects (omit to keep the preset's own travel). Credits are held when the job is accepted and refunded if it fails or is cancelled. Requires an API key (user scope). The call returns 202 with a job id - poll getApiJob (pass wait 30 to long-poll) honouring poll_after_ms, until status is succeeded; its result field is exactly the response documented for this operation. Synchronous responses are deprecated but still supported: pass `async: false` to block until the result is ready and receive it as the response body. Synchronous calls run on the same queue: the response carries an X-Ludo-Job-Id header, and a job still running after 15 minutes comes back as 202 with the job instead of an error. Each account may have up to 50 generations queued or running at once via the API; a request beyond that returns 429 (code PENDING_JOBS_LIMIT). * * POST /assets/3d-model/animate-preset */ export const createApiAssets3dModelAnimatePreset = async (args: CreateApiAssets3dModelAnimatePresetArgs, options: CreateApiAssets3dModelAnimatePresetOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("Authorization", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/assets/3d-model/animate-preset${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(animationCandidates, await res.json()) };