Page MenuHome

Geometry Nodes: Fix Face is Planar Normal Comparison
ClosedPublic

Authored by Johnny Matthews (guitargeek) on Jun 9 2022, 5:40 PM.

Details

Summary

Take the absolute value of the dot product between the reference normal and each point. That way there is not an issue if the reference normal becomes negative.

Diff Detail

Repository
rB Blender

Event Timeline

Johnny Matthews (guitargeek) requested review of this revision.Jun 9 2022, 5:40 PM
Johnny Matthews (guitargeek) created this revision.

This doesn't really solve the problem. The issue is that the dot product as it stands will calculate distance from the object center wrt. the optimal plane. Instead we need to compute the distance from the polygon centroid:

diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
index c400760f902..b32f1f44beb 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
@@ -63,13 +63,16 @@ class PlanarFieldInput final : public GeometryFieldInput {
       const int loops = mesh->mpoly[i_poly].totloop;
       Span<MLoop> poly_loops(&mesh->mloop[loopstart], loops);
       float3 reference_normal = poly_normals[i_poly];
+      float3 poly_center;
+      BKE_mesh_calc_poly_center(
+          &mesh->mpoly[i_poly], &mesh->mloop[loopstart], mesh->mvert, poly_center);

       float min = FLT_MAX;
       float max = FLT_MIN;

       for (const int i_loop : poly_loops.index_range()) {
         const float3 vert = mesh->mvert[poly_loops[i_loop].v].co;
-        float dot = math::dot(reference_normal, vert);
+        float dot = math::dot(reference_normal, vert - poly_center);
         if (dot > max) {
           max = dot;
         }

source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
68

The issue is probably that this is not -FLT_MAX.

The issue is that the dot product as it stands will calculate distance from the object center wrt. the optimal plane. Instead we need to compute the distance from the polygon centroid.

Afaik, this is wrong. You should be able to add any constant vector to vert without changing the result (so subtracting poly_center does not make a difference). Also see the discussion in D13906.

  • Merge branch 'master' into fix_planar
  • Use -FLT_MAX rather than FLT_MIN for initial comparison values.

You should be able to add any constant vector to vert without changing the result

You're right, i didn't realize it compares the range and not min/max separately.

This revision is now accepted and ready to land.Jun 14 2022, 6:10 PM