Fix parenting objects to bones/vertices causes offset

This reverts part of rBbc5482337669.
Problem with above commit is that the evaluated object seems to not have
partype, par1, par2, par3 copied from the original (yet). Using original
object instead now.
Second issue (when parenting to 'Bone Relative') is that the bones
BONE_RELATIVE_PARENTING flag is set on the original, but not the
evaluated bone (yet), setting this on both now.

Fixes T60623 (and part of T59352)

Reviewers: brecht, sergey

Maniphest Tasks: T60623

Differential Revision: https://developer.blender.org/D4309
This commit is contained in:
Philipp Oeser
2019-02-05 15:43:34 +01:00
parent 76608f5ec5
commit 2894e75121
2 changed files with 20 additions and 12 deletions

View File

@@ -2527,7 +2527,6 @@ void BKE_object_where_is_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
*/
void BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob, Object *workob)
{
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
BKE_object_workob_clear(workob);
unit_m4(workob->obmat);
@@ -2537,17 +2536,17 @@ void BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *o
/* Since this is used while calculating parenting, at this moment ob_eval->parent is still NULL. */
workob->parent = DEG_get_evaluated_object(depsgraph, ob->parent);
workob->trackflag = ob_eval->trackflag;
workob->upflag = ob_eval->upflag;
workob->trackflag = ob->trackflag;
workob->upflag = ob->upflag;
workob->partype = ob_eval->partype;
workob->par1 = ob_eval->par1;
workob->par2 = ob_eval->par2;
workob->par3 = ob_eval->par3;
workob->partype = ob->partype;
workob->par1 = ob->par1;
workob->par2 = ob->par2;
workob->par3 = ob->par3;
workob->constraints = ob_eval->constraints;
workob->constraints = ob->constraints;
BLI_strncpy(workob->parsubstr, ob_eval->parsubstr, sizeof(workob->parsubstr));
BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr));
BKE_object_where_is_calc(depsgraph, scene, workob);
}

View File

@@ -89,6 +89,7 @@
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -615,9 +616,11 @@ bool ED_object_parent_set(ReportList *reports, const bContext *C, Scene *scene,
Main *bmain = CTX_data_main(C);
Depsgraph *depsgraph = CTX_data_depsgraph(C);
bPoseChannel *pchan = NULL;
bPoseChannel *pchan_eval = NULL;
const bool pararm = ELEM(partype, PAR_ARMATURE, PAR_ARMATURE_NAME, PAR_ARMATURE_ENVELOPE, PAR_ARMATURE_AUTO);
Object *parent_eval = DEG_get_evaluated_object(depsgraph, par);
DEG_id_tag_update(&par->id, ID_RECALC_TRANSFORM);
DEG_id_tag_update(&par->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
/* preconditions */
if (partype == PAR_FOLLOW || partype == PAR_PATH_CONST) {
@@ -653,6 +656,7 @@ bool ED_object_parent_set(ReportList *reports, const bContext *C, Scene *scene,
}
else if (ELEM(partype, PAR_BONE, PAR_BONE_RELATIVE)) {
pchan = BKE_pose_channel_active(par);
pchan_eval = BKE_pose_channel_active(parent_eval);
if (pchan == NULL) {
BKE_report(reports, RPT_ERROR, "No active bone");
@@ -680,6 +684,7 @@ bool ED_object_parent_set(ReportList *reports, const bContext *C, Scene *scene,
ob->parent = par;
/* Always clear parentinv matrix for sake of consistency, see T41950. */
unit_m4(ob->parentinv);
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
}
/* handle types */
@@ -740,13 +745,17 @@ bool ED_object_parent_set(ReportList *reports, const bContext *C, Scene *scene,
}
else if (partype == PAR_BONE) {
ob->partype = PARBONE; /* note, dna define, not operator property */
if (pchan->bone)
if (pchan->bone) {
pchan->bone->flag &= ~BONE_RELATIVE_PARENTING;
pchan_eval->bone->flag &= ~BONE_RELATIVE_PARENTING;
}
}
else if (partype == PAR_BONE_RELATIVE) {
ob->partype = PARBONE; /* note, dna define, not operator property */
if (pchan->bone)
if (pchan->bone) {
pchan->bone->flag |= BONE_RELATIVE_PARENTING;
pchan_eval->bone->flag |= BONE_RELATIVE_PARENTING;
}
}
else if (partype == PAR_VERTEX) {
ob->partype = PARVERT1;