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