[Bf-blender-cvs] [ba82bc87aa5] soc-2021-adaptive-cloth: adaptive_cloth: AdaptiveMesh: collapse edge: face inversion test
ishbosamiya
noreply at git.blender.org
Sun Aug 22 17:23:38 CEST 2021
Commit: ba82bc87aa5ea45a58d24b6fa5f646b682dbbdbc
Author: ishbosamiya
Date: Wed Aug 11 12:35:02 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rBba82bc87aa5ea45a58d24b6fa5f646b682dbbdbc
adaptive_cloth: AdaptiveMesh: collapse edge: face inversion test
An edge is collapsible only if it doesn't invert any faces.
===================================================================
M source/blender/blenkernel/BKE_cloth_remesh.hh
M source/blender/blenkernel/intern/cloth_remesh.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_cloth_remesh.hh b/source/blender/blenkernel/BKE_cloth_remesh.hh
index 2dc5a7f43af..e66dfd7655c 100644
--- a/source/blender/blenkernel/BKE_cloth_remesh.hh
+++ b/source/blender/blenkernel/BKE_cloth_remesh.hh
@@ -1285,6 +1285,18 @@ template<typename END, typename EVD, typename EED, typename EFD> class Mesh {
return res;
}
+ /**
+ * A "3D edge" is the set of all edges between 2 nodes. An edge
+ * stores the edge verts, these are used to find the edge nodes and
+ * all connecting edge indicies between the edge nodes constitute
+ * the 3D edge.
+ */
+ blender::Vector<EdgeIndex> get_checked_3d_edge(const Edge<EED> &edge) const
+ {
+ const auto [n1, n2] = this->get_checked_nodes_of_edge(edge);
+ return this->get_connecting_edge_indices(n1, n2);
+ }
+
/**
* Gives first vert index of face that is not part of edge.
* This should be called only when the face has 3 verts, will return
diff --git a/source/blender/blenkernel/intern/cloth_remesh.cc b/source/blender/blenkernel/intern/cloth_remesh.cc
index 79158bd6eef..16d58f69092 100644
--- a/source/blender/blenkernel/intern/cloth_remesh.cc
+++ b/source/blender/blenkernel/intern/cloth_remesh.cc
@@ -833,9 +833,12 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
return false;
}
- /* Newly formed edges shouldn't exceed the edge size criterion */
+ /* Newly formed edges shouldn't exceed the edge size criterion
+ * and newly formed faces shouldn't be inverted */
{
const auto [v1_a, v2_a] = this->get_checked_verts_of_edge(edge, verts_swapped);
+ const auto v1_index = v1_a.get_self_index();
+ const auto v2_index = v2_a.get_self_index();
const auto &n1_a = this->get_checked_node_of_vert(v1_a);
const auto &n2_a = this->get_checked_node_of_vert(v2_a);
const auto n1_index = n1_a.get_self_index();
@@ -846,7 +849,8 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
for (const auto &edge_index : edge_indices) {
/* Get v1 of the 3D edge in correct order */
const auto &e = this->get_checked_edge(edge_index);
- const auto [v1_index, v2_index] = this->get_checked_vert_indices_of_edge_aligned_with_n1(e, n1_index);
+ const auto [v1_index, v2_index] = this->get_checked_vert_indices_of_edge_aligned_with_n1(
+ e, n1_index);
const auto &v1 = this->get_checked_vert(v1_index);
const auto &v2 = this->get_checked_vert(v2_index);
@@ -869,6 +873,46 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
}
}
}
+
+ /* Face inversion check */
+ const auto v1_face_indices = this->get_checked_face_indices_of_vert(v1_index);
+ for (const auto &face_index : v1_face_indices) {
+ auto &f = this->get_checked_face(face_index);
+
+ /* Cannot create face between v2, v2, ov */
+ if (f.has_vert_index(v2_index)) {
+ continue;
+ }
+
+ BLI_assert(f.get_verts().size() == 3);
+
+ blender::Array<VertIndex> vert_indices(f.get_verts().as_span());
+
+ bool v2_exists = false;
+ for (auto &vert_index : vert_indices) {
+ if (vert_index == v2_index) {
+ v2_exists = true;
+ break;
+ }
+ if (vert_index == v1_index) {
+ vert_index = v2_index;
+ break;
+ }
+ }
+
+ if (v2_exists) {
+ continue;
+ }
+
+ const auto new_normal = this->compute_face_normal(this->get_checked_vert(vert_indices[0]),
+ this->get_checked_vert(vert_indices[1]),
+ this->get_checked_vert(vert_indices[2]));
+ const auto &expected_normal = f.get_normal();
+
+ if (float3::dot(new_normal, expected_normal) <= 0.0) {
+ return false;
+ }
+ }
}
/* TODO(ish): aspect ratio test */
More information about the Bf-blender-cvs
mailing list