From 05d22902c78688ea56f05e9cf0a8434d1d72359f Mon Sep 17 00:00:00 2001 From: Yusarina Date: Sun, 30 Jun 2024 13:07:43 +0100 Subject: [PATCH 1/2] FBX Import - Add's the ability to import FBX Models. --- core/importer.py | 17 +++++++++++++++++ ui/quick_access.py | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 core/importer.py diff --git a/core/importer.py b/core/importer.py new file mode 100644 index 0000000..e29ca11 --- /dev/null +++ b/core/importer.py @@ -0,0 +1,17 @@ +import bpy + +# Importers which don't need much code should be added here, however if a importer needs alot of code +# Like the PMX and PMD importers, they should be added to their own files. + + +# FBX Importer settings borrowed form Cat's Blender Plugin +def import_fbx(filepath): + try: + bpy.ops.import_scene.fbx( + filepath=filepath, + automatic_bone_orientation=False, + use_prepost_rot=False, + use_anim=False + ) + except (TypeError, ValueError) as e: + print(f"Error importing FBX: {str(e)}") diff --git a/ui/quick_access.py b/ui/quick_access.py index 80562b1..dcbae0b 100644 --- a/ui/quick_access.py +++ b/ui/quick_access.py @@ -4,6 +4,7 @@ from .panel import AvatarToolkitPanel from ..core.import_pmx import import_pmx from ..core.import_pmd import import_pmd +from ..core.importer import import_fbx @register_wrap class AvatarToolkitQuickAccessPanel(bpy.types.Panel): @@ -45,6 +46,8 @@ class AVATAR_TOOLKIT_OT_import_menu(bpy.types.Operator): layout.label(text="Select Import Method") layout.operator("avatar_toolkit.import_pmx", text="Import PMX") layout.operator("avatar_toolkit.import_pmd", text="Import PMD") + layout.operator("avatar_toolkit.import_fbx", text="Import FBX") + @register_wrap class AVATAR_TOOLKIT_OT_export_menu(bpy.types.Operator): @@ -91,3 +94,18 @@ class AVATAR_TOOLKIT_OT_import_pmd(bpy.types.Operator): def invoke(self, context, event): context.window_manager.fileselect_add(self) return {'RUNNING_MODAL'} + +@register_wrap +class AVATAR_TOOLKIT_OT_import_fbx(bpy.types.Operator): + bl_idname = "avatar_toolkit.import_fbx" + bl_label = "Import FBX" + + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + + def execute(self, context): + import_fbx(self.filepath) + return {'FINISHED'} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {'RUNNING_MODAL'} From 041ce3e5d11122dc264633b446241934dc2282f1 Mon Sep 17 00:00:00 2001 From: Yusarina Date: Mon, 22 Jul 2024 02:24:33 +0100 Subject: [PATCH 2/2] Added FBX Export --- ui/quick_access.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ui/quick_access.py b/ui/quick_access.py index dca6bcf..9ceee62 100644 --- a/ui/quick_access.py +++ b/ui/quick_access.py @@ -49,12 +49,15 @@ class AVATAR_TOOLKIT_OT_import_menu(bpy.types.Operator): layout.operator("avatar_toolkit.import_pmd", text="Import PMD") layout.operator("avatar_toolkit.import_fbx", text="Import FBX") - @register_wrap class AVATAR_TOOLKIT_OT_export_menu(bpy.types.Operator): bl_idname = "avatar_toolkit.export_menu" bl_label = "Export Menu" + @classmethod + def poll(cls, context): + return any(obj.type == 'MESH' for obj in context.scene.objects) + def execute(self, context: Context): return {'FINISHED'} @@ -66,6 +69,7 @@ class AVATAR_TOOLKIT_OT_export_menu(bpy.types.Operator): layout = self.layout layout.label(text="Select Export Method") layout.operator("avatar_toolkit.export_resonite", text="Export Resonite") + layout.operator("avatar_toolkit.export_fbx", text="Export FBX") @register_wrap class AVATAR_TOOLKIT_OT_import_pmx(bpy.types.Operator): @@ -111,3 +115,16 @@ class AVATAR_TOOLKIT_OT_import_fbx(bpy.types.Operator): def invoke(self, context, event): context.window_manager.fileselect_add(self) return {'RUNNING_MODAL'} + +@register_wrap +class AVATAR_TOOLKIT_OT_export_fbx(bpy.types.Operator): + bl_idname = 'avatar_toolkit.export_fbx' + bl_label = "Export FBX" + bl_description = "Export the model as FBX" + bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} + + def execute(self, context): + bpy.ops.export_scene.fbx('INVOKE_DEFAULT') + return {'FINISHED'} + +