Export_3ds: Improved distance cue node search
[blender-addons.git] / io_anim_nuke_chan / export_nuke_chan.py
blob1bb911d4da573ad54d1e31408342aa3fae8e0237
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
16 scene = context.scene
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')
29 fw = filehandle.write
31 # iterate the frames
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
42 if y_up:
43 mat = rot_mat @ mat
45 # create the first component of a new line, the frame number
46 fw("%i\t" % frame)
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
58 previous_rotation = r
60 # if the selected object is a camera export vertical fov also
61 if camera:
62 vfov = degrees(camera.angle_y)
63 fw("%f" % vfov)
65 fw("\n")
67 # after the whole loop close the file
68 filehandle.close()
70 return {'FINISHED'}