Fix quad and n-gon OBJ/faces - Fan-triangulate - #12
Open
dirlligafu wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.