[Bf-blender-cvs] [11195356ba8] soc-2019-adaptive-cloth: Cloth: Added comments for what needs to be added for the caching
ishbosamiya
noreply at git.blender.org
Tue Aug 6 20:32:46 CEST 2019
Commit: 11195356ba8499f78ccd12b0a8ab6eec7fa52094
Author: ishbosamiya
Date: Sun Aug 4 16:31:27 2019 +0530
Branches: soc-2019-adaptive-cloth
https://developer.blender.org/rB11195356ba8499f78ccd12b0a8ab6eec7fa52094
Cloth: Added comments for what needs to be added for the caching
===================================================================
M source/blender/blenkernel/BKE_cloth.h
M source/blender/blenkernel/intern/cloth.c
M source/blender/blenkernel/intern/pointcache.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/modifiers/intern/MOD_cloth.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index d8a636832d4..d5dff1d119b 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -46,7 +46,7 @@ struct ClothSizing;
#define ALMOST_ZERO FLT_EPSILON
/* Toggle Cloth Cache */
-#define USE_CLOTH_CACHE 0
+#define USE_CLOTH_CACHE 1
/* Bits to or into the ClothVertex.flags. */
typedef enum eClothVertexFlag {
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index d690a67d0e6..b3df3a4437e 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -471,10 +471,13 @@ Mesh *clothModifier_do(
bool can_simulate = (framenr == clmd->clothObject->last_frame + 1) &&
!(cache->flag & PTCACHE_BAKED);
+ clmd->mesh = mesh_result;
cache_result = BKE_ptcache_read(&pid, (float)framenr + scene->r.subframe, can_simulate);
if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED ||
(!can_simulate && cache_result == PTCACHE_READ_OLD)) {
+ /* TODO(Ish): Need to update mesh_result to be the new mesh that was generated while reading
+ * the cache */
BKE_cloth_solver_set_positions(clmd);
cloth_to_mesh(ob, clmd, mesh_result);
@@ -487,7 +490,6 @@ Mesh *clothModifier_do(
#endif
clmd->clothObject->last_frame = framenr;
#if USE_CLOTH_CACHE
-
return mesh_result;
}
else if (cache_result == PTCACHE_READ_OLD) {
@@ -556,6 +558,9 @@ void cloth_free_modifier(ClothModifierData *clmd)
if (!clmd) {
return;
}
+ clmd->depsgraph = NULL;
+ clmd->ob = NULL;
+ clmd->mesh = NULL;
cloth = clmd->clothObject;
@@ -645,6 +650,10 @@ void cloth_free_modifier_extern(ClothModifierData *clmd)
return;
}
+ clmd->depsgraph = NULL;
+ clmd->ob = NULL;
+ clmd->mesh = NULL;
+
cloth = clmd->clothObject;
if (cloth) {
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index cd2caf3a837..ca8c45ec25c 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -41,6 +41,8 @@
#include "DNA_rigidbody_types.h"
#include "DNA_scene_types.h"
#include "DNA_smoke_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_cloth_types.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
@@ -49,6 +51,8 @@
#include "BLT_translation.h"
+#include "DEG_depsgraph.h"
+
#include "PIL_time.h"
#include "BKE_appdir.h"
@@ -541,9 +545,14 @@ static void ptcache_cloth_read(
/* TODO(Ish): add the remeshing step here, so that the mesh has been updated with the correct
* number of vertices for the next frame */
Object *ob = clmd->ob;
- struct Depsgraph *depsgraph = clmd->depsgraph;
- CustomData_MeshMasks cddata_masks = cloth_remeshing_get_cd_mesh_masks();
- struct Mesh *mesh = BKE_mesh_from_bmesh_for_eval_nomain(clmd->clothObject->bm, &cddata_masks);
+ Depsgraph *depsgraph = clmd->depsgraph;
+ Mesh *mesh = clmd->mesh;
+ printf("mesh in %s has totvert: %d totedge: %d totface %d\n",
+ __func__,
+ mesh->totvert,
+ mesh->totedge,
+ mesh->totpoly);
+ clmd->sim_parms->remeshing_reset = 1;
cloth_remeshing_step(depsgraph, ob, clmd, mesh);
}
static void ptcache_cloth_interpolate(
@@ -2943,7 +2952,14 @@ static int ptcache_read(PTCacheID *pid, int cfra)
int pid_totpoint = pid->totpoint(pid->calldata, cfra);
if (totpoint != pid_totpoint) {
- pid->error(pid->calldata, "Number of points in cache does not match mesh");
+ /* TODO(Ish): need to run the remeshing step before this check */
+ char *em;
+ sprintf(em,
+ "%s memory_cache_totpoint: %d pid_totpoint: %d",
+ "Number of points in cache does not match mesh",
+ totpoint,
+ pid_totpoint);
+ pid->error(pid->calldata, em);
totpoint = MIN2(totpoint, pid_totpoint);
}
}
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index edff4bbae47..fd3c3c44497 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -730,6 +730,7 @@ typedef struct ClothModifierData {
struct ListBase ptcaches;
struct Depsgraph *depsgraph;
struct Object *ob;
+ struct Mesh *mesh;
/* XXX nasty hack, remove once hair can be separated from cloth modifier data */
struct ClothHairData *hairdata;
diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c
index ea5167ad2fb..948dd0b9f4a 100644
--- a/source/blender/modifiers/intern/MOD_cloth.c
+++ b/source/blender/modifiers/intern/MOD_cloth.c
@@ -31,7 +31,7 @@
#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
-#define USE_CLOTH_CACHE 0
+#define USE_CLOTH_CACHE 1
#if USE_CLOTH_CACHE
#else
# include "DNA_object_force_types.h"
More information about the Bf-blender-cvs
mailing list