I have two sets of rotation data: Global rotation as [x,y,z] degrees AND local rotation as [x,y,z] degrees.
#eg.
globRot = numpy.radians([13,125,45])
locRot = numpy.radians([34,10,258])
How do I apply the rotations to a blender object in python... this is what I've come up with so far looking at other examples such as Rotate object on local axis using a slider
Is this correct?
import bpy
import numpy
from mathutils import Euler
def get_rotation(obj):
print(f"\nCurrent rotation: {obj.rotation_euler.to_matrix().to_euler('ZYX')}")
return obj.rotation_euler.to_matrix().to_euler('ZYX')
def set_global_rotation(obj, value):
obj.rotation_euler = value
print(f"Global rotation was set to: {value}")
return
def set_loc_rotation(obj, value):
rot = Euler(value, 'ZYX')
obj.rotation_euler = (obj.rotation_euler.to_matrix() @ rot.to_matrix()).to_euler(obj.rotation_mode)
print(f"Local rotation added: {value}")
return
globRot = numpy.radians([13,125,45])
locRot = numpy.radians([34,10,258])
obj = bpy.context.object
get_rotation(obj)
set_global_rotation(obj, globRot)
set_loc_rotation(obj, locRot)
print(f"Final rotation is: {obj.rotation_euler}")