bugfix [#24616] Apply Visual Transform doesn't always apply location
- object updates were not being flushed, so children weren't updating. - apply the matrix relative to the parent, added this as an option to object_apply_mat4() which allows assigning the worldspace matrix in python without worrying about the parent.
This commit is contained in:
@@ -101,7 +101,7 @@ void object_rot_to_mat3(struct Object *ob, float mat[][3]);
|
||||
void object_mat3_to_rot(struct Object *ob, float mat[][3], short use_compat);
|
||||
void object_to_mat3(struct Object *ob, float mat[][3]);
|
||||
void object_to_mat4(struct Object *ob, float mat[][4]);
|
||||
void object_apply_mat4(struct Object *ob, float mat[][4], short use_compat);
|
||||
void object_apply_mat4(struct Object *ob, float mat[][4], const short use_compat, const short use_parent);
|
||||
|
||||
void set_no_parent_ipo(int val);
|
||||
|
||||
|
||||
@@ -1550,7 +1550,7 @@ void object_make_proxy(Object *ob, Object *target, Object *gob)
|
||||
if(gob) {
|
||||
ob->rotmode= target->rotmode;
|
||||
mul_m4_m4m4(ob->obmat, target->obmat, gob->obmat);
|
||||
object_apply_mat4(ob, ob->obmat, FALSE);
|
||||
object_apply_mat4(ob, ob->obmat, FALSE, TRUE);
|
||||
}
|
||||
else {
|
||||
copy_object_transform(ob, target);
|
||||
@@ -1694,11 +1694,25 @@ void object_mat3_to_rot(Object *ob, float mat[][3], short use_compat)
|
||||
}
|
||||
|
||||
/* see pchan_apply_mat4() for the equivalent 'pchan' function */
|
||||
void object_apply_mat4(Object *ob, float mat[][4], short use_compat)
|
||||
void object_apply_mat4(Object *ob, float mat[][4], const short use_compat, const short use_parent)
|
||||
{
|
||||
float rot[3][3];
|
||||
mat4_to_loc_rot_size(ob->loc, rot, ob->size, mat);
|
||||
object_mat3_to_rot(ob, rot, use_compat);
|
||||
|
||||
if(use_parent && ob->parent) {
|
||||
float rmat[4][4], diff_mat[4][4], imat[4][4];
|
||||
mul_m4_m4m4(diff_mat, ob->parentinv, ob->parent->obmat);
|
||||
invert_m4_m4(imat, diff_mat);
|
||||
mul_m4_m4m4(rmat, mat, imat); /* get the parent relative matrix */
|
||||
object_apply_mat4(ob, rmat, use_compat, FALSE);
|
||||
|
||||
/* same as below, use rmat rather then mat */
|
||||
mat4_to_loc_rot_size(ob->loc, rot, ob->size, rmat);
|
||||
object_mat3_to_rot(ob, rot, use_compat);
|
||||
}
|
||||
else {
|
||||
mat4_to_loc_rot_size(ob->loc, rot, ob->size, mat);
|
||||
object_mat3_to_rot(ob, rot, use_compat);
|
||||
}
|
||||
}
|
||||
|
||||
void object_to_mat3(Object *ob, float mat[][3]) /* no parent */
|
||||
@@ -2127,7 +2141,7 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[
|
||||
copy_m3_m4(originmat, tmat);
|
||||
|
||||
// origin, voor help line
|
||||
if( (ob->partype & 15)==PARSKEL ) {
|
||||
if( (ob->partype & PARTYPE)==PARSKEL ) {
|
||||
VECCOPY(ob->orig, par->obmat[3]);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -403,7 +403,7 @@ void AnimationImporter::read_node_transform(COLLADAFW::Node *node, Object *ob)
|
||||
TransformReader::get_node_mat(mat, node, &uid_animated_map, ob);
|
||||
if (ob) {
|
||||
copy_m4_m4(ob->obmat, mat);
|
||||
object_apply_mat4(ob, ob->obmat, 0);
|
||||
object_apply_mat4(ob, ob->obmat, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::Unique
|
||||
((ArmatureModifierData *)md)->object = ob_arm;
|
||||
|
||||
copy_m4_m4(ob->obmat, bind_shape_matrix);
|
||||
object_apply_mat4(ob, ob->obmat, 0);
|
||||
object_apply_mat4(ob, ob->obmat, 0, 0);
|
||||
#if 1
|
||||
bc_set_parent(ob, ob_arm, C);
|
||||
#else
|
||||
|
||||
@@ -88,7 +88,7 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
|
||||
}
|
||||
|
||||
// apply child obmat (i.e. decompose it into rot/loc/size)
|
||||
object_apply_mat4(ob, ob->obmat, 0);
|
||||
object_apply_mat4(ob, ob->obmat, 0, 0);
|
||||
|
||||
// compute parentinv
|
||||
what_does_parent(sce, ob, &workob);
|
||||
|
||||
@@ -534,7 +534,7 @@ static void applyarmature_fix_boneparents (Scene *scene, Object *armob)
|
||||
/* apply current transform from parent (not yet destroyed),
|
||||
* then calculate new parent inverse matrix
|
||||
*/
|
||||
object_apply_mat4(ob, ob->obmat, FALSE);
|
||||
object_apply_mat4(ob, ob->obmat, FALSE, FALSE);
|
||||
|
||||
what_does_parent(scene, ob, &workob);
|
||||
invert_m4_m4(ob->parentinv, workob.obmat);
|
||||
|
||||
@@ -982,7 +982,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base)
|
||||
ob->lay= base->lay;
|
||||
|
||||
copy_m4_m4(ob->obmat, dob->mat);
|
||||
object_apply_mat4(ob, ob->obmat, FALSE);
|
||||
object_apply_mat4(ob, ob->obmat, FALSE, FALSE);
|
||||
}
|
||||
|
||||
copy_object_set_idnew(C, 0);
|
||||
|
||||
@@ -431,7 +431,7 @@ static int parent_clear_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
else if(type == 1) {
|
||||
ob->parent= NULL;
|
||||
object_apply_mat4(ob, ob->obmat, TRUE);
|
||||
object_apply_mat4(ob, ob->obmat, TRUE, FALSE);
|
||||
}
|
||||
else if(type == 2)
|
||||
unit_m4(ob->parentinv);
|
||||
@@ -906,7 +906,7 @@ static int object_track_clear_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
if(type == 1)
|
||||
object_apply_mat4(ob, ob->obmat, TRUE);
|
||||
object_apply_mat4(ob, ob->obmat, TRUE, TRUE);
|
||||
}
|
||||
CTX_DATA_END;
|
||||
|
||||
|
||||
@@ -391,7 +391,7 @@ static void ignore_parent_tx(Main *bmain, Scene *scene, Object *ob )
|
||||
/* a change was made, adjust the children to compensate */
|
||||
for(ob_child=bmain->object.first; ob_child; ob_child=ob_child->id.next) {
|
||||
if(ob_child->parent == ob) {
|
||||
object_apply_mat4(ob_child, ob_child->obmat, TRUE);
|
||||
object_apply_mat4(ob_child, ob_child->obmat, TRUE, FALSE);
|
||||
what_does_parent(scene, ob_child, &workob);
|
||||
invert_m4_m4(ob_child->parentinv, workob.obmat);
|
||||
}
|
||||
@@ -577,9 +577,12 @@ static int visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
|
||||
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
|
||||
where_is_object(scene, ob);
|
||||
object_apply_mat4(ob, ob->obmat, TRUE);
|
||||
object_apply_mat4(ob, ob->obmat, TRUE, TRUE);
|
||||
where_is_object(scene, ob);
|
||||
|
||||
|
||||
/* update for any children that may get moved */
|
||||
DAG_id_flush_update(&ob->id, OB_RECALC_OB);
|
||||
|
||||
change = 1;
|
||||
}
|
||||
CTX_DATA_END;
|
||||
|
||||
@@ -794,7 +794,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
|
||||
view3d_persp_mat4(rv3d, view_mat);
|
||||
mul_m4_m4m4(diff_mat, prev_view_imat, view_mat);
|
||||
mul_m4_m4m4(parent_mat, fly->root_parent->obmat, diff_mat);
|
||||
object_apply_mat4(fly->root_parent, parent_mat, TRUE);
|
||||
object_apply_mat4(fly->root_parent, parent_mat, TRUE, FALSE);
|
||||
|
||||
// where_is_object(scene, fly->root_parent);
|
||||
|
||||
@@ -812,7 +812,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
|
||||
else {
|
||||
float view_mat[4][4];
|
||||
view3d_persp_mat4(rv3d, view_mat);
|
||||
object_apply_mat4(v3d->camera, view_mat, TRUE);
|
||||
object_apply_mat4(v3d->camera, view_mat, TRUE, FALSE);
|
||||
id_key= &v3d->camera->id;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ static void rna_Object_internal_update(Main *bmain, Scene *scene, PointerRNA *pt
|
||||
static void rna_Object_matrix_world_update(Main *bmain, Scene *scene, PointerRNA *ptr)
|
||||
{
|
||||
/* dont use compat so we get pradictable rotation */
|
||||
object_apply_mat4(ptr->id.data, ((Object *)ptr->id.data)->obmat, FALSE);
|
||||
object_apply_mat4(ptr->id.data, ((Object *)ptr->id.data)->obmat, FALSE, TRUE);
|
||||
rna_Object_internal_update(bmain, scene, ptr);
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ static void rna_Object_matrix_local_set(PointerRNA *ptr, const float values[16])
|
||||
}
|
||||
|
||||
/* dont use compat so we get pradictable rotation */
|
||||
object_apply_mat4(ob, ob->obmat, FALSE);
|
||||
object_apply_mat4(ob, ob->obmat, FALSE, FALSE);
|
||||
}
|
||||
|
||||
void rna_Object_internal_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
|
||||
|
||||
Reference in New Issue
Block a user