import {z} from 'zod' export type ThreeDGenerationParameters = {model?: ('prop' | 'hero') | undefined, rig?: boolean | undefined, rig_type?: ('general' | 'humanoid' | 'game' | 'humanoid_template' | 'humanoid_template_hands') | undefined, joint_naming?: ('smpl' | 'mixamo' | 'humanik' | 'unreal' | 'godot' | 'rigify' | 'vroid') | undefined, target_num_faces?: number | undefined, dynamic_simplification?: number | undefined, remeshing?: string | undefined, texture_size?: number | undefined, texture_type?: string | undefined, render_format?: string | undefined, render_video?: boolean | undefined}; export type AssetGeneration = {id?: string | undefined, rigged?: boolean | undefined, animatable?: boolean | undefined, seed?: number | undefined, images_b64?: Array | undefined, params_encrypted?: string | undefined, request_id?: string | undefined, video_b64?: string | undefined, mesh_video_b64?: string | undefined, snapshots_b64?: Array | undefined, model_b64?: string | undefined, binary_data_b64?: string | undefined, voxels_b64?: string | undefined, mask_snapshots_b64?: Array | undefined, depth_snapshots_b64?: Array | undefined, normal_snapshots_b64?: Array | undefined, textured?: boolean | undefined, view_azimuths?: Array | undefined, generation_model?: string | undefined, generation_parameters?: ThreeDGenerationParameters | undefined}; export type RetopologyPayload = {request_id?: string | undefined, asset_generation?: AssetGeneration | undefined, generation_parameters?: ThreeDGenerationParameters | undefined}; export type CreateApiGamesGenerateRetopologyArgs = {body: RetopologyPayload}; export type CreateApiGamesGenerateRetopologyOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const threeDGenerationParameters = z.object({model: z.enum(["prop", "hero"]).optional(), rig: z.boolean().optional(), rig_type: z.enum(["general", "humanoid", "game", "humanoid_template", "humanoid_template_hands"]).optional(), joint_naming: z.enum(["smpl", "mixamo", "humanik", "unreal", "godot", "rigify", "vroid"]).optional(), target_num_faces: z.number().int().optional(), dynamic_simplification: z.number().optional(), remeshing: z.string().optional(), texture_size: z.number().int().optional(), texture_type: z.string().optional(), render_format: z.string().optional(), render_video: z.boolean().optional()}); export const assetGeneration = z.object({id: z.string().optional(), rigged: z.boolean().optional(), animatable: z.boolean().optional(), seed: z.number().int().optional(), images_b64: z.array(z.string()).optional(), params_encrypted: z.string().optional(), request_id: z.string().optional(), video_b64: z.string().optional(), mesh_video_b64: z.string().optional(), snapshots_b64: z.array(z.string()).optional(), model_b64: z.string().optional(), binary_data_b64: z.string().optional(), voxels_b64: z.string().optional(), mask_snapshots_b64: z.array(z.string()).optional(), depth_snapshots_b64: z.array(z.string()).optional(), normal_snapshots_b64: z.array(z.string()).optional(), textured: z.boolean().optional(), view_azimuths: z.array(z.number()).optional(), generation_model: z.string().optional(), generation_parameters: threeDGenerationParameters.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 }; /** * Retopologizes a 3D model (Roles: user) * * POST /games/generate/retopology */ export const createApiGamesGenerateRetopology = async (args: CreateApiGamesGenerateRetopologyArgs, options: CreateApiGamesGenerateRetopologyOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/games/generate/retopology${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(assetGeneration, await res.json()) };