Merge branch 'master' into blender2.8
[blender.git] / source / blender / modifiers / intern / MOD_lattice.c
index 05abd6ebc9205d8fbaed09151d055e7172af2eb8..548480acdd8db1537b3121e1cf300202100297b6 100644 (file)
 
 #include "BLI_utildefines.h"
 
-#include "BKE_cdderivedmesh.h"
+#include "BKE_editmesh.h"
 #include "BKE_lattice.h"
+#include "BKE_library.h"
 #include "BKE_library_query.h"
+#include "BKE_mesh.h"
 #include "BKE_modifier.h"
 
-#include "depsgraph_private.h"
+#include "MEM_guardedalloc.h"
 
 #include "MOD_util.h"
 
@@ -81,18 +83,6 @@ static void foreachObjectLink(
        walk(userData, ob, &lmd->object, IDWALK_CB_NOP);
 }
 
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
-       LatticeModifierData *lmd = (LatticeModifierData *) md;
-
-       if (lmd->object) {
-               DagNode *latNode = dag_get_node(ctx->forest, lmd->object);
-
-               dag_add_relation(ctx->forest, latNode, ctx->obNode,
-                                DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Lattice Modifier");
-       }
-}
-
 static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
 {
        LatticeModifierData *lmd = (LatticeModifierData *)md;
@@ -103,32 +93,35 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
        DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Lattice Modifier");
 }
 
-static void deformVerts(ModifierData *md, Object *ob,
-                        DerivedMesh *derivedData,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
+                        struct Mesh *mesh,
                         float (*vertexCos)[3],
-                        int numVerts,
-                        ModifierApplyFlag UNUSED(flag))
+                        int numVerts)
 {
        LatticeModifierData *lmd = (LatticeModifierData *) md;
-
+       struct Mesh *mesh_src = mesh ? mesh : ctx->object->data;
 
        modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */
-       
-       lattice_deform_verts(lmd->object, ob, derivedData,
+
+       lattice_deform_verts(lmd->object, ctx->object, mesh_src,
                             vertexCos, numVerts, lmd->name, lmd->strength);
 }
 
 static void deformVertsEM(
-        ModifierData *md, Object *ob, struct BMEditMesh *em,
-        DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
+        ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em,
+        struct Mesh *mesh, float (*vertexCos)[3], int numVerts)
 {
-       DerivedMesh *dm = derivedData;
+       struct Mesh *mesh_src = mesh;
 
-       if (!derivedData) dm = CDDM_from_editbmesh(em, false, false);
+       if (!mesh) {
+               mesh_src = BKE_bmesh_to_mesh_nomain(em->bm, &(struct BMeshToMeshParams){0});
+       }
 
-       deformVerts(md, ob, dm, vertexCos, numVerts, 0);
+       deformVerts(md, ctx, mesh_src, vertexCos, numVerts);
 
-       if (!derivedData) dm->release(dm);
+       if (!mesh) {
+               BKE_id_free(NULL, mesh_src);
+       }
 }
 
 
@@ -140,18 +133,27 @@ ModifierTypeInfo modifierType_Lattice = {
        /* flags */             eModifierTypeFlag_AcceptsCVs |
                                eModifierTypeFlag_AcceptsLattice |
                                eModifierTypeFlag_SupportsEditmode,
+
        /* copyData */          modifier_copyData_generic,
+
+       /* deformVerts_DM */    NULL,
+       /* deformMatrices_DM */ NULL,
+       /* deformVertsEM_DM */  NULL,
+       /* deformMatricesEM_DM*/NULL,
+       /* applyModifier_DM */  NULL,
+       /* applyModifierEM_DM */NULL,
+
        /* deformVerts */       deformVerts,
        /* deformMatrices */    NULL,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  NULL,
        /* applyModifier */     NULL,
        /* applyModifierEM */   NULL,
+
        /* initData */          initData,
        /* requiredDataMask */  requiredDataMask,
        /* freeData */          NULL,
        /* isDisabled */        isDisabled,
-       /* updateDepgraph */    updateDepgraph,
        /* updateDepsgraph */   updateDepsgraph,
        /* dependsOnTime */     NULL,
        /* dependsOnNormals */  NULL,