diff --git a/__init__.py b/__init__.py index 2b4f93f..f912342 100644 --- a/__init__.py +++ b/__init__.py @@ -1,9 +1,9 @@ bl_info = { "name" : "Batex", - "author" : "jayanam", + "author" : "jayanam, Rodrigo Camacho (forked from jayanam)", "descrtion" : "Batch export as Fbx", "blender" : (2, 80, 0), - "version" : (0, 6, 0, 0), + "version" : (0, 7, 0, 0), "location" : "Batex panel", "warning" : "", "category" : "Import-Export" @@ -16,17 +16,17 @@ from . bex_op import * from . bex_folder_op import * -bpy.types.Scene.export_folder = StringProperty(name="Export folder", - subtype="DIR_PATH", - description="Directory to export the fbx files into") +bpy.types.Scene.export_folder = StringProperty(name="Export folder", + subtype="DIR_PATH", + description="Directory to export the fbx files into") bpy.types.Scene.center_transform = BoolProperty(name="Center transform", - default=True, - description="Set the pivot point of the object to the center") + default=True, + description="Set the pivot point of the object to the center") bpy.types.Scene.apply_transform = BoolProperty(name="Apply transform", - default=True, - description="Applies scale and transform (Experimental)") + default=True, + description="Applies scale and transform (Experimental)") bpy.types.Scene.export_smoothing = EnumProperty( name="Smoothing", @@ -35,21 +35,21 @@ ('EDGE', 'Edge', 'Write edge smoothing',0), ('FACE', 'Face', 'Write face smoothing',1), ('OFF', 'Normals Only', 'Write normals only',2) - ), + ), default='OFF' - ) +) bpy.types.Scene.export_animations = BoolProperty(name="Export Rig & Animations", - default=False, - description="Export rig and animations") + default=False, + description="Export rig and animations") bpy.types.Scene.one_material_ID = BoolProperty(name="One material ID", - default=True, - description="Export just one material per object") + default=True, + description="Export just one material per object") classes = ( BATEX_PT_Panel, BATEX_OT_Operator, BATEX_OT_OpenFolder ) register, unregister = bpy.utils.register_classes_factory(classes) - + if __name__ == "__main__": register() diff --git a/bex_export.py b/bex_export.py index 35e7e8e..072b958 100644 --- a/bex_export.py +++ b/bex_export.py @@ -29,16 +29,15 @@ def do_center(self, obj): return None def remove_materials(self, obj): - if obj.type == 'ARMATURE': + # Check if the object has mesh data and is not an armature + if obj.type != 'MESH' or obj.data is None: return False mat_count = len(obj.data.materials) if mat_count > 1 and self.__one_material_id: - # Save material ids for faces bpy.ops.object.mode_set(mode='EDIT') - bm = bmesh.from_edit_mesh(obj.data) for face in bm.faces: @@ -58,6 +57,7 @@ def remove_materials(self, obj): else: return False + def restore_materials(self, obj): # Restore the materials for the object @@ -86,7 +86,7 @@ def do_export(self): bpy.ops.object.mode_set(mode='OBJECT') for obj in self.__export_objects: - bpy.ops.object.select_all(action='DESELECT') + bpy.ops.object.select_all(action='DESELECT') obj.select_set(state=True) # Center selected object @@ -96,31 +96,34 @@ def do_export(self): for child in get_children(obj): child.select_set(state=True) - # Remove materials except the last one - materials_removed = self.remove_materials(obj) + # Include empty objects in the export + ex_object_types = {'MESH', 'EMPTY'} - ex_object_types = { 'MESH' } - - if(self.__export_animations): + if self.__export_animations: ex_object_types.add('ARMATURE') - # Export the selected object as fbx - bpy.ops.export_scene.fbx(check_existing=False, - filepath=self.__export_folder + "/" + obj.name + ".fbx", - filter_glob="*.fbx", - use_selection=True, - object_types=ex_object_types, - bake_anim=self.__export_animations, - bake_anim_use_all_bones=self.__export_animations, - bake_anim_use_all_actions=self.__export_animations, - use_armature_deform_only=True, - bake_space_transform=self.__apply_transform, - mesh_smooth_type=self.__context.scene.export_smoothing, - add_leaf_bones=False, - path_mode='ABSOLUTE') + # Remove materials except the last one + materials_removed = self.remove_materials(obj) + + # Export the selected object and its children as fbx + bpy.ops.export_scene.fbx( + check_existing=False, + filepath=os.path.join(self.__export_folder, f"{obj.name}.fbx"), + filter_glob="*.fbx", + use_selection=True, + object_types=ex_object_types, + bake_anim=self.__export_animations, + bake_anim_use_all_bones=self.__export_animations, + bake_anim_use_all_actions=self.__export_animations, + use_armature_deform_only=True, + bake_space_transform=self.__apply_transform, + mesh_smooth_type=self.__context.scene.export_smoothing, + add_leaf_bones=False, + path_mode='ABSOLUTE' + ) if materials_removed: self.restore_materials(obj) if old_pos is not None: - set_object_to_loc(obj, old_pos) \ No newline at end of file + set_object_to_loc(obj, old_pos)