Anim: Align new bones with the world axes #113138

Open
Sybren A. Stüvel wants to merge 2 commits from dr.sybren/blender:pr/align-default-bone-to-y into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 11 additions and 15 deletions

View File

@ -87,7 +87,7 @@ EditBone *ED_armature_ebone_add(bArmature *arm, const char *name)
return bone;
}
EditBone *ED_armature_ebone_add_primitive(Object *obedit_arm, float length, bool view_aligned)
EditBone *ED_armature_ebone_add_primitive(Object *obedit_arm, const float length)
{
bArmature *arm = static_cast<bArmature *>(obedit_arm->data);
EditBone *bone;
@ -100,9 +100,9 @@ EditBone *ED_armature_ebone_add_primitive(Object *obedit_arm, float length, bool
arm->act_edbone = bone;
zero_v3(bone->head);
zero_v3(bone->tail);
bone->tail[view_aligned ? 1 : 2] = length;
bone->tail[0] = 0;
bone->tail[1] = length;
bone->tail[2] = 0;
if (arm->runtime.active_collection) {
ANIM_armature_bonecoll_assign_editbone(arm->runtime.active_collection, bone);
@ -1655,13 +1655,7 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op)
ANIM_armature_bonecoll_assign_active(static_cast<bArmature *>(obedit->data), bone);
copy_v3_v3(bone->head, curs);
if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) {
add_v3_v3v3(bone->tail, bone->head, imat[1]); /* bone with unit length 1 */
}
else {
add_v3_v3v3(bone->tail, bone->head, imat[2]); /* bone with unit length 1, pointing up Z */
}
add_v3_v3v3(bone->tail, bone->head, imat[1]); /* bone with unit length 1 */
/* NOTE: notifier might evolve. */
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit);

View File

@ -62,7 +62,11 @@ struct wmOperator;
* \note should be used everywhere, now it allocates bones still locally in functions.
*/
EditBone *ED_armature_ebone_add(bArmature *arm, const char *name);
EditBone *ED_armature_ebone_add_primitive(Object *obedit_arm, float length, bool view_aligned);
/**
* Add a new editbone, with the head at the origin and the tail at (0, length, 0).
*/
EditBone *ED_armature_ebone_add_primitive(Object *obedit_arm, float length);
void ED_armature_ebone_copy(EditBone *dest, const EditBone *source);

View File

@ -1119,12 +1119,10 @@ static int object_armature_add_exec(bContext *C, wmOperator *op)
BKE_view_layer_synced_ensure(scene, view_layer);
Object *obedit = BKE_view_layer_edit_object_get(view_layer);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
bool newob = false;
bool enter_editmode;
ushort local_view_bits;
float loc[3], rot[3], dia;
bool view_aligned = rv3d && (U.flag & USER_ADD_VIEWALIGNED);
WM_operator_view3d_unit_defaults(C, op);
if (!ED_object_add_generic_get_opts(
@ -1152,7 +1150,7 @@ static int object_armature_add_exec(bContext *C, wmOperator *op)
ANIM_armature_bonecoll_active_set(armature, default_bonecoll);
dia = RNA_float_get(op->ptr, "radius");
ED_armature_ebone_add_primitive(obedit, dia, view_aligned);
ED_armature_ebone_add_primitive(obedit, dia);
/* userdef */
if (newob && !enter_editmode) {