From be119a26c813a3e5a6ac888343fc9ad314baa246 Mon Sep 17 00:00:00 2001 From: Dirlligafu Date: Mon, 13 Jul 2026 20:15:05 +1100 Subject: [PATCH] Fan-triangulate quad and n-gon faces when parsing OBJ files OBJ exports without a Triangulate step contain faces with more than 3 vertices. The manual OBJ parser stored them as-is, so building the numpy face array later failed with an inhomogeneous shape error since it expected every face to have the same length. --- model_loader.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/model_loader.py b/model_loader.py index aa192de..ac84d77 100644 --- a/model_loader.py +++ b/model_loader.py @@ -100,7 +100,14 @@ def _parse_obj_groups(path): uv_ambiguous += 1 else: vertex_uv[v_idx] = vt_idx - groups[current].append(idx) + if len(idx) < 3: + continue + # Fan-triangulate quads/n-gons: exported OBJs without a + # "Triangulate" step mix face vertex counts, which crashes + # np.array(all_faces) downstream with an inhomogeneous-shape + # error since it expects every face to have the same length. + for i in range(1, len(idx) - 1): + groups[current].append([idx[0], idx[i], idx[i + 1]]) if not groups.get("(ungrouped)"): groups.pop("(ungrouped)", None)