Fix vertical slice artifacts in mesh voxelization#323
Open
meet-brad-ch wants to merge 1 commit intoProjectPhysX:masterfrom
Open
Fix vertical slice artifacts in mesh voxelization#323meet-brad-ch wants to merge 1 commit intoProjectPhysX:masterfrom
meet-brad-ch wants to merge 1 commit intoProjectPhysX:masterfrom
Conversation
Add small jitter (0.1%) to ray origins to avoid coplanarity
|
I also faced this problem. Thank you for your solution, Brad. |
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.
Fix: STL Voxelization Artifacts (Vertical Slices)
Problem
When voxelizing STL meshes with regular grid structures (e.g., terrain generated from height maps), vertical slice artifacts appear in the voxelized output. These manifest as missing voxels forming vertical gaps through the geometry.
Root Cause
The
voxelize_meshkernel uses ray-triangle intersection (Moeller-Trumbore algorithm) to determine if voxels are inside or outside the mesh. The algorithm becomes numerically unstable when rays align exactly with mesh vertices or edges.For meshes with regular grid topology (common in terrain/heightmap data), ray origins often fall exactly on vertex planes, causing:
Solution
Add a small jitter (0.1% of voxel size) to ray origins perpendicular to the ray direction. This ensures rays never start exactly on mesh vertex planes while maintaining voxelization accuracy.
Code Change
File:
src/kernel.cpp(invoxelize_meshkernel)How It Works
(direction!=N)masksTesting
Tested with
hill.stlterrain mesh (421 Y-aligned planes, regular grid structure):Notes