meshfx // OBJ NGONS

How to fix n-gons in an OBJ file

You fix n-gons in an OBJ by triangulating them in your 3D editor or on export, since an OBJ f line can list any number of corners and each importer splits those faces its own way. Some split from the first corner in a fan, which breaks concave faces. Triangulate first and every program reads the same triangles.

pyrofx effects work today, and new accounts start with $5 of usage.

MODULE // meshfx AVAILABLE

meshfx measures faults, checks repairs and makes LODs for a triangle budget. meshfx runs on the hosted API: try it in the Playground.

  • f lines may list 3, 4 or more corners
  • Importers triangulate on load
  • Fan splits break concave faces

01 // WHY

How an OBJ stores an n-gon

A face line such as f 1 2 3 4 5 6 is a six-sided face. OBJ allows it, and importers turn it into triangles on load. The simplest method draws a fan from the first corner, which is fine for a convex face and wrong for an L-shaped one, where some fan triangles fall outside the face and overlap.

Because OBJ is text, you can check a file without opening an editor: count the entries on each f line.

count-ngons.js
// objText: the OBJ file as a string
const ngons = objText
  .split('\n')
  .filter((l) => l.startsWith('f ') && l.trim().split(/\s+/).length - 1 > 4).length;
console.log(ngons, 'faces with more than four corners');

02 // HOW TO

Triangulate the OBJ

  1. Find the n-gons: select faces by sides in your 3D editor, or run count-ngons.js on the file.
  2. Cut concave and non-planar faces into quads or triangles by hand.
  3. Export the OBJ with the exporter's triangulate faces option on.
  4. Check that every f line now has three entries.
  5. Import into your engine and look at the wireframe.

meshfx measures holes, flipped faces and non-manifold edges. Each repair is checked against the source and undone with a warning if it moves the surface too far. Hosted meshfx runs are available in the Playground.

04 // FAQ

OBJ n-gon questions

All questions →

README.FIX_NGONS_OBJ
Does OBJLoader in three.js handle ngons?

Yes, it splits faces with more than three corners into a fan of triangles, which breaks concave faces. Triangulate in your 3D editor first.

How do I convert ngons into clean quads or triangles before exporting an OBJ?

Cut them into quads with knife cuts where shape matters, then turn on triangulate faces in the OBJ exporter for the rest.

Can triangulating an OBJ create degenerate triangles?

Yes, when an ngon has three corners on one straight line, which is common after a boolean cut. Run a degenerate cleanup afterward.

Does Unreal Engine read OBJ ngons?

Yes. Its importer triangulates them as it builds the static mesh, so triangulate beforehand if any faces are concave.

Explore meshfx outputs

Inspect compiled meshfx outputs and their reports. Hosted meshfx runs are available in the Playground.

All effects, guides and explainers →