How to change matrix_world, matrix_basis....

Hi all,

I have computed four matrices w,p,l,b and I want to do

myObject.matrix_world=w
myObject.matrix_parent_inverse=p
myObject.matrix_local=l
myObject.matrix_basis=b

Problem : Blender updates some matrices when I change one of them (always these side effects of the API…)
and the four matrices of the object end up being matrices different from w,p,l,b.

So my question: how to assign exactly the matrices, without blender coming into the play ?

I’m pretty sure they are inter-related, that’s why they keep changing

Yes, the matrices are inter-related, we have the relations l=bp, and w=wwl where ww is the world matrix of the parent (=1 if no parent).

Now I have four abstract matrices with these relations : how to assign these matrices to the matrices of my object ?

If you don’t want the matrix update (use .copy()):
w = myObject.matrix_world.copy()

You can then reapply the matrix this way:
myObject.matrix_world = w

just assign the ones that are necessary to trigger the calculations for the others - shouldn’t they all match up in the end?

There is something unclear here. There are four matrices. When two matrices are chosen, the two remaining ones are determined by the chosen matrices (except when the chosen matrices are world and local, let me skip the math details here).

When I change just one matrix, blender stars to compute things. This is unnatural, because we don’t know which pair has to be kept at this point. It seems that it keeps the changed matrix (this is OK) and I was not able to figure out the algorithm for the three remaining ones.

This arbitrary undocumented choices of Blender makes the situation difficult to control. Suppose I have two changes, let’s call them change1 and change2. Suppose that each change assigns one matrix among the four. After change1, blender does some work, And after change2, blender does again some work. Sometimes after change2, Blender changes the matrix that I have carefully chosen with change1.

Even when I try to assign only one matrix, nameley the matrix matrix_world i have problems : the childs are not updated after the execution of sce.update(). And If I start with a non updated situation, the situation is worse. The matrices are changed by Blender following an ordre which appears completly random to me. I cannot even guarantee that Blender keeps the matrix that I assigned if I do just one change.

Maybe a better solution would be to convert these matrices to a euler or quaternion representation, and thus save yourself from all that trouble about the matrices?

Yes, Bayesian, I am more or less convinced that there is no solution with matrices. What do you suggest if I know the quaternions/translation for the operation. Using bpy.ops ? Is it the best solution ?