Import images: add file handler
[blender-addons.git] / io_anim_nuke_chan / __init__.py
blob176f9b37039906b907b76917455586ec795204a1
1 # SPDX-FileCopyrightText: 2011-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 bl_info = {
6 "name": "Nuke Animation Format (.chan)",
7 "author": "Michael Krupa",
8 "version": (1, 0),
9 "blender": (2, 80, 0),
10 "location": "File > Import/Export > Nuke (.chan)",
11 "description": "Import/Export object's animation with nuke",
12 "warning": "",
13 "doc_url": "{BLENDER_MANUAL_URL}/addons/import_export/anim_nuke_chan.html",
14 "category": "Import-Export",
18 # To support reload properly, try to access a package var,
19 # if it's there, reload everything
20 if "bpy" in locals():
21 import importlib
22 if "import_nuke_chan" in locals():
23 importlib.reload(import_nuke_chan)
24 if "export_nuke_chan" in locals():
25 importlib.reload(export_nuke_chan)
28 import bpy
29 from bpy.types import Operator
30 from bpy_extras.io_utils import ImportHelper, ExportHelper
31 from bpy.props import (
32 StringProperty,
33 BoolProperty,
34 EnumProperty,
35 FloatProperty,
38 # property shared by both operators
39 rotation_order = EnumProperty(
40 name="Rotation order",
41 description="Choose the export rotation order",
42 items=(('XYZ', "XYZ", "XYZ"),
43 ('XZY', "XZY", "XZY"),
44 ('YXZ', "YXZ", "YXZ"),
45 ('YZX', "YZX", "YZX"),
46 ('ZXY', "ZXY", "ZXY"),
47 ('ZYX', "ZYX", "ZYX"),
49 default='XYZ')
52 class ImportChan(Operator, ImportHelper):
53 """Import animation from .chan file, exported from nuke or houdini """ \
54 """(the importer uses frame numbers from the file)"""
55 bl_idname = "import_scene.import_chan"
56 bl_label = "Import chan file"
58 filename_ext = ".chan"
60 filter_glob: StringProperty(default="*.chan", options={'HIDDEN'})
62 rotation_order: rotation_order
63 z_up: BoolProperty(
64 name="Make Z up",
65 description="Switch the Y and Z axis",
66 default=True)
68 sensor_width: FloatProperty(
69 name="Camera sensor width",
70 description="Imported camera sensor width",
71 default=32.0)
73 sensor_height: FloatProperty(
74 name="Camera sensor height",
75 description="Imported camera sensor height",
76 default=18.0)
78 @classmethod
79 def poll(cls, context):
80 return context.active_object is not None
82 def execute(self, context):
83 from . import import_nuke_chan
84 return import_nuke_chan.read_chan(context,
85 self.filepath,
86 self.z_up,
87 self.rotation_order,
88 self.sensor_width,
89 self.sensor_height)
92 class ExportChan(Operator, ExportHelper):
93 """Export the animation to .chan file, readable by nuke and houdini """ \
94 """(the exporter uses frames from the frames range)"""
95 bl_idname = "export.export_chan"
96 bl_label = "Export chan file"
98 filename_ext = ".chan"
99 filter_glob: StringProperty(default="*.chan", options={'HIDDEN'})
100 y_up: BoolProperty(
101 name="Make Y up",
102 description="Switch the Y and Z axis",
103 default=True)
104 rotation_order: rotation_order
106 @classmethod
107 def poll(cls, context):
108 return context.active_object is not None
110 def execute(self, context):
111 from . import export_nuke_chan
112 return export_nuke_chan.save_chan(context,
113 self.filepath,
114 self.y_up,
115 self.rotation_order)
118 def menu_func_import(self, context):
119 self.layout.operator(ImportChan.bl_idname, text="Nuke (.chan)")
122 def menu_func_export(self, context):
123 self.layout.operator(ExportChan.bl_idname, text="Nuke (.chan)")
126 def register():
127 bpy.utils.register_class(ImportChan)
128 bpy.utils.register_class(ExportChan)
129 bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
130 bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
133 def unregister():
134 bpy.utils.unregister_class(ImportChan)
135 bpy.utils.unregister_class(ExportChan)
136 bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
137 bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
140 if __name__ == "__main__":
141 register()