[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18818] branches/blender2.5/blender/source /blender: 2.5 - Context API access for Bones (EditMode and PoseMode)
Joshua Leung
aligorith at gmail.com
Thu Feb 5 04:28:27 CET 2009
Revision: 18818
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18818
Author: aligorith
Date: 2009-02-05 04:28:07 +0100 (Thu, 05 Feb 2009)
Log Message:
-----------
2.5 - Context API access for Bones (EditMode and PoseMode)
* Added selected, selected+editable, and active to access EditBones for Armature Operators to use. These take into account X-Axis Mirror too, so there is really no need to check that sort of thing anymore in tools.
* Added a quick testing operator for verifying that these loops filter the data correctly. I've dumped this in armature_ops.c for now. It can be activated using the TKEY hotkey in Armature EditMode only. This should be removed once we have a few more functional tools.
* Ported over cleaned up roll-calculation tools from AnimSys2
* Removed a few ugly stubs from posemode code
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/blenkernel/BKE_context.h
branches/blender2.5/blender/source/blender/blenkernel/intern/context.c
branches/blender2.5/blender/source/blender/editors/armature/armature_ops.c
branches/blender2.5/blender/source/blender/editors/armature/editarmature.c
branches/blender2.5/blender/source/blender/editors/armature/poseobject.c
branches/blender2.5/blender/source/blender/editors/space_view3d/space_view3d.c
branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_context.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_context.h 2009-02-05 01:32:37 UTC (rev 18817)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_context.h 2009-02-05 03:28:07 UTC (rev 18818)
@@ -51,6 +51,8 @@
struct ToolSettings;
struct Image;
struct ImBuf;
+struct EditBone;
+struct bPoseChannel;
struct wmWindow;
struct wmWindowManager;
@@ -81,7 +83,14 @@
CTX_DATA_EDIT_IMAGE,
CTX_DATA_EDIT_IMAGE_BUFFER,
- CTX_DATA_SELECTED_NODES
+ CTX_DATA_SELECTED_NODES,
+
+ CTX_DATA_SELECTED_BONES,
+ CTX_DATA_SELECTED_EDITABLE_BONES,
+ CTX_DATA_SELECTED_PCHANS,
+
+ CTX_DATA_ACTIVE_BONE,
+ CTX_DATA_ACTIVE_PCHAN,
};
typedef int bContextDataMember;
@@ -185,6 +194,13 @@
int CTX_data_selected_nodes(const bContext *C, ListBase *list);
+struct EditBone *CTX_data_active_bone(const bContext *C);
+int CTX_data_selected_bones(const bContext *C, ListBase *list);
+int CTX_data_selected_editable_bones(const bContext *C, ListBase *list);
+
+struct bPoseChannel *CTX_data_active_pchan(const bContext *C);
+int CTX_data_selected_pchans(const bContext *C, ListBase *list);
+
/* Data Evaluation Context */
float CTX_eval_frame(const bContext *C);
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/context.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/context.c 2009-02-05 01:32:37 UTC (rev 18817)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/context.c 2009-02-05 03:28:07 UTC (rev 18818)
@@ -441,6 +441,31 @@
return ctx_data_pointer_get(C, CTX_DATA_EDIT_IMAGE_BUFFER);
}
+struct EditBone *CTX_data_active_bone(const bContext *C)
+{
+ return ctx_data_pointer_get(C, CTX_DATA_ACTIVE_BONE);
+}
+
+int CTX_data_selected_bones(const bContext *C, ListBase *list)
+{
+ return ctx_data_collection_get(C, CTX_DATA_SELECTED_BONES, list);
+}
+
+int CTX_data_selected_editable_bones(const bContext *C, ListBase *list)
+{
+ return ctx_data_collection_get(C, CTX_DATA_SELECTED_EDITABLE_BONES, list);
+}
+
+struct bPoseChannel *CTX_data_active_pchan(const bContext *C)
+{
+ return ctx_data_pointer_get(C, CTX_DATA_ACTIVE_PCHAN);
+}
+
+int CTX_data_selected_pchans(const bContext *C, ListBase *list)
+{
+ return ctx_data_collection_get(C, CTX_DATA_SELECTED_PCHANS, list);
+}
+
/* data evaluation */
float CTX_eval_frame(const bContext *C)
Modified: branches/blender2.5/blender/source/blender/editors/armature/armature_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/armature/armature_ops.c 2009-02-05 01:32:37 UTC (rev 18817)
+++ branches/blender2.5/blender/source/blender/editors/armature/armature_ops.c 2009-02-05 03:28:07 UTC (rev 18818)
@@ -58,7 +58,50 @@
#include "armature_intern.h"
+/* ************************** quick tests **********************************/
+/* XXX This is a quick test operator to print names of all EditBones in context
+ * that should be removed once tool coding starts...
+ */
+
+static int armature_test_exec (bContext *C, wmOperator *op)
+{
+ printf("EditMode Armature Test: \n");
+
+ printf("\tSelected Bones \n");
+ CTX_DATA_BEGIN(C, EditBone*, ebone, selected_bones)
+ {
+ printf("\t\tEditBone '%s' \n", ebone->name);
+ }
+ CTX_DATA_END;
+
+ printf("\tEditable Bones \n");
+ CTX_DATA_BEGIN(C, EditBone*, ebone, selected_editable_bones)
+ {
+ printf("\t\tEditBone '%s' \n", ebone->name);
+ }
+ CTX_DATA_END;
+
+ printf("\tActive Bone \n");
+ {
+ EditBone *ebone= CTX_data_active_bone(C);
+ if (ebone) printf("\t\tEditBone '%s' \n");
+ else printf("\t\t<None> \n");
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+void ARMATURE_OT_test(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Test Context";
+ ot->idname= "ARMATURE_OT_test";
+
+ /* api callbacks */
+ ot->exec= armature_test_exec;
+}
+
/* ************************** registration **********************************/
/* Both operators ARMATURE_OT_xxx and POSE_OT_xxx here */
@@ -66,16 +109,23 @@
{
WM_operatortype_append(POSE_OT_hide);
WM_operatortype_append(POSE_OT_reveil);
+
+ WM_operatortype_append(ARMATURE_OT_test); // XXX temp test for context iterators... to be removed
}
void ED_keymap_armature(wmWindowManager *wm)
{
- ListBase *keymap= WM_keymap_listbase(wm, "Armature", 0, 0);
+ ListBase *keymap;
wmKeymapItem *kmi;
+ /* Armature ------------------------ */
+ keymap= WM_keymap_listbase(wm, "Armature", 0, 0);
+
/* only set in editmode armature, by space_view3d listener */
// WM_keymap_add_item(keymap, "ARMATURE_OT_hide", HKEY, KM_PRESS, 0, 0);
-
+ WM_keymap_add_item(keymap, "ARMATURE_OT_test", TKEY, KM_PRESS, 0, 0); // XXX temp test for context iterators... to be removed
+
+ /* Pose ------------------------ */
/* only set in posemode, by space_view3d listener */
keymap= WM_keymap_listbase(wm, "Pose", 0, 0);
Modified: branches/blender2.5/blender/source/blender/editors/armature/editarmature.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/armature/editarmature.c 2009-02-05 01:32:37 UTC (rev 18817)
+++ branches/blender2.5/blender/source/blender/editors/armature/editarmature.c 2009-02-05 03:28:07 UTC (rev 18818)
@@ -1844,20 +1844,97 @@
return roll;
}
+
+/* Set roll value for given bone -> Z-Axis Point up (original method) */
+void auto_align_ebone_zaxisup(Scene *scene, View3D *v3d, EditBone *ebone)
+{
+ float delta[3], curmat[3][3];
+ float xaxis[3]={1.0f, 0.0f, 0.0f}, yaxis[3], zaxis[3]={0.0f, 0.0f, 1.0f};
+ float targetmat[3][3], imat[3][3], diffmat[3][3];
+
+ /* Find the current bone matrix */
+ VecSubf(delta, ebone->tail, ebone->head);
+ vec_roll_to_mat3(delta, 0.0f, curmat);
+
+ /* Make new matrix based on y axis & z-up */
+ VECCOPY(yaxis, curmat[1]);
+
+ Mat3One(targetmat);
+ VECCOPY(targetmat[0], xaxis);
+ VECCOPY(targetmat[1], yaxis);
+ VECCOPY(targetmat[2], zaxis);
+ Mat3Ortho(targetmat);
+
+ /* Find the difference between the two matrices */
+ Mat3Inv(imat, targetmat);
+ Mat3MulMat3(diffmat, imat, curmat);
+
+ // old-method... let's see if using mat3_to_vec_roll is more accurate
+ //ebone->roll = atan2(diffmat[2][0], diffmat[2][2]);
+ mat3_to_vec_roll(diffmat, delta, &ebone->roll);
+}
+
+/* Set roll value for given bone -> Z-Axis point towards cursor */
+void auto_align_ebone_tocursor(Scene *scene, View3D *v3d, EditBone *ebone)
+{
+ Object *obedit= scene->obedit; // XXX get from context
+ float *cursor= give_cursor(scene, v3d);
+ float delta[3], curmat[3][3];
+ float mat[4][4], tmat[4][4], imat[4][4];
+ float rmat[4][4], rot[3];
+ float vec[3];
+
+ /* find the current bone matrix as a 4x4 matrix (in Armature Space) */
+ VecSubf(delta, ebone->tail, ebone->head);
+ vec_roll_to_mat3(delta, ebone->roll, curmat);
+ Mat4CpyMat3(mat, curmat);
+ VECCOPY(mat[3], ebone->head);
+
+ /* multiply bone-matrix by object matrix (so that bone-matrix is in WorldSpace) */
+ Mat4MulMat4(tmat, mat, obedit->obmat);
+ Mat4Invert(imat, tmat);
+
+ /* find position of cursor relative to bone */
+ VecMat4MulVecfl(vec, imat, cursor);
+
+ /* check that cursor is in usable position */
+ if ((IS_EQ(vec[0], 0)==0) && (IS_EQ(vec[2], 0)==0)) {
+ /* Compute a rotation matrix around y */
+ rot[1] = atan2(vec[0], vec[2]);
+ rot[0] = rot[2] = 0.0f;
+ EulToMat4(rot, rmat);
+
+ /* Multiply the bone matrix by rotation matrix. This should be new bone-matrix */
+ Mat4MulMat4(tmat, rmat, mat);
+ Mat3CpyMat4(curmat, tmat);
+
+ /* Now convert from new bone-matrix, back to a roll value (in radians) */
+ mat3_to_vec_roll(curmat, delta, &ebone->roll);
+ }
+}
+
/* Sets the roll value of selected bones, depending on the mode
* mode == 0: their z-axes point upwards
* mode == 1: their z-axes point towards 3d-cursor
*/
void auto_align_armature(Scene *scene, View3D *v3d, short mode)
{
- Object *obedit= scene->obedit; // XXX get from context
+ Object *obedit= scene->obedit;
bArmature *arm= obedit->data;
EditBone *ebone;
EditBone *flipbone = NULL;
- float delta[3];
- float curmat[3][3];
- float *cursor= give_cursor(scene, v3d);
-
+ void (*roll_func)(Scene *, View3D *, EditBone *) = NULL;
+
+ /* specific method used to calculate roll depends on mode */
+ switch (mode) {
+ case 1: /* Z-Axis point towards cursor */
+ roll_func= auto_align_ebone_tocursor;
+ break;
+ default: /* Z-Axis Point Up */
+ roll_func= auto_align_ebone_zaxisup;
+ break;
+ }
+
for (ebone = arm->edbo->first; ebone; ebone=ebone->next) {
if (EBONE_VISIBLE(arm, ebone)) {
if (arm->flag & ARM_MIRROR_EDIT)
@@ -1866,65 +1943,8 @@
if ((ebone->flag & BONE_SELECTED) ||
(flipbone && (flipbone->flag & BONE_SELECTED)))
{
- /* specific method used to calculate roll depends on mode */
- if (mode == 1) {
- /* Z-Axis point towards cursor */
- float mat[4][4], tmat[4][4], imat[4][4];
- float rmat[4][4], rot[3];
- float vec[3];
-
- /* find the current bone matrix as a 4x4 matrix (in Armature Space) */
- VecSubf(delta, ebone->tail, ebone->head);
- vec_roll_to_mat3(delta, ebone->roll, curmat);
- Mat4CpyMat3(mat, curmat);
- VECCOPY(mat[3], ebone->head);
-
- /* multiply bone-matrix by object matrix (so that bone-matrix is in WorldSpace) */
- Mat4MulMat4(tmat, mat, obedit->obmat);
- Mat4Invert(imat, tmat);
-
- /* find position of cursor relative to bone */
- VecMat4MulVecfl(vec, imat, cursor);
-
- /* check that cursor is in usable position */
- if ((IS_EQ(vec[0], 0)==0) && (IS_EQ(vec[2], 0)==0)) {
- /* Compute a rotation matrix around y */
- rot[1] = atan2(vec[0], vec[2]);
- rot[0] = rot[2] = 0.0f;
- EulToMat4(rot, rmat);
-
- /* Multiply the bone matrix by rotation matrix. This should be new bone-matrix */
- Mat4MulMat4(tmat, rmat, mat);
- Mat3CpyMat4(curmat, tmat);
-
- /* Now convert from new bone-matrix, back to a roll value (in radians) */
- mat3_to_vec_roll(curmat, delta, &ebone->roll);
- }
- }
- else {
- /* Z-Axis Point Up */
- float xaxis[3]={1.0, 0.0, 0.0}, yaxis[3], zaxis[3]={0.0, 0.0, 1.0};
- float targetmat[3][3], imat[3][3], diffmat[3][3];
-
- /* Find the current bone matrix */
- VecSubf(delta, ebone->tail, ebone->head);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list