BallanceBlenderHelper/ballance_blender_plugin/__init__.py

217 lines
8.0 KiB
Python
Raw Normal View History

2020-07-09 11:33:45 +08:00
bl_info={
"name":"Ballance Blender Plugin",
"description":"Ballance mapping tools for Blender",
"author":"yyc12345",
"version":(3,0),
2020-07-09 11:33:45 +08:00
"blender":(2,83,0),
"category":"Object",
2020-08-08 11:35:32 +08:00
"support":"TESTING",
"warning": "Please read document before using this plugin.",
"wiki_url": "https://github.com/yyc12345/BallanceBlenderHelper",
"tracker_url": "https://github.com/yyc12345/BallanceBlenderHelper/issues"
2020-07-09 11:33:45 +08:00
}
# =============================================
# import system
2022-04-04 22:04:11 +08:00
import bpy, bpy_extras
2020-10-05 22:30:06 +08:00
import bpy.utils.previews
import os
2020-07-09 11:33:45 +08:00
# import my code (with reload)
if "bpy" in locals():
import importlib
if "UTILS_constants" in locals():
importlib.reload(UTILS_constants)
if "UTILS_functions" in locals():
importlib.reload(UTILS_functions)
if "UTILS_preferences" in locals():
importlib.reload(UTILS_preferences)
if "UTILS_file_io" in locals():
importlib.reload(UTILS_file_io)
if "UTILS_zip_helper" in locals():
importlib.reload(UTILS_zip_helper)
if "UTILS_virtools_prop" in locals():
importlib.reload(UTILS_virtools_prop)
if "BMFILE_export" in locals():
importlib.reload(BMFILE_export)
if "BMFILE_import" in locals():
importlib.reload(BMFILE_import)
if "MODS_rail_uv" in locals():
importlib.reload(MODS_rail_uv)
if "MODS_3dsmax_align" in locals():
importlib.reload(MODS_3dsmax_align)
if "MODS_flatten_uv" in locals():
importlib.reload(MODS_flatten_uv)
if "OBJS_add_components" in locals():
importlib.reload(OBJS_add_components)
if "OBJS_add_floors" in locals():
importlib.reload(OBJS_add_floors)
if "OBJS_add_rails" in locals():
importlib.reload(OBJS_add_rails)
2022-04-04 22:04:11 +08:00
if "NAMES_rename_system" in locals():
importlib.reload(NAMES_rename_system)
if "PROPS_virtools_group" in locals():
importlib.reload(PROPS_virtools_group)
if "PROPS_virtools_material" in locals():
importlib.reload(PROPS_virtools_material)
from . import UTILS_constants, UTILS_functions, UTILS_preferences, UTILS_virtools_prop
from . import BMFILE_export, BMFILE_import
from . import MODS_3dsmax_align, MODS_flatten_uv, MODS_rail_uv
from . import OBJS_add_components, OBJS_add_floors, OBJS_add_rails
2022-04-04 22:04:11 +08:00
from . import NAMES_rename_system
from . import PROPS_virtools_group, PROPS_virtools_material
# =============================================
# menu system
2020-07-12 21:04:38 +08:00
class BALLANCE_MT_ThreeDViewerMenu(bpy.types.Menu):
2022-04-05 15:55:42 +08:00
"""Ballance 3D operators"""
bl_idname = "BALLANCE_MT_ThreeDViewerMenu"
2022-04-04 22:04:11 +08:00
bl_label = "Ballance"
2020-07-12 21:04:38 +08:00
def draw(self, context):
layout = self.layout
layout.operator(MODS_3dsmax_align.BALLANCE_OT_super_align.bl_idname)
layout.operator(MODS_rail_uv.BALLANCE_OT_rail_uv.bl_idname)
layout.operator(MODS_flatten_uv.BALLANCE_OT_flatten_uv.bl_idname)
2020-07-12 21:04:38 +08:00
2022-04-04 22:04:11 +08:00
class BALLANCE_MT_OutlinerMenu(bpy.types.Menu):
"""Ballance rename operators"""
bl_idname = "BALLANCE_MT_OutlinerMenu"
bl_label = "Ballance"
def draw(self, context):
layout = self.layout
2022-04-05 15:55:42 +08:00
oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_rename_by_group.bl_idname)
2022-04-04 22:04:11 +08:00
oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_convert_name.bl_idname)
oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_auto_grouping.bl_idname)
2020-10-05 22:30:06 +08:00
class BALLANCE_MT_AddFloorMenu(bpy.types.Menu):
"""Add Ballance floor"""
bl_idname = "BALLANCE_MT_AddFloorMenu"
bl_label = "Floors"
def draw(self, context):
layout = self.layout
layout.label(text="Basic floor")
2022-04-04 11:30:04 +08:00
for item in UTILS_constants.floor_basicBlockList:
cop = layout.operator(
OBJS_add_floors.BALLANCE_OT_add_floors.bl_idname,
text=item, icon_value = UTILS_constants.icons_floorDict[item])
2020-10-05 22:30:06 +08:00
cop.floor_type = item
layout.separator()
layout.label(text="Derived floor")
for item in UTILS_constants.floor_derivedBlockList:
cop = layout.operator(
OBJS_add_floors.BALLANCE_OT_add_floors.bl_idname,
text=item, icon_value = UTILS_constants.icons_floorDict[item])
2020-10-05 22:30:06 +08:00
cop.floor_type = item
# =============================================
# blender call system
2020-07-12 21:04:38 +08:00
2020-07-09 11:33:45 +08:00
classes = (
UTILS_preferences.BallanceBlenderPluginPreferences,
UTILS_preferences.MyPropertyGroup,
BMFILE_import.BALLANCE_OT_import_bm,
BMFILE_export.BALLANCE_OT_export_bm,
MODS_rail_uv.BALLANCE_OT_rail_uv,
MODS_3dsmax_align.BALLANCE_OT_super_align,
MODS_flatten_uv.BALLANCE_OT_flatten_uv,
BALLANCE_MT_ThreeDViewerMenu,
OBJS_add_components.BALLANCE_OT_add_components,
OBJS_add_rails.BALLANCE_OT_add_rails,
OBJS_add_floors.BALLANCE_OT_add_floors,
2022-04-04 12:45:41 +08:00
BALLANCE_MT_AddFloorMenu,
2022-04-05 15:55:42 +08:00
NAMES_rename_system.BALLANCE_OT_rename_by_group,
2022-04-04 22:04:11 +08:00
NAMES_rename_system.BALLANCE_OT_convert_name,
NAMES_rename_system.BALLANCE_OT_auto_grouping,
BALLANCE_MT_OutlinerMenu,
UTILS_virtools_prop.BALLANCE_PG_virtools_material,
UTILS_virtools_prop.BALLANCE_PG_virtools_group,
PROPS_virtools_group.BALLANCE_OT_add_virtools_group,
PROPS_virtools_group.BALLANCE_OT_rm_virtools_group,
PROPS_virtools_group.BALLANCE_UL_virtools_group,
PROPS_virtools_group.BALLANCE_PT_virtools_group,
PROPS_virtools_material.BALLANCE_OT_apply_virtools_material,
PROPS_virtools_material.BALLANCE_PT_virtools_material
2020-07-09 11:33:45 +08:00
)
def menu_func_bm_import(self, context):
self.layout.operator(BMFILE_import.BALLANCE_OT_import_bm.bl_idname, text="Ballance Map (.bmx)")
2020-07-09 11:33:45 +08:00
def menu_func_bm_export(self, context):
self.layout.operator(BMFILE_export.BALLANCE_OT_export_bm.bl_idname, text="Ballance Map (.bmx)")
2020-07-12 21:04:38 +08:00
def menu_func_ballance_3d(self, context):
layout = self.layout
layout.menu(BALLANCE_MT_ThreeDViewerMenu.bl_idname)
def menu_func_ballance_add(self, context):
layout = self.layout
layout.separator()
layout.label(text="Ballance")
layout.operator_menu_enum(
OBJS_add_components.BALLANCE_OT_add_components.bl_idname,
"elements_type", icon='MESH_ICOSPHERE', text="Elements")
layout.operator(OBJS_add_rails.BALLANCE_OT_add_rails.bl_idname, icon='MESH_CIRCLE', text="Rail section")
2020-10-05 22:30:06 +08:00
layout.menu(BALLANCE_MT_AddFloorMenu.bl_idname, icon='MESH_CUBE')
def menu_func_ballance_rename(self, context):
layout = self.layout
2022-04-04 22:04:11 +08:00
layout.menu(BALLANCE_MT_OutlinerMenu.bl_idname)
2020-07-09 11:33:45 +08:00
def register():
2020-10-05 22:30:06 +08:00
# we need init all icon first
icon_path = os.path.join(os.path.dirname(__file__), "icons")
UTILS_constants.icons_floor = bpy.utils.previews.new()
for key, value in UTILS_constants.floor_blockDict.items():
2020-10-05 22:30:06 +08:00
blockIconName = "Ballance_FloorIcon_" + key
UTILS_constants.icons_floor.load(blockIconName, os.path.join(icon_path, "floor", value["BindingDisplayTexture"]), 'IMAGE')
UTILS_constants.icons_floorDict[key] = UTILS_constants.icons_floor[blockIconName].icon_id
2020-10-05 22:30:06 +08:00
2020-07-09 11:33:45 +08:00
for cls in classes:
bpy.utils.register_class(cls)
2020-10-06 23:57:21 +08:00
bpy.types.Scene.BallanceBlenderPluginProperty = bpy.props.PointerProperty(type=UTILS_preferences.MyPropertyGroup)
UTILS_virtools_prop.register_props()
2020-07-09 11:33:45 +08:00
bpy.types.TOPBAR_MT_file_import.append(menu_func_bm_import)
bpy.types.TOPBAR_MT_file_export.append(menu_func_bm_export)
2020-07-12 21:04:38 +08:00
2022-04-04 12:45:41 +08:00
bpy.types.VIEW3D_MT_editor_menus.prepend(menu_func_ballance_3d)
bpy.types.VIEW3D_MT_add.append(menu_func_ballance_add)
2022-04-04 22:04:11 +08:00
bpy.types.OUTLINER_HT_header.append(menu_func_ballance_rename)
2020-07-09 11:33:45 +08:00
def unregister():
bpy.types.TOPBAR_MT_file_import.remove(menu_func_bm_import)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_bm_export)
2022-04-04 12:45:41 +08:00
bpy.types.VIEW3D_MT_editor_menus.remove(menu_func_ballance_3d)
bpy.types.VIEW3D_MT_add.remove(menu_func_ballance_add)
2022-04-04 22:04:11 +08:00
bpy.types.OUTLINER_HT_header.remove(menu_func_ballance_rename)
2020-07-12 21:04:38 +08:00
UTILS_virtools_prop.unregister_props()
del bpy.types.Scene.BallanceBlenderPluginProperty
2020-07-09 11:33:45 +08:00
for cls in classes:
bpy.utils.unregister_class(cls)
2020-10-05 22:30:06 +08:00
# we need uninstall all icon after all classes unregister
bpy.utils.previews.remove(UTILS_constants.icons_floor)
2020-07-09 11:33:45 +08:00
if __name__=="__main__":
register()