Skip to content

[Bugs] ifc-converter: keep geometry whose normal is NaN, recomputing the normal - #1160

Merged
Aymericr merged 1 commit into
mainfrom
cursor/ifc-keep-nan-normals-31b3
Oct 27, 2026
Merged

Aymericr merged 1 commit into
mainfrom
cursor/ifc-keep-nan-normals-31b3

Conversation

@Aymericr

@Aymericr Aymericr commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Only a non-finite position drops a vertex now. A NaN normal on a vertex that is kept gets recomputed from the faces of the surrounding kept triangles, or set to zero when those faces have no area. Until now, geometry with bad normals was dropped entirely.

Test: imported-mesh-conversion.test.ts runs convertIfcToPascalWithReport with web-ifc's GetVertexArray spied so every normal is NaN. It expects the same meshes and triangle counts as a clean conversion, with finite normals. Without the fix it fails with 1,002 vertices dropped. With the fix, all 103 converter tests pass.

keepValidTriangles dropped a vertex with a non-finite normal, and every
triangle using it, though the position was fine: a NaN normal from a
degenerate face cost real geometry. Only a non-finite position drops a vertex
now; a kept vertex's non-finite normal becomes the area-weighted normal of
the kept triangles around it (zero if they have no area).
@Aymericr Aymericr added the bot:bugs label Oct 27, 2026 — with Cursor
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T00:57:01.825685Z 0a291e5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer cross-review: looks good, approve in substance (posting as a comment because GitHub won't let this account approve its own PR).

  • Dropping only on non-finite positions and recomputing NaN normals from the kept, compacted triangles is the right split. Normals are shading, not shape.
  • Area-weighted sum with a zero fallback for degenerate faces is sound, and the || 0 avoids -0 after rounding.
  • The test spies GetVertexArray to force NaN normals and checks triangle counts match a clean conversion plus finite, unit-length normals. That covers the regression well.

No UI change, so no screenshots needed. Owner: Bugs. Merge once quality and cli-smoke are green and Bugbot/Codex come back clean.

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Maintainer] Cross-review at 0a291e5

Approved at 0a291e5.

CI at this head: quality ✅, cli-smoke ✅, Changed paths ✅, Cursor Bugbot ✅ (no findings). mergeable_state is clean.

Geometry robustness review (packages/ifc-converter/src/geometry-validity.ts)

  • Only a non-finite position drops a vertex now (finiteTriple(mesh.positions, …), :78). A non-finite normal no longer discards otherwise valid geometry.
  • Recompute (recomputeNonFiniteNormals, :135-163): it runs on the compacted buffers, so indices and positions agree, and it only touches vertices whose normal is non-finite. Valid input normals are kept as they are. It's an area-weighted sum of face cross products, which is standard.
  • Degenerate / zero-area faces: a collinear triangle contributes a zero cross product. A vertex whose faces are all zero-area gets length 0, and the normal falls back to [0,0,0] (:161). The || 0 also turns NaN and -0 into 0, so if the cross product overflows (finite but huge coordinates, giving Infinity/Infinity) the result is still 0 rather than NaN. I checked these cases numerically: right triangle → (0,0,1), collinear → zeros, 1e200 coordinates → zeros, and no NaN is left in any case.
  • Isolated vertices: after compaction, only vertices referenced by a kept triangle are emitted (:86-120), so a vertex with no faces can't reach the recompute.
  • Normalization: the sum is divided by its Math.hypot and rounded to 3 decimals, which matches the existing normal precision, so the length is within ±0.001 of 1.
  • Test: it spies GetVertexArray to give every vertex a NaN normal, asserts the same per-mesh triangle counts as a clean conversion, zero skipped vertices, and finite normals with length ≤ 1.001. It fails without the fix (1,002 vertices dropped).

Non-blocking notes

  1. Zero-normal fallback (:161). A [0,0,0] normal is NaN-free, and in practice it only occurs on vertices whose faces all have zero area, which rasterize nothing. Shaders that normalize() it are undefined, though. A fixed unit fallback such as (0,0,1) would be safer if one of those vertices is ever shared with visible faces. The test could also assert length > 0 for non-degenerate meshes.
  2. Performance on large meshes (:141-157). The Map lookups plus the per-triangle [a,b,c], face and [a,b,c] corner arrays allocate on the hot path. In a quick local benchmark (Node, 1M triangles, every normal NaN), this version took about 2.1 s. The same algorithm with a Uint8Array broken-mask and a Float64Array(vertexCount * 3) accumulator took about 0.28 s. That only matters in the worst case, since meshes with no bad normals exit after one O(V) scan, but it would help on mobile.
  3. Reporting. Recomputed normals aren't counted anywhere in the report now. A recomputedNormals count would keep this visible in diagnostics without showing the user a notice.

No merge from me.

@Aymericr
Aymericr merged commit 4151f91 into main Oct 27, 2026
4 checks passed
@Aymericr
Aymericr deleted the cursor/ifc-keep-nan-normals-31b3 branch October 27, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants