BallanceBlenderHelper/ballance_blender_plugin/__init__.py

141 lines
5.1 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",
2020-09-06 10:11:48 +08:00
"version":(1,1),
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
}
2020-07-12 21:04:38 +08:00
# ============================================= import system
2020-07-09 11:33:45 +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 "bm_import_export" in locals():
importlib.reload(bm_import_export)
if "rail_uv" in locals():
importlib.reload(rail_uv)
2020-07-12 21:04:38 +08:00
if "utils" in locals():
importlib.reload(utils)
2020-07-14 14:55:12 +08:00
if "config" in locals():
importlib.reload(config)
2020-07-19 15:05:43 +08:00
if "preferences" in locals():
importlib.reload(preferences)
if "threedsmax_align" in locals():
importlib.reload(threedsmax_align)
if "no_uv_checker" in locals():
importlib.reload(no_uv_checker)
if "add_elements" in locals():
importlib.reload(add_elements)
2020-10-05 22:30:06 +08:00
if "add_floor" in locals():
importlib.reload(add_floor)
from . import config, utils, bm_import_export, rail_uv, preferences, threedsmax_align, no_uv_checker, add_elements, add_floor
2020-07-12 21:04:38 +08:00
# ============================================= menu system
class BALLANCE_MT_ThreeDViewerMenu(bpy.types.Menu):
2020-07-19 15:13:55 +08:00
"""Ballance related 3D operator"""
bl_idname = "BALLANCE_MT_ThreeDViewerMenu"
2020-07-12 21:04:38 +08:00
bl_label = "Ballance 3D"
def draw(self, context):
layout = self.layout
layout.operator("ballance.super_align")
2020-07-12 21:04:38 +08:00
layout.operator("ballance.rail_uv")
layout.operator("ballance.no_uv_checker")
2020-07-12 21:04:38 +08:00
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")
for item in config.floor_basic_block_list:
print(config.blenderIcon_floor_dict[item])
cop = layout.operator("ballance.add_floor", text=item, icon_value = config.blenderIcon_floor_dict[item])
cop.floor_type = item
layout.separator()
layout.label(text="Derived floor")
for item in config.floor_derived_block_list:
cop = layout.operator("ballance.add_floor", text=item, icon_value = config.blenderIcon_floor_dict[item])
cop.floor_type = item
2020-07-12 21:04:38 +08:00
# ============================================= blender call system
2020-07-09 11:33:45 +08:00
classes = (
2020-07-19 15:05:43 +08:00
preferences.BallanceBlenderPluginPreferences,
bm_import_export.BALLANCE_OT_import_bm,
bm_import_export.BALLANCE_OT_export_bm,
rail_uv.BALLANCE_OT_rail_uv,
threedsmax_align.BALLANCE_OT_super_align,
no_uv_checker.BALLANCE_OT_no_uv_checker,
BALLANCE_MT_ThreeDViewerMenu,
2020-09-03 13:57:06 +08:00
add_elements.BALLANCE_OT_add_elements,
2020-10-05 22:30:06 +08:00
add_elements.BALLANCE_OT_add_rail,
add_floor.BALLANCE_OT_add_floor,
BALLANCE_MT_AddFloorMenu
2020-07-09 11:33:45 +08:00
)
def menu_func_bm_import(self, context):
2020-09-06 10:11:48 +08:00
self.layout.operator(bm_import_export.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):
2020-09-06 10:11:48 +08:00
self.layout.operator(bm_import_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")
2020-09-03 13:57:06 +08:00
layout.operator_menu_enum("ballance.add_elements", "elements_type", icon='MESH_ICOSPHERE', text="Elements")
layout.operator("ballance.add_rail", icon='MESH_CUBE', text="Rail section")
2020-10-05 22:30:06 +08:00
layout.menu(BALLANCE_MT_AddFloorMenu.bl_idname, icon='MESH_CUBE')
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")
config.blenderIcon_floor = bpy.utils.previews.new()
for key, value in config.floor_block_dict.items():
blockIconName = "Ballance_FloorIcon_" + key
config.blenderIcon_floor.load(blockIconName, os.path.join(icon_path, "floor", value["BindingDisplayTexture"]), 'IMAGE')
config.blenderIcon_floor_dict[key] = config.blenderIcon_floor[blockIconName].icon_id
2020-07-09 11:33:45 +08:00
for cls in classes:
bpy.utils.register_class(cls)
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
bpy.types.VIEW3D_HT_header.append(menu_func_ballance_3d)
bpy.types.VIEW3D_MT_add.append(menu_func_ballance_add)
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)
2020-07-12 21:04:38 +08:00
bpy.types.VIEW3D_HT_header.remove(menu_func_ballance_3d)
bpy.types.VIEW3D_MT_add.remove(menu_func_ballance_add)
2020-07-12 21:04:38 +08:00
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(config.blenderIcon_floor)
2020-07-09 11:33:45 +08:00
if __name__=="__main__":
register()