Skip to content

Fix quad and n-gon OBJ/faces - Fan-triangulate - #12

Open
dirlligafu wants to merge 1 commit into
6wheel:mainfrom
dirlligafu:fix-obj-ngon-triangulation
Open

Fix quad and n-gon OBJ/faces - Fan-triangulate#12
dirlligafu wants to merge 1 commit into
6wheel:mainfrom
dirlligafu:fix-obj-ngon-triangulation

Conversation

@dirlligafu

Copy link
Copy Markdown

What this fixes

Loading an OBJ file exported without a "Triangulate" step (containing quads or n-gons instead of only triangles) crashed with "Unexpected error loading file: setting an array element with a sequence. The requested array has an inhomogeneous shape..."

Root cause

_parse_obj_groups() stored each face's vertex indices as-is, regardless of how many vertices the face had. _load_obj_with_real_groups() then called np.array(all_faces) on that list, which requires every face to have the same length. A single quad or n-gon mixed in with triangles breaks that assumption.

Fix

Fan-triangulate any face with more than 3 vertices at parse time, so mixed-topology OBJ files load without requiring the user to
pre-triangulate in their 3D software first.

Fixes #9.

Testing

Uploaded a synthetic quad-only OBJ cube (6 quads, 8 vertices, no triangles) through the running app. It now loads correctly as 12
triangles with no error.

Note:

Checked the other import paths (.dae, .stl, .gltf/.glb, .kn5).
Only .obj can actually hit this, the rest triangulate on their own before reaching this code.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant