From 60b9d413dbf1afc24b428dbe3bfea4bc0ec164c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 4 Jul 2018 12:45:30 +0200 Subject: Pass copy flag to modifier copyData function This will allow modifiers to decide whether to copy or share caches between ModifierData copies. --- source/blender/modifiers/intern/MOD_armature.c | 4 ++-- source/blender/modifiers/intern/MOD_cloth.c | 2 +- source/blender/modifiers/intern/MOD_correctivesmooth.c | 4 ++-- source/blender/modifiers/intern/MOD_dynamicpaint.c | 2 +- source/blender/modifiers/intern/MOD_explode.c | 4 ++-- source/blender/modifiers/intern/MOD_fluidsim.c | 2 +- source/blender/modifiers/intern/MOD_hook.c | 4 ++-- source/blender/modifiers/intern/MOD_laplaciandeform.c | 4 ++-- source/blender/modifiers/intern/MOD_meshdeform.c | 4 ++-- source/blender/modifiers/intern/MOD_meshsequencecache.c | 4 ++-- source/blender/modifiers/intern/MOD_ocean.c | 2 +- source/blender/modifiers/intern/MOD_particlesystem.c | 4 ++-- source/blender/modifiers/intern/MOD_smoke.c | 2 +- source/blender/modifiers/intern/MOD_subsurf.c | 4 ++-- source/blender/modifiers/intern/MOD_surfacedeform.c | 4 ++-- source/blender/modifiers/intern/MOD_warp.c | 4 ++-- source/blender/modifiers/intern/MOD_weightvgedit.c | 4 ++-- 17 files changed, 29 insertions(+), 29 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c index 09ba865cce3..a069b261067 100644 --- a/source/blender/modifiers/intern/MOD_armature.c +++ b/source/blender/modifiers/intern/MOD_armature.c @@ -64,14 +64,14 @@ static void initData(ModifierData *md) amd->deformflag = ARM_DEF_VGROUP; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #if 0 const ArmatureModifierData *amd = (const ArmatureModifierData *) md; #endif ArmatureModifierData *tamd = (ArmatureModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); tamd->prevCos = NULL; } diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c index 58979fa201b..34f571f5e30 100644 --- a/source/blender/modifiers/intern/MOD_cloth.c +++ b/source/blender/modifiers/intern/MOD_cloth.c @@ -155,7 +155,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int UNUSED(flag)) { const ClothModifierData *clmd = (const ClothModifierData *) md; ClothModifierData *tclmd = (ClothModifierData *) target; diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c index 879b07de6d9..d59360896e8 100644 --- a/source/blender/modifiers/intern/MOD_correctivesmooth.c +++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c @@ -80,12 +80,12 @@ static void initData(ModifierData *md) } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const CorrectiveSmoothModifierData *csmd = (const CorrectiveSmoothModifierData *)md; CorrectiveSmoothModifierData *tcsmd = (CorrectiveSmoothModifierData *)target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); if (csmd->bind_coords) { tcsmd->bind_coords = MEM_dupallocN(csmd->bind_coords); diff --git a/source/blender/modifiers/intern/MOD_dynamicpaint.c b/source/blender/modifiers/intern/MOD_dynamicpaint.c index 9131bc0659f..61219096b43 100644 --- a/source/blender/modifiers/intern/MOD_dynamicpaint.c +++ b/source/blender/modifiers/intern/MOD_dynamicpaint.c @@ -57,7 +57,7 @@ static void initData(ModifierData *md) pmd->type = MOD_DYNAMICPAINT_TYPE_CANVAS; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int UNUSED(flag)) { const DynamicPaintModifierData *pmd = (const DynamicPaintModifierData *)md; DynamicPaintModifierData *tpmd = (DynamicPaintModifierData *)target; diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c index 948aaf0751e..04bfe96bc59 100644 --- a/source/blender/modifiers/intern/MOD_explode.c +++ b/source/blender/modifiers/intern/MOD_explode.c @@ -70,14 +70,14 @@ static void freeData(ModifierData *md) MEM_SAFE_FREE(emd->facepa); } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #if 0 const ExplodeModifierData *emd = (const ExplodeModifierData *) md; #endif ExplodeModifierData *temd = (ExplodeModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); temd->facepa = NULL; } diff --git a/source/blender/modifiers/intern/MOD_fluidsim.c b/source/blender/modifiers/intern/MOD_fluidsim.c index ffa74be0b33..272cc5c17f4 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim.c +++ b/source/blender/modifiers/intern/MOD_fluidsim.c @@ -65,7 +65,7 @@ static void freeData(ModifierData *md) fluidsim_free(fluidmd); } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int UNUSED(flag)) { const FluidsimModifierData *fluidmd = (const FluidsimModifierData *) md; FluidsimModifierData *tfluidmd = (FluidsimModifierData *) target; diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c index a5013bb38c6..4b34bdd2c16 100644 --- a/source/blender/modifiers/intern/MOD_hook.c +++ b/source/blender/modifiers/intern/MOD_hook.c @@ -63,12 +63,12 @@ static void initData(ModifierData *md) hmd->flag = 0; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const HookModifierData *hmd = (const HookModifierData *) md; HookModifierData *thmd = (HookModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); thmd->curfalloff = curvemapping_copy(hmd->curfalloff); diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c index e5b96c633f7..0224d412ba6 100644 --- a/source/blender/modifiers/intern/MOD_laplaciandeform.c +++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c @@ -704,12 +704,12 @@ static void initData(ModifierData *md) lmd->flag = 0; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const LaplacianDeformModifierData *lmd = (const LaplacianDeformModifierData *)md; LaplacianDeformModifierData *tlmd = (LaplacianDeformModifierData *)target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); tlmd->vertexco = MEM_dupallocN(lmd->vertexco); tlmd->cache_system = NULL; diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index af37b30b7aa..05e1568f780 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -81,12 +81,12 @@ static void freeData(ModifierData *md) if (mmd->bindcos) MEM_freeN(mmd->bindcos); /* deprecated */ } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const MeshDeformModifierData *mmd = (const MeshDeformModifierData *) md; MeshDeformModifierData *tmmd = (MeshDeformModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); if (mmd->bindinfluences) tmmd->bindinfluences = MEM_dupallocN(mmd->bindinfluences); if (mmd->bindoffsets) tmmd->bindoffsets = MEM_dupallocN(mmd->bindoffsets); diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c index a6c9f865e4c..fd8676d6653 100644 --- a/source/blender/modifiers/intern/MOD_meshsequencecache.c +++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c @@ -55,14 +55,14 @@ static void initData(ModifierData *md) mcmd->read_flag = MOD_MESHSEQ_READ_ALL; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #if 0 const MeshSeqCacheModifierData *mcmd = (const MeshSeqCacheModifierData *)md; #endif MeshSeqCacheModifierData *tmcmd = (MeshSeqCacheModifierData *)target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); tmcmd->reader = NULL; } diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 702e557ccb1..58454782b2e 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -163,7 +163,7 @@ static void freeData(ModifierData *md) #endif /* WITH_OCEANSIM */ } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int UNUSED(flag)) { #ifdef WITH_OCEANSIM #if 0 diff --git a/source/blender/modifiers/intern/MOD_particlesystem.c b/source/blender/modifiers/intern/MOD_particlesystem.c index 1821a0fced0..6f9a44cd9e6 100644 --- a/source/blender/modifiers/intern/MOD_particlesystem.c +++ b/source/blender/modifiers/intern/MOD_particlesystem.c @@ -79,14 +79,14 @@ static void freeData(ModifierData *md) psmd->psys->flag |= PSYS_DELETE; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #if 0 const ParticleSystemModifierData *psmd = (const ParticleSystemModifierData *) md; #endif ParticleSystemModifierData *tpsmd = (ParticleSystemModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); tpsmd->mesh_final = NULL; tpsmd->mesh_original = NULL; diff --git a/source/blender/modifiers/intern/MOD_smoke.c b/source/blender/modifiers/intern/MOD_smoke.c index e81c760ed67..9a27f31adaa 100644 --- a/source/blender/modifiers/intern/MOD_smoke.c +++ b/source/blender/modifiers/intern/MOD_smoke.c @@ -71,7 +71,7 @@ static void initData(ModifierData *md) smd->time = -1; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int UNUSED(flag)) { const SmokeModifierData *smd = (const SmokeModifierData *)md; SmokeModifierData *tsmd = (SmokeModifierData *)target; diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c index 3de04e878ac..5a5b596eaab 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.c +++ b/source/blender/modifiers/intern/MOD_subsurf.c @@ -65,14 +65,14 @@ static void initData(ModifierData *md) smd->flags |= eSubsurfModifierFlag_SubsurfUv; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #if 0 const SubsurfModifierData *smd = (const SubsurfModifierData *) md; #endif SubsurfModifierData *tsmd = (SubsurfModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); tsmd->emCache = tsmd->mCache = NULL; } diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c index a3ab2d74602..0c58d47d53f 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.c +++ b/source/blender/modifiers/intern/MOD_surfacedeform.c @@ -136,12 +136,12 @@ static void freeData(ModifierData *md) } } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const SurfaceDeformModifierData *smd = (const SurfaceDeformModifierData *)md; SurfaceDeformModifierData *tsmd = (SurfaceDeformModifierData *)target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); if (smd->verts) { tsmd->verts = MEM_dupallocN(smd->verts); diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c index 54f8ce8c515..69bf44d8b68 100644 --- a/source/blender/modifiers/intern/MOD_warp.c +++ b/source/blender/modifiers/intern/MOD_warp.c @@ -65,12 +65,12 @@ static void initData(ModifierData *md) wmd->flag = 0; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const WarpModifierData *wmd = (const WarpModifierData *) md; WarpModifierData *twmd = (WarpModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); twmd->curfalloff = curvemapping_copy(wmd->curfalloff); } diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c index a26cb73d823..a2f9319ad51 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.c +++ b/source/blender/modifiers/intern/MOD_weightvgedit.c @@ -81,12 +81,12 @@ static void freeData(ModifierData *md) curvemapping_free(wmd->cmap_curve); } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const WeightVGEditModifierData *wmd = (const WeightVGEditModifierData *) md; WeightVGEditModifierData *twmd = (WeightVGEditModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); twmd->cmap_curve = curvemapping_copy(wmd->cmap_curve); } -- cgit v1.2.3 From 175fe29e58156da93e484c25aa6f5767a46106f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 4 Jul 2018 12:46:03 +0200 Subject: Cloth simulation: share point cache between CoW copies of objects --- source/blender/modifiers/intern/MOD_cloth.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'source/blender/modifiers/intern') 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) -- cgit v1.2.3 From d663ec48c06a083de74e90dd9c605e98b28baa37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 4 Jul 2018 15:10:45 +0200 Subject: Fluid Sim: Removed unused PointCache pointer The only uses were setting it to NULL and asserting it is NULL. --- source/blender/modifiers/intern/MOD_fluidsim.c | 5 ----- source/blender/modifiers/intern/MOD_fluidsim_util.c | 4 ---- 2 files changed, 9 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_fluidsim.c b/source/blender/modifiers/intern/MOD_fluidsim.c index 272cc5c17f4..6e322dc7016 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim.c +++ b/source/blender/modifiers/intern/MOD_fluidsim.c @@ -76,11 +76,6 @@ static void copyData(const ModifierData *md, ModifierData *target, const int UNU tfluidmd->fss->meshVelocities = MEM_dupallocN(tfluidmd->fss->meshVelocities); } } - - /* Seems to never be used, but for sqke of consistency... */ - BLI_assert(fluidmd->point_cache == NULL); - BLI_assert(tfluidmd->point_cache == NULL); - tfluidmd->point_cache = NULL; } diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index cea9e69526c..ed5d08a95d4 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -160,10 +160,6 @@ void fluidsim_free(FluidsimModifierData *fluidmd) MEM_SAFE_FREE(fluidmd->fss); } - /* Seems to never be used, but for sqke of consistency... */ - BLI_assert(fluidmd->point_cache == NULL); - fluidmd->point_cache = NULL; - return; } -- cgit v1.2.3 From fd341dd6f74e7145d5df725170e886f0f3ef51b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 4 Jul 2018 15:15:08 +0200 Subject: Added copyData flag to ocean modifier --- source/blender/modifiers/intern/MOD_ocean.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 58454782b2e..e9dc7e068ca 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -163,7 +163,7 @@ static void freeData(ModifierData *md) #endif /* WITH_OCEANSIM */ } -static void copyData(const ModifierData *md, ModifierData *target, const int UNUSED(flag)) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #ifdef WITH_OCEANSIM #if 0 @@ -171,7 +171,7 @@ static void copyData(const ModifierData *md, ModifierData *target, const int UNU #endif OceanModifierData *tomd = (OceanModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); tomd->refresh = 0; @@ -186,6 +186,7 @@ static void copyData(const ModifierData *md, ModifierData *target, const int UNU /* unused */ (void)md; (void)target; + (void)flag; #endif /* WITH_OCEANSIM */ } -- cgit v1.2.3 From f4ce6d02cde816c3c681702d97a75617b8e9a598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 5 Jul 2018 11:08:05 +0200 Subject: Fluidsim: ported from DerivedMesh to Mesh Also removed a bunch of unnecessary #include statements from fluidsim.c. --- source/blender/modifiers/intern/MOD_fluidsim.c | 19 +++--- .../blender/modifiers/intern/MOD_fluidsim_util.c | 71 +++++++++++----------- .../blender/modifiers/intern/MOD_fluidsim_util.h | 6 +- 3 files changed, 47 insertions(+), 49 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_fluidsim.c b/source/blender/modifiers/intern/MOD_fluidsim.c index 6e322dc7016..bb87d0065fe 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim.c +++ b/source/blender/modifiers/intern/MOD_fluidsim.c @@ -33,14 +33,13 @@ */ +#include "DNA_mesh_types.h" #include "DNA_scene_types.h" #include "DNA_object_fluidsim_types.h" #include "DNA_object_types.h" #include "BLI_utildefines.h" - -#include "BKE_cdderivedmesh.h" #include "BKE_layer.h" #include "BKE_modifier.h" @@ -80,25 +79,25 @@ static void copyData(const ModifierData *md, ModifierData *target, const int UNU -static DerivedMesh *applyModifier( +static Mesh *applyModifier( ModifierData *md, const ModifierEvalContext *ctx, - DerivedMesh *dm) + Mesh *mesh) { FluidsimModifierData *fluidmd = (FluidsimModifierData *) md; - DerivedMesh *result = NULL; + Mesh *result = NULL; /* check for alloc failing */ if (!fluidmd->fss) { initData(md); if (!fluidmd->fss) { - return dm; + return mesh; } } - result = fluidsimModifier_do(fluidmd, ctx, dm); + result = fluidsimModifier_do(fluidmd, ctx, mesh); - return result ? result : dm; + return result ? result : mesh; } static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx) @@ -145,14 +144,14 @@ ModifierTypeInfo modifierType_Fluidsim = { /* deformMatrices_DM */ NULL, /* deformVertsEM_DM */ NULL, /* deformMatricesEM_DM*/NULL, - /* applyModifier_DM */ applyModifier, + /* applyModifier_DM */ NULL, /* applyModifierEM_DM */NULL, /* deformVerts */ NULL, /* deformMatrices */ NULL, /* deformVertsEM */ NULL, /* deformMatricesEM */ NULL, - /* applyModifier */ NULL, + /* applyModifier */ applyModifier, /* applyModifierEM */ NULL, /* initData */ initData, diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index ed5d08a95d4..963296f80f6 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -47,8 +47,8 @@ #include "BLI_utildefines.h" #include "BKE_fluidsim.h" /* ensure definitions here match */ -#include "BKE_cdderivedmesh.h" #include "BKE_main.h" +#include "BKE_mesh.h" #ifdef WITH_MOD_FLUID # include "BKE_global.h" #endif @@ -165,13 +165,13 @@ void fluidsim_free(FluidsimModifierData *fluidmd) #ifdef WITH_MOD_FLUID /* read .bobj.gz file into a fluidsimDerivedMesh struct */ -static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_example) +static Mesh *fluidsim_read_obj(const char *filename, const MPoly *mp_example) { int wri = 0, i; int gotBytes; gzFile gzf; int numverts = 0, numfaces = 0; - DerivedMesh *dm = NULL; + Mesh *mesh = NULL; MPoly *mp; MLoop *ml; MVert *mv; @@ -220,9 +220,9 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam return NULL; } - dm = CDDM_new(numverts, 0, 0, numfaces * 3, numfaces); + mesh = BKE_mesh_new_nomain(numverts, 0, 0, numfaces * 3, numfaces); - if (!dm) { + if (!mesh) { gzclose(gzf); return NULL; } @@ -231,7 +231,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam gotBytes = gzread(gzf, &wri, sizeof(wri)); /* read vertex position from file */ - mv = CDDM_get_verts(dm); + mv = mesh->mvert; for (i = 0; i < numverts; i++, mv++) gotBytes = gzread(gzf, mv->co, sizeof(float) * 3); @@ -239,16 +239,16 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam /* should be the same as numverts */ gotBytes = gzread(gzf, &wri, sizeof(wri)); if (wri != numverts) { - if (dm) - dm->release(dm); + if (mesh) + BKE_id_free(NULL, mesh); gzclose(gzf); return NULL; } normals = MEM_calloc_arrayN(numverts, 3 * sizeof(short), "fluid_tmp_normals"); if (!normals) { - if (dm) - dm->release(dm); + if (mesh) + BKE_id_free(NULL, mesh); gzclose(gzf); return NULL; } @@ -264,16 +264,16 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam if (wri != numfaces) { printf("Fluidsim: error in reading data from file.\n"); - if (dm) - dm->release(dm); + if (mesh) + BKE_id_free(NULL, mesh); gzclose(gzf); MEM_freeN(normals); return NULL; } /* read triangles from file */ - mp = CDDM_get_polys(dm); - ml = CDDM_get_loops(dm); + mp = mesh->mpoly; + ml = mesh->mloop; for (i = 0; i < numfaces; i++, mp++, ml += 3) { int face[3]; @@ -294,13 +294,12 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam gzclose(gzf); - CDDM_calc_edges(dm); - - CDDM_apply_vert_normals(dm, (short (*)[3])normals); + BKE_mesh_calc_edges(mesh, false, false); + BKE_mesh_apply_vert_normals(mesh, (short (*)[3])normals); MEM_freeN(normals); // CDDM_calc_normals(result); - return dm; + return mesh; } @@ -370,14 +369,14 @@ void fluid_estimate_memory(Object *ob, FluidsimSettings *fss, char *value) /* read zipped fluidsim velocities into the co's of the fluidsimsettings normals struct */ -static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, char *filename) +static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, Mesh *mesh, char *filename) { int wri, i, j; float wrf; gzFile gzf; FluidsimSettings *fss = fluidmd->fss; int len = strlen(filename); - int totvert = dm->getNumVerts(dm); + int totvert = mesh->totvert; FluidVertexVelocity *velarray = NULL; /* mesh and vverts have to be valid from loading... */ @@ -391,7 +390,7 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh * if (fss->domainNovecgen > 0) return; - fss->meshVelocities = MEM_calloc_arrayN(dm->getNumVerts(dm), sizeof(FluidVertexVelocity), "Fluidsim_velocities"); + fss->meshVelocities = MEM_calloc_arrayN(mesh->totvert, sizeof(FluidVertexVelocity), "Fluidsim_velocities"); fss->totvert = totvert; velarray = fss->meshVelocities; @@ -426,8 +425,8 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh * gzclose(gzf); } -static DerivedMesh *fluidsim_read_cache( - Object *ob, DerivedMesh *orgdm, +static Mesh *fluidsim_read_cache( + Object *ob, Mesh *orgmesh, FluidsimModifierData *fluidmd, int framenr, int useRenderParams) { int curFrame = framenr /* - 1 */ /*scene->r.sfra*/; /* start with 0 at start frame */ @@ -436,7 +435,7 @@ static DerivedMesh *fluidsim_read_cache( char targetFile[FILE_MAX]; FluidsimSettings *fss = fluidmd->fss; - DerivedMesh *dm = NULL; + Mesh *newmesh = NULL; MPoly *mpoly; MPoly mp_example = {0}; @@ -467,15 +466,15 @@ static DerivedMesh *fluidsim_read_cache( /* assign material + flags to new dm * if there's no faces in original dm, keep materials and flags unchanged */ - mpoly = orgdm->getPolyArray(orgdm); + mpoly = orgmesh->mpoly; if (mpoly) { mp_example = *mpoly; } /* else leave NULL'd */ - dm = fluidsim_read_obj(targetFile, &mp_example); + newmesh = fluidsim_read_obj(targetFile, &mp_example); - if (!dm) { + if (!newmesh) { /* switch, abort background rendering when fluidsim mesh is missing */ const char *strEnvName2 = "BLENDER_ELBEEMBOBJABORT"; // from blendercall.cpp @@ -498,7 +497,7 @@ static DerivedMesh *fluidsim_read_cache( * TODO? use generate flag as loading flag as well? * warning, needs original .bobj.gz mesh loading filename */ if (displaymode == OB_FSDOM_FINAL) { - fluidsim_read_vel_cache(fluidmd, dm, targetFile); + fluidsim_read_vel_cache(fluidmd, newmesh, targetFile); } else { if (fss->meshVelocities) @@ -507,21 +506,21 @@ static DerivedMesh *fluidsim_read_cache( fss->meshVelocities = NULL; } - return dm; + return newmesh; } #endif // WITH_MOD_FLUID -DerivedMesh *fluidsimModifier_do( +Mesh *fluidsimModifier_do( FluidsimModifierData *fluidmd, const ModifierEvalContext *ctx, - DerivedMesh *dm) + Mesh *mesh) { #ifdef WITH_MOD_FLUID Object *ob = ctx->object; Depsgraph *depsgraph = ctx->depsgraph; const bool useRenderParams = (ctx->flag & MOD_APPLY_RENDER) != 0; // const bool isFinalCalc = (ctx->flag & MOD_APPLY_USECACHE) != 0; - DerivedMesh *result = NULL; + Mesh *result = NULL; int framenr; FluidsimSettings *fss = NULL; @@ -529,11 +528,11 @@ DerivedMesh *fluidsimModifier_do( /* only handle fluidsim domains */ if (fluidmd && fluidmd->fss && (fluidmd->fss->type != OB_FLUIDSIM_DOMAIN)) - return dm; + return mesh; /* sanity check */ if (!fluidmd || !fluidmd->fss) - return dm; + return mesh; fss = fluidmd->fss; @@ -548,10 +547,10 @@ DerivedMesh *fluidsimModifier_do( /* try to read from cache */ /* if the frame is there, fine, otherwise don't do anything */ - if ((result = fluidsim_read_cache(ob, dm, fluidmd, framenr, useRenderParams))) + if ((result = fluidsim_read_cache(ob, mesh, fluidmd, framenr, useRenderParams))) return result; - return dm; + return mesh; #else /* unused */ (void)fluidmd; diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.h b/source/blender/modifiers/intern/MOD_fluidsim_util.h index 0a0c8419a99..041a67eddbd 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.h +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.h @@ -36,16 +36,16 @@ struct Object; struct Scene; struct FluidsimModifierData; -struct DerivedMesh; +struct Mesh; struct ModifierEvalContext; /* new fluid-modifier interface */ void fluidsim_init(struct FluidsimModifierData *fluidmd); void fluidsim_free(struct FluidsimModifierData *fluidmd); -struct DerivedMesh *fluidsimModifier_do( +struct Mesh *fluidsimModifier_do( struct FluidsimModifierData *fluidmd, const struct ModifierEvalContext *ctx, - struct DerivedMesh *dm); + struct Mesh *dm); #endif -- cgit v1.2.3 From 03ef9f32148acb45c4940cf93d7d8afb850231d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 5 Jul 2018 12:21:33 +0200 Subject: Fluidsim: fixed memory leak --- source/blender/modifiers/intern/MOD_fluidsim.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_fluidsim.c b/source/blender/modifiers/intern/MOD_fluidsim.c index bb87d0065fe..ebea7250d18 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim.c +++ b/source/blender/modifiers/intern/MOD_fluidsim.c @@ -69,11 +69,20 @@ static void copyData(const ModifierData *md, ModifierData *target, const int UNU const FluidsimModifierData *fluidmd = (const FluidsimModifierData *) md; FluidsimModifierData *tfluidmd = (FluidsimModifierData *) target; - if (fluidmd->fss) { - tfluidmd->fss = MEM_dupallocN(fluidmd->fss); - if (tfluidmd->fss && (tfluidmd->fss->meshVelocities != NULL)) { - tfluidmd->fss->meshVelocities = MEM_dupallocN(tfluidmd->fss->meshVelocities); - } + /* Free any FSS that was allocated in initData() */ + if (tfluidmd->fss) { + MEM_SAFE_FREE(tfluidmd->fss->meshVelocities); + MEM_freeN(tfluidmd->fss); + } + + if (fluidmd->fss == NULL) { + tfluidmd->fss = NULL; + return; + } + + tfluidmd->fss = MEM_dupallocN(fluidmd->fss); + if (tfluidmd->fss->meshVelocities != NULL) { + tfluidmd->fss->meshVelocities = MEM_dupallocN(tfluidmd->fss->meshVelocities); } } -- cgit v1.2.3 From 1517fa43097a3925b5fd1d4b8738fd56fde17bc8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 5 Jul 2018 12:26:10 +0200 Subject: Fix build w/o fluidsim --- source/blender/modifiers/intern/MOD_fluidsim_util.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 963296f80f6..edd7a7a331c 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -464,8 +464,8 @@ static Mesh *fluidsim_read_cache( BLI_path_abs(targetFile, modifier_path_relbase_from_global(ob)); BLI_path_frame(targetFile, curFrame, 0); // fixed #frame-no - /* assign material + flags to new dm - * if there's no faces in original dm, keep materials and flags unchanged */ + /* assign material + flags to new mesh. + * if there's no faces in original mesh, keep materials and flags unchanged */ mpoly = orgmesh->mpoly; if (mpoly) { mp_example = *mpoly; @@ -489,7 +489,7 @@ static Mesh *fluidsim_read_cache( } } - /* display org. object upon failure which is in dm */ + /* display org. object upon failure which is in new mesh */ return NULL; } @@ -555,7 +555,6 @@ Mesh *fluidsimModifier_do( /* unused */ (void)fluidmd; (void)ctx; - (void)dm; return NULL; #endif } -- cgit v1.2.3 From a4328a4b70f80bbb1c2e8df3b95b793dc5f6fb06 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 5 Jul 2018 12:29:48 +0200 Subject: Cleanup: warning --- source/blender/modifiers/intern/MOD_fluidsim_util.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index edd7a7a331c..44079163de5 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -553,8 +553,7 @@ Mesh *fluidsimModifier_do( return mesh; #else /* unused */ - (void)fluidmd; - (void)ctx; + UNUSED_VARS(fluidmd, ctx, mesh); return NULL; #endif } -- cgit v1.2.3 From 769104016636b26be1b01726a1ea45c95b184a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 6 Jul 2018 12:40:09 +0200 Subject: Ocean Modifier: removed the MOD_OCEAN_REFRESH_ADD flag The flag was only used in readfile.c, and resulted in a delayed call to BKE_ocean_add(); this call is now immediately made instead as it's not very expensive. --- source/blender/modifiers/intern/MOD_ocean.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index c29e835797b..b845e62c530 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -435,9 +435,6 @@ static DerivedMesh *doOcean( } /* update modifier */ - if (omd->refresh & MOD_OCEAN_REFRESH_ADD) { - omd->ocean = BKE_ocean_add(); - } if (omd->refresh & MOD_OCEAN_REFRESH_RESET) { init_ocean_modifier(omd); } -- cgit v1.2.3 From 6807b4318f25a581b7ec75739bd36cf8b07086b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 5 Jul 2018 15:30:00 +0200 Subject: Ocean Modifier: ported from DerivedMesh to Mesh --- source/blender/modifiers/intern/MOD_ocean.c | 85 +++++++++++++++-------------- 1 file changed, 45 insertions(+), 40 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 52bd3e874b6..26011cfc121 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -31,6 +31,7 @@ #include "DNA_customdata_types.h" #include "DNA_object_types.h" +#include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" #include "DNA_scene_types.h" @@ -40,9 +41,9 @@ #include "BLI_task.h" #include "BLI_utildefines.h" -#include "BKE_cdderivedmesh.h" #include "BKE_global.h" #include "BKE_main.h" +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_ocean.h" @@ -344,9 +345,9 @@ static void generate_ocean_geometry_uvs( } } -static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd) +static Mesh *generate_ocean_geometry(OceanModifierData *omd) { - DerivedMesh *result; + Mesh *result; GenerateOceanGeometryData gogd; @@ -371,13 +372,13 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd) gogd.sx /= gogd.rx; gogd.sy /= gogd.ry; - result = CDDM_new(num_verts, 0, 0, num_polys * 4, num_polys); + result = BKE_mesh_new_nomain(num_verts, 0, 0, num_polys * 4, num_polys); - gogd.mverts = CDDM_get_verts(result); - gogd.mpolys = CDDM_get_polys(result); - gogd.mloops = CDDM_get_loops(result); + gogd.mverts = result->mvert; + gogd.mpolys = result->mpoly; + gogd.mloops = result->mloop; - gogd.origindex = CustomData_get_layer(&result->polyData, CD_ORIGINDEX); + gogd.origindex = CustomData_get_layer(&result->pdata, CD_ORIGINDEX); ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); @@ -389,11 +390,11 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd) /* create faces */ BLI_task_parallel_range(0, gogd.res_y, &gogd, generate_ocean_geometry_polygons, &settings); - CDDM_calc_edges(result); + BKE_mesh_calc_edges(result, false, false); /* add uvs */ - if (CustomData_number_of_layers(&result->loopData, CD_MLOOPUV) < MAX_MTFACE) { - gogd.mloopuvs = CustomData_add_layer(&result->loopData, CD_MLOOPUV, CD_CALLOC, NULL, num_polys * 4); + if (CustomData_number_of_layers(&result->ldata, CD_MLOOPUV) < MAX_MTFACE) { + gogd.mloopuvs = CustomData_add_layer(&result->ldata, CD_MLOOPUV, CD_CALLOC, NULL, num_polys * 4); if (gogd.mloopuvs) { /* unlikely to fail */ gogd.ix = 1.0 / gogd.rx; @@ -403,19 +404,19 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd) } } - result->dirty |= DM_DIRTY_NORMALS; + result->runtime.cd_dirty_vert |= CD_MASK_NORMAL; return result; } -static DerivedMesh *doOcean( +static Mesh *doOcean( ModifierData *md, Scene *scene, Object *ob, - DerivedMesh *derivedData, + Mesh *mesh, int UNUSED(useRenderParams)) { OceanModifierData *omd = (OceanModifierData *) md; - DerivedMesh *dm = NULL; + Mesh *result = NULL; OceanResult ocr; MVert *mverts; @@ -433,7 +434,7 @@ static DerivedMesh *doOcean( /* can happen in when size is small, avoid bad array lookups later and quit now */ if (!isfinite(size_co_inv)) { - return derivedData; + return mesh; } /* update modifier */ @@ -457,31 +458,36 @@ static DerivedMesh *doOcean( } if (omd->geometry_mode == MOD_OCEAN_GEOM_GENERATE) { - dm = generate_ocean_geometry(omd); - DM_ensure_normals(dm); + result = generate_ocean_geometry(omd); + BKE_mesh_ensure_normals(result); } else if (omd->geometry_mode == MOD_OCEAN_GEOM_DISPLACE) { - dm = CDDM_copy(derivedData); + BKE_id_copy_ex(NULL, &mesh->id, (ID **)&result, + LIB_ID_CREATE_NO_MAIN | + LIB_ID_CREATE_NO_USER_REFCOUNT | + LIB_ID_CREATE_NO_DEG_TAG | + LIB_ID_COPY_NO_PREVIEW, + false); } cfra = scene->r.cfra; CLAMP(cfra, omd->bakestart, omd->bakeend); cfra -= omd->bakestart; /* shift to 0 based */ - mverts = dm->getVertArray(dm); + mverts = result->mvert; /* add vcols before displacement - allows lookup based on position */ if (omd->flag & MOD_OCEAN_GENERATE_FOAM) { - if (CustomData_number_of_layers(&dm->loopData, CD_MLOOPCOL) < MAX_MCOL) { - const int num_polys = dm->getNumPolys(dm); - const int num_loops = dm->getNumLoops(dm); - MLoop *mloops = dm->getLoopArray(dm); + if (CustomData_number_of_layers(&result->ldata, CD_MLOOPCOL) < MAX_MCOL) { + const int num_polys = result->totpoly; + const int num_loops = result->totloop; + MLoop *mloops = result->mloop; MLoopCol *mloopcols = CustomData_add_layer_named( - &dm->loopData, CD_MLOOPCOL, CD_CALLOC, NULL, num_loops, omd->foamlayername); + &result->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, num_loops, omd->foamlayername); if (mloopcols) { /* unlikely to fail */ - MPoly *mpolys = dm->getPolyArray(dm); + MPoly *mpolys = result->mpoly; MPoly *mp; for (i = 0, mp = mpolys; i < num_polys; i++, mp++) { @@ -518,7 +524,7 @@ static DerivedMesh *doOcean( /* Note: tried to parallelized that one and previous foam loop, but gives 20% slower results... odd. */ { - const int num_verts = dm->getNumVerts(dm); + const int num_verts = result->totvert; for (i = 0; i < num_verts; i++) { float *vco = mverts[i].co; @@ -543,31 +549,30 @@ static DerivedMesh *doOcean( #undef OCEAN_CO - return dm; + return result; } #else /* WITH_OCEANSIM */ -static DerivedMesh *doOcean( +static Mesh *doOcean( ModifierData *UNUSED(md), Scene *UNUSED(scene), Object *UNUSED(ob), - DerivedMesh *derivedData, + Mesh *mesh, int UNUSED(useRenderParams)) { - /* unused */ - return derivedData; + return mesh; } #endif /* WITH_OCEANSIM */ -static DerivedMesh *applyModifier( +static Mesh *applyModifier( ModifierData *md, const ModifierEvalContext *ctx, - DerivedMesh *derivedData) + Mesh *mesh) { - DerivedMesh *result; + Mesh *result; Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); - result = doOcean(md, scene, ctx->object, derivedData, 0); + result = doOcean(md, scene, ctx->object, mesh, 0); - if (result != derivedData) - result->dirty |= DM_DIRTY_NORMALS; + if (result != mesh) + result->runtime.cd_dirty_vert |= CD_MASK_NORMAL; return result; } @@ -588,14 +593,14 @@ ModifierTypeInfo modifierType_Ocean = { /* deformVerts_DM */ NULL, /* deformVertsEM_DM */ NULL, /* deformMatricesEM_DM*/NULL, - /* applyModifier_DM */ applyModifier, + /* applyModifier_DM */ NULL, /* applyModifierEM_DM */NULL, /* deformVerts */ NULL, /* deformMatrices */ NULL, /* deformVertsEM */ NULL, /* deformMatricesEM */ NULL, - /* applyModifier */ NULL, + /* applyModifier */ applyModifier, /* applyModifierEM */ NULL, /* initData */ initData, -- cgit v1.2.3 From de55ae56ae5d871b5bc7fa6383c90ef89d66fcd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 5 Jul 2018 16:23:35 +0200 Subject: Ocean Modifier: refactored the delayed-refresh approach The approach of setting 'refresh' flags on the modifier, and performing the associated actions when the modifier is being evaluated, is a bad one. Instead, we use the separation of the original and the evaluated copy to 'refresh' certain things (because they simply aren't set at all on the original). Other actions are now done directly with BKE_ocean_xxx functions on the original data, intead of during evaluation. --- source/blender/modifiers/intern/MOD_ocean.c | 56 ++++++++--------------------- 1 file changed, 14 insertions(+), 42 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 26011cfc121..b4c028a44e3 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -61,13 +61,6 @@ static void init_cache_data(Object *ob, struct OceanModifierData *omd) omd->chop_amount, omd->foam_coverage, omd->foam_fade, omd->resolution); } -static void clear_cache_data(struct OceanModifierData *omd) -{ - BKE_ocean_free_cache(omd->oceancache); - omd->oceancache = NULL; - omd->cached = false; -} - /* keep in sync with init_ocean_modifier_bake(), object_modifier.c */ static void init_ocean_modifier(struct OceanModifierData *omd) { @@ -91,8 +84,6 @@ static void init_ocean_modifier(struct OceanModifierData *omd) static void simulate_ocean_modifier(struct OceanModifierData *omd) { - if (!omd || !omd->ocean) return; - BKE_ocean_simulate(omd->ocean, omd->time, omd->wave_scale, omd->chop_amount); } #endif /* WITH_OCEANSIM */ @@ -126,8 +117,6 @@ static void initData(ModifierData *md) omd->seed = 0; omd->time = 1.0; - omd->refresh = 0; - omd->size = 1.0; omd->repeat_x = 1; omd->repeat_y = 1; @@ -174,10 +163,8 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla modifier_copyData_generic(md, target, flag); - tomd->refresh = 0; - - /* XXX todo: copy cache runtime too */ - tomd->cached = 0; + /* The oceancache object will be recreated for this copy + * automatically when cached=true */ tomd->oceancache = NULL; tomd->ocean = BKE_ocean_add(); @@ -409,19 +396,18 @@ static Mesh *generate_ocean_geometry(OceanModifierData *omd) return result; } -static Mesh *doOcean( - ModifierData *md, Scene *scene, Object *ob, - Mesh *mesh, - int UNUSED(useRenderParams)) +static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh) { OceanModifierData *omd = (OceanModifierData *) md; + int cfra_scene = (int)DEG_get_ctime(ctx->depsgraph); + Object *ob = ctx->object; Mesh *result = NULL; OceanResult ocr; MVert *mverts; - int cfra; + int cfra_for_cache; int i, j; /* use cached & inverted value for speed @@ -437,21 +423,12 @@ static Mesh *doOcean( return mesh; } - /* update modifier */ - if (omd->refresh & MOD_OCEAN_REFRESH_RESET) { - init_ocean_modifier(omd); - } - if (omd->refresh & MOD_OCEAN_REFRESH_CLEAR_CACHE) { - clear_cache_data(omd); - } - omd->refresh = 0; - /* do ocean simulation */ if (omd->cached == true) { if (!omd->oceancache) { init_cache_data(ob, omd); } - BKE_ocean_simulate_cache(omd->oceancache, scene->r.cfra); + BKE_ocean_simulate_cache(omd->oceancache, cfra_scene); } else { simulate_ocean_modifier(omd); @@ -470,9 +447,9 @@ static Mesh *doOcean( false); } - cfra = scene->r.cfra; - CLAMP(cfra, omd->bakestart, omd->bakeend); - cfra -= omd->bakestart; /* shift to 0 based */ + cfra_for_cache = cfra_scene; + CLAMP(cfra_for_cache, omd->bakestart, omd->bakeend); + cfra_for_cache -= omd->bakestart; /* shift to 0 based */ mverts = result->mvert; @@ -501,7 +478,7 @@ static Mesh *doOcean( float foam; if (omd->oceancache && omd->cached == true) { - BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v); + BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v); foam = ocr.foam; CLAMP(foam, 0.0f, 1.0f); } @@ -532,7 +509,7 @@ static Mesh *doOcean( const float v = OCEAN_CO(size_co_inv, vco[1]); if (omd->oceancache && omd->cached == true) { - BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v); + BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v); } else { BKE_ocean_eval_uv(omd->ocean, &ocr, u, v); @@ -552,10 +529,7 @@ static Mesh *doOcean( return result; } #else /* WITH_OCEANSIM */ -static Mesh *doOcean( - ModifierData *UNUSED(md), Scene *UNUSED(scene), Object *UNUSED(ob), - Mesh *mesh, - int UNUSED(useRenderParams)) +static Mesh *doOcean(ModifierData *UNUSED(md), const ModifierEvalContext *UNUSED(ctx), Mesh *mesh) { return mesh; } @@ -566,10 +540,8 @@ static Mesh *applyModifier( Mesh *mesh) { Mesh *result; - Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); - - result = doOcean(md, scene, ctx->object, mesh, 0); + result = doOcean(md, ctx, mesh); if (result != mesh) result->runtime.cd_dirty_vert |= CD_MASK_NORMAL; -- cgit v1.2.3 From 0c8452ad99035fa560a1c19a3b4a404bdbbd9ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 10 Jul 2018 11:57:01 +0200 Subject: Ocean Modifier: removed duplicated code Some code was copied with 'keep in sync with xxx' comments added to it. --- source/blender/modifiers/intern/MOD_ocean.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index b4c028a44e3..5aafd9b1877 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -61,27 +61,6 @@ static void init_cache_data(Object *ob, struct OceanModifierData *omd) omd->chop_amount, omd->foam_coverage, omd->foam_fade, omd->resolution); } -/* keep in sync with init_ocean_modifier_bake(), object_modifier.c */ -static void init_ocean_modifier(struct OceanModifierData *omd) -{ - int do_heightfield, do_chop, do_normals, do_jacobian; - - if (!omd || !omd->ocean) return; - - do_heightfield = true; - do_chop = (omd->chop_amount > 0); - do_normals = (omd->flag & MOD_OCEAN_GENERATE_NORMALS); - do_jacobian = (omd->flag & MOD_OCEAN_GENERATE_FOAM); - - BKE_ocean_free_data(omd->ocean); - BKE_ocean_init(omd->ocean, omd->resolution * omd->resolution, omd->resolution * omd->resolution, - omd->spatial_size, omd->spatial_size, - omd->wind_velocity, omd->smallest_wave, 1.0, omd->wave_direction, omd->damp, omd->wave_alignment, - omd->depth, omd->time, - do_heightfield, do_chop, do_normals, do_jacobian, - omd->seed); -} - static void simulate_ocean_modifier(struct OceanModifierData *omd) { BKE_ocean_simulate(omd->ocean, omd->time, omd->wave_scale, omd->chop_amount); @@ -131,7 +110,7 @@ static void initData(ModifierData *md) omd->foamlayername[0] = '\0'; /* layer name empty by default */ omd->ocean = BKE_ocean_add(); - init_ocean_modifier(omd); + BKE_ocean_init_from_modifier(omd->ocean, omd); simulate_ocean_modifier(omd); #else /* WITH_OCEANSIM */ /* unused */ @@ -168,7 +147,7 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla tomd->oceancache = NULL; tomd->ocean = BKE_ocean_add(); - init_ocean_modifier(tomd); + BKE_ocean_init_from_modifier(tomd->ocean, tomd); simulate_ocean_modifier(tomd); #else /* WITH_OCEANSIM */ /* unused */ -- cgit v1.2.3 From 25619443bba4b9dda8e6194662683e91be99b247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 10 Jul 2018 11:58:01 +0200 Subject: Ocean Modifier: prevent crashing on 'Apply Modifier' button The 'Apply Modifier' button calls the modifier code on the original object instead of an evaluated copy, which doesn't have an initialised Ocean *. --- source/blender/modifiers/intern/MOD_ocean.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 5aafd9b1877..12845b27166 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -380,6 +380,7 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes OceanModifierData *omd = (OceanModifierData *) md; int cfra_scene = (int)DEG_get_ctime(ctx->depsgraph); Object *ob = ctx->object; + bool allocated_ocean = false; Mesh *result = NULL; OceanResult ocr; @@ -410,6 +411,12 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes BKE_ocean_simulate_cache(omd->oceancache, cfra_scene); } else { + /* omd->ocean is NULL on an original object (in contrast to an evaluated one). + * We can create a new one, but we have to free it as well once we're done. + * This function is only called on an original object when applying the modifier + * using the 'Apply Modifier' button, and thus it is not called frequently for + * simulation. */ + allocated_ocean |= BKE_ocean_ensure(omd); simulate_ocean_modifier(omd); } @@ -503,6 +510,11 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes } } + if (allocated_ocean) { + BKE_ocean_free(omd->ocean); + omd->ocean = NULL; + } + #undef OCEAN_CO return result; -- cgit v1.2.3 From e4ce5fd8d2e8d38ebdac5b1caf779a3c1dedfd52 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 10 Jul 2018 12:14:08 +0200 Subject: Modifiers: Use bool for boolean flag in isDisabled --- source/blender/modifiers/intern/MOD_armature.c | 2 +- source/blender/modifiers/intern/MOD_boolean.c | 2 +- source/blender/modifiers/intern/MOD_cast.c | 2 +- source/blender/modifiers/intern/MOD_curve.c | 2 +- source/blender/modifiers/intern/MOD_datatransfer.c | 2 +- source/blender/modifiers/intern/MOD_displace.c | 2 +- source/blender/modifiers/intern/MOD_hook.c | 2 +- source/blender/modifiers/intern/MOD_laplaciandeform.c | 2 +- source/blender/modifiers/intern/MOD_laplaciansmooth.c | 4 ++-- source/blender/modifiers/intern/MOD_lattice.c | 2 +- source/blender/modifiers/intern/MOD_meshcache.c | 2 +- source/blender/modifiers/intern/MOD_meshdeform.c | 2 +- source/blender/modifiers/intern/MOD_meshsequencecache.c | 2 +- source/blender/modifiers/intern/MOD_none.c | 2 +- source/blender/modifiers/intern/MOD_normal_edit.c | 2 +- source/blender/modifiers/intern/MOD_particleinstance.c | 2 +- source/blender/modifiers/intern/MOD_shrinkwrap.c | 2 +- source/blender/modifiers/intern/MOD_smooth.c | 2 +- source/blender/modifiers/intern/MOD_subsurf.c | 2 +- source/blender/modifiers/intern/MOD_surfacedeform.c | 2 +- source/blender/modifiers/intern/MOD_warp.c | 2 +- source/blender/modifiers/intern/MOD_weightvgedit.c | 2 +- source/blender/modifiers/intern/MOD_weightvgmix.c | 2 +- source/blender/modifiers/intern/MOD_weightvgproximity.c | 2 +- 24 files changed, 25 insertions(+), 25 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c index a069b261067..c44b65dffec 100644 --- a/source/blender/modifiers/intern/MOD_armature.c +++ b/source/blender/modifiers/intern/MOD_armature.c @@ -85,7 +85,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED( return dataMask; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { ArmatureModifierData *amd = (ArmatureModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c index 6cea7b8fece..db1078fa677 100644 --- a/source/blender/modifiers/intern/MOD_boolean.c +++ b/source/blender/modifiers/intern/MOD_boolean.c @@ -76,7 +76,7 @@ static void initData(ModifierData *md) bmd->double_threshold = 1e-6f; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { BooleanModifierData *bmd = (BooleanModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_cast.c b/source/blender/modifiers/intern/MOD_cast.c index cd6cd709b1d..a0901b6d838 100644 --- a/source/blender/modifiers/intern/MOD_cast.c +++ b/source/blender/modifiers/intern/MOD_cast.c @@ -63,7 +63,7 @@ static void initData(ModifierData *md) cmd->object = NULL; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { CastModifierData *cmd = (CastModifierData *) md; short flag; diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c index e90ff939b68..b74b63e2478 100644 --- a/source/blender/modifiers/intern/MOD_curve.c +++ b/source/blender/modifiers/intern/MOD_curve.c @@ -71,7 +71,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static bool isDisabled(const Scene *UNUSED(scene), ModifierData *md, int UNUSED(userRenderParams)) +static bool isDisabled(const Scene *UNUSED(scene), ModifierData *md, bool UNUSED(userRenderParams)) { CurveModifierData *cmd = (CurveModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_datatransfer.c b/source/blender/modifiers/intern/MOD_datatransfer.c index 8e025059d6c..ac45ce8732d 100644 --- a/source/blender/modifiers/intern/MOD_datatransfer.c +++ b/source/blender/modifiers/intern/MOD_datatransfer.c @@ -133,7 +133,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { DataTransferModifierData *dtmd = (DataTransferModifierData *) md; /* If no source object, bypass. */ diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c index ac8fb91bc8d..1b8b7120058 100644 --- a/source/blender/modifiers/intern/MOD_displace.c +++ b/source/blender/modifiers/intern/MOD_displace.c @@ -138,7 +138,7 @@ static void foreachTexLink( walk(userData, ob, md, "texture"); } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { DisplaceModifierData *dmd = (DisplaceModifierData *) md; return ((!dmd->texture && dmd->direction == MOD_DISP_DIR_RGB_XYZ) || dmd->strength == 0.0f); diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c index 4b34bdd2c16..a1629d8c1f2 100644 --- a/source/blender/modifiers/intern/MOD_hook.c +++ b/source/blender/modifiers/intern/MOD_hook.c @@ -96,7 +96,7 @@ static void freeData(ModifierData *md) MEM_SAFE_FREE(hmd->indexar); } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { HookModifierData *hmd = (HookModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c index 0224d412ba6..2406739e6df 100644 --- a/source/blender/modifiers/intern/MOD_laplaciandeform.c +++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c @@ -715,7 +715,7 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla tlmd->cache_system = NULL; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md; if (lmd->anchor_grp_name[0]) return 0; diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c index 580de4b1572..19838a2b637 100644 --- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c +++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c @@ -81,7 +81,7 @@ struct BLaplacianSystem { typedef struct BLaplacianSystem LaplacianSystem; static CustomDataMask required_data_mask(Object *ob, ModifierData *md); -static bool is_disabled(const struct Scene *UNUSED(scene), ModifierData *md, int useRenderParams); +static bool is_disabled(const struct Scene *UNUSED(scene), ModifierData *md, bool useRenderParams); static float compute_volume(const float center[3], float (*vertexCos)[3], const MPoly *mpoly, int numPolys, const MLoop *mloop); static LaplacianSystem *init_laplacian_system(int a_numEdges, int a_numPolys, int a_numLoops, int a_numVerts); static void delete_laplacian_system(LaplacianSystem *sys); @@ -474,7 +474,7 @@ static void init_data(ModifierData *md) smd->defgrp_name[0] = '\0'; } -static bool is_disabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool is_disabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { LaplacianSmoothModifierData *smd = (LaplacianSmoothModifierData *) md; short flag; diff --git a/source/blender/modifiers/intern/MOD_lattice.c b/source/blender/modifiers/intern/MOD_lattice.c index 540876ac339..3acd39bf19d 100644 --- a/source/blender/modifiers/intern/MOD_lattice.c +++ b/source/blender/modifiers/intern/MOD_lattice.c @@ -67,7 +67,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(userRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(userRenderParams)) { LatticeModifierData *lmd = (LatticeModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c index 9d6dfc0e1eb..8d2ac001e2d 100644 --- a/source/blender/modifiers/intern/MOD_meshcache.c +++ b/source/blender/modifiers/intern/MOD_meshcache.c @@ -72,7 +72,7 @@ static bool dependsOnTime(ModifierData *md) return (mcmd->play_mode == MOD_MESHCACHE_PLAY_CFEA); } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { MeshCacheModifierData *mcmd = (MeshCacheModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index 05e1568f780..9bfbbc4e44e 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -109,7 +109,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { MeshDeformModifierData *mmd = (MeshDeformModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c index fd8676d6653..cef55bf467b 100644 --- a/source/blender/modifiers/intern/MOD_meshsequencecache.c +++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c @@ -79,7 +79,7 @@ static void freeData(ModifierData *md) } } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_none.c b/source/blender/modifiers/intern/MOD_none.c index c973bd18830..7a6a5b94b8e 100644 --- a/source/blender/modifiers/intern/MOD_none.c +++ b/source/blender/modifiers/intern/MOD_none.c @@ -43,7 +43,7 @@ * no other functions will be called */ -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *UNUSED(md), int UNUSED(userRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *UNUSED(md), bool UNUSED(userRenderParams)) { return true; } diff --git a/source/blender/modifiers/intern/MOD_normal_edit.c b/source/blender/modifiers/intern/MOD_normal_edit.c index ae67296dda7..14af389668c 100644 --- a/source/blender/modifiers/intern/MOD_normal_edit.c +++ b/source/blender/modifiers/intern/MOD_normal_edit.c @@ -524,7 +524,7 @@ static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, walk(userData, ob, &enmd->target, IDWALK_CB_NOP); } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { NormalEditModifierData *enmd = (NormalEditModifierData *)md; diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c index bb6ed8e8344..edafcd6fcb9 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.c +++ b/source/blender/modifiers/intern/MOD_particleinstance.c @@ -88,7 +88,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) } -static bool isDisabled(const struct Scene *scene, ModifierData *md, int useRenderParams) +static bool isDisabled(const struct Scene *scene, ModifierData *md, bool useRenderParams) { ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md; ParticleSystem *psys; diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c index 72c1c1552c7..5497673a52d 100644 --- a/source/blender/modifiers/intern/MOD_shrinkwrap.c +++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c @@ -84,7 +84,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { ShrinkwrapModifierData *smd = (ShrinkwrapModifierData *) md; return !smd->target; diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c index 280a795fae8..29508524f9c 100644 --- a/source/blender/modifiers/intern/MOD_smooth.c +++ b/source/blender/modifiers/intern/MOD_smooth.c @@ -61,7 +61,7 @@ static void initData(ModifierData *md) smd->defgrp_name[0] = '\0'; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { SmoothModifierData *smd = (SmoothModifierData *) md; short flag; diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c index 5a5b596eaab..f532c168b04 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.c +++ b/source/blender/modifiers/intern/MOD_subsurf.c @@ -91,7 +91,7 @@ static void freeData(ModifierData *md) } } -static bool isDisabled(const Scene *scene, ModifierData *md, int useRenderParams) +static bool isDisabled(const Scene *scene, ModifierData *md, bool useRenderParams) { SubsurfModifierData *smd = (SubsurfModifierData *) md; int levels = (useRenderParams) ? smd->renderLevels : smd->levels; diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c index 0c58d47d53f..6dbeed9b4c8 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.c +++ b/source/blender/modifiers/intern/MOD_surfacedeform.c @@ -1195,7 +1195,7 @@ static void deformVertsEM( surfacedeformModifier_do(md, ctx, vertexCos, numVerts, ctx->object); } -static bool isDisabled(const Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md; diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c index 69bf44d8b68..a8f305bcc13 100644 --- a/source/blender/modifiers/intern/MOD_warp.c +++ b/source/blender/modifiers/intern/MOD_warp.c @@ -109,7 +109,7 @@ static void freeData(ModifierData *md) } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(userRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(userRenderParams)) { WarpModifierData *wmd = (WarpModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c index a2f9319ad51..a34ed1baaff 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.c +++ b/source/blender/modifiers/intern/MOD_weightvgedit.c @@ -148,7 +148,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md; /* If no vertex group, bypass. */ diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c index 90bd5acff62..b6a7228b171 100644 --- a/source/blender/modifiers/intern/MOD_weightvgmix.c +++ b/source/blender/modifiers/intern/MOD_weightvgmix.c @@ -185,7 +185,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { WeightVGMixModifierData *wmd = (WeightVGMixModifierData *) md; /* If no vertex group, bypass. */ diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 88e33f28eaf..05b1ec19253 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -358,7 +358,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md; /* If no vertex group, bypass. */ -- cgit v1.2.3 From 5fd677c83c80aa33cac9f4fe47dc149e61b96f67 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 17 Jul 2018 18:09:18 +0200 Subject: Subsurf: Add subdivision code which uses new module The code is ifdef-ed for now, since there is more work needed to be done before we can officially switch to it. Uses new subdiv module. --- source/blender/modifiers/intern/MOD_subsurf.c | 75 ++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c index f532c168b04..c92845a24eb 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.c +++ b/source/blender/modifiers/intern/MOD_subsurf.c @@ -35,8 +35,9 @@ #include -#include "DNA_scene_types.h" #include "DNA_object_types.h" +#include "DNA_scene_types.h" +#include "DNA_mesh_types.h" #ifdef WITH_OPENSUBDIV # include "DNA_userdef_types.h" @@ -44,9 +45,9 @@ #include "BLI_utildefines.h" - #include "BKE_cdderivedmesh.h" #include "BKE_scene.h" +#include "BKE_subdiv.h" #include "BKE_subsurf.h" #include "DEG_depsgraph.h" @@ -56,6 +57,8 @@ #include "intern/CCGSubSurf.h" +// #define USE_OPENSUBDIV + static void initData(ModifierData *md) { SubsurfModifierData *smd = (SubsurfModifierData *) md; @@ -181,9 +184,73 @@ static DerivedMesh *applyModifierEM( #endif result = subsurf_make_derived_from_derived(derivedData, smd, scene, NULL, ss_flags); + return result; +} + +#ifdef USE_OPENSUBDIV +static int subdiv_levels_for_modifier_get(const SubsurfModifierData *smd, + const ModifierEvalContext *ctx) +{ + Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); + const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER); + const int requested_levels = (use_render_params) ? smd->renderLevels + : smd->levels; + return get_render_subsurf_level(&scene->r, + requested_levels, + use_render_params); +} + +static void subdiv_settings_init(SubdivSettings *settings, + const SubsurfModifierData *smd, + const ModifierEvalContext *ctx) +{ + settings->is_simple = (smd->subdivType == SUBSURF_TYPE_SIMPLE); + settings->is_adaptive = !settings->is_simple; + settings->level = subdiv_levels_for_modifier_get(smd, ctx); + settings->fvar_linear_interpolation = + (smd->flags & eSubsurfModifierFlag_SubsurfUv) + ? SUBDIV_FVAR_LINEAR_INTERPOLATION_CORNERS_ONLY + : SUBDIV_FVAR_LINEAR_INTERPOLATION_ALL; +} + +static void subdiv_mesh_settings_init(SubdivToMeshSettings *settings, + const SubdivSettings *subdiv_settings) +{ + settings->resolution = (1 << subdiv_settings->level) + 1; +} +static Mesh *applyModifier_subdiv(ModifierData *md, + const ModifierEvalContext *ctx, + Mesh *mesh) +{ + Mesh *result = mesh; + SubsurfModifierData *smd = (SubsurfModifierData *) md; + SubdivSettings subdiv_settings; + subdiv_settings_init(&subdiv_settings, smd, ctx); + if (subdiv_settings.level == 0) { + /* NOTE: Shouldn't really happen, is supposed to be catched by + * isDisabled() callback. + */ + return result; + } + /* TODO(sergey): Try to re-use subdiv when possible. */ + Subdiv *subdiv = BKE_subdiv_new_from_mesh(&subdiv_settings, mesh); + if (subdiv == NULL) { + /* Happens on bad topology. */ + /* TODO(sergey): This also happens on meshes without faces, so probably + * need to handle those differently (i.e. set modifier error when + * topology itself is bad, and not do anything when there are no faces). + */ + return result; + } + SubdivToMeshSettings mesh_settings; + subdiv_mesh_settings_init(&mesh_settings, &subdiv_settings); + result = BKE_subdiv_to_mesh(subdiv, &mesh_settings, mesh); + /* TODO(sergey): Cache subdiv somehow. */ + BKE_subdiv_free(subdiv); return result; } +#endif static bool dependsOnNormals(ModifierData *md) { @@ -222,7 +289,11 @@ ModifierTypeInfo modifierType_Subsurf = { /* deformMatrices */ NULL, /* deformVertsEM */ NULL, /* deformMatricesEM */ NULL, +#ifdef USE_OPENSUBDIV + /* applyModifier */ applyModifier_subdiv, +#else /* applyModifier */ NULL, +#endif /* applyModifierEM */ NULL, /* initData */ initData, -- cgit v1.2.3 From 8a42b3909f33d90b065eec2b8eb342df0a1fb659 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 19 Jul 2018 16:27:18 +0200 Subject: Subsurf: Add basic statistics to help benchmarking --- source/blender/modifiers/intern/MOD_subsurf.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c index c92845a24eb..08dc7c92693 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.c +++ b/source/blender/modifiers/intern/MOD_subsurf.c @@ -247,6 +247,7 @@ static Mesh *applyModifier_subdiv(ModifierData *md, subdiv_mesh_settings_init(&mesh_settings, &subdiv_settings); result = BKE_subdiv_to_mesh(subdiv, &mesh_settings, mesh); /* TODO(sergey): Cache subdiv somehow. */ + // BKE_subdiv_stats_print(&subdiv->stats); BKE_subdiv_free(subdiv); return result; } -- cgit v1.2.3