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
This commit is contained in:
Cody Winchester 2020-04-10 14:03:36 +02:00 committed by Bastien Montagne
parent d6cefef98f
commit 4f9a56cbc4
Notes: blender-bot 2023-02-14 05:25:44 +01:00
Referenced by commit 1760b8c59f, Fix T75878: Modifiers disappearing from UI
Referenced by commit a0a59972e7, Fix T75878: Modifiers disappearing from UI
12 changed files with 99 additions and 14 deletions

View File

@ -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")

View File

@ -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. */

View File

@ -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)

View File

@ -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(

View File

@ -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) {

View File

@ -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");

View File

@ -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");

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);