Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 46 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
# Batex
Export selected objects as fbx in batch operation.

### Features
* One fbx file per selected object
* Set the pivot point to center before exporting (useful e.g. for Unreal Engine 4 imports)
* Set the smoothing type before exporting (e.g. for low poly objects set it to FACE)
* Define export folder, which is stored to .blend-file
* Open export folder with one click
* Export armature and animations

### Installing
1. Download zip file: https://github.com/jayanam/batex/archive/master.zip
2. Open Blender
3. Go to edit -> preferences -> addons
4. Click install button
5. Select the zip file you downloaded
6. Check the box next to "inport-Export: Batex" to enable plugin

### Using
* After installing Batex panel is added to the sidebar (below item/tool/view, right side of 3d viewport)
* Sidebar can be shown/hidden with the 'n' key.
* Change options and use the 'Export' button to export
# Batex - Batch Export as FBX

**Version:** 0.7.0
**Author:** jayanam, Rodrigo Camacho (forked from jayanam)

## Description

Batex is a Blender add-on that allows for batch exporting selected objects as FBX files. The add-on is particularly useful for exporting multiple objects with specific configurations like centered transforms, applied transforms, smoothing options, and more.

## Features

- Export multiple selected objects as FBX.
- Option to center the transform before exporting.
- Apply transforms like scale and rotation (Experimental).
- Support for different smoothing options (Edge, Face, Normals Only).
- Export rig and animations along with the objects.
- Option to export just one material per object.

## Recent Modifications

### Version 0.7.0

- **Added support for exporting empty objects with children:**
- Empty objects are now included in the export process, preserving the parent-child relationship when re-importing the FBX files.
- This ensures that the hierarchy is maintained, even if the parent object is an empty object.

- **Improved error handling for objects without materials:**
- The export process now checks if an object has mesh data before attempting to access its materials, preventing errors when processing empty objects or other non-mesh types.

## Installation

1. Download the Batex add-on from the repository.
2. Open Blender and go to `Edit > Preferences > Add-ons`.
3. Click `Install` and select the downloaded file.
4. Enable the add-on from the list.

## Usage

1. Open the Batex panel in the 3D view (`N` panel > `Batex`).
2. Set the export folder, and choose your desired options like centering transforms, applying transforms, etc.
3. Select the objects you wish to export.
4. Click `Export` to batch export the selected objects as FBX.

## License

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.
32 changes: 16 additions & 16 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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",
Expand All @@ -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()
51 changes: 27 additions & 24 deletions bex_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -58,6 +57,7 @@ def remove_materials(self, obj):
else:
return False


def restore_materials(self, obj):

# Restore the materials for the object
Expand Down Expand Up @@ -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
Expand All @@ -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)
set_object_to_loc(obj, old_pos)