Skip to content

Fixes misaligned SDF grid#11

Open
Shardj wants to merge 1 commit into
wang-ps:masterfrom
Shardj:master
Open

Fixes misaligned SDF grid#11
Shardj wants to merge 1 commit into
wang-ps:masterfrom
Shardj:master

Conversation

@Shardj

@Shardj Shardj commented May 16, 2026

Copy link
Copy Markdown

This fixes an off-by-one alignment issue in the SDF grid coordinate mapping.

The API documents input vertices as being in [-1, 1], and as a result the expected a grid of size samples should span that same domain. However, the C++ binding used dx = 2.0f / size with origin (-1, -1, -1), so the sampled coordinates were:

-1, -1 + 2/size, ..., 1 - 2/size

The positive +1 boundary was never sampled. In practice this makes padding applied to the mesh asymmetric: geometry aligned with the negative side of an axis gets the expected margin, while geometry aligned with the positive side is one grid interval short. When mapping the SDF grid coordinates back to world space it then also resulted in a misalignment between the position and size of the mesh and the position and size of the surface described by the SDF grid.

This PR changes the spacing to 2.0f / (size - 1), treating size as the number of samples rather than the number of intervals, so the grid samples now use the full [-1,1] range. Spanning:

-1, -1 + 2/(size - 1), ..., 1

The fix=True marching-cubes voxel-coordinate normalization is updated the same way, keeping the reconstructed mesh in the same coordinate frame as the SDF grid.

@Shardj

Shardj commented May 16, 2026

Copy link
Copy Markdown
Author

Before Fix before-fix
After Fix after-fix

This one was driving me crazy haha, bunny has a tail now

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