From f7727b5366f74596ae21dcd878856e2c2ba1b99b Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 8 May 2018 18:41:43 +0200 Subject: Modifier stack: Port Warp to new Mesh-based system. --- source/blender/modifiers/intern/MOD_warp.c | 63 ++++++++++++++---------------- 1 file changed, 29 insertions(+), 34 deletions(-) (limited to 'source/blender/modifiers/intern/MOD_warp.c') diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c index 07babc5b12f..34e69f570d5 100644 --- a/source/blender/modifiers/intern/MOD_warp.c +++ b/source/blender/modifiers/intern/MOD_warp.c @@ -29,14 +29,17 @@ #include "MEM_guardedalloc.h" -#include "DNA_object_types.h" +#include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" +#include "DNA_object_types.h" #include "BLI_math.h" #include "BLI_utildefines.h" -#include "BKE_cdderivedmesh.h" +#include "BKE_editmesh.h" +#include "BKE_library.h" #include "BKE_library_query.h" +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_deform.h" #include "BKE_texture.h" @@ -146,7 +149,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } static void warpModifier_do(WarpModifierData *wmd, Object *ob, - DerivedMesh *dm, float (*vertexCos)[3], int numVerts) + Mesh *mesh, float (*vertexCos)[3], int numVerts) { float obinv[4][4]; float mat_from[4][4]; @@ -169,7 +172,7 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob, if (!(wmd->object_from && wmd->object_to)) return; - modifier_get_vgroup(ob, dm, wmd->defgrp_name, &dvert, &defgrp_index); + modifier_get_vgroup_mesh(ob, mesh, wmd->defgrp_name, &dvert, &defgrp_index); if (dvert == NULL) { defgrp_index = -1; } @@ -207,7 +210,7 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob, if (wmd->texture) { tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "warpModifier_do tex_co"); - get_texture_coords((MappingInfoModifierData *)wmd, ob, dm, vertexCos, tex_co, numVerts); + get_texture_coords_mesh((MappingInfoModifierData *)wmd, ob, mesh, vertexCos, tex_co); modifier_init_texture(wmd->modifier.scene, wmd->texture); } @@ -295,48 +298,40 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob, } } - if (tex_co) + if (tex_co) { MEM_freeN(tex_co); - -} - -static int warp_needs_dm(WarpModifierData *wmd) -{ - return wmd->texture || wmd->defgrp_name[0]; + } } -static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, DerivedMesh *derivedData, +static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, float (*vertexCos)[3], int numVerts) { - DerivedMesh *dm = NULL; - int use_dm = warp_needs_dm((WarpModifierData *)md); + Mesh *mesh_src = mesh; - if (use_dm) { - dm = get_cddm(ctx->object, NULL, derivedData, vertexCos, false); + if (mesh_src == NULL) { + mesh_src = ctx->object->data; } - warpModifier_do((WarpModifierData *)md, ctx->object, dm, vertexCos, numVerts); + BLI_assert(mesh_src->totvert == numVerts); - if (use_dm) { - if (dm != derivedData) dm->release(dm); - } + warpModifier_do((WarpModifierData *)md, ctx->object, mesh_src, vertexCos, numVerts); } static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em, - DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) + Mesh *mesh, float (*vertexCos)[3], int numVerts) { - DerivedMesh *dm = derivedData; - int use_dm = warp_needs_dm((WarpModifierData *)md); + Mesh *mesh_src = mesh; - if (use_dm) { - if (!derivedData) - dm = CDDM_from_editbmesh(em, false, false); + if (mesh_src == NULL) { + mesh_src = BKE_bmesh_to_mesh_nomain(em->bm, &(struct BMeshToMeshParams){0}); } - deformVerts(md, ctx, dm, vertexCos, numVerts); + BLI_assert(mesh_src->totvert == numVerts); + + warpModifier_do((WarpModifierData *)md, ctx->object, mesh_src, vertexCos, numVerts); - if (use_dm) { - if (!derivedData) dm->release(dm); + if (!mesh) { + BKE_id_free(NULL, mesh_src); } } @@ -351,16 +346,16 @@ ModifierTypeInfo modifierType_Warp = { eModifierTypeFlag_SupportsEditmode, /* copyData */ copyData, - /* deformVerts_DM */ deformVerts, + /* deformVerts_DM */ NULL, /* deformMatrices_DM */ NULL, - /* deformVertsEM_DM */ deformVertsEM, + /* deformVertsEM_DM */ NULL, /* deformMatricesEM_DM*/NULL, /* applyModifier_DM */ NULL, /* applyModifierEM_DM */NULL, - /* deformVerts */ NULL, + /* deformVerts */ deformVerts, /* deformMatrices */ NULL, - /* deformVertsEM */ NULL, + /* deformVertsEM */ deformVertsEM, /* deformMatricesEM */ NULL, /* applyModifier */ NULL, /* applyModifierEM */ NULL, -- cgit v1.2.3