Fix cap vertex normals of oblique IfcExtrudedAreaSolid#2054
Open
cvillagrasa wants to merge 1 commit into
Open
Conversation
Cap faces always lie in planes parallel to the profile plane, but the extrusion tessellator stored the extrusion direction as their vertex normal, which is only correct for perpendicular extrusions. Oblique extrusions (schema-legal per ValidExtrusionDirection) rendered with mis-shaded caps since 0.0.52, when the fuzzybools normalization round-trip that used to rebuild normals from positions was removed. Compute the cap normal from the outer profile contour with Newell's method, oriented along the extrusion direction for the top cap and against it for the bottom cap; a cutting-plane-projected bottom cap uses the cutting plane's normal. Adds a spec with an inline two-box model (perpendicular and oblique) asserting stored vertex normals match geometric triangle normals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed the roof of the IfcOpenHouse model shading not correct at the vertical eave faces. The roof there is an
IfcExtrudedAreaSolidwith anExtrudedDirectionnot perpendicular to the profile plane. I see that it happens both with the original file by Thomas Krijnen, already bundled in this repo intests/ifcfiles/public/IfcOpenHouse_IFC4.ifc, and with another version I did with the ifcopenshell API.It seems that the cause is that the extrusion tessellator stores the extrusion direction as the vertex normal of both cap faces. The caps of an extrusion lie in planes parallel to the profile plane regardless of the direction, so this is only correct when the extrusion is perpendicular, not for a 45° oblique roof.
The following lines reproduce the issue:
Bisecting the npm releases: up to 0.0.51 render correctly, 0.0.52 onwards do not. The tessellator has always written
diras the cap normal, but until 0.0.52 every mesh was round-tripped throughfuzzybools::Geometry::Normalize, which rebuilt vertex normals from triangle positions and silently corrected the caps. Commit 97714b4 removed that round-trip while fixing #664 and #597, and the raw tessellator cap normals became visible.In this PR, in
bimGeometry::Extrude(src/cpp/web-ifc/geometry/operations/bim-geometry/utils.h):cuttingPlaneNormalprovided), that plane's normal is used instead, also oriented against the extrusion direction.Side faces are unaffected, since they already compute geometric normals via
AddFace(a, b, c). Vertex positions, indices and transformations are untouched.tests/functional/ExtrusionCapNormals.spec.tsloads the fixture (one perpendicular box, one oblique box) and asserts that every stored vertex normal matches the geometric triangle normal. The oblique case fails before this change (minDot = 0.7071) and passes after (minDot = 1.0). The perpendicular case passes before and after. IfcOpenHouse roofs also come out exact (dot = 1.0on all triangles) with the fix.