[Bf-blender-cvs] [4b94a2be222] soc-2021-adaptive-cloth: adaptive_cloth: NodeData: initial implementation

ishbosamiya noreply at git.blender.org
Mon Jul 19 17:35:44 CEST 2021


Commit: 4b94a2be222cb8ef1784868d19bb04ccea965a18
Author: ishbosamiya
Date:   Fri Jul 16 21:56:41 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB4b94a2be222cb8ef1784868d19bb04ccea965a18

adaptive_cloth: NodeData: initial implementation

Used to store extra `Node` data in the `Mesh`.

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

M	source/blender/blenkernel/BKE_cloth.h
M	source/blender/blenkernel/intern/cloth_remesh.cc

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

diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index fe090340b23..7bc042e393c 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -101,6 +101,9 @@ typedef struct Cloth {
 
 /**
  * The definition of a cloth vertex.
+ *
+ * When adding a new element to this structure, ensure that
+ * `NodeData::interp()` in `cloth_remesh.cc` has been updated.
  */
 typedef struct ClothVertex {
   int flags;                  /* General flags per vertex.        */
diff --git a/source/blender/blenkernel/intern/cloth_remesh.cc b/source/blender/blenkernel/intern/cloth_remesh.cc
index fc8fdcd7f70..989cbc2d70e 100644
--- a/source/blender/blenkernel/intern/cloth_remesh.cc
+++ b/source/blender/blenkernel/intern/cloth_remesh.cc
@@ -21,10 +21,12 @@
  * \ingroup bke
  */
 
+#include "BLI_math_vector.h"
 #include "DNA_cloth_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
 
+#include "BLI_float2x2.hh"
 #include "BLI_utildefines.h"
 
 #include "BKE_cloth.h"
@@ -33,6 +35,81 @@
 #include <cstdio>
 
 namespace blender::bke {
+class NodeData;
+
+template<typename T> static inline T simple_interp(const T &a, const T &b)
+{
+  return (a + b) * 0.5;
+}
+
+class NodeData {
+  ClothVertex cloth_node_data; /* The cloth simulation calls it
+                                * Vertex, internal::Mesh calls it Node */
+ public:
+  NodeData() = default;
+  NodeData(ClothVertex &&cloth_node_data) : cloth_node_data(cloth_node_data)
+  {
+  }
+
+  void set_cloth_node_data(ClothVertex &&cloth_node_data)
+  {
+    this->cloth_node_data = std::move(cloth_node_data);
+  }
+
+  const auto &get_cloth_node_data() const
+  {
+    return this->cloth_node_data;
+  }
+
+  NodeData interp(const NodeData &other) const
+  {
+    {
+      /* This check is to ensure that any new element added to
+       * ClothVertex is also updated here. After adding the
+       * interpolated value for the element (if needed), set the
+       * correct sizeof(ClothVertex) in the assertion below. */
+      BLI_assert(sizeof(ClothVertex) == 125);
+    }
+
+    ClothVertex cn;
+    /* TODO(ish): figure out how to handle the flags */
+    /* cn.flags; */
+    interp_v3_v3v3(cn.v, this->cloth_node_data.v, other.cloth_node_data.v, 0.5);
+    interp_v3_v3v3(cn.xconst, this->cloth_node_data.xconst, other.cloth_node_data.xconst, 0.5);
+    interp_v3_v3v3(cn.x, this->cloth_node_data.x, other.cloth_node_data.x, 0.5);
+    interp_v3_v3v3(cn.xold, this->cloth_node_data.xold, other.cloth_node_data.xold, 0.5);
+    interp_v3_v3v3(cn.tx, this->cloth_node_data.tx, other.cloth_node_data.tx, 0.5);
+    interp_v3_v3v3(cn.txold, this->cloth_node_data.txold, other.cloth_node_data.txold, 0.5);
+    interp_v3_v3v3(cn.tv, this->cloth_node_data.tv, other.cloth_node_data.tv, 0.5);
+    cn.mass = simple_interp(this->cloth_node_data.mass, other.cloth_node_data.mass);
+    cn.goal = simple_interp(this->cloth_node_data.goal, other.cloth_node_data.goal);
+    interp_v3_v3v3(cn.impulse, this->cloth_node_data.impulse, other.cloth_node_data.impulse, 0.5);
+    interp_v3_v3v3(cn.xrest, this->cloth_node_data.xrest, other.cloth_node_data.xrest, 0.5);
+    interp_v3_v3v3(cn.dcvel, this->cloth_node_data.dcvel, other.cloth_node_data.dcvel, 0.5);
+    /* TODO(ish): these might need to be set else where */
+    {
+      cn.impulse_count = simple_interp(this->cloth_node_data.impulse_count,
+                                       other.cloth_node_data.impulse_count);
+      cn.avg_spring_len = simple_interp(this->cloth_node_data.avg_spring_len,
+                                        other.cloth_node_data.avg_spring_len);
+      cn.struct_stiff = simple_interp(this->cloth_node_data.struct_stiff,
+                                      other.cloth_node_data.struct_stiff);
+      cn.bend_stiff = simple_interp(this->cloth_node_data.bend_stiff,
+                                    other.cloth_node_data.bend_stiff);
+      cn.shear_stiff = simple_interp(this->cloth_node_data.shear_stiff,
+                                     other.cloth_node_data.shear_stiff);
+      cn.spring_count = simple_interp(this->cloth_node_data.spring_count,
+                                      other.cloth_node_data.spring_count);
+      cn.shrink_factor = simple_interp(this->cloth_node_data.shrink_factor,
+                                       other.cloth_node_data.shrink_factor);
+      cn.internal_stiff = simple_interp(this->cloth_node_data.internal_stiff,
+                                        other.cloth_node_data.internal_stiff);
+      cn.pressure_factor = simple_interp(this->cloth_node_data.pressure_factor,
+                                         other.cloth_node_data.pressure_factor);
+    }
+    return NodeData(std::move(cn));
+  }
+};
 
 Mesh *BKE_cloth_remesh(Object *ob, ClothModifierData *clmd, Mesh *mesh)
 {



More information about the Bf-blender-cvs mailing list