Merge branch 'master' into blender2.8
[blender.git] / source / blender / modifiers / intern / MOD_armature.c
index 579854be7251489b593ac032bfe8e1c2f45266c8..6644e5383df3f1343fbca98765204f941930419b 100644 (file)
 #include "BLI_utildefines.h"
 #include "BLI_string.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 "MEM_guardedalloc.h"
+#include "bmesh.h"
+#include "bmesh_tools.h"
 
-#include "depsgraph_private.h"
+#include "MEM_guardedalloc.h"
 
 #include "MOD_util.h"
 
@@ -99,18 +101,6 @@ static void foreachObjectLink(
        walk(userData, ob, &amd->object, IDWALK_CB_NOP);
 }
 
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
-       ArmatureModifierData *amd = (ArmatureModifierData *) md;
-
-       if (amd->object) {
-               DagNode *curNode = dag_get_node(ctx->forest, amd->object);
-
-               dag_add_relation(ctx->forest, curNode, ctx->obNode,
-                                DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Armature Modifier");
-       }
-}
-
 static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
 {
        ArmatureModifierData *amd = (ArmatureModifierData *)md;
@@ -121,17 +111,16 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
        DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Armature Modifier");
 }
 
-static void deformVerts(ModifierData *md, Object *ob,
-                        DerivedMesh *derivedData,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
+                        Mesh *mesh,
                         float (*vertexCos)[3],
-                        int numVerts,
-                        ModifierApplyFlag UNUSED(flag))
+                        int numVerts)
 {
        ArmatureModifierData *amd = (ArmatureModifierData *) md;
 
        modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */
        
-       armature_deform_verts(amd->object, ob, derivedData, vertexCos, NULL,
+       armature_deform_verts(amd->object, ctx->object, mesh, vertexCos, NULL,
                              numVerts, amd->deformflag, (float(*)[3])amd->prevCos, amd->defgrp_name);
 
        /* free cache */
@@ -142,17 +131,19 @@ static void deformVerts(ModifierData *md, Object *ob,
 }
 
 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)
 {
        ArmatureModifierData *amd = (ArmatureModifierData *) md;
-       DerivedMesh *dm = derivedData;
+       Mesh *mesh_src = mesh;
 
-       if (!derivedData) dm = CDDM_from_editbmesh(em, false, false);
+       if (!mesh) {
+               mesh_src = BKE_bmesh_to_mesh(em->bm, &(struct BMeshToMeshParams){0});
+       }
 
        modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */
 
-       armature_deform_verts(amd->object, ob, dm, vertexCos, NULL,
+       armature_deform_verts(amd->object, ctx->object, mesh_src, vertexCos, NULL,
                              numVerts, amd->deformflag, (float(*)[3])amd->prevCos, amd->defgrp_name);
 
        /* free cache */
@@ -161,37 +152,39 @@ static void deformVertsEM(
                amd->prevCos = NULL;
        }
 
-       if (!derivedData) dm->release(dm);
+       if (!mesh) {
+               BKE_id_free(NULL, mesh_src);
+       }
 }
 
 static void deformMatricesEM(
-        ModifierData *md, Object *ob, struct BMEditMesh *em,
-        DerivedMesh *derivedData, float (*vertexCos)[3],
+        ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em,
+        Mesh *mesh, float (*vertexCos)[3],
         float (*defMats)[3][3], int numVerts)
 {
        ArmatureModifierData *amd = (ArmatureModifierData *) md;
-       DerivedMesh *dm = derivedData;
+       Mesh *mesh_src = mesh;
 
-       if (!derivedData) dm = CDDM_from_editbmesh(em, false, false);
+       if (!mesh) {
+               mesh_src = BKE_bmesh_to_mesh(em->bm, &(struct BMeshToMeshParams){0});
+       }
 
-       armature_deform_verts(amd->object, ob, dm, vertexCos, defMats, numVerts,
+       armature_deform_verts(amd->object, ctx->object, mesh_src, vertexCos, defMats, numVerts,
                              amd->deformflag, NULL, amd->defgrp_name);
 
-       if (!derivedData) dm->release(dm);
+       if (!mesh) {
+               BKE_id_free(NULL, mesh_src);
+       }
 }
 
-static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedData,
+static void deformMatrices(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh,
                            float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
 {
        ArmatureModifierData *amd = (ArmatureModifierData *) md;
-       DerivedMesh *dm = derivedData;
-
-       if (!derivedData) dm = CDDM_from_mesh((Mesh *)ob->data);
+       Mesh *mesh_src = mesh ? mesh : ctx->object->data;
 
-       armature_deform_verts(amd->object, ob, dm, vertexCos, defMats, numVerts,
+       armature_deform_verts(amd->object, ctx->object, mesh_src, vertexCos, defMats, numVerts,
                              amd->deformflag, NULL, amd->defgrp_name);
-
-       if (!derivedData) dm->release(dm);
 }
 
 ModifierTypeInfo modifierType_Armature = {
@@ -204,17 +197,25 @@ ModifierTypeInfo modifierType_Armature = {
                                eModifierTypeFlag_SupportsEditmode,
 
        /* copyData */          copyData,
+
+       /* deformVerts_DM */    NULL,
+       /* deformMatrices_DM */ NULL,
+       /* deformVertsEM_DM */  NULL,
+       /* deformMatricesEM_DM*/NULL,
+       /* applyModifier_DM */  NULL,
+       /* applyModifierEM_DM */NULL,
+
        /* deformVerts */       deformVerts,
        /* deformMatrices */    deformMatrices,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  deformMatricesEM,
        /* applyModifier */     NULL,
        /* applyModifierEM */   NULL,
+
        /* initData */          initData,
        /* requiredDataMask */  requiredDataMask,
        /* freeData */          NULL,
        /* isDisabled */        isDisabled,
-       /* updateDepgraph */    updateDepgraph,
        /* updateDepsgraph */   updateDepsgraph,
        /* dependsOnTime */     NULL,
        /* dependsOnNormals */  NULL,