Here is an answer. But the answer uses euler angles instead of setting the i,j,k base coordinates in the cam's model matrix. I'd like to set the camera's orientation by its i,j,k coordinates (these are the coordinates in the model matrix which sets the object's orientation and scaling). What is the Blender python API for doing it?
Asked
Active
Viewed 3,311 times
1 Answers
2
Blender's mathutils module is used to work with matrices. To transform any object using a matrix you set the objects matrix_world
property.
import bpy
import mathutils
import math
mat_loc = mathutils.Matrix.Translation((2.0, 3.0, 4.0))
mat_sca = mathutils.Matrix.Scale(0.5, 4, (0.0, 0.0, 1.0))
mat_rot = mathutils.Matrix.Rotation(math.radians(45.0), 4, 'X')
mat_comb = mat_loc * mat_rot * mat_sca
cam = bpy.data.objects['Camera']
cam.matrix_world = mat_comb

sambler
- 6,917
- 1
- 16
- 23
-
1In Blender 2.8+ this does not work anymore. To fix this simply replace * with @ Source: https://blender.stackexchange.com/questions/129473/typeerror-element-wise-multiplication-not-supported-between-matrix-and-vect#129474 – pix_1 Feb 15 '21 at 09:43