Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / armature / armature_skinning.c
index 8ab8d60..463e009 100644 (file)
 
 #include "BKE_action.h"
 #include "BKE_armature.h"
+#include "BKE_context.h"
 #include "BKE_deform.h"
 #include "BKE_object_deform.h"
 #include "BKE_report.h"
 #include "BKE_subsurf.h"
 #include "BKE_modifier.h"
 
+#include "DEG_depsgraph.h"
+
 #include "ED_armature.h"
 #include "ED_mesh.h"
 
 #include "armature_intern.h"
 #include "meshlaplacian.h"
 
-#if 0
-#include "reeb.h"
-#endif
-
 /* ********************************** Bone Skinning *********************************************** */
 
-static int bone_skinnable_cb(Object *ob, Bone *bone, void *datap)
+static int bone_skinnable_cb(Object *UNUSED(ob), Bone *bone, void *datap)
 {
        /* Bones that are deforming
         * are regarded to be "skinnable" and are eligible for
@@ -89,9 +88,9 @@ static int bone_skinnable_cb(Object *ob, Bone *bone, void *datap)
         */
        Bone ***hbone;
        int a, segments;
-       struct { Object *armob; void *list; int heat; } *data = datap;
+       struct { Object *armob; void *list; int heat; bool is_weight_paint; } *data = datap;
 
-       if (!(ob->mode & OB_MODE_WEIGHT_PAINT) || !(bone->flag & BONE_HIDDEN_P)) {
+       if (!(data->is_weight_paint) || !(bone->flag & BONE_HIDDEN_P)) {
                if (!(bone->flag & BONE_NO_DEFORM)) {
                        if (data->heat && data->armob->pose && BKE_pose_channel_find_name(data->armob->pose, bone->name))
                                segments = bone->segments;
@@ -154,18 +153,17 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap)
         */
        bDeformGroup ***hgroup, *defgroup = NULL;
        int a, segments;
-       struct { Object *armob; void *list; int heat; } *data = datap;
-       int wpmode = (ob->mode & OB_MODE_WEIGHT_PAINT);
+       struct { Object *armob; void *list; int heat; bool is_weight_paint; } *data = datap;
        bArmature *arm = data->armob->data;
 
-       if (!wpmode || !(bone->flag & BONE_HIDDEN_P)) {
+       if (!data->is_weight_paint || !(bone->flag & BONE_HIDDEN_P)) {
                if (!(bone->flag & BONE_NO_DEFORM)) {
                        if (data->heat && data->armob->pose && BKE_pose_channel_find_name(data->armob->pose, bone->name))
                                segments = bone->segments;
                        else
                                segments = 1;
 
-                       if (!wpmode || ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED))) {
+                       if (!data->is_weight_paint || ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED))) {
                                if (!(defgroup = defgroup_find_name(ob, bone->name))) {
                                        defgroup = BKE_object_defgroup_add_name(ob, bone->name);
                                }
@@ -189,9 +187,10 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap)
        return 0;
 }
 
-static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], int numbones, Bone **bonelist,
-                                    bDeformGroup **dgrouplist, bDeformGroup **dgroupflip,
-                                    float (*root)[3], float (*tip)[3], const int *selected, float scale)
+static void envelope_bone_weighting(
+        Object *ob, Mesh *mesh, float (*verts)[3], int numbones, Bone **bonelist,
+        bDeformGroup **dgrouplist, bDeformGroup **dgroupflip,
+        float (*root)[3], float (*tip)[3], const int *selected, float scale)
 {
        /* Create vertex group weights from envelopes */
 
@@ -247,8 +246,9 @@ static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], i
        }
 }
 
-static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob, Object *par,
-                                 int heat, const bool mirror)
+static void add_verts_to_dgroups(
+        ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, Object *par,
+        int heat, const bool mirror)
 {
        /* This functions implements the automatic computation of vertex group
         * weights, either through envelopes or using a heat equilibrium.
@@ -272,12 +272,13 @@ static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob,
        float (*root)[3], (*tip)[3], (*verts)[3];
        int *selected;
        int numbones, vertsfilled = 0, i, j, segments = 0;
-       int wpmode = (ob->mode & OB_MODE_WEIGHT_PAINT);
-       struct { Object *armob; void *list; int heat; } looper_data;
+       const bool wpmode = (ob->mode & OB_MODE_WEIGHT_PAINT);
+       struct { Object *armob; void *list; int heat; bool is_weight_paint; } looper_data;
 
        looper_data.armob = par;
        looper_data.heat = heat;
        looper_data.list = NULL;
+       looper_data.is_weight_paint = wpmode;
 
        /* count the number of skinnable bones */
        numbones = bone_looper(ob, arm->bonebase.first, &looper_data, bone_skinnable_cb);
@@ -372,7 +373,7 @@ static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob,
 
        if (wpmode) {
                /* if in weight paint mode, use final verts from derivedmesh */
-               DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+               DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH);
 
                if (dm->foreachMappedVert) {
                        mesh_get_mapped_verts_coords(dm, verts, mesh->totvert);
@@ -400,15 +401,17 @@ static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob,
        if (heat) {
                const char *error = NULL;
 
-               heat_bone_weighting(ob, mesh, verts, numbones, dgrouplist, dgroupflip,
-                                   root, tip, selected, &error);
+               heat_bone_weighting(
+                       ob, mesh, verts, numbones, dgrouplist, dgroupflip,
+                       root, tip, selected, &error);
                if (error) {
                        BKE_report(reports, RPT_WARNING, error);
                }
        }
        else {
-               envelope_bone_weighting(ob, mesh, verts, numbones, bonelist, dgrouplist,
-                                       dgroupflip, root, tip, selected, mat4_to_scale(par->obmat));
+               envelope_bone_weighting(
+                       ob, mesh, verts, numbones, bonelist, dgrouplist,
+                       dgroupflip, root, tip, selected, mat4_to_scale(par->obmat));
        }
 
        /* only generated in some cases but can call anyway */
@@ -424,8 +427,9 @@ static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob,
        MEM_freeN(verts);
 }
 
-void ED_object_vgroup_calc_from_armature(ReportList *reports, Scene *scene, Object *ob, Object *par,
-                                  const int mode, const bool mirror)
+void ED_object_vgroup_calc_from_armature(
+        ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, Object *par,
+        const int mode, const bool mirror)
 {
        /* Lets try to create some vertex groups
         * based on the bones of the parent armature.
@@ -451,6 +455,6 @@ void ED_object_vgroup_calc_from_armature(ReportList *reports, Scene *scene, Obje
                 * that are populated with the vertices for which the
                 * bone is closest.
                 */
-               add_verts_to_dgroups(reports, scene, ob, par, (mode == ARM_GROUPS_AUTO), mirror);
+               add_verts_to_dgroups(reports, depsgraph, scene, ob, par, (mode == ARM_GROUPS_AUTO), mirror);
        }
 }