1 # SPDX-License-Identifier: GPL-2.0-or-later
3 """ This script is an exporter to the nuke's .chan files.
4 It takes the currently active object and writes it's transformation data
5 into a text file with .chan extension."""
7 from mathutils
import Matrix
, Euler
8 from math
import radians
, degrees
11 def save_chan(context
, filepath
, y_up
, rot_ord
):
13 # get the active scene and object
15 obj
= context
.active_object
16 camera
= obj
.data
if obj
.type == 'CAMERA' else None
18 # get the range of an animation
19 f_start
= scene
.frame_start
20 f_end
= scene
.frame_end
22 # prepare the correcting matrix
23 rot_mat
= Matrix
.Rotation(radians(-90.0), 4, 'X').to_4x4()
24 previous_rotation
= Euler()
26 filehandle
= open(filepath
, 'w')
30 for frame
in range(f_start
, f_end
+ 1, 1):
32 # set the current frame
33 scene
.frame_set(frame
)
35 # get the objects world matrix
36 mat
= obj
.matrix_world
.copy()
38 # if the setting is proper use the rotation matrix
39 # to flip the Z and Y axis
43 # create the first component of a new line, the frame number
46 # create transform component
47 t
= mat
.to_translation()
48 fw("%f\t%f\t%f\t" % t
[:])
50 # create rotation component
51 r
= mat
.to_euler(rot_ord
, previous_rotation
)
53 fw("%f\t%f\t%f\t" % (degrees(r
[0]), degrees(r
[1]), degrees(r
[2])))
55 # store previous rotation for compatibility
58 # if the selected object is a camera export vertical fov also
60 vfov
= degrees(camera
.angle_y
)
65 # after the whole loop close the file