Merge branch 'master' into blender2.8
[blender.git] / source / blender / modifiers / intern / MOD_curve.c
index 91772faa08bf2e3f728175e3330b17aca97c798e..805d27de2736549eab21cf4640ae7d6bcde5b438 100644 (file)
 
 #include <string.h>
 
+#include "DNA_mesh_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
 
 #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 "DEG_depsgraph.h"
 #include "DEG_depsgraph_build.h"
 
 #include "MOD_modifiertypes.h"
@@ -83,19 +86,6 @@ static void foreachObjectLink(
        walk(userData, ob, &cmd->object, IDWALK_CB_NOP);
 }
 
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
-       CurveModifierData *cmd = (CurveModifierData *) md;
-
-       if (cmd->object) {
-               DagNode *curNode = dag_get_node(ctx->forest, cmd->object);
-               curNode->eval_flags |= DAG_EVAL_NEED_CURVE_PATH;
-
-               dag_add_relation(ctx->forest, curNode, ctx->obNode,
-                                DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Modifier");
-       }
-}
-
 static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
 {
        CurveModifierData *cmd = (CurveModifierData *)md;
@@ -114,31 +104,49 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
        DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Curve Modifier");
 }
 
-static void deformVerts(ModifierData *md, Object *ob,
-                        DerivedMesh *derivedData,
-                        float (*vertexCos)[3],
-                        int numVerts,
-                        ModifierApplyFlag UNUSED(flag))
+static void deformVerts(
+        ModifierData *md,
+        const ModifierEvalContext *ctx,
+        Mesh *mesh,
+        float (*vertexCos)[3],
+        int numVerts)
 {
        CurveModifierData *cmd = (CurveModifierData *) md;
 
+       Mesh *mesh_src = mesh;
+
+       if (mesh_src == NULL) {
+               mesh_src = ctx->object->data;
+       }
+
+       BLI_assert(mesh_src->totvert == numVerts);
+
        /* silly that defaxis and curve_deform_verts are off by 1
         * but leave for now to save having to call do_versions */
-       curve_deform_verts(md->scene, cmd->object, ob, derivedData, vertexCos, numVerts,
-                          cmd->name, cmd->defaxis - 1);
+       curve_deform_verts(cmd->object, ctx->object, mesh_src, vertexCos, numVerts, cmd->name, cmd->defaxis - 1);
 }
 
 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,
+        Mesh *mesh,
+        float (*vertexCos)[3],
+        int numVerts)
 {
-       DerivedMesh *dm = derivedData;
+       Mesh *mesh_src = mesh;
+
+       if (mesh_src == NULL) {
+               mesh_src = BKE_bmesh_to_mesh_nomain(em->bm, &(struct BMeshToMeshParams){0});
+       }
 
-       if (!derivedData) dm = CDDM_from_editbmesh(em, false, false);
+       BLI_assert(mesh_src->totvert == numVerts);
 
-       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);
+       }
 }
 
 
@@ -152,17 +160,25 @@ ModifierTypeInfo modifierType_Curve = {
                                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,