diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-11-09 01:32:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-11-09 01:32:28 +0300 |
commit | c4967b5dde966a3342a835fc8831fa170f856a97 (patch) | |
tree | 07eb5779f0612c66a73a4eb88783b2072e6c707f | |
parent | 0c27782b8e4b2eb8f756b081cef39c5ee089b032 (diff) |
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.
-rw-r--r-- | source/blender/blenkernel/BKE_object.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 24 | ||||
-rw-r--r-- | source/blender/collada/AnimationImporter.cpp | 2 | ||||
-rw-r--r-- | source/blender/collada/SkinInfo.cpp | 2 | ||||
-rw-r--r-- | source/blender/collada/collada_utils.cpp | 2 | ||||
-rw-r--r-- | source/blender/editors/armature/editarmature.c | 2 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 2 | ||||
-rw-r--r-- | source/blender/editors/object/object_relations.c | 4 | ||||
-rw-r--r-- | source/blender/editors/object/object_transform.c | 9 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_fly.c | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 4 |
11 files changed, 37 insertions, 20 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index b64011a7c9a..8999d7285c2 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -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); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index e006c48aca5..9512aa3a1ce 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -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 { diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index c7267bd46f8..d462042b3f6 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -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); } } diff --git a/source/blender/collada/SkinInfo.cpp b/source/blender/collada/SkinInfo.cpp index b052f283e62..97d12f10c05 100644 --- a/source/blender/collada/SkinInfo.cpp +++ b/source/blender/collada/SkinInfo.cpp @@ -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 diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index 98728001eb8..b6451c58a01 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -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); diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 9dd86a96dae..8b5b99c2870 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -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); diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 196440f29cf..dd0f041342f 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -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); diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 5f9eeb04125..c017895c016 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -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; diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index bd8a7f99978..2917de2864b 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -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; diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index e137270aa5b..b6372242a9a 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -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; } diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 599aa4abc91..e2967d570fa 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -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) |