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 | |
parent | db795b66fa865ad99bc52fb3c9b053b9bb332f9b (diff) |
'Transform' Python Function for armature, curve and lattice.
patch by Paolo Acampora with some edits.
Diffstat (limited to 'source/blender/editors')
18 files changed, 129 insertions, 58 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); diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index e6ea74b380b..bc97515f055 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1370,6 +1370,37 @@ void CU_select_swap(Object *obedit) } } +/******************** transform operator **********************/ + +void ED_curve_transform(Curve *cu, float mat[4][4]) +{ + Nurb *nu; + BPoint *bp; + BezTriple *bezt; + int a; + + float scale = mat4_to_scale(mat); + + for (nu = cu->nurb.first; nu; nu = nu->next) { + if (nu->type == CU_BEZIER) { + a = nu->pntsu; + for (bezt = nu->bezt; a--; bezt++) { + mul_m4_v3(mat, bezt->vec[0]); + mul_m4_v3(mat, bezt->vec[1]); + mul_m4_v3(mat, bezt->vec[2]); + bezt->radius *= scale; + } + BKE_nurb_handles_calc(nu); + } + else { + a = nu->pntsu * nu->pntsv; + for (bp = nu->bp; a--; bp++) + mul_m4_v3(mat, bp->vec); + } + } + DAG_id_tag_update(&cu->id, 0); +} + /******************** separate operator ***********************/ static int separate_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h index e9caf89d9da..61fcdc86d58 100644 --- a/source/blender/editors/include/ED_armature.h +++ b/source/blender/editors/include/ED_armature.h @@ -116,9 +116,9 @@ void ED_operatormacros_armature(void); void ED_keymap_armature(struct wmKeyConfig *keyconf); /* editarmature.c */ -void ED_armature_from_edit(struct Object *obedit); -void ED_armature_to_edit(struct Object *ob); -void ED_armature_edit_free(struct Object *ob); +void ED_armature_from_edit(struct bArmature *arm); +void ED_armature_to_edit(struct bArmature *arm); +void ED_armature_edit_free(struct bArmature *arm); void ED_armature_deselect_all(struct Object *obedit, int toggle); void ED_armature_deselect_all_visible(struct Object *obedit); @@ -146,7 +146,9 @@ void ED_armature_ebone_to_mat4(EditBone *ebone, float mat[4][4]); void transform_armature_mirror_update(struct Object *obedit); void ED_armature_origin_set(struct Scene *scene, struct Object *ob, float cursor[3], int centermode, int around); +void ED_armature_transform_bones(struct bArmature *arm, float mat[4][4]); void ED_armature_apply_transform(struct Object *ob, float mat[4][4]); +void ED_armature_transform(struct bArmature *arm, float mat[4][4]); #define ARM_GROUPS_NAME 1 #define ARM_GROUPS_ENVELOPE 2 diff --git a/source/blender/editors/include/ED_curve.h b/source/blender/editors/include/ED_curve.h index 571788f4f8f..ce6c8f8354b 100644 --- a/source/blender/editors/include/ED_curve.h +++ b/source/blender/editors/include/ED_curve.h @@ -51,6 +51,7 @@ void ED_operatormacros_curve(void); void ED_keymap_curve(struct wmKeyConfig *keyconf); /* editcurve.c */ +void ED_curve_transform(struct Curve *cv, float mat[4][4]); void CU_deselect_all(struct Object *obedit); void CU_select_all(struct Object *obedit); void CU_select_swap(struct Object *obedit); diff --git a/source/blender/editors/include/ED_lattice.h b/source/blender/editors/include/ED_lattice.h index 6fe1524cb6d..4d19b6d5548 100644 --- a/source/blender/editors/include/ED_lattice.h +++ b/source/blender/editors/include/ED_lattice.h @@ -32,9 +32,11 @@ #define __ED_LATTICE_H__ struct Object; +struct Lattice; void free_editLatt(struct Object *ob); void make_editLatt(struct Object *obedit); void load_editLatt(struct Object *obedit); +void ED_lattice_transform(struct Lattice *lt, float mat[4][4]); #endif /* __ED_LATTICE_H__ */ diff --git a/source/blender/editors/include/ED_mball.h b/source/blender/editors/include/ED_mball.h index 22aec69838b..680e9d79109 100644 --- a/source/blender/editors/include/ED_mball.h +++ b/source/blender/editors/include/ED_mball.h @@ -50,6 +50,6 @@ void load_editMball(struct Object *obedit); void undo_push_mball(struct bContext *C, const char *name); -void ED_mball_transform(struct MetaBall *mb, float *mat); +void ED_mball_transform(struct MetaBall *mb, float mat[4][4]); #endif /* __ED_MBALL_H__ */ diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 9d3404aa29b..6d9a0578007 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -269,7 +269,7 @@ void ED_mesh_faces_remove(struct Mesh *mesh, struct ReportList *reports, int cou void ED_mesh_edges_remove(struct Mesh *mesh, struct ReportList *reports, int count); void ED_mesh_vertices_remove(struct Mesh *mesh, struct ReportList *reports, int count); -void ED_mesh_transform(struct Mesh *me, float *mat); +void ED_mesh_transform(struct Mesh *me, float mat[4][4]); void ED_mesh_calc_tessface(struct Mesh *mesh); void ED_mesh_update(struct Mesh *mesh, struct bContext *C, int calc_edges, int calc_tessface); diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index f35a46b50d3..6decec75de4 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -880,13 +880,13 @@ static void mesh_add_verts(Mesh *mesh, int len) mesh->totvert = totvert; } -void ED_mesh_transform(Mesh *me, float *mat) +void ED_mesh_transform(Mesh *me, float mat[4][4]) { int i; MVert *mvert = me->mvert; for (i = 0; i < me->totvert; i++, mvert++) - mul_m4_v3((float (*)[4])mat, mvert->co); + mul_m4_v3(mat, mvert->co); /* don't update normals, caller can do this explicitly */ } diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index 3daffe9bb37..26008694b3c 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -751,18 +751,17 @@ void undo_push_mball(bContext *C, const char *name) undo_editmode_push(C, name, get_data, free_undoMball, undoMball_to_editMball, editMball_to_undoMball, NULL); } -/* matrix is 4x4 */ -void ED_mball_transform(MetaBall *mb, float *mat) +void ED_mball_transform(MetaBall *mb, float mat[4][4]) { MetaElem *me; float quat[4]; - const float scale = mat4_to_scale((float (*)[4])mat); + const float scale = mat4_to_scale(mat); const float scale_sqrt = sqrtf(scale); - mat4_to_quat(quat, (float (*)[4])mat); + mat4_to_quat(quat, mat); for (me = mb->elems.first; me; me = me->next) { - mul_m4_v3((float (*)[4])mat, &me->x); + mul_m4_v3(mat, &me->x); mul_qt_qtqt(me->quat, quat, me->quat); me->rad *= scale; /* hrmf, probably elems shouldn't be @@ -774,4 +773,5 @@ void ED_mball_transform(MetaBall *mb, float *mat) mul_v3_fl(&me->expx, scale_sqrt); } } + DAG_id_tag_update(&mb->id, 0); } diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 465eb07f993..dc641dbe765 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -343,9 +343,9 @@ static bool ED_object_editmode_load_ex(Object *obedit, const bool freedata) } } else if (obedit->type == OB_ARMATURE) { - ED_armature_from_edit(obedit); + ED_armature_from_edit(obedit->data); if (freedata) - ED_armature_edit_free(obedit); + ED_armature_edit_free(obedit->data); } else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { load_editNurb(obedit); @@ -493,7 +493,7 @@ void ED_object_editmode_enter(bContext *C, int flag) WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MESH, scene); } else if (ob->type == OB_ARMATURE) { - bArmature *arm = base->object->data; + bArmature *arm = ob->data; if (!arm) return; /* * The function BKE_object_obdata_is_libdata make a problem here, the @@ -509,7 +509,7 @@ void ED_object_editmode_enter(bContext *C, int flag) } ok = 1; scene->obedit = ob; - ED_armature_to_edit(ob); + ED_armature_to_edit(arm); /* to ensure all goes in restposition and without striding */ DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); /* XXX: should this be OB_RECALC_DATA? */ diff --git a/source/blender/editors/object/object_lattice.c b/source/blender/editors/object/object_lattice.c index fdc9a604c07..c5e2aff0bc2 100644 --- a/source/blender/editors/object/object_lattice.c +++ b/source/blender/editors/object/object_lattice.c @@ -174,6 +174,21 @@ void load_editLatt(Object *obedit) } } +/*************************** Transform Operator ************************/ + +void ED_lattice_transform(Lattice *lt, float mat[4][4]) +{ + BPoint *bp = lt->def; + int a = lt->pntsu * lt->pntsv * lt->pntsw; + + while (a--) { + mul_m4_v3(mat, bp->vec); + bp++; + } + + DAG_id_tag_update(<->id, 0); +} + /************************** Select Random Operator **********************/ static int lattice_select_random_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 16b54b4f4b4..c06164203b6 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -1787,8 +1787,8 @@ static Object *modifier_skin_armature_create(Main *bmain, Scene *scene, Object * MEM_freeN(emap); MEM_freeN(emap_mem); - ED_armature_from_edit(arm_ob); - ED_armature_edit_free(arm_ob); + ED_armature_from_edit(arm); + ED_armature_edit_free(arm); return arm_ob; } diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 63388600398..d40d239319c 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -512,7 +512,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo } else if (ob->type == OB_MBALL) { MetaBall *mb = ob->data; - ED_mball_transform(mb, (float *)mat); + ED_mball_transform(mb, mat); } else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { Curve *cu = ob->data; diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 0e357dc53c1..df1dad69db0 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -128,7 +128,7 @@ void ED_editors_exit(bContext *C) } } else if (ob->type == OB_ARMATURE) { - ED_armature_edit_free(ob); + ED_armature_edit_free(ob->data); } } } |