diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2018-05-30 12:34:08 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2018-05-30 13:04:06 +0300 |
commit | 72f4ac99c70b02e095cc9a71d501d6b1dc85ac3e (patch) | |
tree | 940c598d4efb2246eb7b523840e2b7337a59bc1b /source/blender/modifiers/intern | |
parent | e55c1a9b5a089f3c688a0b47cba363cb0d6f92d0 (diff) |
Cleanup/fix wrong modifiers targets handling in COW context.
Modifiers stack only get COW/evaluated IDs, so no need to go auery again
DEG for those. Further more, now unified handling of EditBMesh case (was
done on case-by-case basis in a few modifiers, not all for some reason).
We are still missing the ability to get final and cage deformed meshes
when in Edit mode though, this is to be defined/implemented in depsgraph.
Diffstat (limited to 'source/blender/modifiers/intern')
-rw-r--r-- | source/blender/modifiers/intern/MOD_array.c | 12 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_boolean.c | 18 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_meshdeform.c | 36 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_shrinkwrap.c | 4 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_surfacedeform.c | 35 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_weightvgproximity.c | 7 |
6 files changed, 43 insertions, 69 deletions
diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c index e74d9087427..c1268157d58 100644 --- a/source/blender/modifiers/intern/MOD_array.c +++ b/source/blender/modifiers/intern/MOD_array.c @@ -49,6 +49,7 @@ #include "BKE_cdderivedmesh.h" #include "BKE_displist.h" #include "BKE_curve.h" +#include "BKE_library.h" #include "BKE_library_query.h" #include "BKE_modifier.h" #include "BKE_mesh.h" @@ -373,6 +374,7 @@ static Mesh *arrayModifier_doArray( int first_chunk_start, first_chunk_nverts, last_chunk_start, last_chunk_nverts; Mesh *result, *start_cap_mesh = NULL, *end_cap_mesh = NULL; + bool start_cap_mesh_free, end_cap_mesh_free; int *vgroup_start_cap_remap = NULL; int vgroup_start_cap_remap_len = 0; @@ -390,7 +392,7 @@ static Mesh *arrayModifier_doArray( vgroup_start_cap_remap = BKE_object_defgroup_index_map_create( amd->start_cap, ctx->object, &vgroup_start_cap_remap_len); - start_cap_mesh = BKE_modifier_get_evaluated_mesh_from_object(ctx, amd->start_cap); + start_cap_mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(amd->start_cap, &start_cap_mesh_free); if (start_cap_mesh) { start_cap_nverts = start_cap_mesh->totvert; start_cap_nedges = start_cap_mesh->totedge; @@ -402,7 +404,7 @@ static Mesh *arrayModifier_doArray( vgroup_end_cap_remap = BKE_object_defgroup_index_map_create( amd->end_cap, ctx->object, &vgroup_end_cap_remap_len); - end_cap_mesh = BKE_modifier_get_evaluated_mesh_from_object(ctx, amd->end_cap); + end_cap_mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(amd->end_cap, &end_cap_mesh_free); if (end_cap_mesh) { end_cap_nverts = end_cap_mesh->totvert; end_cap_nedges = end_cap_mesh->totedge; @@ -737,6 +739,12 @@ static Mesh *arrayModifier_doArray( if (vgroup_end_cap_remap) { MEM_freeN(vgroup_end_cap_remap); } + if (start_cap_mesh != NULL && start_cap_mesh_free) { + BKE_id_free(NULL, start_cap_mesh); + } + if (end_cap_mesh != NULL && end_cap_mesh_free) { + BKE_id_free(NULL, end_cap_mesh); + } return result; } diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c index 73d1388d88f..2b6f6cf8920 100644 --- a/source/blender/modifiers/intern/MOD_boolean.c +++ b/source/blender/modifiers/intern/MOD_boolean.c @@ -170,14 +170,16 @@ static int bm_face_isect_pair(BMFace *f, void *UNUSED(user_data)) static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh) { BooleanModifierData *bmd = (BooleanModifierData *) md; + Mesh *result; + Mesh *mesh_other; + bool mesh_other_free; if (!bmd->object) return mesh; - mesh_other = BKE_modifier_get_evaluated_mesh_from_object(ctx, bmd->object); + mesh_other = BKE_modifier_get_evaluated_mesh_from_evaluated_object(bmd->object, &mesh_other_free); if (mesh_other) { - Mesh *result; Object *object_eval = DEG_get_evaluated_object(ctx->depsgraph, ctx->object); Object *other_eval = DEG_get_evaluated_object(ctx->depsgraph, bmd->object); @@ -321,19 +323,19 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes #ifdef DEBUG_TIME TIMEIT_END(boolean_bmesh); #endif - - return result; } /* if new mesh returned, return it; otherwise there was * an error, so delete the modifier object */ - if (result) - return result; - else + if (result == NULL) modifier_setError(md, "Cannot execute boolean operation"); } - return mesh; + if (mesh_other != NULL && mesh_other_free) { + BKE_id_free(NULL, mesh_other); + } + + return result; } static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(md)) diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index 48653856178..e9e8c974413 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -275,10 +275,12 @@ static void meshdeform_vert_task( } static void meshdeformModifier_do( - ModifierData *md, Depsgraph *depsgraph, Object *ob, Mesh *mesh, + ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, float (*vertexCos)[3], int numVerts) { MeshDeformModifierData *mmd = (MeshDeformModifierData *) md; + Object *ob = ctx->object; + Mesh *cagemesh; MDeformVert *dvert = NULL; float imat[4][4], cagemat[4][4], iobmat[4][4], icagemat[3][3], cmat[4][4]; @@ -301,29 +303,9 @@ static void meshdeformModifier_do( * * We'll support this case once granular dependency graph is landed. */ - if (mmd->object->mode & OB_MODE_EDIT) { - BMEditMesh *em = BKE_editmesh_from_object(mmd->object); - cagemesh = BKE_bmesh_to_mesh_nomain(em->bm, &(struct BMeshToMeshParams){0}); - free_cagemesh = true; - } - else { - ModifierEvalContext ctx = { - .depsgraph = depsgraph, - .flag = md->mode & eModifierMode_Render ? MOD_APPLY_RENDER : 0, - }; - cagemesh = BKE_modifier_get_evaluated_mesh_from_object(&ctx, ob); - } - - /* if we don't have one computed, use derivedmesh from data - * without any modifiers */ - if (!cagemesh) { - cagemesh = get_mesh(mmd->object, NULL, NULL, NULL, false, false); - if (cagemesh) { - free_cagemesh = true; - } - } + cagemesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob, &free_cagemesh); - if (!cagemesh) { + if (cagemesh == NULL) { modifier_setError(md, "Cannot get mesh from cage object"); return; } @@ -412,7 +394,9 @@ static void meshdeformModifier_do( /* release cage derivedmesh */ MEM_freeN(dco); MEM_freeN(cagecos); - if (free_cagemesh) BKE_id_free(NULL, cagemesh); + if (cagemesh != NULL && free_cagemesh) { + BKE_id_free(NULL, cagemesh); + } } static void deformVerts( @@ -425,7 +409,7 @@ static void deformVerts( modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */ - meshdeformModifier_do(md, ctx->depsgraph, ctx->object, mesh_src, vertexCos, numVerts); + meshdeformModifier_do(md, ctx, mesh_src, vertexCos, numVerts); if (mesh_src && mesh_src != mesh) { BKE_id_free(NULL, mesh_src); @@ -441,7 +425,7 @@ static void deformVertsEM( { Mesh *mesh_src = get_mesh(ctx->object, NULL, mesh, NULL, false, false); - meshdeformModifier_do(md, ctx->depsgraph, ctx->object, mesh_src, vertexCos, numVerts); + meshdeformModifier_do(md, ctx, mesh_src, vertexCos, numVerts); if (mesh_src && mesh_src != mesh) { BKE_id_free(NULL, mesh_src); diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c index 1e503f41310..29f5815c733 100644 --- a/source/blender/modifiers/intern/MOD_shrinkwrap.c +++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c @@ -111,7 +111,7 @@ static void deformVerts( BLI_assert(mesh_src->totvert == numVerts); - shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ctx->object, mesh_src, vertexCos, numVerts, ctx); + shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ctx->object, mesh_src, vertexCos, numVerts); } static void deformVertsEM( @@ -127,7 +127,7 @@ static void deformVertsEM( BLI_assert(mesh_src->totvert == numVerts); - shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ctx->object, mesh_src, vertexCos, numVerts, ctx); + shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ctx->object, mesh_src, vertexCos, numVerts); if (!mesh) { BKE_id_free(NULL, mesh_src); diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c index f03ae73e2bb..c75f317e3bc 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.c +++ b/source/blender/modifiers/intern/MOD_surfacedeform.c @@ -1041,33 +1041,6 @@ static bool surfacedeformBind( return data.success == 1; } -static Mesh *surfacedeform_get_mesh(Depsgraph *depsgraph, SurfaceDeformModifierData *smd, bool *r_needsfree) -{ - Mesh *mesh; - - /* Handle target mesh both in and out of edit mode */ - if (smd->target->mode & OB_MODE_EDIT) { - BMEditMesh *em = BKE_editmesh_from_object(smd->target); - mesh = BKE_bmesh_to_mesh_nomain(em->bm, &(struct BMeshToMeshParams){0}); - *r_needsfree = true; - } - else { - ModifierEvalContext ctx = { - .depsgraph = depsgraph, - .flag = smd->modifier.mode & eModifierMode_Render ? MOD_APPLY_RENDER : 0, - }; - mesh = BKE_modifier_get_evaluated_mesh_from_object(&ctx, smd->target); - *r_needsfree = false; - } - - if (!mesh) { - mesh = get_mesh(smd->target, NULL, NULL, NULL, false, false); - *r_needsfree = true; - } - - return mesh; -} - static void deformVert( void *__restrict userdata, const int index, @@ -1127,7 +1100,7 @@ static void deformVert( static void surfacedeformModifier_do( ModifierData *md, - const ModifierEvalContext *ctx, + const ModifierEvalContext *UNUSED(ctx), float (*vertexCos)[3], unsigned int numverts, Object *ob) { SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md; @@ -1141,7 +1114,7 @@ static void surfacedeformModifier_do( return; } - target = surfacedeform_get_mesh(ctx->depsgraph, smd, &free_target); + target = BKE_modifier_get_evaluated_mesh_from_evaluated_object(smd->target, &free_target); if (!target) { modifier_setError(md, "No valid target mesh"); return; @@ -1200,7 +1173,9 @@ static void surfacedeformModifier_do( MEM_freeN(data.targetCos); } - if (free_target) BKE_id_free(NULL, target); + if (target != NULL && free_target) { + BKE_id_free(NULL, target); + } } static void deformVerts( diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 9e77e0d3794..4549e60a8d8 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -506,7 +506,8 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes const bool use_trgt_faces = (wmd->proximity_flags & MOD_WVG_PROXIMITY_GEOM_FACES) != 0; if (use_trgt_verts || use_trgt_edges || use_trgt_faces) { - Mesh *target_mesh = BKE_modifier_get_evaluated_mesh_from_object(ctx, obr); + bool target_mesh_free; + Mesh *target_mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(obr, &target_mesh_free); /* We must check that we do have a valid target_mesh! */ if (target_mesh != NULL) { @@ -529,6 +530,10 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes MEM_SAFE_FREE(dists_v); MEM_SAFE_FREE(dists_e); MEM_SAFE_FREE(dists_f); + + if (target_mesh_free) { + BKE_id_free(NULL, target_mesh); + } } /* Else, fall back to default obj2vert behavior. */ else { |