Skip to content

Commit 1ba82cf

Browse files
fix(assimp): pass -f<format> so non-extension targets work (#557)
* fix(assimp): pass -f<format> so non-extension targets work The assimp converter invokes `assimp export <in> <out>` and relies on assimp's extension-based format inference to pick the output format. That works for targets whose id happens to match a real file extension (glb, gltf, obj, stl, ply, etc.) but silently fails for every target whose assimp id is not a conventional filename extension: glb2, gltf2, objnomtl, stlb, plyb, fbxa, assbin, assxml, pbrt, assjson Picking any of those in the UI aborts the job with: assimp export: no output format specified and I failed to guess it assimp_cmd's `-f<h>` flag overrides extension inference, and the values in `properties.to.object` already correspond 1:1 to assimp's format ids (verified against `assimp listexport`). Passing `-f${convertTo}` makes every advertised target work without changing anything else. Reproduction: upload any .stl, convert to glb2. Before: ENOENT on the nonexistent output file. After: valid binary glTF 2.0. * fix(assimp): write real file extensions for non-extension format ids Follow-up to the previous commit. With `-f<format>` now passed to assimp, every advertised target exports successfully — but seven of them still produce files with assimp's internal format id as the extension, which no third-party viewer recognises: glb2 → .glb2 (really binary glTF 2.0, should be .glb) gltf2 → .gltf2 (text glTF 2.0, should be .gltf) objnomtl → .objnomtl (OBJ without .mtl, should be .obj) stlb → .stlb (binary STL, should be .stl) plyb → .plyb (binary PLY, should be .ply) fbxa → .fbxa (ASCII FBX, should be .fbx) assjson → .assjson (JSON dump, should be .json) Map these in `normalizeOutputFiletype`, the same helper that already handles jpeg→jpg, latex→tex, markdown→md. The format id on `convertTo` is untouched, so `assimp -f<id>` still selects the correct encoding/variant — only the output filename changes. assbin, assxml, and pbrt are both the format id and the canonical extension, so they need no mapping. * style(assimp): fix prettier formatting
1 parent 70fcc84 commit 1ba82cf

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

src/converters/assimp.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,24 @@ export async function convert(
121121
execFile: ExecFileFn = execFileOriginal, // to make it mockable
122122
): Promise<string> {
123123
return new Promise((resolve, reject) => {
124-
execFile("assimp", ["export", filePath, targetPath], (error, stdout, stderr) => {
125-
if (error) {
126-
reject(`error: ${error}`);
127-
}
124+
execFile(
125+
"assimp",
126+
["export", filePath, targetPath, `-f${convertTo}`],
127+
(error, stdout, stderr) => {
128+
if (error) {
129+
reject(`error: ${error}`);
130+
}
128131

129-
if (stdout) {
130-
console.log(`stdout: ${stdout}`);
131-
}
132+
if (stdout) {
133+
console.log(`stdout: ${stdout}`);
134+
}
132135

133-
if (stderr) {
134-
console.error(`stderr: ${stderr}`);
135-
}
136+
if (stderr) {
137+
console.error(`stderr: ${stderr}`);
138+
}
136139

137-
resolve("Done");
138-
});
140+
resolve("Done");
141+
},
142+
);
139143
});
140144
}

src/helpers/normalizeFiletype.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ export const normalizeOutputFiletype = (filetype: string): string => {
3131
case "markdown_mmd":
3232
case "markdown":
3333
return "md";
34+
// assimp format ids that aren't real file extensions — map to the
35+
// canonical extension for the underlying format so the output file
36+
// opens in third-party viewers. The format id is still passed to
37+
// `assimp export -f<id>` so the right encoding/variant is produced.
38+
case "glb2":
39+
return "glb";
40+
case "gltf2":
41+
return "gltf";
42+
case "objnomtl":
43+
return "obj";
44+
case "stlb":
45+
return "stl";
46+
case "plyb":
47+
return "ply";
48+
case "fbxa":
49+
return "fbx";
50+
case "assjson":
51+
return "json";
3452
default:
3553
return lowercaseFiletype;
3654
}

0 commit comments

Comments
 (0)