[Bf-blender-cvs] [a6284e47743] soc-2019-adaptive-cloth: Cloth: Added flagging if previous frame was read from cache

ishbosamiya noreply at git.blender.org
Tue Aug 6 20:32:48 CEST 2019


Commit: a6284e477438f09c0144eb7c71ffe6a5fb95c598
Author: ishbosamiya
Date:   Mon Aug 5 15:43:29 2019 +0530
Branches: soc-2019-adaptive-cloth
https://developer.blender.org/rBa6284e477438f09c0144eb7c71ffe6a5fb95c598

Cloth: Added flagging if previous frame was read from cache

It might be necessary to move this part to clmd itself instead of the clothObject.

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

M	source/blender/blenkernel/BKE_cloth.h
M	source/blender/blenkernel/intern/cloth.c
M	source/blender/blenkernel/intern/pointcache.c

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

diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index d5dff1d119b..e9cf041bc74 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -48,6 +48,11 @@ struct ClothSizing;
 /* Toggle Cloth Cache */
 #define USE_CLOTH_CACHE 1
 
+typedef enum eClothFlag {
+  /* Flag to check if previous frame was read from cache */
+  CLOTH_FLAG_PREV_FRAME_READ_CACHE = (1 << 0),
+} eClothFlag;
+
 /* Bits to or into the ClothVertex.flags. */
 typedef enum eClothVertexFlag {
   CLOTH_VERT_FLAG_PINNED = 1,
@@ -98,6 +103,7 @@ typedef struct Cloth {
   struct Implicit_Data *implicit; /* our implicit solver connects to this pointer */
   struct EdgeSet *edgeset;        /* used for selfcollisions */
   int last_frame;
+  int flags;
 } Cloth;
 
 /**
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index b3df3a4437e..a823988f9d3 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -471,16 +471,25 @@ Mesh *clothModifier_do(
   bool can_simulate = (framenr == clmd->clothObject->last_frame + 1) &&
                       !(cache->flag & PTCACHE_BAKED);
 
-  clmd->mesh = mesh_result;
+  /* TODO(Ish): clmd->mesh = mesh_result should be done only on the first frame of reading the
+   * cache */
+  if (clmd->clothObject->flags & CLOTH_FLAG_PREV_FRAME_READ_CACHE) {
+  }
+  else {
+    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 */
+    mesh_result = clmd->mesh;
     BKE_cloth_solver_set_positions(clmd);
     cloth_to_mesh(ob, clmd, mesh_result);
 
+    clmd->clothObject->flags |= CLOTH_FLAG_PREV_FRAME_READ_CACHE;
+
     BKE_ptcache_validate(cache, framenr);
 
     if (cache_result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED) {
@@ -915,6 +924,7 @@ static int cloth_from_object(
     clmd->clothObject->edgeset = NULL;
     clmd->clothObject->bm = NULL;
     clmd->clothObject->bm_prev = NULL;
+    clmd->clothObject->flags = 0;
   }
   else if (!clmd->clothObject) {
     modifier_setError(&(clmd->modifier), "Out of memory on allocating clmd->clothObject");
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index ca8c45ec25c..8c89cfc4de2 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -544,16 +544,16 @@ 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;
-  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);
+  /* Object *ob = clmd->ob; */
+  /* 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(
     int index, void *cloth_v, void **data, float cfra, float cfra1, float cfra2, float *old_data)
@@ -2949,8 +2949,32 @@ static int ptcache_read(PTCacheID *pid, int cfra)
     int totpoint = pm->totpoint;
 
     if ((pid->data_types & (1 << BPHYS_DATA_INDEX)) == 0) {
+      if (pid->type == PTCACHE_TYPE_CLOTH) {
+        ClothModifierData *clmd = pid->calldata;
+        Object *ob = clmd->ob;
+        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);
+        if (clmd->clothObject->flags & CLOTH_FLAG_PREV_FRAME_READ_CACHE) {
+          clmd->sim_parms->remeshing_reset = 1;
+        }
+        Mesh *mesh_result = cloth_remeshing_step(depsgraph, ob, clmd, mesh);
+        if (clmd->mesh && mesh_result) {
+          BKE_mesh_free(clmd->mesh);
+          clmd->mesh = mesh_result;
+          mesh = clmd->mesh;
+          printf("mesh in %s has totvert: %d totedge: %d totface %d\n\n",
+                 __func__,
+                 mesh->totvert,
+                 mesh->totedge,
+                 mesh->totpoly);
+        }
+      }
       int pid_totpoint = pid->totpoint(pid->calldata, cfra);
-
       if (totpoint != pid_totpoint) {
         /* TODO(Ish): need to run the remeshing step before this check */
         char *em;



More information about the Bf-blender-cvs mailing list