[#29509] Randomize rotations fails with Axis/Angle
authorDaniel Salazar <zanqdo@gmail.com>
Fri, 9 Dec 2011 06:21:26 +0000 (06:21 +0000)
committerDaniel Salazar <zanqdo@gmail.com>
Fri, 9 Dec 2011 06:21:26 +0000 (06:21 +0000)
Fix based on Brecht's idea: use Blender's conversion from quat or axis angle to euler and back. Euler rotations are left alone so their rotation order is respected

release/scripts/startup/bl_operators/object_randomize_transform.py

index ed881fab5fd044a8151d6e31632e1234d9ccaed8..319fd1526fbcc7745ca48ac4ebbbbe4480e0b880 100644 (file)
@@ -42,8 +42,13 @@ def randomize_selected(seed, delta, loc, rot, scale, scale_even, scale_min):
         else:  # otherwise the values change under us
             uniform(0.0, 0.0), uniform(0.0, 0.0), uniform(0.0, 0.0)
 
-        if rot:  # TODO, non euler's
+        if rot:
             vec = rand_vec(rot)
+            
+            rotation_mode = obj.rotation_mode
+            if rotation_mode in ('QUATERNION', 'AXIS_ANGLE'):
+                obj.rotation_mode = 'XYZ'
+                
             if delta:
                 obj.delta_rotation_euler[0] += vec[0]
                 obj.delta_rotation_euler[1] += vec[1]
@@ -52,6 +57,7 @@ def randomize_selected(seed, delta, loc, rot, scale, scale_even, scale_min):
                 obj.rotation_euler[0] += vec[0]
                 obj.rotation_euler[1] += vec[1]
                 obj.rotation_euler[2] += vec[2]
+            obj.rotation_mode = rotation_mode
         else:
             uniform(0.0, 0.0), uniform(0.0, 0.0), uniform(0.0, 0.0)