mirror of
https://gitlab.com/ProcyonLotor/vrchat-template.git
synced 2026-08-25 10:43:53 +05:00
Much less cluttered version of the script
This commit is contained in:
Binary file not shown.
@@ -39,7 +39,7 @@ def fbx_export(context: Context) -> None:
|
|||||||
|
|
||||||
rootpath = os.path.normpath(bpy.path.abspath(context.scene.fbx_export.export_dir))
|
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_export.exportable]:
|
for group in [g for g in bpy.data.groups if g.fbx_exportable]:
|
||||||
filepath = os.path.join(rootpath, name_as_path(group.name))
|
filepath = os.path.join(rootpath, name_as_path(group.name))
|
||||||
basepath = os.path.dirname(filepath)
|
basepath = os.path.dirname(filepath)
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ def fbx_export(context: Context) -> None:
|
|||||||
override = context.copy()
|
override = context.copy()
|
||||||
override.update(
|
override.update(
|
||||||
{
|
{
|
||||||
"selected_objects": [o for o in group.objects if o.fbx_exportable]
|
"selected_objects": group.objects
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ def fbx_export(context: Context) -> None:
|
|||||||
axis_forward='-Z',
|
axis_forward='-Z',
|
||||||
axis_up='Y',
|
axis_up='Y',
|
||||||
object_types=context.scene.fbx_export.object_types,
|
object_types=context.scene.fbx_export.object_types,
|
||||||
use_mesh_modifiers=context.scene.fbx_export.use_mesh_modifiers,
|
use_mesh_modifiers=True,
|
||||||
mesh_smooth_type='OFF',
|
mesh_smooth_type='OFF',
|
||||||
use_mesh_edges=False,
|
use_mesh_edges=False,
|
||||||
use_tspace=False,
|
use_tspace=False,
|
||||||
@@ -77,7 +77,78 @@ def fbx_export(context: Context) -> None:
|
|||||||
filepath=filepath,
|
filepath=filepath,
|
||||||
)
|
)
|
||||||
|
|
||||||
print("[%s] Batch FBX export end." % datetime.now())
|
print("\n[%s] Batch FBX export end." % datetime.now())
|
||||||
|
|
||||||
|
|
||||||
|
class FBXExportProps(PropertyGroup):
|
||||||
|
export_dir = StringProperty(
|
||||||
|
name="FBX Export Dir",
|
||||||
|
description="FBX Export Directory",
|
||||||
|
subtype="DIR_PATH",
|
||||||
|
default="//../fbx/",
|
||||||
|
)
|
||||||
|
on_save = BoolProperty(
|
||||||
|
name="Export on save",
|
||||||
|
description="Export FBX on Blender file save",
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
object_types = ExportFBX.object_types
|
||||||
|
group_index = IntProperty(default=0)
|
||||||
|
|
||||||
|
|
||||||
|
class FBX_OT_ManualExport(Operator):
|
||||||
|
bl_idname = "fbx.manual_export"
|
||||||
|
bl_label = "Manual Export"
|
||||||
|
bl_description = "Export FBX manualy"
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
try:
|
||||||
|
fbx_export(context)
|
||||||
|
except Exception as e:
|
||||||
|
self.report({'ERROR'}, str(e))
|
||||||
|
return {'CANCELLED'}
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
|
class FBX_UL_ExportItems(UIList):
|
||||||
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.prop(item, "fbx_exportable", icon='CHECKBOX_HLT' if item.fbx_exportable else 'CHECKBOX_DEHLT', text="", emboss=False)
|
||||||
|
row.prop(item, "name", text="", emboss=False, icon='GROUP')
|
||||||
|
|
||||||
|
|
||||||
|
class SCENE_PT_fbx_autoexport(Panel):
|
||||||
|
"""Creates a Panel in the scene context of the properties editor"""
|
||||||
|
bl_label = "FBX Auto-Export"
|
||||||
|
bl_idname = "SCENE_PT_fbx_autoexport"
|
||||||
|
bl_space_type = 'PROPERTIES'
|
||||||
|
bl_region_type = 'WINDOW'
|
||||||
|
bl_context = "scene"
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
scene = context.scene
|
||||||
|
|
||||||
|
col = layout.column()
|
||||||
|
|
||||||
|
sub = col.column(align=True)
|
||||||
|
sub.prop(scene.fbx_export, "on_save", icon='LOAD_FACTORY')
|
||||||
|
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 = split.column()
|
||||||
|
sub.label("Filter object types:")
|
||||||
|
sub.prop(scene.fbx_export, "object_types")
|
||||||
|
|
||||||
|
col.separator()
|
||||||
|
|
||||||
|
col.prop(scene.fbx_export, "export_dir")
|
||||||
|
|
||||||
|
|
||||||
def on_save(*args, **kwargs) -> None:
|
def on_save(*args, **kwargs) -> None:
|
||||||
@@ -93,109 +164,32 @@ def on_save(*args, **kwargs) -> None:
|
|||||||
message_box(str(e), "Export error", 'ERROR')
|
message_box(str(e), "Export error", 'ERROR')
|
||||||
|
|
||||||
|
|
||||||
class FBX_OT_ForceExport(Operator):
|
classes = [
|
||||||
bl_idname = "fbx.force_export"
|
FBXExportProps,
|
||||||
bl_label = "Force Export"
|
FBX_OT_ManualExport,
|
||||||
bl_description = "Force export FBX"
|
FBX_UL_ExportItems,
|
||||||
|
SCENE_PT_fbx_autoexport,
|
||||||
def execute(self, context):
|
]
|
||||||
try:
|
|
||||||
fbx_export(context)
|
|
||||||
except Exception as e:
|
|
||||||
self.report({'ERROR'}, str(e))
|
|
||||||
return {'CANCELLED'}
|
|
||||||
return {'FINISHED'}
|
|
||||||
|
|
||||||
|
|
||||||
class AutoexportProps(PropertyGroup):
|
def register() -> None:
|
||||||
object_types = ExportFBX.object_types
|
for cls in classes:
|
||||||
use_mesh_modifiers = ExportFBX.use_mesh_modifiers
|
bpy.utils.register_class(cls)
|
||||||
export_dir = StringProperty(
|
bpy.types.Scene.fbx_export = PointerProperty(type=FBXExportProps)
|
||||||
name="FBX Export Dir",
|
bpy.types.Group.fbx_exportable = BoolProperty(
|
||||||
description="FBX Export Directory",
|
|
||||||
subtype="DIR_PATH",
|
|
||||||
default="//../fbx/",
|
|
||||||
)
|
|
||||||
on_save = BoolProperty(
|
|
||||||
name="Export on save",
|
|
||||||
description="Export FBX on Blender file save",
|
|
||||||
default=True
|
|
||||||
)
|
|
||||||
group_index = IntProperty(default=0)
|
|
||||||
|
|
||||||
|
|
||||||
class GroupExportProps(PropertyGroup):
|
|
||||||
exportable = BoolProperty(
|
|
||||||
name="Export Group",
|
name="Export Group",
|
||||||
description="Mark group as FBX exportable",
|
description="Mark group as FBX exportable",
|
||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
obj_index = IntProperty(default=0)
|
bpy.app.handlers.save_pre.append(on_save)
|
||||||
show_obj_list = BoolProperty(default=False)
|
|
||||||
|
|
||||||
|
|
||||||
class FBX_UL_ExportObjects(UIList):
|
def unregister() -> None:
|
||||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
bpy.app.handlers.save_pre.remove(on_save)
|
||||||
col = layout.column()
|
del bpy.types.Group.fbx_exportable
|
||||||
row = col.row(align=True)
|
del bpy.types.Scene.fbx_export
|
||||||
row.prop(item, "fbx_exportable", icon='CHECKBOX_HLT' if item.fbx_exportable else 'CHECKBOX_DEHLT', text="", emboss=False)
|
for cls in reversed(classes):
|
||||||
row.prop(item, "name", text="", emboss=False, icon='OBJECT_DATA' if item.dupli_type == "NONE" else 'OUTLINER_OB_GROUP_INSTANCE')
|
bpy.utils.unregister_class(cls)
|
||||||
|
|
||||||
|
|
||||||
class FBX_UL_ExportItems(UIList):
|
register()
|
||||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
|
||||||
col = layout.box().column()
|
|
||||||
row = col.split()
|
|
||||||
|
|
||||||
sub = row.row(align=True)
|
|
||||||
# sub.alignment = 'LEFT'
|
|
||||||
sub.prop(item.fbx_export, "exportable", icon='CHECKBOX_HLT' if item.fbx_export.exportable else 'CHECKBOX_DEHLT', text="", emboss=False)
|
|
||||||
sub.prop(item, "name", text="", emboss=False, icon='GROUP')
|
|
||||||
sub = row.row()
|
|
||||||
sub.alignment = 'RIGHT'
|
|
||||||
sub.label(text=str(len(item.objects)), icon='OBJECT_DATA')
|
|
||||||
sub.prop(item.fbx_export, "show_obj_list", icon='TRIA_DOWN' if item.fbx_export.show_obj_list else 'TRIA_LEFT', text="", emboss=False)
|
|
||||||
|
|
||||||
if item.fbx_export.show_obj_list:
|
|
||||||
col.template_list("FBX_UL_ExportObjects", str(index), item, "objects", item.fbx_export, "obj_index", rows=2)
|
|
||||||
|
|
||||||
|
|
||||||
class SCENE_PT_fbx_autoexport(Panel):
|
|
||||||
"""Creates a Panel in the scene context of the properties editor"""
|
|
||||||
bl_label = "FBX Auto-Export"
|
|
||||||
bl_idname = "SCENE_PT_fbx_autoexport"
|
|
||||||
bl_space_type = 'PROPERTIES'
|
|
||||||
bl_region_type = 'WINDOW'
|
|
||||||
bl_context = "scene"
|
|
||||||
|
|
||||||
def draw(self, context):
|
|
||||||
layout = self.layout
|
|
||||||
scene = context.scene
|
|
||||||
|
|
||||||
col = layout.column()
|
|
||||||
col.prop(scene.fbx_export, "use_mesh_modifiers")
|
|
||||||
sub = col.row()
|
|
||||||
sub.prop(scene.fbx_export, "object_types")
|
|
||||||
col.template_list("FBX_UL_ExportItems", "", bpy.data, "groups", scene.fbx_export, "group_index", rows=3)
|
|
||||||
|
|
||||||
col.separator()
|
|
||||||
col.prop(scene.fbx_export, "export_dir")
|
|
||||||
row = col.row(align=True)
|
|
||||||
row.prop(scene.fbx_export, "on_save", icon='LOAD_FACTORY')
|
|
||||||
row.operator(FBX_OT_ForceExport.bl_idname, icon="PASTEDOWN")
|
|
||||||
|
|
||||||
|
|
||||||
bpy.types.Object.fbx_exportable = BoolProperty(
|
|
||||||
name="Export Object",
|
|
||||||
description="Mark object as FBX exportable",
|
|
||||||
default=True
|
|
||||||
)
|
|
||||||
bpy.utils.register_class(FBX_OT_ForceExport)
|
|
||||||
bpy.utils.register_class(FBX_UL_ExportObjects)
|
|
||||||
bpy.utils.register_class(FBX_UL_ExportItems)
|
|
||||||
bpy.utils.register_class(AutoexportProps)
|
|
||||||
bpy.utils.register_class(GroupExportProps)
|
|
||||||
bpy.types.Scene.fbx_export = PointerProperty(type=AutoexportProps)
|
|
||||||
bpy.types.Group.fbx_export = PointerProperty(type=GroupExportProps)
|
|
||||||
bpy.utils.register_class(SCENE_PT_fbx_autoexport)
|
|
||||||
bpy.app.handlers.save_pre.append(on_save)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user