Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / armature / armature_skinning.c
index 1722cbd..463e009 100644 (file)
@@ -71,7 +71,7 @@ static int bone_skinnable_cb(Object *UNUSED(ob), Bone *bone, void *datap)
         * This function performs 2 functions:
         *
         *   a) It returns 1 if the bone is skinnable.
-        *      If we loop over all bones with this 
+        *      If we loop over all bones with this
         *      function, we can count the number of
         *      skinnable bones.
         *   b) If the pointer data is non null,
@@ -96,10 +96,10 @@ static int bone_skinnable_cb(Object *UNUSED(ob), Bone *bone, void *datap)
                                segments = bone->segments;
                        else
                                segments = 1;
-                       
+
                        if (data->list != NULL) {
                                hbone = (Bone ***) &data->list;
-                               
+
                                for (a = 0; a < segments; a++) {
                                        **hbone = bone;
                                        ++*hbone;
@@ -111,10 +111,10 @@ static int bone_skinnable_cb(Object *UNUSED(ob), Bone *bone, void *datap)
        return 0;
 }
 
-static int vgroup_add_unique_bone_cb(Object *ob, Bone *bone, void *UNUSED(ptr)) 
+static int vgroup_add_unique_bone_cb(Object *ob, Bone *bone, void *UNUSED(ptr))
 {
        /* This group creates a vertex group to ob that has the
-        * same name as bone (provided the bone is skinnable). 
+        * same name as bone (provided the bone is skinnable).
         * If such a vertex group already exist the routine exits.
         */
        if (!(bone->flag & BONE_NO_DEFORM)) {
@@ -126,7 +126,7 @@ static int vgroup_add_unique_bone_cb(Object *ob, Bone *bone, void *UNUSED(ptr))
        return 0;
 }
 
-static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap) 
+static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap)
 {
        /* Bones that are deforming
         * are regarded to be "skinnable" and are eligible for
@@ -134,16 +134,16 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap)
         *
         * This function performs 2 functions:
         *
-        *   a) If the bone is skinnable, it creates 
+        *   a) If the bone is skinnable, it creates
         *      a vertex group for ob that has
         *      the name of the skinnable bone
         *      (if one doesn't exist already).
         *   b) If the pointer data is non null,
         *      it is treated like a handle to a
-        *      bDeformGroup pointer -- the 
+        *      bDeformGroup pointer -- the
         *      bDeformGroup pointer is set to point
         *      to the deform group with the bone's
-        *      name, and the pointer the handle 
+        *      name, and the pointer the handle
         *      points to is incremented to point to the
         *      next member of an array of pointers
         *      to bDeformGroups. This way we can loop using
@@ -162,7 +162,7 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap)
                                segments = bone->segments;
                        else
                                segments = 1;
-                       
+
                        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);
@@ -172,10 +172,10 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap)
                                        defgroup = NULL;
                                }
                        }
-                       
+
                        if (data->list != NULL) {
                                hgroup = (bDeformGroup ***) &data->list;
-                               
+
                                for (a = 0; a < segments; a++) {
                                        **hgroup = defgroup;
                                        ++*hgroup;
@@ -215,25 +215,25 @@ static void envelope_bone_weighting(
                }
 
                iflip = (dgroupflip) ? mesh_get_x_mirror_vert(ob, NULL, i, use_topology) : -1;
-               
+
                /* for each skinnable bone */
                for (j = 0; j < numbones; ++j) {
                        if (!selected[j])
                                continue;
-                       
+
                        bone = bonelist[j];
                        dgroup = dgrouplist[j];
-                       
+
                        /* store the distance-factor from the vertex to the bone */
                        distance = distfactor_to_bone(verts[i], root[j], tip[j],
                                                      bone->rad_head * scale, bone->rad_tail * scale, bone->dist * scale);
-                       
+
                        /* add the vert to the deform group if (weight != 0.0) */
                        if (distance != 0.0f)
                                ED_vgroup_vert_add(ob, dgroup, i, distance, WEIGHT_REPLACE);
                        else
                                ED_vgroup_vert_remove(ob, dgroup, i);
-                       
+
                        /* do same for mirror */
                        if (dgroupflip && dgroupflip[j] && iflip != -1) {
                                if (distance != 0.0f)
@@ -282,10 +282,10 @@ static void add_verts_to_dgroups(
 
        /* count the number of skinnable bones */
        numbones = bone_looper(ob, arm->bonebase.first, &looper_data, bone_skinnable_cb);
-       
+
        if (numbones == 0)
                return;
-       
+
        if (BKE_object_defgroup_data_create(ob->data) == NULL)
                return;
 
@@ -313,13 +313,13 @@ static void add_verts_to_dgroups(
        for (j = 0; j < numbones; ++j) {
                bone = bonelist[j];
                dgroup = dgrouplist[j];
-               
+
                /* handle bbone */
                if (heat) {
                        if (segments == 0) {
                                segments = 1;
                                bbone = NULL;
-                               
+
                                if ((par->pose) && (pchan = BKE_pose_channel_find_name(par->pose, bone->name))) {
                                        if (bone->segments > 1) {
                                                segments = bone->segments;
@@ -328,10 +328,10 @@ static void add_verts_to_dgroups(
                                        }
                                }
                        }
-                       
+
                        segments--;
                }
-               
+
                /* compute root and tip */
                if (bbone) {
                        mul_v3_m4v3(root[j], bone->arm_mat, bbone[segments].mat[3]);
@@ -346,10 +346,10 @@ static void add_verts_to_dgroups(
                        copy_v3_v3(root[j], bone->arm_head);
                        copy_v3_v3(tip[j], bone->arm_tail);
                }
-               
+
                mul_m4_v3(par->obmat, root[j]);
                mul_m4_v3(par->obmat, tip[j]);
-               
+
                /* set selected */
                if (wpmode) {
                        if ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED))
@@ -357,7 +357,7 @@ static void add_verts_to_dgroups(
                }
                else
                        selected[j] = 1;
-               
+
                /* find flipped group */
                if (dgroup && mirror) {
                        char name_flip[MAXBONENAME];
@@ -374,12 +374,12 @@ static void add_verts_to_dgroups(
        if (wpmode) {
                /* if in weight paint mode, use final verts from derivedmesh */
                DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH);
-               
+
                if (dm->foreachMappedVert) {
                        mesh_get_mapped_verts_coords(dm, verts, mesh->totvert);
                        vertsfilled = 1;
                }
-               
+
                dm->release(dm);
        }
        else if (modifiers_findByType(ob, eModifierType_Subsurf)) {
@@ -431,7 +431,7 @@ 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 
+       /* Lets try to create some vertex groups
         * based on the bones of the parent armature.
         */
        bArmature *arm = par->data;
@@ -439,7 +439,7 @@ void ED_object_vgroup_calc_from_armature(
        if (mode == ARM_GROUPS_NAME) {
                const int defbase_tot = BLI_listbase_count(&ob->defbase);
                int defbase_add;
-               /* Traverse the bone list, trying to create empty vertex 
+               /* Traverse the bone list, trying to create empty vertex
                 * groups corresponding to the bone.
                 */
                defbase_add = bone_looper(ob, arm->bonebase.first, NULL, vgroup_add_unique_bone_cb);
@@ -451,7 +451,7 @@ void ED_object_vgroup_calc_from_armature(
                }
        }
        else if (ELEM(mode, ARM_GROUPS_ENVELOPE, ARM_GROUPS_AUTO)) {
-               /* Traverse the bone list, trying to create vertex groups 
+               /* Traverse the bone list, trying to create vertex groups
                 * that are populated with the vertices for which the
                 * bone is closest.
                 */