The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Retexture: 800 characters of style words, WebP style pictures up to 20 MB, new UVs for a model without them
Adarsh0431a1cc93cc
diff --git a/src/components/model3d/retexture-dialog.tsx b/src/components/model3d/retexture-dialog.tsxindex b45b0d40..7b8af945 100644--- a/src/components/model3d/retexture-dialog.tsx+++ b/src/components/model3d/retexture-dialog.tsx@@ -1,7 +1,7 @@"use client";import { ImagePlus, Loader2, Paintbrush, X } from "lucide-react";-import { useRef, useState } from "react";+import { useEffect, useRef, useState } from "react";import { toast } from "sonner";import { OwnSetupNote } from "@/components/own-setup";import { Button } from "@/components/ui/button";@@ -10,7 +10,17 @@ import { Label } from "@/components/ui/label";import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";import { Textarea } from "@/components/ui/textarea";import { uploadFile } from "@/lib/api";-import { MODEL3D_KEY, RETEXTURE_MODELS, RETEXTURE_PROMPT_MAX, RETEXTURE_SIZES, retextureRequest, type RetextureModel } from "@/lib/av/model3d";+import {+ glbHasUv,+ MODEL3D_KEY,+ RETEXTURE_MODELS,+ RETEXTURE_PROMPT_MAX,+ RETEXTURE_SIZES,+ RETEXTURE_STYLE_MAX_BYTES,+ RETEXTURE_STYLE_TYPES,+ retextureRequest,+ type RetextureModel,+} from "@/lib/av/model3d";import { toastError } from "@/lib/refusals";import { priceLine, useCreate3d, useRunPreview } from "./hooks";@@ -40,13 +50,28 @@ export function RetextureDialog({const [uploading, setUploading] = useState(false);const [model, setModel] = useState<RetextureModel>(RETEXTURE_MODELS[0].id);const [size, setSize] = useState<(typeof RETEXTURE_SIZES)[number]>("2k");+ // A model without UVs (a vertex-coloured mesh) asks for new ones; unknown keeps fal's default (the model's own).+ const [keepUv, setKeepUv] = useState<boolean | undefined>(undefined);+ useEffect(() => {+ if (!open) return;+ const ctl = new AbortController();+ fetch(glb, { headers: { Range: "bytes=0-4194303" }, signal: ctl.signal })+ .then((r) => (r.ok ? r.arrayBuffer() : Promise.reject(new Error(String(r.status)))))+ .then((b) => setKeepUv(glbHasUv(new Uint8Array(b))))+ .catch(() => setKeepUv(undefined));+ return () => ctl.abort();+ }, [glb, open]);const file = useRef<HTMLInputElement>(null);const ready = cloudAllowed && !uploading && (!!prompt.trim() || !!style);- const req = ready ? retextureRequest({ glb, prompt, style: style?.url, model, size }) : null;+ const req = ready ? retextureRequest({ glb, prompt, style: style?.url, model, size, keepUv }) : null;const preview = useRunPreview(open ? req : null);const price = priceLine(preview.data);const pickStyle = async (f: File | undefined) => {if (!f) return;+ if (f.size > RETEXTURE_STYLE_MAX_BYTES) {+ toast.error("The style picture must be 20 MB or less");+ return;+ }setUploading(true);try {const asset = await uploadFile(f);@@ -116,7 +141,7 @@ export function RetextureDialog({{uploading ? <Loader2 className="size-3.5 animate-spin" /> : <ImagePlus className="size-3.5" />} Style picture</Button>)}- <input ref={file} type="file" accept="image/png,image/jpeg" className="hidden" onChange={(e) => void pickStyle(e.target.files?.[0])} />+ <input ref={file} type="file" accept={RETEXTURE_STYLE_TYPES} className="hidden" onChange={(e) => void pickStyle(e.target.files?.[0])} /><Select value={model} onValueChange={(v) => setModel(v as RetextureModel)}><SelectTrigger size="sm" className="rounded-full" aria-label="Model"><SelectValue />diff --git a/src/lib/av/model3d.ts b/src/lib/av/model3d.tsindex 38b76ad3..97ff8d49 100644--- a/src/lib/av/model3d.ts+++ b/src/lib/av/model3d.ts@@ -601,22 +601,57 @@ export const RETEXTURE_MODELS = [{ id: "meshy-6-retexture", label: "Meshy 6" },] as const;export type RetextureModel = (typeof RETEXTURE_MODELS)[number]["id"];-/** Meshy's style prompt: "Maximum 600 characters". */-export const RETEXTURE_PROMPT_MAX = 600;+/** Meshy's style prompt: "Maximum 800 characters" (fal's schema and Meshy's own API, 2026-11-06). */+export const RETEXTURE_PROMPT_MAX = 800;export const RETEXTURE_SIZES = ["2k", "4k", "8k"] as const;+/** fal's image_style_url: max_file_size 20 MB; .jpg, .jpeg, .png or .webp. */+export const RETEXTURE_STYLE_MAX_BYTES = 20 * 1024 * 1024;+export const RETEXTURE_STYLE_TYPES = "image/png,image/jpeg,image/webp";-/** Retexture a finished model: the words, or a style picture (which wins when both go), at a texture size. */-export function retextureRequest(o: { glb: string; prompt?: string; style?: string; model?: RetextureModel; size?: (typeof RETEXTURE_SIZES)[number] }): GenerationRequest {+/**+ * Retexture a finished model: the words, or a style picture (which wins when both go), at a texture size. keepUv false+ * (a model without UVs, glbHasUv) asks Meshy for new UVs: fal keeps the model's own by default, and says "If the model+ * has no original UV, output quality may be reduced".+ */+export function retextureRequest(o: {+ glb: string;+ prompt?: string;+ style?: string;+ model?: RetextureModel;+ size?: (typeof RETEXTURE_SIZES)[number];+ keepUv?: boolean;+}): GenerationRequest {+ const extra = { ...(o.size && o.size !== "2k" && { texture_resolution: o.size }), ...(o.keepUv === false && { enable_original_uv: false }) };return {feature: MODEL3D_FEATURE,modelId: o.model ?? RETEXTURE_MODELS[0].id,op: "retexture-3d",prompt: (o.prompt ?? "").trim().slice(0, RETEXTURE_PROMPT_MAX),inputs: { model3d: o.glb, ...(o.style && { images: [o.style] }) },- ...(o.size && o.size !== "2k" && { params: { extra: { texture_resolution: o.size } } }),+ ...(Object.keys(extra).length > 0 && { params: { extra } }),};}+/**+ * Whether a GLB's meshes carry UVs (TEXCOORD_0 on every primitive), read from its JSON chunk; undefined when the bytes+ * are not a GLB 2.0 file or stop before the chunk ends (the first bytes of a large file).+ */+export function glbHasUv(bytes: Uint8Array): boolean | undefined {+ if (bytes.length < 20) return undefined;+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);+ if (view.getUint32(0, true) !== 0x46546c67 || view.getUint32(4, true) !== 2) return undefined; // "glTF", version 2+ const length = view.getUint32(12, true);+ if (view.getUint32(16, true) !== 0x4e4f534a || 20 + length > bytes.length) return undefined; // "JSON"+ let doc: { meshes?: { primitives?: { attributes?: Record<string, unknown> }[] }[] };+ try {+ doc = JSON.parse(new TextDecoder().decode(bytes.subarray(20, 20 + length)));+ } catch {+ return undefined;+ }+ const prims = (doc.meshes ?? []).flatMap((m) => m.primitives ?? []);+ return prims.length > 0 && prims.every((p) => !!p.attributes && "TEXCOORD_0" in p.attributes);+}+/** What Make it 3D (quick) on an image result does: shown in the studio with the picture handed over (never "2 s"). */export const MAKE_3D_HINT = "Turns this picture into a 3D splat on your GPU and renders a turning preview. Takes tens of seconds on a consumer GPU.";diff --git a/tests/hosted-catchup.test.ts b/tests/hosted-catchup.test.tsindex 363a9725..066a827c 100644--- a/tests/hosted-catchup.test.ts+++ b/tests/hosted-catchup.test.ts@@ -192,7 +192,7 @@ describe("payloads match the stored schemas", () => {const { plan, payload } = payloadFor(req.modelId, req);expect(plan.op).toBe("retexture-3d");expect(payload).toMatchObject({ model_url: GLB, text_style_prompt: "weathered bronze", image_style_url: IMG, texture_resolution: "4k", enable_pbr: true });- expect(retextureRequest({ glb: GLB, prompt: "x".repeat(900) }).prompt).toHaveLength(600);+ expect(retextureRequest({ glb: GLB, prompt: "x".repeat(900) }).prompt).toHaveLength(800);expect(RETEXTURE_MODELS.map((m) => m.id)).toEqual(["meshy-7-retexture", "meshy-6-retexture"]);});diff --git a/tests/retexture-spec.test.ts b/tests/retexture-spec.test.tsnew file mode 100644index 00000000..88810fe2--- /dev/null+++ b/tests/retexture-spec.test.ts@@ -0,0 +1,65 @@+/**+ * Meshy 7 / 6 Retexture against fal's schema (meshy/v7/retexture and meshy/v6/retexture, fetched 2026-11-06):+ * - text_style_prompt: maxLength 800 ("Maximum 800 characters"; Meshy's own API: "up to 800 characters").+ * - enable_original_uv: default true; "If the model has no original UV, output quality may be reduced". A model without+ * UVs (a vertex-coloured mesh) asks for new ones.+ * - image_style_url: max_file_size 20971520; .jpg, .jpeg, .png and .webp.+ */+import { describe, expect, it } from "vitest";+import { getModel } from "@/lib/catalog";+import { buildPayload } from "@/lib/catalog/payload";+import { glbHasUv, RETEXTURE_PROMPT_MAX, RETEXTURE_STYLE_MAX_BYTES, RETEXTURE_STYLE_TYPES, retextureRequest } from "@/lib/av/model3d";+import type { FieldMap, GenInput } from "@/lib/catalog/types";++const GLB_URL = "https://v3b.fal.media/files/b/test/in.glb";+const glb = (json: object) => {+ const j = new TextEncoder().encode(JSON.stringify(json));+ const chunk = new Uint8Array(Math.ceil(j.length / 4) * 4).fill(0x20);+ chunk.set(j);+ const out = new Uint8Array(20 + chunk.length);+ const v = new DataView(out.buffer);+ v.setUint32(0, 0x46546c67, true);+ v.setUint32(4, 2, true);+ v.setUint32(8, out.length, true);+ v.setUint32(12, chunk.length, true);+ v.setUint32(16, 0x4e4f534a, true);+ out.set(chunk, 20);+ return out;+};+const body = (modelId: string, req: ReturnType<typeof retextureRequest>) => {+ const map = getModel(modelId)!.routes[0].map as FieldMap;+ return buildPayload(map, { prompt: req.prompt ?? "", model3d: req.inputs?.model3d, images: req.inputs?.images, extra: req.params?.extra } as GenInput);+};++describe("Meshy retexture follows fal's schema", () => {+ it("sends up to 800 characters of style words", () => {+ expect(RETEXTURE_PROMPT_MAX).toBe(800);+ for (const id of ["meshy-7-retexture", "meshy-6-retexture"]) {+ expect((getModel(id)!.routes[0].map as FieldMap).promptMax).toBe(800);+ const req = retextureRequest({ glb: GLB_URL, prompt: "y".repeat(900), model: id as never });+ expect(String(body(id, req).text_style_prompt)).toHaveLength(800);+ }+ });++ it("asks for new UVs only for a model without them", () => {+ expect(body("meshy-7-retexture", retextureRequest({ glb: GLB_URL, prompt: "oak", keepUv: false }))).toMatchObject({ enable_original_uv: false, enable_pbr: true });+ expect(body("meshy-7-retexture", retextureRequest({ glb: GLB_URL, prompt: "oak", keepUv: true }))).not.toHaveProperty("enable_original_uv");+ expect(body("meshy-7-retexture", retextureRequest({ glb: GLB_URL, prompt: "oak" }))).not.toHaveProperty("enable_original_uv");+ expect(body("meshy-6-retexture", retextureRequest({ glb: GLB_URL, prompt: "oak", size: "8k", keepUv: false }))).toMatchObject({ texture_resolution: "8k", enable_original_uv: false });+ });++ it("reads UVs from a GLB's JSON chunk", () => {+ expect(glbHasUv(glb({ asset: { version: "2.0" }, meshes: [{ primitives: [{ attributes: { POSITION: 0, TEXCOORD_0: 1 } }] }] }))).toBe(true);+ expect(glbHasUv(glb({ asset: { version: "2.0" }, meshes: [{ primitives: [{ attributes: { POSITION: 0, COLOR_0: 1 } }] }] }))).toBe(false);+ expect(glbHasUv(glb({ asset: { version: "2.0" }, meshes: [{ primitives: [{ attributes: { POSITION: 0, TEXCOORD_0: 1 } }, { attributes: { POSITION: 2 } }] }] }))).toBe(false);+ expect(glbHasUv(glb({ asset: { version: "2.0" } }))).toBe(false);+ // Not a GLB, or only its first bytes: unknown, so fal's default stays.+ expect(glbHasUv(new TextEncoder().encode("ply\nformat binary_little_endian 1.0\nend_header\n"))).toBeUndefined();+ expect(glbHasUv(glb({ asset: { version: "2.0" }, meshes: [] }).subarray(0, 24))).toBeUndefined();+ });++ it("takes a style picture of 20 MB or less, as PNG, JPEG or WebP", () => {+ expect(RETEXTURE_STYLE_MAX_BYTES).toBe(20_971_520);+ expect(RETEXTURE_STYLE_TYPES.split(",")).toEqual(["image/png", "image/jpeg", "image/webp"]);+ });+});