I’m a programmer but completely new to python/blender.
I have a rotation matrix from another program and cannot work out how to set the rotation matrix of the Camera to my matrix, can anyone help?
I have a very basic start
import bpy
import mathutils
newMat = mathutils.Matrix([[x, y, z],[x, y, z],[x, y, z]])
for obj in bpy.context.selected_objects:
obj.matrix_world = newMat
I want to select my Camera then set its rotation, I know the last line is for scale rot and pos, is it even possible to just do rotation?
Is it not possible to use: matrixEuler= newMat.toEuler() and then set the rotation with that? I am told no such method exists though
edit: Oh it’s to_euler()
So all I would need is a way to set an objects rotation to euler, but I cannot find one
edit 2:
I think I have achieved it with
import bpy
import mathutils
import math
newMat = mathutils.Matrix([[1, 0, 0],[0, 1, 0],[0, 0, 1]])
matrixEuler= newMat.to_euler()
scene = bpy.data.scenes[“Scene”]
scene.camera.rotation_mode = ‘XYZ’
scene.camera.rotation_euler[0] = matrixEuler[0](math.pi/180.0)
scene.camera.rotation_euler[1] = matrixEuler[1] (math.pi/180.0)
scene.camera.rotation_euler[2] = matrixEuler[2]*(math.pi/180.0)
If anyone would confirm this is doing what I want that would be awesome though
CoDEmanX
(CoDEmanX)
May 26, 2015, 2:25am
3
You can set .matrix_world of objects directly, but if you got a 3x3 rotation matrix only, you might need some matrix math to make it the 4x4 transformation matrix you want.