2023-10-09 22:20:21 +08:00
|
|
|
bl_info = {
|
|
|
|
"name": "Ballance Blender Plugin",
|
|
|
|
"description": "Ballance mapping tools for Blender",
|
|
|
|
"author": "yyc12345",
|
|
|
|
"version": (4, 0),
|
|
|
|
"blender": (3, 6, 0),
|
|
|
|
"category": "Object",
|
|
|
|
"support": "COMMUNITY",
|
|
|
|
"warning": "Please read document before using this plugin.",
|
|
|
|
"doc_url": "https://github.com/yyc12345/BallanceBlenderHelper",
|
|
|
|
"tracker_url": "https://github.com/yyc12345/BallanceBlenderHelper/issues"
|
|
|
|
}
|
|
|
|
|
|
|
|
#region Reload and Import
|
|
|
|
|
|
|
|
# import core lib
|
|
|
|
import bpy
|
2023-10-10 16:01:52 +08:00
|
|
|
import typing, collections
|
2023-10-09 22:20:21 +08:00
|
|
|
|
|
|
|
# reload if needed
|
|
|
|
if "bpy" in locals():
|
|
|
|
import importlib
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2023-11-22 19:57:29 +08:00
|
|
|
# we must load icons manager first
|
|
|
|
# and register it
|
|
|
|
from . import UTIL_icons_manager
|
|
|
|
UTIL_icons_manager.register()
|
|
|
|
|
|
|
|
# then load other modules
|
2023-12-14 18:03:03 +08:00
|
|
|
from . import PROP_preferences, PROP_ptrprop_resolver, PROP_virtools_material, PROP_virtools_texture, PROP_virtools_mesh, PROP_virtools_group, PROP_ballance_element, PROP_bme_material
|
2023-10-18 21:23:04 +08:00
|
|
|
from . import OP_IMPORT_bmfile, OP_EXPORT_bmfile, OP_IMPORT_virtools, OP_EXPORT_virtools
|
2023-10-23 10:57:29 +08:00
|
|
|
from . import OP_UV_flatten_uv, OP_UV_rail_uv
|
2023-12-06 17:16:31 +08:00
|
|
|
from . import OP_ADDS_component
|
2023-10-10 16:01:52 +08:00
|
|
|
|
|
|
|
#region Menu
|
|
|
|
|
|
|
|
# ===== Menu Defines =====
|
|
|
|
|
|
|
|
class BBP_MT_View3DMenu(bpy.types.Menu):
|
|
|
|
"""Ballance 3D operators"""
|
|
|
|
bl_idname = "BBP_MT_View3DMenu"
|
|
|
|
bl_label = "Ballance"
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
|
|
|
layout.operator(OP_UV_flatten_uv.BBP_OT_flatten_uv.bl_idname)
|
2023-10-23 10:57:29 +08:00
|
|
|
layout.operator(OP_UV_rail_uv.BBP_OT_rail_uv.bl_idname)
|
2023-10-10 16:01:52 +08:00
|
|
|
|
2023-12-06 17:16:31 +08:00
|
|
|
class BBP_MT_AddFloorMenu(bpy.types.Menu):
|
|
|
|
"""Add Ballance Floor"""
|
|
|
|
bl_idname = "BBP_MT_AddFloorMenu"
|
|
|
|
bl_label = "Floors"
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
|
|
|
|
|
|
|
layout.label(text="Basic floor")
|
|
|
|
|
|
|
|
layout.separator()
|
|
|
|
layout.label(text="Derived floor")
|
|
|
|
class BBP_MT_AddRailMenu(bpy.types.Menu):
|
|
|
|
"""Add Ballance Rail"""
|
|
|
|
bl_idname = "BBP_MT_AddRailMenu"
|
|
|
|
bl_label = "Rails"
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
2023-12-09 17:42:03 +08:00
|
|
|
class BBP_MT_AddComponentsMenu(bpy.types.Menu):
|
|
|
|
"""Add Ballance Components"""
|
|
|
|
bl_idname = "BBP_MT_AddComponentsMenu"
|
|
|
|
bl_label = "Components"
|
2023-12-06 17:16:31 +08:00
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
|
|
|
|
2023-12-09 17:42:03 +08:00
|
|
|
layout.label(text="Basic Components")
|
2023-12-06 17:16:31 +08:00
|
|
|
OP_ADDS_component.BBP_OT_add_component.draw_blc_menu(layout)
|
|
|
|
|
|
|
|
layout.separator()
|
2023-12-09 17:42:03 +08:00
|
|
|
layout.label(text="Nong Components")
|
|
|
|
OP_ADDS_component.BBP_OT_add_nong_extra_point.draw_blc_menu(layout)
|
2023-12-06 17:16:31 +08:00
|
|
|
|
|
|
|
layout.separator()
|
2023-12-09 17:42:03 +08:00
|
|
|
layout.label(text="Series Components")
|
|
|
|
OP_ADDS_component.BBP_OT_add_tilting_block_series.draw_blc_menu(layout)
|
|
|
|
OP_ADDS_component.BBP_OT_add_ventilator_series.draw_blc_menu(layout)
|
|
|
|
|
|
|
|
layout.separator()
|
|
|
|
layout.label(text="Components Pair")
|
|
|
|
OP_ADDS_component.BBP_OT_add_sector_component_pair.draw_blc_menu(layout)
|
2023-12-06 17:16:31 +08:00
|
|
|
|
2023-10-10 16:01:52 +08:00
|
|
|
# ===== Menu Drawer =====
|
|
|
|
|
|
|
|
MenuDrawer_t = typing.Callable[[typing.Any, typing.Any], None]
|
|
|
|
|
2023-10-18 21:23:04 +08:00
|
|
|
def menu_drawer_import(self, context):
|
|
|
|
layout: bpy.types.UILayout = self.layout
|
|
|
|
layout.operator(OP_IMPORT_bmfile.BBP_OT_import_bmfile.bl_idname, text = "Ballance Map (.bmx)")
|
|
|
|
layout.operator(OP_IMPORT_virtools.BBP_OT_import_virtools.bl_idname, text = "Virtools File (.nmo/.cmo/.vmo) (experimental)")
|
|
|
|
|
|
|
|
def menu_drawer_export(self, context):
|
|
|
|
layout: bpy.types.UILayout = self.layout
|
|
|
|
layout.operator(OP_EXPORT_bmfile.BBP_OT_export_bmfile.bl_idname, text = "Ballance Map (.bmx)")
|
|
|
|
layout.operator(OP_EXPORT_virtools.BBP_OT_export_virtools.bl_idname, text = "Virtools File (.nmo/.cmo/.vmo) (experimental)")
|
|
|
|
|
2023-10-10 16:01:52 +08:00
|
|
|
def menu_drawer_view3d(self, context):
|
2023-10-18 21:23:04 +08:00
|
|
|
layout: bpy.types.UILayout = self.layout
|
2023-10-10 16:01:52 +08:00
|
|
|
layout.menu(BBP_MT_View3DMenu.bl_idname)
|
|
|
|
|
2023-12-06 17:16:31 +08:00
|
|
|
def menu_drawer_add(self, context):
|
|
|
|
layout: bpy.types.UILayout = self.layout
|
|
|
|
layout.separator()
|
|
|
|
layout.label(text="Ballance")
|
|
|
|
layout.menu(BBP_MT_AddFloorMenu.bl_idname, icon='MESH_CUBE')
|
|
|
|
layout.menu(BBP_MT_AddRailMenu.bl_idname, icon='MESH_CIRCLE')
|
2023-12-09 17:42:03 +08:00
|
|
|
layout.menu(BBP_MT_AddComponentsMenu.bl_idname, icon='MESH_ICOSPHERE')
|
2023-12-06 17:16:31 +08:00
|
|
|
#layout.operator_menu_enum(
|
|
|
|
# OBJS_add_components.BALLANCE_OT_add_components.bl_idname,
|
2023-12-09 17:42:03 +08:00
|
|
|
# "Components_type", icon='MESH_ICOSPHERE', text="Components")
|
2023-10-10 16:01:52 +08:00
|
|
|
#endregion
|
|
|
|
|
2023-10-09 22:20:21 +08:00
|
|
|
#region Register and Unregister.
|
|
|
|
|
2023-10-14 11:48:41 +08:00
|
|
|
g_BldClasses: tuple[typing.Any, ...] = (
|
2023-10-10 16:01:52 +08:00
|
|
|
BBP_MT_View3DMenu,
|
2023-12-06 17:16:31 +08:00
|
|
|
BBP_MT_AddFloorMenu,
|
|
|
|
BBP_MT_AddRailMenu,
|
2023-12-09 17:42:03 +08:00
|
|
|
BBP_MT_AddComponentsMenu
|
2023-10-10 16:01:52 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
class MenuEntry():
|
|
|
|
mContainerMenu: bpy.types.Menu
|
|
|
|
mIsAppend: bool
|
|
|
|
mMenuDrawer: MenuDrawer_t
|
|
|
|
def __init__(self, cont: bpy.types.Menu, is_append: bool, menu_func: MenuDrawer_t):
|
|
|
|
self.mContainerMenu = cont
|
|
|
|
self.mIsAppend = is_append
|
|
|
|
self.mMenuDrawer = menu_func
|
2023-10-14 11:48:41 +08:00
|
|
|
|
|
|
|
g_BldMenus: tuple[MenuEntry, ...] = (
|
2023-10-10 16:01:52 +08:00
|
|
|
MenuEntry(bpy.types.VIEW3D_MT_editor_menus, False, menu_drawer_view3d),
|
2023-10-18 21:23:04 +08:00
|
|
|
MenuEntry(bpy.types.TOPBAR_MT_file_import, True, menu_drawer_import),
|
|
|
|
MenuEntry(bpy.types.TOPBAR_MT_file_export, True, menu_drawer_export),
|
2023-12-06 17:16:31 +08:00
|
|
|
MenuEntry(bpy.types.VIEW3D_MT_add, True, menu_drawer_add),
|
2023-10-10 16:01:52 +08:00
|
|
|
)
|
|
|
|
|
2023-10-09 22:20:21 +08:00
|
|
|
def register() -> None:
|
2023-10-14 11:48:41 +08:00
|
|
|
# register module
|
2023-10-18 21:23:04 +08:00
|
|
|
PROP_preferences.register()
|
2023-11-16 22:41:03 +08:00
|
|
|
PROP_ptrprop_resolver.register()
|
|
|
|
|
2023-10-14 11:48:41 +08:00
|
|
|
PROP_virtools_material.register()
|
2023-11-11 13:32:58 +08:00
|
|
|
PROP_virtools_texture.register()
|
2023-11-15 23:05:00 +08:00
|
|
|
PROP_virtools_mesh.register()
|
2023-10-27 11:51:12 +08:00
|
|
|
PROP_virtools_group.register()
|
2023-12-14 18:03:03 +08:00
|
|
|
PROP_ballance_element.register()
|
|
|
|
PROP_bme_material.register()
|
2023-10-10 16:01:52 +08:00
|
|
|
|
2023-10-18 21:23:04 +08:00
|
|
|
OP_IMPORT_bmfile.register()
|
|
|
|
OP_EXPORT_bmfile.register()
|
|
|
|
OP_IMPORT_virtools.register()
|
|
|
|
OP_EXPORT_virtools.register()
|
|
|
|
|
2023-10-23 10:57:29 +08:00
|
|
|
OP_UV_rail_uv.register()
|
2023-10-18 21:23:04 +08:00
|
|
|
OP_UV_flatten_uv.register()
|
2023-12-06 17:16:31 +08:00
|
|
|
OP_ADDS_component.register()
|
2023-10-18 21:23:04 +08:00
|
|
|
|
2023-10-14 11:48:41 +08:00
|
|
|
# register other classes
|
|
|
|
for cls in g_BldClasses:
|
|
|
|
bpy.utils.register_class(cls)
|
2023-10-11 22:24:22 +08:00
|
|
|
|
2023-10-10 16:01:52 +08:00
|
|
|
# add menu drawer
|
2023-10-14 11:48:41 +08:00
|
|
|
for entry in g_BldMenus:
|
2023-10-10 16:01:52 +08:00
|
|
|
if entry.mIsAppend:
|
|
|
|
entry.mContainerMenu.append(entry.mMenuDrawer)
|
|
|
|
else:
|
|
|
|
entry.mContainerMenu.prepend(entry.mMenuDrawer)
|
2023-10-09 22:20:21 +08:00
|
|
|
|
|
|
|
def unregister() -> None:
|
2023-10-10 16:01:52 +08:00
|
|
|
# remove menu drawer
|
2023-10-14 11:48:41 +08:00
|
|
|
for entry in g_BldMenus:
|
2023-10-10 16:01:52 +08:00
|
|
|
entry.mContainerMenu.remove(entry.mMenuDrawer)
|
|
|
|
|
2023-10-14 11:48:41 +08:00
|
|
|
# unregister other classes
|
|
|
|
for cls in g_BldClasses:
|
2023-10-10 16:01:52 +08:00
|
|
|
bpy.utils.unregister_class(cls)
|
2023-10-09 22:20:21 +08:00
|
|
|
|
2023-10-14 11:48:41 +08:00
|
|
|
# unregister modules
|
2023-12-06 17:16:31 +08:00
|
|
|
OP_ADDS_component.unregister()
|
2023-10-18 21:23:04 +08:00
|
|
|
OP_UV_flatten_uv.unregister()
|
2023-10-23 10:57:29 +08:00
|
|
|
OP_UV_rail_uv.unregister()
|
2023-10-18 21:23:04 +08:00
|
|
|
|
|
|
|
OP_EXPORT_virtools.unregister()
|
|
|
|
OP_IMPORT_virtools.unregister()
|
|
|
|
OP_EXPORT_bmfile.unregister()
|
|
|
|
OP_IMPORT_bmfile.unregister()
|
|
|
|
|
2023-12-14 18:03:03 +08:00
|
|
|
PROP_bme_material.unregister()
|
2023-10-25 12:07:14 +08:00
|
|
|
PROP_ballance_element.unregister()
|
2023-12-14 18:03:03 +08:00
|
|
|
PROP_virtools_group.unregister()
|
2023-11-15 23:05:00 +08:00
|
|
|
PROP_virtools_mesh.unregister()
|
2023-11-11 13:32:58 +08:00
|
|
|
PROP_virtools_texture.unregister()
|
2023-10-14 11:48:41 +08:00
|
|
|
PROP_virtools_material.unregister()
|
2023-11-16 22:41:03 +08:00
|
|
|
|
|
|
|
PROP_ptrprop_resolver.unregister()
|
2023-10-18 21:23:04 +08:00
|
|
|
PROP_preferences.unregister()
|
2023-10-14 11:48:41 +08:00
|
|
|
|
2023-10-09 22:20:21 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
register()
|
|
|
|
|
|
|
|
#endregion
|