Repository navigation
[Bugs] ifc-converter: unit fallback normal, typed-array recompute, count recomputed normals - #1165
Conversation
…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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Aymericr
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
[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 / 3is an integer on the compacted buffers. Slots are0 … 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 compactedindices, 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 ofconversionReportHasIssues, which is right because nothing is lost.- It's surfaced in the returned
IfcConversionReport, so hosts that recordreport.replacedget 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 exacttoBeon a small handcrafted mesh throughkeepValidTriangleswould 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.
Follow-up to #1160.
Float64Array, with anInt32Arraymapping vertices to slots. The newbun run bench:normals(a 1M-triangle grid with every normal NaN) runs in 169 ms vs 445 ms before.report.replaced.normalscounts 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.