Make bpy.types.EditBone.matrix writeable.
Makes importing armatures from matrices (FBX...) *much* easier.
This commit is contained in:
@@ -216,6 +216,31 @@ void ED_armature_ebone_to_mat4(EditBone *ebone, float mat[4][4])
|
||||
copy_v3_v3(mat[3], ebone->head);
|
||||
}
|
||||
|
||||
void ED_armature_ebone_from_mat3(EditBone *ebone, float mat[3][3])
|
||||
{
|
||||
float vec[3], roll;
|
||||
const float len = len_v3v3(ebone->head, ebone->tail);
|
||||
|
||||
mat3_to_vec_roll(mat, vec, &roll);
|
||||
|
||||
madd_v3_v3v3fl(ebone->tail, ebone->head, vec, len);
|
||||
ebone->roll = roll;
|
||||
}
|
||||
|
||||
void ED_armature_ebone_from_mat4(EditBone *ebone, float mat[4][4])
|
||||
{
|
||||
float mat3[3][3];
|
||||
|
||||
copy_m3_m4(mat3, mat);
|
||||
/* We want normalized matrix here, to be consistent with ebone_to_mat. */
|
||||
BLI_ASSERT_UNIT_M3(mat3);
|
||||
|
||||
sub_v3_v3(ebone->tail, ebone->head);
|
||||
copy_v3_v3(ebone->head, mat[3]);
|
||||
add_v3_v3(ebone->tail, mat[3]);
|
||||
ED_armature_ebone_from_mat3(ebone, mat3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a pointer to the bone of the given name
|
||||
*/
|
||||
|
||||
@@ -143,6 +143,9 @@ EditBone *ED_armature_bone_find_shared_parent(EditBone *ebone_child[], const uns
|
||||
void ED_armature_ebone_to_mat3(EditBone *ebone, float mat[3][3]);
|
||||
void ED_armature_ebone_to_mat4(EditBone *ebone, float mat[4][4]);
|
||||
|
||||
void ED_armature_ebone_from_mat3(EditBone *ebone, float mat[3][3]);
|
||||
void ED_armature_ebone_from_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);
|
||||
|
||||
|
||||
@@ -401,6 +401,12 @@ static void rna_EditBone_matrix_get(PointerRNA *ptr, float *values)
|
||||
ED_armature_ebone_to_mat4(ebone, (float(*)[4])values);
|
||||
}
|
||||
|
||||
static void rna_EditBone_matrix_set(PointerRNA *ptr, const float *values)
|
||||
{
|
||||
EditBone *ebone = (EditBone *)(ptr->data);
|
||||
ED_armature_ebone_from_mat4(ebone, (float(*)[4])values);
|
||||
}
|
||||
|
||||
static void rna_Armature_editbone_transform_update(Main *bmain, Scene *scene, PointerRNA *ptr)
|
||||
{
|
||||
bArmature *arm = (bArmature *)ptr->id.data;
|
||||
@@ -795,11 +801,12 @@ static void rna_def_edit_bone(BlenderRNA *brna)
|
||||
prop = RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
|
||||
/*RNA_def_property_float_sdna(prop, NULL, ""); *//* doesnt access any real data */
|
||||
RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
//RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_flag(prop, PROP_THICK_WRAP); /* no reference to original data */
|
||||
RNA_def_property_ui_text(prop, "Editbone Matrix", "Read-only matrix calculated from the roll (armature space)");
|
||||
/* TODO - this could be made writable also */
|
||||
RNA_def_property_float_funcs(prop, "rna_EditBone_matrix_get", NULL, NULL);
|
||||
RNA_def_property_ui_text(prop, "Editbone Matrix",
|
||||
"Matrix combining loc/rot of the bone (head position, direction and roll), "
|
||||
"in armature space (WARNING: does not include/support bone's length/size)");
|
||||
RNA_def_property_float_funcs(prop, "rna_EditBone_matrix_get", "rna_EditBone_matrix_set", NULL);
|
||||
|
||||
RNA_api_armature_edit_bone(srna);
|
||||
|
||||
|
||||
@@ -303,6 +303,7 @@ void WM_event_remove_timer(struct wmWindowManager *wm, struct wmWindow *win, str
|
||||
void ED_armature_edit_bone_remove(struct bArmature *arm, struct EditBone *exBone) RET_NONE
|
||||
void object_test_constraints(struct Object *owner) RET_NONE
|
||||
void ED_armature_ebone_to_mat4(struct EditBone *ebone, float mat[4][4]) RET_NONE
|
||||
void ED_armature_ebone_from_mat4(EditBone *ebone, float mat[4][4]) RET_NONE
|
||||
void ED_object_parent(struct Object *ob, struct Object *par, int type, const char *substr) RET_NONE
|
||||
void ED_object_constraint_set_active(struct Object *ob, struct bConstraint *con) RET_NONE
|
||||
void ED_node_composit_default(const struct bContext *C, struct Scene *scene) RET_NONE
|
||||
|
||||
Reference in New Issue
Block a user