0

I need to rotate the matrix_world of an object through a quaternion q without changing its actual rotation (i.e. rotation in world space). How to do that through a script?

Edit: Let's say if I rotate the matrix_world by the angle specified by quaternion, then naturally the object will also get rotated in the world space. But I want to undo this object rotation and keep matrix_world rotation. Doing this with translation is straightforward. I would just move all the vertices be the negative Vector and shift the location of the object by positive Vector. So I get translated matrix_world but the object remains at the same place in world space. How do I achieve this with rotation?

Loma Harshana
  • 597
  • 2
  • 9
  • I fail to follow. You want to rotate an object without rotating it? Could you clarify? Do you mean you need to change rotation of your object's origin/local space without changing it's mesh in world space? – Martynas Žiemys Sep 05 '22 at 11:58
  • https://blender.stackexchange.com/a/42110/60759 - might be useful. – Martynas Žiemys Sep 05 '22 at 12:17
  • @MartynasŽiemys Thanks for the link. It discusses only translation of origin. I am talking about rotating the matrix_world. Please see the edit. – Loma Harshana Sep 05 '22 at 14:11

1 Answers1

1

Here's what worked for me (supposing you want to align matrix_world of object obj with quaternion q without changing object rotation in world space):

mw = obj.matrix_world
transMat = q.to_matrix().to_4x4()

for v in plane.data.vertices: v.co = transMat.inverted() @ mw @ v.co obj.matrix_world = transMat

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
Loma Harshana
  • 597
  • 2
  • 9