diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-08-21 14:47:27 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-08-21 14:47:27 +0400 |
commit | 9125fe55fbe18d0fafdf388ce69f9bd29657da2f (patch) | |
tree | 7285e1bc92447c03be5e9029e7d68bae43f42326 | |
parent | 46fb2d37e347b6ecbd0097aa662cd2fdc4b65f33 (diff) |
Hook Modifier - Bone Targets
Made Hook Modifier be able to use bone targets. However, I haven't been able to verify that everything will work perfectly, since just creating a new Hook Modifier and assigning targets doesn't set hmd->indexar correctly.
-rw-r--r-- | release/ui/buttons_data_modifier.py | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/action.c | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 27 | ||||
-rw-r--r-- | source/blender/editors/object/object_edit.c | 4 | ||||
-rw-r--r-- | source/blender/editors/object/object_modifier.c | 19 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 5 |
7 files changed, 56 insertions, 12 deletions
diff --git a/release/ui/buttons_data_modifier.py b/release/ui/buttons_data_modifier.py index cc50256f216..f5af26f8746 100644 --- a/release/ui/buttons_data_modifier.py +++ b/release/ui/buttons_data_modifier.py @@ -200,7 +200,11 @@ class DATA_PT_modifiers(DataButtonsPanel): layout.itemL(text="See Fluid panel.") def HOOK(self, layout, ob, md): - layout.itemR(md, "object") + col = layout.column() + col.itemR(md, "object") + if md.object and md.object.type == "ARMATURE": + layout.item_pointerR(md, "subtarget", md.object.data, "bones", text="Bone") + layout.item_pointerR(md, "vertex_group", ob, "vertex_groups") split = layout.split() diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index f4d4eb1cc9c..6a39139d250 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -410,8 +410,9 @@ bActionGroup *action_groups_find_named (bAction *act, const char name[]) bPoseChannel *get_pose_channel(const bPose *pose, const char *name) { bPoseChannel *chan; - - if (pose==NULL) return NULL; + + if (ELEM(NULL, pose, name) || (name[0] == 0)) + return NULL; for (chan=pose->chanbase.first; chan; chan=chan->next) { if (chan->name[0] == name[0]) { diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 37cf427b897..501638aba0d 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -5598,6 +5598,7 @@ static void hookModifier_copyData(ModifierData *md, ModifierData *target) thmd->indexar = MEM_dupallocN(hmd->indexar); memcpy(thmd->parentinv, hmd->parentinv, sizeof(hmd->parentinv)); strncpy(thmd->name, hmd->name, 32); + strncpy(thmd->subtarget, hmd->subtarget, 32); } CustomDataMask hookModifier_requiredDataMask(Object *ob, ModifierData *md) @@ -5642,9 +5643,11 @@ static void hookModifier_updateDepgraph(ModifierData *md, DagForest *forest, Sce if (hmd->object) { DagNode *curNode = dag_get_node(forest, hmd->object); - - dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA, - "Hook Modifier"); + + if (hmd->subtarget[0]) + dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA|DAG_RL_DATA_DATA, "Hook Modifier"); + else + dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA, "Hook Modifier"); } } @@ -5653,12 +5656,22 @@ static void hookModifier_deformVerts( float (*vertexCos)[3], int numVerts, int useRenderParams, int isFinalCalc) { HookModifierData *hmd = (HookModifierData*) md; - float vec[3], mat[4][4]; + bPoseChannel *pchan= get_pose_channel(hmd->object->pose, hmd->subtarget); + float vec[3], mat[4][4], dmat[4][4], imat[4][4]; int i; DerivedMesh *dm = derivedData; - - Mat4Invert(ob->imat, ob->obmat); - Mat4MulSerie(mat, ob->imat, hmd->object->obmat, hmd->parentinv, + + /* get world-space matrix of target, corrected for the space the verts are in */ + if (hmd->subtarget[0] && pchan) { + /* bone target if there's a matching pose-channel */ + Mat4MulMat4(dmat, pchan->pose_mat, hmd->object->obmat); + } + else { + /* just object target */ + Mat4CpyMat4(dmat, hmd->object->obmat); + } + Mat4Invert(imat, dmat); + Mat4MulSerie(mat, imat, dmat, hmd->parentinv, NULL, NULL, NULL, NULL, NULL); /* vertex indices? */ diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 2fb9835f833..e1b8858937c 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -979,6 +979,9 @@ static void select_editmesh_hook(Object *ob, HookModifierData *hmd) EditVert *eve; int index=0, nr=0; + if (hmd->indexar == NULL) + return; + for(eve= em->verts.first; eve; eve= eve->next, nr++) { if(nr==hmd->indexar[index]) { eve->f |= SELECT; @@ -1361,6 +1364,7 @@ void add_hook(Scene *scene, View3D *v3d, int mode) hmd->totindex= tot; BLI_strncpy(hmd->name, name, 32); + // TODO: need to take into account bone targets here too now... if(mode==1 || mode==2) { /* matrix calculus */ /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */ diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 32a1297aaf4..3785e17f67c 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -31,6 +31,7 @@ #include "MEM_guardedalloc.h" +#include "DNA_action_types.h" #include "DNA_curve_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" @@ -42,6 +43,7 @@ #include "BLI_arithb.h" #include "BLI_listbase.h" +#include "BKE_action.h" #include "BKE_curve.h" #include "BKE_context.h" #include "BKE_depsgraph.h" @@ -853,8 +855,21 @@ static int hook_reset_exec(bContext *C, wmOperator *op) HookModifierData *hmd= ptr.data; if(hmd->object) { - Mat4Invert(hmd->object->imat, hmd->object->obmat); - Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); + bPoseChannel *pchan= get_pose_channel(hmd->object->pose, hmd->subtarget); + + if(hmd->subtarget[0] && pchan) { + float imat[4][4], mat[4][4]; + + /* calculate the world-space matrix for the pose-channel target first, then carry on as usual */ + Mat4MulMat4(mat, pchan->pose_mat, hmd->object->obmat); + + Mat4Invert(imat, mat); + Mat4MulSerie(hmd->parentinv, imat, mat, NULL, NULL, NULL, NULL, NULL, NULL); + } + else { + Mat4Invert(hmd->object->imat, hmd->object->obmat); + Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); + } } DAG_object_flush_update(scene, ob, OB_RECALC_DATA); diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 912d11dcc8c..a4587c34e89 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -426,6 +426,8 @@ typedef struct HookModifierData { ModifierData modifier; struct Object *object; + char subtarget[32]; /* optional name of bone target */ + float parentinv[4][4]; /* matrix making current transform unmodified */ float cent[3]; /* visualization of hook */ float falloff; /* if not zero, falloff is distance where influence zero */ diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index c080b88feaf..bfd93a4218b 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -912,6 +912,11 @@ static void rna_def_modifier_hook(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Object", "Parent Object for hook, also recalculates and clears offset"); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Modifier_dependency_update"); + + prop= RNA_def_property(srna, "subtarget", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "subtarget"); + RNA_def_property_ui_text(prop, "Sub-Target", "Name of Parent Bone for hook (if applicable), also recalculates and clears offset"); + RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Modifier_dependency_update"); prop= RNA_def_property(srna, "vertex_group", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "name"); |