1

I've been hammering away on my keyboard for the last few hours to get something seemingly simple done. What I want to do is further rotate an object's world matrix. So I'm grabbing the world matrix like:

x = bpy.context.object.matrix_world

Now I'd like to rotate that by an Euler angle

eAngle = Euler((0.0, 0.2, 0.0)) # rotate 0.2 radians on the Y axis

What I've tried is:

bpy.context.object.matrix_world.rotate(eAngle)  # yields a ValueError, 'must have 3x3 dimensions', even though the function description states I could use an Euler as input
bpy.context.object.matrix_world.to_3x3().rotate(eAngle)  # does nothing
x = bpy.context.object.matrix_world.to_3x3().rotate(eAngle)  # x is none, so I also cannot set that resulting value somewhere else
hammering_hard_on_the_keyboard  # feels nice, but only yields keys on the table and floor

Can someone please give me a hint on how to achieve such a rotation?

aliasguru
  • 11,231
  • 2
  • 35
  • 72
  • if that helps, you can obj.rotation_euler.rotate( eAngle ) or obj.rotation_quaternion.rotate( eAngle ), which impacts the world_matrix. For more complete info, see https://blender.stackexchange.com/questions/44760/rotate-objects-around-their-origin-along-a-global-axis-scripted-without-bpy-op – lemon Apr 23 '18 at 12:49
  • @lemon Trouble is, in my situation I'd really like to influence the world matrix, as a) the objects might be in an arbitrary parent-child relationship, and b) they already might have rotations on the channels. The effect I'm trying to achieve is a rotation around the world origin, no matter what transforms the objects already have. – aliasguru Apr 23 '18 at 12:58
  • yes, look at the answer from Jerryno above, you can obj.matrix_world = my_transform_matrix * obj.matrix_world where my_transform_matrix can be whatever you need – lemon Apr 23 '18 at 13:02
  • 1
    @lemon That linked answer works for me. I can get my angle using x = Euler((x,y,z)).to_matrix().to_4x4() and use obj.matrix_world = x * obj.matrix_world. – aliasguru Apr 24 '18 at 14:01

0 Answers0