Skip to content

Commit

Permalink
Fix NaN halfedgeTangents (elalish#588)
Browse files Browse the repository at this point in the history
fixed CreateTangents
  • Loading branch information
elalish authored Nov 2, 2023
1 parent a842de9 commit 5930b5c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/manifold/src/smoothing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,13 @@ struct SmoothBezier {
const glm::vec3 edgeNormal =
(triNormal[edge.face] + triNormal[halfedge[edge.pairedHalfedge].face]) /
2.0f;
glm::vec3 dir = glm::normalize(glm::cross(glm::cross(edgeNormal, edgeVec),
vertNormal[edge.startVert]));
glm::vec3 dir = SafeNormalize(glm::cross(glm::cross(edgeNormal, edgeVec),
vertNormal[edge.startVert]));

const float weight = glm::abs(glm::dot(dir, glm::normalize(edgeVec)));
float weight = glm::abs(glm::dot(dir, SafeNormalize(edgeVec)));
if (weight == 0) {
weight = 1;
}
// Quadratic weighted bezier for circular interpolation
const glm::vec4 bz2 =
weight *
Expand Down
18 changes: 18 additions & 0 deletions test/sdf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,21 @@ TEST(SDF, Resize) {
EXPECT_EQ(layers.Status(), Manifold::Error::NoError);
EXPECT_EQ(layers.Genus(), -8);
}

TEST(SDF, SineSurface) {
Mesh surface(LevelSet(
[](glm::vec3 p) {
float mid = glm::sin(p.x) + glm::sin(p.y);
return (p.z > mid - 0.5 && p.z < mid + 0.5) ? 1 : 0;
},
{glm::vec3(-4 * glm::pi<float>()), glm::vec3(4 * glm::pi<float>())}, 1));
Manifold smoothed = Manifold::Smooth(surface).Refine(2);

EXPECT_EQ(smoothed.Status(), Manifold::Error::NoError);
EXPECT_EQ(smoothed.Genus(), -2);

#ifdef MANIFOLD_EXPORT
if (options.exportModels)
ExportMesh("sinesurface.glb", smoothed.GetMeshGL(), {});
#endif
}

0 comments on commit 5930b5c

Please sign in to comment.