From 4f9a56cbc4e8719ee421a57fd6695bed633c591b Mon Sep 17 00:00:00 2001 From: Cody Winchester Date: Fri, 10 Apr 2020 14:03:36 +0200 Subject: 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 --- .../startup/bl_ui/properties_data_modifier.py | 13 +++++++++++++ source/blender/makesdna/DNA_modifier_types.h | 10 ++++++++++ source/blender/makesrna/intern/rna_modifier.c | 10 ++++++++++ source/blender/modifiers/intern/MOD_displace.c | 10 ++++++++-- source/blender/modifiers/intern/MOD_util.c | 20 +++++++++++++++++--- source/blender/modifiers/intern/MOD_warp.c | 5 +++-- source/blender/modifiers/intern/MOD_wave.c | 9 ++++++++- source/blender/modifiers/intern/MOD_weightvg_util.c | 2 ++ source/blender/modifiers/intern/MOD_weightvg_util.h | 1 + source/blender/modifiers/intern/MOD_weightvgedit.c | 11 +++++++++-- source/blender/modifiers/intern/MOD_weightvgmix.c | 11 +++++++++-- .../blender/modifiers/intern/MOD_weightvgproximity.c | 11 +++++++++-- 12 files changed, 99 insertions(+), 14 deletions(-) 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/modifiers/intern/MOD_wave.c +++ b/source/blender/modifiers/intern/MOD_wave.c @@ -102,7 +102,14 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte DEG_add_object_relation(ctx->node, wmd->objectcenter, DEG_OB_COMP_TRANSFORM, "Wave Modifier"); } if (wmd->map_object != NULL) { - DEG_add_object_relation(ctx->node, wmd->map_object, DEG_OB_COMP_TRANSFORM, "Wave Modifier"); + if (wmd->map_bone[0] && wmd->map_object->type == OB_ARMATURE) { + DEG_add_object_relation( + ctx->node, wmd->map_object, DEG_OB_COMP_EVAL_POSE, "Wave Modifier"); + } + else { + DEG_add_object_relation( + ctx->node, wmd->map_object, DEG_OB_COMP_TRANSFORM, "Wave Modifier"); + } } if (wmd->objectcenter != NULL || wmd->map_object != NULL) { DEG_add_modifier_to_transform_relation(ctx->node, "Wave Modifier"); diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c index 23e4da32ed7..633bbb1421b 100644 --- a/source/blender/modifiers/intern/MOD_weightvg_util.c +++ b/source/blender/modifiers/intern/MOD_weightvg_util.c @@ -137,6 +137,7 @@ void weightvg_do_mask(const ModifierEvalContext *ctx, const int tex_use_channel, const int tex_mapping, Object *tex_map_object, + const char *text_map_bone, const char *tex_uvlayer_name, const bool invert_vgroup_mask) { @@ -163,6 +164,7 @@ void weightvg_do_mask(const ModifierEvalContext *ctx, */ t_map.texture = texture; t_map.map_object = tex_map_object; + BLI_strncpy(t_map.map_bone, text_map_bone, sizeof(t_map.map_bone)); BLI_strncpy(t_map.uvlayer_name, tex_uvlayer_name, sizeof(t_map.uvlayer_name)); t_map.texmapping = tex_mapping; diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.h b/source/blender/modifiers/intern/MOD_weightvg_util.h index bcd1076eac6..6a43ac69fe9 100644 --- a/source/blender/modifiers/intern/MOD_weightvg_util.h +++ b/source/blender/modifiers/intern/MOD_weightvg_util.h @@ -73,6 +73,7 @@ void weightvg_do_mask(const ModifierEvalContext *ctx, const int tex_use_channel, const int tex_mapping, Object *tex_map_object, + const char *text_map_bone, const char *tex_uvlayer_name, const bool invert_vgroup_mask); diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c index ba1745f7b5e..e304ca31e86 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.c +++ b/source/blender/modifiers/intern/MOD_weightvgedit.c @@ -135,8 +135,14 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte { WeightVGEditModifierData *wmd = (WeightVGEditModifierData *)md; if (wmd->mask_tex_map_obj != NULL && wmd->mask_tex_mapping == MOD_DISP_MAP_OBJECT) { - DEG_add_object_relation( - ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_TRANSFORM, "WeightVGEdit Modifier"); + if (wmd->mask_tex_map_bone[0] && wmd->mask_tex_map_obj->type == OB_ARMATURE) { + DEG_add_object_relation( + ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_EVAL_POSE, "WeightVGEdit Modifier"); + } + else { + DEG_add_object_relation( + ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_TRANSFORM, "WeightVGEdit Modifier"); + } DEG_add_modifier_to_transform_relation(ctx->node, "WeightVGEdit Modifier"); } else if (wmd->mask_tex_mapping == MOD_DISP_MAP_GLOBAL) { @@ -261,6 +267,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes wmd->mask_tex_use_channel, wmd->mask_tex_mapping, wmd->mask_tex_map_obj, + wmd->mask_tex_map_bone, wmd->mask_tex_uvlayer_name, invert_vgroup_mask); diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c index 4984853d41e..b109d0af5aa 100644 --- a/source/blender/modifiers/intern/MOD_weightvgmix.c +++ b/source/blender/modifiers/intern/MOD_weightvgmix.c @@ -181,8 +181,14 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte { WeightVGMixModifierData *wmd = (WeightVGMixModifierData *)md; if (wmd->mask_tex_map_obj != NULL && wmd->mask_tex_mapping == MOD_DISP_MAP_OBJECT) { - DEG_add_object_relation( - ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_TRANSFORM, "WeightVGMix Modifier"); + if (wmd->mask_tex_map_bone[0] && wmd->mask_tex_map_obj->type == OB_ARMATURE) { + DEG_add_object_relation( + ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_EVAL_POSE, "WeightVGMix Modifier"); + } + else { + DEG_add_object_relation( + ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_TRANSFORM, "WeightVGMix Modifier"); + } DEG_add_object_relation( ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_GEOMETRY, "WeightVGMix Modifier"); @@ -395,6 +401,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes wmd->mask_tex_use_channel, wmd->mask_tex_mapping, wmd->mask_tex_map_obj, + wmd->mask_tex_map_bone, wmd->mask_tex_uvlayer_name, invert_vgroup_mask); diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 7c9242ed900..2cee3878767 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -376,8 +376,14 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } if (wmd->mask_tex_map_obj != NULL && wmd->mask_tex_mapping == MOD_DISP_MAP_OBJECT) { - DEG_add_object_relation( - ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_TRANSFORM, "WeightVGProximity Modifier"); + if (wmd->mask_tex_map_bone[0] && wmd->mask_tex_map_obj->type == OB_ARMATURE) { + DEG_add_object_relation( + ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_EVAL_POSE, "WeightVGProximity Modifier"); + } + else { + DEG_add_object_relation( + ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_TRANSFORM, "WeightVGProximity Modifier"); + } DEG_add_object_relation( ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_GEOMETRY, "WeightVGProximity Modifier"); } @@ -589,6 +595,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes wmd->mask_tex_use_channel, wmd->mask_tex_mapping, wmd->mask_tex_map_obj, + wmd->mask_tex_map_bone, wmd->mask_tex_uvlayer_name, invert_vgroup_mask); -- cgit v1.2.3