[Bf-blender-cvs] [4f9a56cbc4e] master: Modifiers: Add Bone option for Texture Mask Object

Cody Winchester noreply at git.blender.org
Fri Apr 10 21:29:10 CEST 2020


Commit: 4f9a56cbc4e8719ee421a57fd6695bed633c591b
Author: Cody Winchester
Date:   Fri Apr 10 14:03:36 2020 +0200
Branches: master
https://developer.blender.org/rB4f9a56cbc4e8719ee421a57fd6695bed633c591b

Modifiers: Add Bone option for Texture Mask Object

This patch adds the option to use an armature bone in place of an object for texture mask coordinates.

This affects the 3 vertex weight modifiers, the displace modifier, the warp modifier, and the wave modifier.

With minor changes from Bastien Montagne (@mont29).

Differential Revision: https://developer.blender.org/D7348

===================================================================

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_displace.c
M	source/blender/modifiers/intern/MOD_util.c
M	source/blender/modifiers/intern/MOD_warp.c
M	source/blender/modifiers/intern/MOD_wave.c
M	source/blender/modifiers/intern/MOD_weightvg_util.c
M	source/blender/modifiers/intern/MOD_weightvg_util.h
M	source/blender/modifiers/intern/MOD_weightvgedit.c
M	source/blender/modifiers/intern/MOD_weightvgmix.c
M	source/blender/modifiers/intern/MOD_weightvgproximity.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 5510941c4a5..61151b3e02b 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -396,6 +396,10 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         if md.texture_coords == 'OBJECT':
             col.label(text="Object:")
             col.prop(md, "texture_coords_object", text="")
+            obj = md.texture_coords_object
+            if obj and obj.type == 'ARMATURE':
+                col.label(text="Bone:")
+                col.prop_search(md, "texture_coords_bone", obj.data, "bones", text="")
         elif md.texture_coords == 'UV' and ob.type == 'MESH':
             col.label(text="UV Map:")
             col.prop_search(md, "uv_layer", ob.data, "uv_layers", text="")
@@ -1244,6 +1248,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
         if md.texture_coords == 'OBJECT':
             layout.prop(md, "texture_coords_object", text="Object")
+            obj = md.texture_coords_object
+            if obj and obj.type == 'ARMATURE':
+                layout.prop_search(md, "texture_coords_bone", obj.data, "bones", text="Bone")
         elif md.texture_coords == 'UV' and ob.type == 'MESH':
             layout.prop_search(md, "uv_layer", ob.data, "uv_layers")
 
@@ -1296,6 +1303,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
             layout.prop_search(md, "uv_layer", ob.data, "uv_layers")
         elif md.texture_coords == 'OBJECT':
             layout.prop(md, "texture_coords_object")
+            obj = md.texture_coords_object
+            if obj and obj.type == 'ARMATURE':
+                layout.prop_search(md, "texture_coords_bone", obj.data, "bones")
 
         layout.separator()
 
@@ -1366,6 +1376,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
                 if md.mask_tex_mapping == 'OBJECT':
                     layout.prop(md, "mask_tex_map_object", text="Object")
+                    obj = md.mask_text_map_object
+                    if obj and obj.type == 'ARMATURE':
+                        layout.prop_search(md, "mask_tex_map_bone", obj.data, "bones", text="Bone")
                 elif md.mask_tex_mapping == 'UV' and ob.type == 'MESH':
                     layout.prop_search(md, "mask_tex_uv_layer", ob.data, "uv_layers")
 
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 855bf8434be..b2b2a73848a 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -138,6 +138,7 @@ typedef struct MappingInfoModifierData {
 
   struct Tex *texture;
   struct Object *map_object;
+  char map_bone[64];
   /** MAX_CUSTOMDATA_LAYER_NAME. */
   char uvlayer_name[64];
   int uvlayer_tmp;
@@ -496,6 +497,7 @@ typedef struct DisplaceModifierData {
   /* keep in sync with MappingInfoModifierData */
   struct Tex *texture;
   struct Object *map_object;
+  char map_bone[64];
   /** MAX_CUSTOMDATA_LAYER_NAME. */
   char uvlayer_name[64];
   int uvlayer_tmp;
@@ -651,6 +653,7 @@ typedef struct WaveModifierData {
   /* keep in sync with MappingInfoModifierData */
   struct Tex *texture;
   struct Object *map_object;
+  char map_bone[64];
   /** MAX_CUSTOMDATA_LAYER_NAME. */
   char uvlayer_name[64];
   int uvlayer_tmp;
@@ -1318,6 +1321,7 @@ typedef struct WarpModifierData {
   /* keep in sync with MappingInfoModifierData */
   struct Tex *texture;
   struct Object *map_object;
+  char map_bone[64];
   /** MAX_CUSTOMDATA_LAYER_NAME. */
   char uvlayer_name[64];
   int uvlayer_tmp;
@@ -1393,6 +1397,8 @@ typedef struct WeightVGEditModifierData {
   struct Tex *mask_texture;
   /** Name of the map object. */
   struct Object *mask_tex_map_obj;
+  /** Name of the map bone. */
+  char mask_tex_map_bone[64];
   /** How to map the texture (using MOD_DISP_MAP_* enums). */
   int mask_tex_mapping;
   /** Name of the UV map. MAX_CUSTOMDATA_LAYER_NAME. */
@@ -1444,6 +1450,8 @@ typedef struct WeightVGMixModifierData {
   struct Tex *mask_texture;
   /** Name of the map object. */
   struct Object *mask_tex_map_obj;
+  /** Name of the map bone. */
+  char mask_tex_map_bone[64];
   /** How to map the texture!. */
   int mask_tex_mapping;
   /** Name of the UV map. MAX_CUSTOMDATA_LAYER_NAME. */
@@ -1518,6 +1526,8 @@ typedef struct WeightVGProximityModifierData {
   struct Tex *mask_texture;
   /** Name of the map object. */
   struct Object *mask_tex_map_obj;
+  /** Name of the map bone. */
+  char mask_tex_map_bone[64];
   /** How to map the texture!. */
   int mask_tex_mapping;
   /** Name of the UV Map. MAX_CUSTOMDATA_LAYER_NAME. */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 36db4e5b33a..50a049883a1 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -1785,6 +1785,11 @@ static void rna_def_modifier_generic_map_info(StructRNA *srna)
   RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
   RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
   RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
+
+  prop = RNA_def_property(srna, "texture_coords_bone", PROP_STRING, PROP_NONE);
+  RNA_def_property_string_sdna(prop, NULL, "map_bone");
+  RNA_def_property_ui_text(prop, "Texture Coordinate Bone", "Bone to set the texture coordinates");
+  RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
 }
 
 static void rna_def_modifier_warp(BlenderRNA *brna)
@@ -4792,6 +4797,11 @@ static void rna_def_modifier_weightvg_mask(BlenderRNA *UNUSED(brna),
   RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
   RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
   RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
+
+  prop = RNA_def_property(srna, "mask_tex_map_bone", PROP_STRING, PROP_NONE);
+  RNA_def_property_string_sdna(prop, NULL, "mask_tex_map_bone");
+  RNA_def_property_ui_text(prop, "Texture Coordinate Bone", "Which bone to take texture coordinates from");
+  RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
 }
 
 static void rna_def_modifier_weightvgedit(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c
index a1b02e201d9..a03167c082f 100644
--- a/source/blender/modifiers/intern/MOD_displace.c
+++ b/source/blender/modifiers/intern/MOD_displace.c
@@ -135,9 +135,15 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
 {
   DisplaceModifierData *dmd = (DisplaceModifierData *)md;
   if (dmd->map_object != NULL && dmd->texmapping == MOD_DISP_MAP_OBJECT) {
+    if (dmd->map_bone[0] && dmd->map_object->type == OB_ARMATURE) {
+      DEG_add_object_relation(
+          ctx->node, dmd->map_object, DEG_OB_COMP_EVAL_POSE, "Displace Modifier");
+    }
+    else {
+      DEG_add_object_relation(
+          ctx->node, dmd->map_object, DEG_OB_COMP_TRANSFORM, "Displace Modifier");
+    }
     DEG_add_modifier_to_transform_relation(ctx->node, "Displace Modifier");
-    DEG_add_object_relation(
-        ctx->node, dmd->map_object, DEG_OB_COMP_TRANSFORM, "Displace Modifier");
   }
   if (dmd->texmapping == MOD_DISP_MAP_GLOBAL ||
       (ELEM(
diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c
index c0014a2c0cd..912b4a871a6 100644
--- a/source/blender/modifiers/intern/MOD_util.c
+++ b/source/blender/modifiers/intern/MOD_util.c
@@ -36,6 +36,7 @@
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
+#include "BKE_action.h" /* BKE_pose_channel_find_name */
 #include "BKE_deform.h"
 #include "BKE_editmesh.h"
 #include "BKE_image.h"
@@ -81,12 +82,25 @@ void MOD_get_texture_coords(MappingInfoModifierData *dmd,
   const int numVerts = mesh->totvert;
   int i;
   int texmapping = dmd->texmapping;
-  float mapob_imat[4][4];
+  float mapref_imat[4][4];
 
   if (texmapping == MOD_DISP_MAP_OBJECT) {
     if (dmd->map_object != NULL) {
       Object *map_object = dmd->map_object;
-      invert_m4_m4(mapob_imat, map_object->obmat);
+      if (dmd->map_bone[0] != '\0') {
+        bPoseChannel *pchan = BKE_pose_channel_find_name(map_object->pose, dmd->map_bone);
+        if (pchan) {
+          float mat_bone_world[4][4];
+          mul_m4_m4m4(mat_bone_world, map_object->obmat, pchan->pose_mat);
+          invert_m4_m4(mapref_imat, mat_bone_world);
+        }
+        else {
+          invert_m4_m4(mapref_imat, map_object->obmat);
+        }
+      }
+      else {
+        invert_m4_m4(mapref_imat, map_object->obmat);
+      }
     }
     else { /* if there is no map object, default to local */
       texmapping = MOD_DISP_MAP_LOCAL;
@@ -145,7 +159,7 @@ void MOD_get_texture_coords(MappingInfoModifierData *dmd,
         break;
       case MOD_DISP_MAP_OBJECT:
         mul_v3_m4v3(*r_texco, ob->obmat, cos != NULL ? *cos : mv->co);
-        mul_m4_v3(mapob_imat, *r_texco);
+        mul_m4_v3(mapref_imat, *r_texco);
         break;
     }
     if (cos != NULL) {
diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c
index c3515578e42..732644411b0 100644
--- a/source/blender/modifiers/intern/MOD_warp.c
+++ b/source/blender/modifiers/intern/MOD_warp.c
@@ -176,8 +176,9 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
   }
 
   if ((wmd->texmapping == MOD_DISP_MAP_OBJECT) && wmd->map_object != NULL) {
-    DEG_add_object_relation(
-        ctx->node, wmd->map_object, DEG_OB_COMP_TRANSFORM, "Warp Modifier map");
+    warp_deps_object_bone_new(ctx->node, wmd->map_object, wmd->map_bone);
+
+    DEG_add_modifier_to_transform_relation(ctx->node, "Warp Modifier map");
   }
   if (wmd->texture != NULL) {
     DEG_add_generic_id_relation(ctx->node, &wmd->texture->id, "Warp Modifier");
diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c
index 56b2a81fdb1..024d70bcfda 100644
--- a/source/blender/modifie

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list