5
$\begingroup$

When you create a hierarchy with nesting like so:

enter image description here

Does Circle inherit the properties from the parent matrix? Or is first the matrix of Cirlce.001 applied followed by the matrix of Circle?

You can't tell by the values in the editor since it could subtract with the parent values. So hopefully a programmer can answer me this.

$\endgroup$

1 Answer 1

13
$\begingroup$

Basics of Local and Global Coordinate systems

Each object in blender has a number of matrices. Its global transform matrix ob.matrix_world its local space matrix ob.matrix_local. The basis matrix ob.matrix_basis, this is what you see in the "editor" enter image description here

and its parenting matrix ob.matrix_parent_inverse (This is set when choosing parenting Keep Offset for example)

Relation between basis and local

ob.matrix_local = ob.matrix_parent_inverse @ ob.matrix_basis

As an example, select an object and calculate its global matrix by going up the hierarchy chain.

import bpy
from mathutils import Matrix

context = bpy.context
ob = context.object
M = Matrix()
print(ob.matrix_world)
while ob.parent:
    M = (ob.matrix_parent_inverse @ ob.matrix_basis) @ M
    ob = ob.parent

M = ob.matrix_basis @ M

print(M)

similarly

import bpy
from mathutils import Matrix

context = bpy.context
ob = context.object
M = Matrix()
print(ob.matrix_world)
while ob.parent:
    M = ob.matrix_local @ M
    ob = ob.parent

M = ob.matrix_local @ M

print(M)

Result on test case, Cube is parent of Cube.001 is parent of Cube.002 some random transforms applied to each.

enter image description here

<Matrix 4x4 ( 0.3256, -0.9107,  0.8122, -3.8782)
            (-0.6125, -0.9379, -0.8588, -6.2457)
            ( 1.5886,  0.1065, -0.9282,  4.2578)
            ( 0.0000,  0.0000,  0.0000,  1.0000)>
<Matrix 4x4 ( 0.3256, -0.9107,  0.8122, -3.8782)
            (-0.6125, -0.9379, -0.8588, -6.2457)
            ( 1.5886,  0.1065, -0.9282,  4.2578)
            ( 0.0000,  0.0000,  0.0000,  1.0000)>
$\endgroup$
1
  • 3
    $\begingroup$ Awesome explanation! $\endgroup$
    – brockmann
    Commented Mar 11, 2020 at 19:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .