1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
21 """ This script is an exporter to the nuke's .chan files.
22 It takes the currently active object and writes it's transformation data
23 into a text file with .chan extension."""
25 from mathutils
import Matrix
26 from math
import radians
, degrees
29 def save_chan(context
, filepath
, y_up
, rot_ord
):
31 # get the active scene and object
33 obj
= context
.active_object
34 camera
= obj
.data
if obj
.type == 'CAMERA' else None
36 # get the range of an animation
37 f_start
= scene
.frame_start
38 f_end
= scene
.frame_end
40 # prepare the correcting matrix
41 rot_mat
= Matrix
.Rotation(radians(-90.0), 4, 'X').to_4x4()
43 filehandle
= open(filepath
, 'w')
47 for frame
in range(f_start
, f_end
+ 1, 1):
49 # set the current frame
50 scene
.frame_set(frame
)
52 # get the objects world matrix
53 mat
= obj
.matrix_world
.copy()
55 # if the setting is proper use the rotation matrix
56 # to flip the Z and Y axis
60 # create the first component of a new line, the frame number
63 # create transform component
64 t
= mat
.to_translation()
65 fw("%f\t%f\t%f\t" % t
[:])
67 # create rotation component
68 r
= mat
.to_euler(rot_ord
)
70 fw("%f\t%f\t%f\t" % (degrees(r
[0]), degrees(r
[1]), degrees(r
[2])))
72 # if the selected object is a camera export vertical fov also
74 vfov
= degrees(camera
.angle_y
)
79 # after the whole loop close the file