Add local Draco optimization for GLB uploads

This commit is contained in:
CODEX
2026-06-24 21:56:32 +03:00
parent 376a4237fa
commit d601058b3f
14 changed files with 4368 additions and 14 deletions
+20 -4
View File
@@ -95,6 +95,7 @@ const CONVERTIBLE_MODEL_FORMATS = new Map([
[".step", "step"],
[".stp", "step"]
]);
const GLB_DRACO_OPTIMIZABLE_FORMATS = new Set(["glb"]);
const nowIso = () => new Date().toISOString();
@@ -2593,8 +2594,22 @@ const handleRawUpload = async (req, res, url) => {
const uploadedAt = nowIso();
const sha256 = await calculateFileSha256(targetPath);
const src = path.join("uploads", uploadId, assetId, versionId, safeName).replace(/\\/g, "/");
const rawSourceFormat = path.extname(safeName).replace(/^\./, "").toLowerCase();
const sourceFormat = CONVERTIBLE_MODEL_FORMATS.get(path.extname(safeName).toLowerCase());
const reusableOriginal = await findReusableOriginalBySha256({sha256, sourceFormat, targetPath});
const modelSourceFormat = sourceFormat || rawSourceFormat || "file";
const dracoOptimization = !sourceFormat && GLB_DRACO_OPTIMIZABLE_FORMATS.has(modelSourceFormat)
? {
status: "queued",
targetFormat: "gltf",
compression: "draco",
updatedAt: uploadedAt
}
: null;
const reusableOriginal = await findReusableOriginalBySha256({
sha256,
sourceFormat: modelSourceFormat === "file" ? null : modelSourceFormat,
targetPath
});
const sourceDedup = reusableOriginal
? {
sourceDedupMode: await linkOrCopyUploadFile(reusableOriginal.sourcePath, targetPath),
@@ -2613,10 +2628,12 @@ const handleRawUpload = async (req, res, url) => {
sha256,
sourceSrc: src,
downloadSrc: src,
sourceFormat: sourceFormat || path.extname(safeName).replace(/^\./, "").toLowerCase() || "file",
sourceFormat: modelSourceFormat,
status: sourceFormat ? "conversion_required" : "ready",
targetFormat: sourceFormat ? "xkt" : null,
targetFormat: sourceFormat ? "xkt" : (dracoOptimization ? "gltf" : null),
uploadedAt,
message: dracoOptimization ? "Model is ready. Draco optimization queued." : "Model is ready.",
...(dracoOptimization ? {dracoOptimization} : {}),
...(sourceDedup || {})
};
@@ -2658,7 +2675,6 @@ const handleRawUpload = async (req, res, url) => {
await writeJSONFile(manifestPathForSource(targetPath), {
...versionRecord,
message: "Model is ready.",
updatedAt: uploadedAt
});
await upsertAssetVersion(assetDir, versionRecord);