diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_shrinkwrap.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/shrinkwrap.c | 22 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_shrinkwrap.c | 50 |
3 files changed, 43 insertions, 33 deletions
diff --git a/source/blender/blenkernel/BKE_shrinkwrap.h b/source/blender/blenkernel/BKE_shrinkwrap.h index 31b4b5cecc5..79e60b1a6a0 100644 --- a/source/blender/blenkernel/BKE_shrinkwrap.h +++ b/source/blender/blenkernel/BKE_shrinkwrap.h @@ -48,6 +48,7 @@ struct Object; struct DerivedMesh; +struct Mesh; struct MVert; struct MDeformVert; struct ShrinkwrapModifierData; @@ -69,6 +70,7 @@ typedef struct ShrinkwrapCalcData { int vgroup; //Vertex group num bool invert_vgroup; /* invert vertex group influence */ + /* TODO to be moved to Mesh once we are done with changes in BVHTree helper code. */ struct DerivedMesh *target; //mesh we are shrinking to struct SpaceTransform local2target; //transform to move between local and target space @@ -76,7 +78,7 @@ typedef struct ShrinkwrapCalcData { } ShrinkwrapCalcData; -void shrinkwrapModifier_deform(struct ShrinkwrapModifierData *smd, struct Object *ob, struct DerivedMesh *dm, +void shrinkwrapModifier_deform(struct ShrinkwrapModifierData *smd, struct Object *ob, struct Mesh *mesh, float (*vertexCos)[3], int numVerts, bool for_render); /* diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index bf22b106cf8..344751f7871 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -47,6 +47,7 @@ #include "BLI_task.h" #include "BKE_shrinkwrap.h" +#include "BKE_cdderivedmesh.h" #include "BKE_DerivedMesh.h" #include "BKE_lattice.h" @@ -616,7 +617,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) } /* Main shrinkwrap function */ -void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedMesh *dm, +void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, Mesh *mesh, float (*vertexCos)[3], int numVerts, bool for_render) { @@ -637,8 +638,8 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM /* DeformVertex */ calc.vgroup = defgroup_name_index(calc.ob, calc.smd->vgroup_name); - if (dm) { - calc.dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); + if (mesh) { + calc.dvert = mesh->dvert; } else if (calc.ob->type == OB_LATTICE) { calc.dvert = BKE_lattice_deform_verts_get(calc.ob); @@ -661,10 +662,10 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM calc.vgroup = defgroup_name_index(calc.ob, smd->vgroup_name); - if (dm != NULL && smd->shrinkType == MOD_SHRINKWRAP_PROJECT) { + if (mesh != NULL && smd->shrinkType == MOD_SHRINKWRAP_PROJECT) { /* Setup arrays to get vertexs positions, normals and deform weights */ - calc.vert = dm->getVertDataArray(dm, CD_MVERT); - calc.dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); + calc.vert = mesh->mvert; + calc.dvert = mesh->dvert; /* Using vertexs positions/normals as if a subsurface was applied */ if (smd->subsurfLevels) { @@ -672,6 +673,9 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM ssmd.subdivType = ME_CC_SUBSURF; /* catmull clark */ ssmd.levels = smd->subsurfLevels; /* levels */ + /* TODO to be moved to Mesh once we are done with changes in subsurf code. */ + DerivedMesh *dm = CDDM_from_mesh(mesh); + ss_mesh = subsurf_make_derived_from_derived(dm, &ssmd, NULL, (ob->mode & OB_MODE_EDIT) ? SUBSURF_IN_EDIT_MODE : 0); if (ss_mesh) { @@ -684,8 +688,10 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM } /* Just to make sure we are not leaving any memory behind */ - assert(ssmd.emCache == NULL); - assert(ssmd.mCache == NULL); + BLI_assert(ssmd.emCache == NULL); + BLI_assert(ssmd.mCache == NULL); + + dm->release(dm); } } diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c index b2077f62bf4..2d57b9d19d5 100644 --- a/source/blender/modifiers/intern/MOD_shrinkwrap.c +++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c @@ -35,13 +35,16 @@ #include <string.h> +#include "DNA_mesh_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_shrinkwrap.h" @@ -95,41 +98,40 @@ static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, } static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, - DerivedMesh *derivedData, + Mesh *mesh, float (*vertexCos)[3], int numVerts) { - DerivedMesh *dm = derivedData; - CustomDataMask dataMask = requiredDataMask(ctx->object, md); - bool forRender = (ctx->flag & MOD_APPLY_RENDER) != 0; + const bool forRender = (ctx->flag & MOD_APPLY_RENDER) != 0; - /* ensure we get a CDDM with applied vertex coords */ - if (dataMask) { - dm = get_cddm(ctx->object, NULL, dm, vertexCos, dependsOnNormals(md)); + Mesh *mesh_src = mesh; + + if (mesh_src == NULL) { + mesh_src = ctx->object->data; } - shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ctx->object, dm, vertexCos, numVerts, forRender); + BLI_assert(mesh_src->totvert == numVerts); - if (dm != derivedData) - dm->release(dm); + shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ctx->object, mesh_src, vertexCos, numVerts, forRender); } static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, - struct BMEditMesh *editData, DerivedMesh *derivedData, + struct BMEditMesh *editData, Mesh *mesh, float (*vertexCos)[3], int numVerts) { - DerivedMesh *dm = derivedData; - CustomDataMask dataMask = requiredDataMask(ctx->object, md); + Mesh *mesh_src = mesh; - /* ensure we get a CDDM with applied vertex coords */ - if (dataMask) { - dm = get_cddm(ctx->object, editData, dm, vertexCos, dependsOnNormals(md)); + if (mesh_src == NULL) { + mesh_src = BKE_bmesh_to_mesh_nomain(editData->bm, &(struct BMeshToMeshParams){0}); } - shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ctx->object, dm, vertexCos, numVerts, false); + BLI_assert(mesh_src->totvert == numVerts); + + shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ctx->object, mesh_src, vertexCos, numVerts, false); - if (dm != derivedData) - dm->release(dm); + if (!mesh) { + BKE_id_free(NULL, mesh_src); + } } static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx) @@ -168,16 +170,16 @@ ModifierTypeInfo modifierType_Shrinkwrap = { /* copyData */ modifier_copyData_generic, - /* 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, |