-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDF interpolation #866
SDF interpolation #866
Conversation
Can I use this to create manifold meshes out of non manifold input? This was done in coacd via sony's vdb and also the same idea was implemented in Unreal Engine's mesh decimation tool. |
Yes, an SDF is a great way to guarantee manifoldness. Of course, making "good" output from non manifold input will always be a hard problem since it's so arbitrary. And the SDF will not retain sharp corners. So, as usual, it's all tradeoffs. |
@pca006132 this is odd - we're getting Vec out of Range errors on some of the CI bots just for |
Is there any chance this is something related to concurrency? I am a bit busy this week (for some reason I need to do a 40 minutes presentation to a bunch of random peolpe now), so it will take some time. |
Ah, seems something that can be reproduced on any machine. Will check. |
Apparently it is somewhere in
Compiling without parallelization also has this bug:
|
@pca006132 Thanks, it looks like I'm getting a few NaN verts out of smoothing, but not on my machine. I must have missed a divide-by-zero somewhere. Since you have a repro, is there a chance you can expand on the last commit I made to hunt down where the first NaN creeps in? It's a bit tedious doing a debug cycle through our CI, but that's what I'll do if you don't have a chance to look at this first. |
I think the simplest way may be to bring up a linux vm? I am outside almost everyday now so I have very limited debugging capacity |
Got some time and did some debugging. diff --git a/src/manifold/src/smoothing.cpp b/src/manifold/src/smoothing.cpp
index 2fa994cf..280de296 100644
--- a/src/manifold/src/smoothing.cpp
+++ b/src/manifold/src/smoothing.cpp
@@ -769,6 +769,10 @@ void Manifold::Impl::DistributeTangents(const Vec<bool>& fixedHalfedges) {
glm::vec3 tangent(halfedgeTangent_[current]);
halfedgeTangent_[current] = glm::vec4(
glm::rotate(tangent, angle, normal), halfedgeTangent_[current].w);
+ if (!isfinite(halfedgeTangent_[current].x)) {
+ std::cout << "angle = " << angle << ", normal = " << normal << std::endl;
+ __builtin_debugtrap();
+ }
++i;
} while (!fixedHalfedges[current]);
}); The normal is somehow zero here, which makes the rotation ill-defined and causes the tangent to become NaN. |
Thinking if automatic differentiation can be useful for computing a precise normal automatically, when users are given a set of function combinators... |
@pca006132 Thank you for narrowing that down for me! This was an existing bug, just brought to the surface by this new test. After some checking, the one-line fix should be fine. The reason the normal was zero was that the only valid tangents were exactly opposed, in which case there is nothing |
This tests out a new use-case for our smooth mesh interpolation: evaluating SDFs on a coarse grid, then smoothly interpolating them to get a cleaner shape with less computation. The SDF grid size becomes about feature extraction (what is the thinnest feature desired, etc), but the smoothness of the surface can be refined arbitrarily after the fact.
In order to not introduce wiggles to the interpolated mesh, the vertices must be very precise, so I've added a precision parameter to
LevelSet
and an improved version of bisection root-finding. This API is not final, as I'm making a follow-on PR to pullLevelSet
intoManifold
as a static constructor. It is also important to use precise normals, so I evaluated them analytically, rather than using our pseudonormal calculation.This isn't quite ready to merge, as I think I found a bug when I was playing around with the new test.
Original SDF result:

With smoothing:
