diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-07-04 13:46:03 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-07-04 15:54:16 +0300 |
commit | 175fe29e58156da93e484c25aa6f5767a46106f8 (patch) | |
tree | ec0429d5c331778e1f19be3830ccc70793deeb28 /source | |
parent | 60b9d413dbf1afc24b428dbe3bfea4bc0ec164c5 (diff) |
Cloth simulation: share point cache between CoW copies of objects
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 6 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_cloth.c | 23 |
2 files changed, 24 insertions, 5 deletions
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 712958deca1..49d72eddd09 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -119,6 +119,8 @@ typedef struct ModifierData { typedef enum { /* This modifier has been inserted in local override, and hence can be fully edited. */ eModifierFlag_StaticOverride_Local = (1 << 0), + /* This modifier does not own its caches, but instead shares them with another modifier. */ + eModifierFlag_SharedCaches = (1 << 1), } ModifierFlag; typedef enum { @@ -608,8 +610,12 @@ typedef struct ClothModifierData { struct Cloth *clothObject; /* The internal data structure for cloth. */ struct ClothSimSettings *sim_parms; /* definition is in DNA_cloth_types.h */ struct ClothCollSettings *coll_parms; /* definition is in DNA_cloth_types.h */ + + /* PointCache can be shared with other instances of ClothModifierData. + * Inspect (modifier.flag & eModifierFlag_SharedCaches) to find out. */ struct PointCache *point_cache; /* definition is in DNA_object_force_types.h */ struct ListBase ptcaches; + /* XXX nasty hack, remove once hair can be separated from cloth modifier data */ struct ClothHairData *hairdata; /* grid geometry values of hair continuum */ diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c index 34f571f5e30..53e71bfc1a4 100644 --- a/source/blender/modifiers/intern/MOD_cloth.c +++ b/source/blender/modifiers/intern/MOD_cloth.c @@ -42,6 +42,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_listbase.h" #include "BLI_utildefines.h" #include "BKE_cloth.h" @@ -155,7 +156,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static void copyData(const ModifierData *md, ModifierData *target, const int UNUSED(flag)) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const ClothModifierData *clmd = (const ClothModifierData *) md; ClothModifierData *tclmd = (ClothModifierData *) target; @@ -170,14 +171,21 @@ static void copyData(const ModifierData *md, ModifierData *target, const int UNU MEM_freeN(tclmd->coll_parms); BKE_ptcache_free_list(&tclmd->ptcaches); - tclmd->point_cache = NULL; + if (flag & LIB_ID_CREATE_NO_MAIN) { + /* Share the cache with the original object's modifier. */ + tclmd->modifier.flag |= eModifierFlag_SharedCaches; + tclmd->ptcaches = clmd->ptcaches; + tclmd->point_cache = clmd->point_cache; + } + else { + tclmd->point_cache = BKE_ptcache_add(&tclmd->ptcaches); + tclmd->point_cache->step = 1; + } tclmd->sim_parms = MEM_dupallocN(clmd->sim_parms); if (clmd->sim_parms->effector_weights) tclmd->sim_parms->effector_weights = MEM_dupallocN(clmd->sim_parms->effector_weights); tclmd->coll_parms = MEM_dupallocN(clmd->coll_parms); - tclmd->point_cache = BKE_ptcache_add(&tclmd->ptcaches); - tclmd->point_cache->step = 1; tclmd->clothObject = NULL; tclmd->hairdata = NULL; tclmd->solver_result = NULL; @@ -206,7 +214,12 @@ static void freeData(ModifierData *md) if (clmd->coll_parms) MEM_freeN(clmd->coll_parms); - BKE_ptcache_free_list(&clmd->ptcaches); + if (md->flag & eModifierFlag_SharedCaches) { + BLI_listbase_clear(&clmd->ptcaches); + } + else { + BKE_ptcache_free_list(&clmd->ptcaches); + } clmd->point_cache = NULL; if (clmd->hairdata) |