1
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ 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 blender.stackexchange.com/questions/44760/… $\endgroup$
    – lemon
    Commented Apr 23, 2018 at 12:49
  • $\begingroup$ @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. $\endgroup$
    – aliasguru
    Commented Apr 23, 2018 at 12:58
  • $\begingroup$ 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 $\endgroup$
    – lemon
    Commented Apr 23, 2018 at 13:02
  • 1
    $\begingroup$ @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. $\endgroup$
    – aliasguru
    Commented Apr 24, 2018 at 14:01

0

You must log in to answer this question.

Browse other questions tagged .