Fix stupid handling of 'Object.matrix_local' in RNA.
The getter of this matrix (actually, `BKE_object_matrix_local_get()`) was only correct in case of pure-object parenting, bone parenting and such did not gave valid results. Also cleaned up a bit setter code, was using as temp storage ob->obmat itself, which is supposed to be a world matrix! Reviewers: campbellbarton Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D958
This commit is contained in:
parent
c5927cd977
commit
fb7ff31315
Notes:
blender-bot
2023-02-14 10:09:24 +01:00
Referenced by commit 2d4980e68e
, Fix T42510: bake animation wrong result.
|
@ -2019,12 +2019,16 @@ void BKE_object_to_mat4(Object *ob, float mat[4][4])
|
|||
add_v3_v3v3(mat[3], ob->loc, ob->dloc);
|
||||
}
|
||||
|
||||
static void ob_get_parent_matrix(Scene *scene, Object *ob, Object *par, float parentmat[4][4]);
|
||||
|
||||
void BKE_object_matrix_local_get(struct Object *ob, float mat[4][4])
|
||||
{
|
||||
if (ob->parent) {
|
||||
float invmat[4][4]; /* for inverse of parent's matrix */
|
||||
invert_m4_m4(invmat, ob->parent->obmat);
|
||||
mul_m4_m4m4(mat, invmat, ob->obmat);
|
||||
float par_imat[4][4];
|
||||
|
||||
ob_get_parent_matrix(NULL, ob, ob->parent, par_imat);
|
||||
invert_m4(par_imat);
|
||||
mul_m4_m4m4(mat, par_imat, ob->obmat);
|
||||
}
|
||||
else {
|
||||
copy_m4_m4(mat, ob->obmat);
|
||||
|
|
|
@ -102,7 +102,7 @@ void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob, B
|
|||
double d_obmat[4][4];
|
||||
float f_obmat[4][4];
|
||||
|
||||
/* Export the local Matrix (relative to the object parent) */
|
||||
/* Export the local Matrix (relative to the object parent, be it an object, bone or vertex(-tices)) */
|
||||
BKE_object_matrix_local_get(ob, f_obmat);
|
||||
converter.mat4_to_dae_double(d_obmat, f_obmat);
|
||||
|
||||
|
|
|
@ -233,21 +233,21 @@ static void rna_Object_matrix_local_get(PointerRNA *ptr, float values[16])
|
|||
static void rna_Object_matrix_local_set(PointerRNA *ptr, const float values[16])
|
||||
{
|
||||
Object *ob = ptr->id.data;
|
||||
float local_mat[4][4];
|
||||
|
||||
/* localspace matrix is truly relative to the parent, but parameters
|
||||
* stored in object are relative to parentinv matrix. Undo the parent
|
||||
* inverse part before updating obmat and calling apply_obmat() */
|
||||
/* localspace matrix is truly relative to the parent, but parameters stored in object are
|
||||
* relative to parentinv matrix. Undo the parent inverse part before applying it as local matrix. */
|
||||
if (ob->parent) {
|
||||
float invmat[4][4];
|
||||
invert_m4_m4(invmat, ob->parentinv);
|
||||
mul_m4_m4m4(ob->obmat, invmat, (float(*)[4])values);
|
||||
mul_m4_m4m4(local_mat, invmat, (float(*)[4])values);
|
||||
}
|
||||
else {
|
||||
copy_m4_m4(ob->obmat, (float(*)[4])values);
|
||||
copy_m4_m4(local_mat, (float(*)[4])values);
|
||||
}
|
||||
|
||||
/* don't use compat so we get predictable rotation */
|
||||
BKE_object_apply_mat4(ob, ob->obmat, false, false);
|
||||
/* don't use compat so we get predictable rotation, and do not use parenting either, because it's a local matrix! */
|
||||
BKE_object_apply_mat4(ob, local_mat, false, false);
|
||||
}
|
||||
|
||||
static void rna_Object_matrix_basis_get(PointerRNA *ptr, float values[16])
|
||||
|
|
Loading…
Reference in New Issue