diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-12-17 15:13:15 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-12-17 16:04:36 +0400 |
commit | f5076d54cb3a95ab583cddb7de07ed746d2e2be6 (patch) | |
tree | 421505d1a20dcb53fd8bfeb97e67e9a97a30566a /source/blender/editors/armature | |
parent | db795b66fa865ad99bc52fb3c9b053b9bb332f9b (diff) |
'Transform' Python Function for armature, curve and lattice.
patch by Paolo Acampora with some edits.
Diffstat (limited to 'source/blender/editors/armature')
5 files changed, 58 insertions, 38 deletions
diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c index c284769ff5c..9bc94e01085 100644 --- a/source/blender/editors/armature/armature_edit.c +++ b/source/blender/editors/armature/armature_edit.c @@ -65,17 +65,27 @@ void ED_armature_apply_transform(Object *ob, float mat[4][4]) { - EditBone *ebone; bArmature *arm = ob->data; + + /* Put the armature into editmode */ + ED_armature_to_edit(arm); + + /* Transform the bones*/ + ED_armature_transform_bones(arm, mat); + + /* Turn the list into an armature */ + ED_armature_from_edit(arm); + ED_armature_edit_free(arm); +} + +void ED_armature_transform_bones(struct bArmature *arm, float mat[4][4]) +{ + EditBone *ebone; float scale = mat4_to_scale(mat); /* store the scale of the matrix here to use on envelopes */ float mat3[3][3]; - + copy_m3_m4(mat3, mat); normalize_m3(mat3); - - /* Put the armature into editmode */ - ED_armature_to_edit(ob); - /* Do the rotations */ for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { float tmat[3][3]; @@ -89,7 +99,7 @@ void ED_armature_apply_transform(Object *ob, float mat[4][4]) /* transform the bone */ mul_m4_v3(mat, ebone->head); mul_m4_v3(mat, ebone->tail); - + /* apply the transfiormed roll back */ mat3_to_vec_roll(tmat, NULL, &ebone->roll); @@ -101,10 +111,24 @@ void ED_armature_apply_transform(Object *ob, float mat[4][4]) ebone->xwidth *= scale; ebone->zwidth *= scale; } - - /* Turn the list into an armature */ - ED_armature_from_edit(ob); - ED_armature_edit_free(ob); +} + +void ED_armature_transform(struct bArmature *arm, float mat[4][4]) +{ + if (arm->edbo) { + ED_armature_transform_bones(arm, mat); + } + else { + /* Put the armature into editmode */ + ED_armature_to_edit(arm); + + /* Transform the bones */ + ED_armature_transform_bones(arm, mat); + + /* Go back to object mode*/ + ED_armature_from_edit(arm); + ED_armature_edit_free(arm); + } } /* exported for use in editors/object/ */ @@ -118,7 +142,7 @@ void ED_armature_origin_set(Scene *scene, Object *ob, float cursor[3], int cente /* Put the armature into editmode */ if (ob != obedit) { - ED_armature_to_edit(ob); + ED_armature_to_edit(arm); obedit = NULL; /* we cant use this so behave as if there is no obedit */ } @@ -160,8 +184,8 @@ void ED_armature_origin_set(Scene *scene, Object *ob, float cursor[3], int cente /* Turn the list into an armature */ if (obedit == NULL) { - ED_armature_from_edit(ob); - ED_armature_edit_free(ob); + ED_armature_from_edit(arm); + ED_armature_edit_free(arm); } /* Adjust object location for new centerpoint */ diff --git a/source/blender/editors/armature/armature_relations.c b/source/blender/editors/armature/armature_relations.c index 087e9a86241..7a5d43acf9c 100644 --- a/source/blender/editors/armature/armature_relations.c +++ b/source/blender/editors/armature/armature_relations.c @@ -204,7 +204,7 @@ int join_armature_exec(bContext *C, wmOperator *op) } /* Get editbones of active armature to add editbones to */ - ED_armature_to_edit(ob); + ED_armature_to_edit(arm); /* get pose of active object and move it out of posemode */ pose = ob->pose; @@ -216,7 +216,7 @@ int join_armature_exec(bContext *C, wmOperator *op) bArmature *curarm = base->object->data; /* Make a list of editbones in current armature */ - ED_armature_to_edit(base->object); + ED_armature_to_edit(base->object->data); /* Get Pose of current armature */ opose = base->object->pose; @@ -286,8 +286,8 @@ int join_armature_exec(bContext *C, wmOperator *op) DAG_relations_tag_update(bmain); /* because we removed object(s) */ - ED_armature_from_edit(ob); - ED_armature_edit_free(ob); + ED_armature_from_edit(arm); + ED_armature_edit_free(arm); WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); @@ -409,7 +409,7 @@ static void separate_armature_bones(Object *ob, short sel) EditBone *curbone; /* make local set of editbones to manipulate here */ - ED_armature_to_edit(ob); + ED_armature_to_edit(arm); /* go through pose-channels, checking if a bone should be removed */ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchann) { @@ -449,8 +449,8 @@ static void separate_armature_bones(Object *ob, short sel) } /* exit editmode (recalculates pchans too) */ - ED_armature_from_edit(ob); - ED_armature_edit_free(ob); + ED_armature_from_edit(ob->data); + ED_armature_edit_free(ob->data); } /* separate selected bones into their armature */ @@ -492,8 +492,8 @@ static int separate_armature_exec(bContext *C, wmOperator *op) oldob->mode &= ~OB_MODE_POSE; //oldbase->flag &= ~OB_POSEMODE; - ED_armature_from_edit(obedit); - ED_armature_edit_free(obedit); + ED_armature_from_edit(obedit->data); + ED_armature_edit_free(obedit->data); /* 2) duplicate base */ newbase = ED_object_add_duplicate(bmain, scene, oldbase, USER_DUP_ARM); /* only duplicate linked armature */ @@ -518,7 +518,7 @@ static int separate_armature_exec(bContext *C, wmOperator *op) /* 5) restore original conditions */ obedit = oldob; - ED_armature_to_edit(obedit); + ED_armature_to_edit(obedit->data); BKE_report(op->reports, RPT_INFO, "Separated bones"); diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c index 7d6b3710a38..7c7027641d7 100644 --- a/source/blender/editors/armature/armature_utils.c +++ b/source/blender/editors/armature/armature_utils.c @@ -492,9 +492,8 @@ static void fix_bonelist_roll(ListBase *bonelist, ListBase *editbonelist) } /* put EditMode back in Object */ -void ED_armature_from_edit(Object *obedit) +void ED_armature_from_edit(bArmature *arm) { - bArmature *arm = obedit->data; EditBone *eBone, *neBone; Bone *newBone; Object *obt; @@ -601,12 +600,11 @@ void ED_armature_from_edit(Object *obedit) BKE_pose_rebuild(obt, arm); } - DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); + DAG_id_tag_update(&arm->id, 0); } -void ED_armature_edit_free(struct Object *ob) +void ED_armature_edit_free(struct bArmature *arm) { - bArmature *arm = ob->data; EditBone *eBone; /* Clear the editbones list */ @@ -628,11 +626,9 @@ void ED_armature_edit_free(struct Object *ob) } /* Put armature in EditMode */ -void ED_armature_to_edit(Object *ob) +void ED_armature_to_edit(bArmature *arm) { - bArmature *arm = ob->data; - - ED_armature_edit_free(ob); + ED_armature_edit_free(arm); arm->edbo = MEM_callocN(sizeof(ListBase), "edbo armature"); arm->act_edbone = make_boneList(arm->edbo, &arm->bonebase, NULL, arm->act_bone); diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c index 2c00c5e646c..4ea564b46ce 100644 --- a/source/blender/editors/armature/editarmature_retarget.c +++ b/source/blender/editors/armature/editarmature_retarget.c @@ -2416,7 +2416,7 @@ static void adjustGraphs(bContext *C, RigGraph *rigg) /* Turn the list into an armature */ arm->edbo = rigg->editbones; - ED_armature_from_edit(rigg->ob); + ED_armature_from_edit(arm); ED_undo_push(C, "Retarget Skeleton"); } @@ -2443,7 +2443,7 @@ static void retargetGraphs(bContext *C, RigGraph *rigg) /* Turn the list into an armature */ arm->edbo = rigg->editbones; - ED_armature_from_edit(rigg->ob); + ED_armature_from_edit(arm); } const char *RIG_nameBone(RigGraph *rg, int arc_index, int bone_index) diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c index 578f048cb15..993b0cc5e05 100644 --- a/source/blender/editors/armature/pose_transform.c +++ b/source/blender/editors/armature/pose_transform.c @@ -112,7 +112,7 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) "transforms stored are relative to the old rest pose"); /* Get editbones of active armature to alter */ - ED_armature_to_edit(ob); + ED_armature_to_edit(arm); /* get pose of active object and move it out of posemode */ pose = ob->pose; @@ -160,8 +160,8 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) } /* convert editbones back to bones, and then free the edit-data */ - ED_armature_from_edit(ob); - ED_armature_edit_free(ob); + ED_armature_from_edit(arm); + ED_armature_edit_free(arm); /* flush positions of posebones */ BKE_pose_where_is(scene, ob); |