Merge branch 'blender-v2.92-release'
[blender-addons.git] / io_anim_nuke_chan / __init__.py
blob3fca3f0768435293e7e1b9f94acddb6495a84ec7
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 #####
19 # <pep8-80 compliant>
21 bl_info = {
22 "name": "Nuke Animation Format (.chan)",
23 "author": "Michael Krupa",
24 "version": (1, 0),
25 "blender": (2, 80, 0),
26 "location": "File > Import/Export > Nuke (.chan)",
27 "description": "Import/Export object's animation with nuke",
28 "warning": "",
29 "doc_url": "{BLENDER_MANUAL_URL}/addons/import_export/anim_nuke_chan.html",
30 "category": "Import-Export",
34 # To support reload properly, try to access a package var,
35 # if it's there, reload everything
36 if "bpy" in locals():
37 import importlib
38 if "import_nuke_chan" in locals():
39 importlib.reload(import_nuke_chan)
40 if "export_nuke_chan" in locals():
41 importlib.reload(export_nuke_chan)
44 import bpy
45 from bpy.types import Operator
46 from bpy_extras.io_utils import ImportHelper, ExportHelper
47 from bpy.props import (
48 StringProperty,
49 BoolProperty,
50 EnumProperty,
51 FloatProperty,
54 # property shared by both operators
55 rotation_order = EnumProperty(
56 name="Rotation order",
57 description="Choose the export rotation order",
58 items=(('XYZ', "XYZ", "XYZ"),
59 ('XZY', "XZY", "XZY"),
60 ('YXZ', "YXZ", "YXZ"),
61 ('YZX', "YZX", "YZX"),
62 ('ZXY', "ZXY", "ZXY"),
63 ('ZYX', "ZYX", "ZYX"),
65 default='XYZ')
68 class ImportChan(Operator, ImportHelper):
69 """Import animation from .chan file, exported from nuke or houdini """ \
70 """(the importer uses frame numbers from the file)"""
71 bl_idname = "import_scene.import_chan"
72 bl_label = "Import chan file"
74 filename_ext = ".chan"
76 filter_glob: StringProperty(default="*.chan", options={'HIDDEN'})
78 rotation_order: rotation_order
79 z_up: BoolProperty(
80 name="Make Z up",
81 description="Switch the Y and Z axis",
82 default=True)
84 sensor_width: FloatProperty(
85 name="Camera sensor width",
86 description="Imported camera sensor width",
87 default=32.0)
89 sensor_height: FloatProperty(
90 name="Camera sensor height",
91 description="Imported camera sensor height",
92 default=18.0)
94 @classmethod
95 def poll(cls, context):
96 return context.active_object is not None
98 def execute(self, context):
99 from . import import_nuke_chan
100 return import_nuke_chan.read_chan(context,
101 self.filepath,
102 self.z_up,
103 self.rotation_order,
104 self.sensor_width,
105 self.sensor_height)
108 class ExportChan(Operator, ExportHelper):
109 """Export the animation to .chan file, readable by nuke and houdini """ \
110 """(the exporter uses frames from the frames range)"""
111 bl_idname = "export.export_chan"
112 bl_label = "Export chan file"
114 filename_ext = ".chan"
115 filter_glob: StringProperty(default="*.chan", options={'HIDDEN'})
116 y_up: BoolProperty(
117 name="Make Y up",
118 description="Switch the Y and Z axis",
119 default=True)
120 rotation_order: rotation_order
122 @classmethod
123 def poll(cls, context):
124 return context.active_object is not None
126 def execute(self, context):
127 from . import export_nuke_chan
128 return export_nuke_chan.save_chan(context,
129 self.filepath,
130 self.y_up,
131 self.rotation_order)
134 def menu_func_import(self, context):
135 self.layout.operator(ImportChan.bl_idname, text="Nuke (.chan)")
138 def menu_func_export(self, context):
139 self.layout.operator(ExportChan.bl_idname, text="Nuke (.chan)")
142 def register():
143 bpy.utils.register_class(ImportChan)
144 bpy.utils.register_class(ExportChan)
145 bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
146 bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
149 def unregister():
150 bpy.utils.unregister_class(ImportChan)
151 bpy.utils.unregister_class(ExportChan)
152 bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
153 bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
156 if __name__ == "__main__":
157 register()