2010-04-11 14:22:27 +00:00
|
|
|
import mathutils
|
2011-10-17 02:20:53 +00:00
|
|
|
import math
|
2010-04-11 14:22:27 +00:00
|
|
|
|
2025-04-02 23:46:58 +00:00
|
|
|
# Create a new euler with default axis rotation order.
|
2011-10-17 02:20:53 +00:00
|
|
|
eul = mathutils.Euler((0.0, math.radians(45.0), 0.0), 'XYZ')
|
|
|
|
|
|
2025-04-02 23:46:58 +00:00
|
|
|
# Rotate the euler.
|
2014-06-25 03:04:53 +10:00
|
|
|
eul.rotate_axis('Z', math.radians(10.0))
|
2011-10-17 02:20:53 +00:00
|
|
|
|
2025-04-02 23:46:58 +00:00
|
|
|
# You can access its components by attribute or index.
|
2011-10-17 02:20:53 +00:00
|
|
|
print("Euler X", eul.x)
|
|
|
|
|
print("Euler Y", eul[1])
|
|
|
|
|
print("Euler Z", eul[-1])
|
|
|
|
|
|
2025-04-02 23:46:58 +00:00
|
|
|
# Components of an existing euler can be set.
|
2011-10-17 02:20:53 +00:00
|
|
|
eul[:] = 1.0, 2.0, 3.0
|
|
|
|
|
|
2025-04-02 23:46:58 +00:00
|
|
|
# Components of an existing euler can use slice notation to get a tuple.
|
2024-04-12 15:33:40 +10:00
|
|
|
print("Values: {:f}, {:f}, {:f}".format(*eul))
|
2011-10-17 02:20:53 +00:00
|
|
|
|
2025-04-02 23:46:58 +00:00
|
|
|
# The order can be set at any time too.
|
2011-10-17 02:20:53 +00:00
|
|
|
eul.order = 'ZYX'
|
|
|
|
|
|
2025-04-02 23:46:58 +00:00
|
|
|
# Eulers can be used to rotate vectors.
|
2011-10-17 02:20:53 +00:00
|
|
|
vec = mathutils.Vector((0.0, 0.0, 1.0))
|
|
|
|
|
vec.rotate(eul)
|
|
|
|
|
|
2025-04-02 23:46:58 +00:00
|
|
|
# Often its useful to convert the euler into a matrix so it can be used as
|
|
|
|
|
# transformations with more flexibility.
|
2011-10-17 02:20:53 +00:00
|
|
|
mat_rot = eul.to_matrix()
|
|
|
|
|
mat_loc = mathutils.Matrix.Translation((2.0, 3.0, 4.0))
|
2019-06-06 17:12:49 +02:00
|
|
|
mat = mat_loc @ mat_rot.to_4x4()
|
2025-08-16 17:38:20 +10:00
|
|
|
|
|
|
|
|
# Direct buffer access is supported.
|
|
|
|
|
print(memoryview(eul).tobytes())
|