Blender:如何从 python 脚本移动相机

Blender: how to move the camera from python script

这是一个answer。但是答案使用欧拉角而不是在凸轮的模型矩阵中设置 i,j,k 基坐标。 我想通过它的 i、j、k 坐标设置相机的方向(这些是模型矩阵中设置对象方向和缩放比例的坐标)。 Blender python API 是做什么用的?

Blender 的 mathutils module is used to work with matrices. To transform any object using a matrix you set the objects matrix_world 属性.

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