[Bf-blender-cvs] [2fff595dbc7] soc-2021-adaptive-cloth: cloth: cloth_to_object: create copy only if needed
ishbosamiya
noreply at git.blender.org
Mon Jul 5 17:33:38 CEST 2021
Commit: 2fff595dbc7f1165e3a6b1be4a1a7aa3b4240958
Author: ishbosamiya
Date: Fri Jul 2 15:39:42 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB2fff595dbc7f1165e3a6b1be4a1a7aa3b4240958
cloth: cloth_to_object: create copy only if needed
===================================================================
M source/blender/blenkernel/BKE_cloth.h
M source/blender/blenkernel/BKE_cloth_remesh.hh
M source/blender/blenkernel/intern/cloth.c
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 7bf47e37c69..fe090340b23 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -249,6 +249,12 @@ struct Mesh *clothModifier_do(struct ClothModifierData *clmd,
int cloth_uses_vgroup(struct ClothModifierData *clmd);
+/* Needed for cloth_remesh.cc */
+struct Mesh *cloth_to_object(struct Object *ob,
+ struct ClothModifierData *clmd,
+ struct Mesh *mesh,
+ bool create_new);
+
// needed for collision.c
void bvhtree_update_from_cloth(struct ClothModifierData *clmd, bool moving, bool self);
diff --git a/source/blender/blenkernel/BKE_cloth_remesh.hh b/source/blender/blenkernel/BKE_cloth_remesh.hh
index 70822d0e5a4..850564a5233 100644
--- a/source/blender/blenkernel/BKE_cloth_remesh.hh
+++ b/source/blender/blenkernel/BKE_cloth_remesh.hh
@@ -51,7 +51,7 @@ extern "C" {
struct ClothModifierData;
struct Object;
-Mesh *BKE_cloth_remesh(const struct Object *ob, struct ClothModifierData *clmd, struct Mesh *mesh);
+Mesh *BKE_cloth_remesh(struct Object *ob, struct ClothModifierData *clmd, struct Mesh *mesh);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index b74977d3f23..16ce1e9279c 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -55,7 +55,6 @@
/* ********** cloth engine ******* */
/* Prototypes for internal functions.
*/
-static Mesh *cloth_to_object(Object *ob, ClothModifierData *clmd, Mesh *mesh);
static void cloth_from_mesh(ClothModifierData *clmd, const Object *ob, Mesh *mesh);
static bool cloth_from_object(
Object *ob, ClothModifierData *clmd, Mesh *mesh, float framenr, int first);
@@ -327,7 +326,8 @@ static Mesh *do_step_cloth(
}
/* if remeshing is off, need to update `mesh` from `clmd->clothObject` */
- return cloth_to_object(ob, clmd, mesh);
+ cloth_to_object(ob, clmd, mesh, false);
+ return mesh;
}
/************************************************
@@ -392,7 +392,7 @@ Mesh *clothModifier_do(
(!can_simulate && cache_result == PTCACHE_READ_OLD)) {
SIM_cloth_solver_set_positions(clmd);
- Mesh *mesh_result = cloth_to_object(ob, clmd, mesh);
+ cloth_to_object(ob, clmd, mesh, false);
BKE_ptcache_validate(cache, framenr);
@@ -402,7 +402,7 @@ Mesh *clothModifier_do(
clmd->clothObject->last_frame = framenr;
- return mesh_result;
+ return mesh;
}
if (cache_result == PTCACHE_READ_OLD) {
SIM_cloth_solver_set_positions(clmd);
@@ -604,16 +604,19 @@ void cloth_free_modifier_extern(ClothModifierData *clmd)
******************************************************************************/
/**
- * Creates a copy of `mesh` without reference and applies the deformed vertices after converting
- * the world space coordinates stored in `cloth->verts` to local space coords Returns the copy.
+ * Creates a copy of `mesh` without reference if `create_new` is true
+ * and applies the deformed vertices after converting the world space
+ * coordinates stored in `cloth->verts` to local space coords.
+ *
+ * Returns the copy if create_new else NULL.
*/
-static Mesh *cloth_to_object(Object *ob, ClothModifierData *clmd, Mesh *mesh)
+Mesh *cloth_to_object(Object *ob, ClothModifierData *clmd, Mesh *mesh, bool create_new)
{
/* TODO(ish): might need a better name for the function now that it
* directly applies the vertex * positions to the mesh */
Cloth *cloth = clmd->clothObject;
- Mesh *mesh_result = BKE_mesh_copy_for_eval(mesh, false);
+ Mesh *mesh_result = create_new ? BKE_mesh_copy_for_eval(mesh, false) : mesh;
if (clmd->clothObject) {
/* inverse matrix is not uptodate... */
@@ -633,7 +636,11 @@ static Mesh *cloth_to_object(Object *ob, ClothModifierData *clmd, Mesh *mesh)
MEM_freeN(vert_coords);
}
- return mesh_result;
+ if (create_new) {
+ return mesh_result;
+ }
+
+ return NULL;
}
int cloth_uses_vgroup(ClothModifierData *clmd)
diff --git a/source/blender/blenkernel/intern/cloth_remesh.cc b/source/blender/blenkernel/intern/cloth_remesh.cc
index bc896dfcee1..28d8df32004 100644
--- a/source/blender/blenkernel/intern/cloth_remesh.cc
+++ b/source/blender/blenkernel/intern/cloth_remesh.cc
@@ -27,13 +27,21 @@
#include "BLI_utildefines.h"
+#include "BKE_cloth.h"
#include "BKE_cloth_remesh.hh"
#include <cstdio>
-Mesh *BKE_cloth_remesh(const Object *UNUSED(ob),
- ClothModifierData *UNUSED(clmd),
- Mesh *UNUSED(r_mesh))
+using namespace blender::bke;
+
+Mesh *BKE_cloth_remesh(Object *ob, ClothModifierData *clmd, Mesh *mesh)
{
- return nullptr;
+ auto *cloth_to_object_res = cloth_to_object(ob, clmd, mesh, false);
+ BLI_assert(cloth_to_object_res == nullptr);
+
+ internal::MeshIO meshio;
+
+ meshio.read(mesh);
+
+ return meshio.write();
}
More information about the Bf-blender-cvs
mailing list