[Bf-blender-cvs] [99b9417f428] soc-2021-adaptive-cloth: adaptive_cloth: Mesh: compute face normal(s)

ishbosamiya noreply at git.blender.org
Sun Aug 22 17:23:37 CEST 2021


Commit: 99b9417f42890e1c9a8f4c78e7b2ad0e858e535a
Author: ishbosamiya
Date:   Tue Aug 10 22:07:58 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB99b9417f42890e1c9a8f4c78e7b2ad0e858e535a

adaptive_cloth: Mesh: compute face normal(s)

===================================================================

M	source/blender/blenkernel/BKE_cloth_remesh.hh

===================================================================

diff --git a/source/blender/blenkernel/BKE_cloth_remesh.hh b/source/blender/blenkernel/BKE_cloth_remesh.hh
index 062b3aa0209..9a28f039608 100644
--- a/source/blender/blenkernel/BKE_cloth_remesh.hh
+++ b/source/blender/blenkernel/BKE_cloth_remesh.hh
@@ -595,6 +595,11 @@ template<typename T> class Face {
     return this->self_index;
   }
 
+  const auto &get_normal() const
+  {
+    return this->normal;
+  }
+
   void set_extra_data(T extra_data)
   {
     this->extra_data = extra_data;
@@ -2429,6 +2434,36 @@ template<typename END, typename EVD, typename EED, typename EFD> class Mesh {
                     std::move(deleted_faces));
   }
 
+  float3 compute_face_normal(const Vert<EVD> &v1, const Vert<EVD> &v2, const Vert<EVD> &v3) const
+  {
+    const auto &n1 = this->get_checked_node_of_vert(v1);
+    const auto &n2 = this->get_checked_node_of_vert(v2);
+    const auto &n3 = this->get_checked_node_of_vert(v3);
+
+    return float3::cross(n2.pos - n1.pos, n3.pos - n1.pos).normalized();
+  }
+
+  /**
+   * Takes the first 3 verts to compute the face normal
+   */
+  void compute_face_normal(Face<EFD> &face)
+  {
+    BLI_assert(face.get_verts().size() >= 3);
+
+    const auto &v1 = this->get_checked_vert(face.get_verts()[0]);
+    const auto &v2 = this->get_checked_vert(face.get_verts()[1]);
+    const auto &v3 = this->get_checked_vert(face.get_verts()[2]);
+
+    face.normal = this->compute_face_normal(v1, v2, v3);
+  }
+
+  void compute_face_normal_all_faces()
+  {
+    for (auto &face : this->get_faces_mut()) {
+      this->compute_face_normal(face);
+    }
+  }
+
   std::string serialize() const
   {
     std::stringstream ss;



More information about the Bf-blender-cvs mailing list