利用者:Pepribal/Ref/Appendices/ParentInverse
The parent inverse matrix
At the very moment of establishing a hierarchical relationship between objects (parenting), the transformation coordinates of the child object remain unchanged, and yet this object doesn't change its global transforms visually (location, orientation or scale), though its reference "world" has changed from global origin (zero transforms) to the global transforms of the parent.
Origin of unparented objects is the global origin: global (0,0,0) location, zero rotation, and unity scale. After being parented, the new origin should be that of the parent. And it is. But a correction matrix is applied to the child, so that the new reference point is not the global transforms of the parent, but the global origin. This correction matrix is applied to the global transforms of the parent before applying them to the child.
That correction matrix is the parent inverse matrix, and it corrects the transform coordinates of the parent (position, rotation and scale), to take the reference point of the child back to the global origin. Further transform modifications of the parent will not change the parent inverse of that child any more, so from the moment of parenting on, this correcting matrix will remain constant (unless changed specifically). So after parenting, children will keep following further parent transformations. Keep in mind that the correcting matrix is applied and belongs to the child objects, though its value depends on the values that the parent transforms had at the very moment of parenting.
The exact value of the Parent Inverse matrix of a child object is the inverse of the global transformation matrix of the parent at the very moment of parenting, and it remains unchanged unless we specifically change it.
If we clear that correcting matrix on a child object, the origin of that child objects will effectively be the parent's global location, rotation and scale. Bear in mind that at the same time the parent might have its own parent, and so, it might also have a correcting matrix.
Python object transformation properties
Objects store their transformation coordinates in a 4x4 matrix. To access that matrix, you can use the property matrix_basis. Basicly it stores the information you find in the Transform panel in the Properties sidebar of the 3D View editor. You can also access the transformation properties for location (location), rotation (rotation_axis_angle, rotation_euler or rotation_quaternion, depending on the value of rotation_mode) or scale (scale).
The objects also have a property that stores the parent inverse correcting matrix. That property is matrix_parent_inverse. If the object has no parent or it has its parent inverse cleared, this matrix equals the unit matrix, so that multiplying any transformation matrix by this unit matrix will return the first one unchanged.
In addition, there is another object property, matrix_local that stores the result of multiplying matrix_basis by matrix_parent_inverse. If the object has a cleared parent inverse, then matrix_local equals matrix_basis. This property shows the object transformation coordinates from the global coordinates of its parent (or from the global origin if it has no parent).
Finally, there is matrix_world, that reflects the global transformation of the object, using the matrix_world of the parent for its calculation (if there is one).
In summary:
- matrix_basis = object transform coordinates
- matrix_parent_inverse = object correcting matrix
- matrix_local = matrix_parent_inverse x matrix_basis
- matrix_world = parent's matrix_world (or global origin) x matrix_local