Fix #35997: add armature > single bone, then change location or rotation would
move only the origin and not the bone. It doesn't need to use any object matrices to add the bone, the only reason this worked before is because they were still unit matrices due to depsgraph not running immediately on add.
This commit is contained in:
@@ -84,39 +84,25 @@ EditBone *ED_armature_edit_bone_add(bArmature *arm, const char *name)
|
||||
return bone;
|
||||
}
|
||||
|
||||
/* v3d and rv3d are allowed to be NULL */
|
||||
void add_primitive_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d)
|
||||
void add_primitive_bone(Object *obedit_arm, bool view_aligned)
|
||||
{
|
||||
Object *obedit = scene->obedit; // XXX get from context
|
||||
bArmature *arm = obedit->data;
|
||||
float obmat[3][3], curs[3], viewmat[3][3], totmat[3][3], imat[3][3];
|
||||
EditBone *bone;
|
||||
bArmature *arm = obedit_arm->data;
|
||||
EditBone *bone;
|
||||
|
||||
/* Get inverse point for head and orientation for tail */
|
||||
invert_m4_m4(obedit->imat, obedit->obmat);
|
||||
mul_v3_m4v3(curs, obedit->imat, give_cursor(scene, v3d));
|
||||
|
||||
if (rv3d && (U.flag & USER_ADD_VIEWALIGNED))
|
||||
copy_m3_m4(obmat, rv3d->viewmat);
|
||||
else unit_m3(obmat);
|
||||
|
||||
copy_m3_m4(viewmat, obedit->obmat);
|
||||
mul_m3_m3m3(totmat, obmat, viewmat);
|
||||
invert_m3_m3(imat, totmat);
|
||||
|
||||
ED_armature_deselect_all(obedit, 0);
|
||||
ED_armature_deselect_all(obedit_arm, 0);
|
||||
|
||||
/* Create a bone */
|
||||
bone = ED_armature_edit_bone_add(arm, "Bone");
|
||||
|
||||
arm->act_edbone = 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
|
||||
zero_v3(bone->head);
|
||||
zero_v3(bone->tail);
|
||||
|
||||
if (view_aligned)
|
||||
bone->tail[1] = 1.0f;
|
||||
else
|
||||
add_v3_v3v3(bone->tail, bone->head, imat[2]); // bone with unit length 1, pointing up Z
|
||||
bone->tail[2] = 1.0f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ EditBone *ED_armature_bone_get_mirrored(struct ListBase *edbo, EditBone *ebo); /
|
||||
void ED_armature_sync_selection(struct ListBase *edbo);
|
||||
void ED_armature_validate_active(struct bArmature *arm);
|
||||
|
||||
void add_primitive_bone(struct Scene *scene, struct View3D *v3d, struct RegionView3D *rv3d);
|
||||
void add_primitive_bone(struct Object *obedit_arm, bool view_aligned);
|
||||
struct EditBone *ED_armature_edit_bone_add(struct bArmature *arm, const char *name);
|
||||
void ED_armature_edit_bone_remove(struct bArmature *arm, EditBone *exBone);
|
||||
bool ED_armature_ebone_is_child_recursive(EditBone *ebone_parent, EditBone *ebone_child);
|
||||
|
||||
@@ -657,12 +657,12 @@ void OBJECT_OT_text_add(wmOperatorType *ot)
|
||||
static int object_armature_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *obedit = CTX_data_edit_object(C);
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
RegionView3D *rv3d = CTX_wm_region_view3d(C);
|
||||
bool newob = false;
|
||||
bool enter_editmode;
|
||||
unsigned int layer;
|
||||
float loc[3], rot[3];
|
||||
bool view_aligned = rv3d && (U.flag & USER_ADD_VIEWALIGNED);
|
||||
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL))
|
||||
return OPERATOR_CANCELLED;
|
||||
@@ -681,8 +681,7 @@ static int object_armature_add_exec(bContext *C, wmOperator *op)
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
/* v3d and rv3d are allowed to be NULL */
|
||||
add_primitive_bone(CTX_data_scene(C), v3d, rv3d);
|
||||
add_primitive_bone(obedit, view_aligned);
|
||||
|
||||
/* userdef */
|
||||
if (newob && !enter_editmode)
|
||||
|
||||
Reference in New Issue
Block a user