2020-07-09 11:33:45 +08:00
|
|
|
bl_info={
|
|
|
|
"name":"Ballance Blender Plugin",
|
|
|
|
"description":"Ballance mapping tools for Blender",
|
|
|
|
"author":"yyc12345",
|
2020-10-21 13:48:36 +08:00
|
|
|
"version":(2,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
|
|
|
}
|
|
|
|
|
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)
|
2020-08-31 21:56:08 +08:00
|
|
|
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)
|
2020-08-31 21:56:08 +08:00
|
|
|
if "threedsmax_align" in locals():
|
|
|
|
importlib.reload(threedsmax_align)
|
|
|
|
if "no_uv_checker" in locals():
|
|
|
|
importlib.reload(no_uv_checker)
|
2020-09-02 23:04:21 +08:00
|
|
|
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)
|
2020-10-10 17:00:31 +08:00
|
|
|
if "flatten_uv" in locals():
|
|
|
|
importlib.reload(flatten_uv)
|
|
|
|
from . import config, utils, bm_import_export, rail_uv, preferences, threedsmax_align, no_uv_checker, add_elements, add_floor, flatten_uv
|
2020-07-12 21:04:38 +08:00
|
|
|
|
|
|
|
# ============================================= menu system
|
|
|
|
|
2020-09-02 23:04:21 +08:00
|
|
|
class BALLANCE_MT_ThreeDViewerMenu(bpy.types.Menu):
|
2020-07-19 15:13:55 +08:00
|
|
|
"""Ballance related 3D operator"""
|
2020-09-02 23:04:21 +08:00
|
|
|
bl_idname = "BALLANCE_MT_ThreeDViewerMenu"
|
2020-07-12 21:04:38 +08:00
|
|
|
bl_label = "Ballance 3D"
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
|
|
|
|
2020-09-02 23:04:21 +08:00
|
|
|
layout.operator("ballance.super_align")
|
2020-07-12 21:04:38 +08:00
|
|
|
layout.operator("ballance.rail_uv")
|
2020-08-31 21:56:08 +08:00
|
|
|
layout.operator("ballance.no_uv_checker")
|
2020-10-10 17:00:31 +08:00
|
|
|
layout.operator("ballance.flatten_uv")
|
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:
|
|
|
|
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,
|
2020-10-06 23:57:21 +08:00
|
|
|
preferences.MyPropertyGroup,
|
2020-09-02 23:04:21 +08:00
|
|
|
|
|
|
|
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,
|
2020-10-10 17:00:31 +08:00
|
|
|
flatten_uv.BALLANCE_OT_flatten_uv,
|
2020-09-02 23:04:21 +08:00
|
|
|
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
|
2020-09-02 23:04:21 +08:00
|
|
|
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")
|
2020-10-06 12:57:25 +08:00
|
|
|
layout.operator("ballance.add_rail", icon='MESH_CIRCLE', 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)
|
2020-10-06 23:57:21 +08:00
|
|
|
|
|
|
|
bpy.types.Scene.BallanceBlenderPluginProperty = bpy.props.PointerProperty(type=preferences.MyPropertyGroup)
|
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
|
|
|
|
|
|
|
bpy.types.VIEW3D_HT_header.append(menu_func_ballance_3d)
|
2020-09-02 23:04:21 +08:00
|
|
|
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)
|
2020-09-02 23:04:21 +08:00
|
|
|
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()
|