bugfix [#24616] Apply Visual Transform doesn't always apply location
authorCampbell Barton <ideasman42@gmail.com>
Mon, 8 Nov 2010 22:32:28 +0000 (22:32 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 8 Nov 2010 22:32:28 +0000 (22:32 +0000)
- 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.

source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/object.c
source/blender/collada/AnimationImporter.cpp
source/blender/collada/SkinInfo.cpp
source/blender/collada/collada_utils.cpp
source/blender/editors/armature/editarmature.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_relations.c
source/blender/editors/object/object_transform.c
source/blender/editors/space_view3d/view3d_fly.c
source/blender/makesrna/intern/rna_object.c

index b64011a7c9acb305a0af861223ed727e88d4ce1e..8999d7285c270e8bdd2bbf8d144a12118f640f75 100644 (file)
@@ -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);
 
index e006c48aca55c16f610e2f007c7aae932fb41216..9512aa3a1cee63c157bd04178ce3d7878bf109e5 100644 (file)
@@ -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 {
index c7267bd46f820673e0936e1e56ec0b3da5a334c0..d462042b3f6e7ba5725360240838efc6236d4efa 100644 (file)
@@ -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);
        }
 }
 
index b052f283e62fa3231b5dd32c048c608369185ea5..97d12f10c05f83473020101ac25a704dfec606b2 100644 (file)
@@ -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
index 98728001eb8c2816e87e223f65f877e89d6fe65c..b6451c58a018d12ad2066eeb2a402c88cf3dbb2f 100644 (file)
@@ -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);
index 9dd86a96dae90ea2ff484db80d8a06246e27a977..8b5b99c28707337d47a15555238d35bf26f61e64 100644 (file)
@@ -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);
index 196440f29cfe90e0a6754b62c863bb6ecaaf7759..dd0f041342fe6f00c4f4be5cd33259205f728b0c 100644 (file)
@@ -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);
index 5f9eeb041255a925d1c6d89113dd0f8016bdf796..c017895c0168f879cd67e5fbaf46f74d105c8572 100644 (file)
@@ -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;
 
index bd8a7f999788504a5cc3f6fbb344290128d8d4cf..2917de2864b610c1d705303e6ce603cd2c861488 100644 (file)
@@ -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;
index e137270aa5bbab6cbbd03aa9a95d15273837d9e1..b6372242a9abd7347127a477e338f5e3cad8c628 100644 (file)
@@ -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;
                                }
 
index 599aa4abc9191570de1f953799c817746576d3d7..e2967d570fa914099773d837b2d2ea334b07b8a4 100644 (file)
@@ -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)