Future-proof implementation

This commit is contained in:
raccoon
2025-01-20 03:16:06 +05:00
parent a01ccf03ce
commit 5a270289f0

View File

@@ -2,10 +2,13 @@ import os
from datetime import datetime
import bpy
from bpy.props import StringProperty, BoolProperty, PointerProperty, IntProperty
FUTURE = bpy.app.version >= (2, 80, 0)
from bpy.props import EnumProperty, StringProperty, BoolProperty, PointerProperty, IntProperty
from bpy.types import UIList, Operator, Panel, PropertyGroup, Context
from io_scene_fbx import ExportFBX
if FUTURE:
from bpy.types import Collection as Group
else:
from bpy.types import Group
def message_box(message: str, title: str = "Message", icon: str = 'INFO') -> None:
@@ -18,7 +21,7 @@ def message_box(message: str, title: str = "Message", icon: str = 'INFO') -> Non
def draw(self, context):
col = self.layout.column(align=True)
for line in message.strip().split("\n"):
col.label(line)
col.label(text=line)
bpy.context.window_manager.popup_menu(draw, title=title, icon=icon)
@@ -39,7 +42,8 @@ def fbx_export(context: Context) -> None:
rootpath = os.path.normpath(bpy.path.abspath(context.scene.fbx_export.export_dir))
for group in [g for g in bpy.data.groups if g.fbx_exportable]:
groups = bpy.data.collections if FUTURE else bpy.data.groups
for group in [g for g in groups if g.fbx_exportable]:
filepath = os.path.join(rootpath, name_as_path(group.name))
basepath = os.path.dirname(filepath)
@@ -93,7 +97,20 @@ class FBXExportProps(PropertyGroup):
description="Export FBX on Blender file save",
default=False
)
object_types = ExportFBX.object_types
object_types = EnumProperty(
name="Object Types",
options={'ENUM_FLAG'},
items=(
('EMPTY', "Empty", ""),
('CAMERA', "Camera", ""),
('LAMP', "Lamp", ""),
('ARMATURE', "Armature", "WARNING: not supported in dupli/group instances"),
('MESH', "Mesh", ""),
('OTHER', "Other", "Other geometry types, like curve, metaball, etc. (converted to meshes)"),
),
description="Which kind of object to export",
default={'EMPTY', 'CAMERA', 'LAMP', 'ARMATURE', 'MESH', 'OTHER'},
)
group_index = IntProperty(default=0)
@@ -133,17 +150,17 @@ class SCENE_PT_fbx_autoexport(Panel):
col = layout.column()
sub = col.column(align=True)
sub.prop(scene.fbx_export, "on_save", icon='LOAD_FACTORY')
sub.prop(scene.fbx_export, "on_save", icon='FILE_REFRESH')
sub.operator(FBX_OT_ManualExport.bl_idname, icon="PASTEDOWN")
col.separator()
split = col.split()
sub = split.column()
sub.label("Filter groups:")
sub.template_list("FBX_UL_ExportItems", "", bpy.data, "groups", scene.fbx_export, "group_index", rows=5)
sub.label(text="Filter groups:")
sub.template_list("FBX_UL_ExportItems", "", bpy.data, "collections" if FUTURE else "groups", scene.fbx_export, "group_index", rows=5)
sub = split.column()
sub.label("Filter object types:")
sub.label(text="Filter object types:")
sub.prop(scene.fbx_export, "object_types")
col.separator()
@@ -176,7 +193,7 @@ def register() -> None:
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.fbx_export = PointerProperty(type=FBXExportProps)
bpy.types.Group.fbx_exportable = BoolProperty(
Group.fbx_exportable = BoolProperty(
name="Export Group",
description="Mark group as FBX exportable",
default=False
@@ -186,7 +203,7 @@ def register() -> None:
def unregister() -> None:
bpy.app.handlers.save_pre.remove(on_save)
del bpy.types.Group.fbx_exportable
del Group.fbx_exportable
del bpy.types.Scene.fbx_export
for cls in reversed(classes):
bpy.utils.unregister_class(cls)