Skip to content

[Bugs] ifc-converter: unit fallback normal, typed-array recompute, count recomputed normals - #1165

Merged
Aymericr merged 1 commit into
mainfrom
cursor/ifc-normal-recompute-followups-31b3
Oct 27, 2026
Merged

Aymericr merged 1 commit into
mainfrom
cursor/ifc-normal-recompute-followups-31b3

Conversation

@Aymericr

@Aymericr Aymericr commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #1160.

  • A vertex whose adjacent faces have no area now gets the unit normal (0,0,1) instead of [0,0,0].
  • The recompute sums into a Float64Array, with an Int32Array mapping vertices to slots. The new bun run bench:normals (a 1M-triangle grid with every normal NaN) runs in 169 ms vs 445 ms before.
  • report.replaced.normals counts recomputed normals. It doesn't count as a conversion issue.

Tests in imported-mesh-conversion.test.ts: degenerate geometry gets (0,0,1) normals, and the all-NaN test checks the count and that recomputed normals match web-ifc's on flat faces. Both fail on the old code. All 104 converter tests pass.

…omputed normals

- A recomputed normal whose faces have no area is (0, 0, 1), not a zero
  vector that leaves the vertex unlit.
- The recompute accumulates in a Float64Array indexed through an Int32Array
  slot map instead of a Map of arrays (__bench__/normal-recompute.bench.ts,
  bun run bench:normals).
- report.replaced.normals counts the normals recomputed. It stays out of
  conversionReportHasIssues: shading only, nothing left out.
@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-27T01:23:53.926319Z 4247ecb 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 review: looks good to me. The typed-array slot map is a clean swap for the Map, the (0,0,1) fallback is a sensible fix for zero-area vertices, and counting recomputed normals without flagging them as issues is the right call. Tests cover both new behaviors.

One small nit, not blocking: src/__bench__/normal-recompute.bench.ts uses the Bun global and sits under src/, so check that tsc --build doesn't type-check or emit it into the published package. Moving it next to tests/ or excluding __bench__ in tsconfig would avoid that.

No visible UI change, so no screenshots needed. I can't approve this one since it's opened from the same account, so it's good to merge once CI is green and another bot signs off.

@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 4247ecb

Approved at 4247ecb.

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

Fallback condition (packages/ifc-converter/src/geometry-validity.ts:186)

length > 0 ? [x/length, …] : FALLBACK_NORMAL applies (0,0,1) when the accumulated sum has zero length, i.e. every adjacent face has zero area, or when the length is NaN, since NaN > 0 is false. It never applies to a vertex with a usable sum, and it only runs for vertices whose input normal was non-finite (slotOf[vertex] >= 0). Valid input normals are untouched.

One edge case (non-blocking). If the sum is finite but its Math.hypot overflows to Infinity, which needs coordinate differences around 1e154 or more, then length > 0 is true, every x / Infinity is 0, and the vertex gets [0,0,0] rather than the fallback. I reproduced this with a triangle at 1e200. Real IFC data won't get there, but Number.isFinite(length) && length > 0 would make the fallback cover it.

Typed arrays and index math

  • slotOf = new Int32Array(vertexCount) (:151). vertexCount = positions.length / 3 is an integer on the compacted buffers. Slots are 0 … broken - 1, so they're < vertexCount, well inside Int32 for any mesh that fits in memory.
  • sums = new Float64Array(broken * 3) (:156) is exactly sized, with one triple per broken vertex.
  • All index arithmetic (slot * 3, a * 3 + k) is done in JS doubles on values read from the arrays, not in Int32 storage, so nothing overflows. Corner indices all come from the compacted indices, which are < vertexCount.

Matches the old implementation

I ran the #1160 implementation and this one side by side on 50 random shared-vertex meshes: 100k vertices, about 30% NaN normals, and about 5% degenerate triangles. Every non-degenerate vertex was bit-identical, since the summation order and the divide-then-round are unchanged. The only differences were the 98 zero-length cases, which went from [0,0,0] to (0,0,1), as intended. The new flat-face test (normalsOf(broken) == normalsOf(clean)) confirms the same against real web-ifc output.

Count

  • report.replaced.normals += recomputeNonFiniteNormals(…) (:125) counts each recomputed vertex once. It's deliberately left out of conversionReportHasIssues, which is right because nothing is lost.
  • It's surfaced in the returned IfcConversionReport, so hosts that record report.replaced get it.
  • It's tested: 0 on the clean conversion, at least the kept vertex count on the all-NaN conversion, and at least the normal count in the degenerate test. The >= bounds are loose, presumably because pieces can be recomputed and then dropped later. An exact toBe on a small handcrafted mesh through keepValidTriangles would pin the count precisely. Optional.

Tests and bench

The fallback test collapses every vertex to one point with NaN normals and asserts (0,0,1) everywhere. That fails on the old zero output. bench:normals lives under src/__bench__, so make sure the package's tsc --build / publish files don't ship it, or move it beside tests/. Non-blocking.

No merge from me.

@Aymericr
Aymericr merged commit c76f541 into main Oct 27, 2026
4 checks passed
@Aymericr
Aymericr deleted the cursor/ifc-normal-recompute-followups-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