Greetings,
I am starting to learn Blender and would like to use Python to help script some of my objects for animation. So far I have reviewed the documentation and even searched the forums but things still are not clicking for me in terms of understanding the Blender 4 x 4 matrix associated with each object. If I execute the following code:
camObj = scn.objects.camera
matrix = camObj.getMatrix()
For a camera at LocX: 0 LocY: -1 LocZ: 1.2 with RotX: 45 RotY: 0 RotZ: 0 ScaleX: 1 ScaleY: 1 ScaleZ: 1 I get a matrix value of:
[1, 0, 0, 0]
[0, 0.707, 0.707, 0]
[0, -0.707, 0.707, 0]
[0, -1, 1.2, 1]
What I don’t grasp is how the camera position, rotation, scale are related to the values in matrix? In other words given the value in the matrix variable how can I get the same location, rotation, and scale that Blender displays? I understand camera position that one is easy. Rotation has me scratching my head. The Blender command “camObj.getMatrix()” has me confused, I looked all over trying to find a reference in the API of what the 4 x 4 matrix actually means, like row 3 is location. If I use the Blender command "camObj.getEuler()” I noticed that I get a vector with RotX, RotY, and RotZ in radians. Does anybody have any online references on how blender uses a 4 x 4 matrix to store location, rotation, and scale? I understand that Blender has many nice functions like getEuler but I would like to understand the meaning of the “WorldSpace” so I can better work with LuxRender’s LuxBlend script. Thanks for the help.
I traced the getEuler method in the Blender source and was able to extract the functions I needed. Attached is the example code and a case study. At this point I don’t understand all the code since I just copied and paste, but the code does produce Euler angles from the lookAt variable in the Lux Scene Files.
[SIZE=2]
pastebin “dot” ca “slash” 2005122
[/SIZE]
Do not learn the old Blender <=2.49
The 2.55 gives this info about the camea and its local_matrix
>> dir(c.matrix_local)
['OrthoProjection', 'Rotation', 'Scale', 'Shear', 'Translation', '__add__', '__class__', '__copy__', '__delattr__',
'__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__',
'__hash__', '__init__', '__invert__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__',
'__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__rsub__', '__setattr__', '__setitem__',
'__sizeof__', '__str__', '__sub__', '__subclasshook__', 'col_size', 'copy', 'decompose', 'determinant',
'identity', 'invert', 'is_negative', 'is_wrapped', 'lerp', 'median_scale', 'owner', 'resize4x4', 'rotation_part',
'row_size', 'scale_part', 'to_3x3', 'to_4x4', 'to_euler', 'to_quat', 'translation_part', 'transpose', 'zero']
Meaning eg for the ‘scale’
>> c.matrix_local.scale_part()
Vector((1.0, 1.0, 0.9999999403953552))
and try the other possibilities!