Warp modifier: add bone from and bone to options when using armature objects

This commit adds the option to use armature bones for the From and To targets
when using armature objects.

The changes are based on the UV Warp modifier.

Reviewed By: mont29

Differential Revision: https://developer.blender.org/D6820
This commit is contained in:
Cody Winchester 2020-03-27 10:27:00 +01:00 committed by Bastien Montagne
parent 3441862c96
commit ba1f7acc3f
4 changed files with 70 additions and 10 deletions

View File

@ -1173,11 +1173,27 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
col.label(text="From:")
col.prop(md, "object_from", text="")
col.prop(md, "use_volume_preserve")
col = split.column()
col.label(text="To:")
col.prop(md, "object_to", text="")
split = layout.split()
col = split.column()
obj = md.object_from
if obj and obj.type == 'ARMATURE':
col.label(text="Bone:")
col.prop_search(md, "bone_from", obj.data, "bones", text="")
col = split.column()
obj = md.object_to
if obj and obj.type == 'ARMATURE':
col.label(text="Bone:")
col.prop_search(md, "bone_to", obj.data, "bones", text="")
split = layout.split()
col = split.column()
col.prop(md, "use_volume_preserve")
col = split.column()
row = col.row(align=True)
row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
row.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')

View File

@ -1324,6 +1324,11 @@ typedef struct WarpModifierData {
struct Object *object_from;
struct Object *object_to;
/** Optional name of bone target, MAX_ID_NAME-2. */
char bone_from[64];
/** Optional name of bone target, MAX_ID_NAME-2. */
char bone_to[64];
struct CurveMapping *curfalloff;
/** Optional vertexgroup name, MAX_VGROUP_NAME. */
char defgrp_name[64];

View File

@ -1795,17 +1795,29 @@ static void rna_def_modifier_warp(BlenderRNA *brna)
RNA_def_struct_ui_icon(srna, ICON_MOD_WARP);
prop = RNA_def_property(srna, "object_from", PROP_POINTER, PROP_NONE);
RNA_def_property_ui_text(prop, "From", "Object to transform from");
RNA_def_property_pointer_sdna(prop, NULL, "object_from");
RNA_def_property_ui_text(prop, "Object From", "Object to transform from");
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, "bone_from", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "bone_from");
RNA_def_property_ui_text(prop, "Bone From", "Bone to transform from");
RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
prop = RNA_def_property(srna, "object_to", PROP_POINTER, PROP_NONE);
RNA_def_property_ui_text(prop, "To", "Object to transform to");
RNA_def_property_pointer_sdna(prop, NULL, "object_to");
RNA_def_property_ui_text(prop, "Object To", "Object to transform to");
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, "bone_to", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "bone_to");
RNA_def_property_ui_text(prop, "Bone To", "Bone defining offset");
RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
RNA_def_property_ui_range(prop, -100, 100, 10, 2);

View File

@ -32,6 +32,7 @@
#include "BKE_colortools.h"
#include "BKE_deform.h"
#include "BKE_action.h" /* BKE_pose_channel_find_name */
#include "BKE_editmesh.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
@ -85,6 +86,17 @@ static void requiredDataMask(Object *UNUSED(ob),
}
}
static void matrix_from_obj_pchan(float mat[4][4], float obinv[4][4], Object *ob, const char *bonename)
{
bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bonename);
if (pchan) {
mul_m4_m4m4(mat, obinv, pchan->pose_mat);
}
else {
mul_m4_m4m4(mat, obinv, ob->obmat);
}
}
static bool dependsOnTime(ModifierData *md)
{
WarpModifierData *wmd = (WarpModifierData *)md;
@ -135,15 +147,29 @@ static void foreachTexLink(ModifierData *md, Object *ob, TexWalkFunc walk, void
walk(userData, ob, md, "texture");
}
static void warp_deps_object_bone_new(struct DepsNodeHandle *node,
Object *object,
const char *bonename)
{
if (bonename[0] && object->type == OB_ARMATURE) {
DEG_add_object_relation(node, object, DEG_OB_COMP_EVAL_POSE, "Warp Modifier");
}
else {
DEG_add_object_relation(node, object, DEG_OB_COMP_TRANSFORM, "Warp Modifier");
}
}
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
WarpModifierData *wmd = (WarpModifierData *)md;
if (wmd->object_from != NULL && wmd->object_to != NULL) {
DEG_add_modifier_to_transform_relation(ctx->node, "Warplace Modifier");
DEG_add_object_relation(
ctx->node, wmd->object_from, DEG_OB_COMP_TRANSFORM, "Warp Modifier from");
DEG_add_object_relation(ctx->node, wmd->object_to, DEG_OB_COMP_TRANSFORM, "Warp Modifier to");
warp_deps_object_bone_new(ctx->node, wmd->object_from, wmd->bone_from);
warp_deps_object_bone_new(ctx->node, wmd->object_to, wmd->bone_to);
DEG_add_modifier_to_transform_relation(ctx->node, "Warp Modifier");
}
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");
@ -197,8 +223,9 @@ static void warpModifier_do(WarpModifierData *wmd,
invert_m4_m4(obinv, ob->obmat);
mul_m4_m4m4(mat_from, obinv, wmd->object_from->obmat);
mul_m4_m4m4(mat_to, obinv, wmd->object_to->obmat);
/* Checks that the objects/bones are available. */
matrix_from_obj_pchan(mat_from, obinv, wmd->object_from, wmd->bone_from);
matrix_from_obj_pchan(mat_to, obinv, wmd->object_to, wmd->bone_to);
invert_m4_m4(tmat, mat_from); // swap?
mul_m4_m4m4(mat_final, tmat, mat_to);