import {z} from 'zod' export type PILImage = {format?: string | undefined, format_description?: string | undefined}; export type SpritePose = {animation_prompt?: string | undefined, margin_ratio?: number | undefined, margin_ratio_mode?: string | undefined, name?: string | undefined, prompt?: string | undefined}; export type Sprite3DRender = {style_id?: string | undefined, style_version?: number | undefined, style_params?: Record | undefined, params?: Record | undefined, perspective?: string | undefined, direction?: string | undefined, animation_name?: string | undefined, motion?: Record | undefined, mirror?: boolean | undefined, fps?: number | undefined, keep_horizontal_travel?: boolean | undefined, keep_vertical_travel?: boolean | undefined, pixel_block?: number | undefined, generated_model?: Record | undefined}; export type GameImage = {tags?: Array | undefined, id?: string | undefined, image_id?: string | undefined, url?: string | undefined, type?: string | undefined, final_score?: number | undefined, nsfw_prob?: number | undefined, similarity?: number | undefined, width?: number | undefined, height?: number | undefined, game_id?: string | undefined, hosted_filename?: string | undefined, icon?: boolean | undefined, targetSize?: number | undefined, seed?: number | undefined, embedded?: boolean | undefined, analysed?: boolean | undefined, image?: string | undefined, image_type?: string | undefined, prompt?: string | undefined, motion_prompt?: string | undefined, request_id?: string | undefined, hints?: Array | undefined, selected_genres?: Array | undefined, selected_colors?: Array | undefined, selected_style?: string | undefined, selected_perspective?: string | undefined, is_safe?: boolean | undefined, platform?: string | undefined, loading?: boolean | undefined, original_hints?: Array | undefined, genres?: Array | undefined, edit_mask?: string | undefined, edit_mode?: string | undefined, camera_rotation?: number | undefined, camera_elevation?: number | undefined, edit_mask_pil_image?: PILImage | undefined, pil_image?: PILImage | undefined, nsfw?: number | undefined, pose?: SpritePose | undefined, render_3d?: Sprite3DRender | undefined, pixel_grid?: (Array | null) | undefined, pixel_size?: number | undefined, model?: string | undefined, normals?: string | undefined}; 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 ImageTo3DPayload = {request_id?: string | undefined, image?: GameImage | undefined, back_image?: GameImage | undefined, generation_parameters?: ThreeDGenerationParameters | undefined}; export type CreateApiGamesGenerateImageTo3dArgs = {body: ImageTo3DPayload}; export type CreateApiGamesGenerateImageTo3dOptions = {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 }; /** * Generates 3D models from image (Roles: user) * * POST /games/generate/image-to-3d */ export const createApiGamesGenerateImageTo3d = async (args: CreateApiGamesGenerateImageTo3dArgs, options: CreateApiGamesGenerateImageTo3dOptions) => { 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/image-to-3d${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()) };