Revert "Fix for exporting animation on armature bones that have keys for a rotation_m...
[blender-addons.git] / io_scene_obj / __init__.py
blob1d778e311a709aae91f59b4ed6ffb2d3d60482b6
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": "Wavefront OBJ format",
23 "author": "Campbell Barton, Bastien Montagne",
24 "version": (2, 1, 0),
25 "blender": (2, 74, 0),
26 "location": "File > Import-Export",
27 "description": "Import-Export OBJ, Import OBJ mesh, UV's, "
28 "materials and textures",
29 "warning": "",
30 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
31 "Scripts/Import-Export/Wavefront_OBJ",
32 "support": 'OFFICIAL',
33 "category": "Import-Export"}
35 if "bpy" in locals():
36 import importlib
37 if "import_obj" in locals():
38 importlib.reload(import_obj)
39 if "export_obj" in locals():
40 importlib.reload(export_obj)
43 import bpy
44 from bpy.props import (
45 BoolProperty,
46 FloatProperty,
47 StringProperty,
48 EnumProperty,
50 from bpy_extras.io_utils import (
51 ImportHelper,
52 ExportHelper,
53 orientation_helper_factory,
54 path_reference_mode,
55 axis_conversion,
59 IOOBJOrientationHelper = orientation_helper_factory("IOOBJOrientationHelper", axis_forward='-Z', axis_up='Y')
62 class ImportOBJ(bpy.types.Operator, ImportHelper, IOOBJOrientationHelper):
63 """Load a Wavefront OBJ File"""
64 bl_idname = "import_scene.obj"
65 bl_label = "Import OBJ"
66 bl_options = {'PRESET', 'UNDO'}
68 filename_ext = ".obj"
69 filter_glob = StringProperty(
70 default="*.obj;*.mtl",
71 options={'HIDDEN'},
74 use_edges = BoolProperty(
75 name="Lines",
76 description="Import lines and faces with 2 verts as edge",
77 default=True,
79 use_smooth_groups = BoolProperty(
80 name="Smooth Groups",
81 description="Surround smooth groups by sharp edges",
82 default=True,
85 use_split_objects = BoolProperty(
86 name="Object",
87 description="Import OBJ Objects into Blender Objects",
88 default=True,
90 use_split_groups = BoolProperty(
91 name="Group",
92 description="Import OBJ Groups into Blender Objects",
93 default=True,
96 use_groups_as_vgroups = BoolProperty(
97 name="Poly Groups",
98 description="Import OBJ groups as vertex groups",
99 default=False,
102 use_image_search = BoolProperty(
103 name="Image Search",
104 description="Search subdirs for any associated images "
105 "(Warning, may be slow)",
106 default=True,
109 split_mode = EnumProperty(
110 name="Split",
111 items=(('ON', "Split", "Split geometry, omits unused verts"),
112 ('OFF', "Keep Vert Order", "Keep vertex order from file"),
116 global_clamp_size = FloatProperty(
117 name="Clamp Size",
118 description="Clamp bounds under this value (zero to disable)",
119 min=0.0, max=1000.0,
120 soft_min=0.0, soft_max=1000.0,
121 default=0.0,
124 def execute(self, context):
125 # print("Selected: " + context.active_object.name)
126 from . import import_obj
128 if self.split_mode == 'OFF':
129 self.use_split_objects = False
130 self.use_split_groups = False
131 else:
132 self.use_groups_as_vgroups = False
134 keywords = self.as_keywords(ignore=("axis_forward",
135 "axis_up",
136 "filter_glob",
137 "split_mode",
140 global_matrix = axis_conversion(from_forward=self.axis_forward,
141 from_up=self.axis_up,
142 ).to_4x4()
143 keywords["global_matrix"] = global_matrix
145 if bpy.data.is_saved and context.user_preferences.filepaths.use_relative_paths:
146 import os
147 keywords["relpath"] = os.path.dirname((bpy.data.path_resolve("filepath", False).as_bytes()))
149 return import_obj.load(self, context, **keywords)
151 def draw(self, context):
152 layout = self.layout
154 row = layout.row(align=True)
155 row.prop(self, "use_smooth_groups")
156 row.prop(self, "use_edges")
158 box = layout.box()
159 row = box.row()
160 row.prop(self, "split_mode", expand=True)
162 row = box.row()
163 if self.split_mode == 'ON':
164 row.label(text="Split by:")
165 row.prop(self, "use_split_objects")
166 row.prop(self, "use_split_groups")
167 else:
168 row.prop(self, "use_groups_as_vgroups")
170 row = layout.split(percentage=0.67)
171 row.prop(self, "global_clamp_size")
172 layout.prop(self, "axis_forward")
173 layout.prop(self, "axis_up")
175 layout.prop(self, "use_image_search")
178 class ExportOBJ(bpy.types.Operator, ExportHelper, IOOBJOrientationHelper):
179 """Save a Wavefront OBJ File"""
181 bl_idname = "export_scene.obj"
182 bl_label = 'Export OBJ'
183 bl_options = {'PRESET'}
185 filename_ext = ".obj"
186 filter_glob = StringProperty(
187 default="*.obj;*.mtl",
188 options={'HIDDEN'},
191 # context group
192 use_selection = BoolProperty(
193 name="Selection Only",
194 description="Export selected objects only",
195 default=False,
197 use_animation = BoolProperty(
198 name="Animation",
199 description="Write out an OBJ for each frame",
200 default=False,
203 # object group
204 use_mesh_modifiers = BoolProperty(
205 name="Apply Modifiers",
206 description="Apply modifiers (preview resolution)",
207 default=True,
210 # extra data group
211 use_edges = BoolProperty(
212 name="Include Edges",
213 description="",
214 default=True,
216 use_smooth_groups = BoolProperty(
217 name="Smooth Groups",
218 description="Write sharp edges as smooth groups",
219 default=False,
221 use_smooth_groups_bitflags = BoolProperty(
222 name="Bitflag Smooth Groups",
223 description="Same as 'Smooth Groups', but generate smooth groups IDs as bitflags "
224 "(produces at most 32 different smooth groups, usually much less)",
225 default=False,
227 use_normals = BoolProperty(
228 name="Write Normals",
229 description="Export one normal per vertex and per face, to represent flat faces and sharp edges",
230 default=True,
232 use_uvs = BoolProperty(
233 name="Include UVs",
234 description="Write out the active UV coordinates",
235 default=True,
237 use_materials = BoolProperty(
238 name="Write Materials",
239 description="Write out the MTL file",
240 default=True,
242 use_triangles = BoolProperty(
243 name="Triangulate Faces",
244 description="Convert all faces to triangles",
245 default=False,
247 use_nurbs = BoolProperty(
248 name="Write Nurbs",
249 description="Write nurbs curves as OBJ nurbs rather than "
250 "converting to geometry",
251 default=False,
253 use_vertex_groups = BoolProperty(
254 name="Polygroups",
255 description="",
256 default=False,
259 # grouping group
260 use_blen_objects = BoolProperty(
261 name="Objects as OBJ Objects",
262 description="",
263 default=True,
265 group_by_object = BoolProperty(
266 name="Objects as OBJ Groups ",
267 description="",
268 default=False,
270 group_by_material = BoolProperty(
271 name="Material Groups",
272 description="",
273 default=False,
275 keep_vertex_order = BoolProperty(
276 name="Keep Vertex Order",
277 description="",
278 default=False,
281 global_scale = FloatProperty(
282 name="Scale",
283 min=0.01, max=1000.0,
284 default=1.0,
287 path_mode = path_reference_mode
289 check_extension = True
291 def execute(self, context):
292 from . import export_obj
294 from mathutils import Matrix
295 keywords = self.as_keywords(ignore=("axis_forward",
296 "axis_up",
297 "global_scale",
298 "check_existing",
299 "filter_glob",
302 global_matrix = (Matrix.Scale(self.global_scale, 4) *
303 axis_conversion(to_forward=self.axis_forward,
304 to_up=self.axis_up,
305 ).to_4x4())
307 keywords["global_matrix"] = global_matrix
308 return export_obj.save(self, context, **keywords)
311 def menu_func_import(self, context):
312 self.layout.operator(ImportOBJ.bl_idname, text="Wavefront (.obj)")
315 def menu_func_export(self, context):
316 self.layout.operator(ExportOBJ.bl_idname, text="Wavefront (.obj)")
319 def register():
320 bpy.utils.register_module(__name__)
322 bpy.types.INFO_MT_file_import.append(menu_func_import)
323 bpy.types.INFO_MT_file_export.append(menu_func_export)
326 def unregister():
327 bpy.utils.unregister_module(__name__)
329 bpy.types.INFO_MT_file_import.remove(menu_func_import)
330 bpy.types.INFO_MT_file_export.remove(menu_func_export)
332 if __name__ == "__main__":
333 register()