Skip to content

fix: filter out NaN vertices from IFC geometry#196

Open
TeapoyY wants to merge 2 commits intoThatOpen:mainfrom
TeapoyY:fix/nan-bounding-sphere
Open

fix: filter out NaN vertices from IFC geometry#196
TeapoyY wants to merge 2 commits intoThatOpen:mainfrom
TeapoyY:fix/nan-bounding-sphere

Conversation

@TeapoyY
Copy link
Copy Markdown

@TeapoyY TeapoyY commented Apr 6, 2026

Summary

When loading certain IFC files, the web-ifc parser can produce geometry with NaN position values. This causes Three.js to throw computeBoundingSphere(): Computed radius is NaN when the geometry's bounding sphere is computed, crashing the application.

This fix adds a NaN check in ifcGeometryToBuffer():

  1. First pass: identify vertices with NaN position coordinates
  2. Fast path: if all vertices are valid (no NaN), use the original code unchanged — zero overhead for well-formed files
  3. Slow path: if NaN vertices are found, filter them out and remap the index buffer to exclude any triangles that reference invalid vertices

The Bug

Issue: #88

When loading an IFC file with malformed geometry data (e.g., from ifc2.zip attached to the issue), the vertex positions contain NaN values. When Three.js tries to compute the bounding sphere for rendering, it gets NaN for the radius and throws an uncaught error.

The Fix

In IFCParser.ifcGeometryToBuffer(), after extracting the vertex data from web-ifc:

  • Check each vertex's (x, y, z) position values using Number.isFinite()
  • Build a validity flag array and count of valid vertices
  • If all valid: use the original code unchanged
  • If any invalid: build a remapping from old vertex indices to new compact indices, construct new compact position/normal/id arrays, and a new index buffer that only references valid vertices (dropping degenerate triangles)

Bounty

This PR addresses #88 (labeled: bounty)

TeapoyY added 2 commits April 6, 2026 08:24
… message

Previously, when a user tried to load a JSON file (produced by the
ifc-to-json tool) using IFCLoader.load(), the loader would attempt
to parse it as a binary IFC file, resulting in a cryptic 'File too
small' error from web-ifc.

This change adds detection of .json URLs at the start of the load()
method and throws a clear, actionable error message explaining:
1. That .json files cannot be loaded directly
2. That JSON files from ifc-to-json only contain property data,
   not geometry
3. That users should load the IFC file normally and then use
   addModelJSONData() for property data
4. A link to the documentation for the correct workflow

Fixes ThatOpen#136 (bounty)
…dingSphere NaN error

When loading certain IFC files, the web-ifc parser can produce geometry
with NaN position values. This causes Three.js to throw
'computeBoundingSphere(): Computed radius is NaN' when the geometry's
bounding sphere is computed.

This fix adds a NaN check in ifcGeometryToBuffer():
1. First pass: identify vertices with NaN position coordinates
2. Fast path: if all vertices are valid, use the original code
3. Slow path: filter out invalid vertices and remap the index buffer
   to exclude triangles that reference invalid vertices

Fixes ThatOpen#88 (bounty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant