[feat] promote experience about floor creation.
- change bl_options and rewrite invoke and draw functions to let floor creating window become more visual. credit: BLumia. - also change 3ds max align and flatten uv presentation after changing creating floor window. - seperate icon loader/unload module.
This commit is contained in:
parent
ef459a210d
commit
9b9fc9cde8
@ -5,7 +5,7 @@ class BALLANCE_OT_super_align(bpy.types.Operator):
|
|||||||
"""Align object with 3ds Max style"""
|
"""Align object with 3ds Max style"""
|
||||||
bl_idname = "ballance.super_align"
|
bl_idname = "ballance.super_align"
|
||||||
bl_label = "3ds Max Align"
|
bl_label = "3ds Max Align"
|
||||||
bl_options = {'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
align_x: bpy.props.BoolProperty(name="X position")
|
align_x: bpy.props.BoolProperty(name="X position")
|
||||||
align_y: bpy.props.BoolProperty(name="Y position")
|
align_y: bpy.props.BoolProperty(name="Y position")
|
||||||
@ -18,7 +18,8 @@ class BALLANCE_OT_super_align(bpy.types.Operator):
|
|||||||
('POINT', "Center (axis)", ""),
|
('POINT', "Center (axis)", ""),
|
||||||
('MAX', "Max", "")
|
('MAX', "Max", "")
|
||||||
),
|
),
|
||||||
)
|
default='POINT',
|
||||||
|
)
|
||||||
|
|
||||||
target_references: bpy.props.EnumProperty(
|
target_references: bpy.props.EnumProperty(
|
||||||
name="Target (Other Objects)",
|
name="Target (Other Objects)",
|
||||||
@ -27,7 +28,8 @@ class BALLANCE_OT_super_align(bpy.types.Operator):
|
|||||||
('POINT', "Center (axis)", ""),
|
('POINT', "Center (axis)", ""),
|
||||||
('MAX', "Max", "")
|
('MAX', "Max", "")
|
||||||
),
|
),
|
||||||
)
|
default='POINT',
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(self, context):
|
def poll(self, context):
|
||||||
@ -37,9 +39,11 @@ class BALLANCE_OT_super_align(bpy.types.Operator):
|
|||||||
_align_object(self.align_x, self.align_y, self.align_z, self.current_references, self.target_references)
|
_align_object(self.align_x, self.align_y, self.align_z, self.current_references, self.target_references)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
"""
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
wm = context.window_manager
|
wm = context.window_manager
|
||||||
return wm.invoke_props_dialog(self)
|
return wm.invoke_props_dialog(self)
|
||||||
|
"""
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
|
@ -6,7 +6,7 @@ class BALLANCE_OT_flatten_uv(bpy.types.Operator):
|
|||||||
"""Flatten selected face UV. Only works for convex face"""
|
"""Flatten selected face UV. Only works for convex face"""
|
||||||
bl_idname = "ballance.flatten_uv"
|
bl_idname = "ballance.flatten_uv"
|
||||||
bl_label = "Flatten UV"
|
bl_label = "Flatten UV"
|
||||||
bl_options = {'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
reference_edge : bpy.props.IntProperty(
|
reference_edge : bpy.props.IntProperty(
|
||||||
name="Reference edge",
|
name="Reference edge",
|
||||||
@ -20,7 +20,7 @@ class BALLANCE_OT_flatten_uv(bpy.types.Operator):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def poll(self, context):
|
def poll(self, context):
|
||||||
obj = bpy.context.active_object
|
obj = bpy.context.active_object
|
||||||
if obj == None:
|
if obj is None:
|
||||||
return False
|
return False
|
||||||
if obj.type != 'MESH':
|
if obj.type != 'MESH':
|
||||||
return False
|
return False
|
||||||
@ -28,17 +28,16 @@ class BALLANCE_OT_flatten_uv(bpy.types.Operator):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
"""
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
wm = context.window_manager
|
wm = context.window_manager
|
||||||
return wm.invoke_props_dialog(self)
|
return wm.invoke_props_dialog(self)
|
||||||
|
"""
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
no_processed_count = _real_flatten_uv(bpy.context.active_object.data, self.reference_edge)
|
no_processed_count = _real_flatten_uv(bpy.context.active_object.data, self.reference_edge)
|
||||||
if no_processed_count != 0:
|
if no_processed_count != 0:
|
||||||
UTILS_functions.show_message_box(
|
print("[Flatten UV] {} faces may not be processed correctly because they have problem.".format(no_processed_count))
|
||||||
("{} faces may not be processed correctly because they have problem.".format(no_processed_count), ),
|
|
||||||
"Warning", 'ERROR'
|
|
||||||
)
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
|
@ -4,18 +4,28 @@ import ast
|
|||||||
from bpy_extras import io_utils,node_shader_utils
|
from bpy_extras import io_utils,node_shader_utils
|
||||||
# from bpy_extras.io_utils import unpack_list
|
# from bpy_extras.io_utils import unpack_list
|
||||||
from bpy_extras.image_utils import load_image
|
from bpy_extras.image_utils import load_image
|
||||||
from . import UTILS_constants, UTILS_functions, UTILS_safe_eval
|
from . import UTILS_constants, UTILS_functions, UTILS_safe_eval, UTILS_icons_manager
|
||||||
|
|
||||||
class BALLANCE_OT_add_floors(bpy.types.Operator):
|
class BALLANCE_OT_add_floors(bpy.types.Operator):
|
||||||
"""Add Ballance floor"""
|
"""Add Ballance floor"""
|
||||||
bl_idname = "ballance.add_floors"
|
bl_idname = "ballance.add_floors"
|
||||||
bl_label = "Add floor"
|
bl_label = "Add floor"
|
||||||
bl_options = {'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
floor_type: bpy.props.EnumProperty(
|
floor_type: bpy.props.EnumProperty(
|
||||||
name="Type",
|
name="Type",
|
||||||
description="Floor type",
|
description="Floor type",
|
||||||
items=tuple((x, x, "") for x in UTILS_constants.floor_blockDict.keys()),
|
items=tuple(
|
||||||
|
# token, display name, descriptions
|
||||||
|
(blk, blk, "")
|
||||||
|
for blk in UTILS_constants.floor_blockDict.keys()
|
||||||
|
),
|
||||||
|
#items=tuple(
|
||||||
|
# # token, display name, descriptions, icon, index
|
||||||
|
# (blk, blk, "", UTILS_icons_manager.get_floor_icon(blk), idx)
|
||||||
|
# for idx, blk in enumerate(UTILS_constants.floor_blockDict.keys())
|
||||||
|
#),
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
expand_length_1 : bpy.props.IntProperty(
|
expand_length_1 : bpy.props.IntProperty(
|
||||||
@ -40,22 +50,28 @@ class BALLANCE_OT_add_floors(bpy.types.Operator):
|
|||||||
)
|
)
|
||||||
|
|
||||||
use_2d_top : bpy.props.BoolProperty(
|
use_2d_top : bpy.props.BoolProperty(
|
||||||
name="Top edge"
|
name="Top edge",
|
||||||
|
default=True
|
||||||
)
|
)
|
||||||
use_2d_right : bpy.props.BoolProperty(
|
use_2d_right : bpy.props.BoolProperty(
|
||||||
name="Right edge"
|
name="Right edge",
|
||||||
|
default=False
|
||||||
)
|
)
|
||||||
use_2d_bottom : bpy.props.BoolProperty(
|
use_2d_bottom : bpy.props.BoolProperty(
|
||||||
name="Bottom edge"
|
name="Bottom edge",
|
||||||
|
default=True
|
||||||
)
|
)
|
||||||
use_2d_left : bpy.props.BoolProperty(
|
use_2d_left : bpy.props.BoolProperty(
|
||||||
name="Left edge"
|
name="Left edge",
|
||||||
|
default=True
|
||||||
)
|
)
|
||||||
use_3d_top : bpy.props.BoolProperty(
|
use_3d_top : bpy.props.BoolProperty(
|
||||||
name="Top face"
|
name="Top face",
|
||||||
|
default=True
|
||||||
)
|
)
|
||||||
use_3d_bottom : bpy.props.BoolProperty(
|
use_3d_bottom : bpy.props.BoolProperty(
|
||||||
name="Bottom face"
|
name="Bottom face",
|
||||||
|
default=True
|
||||||
)
|
)
|
||||||
|
|
||||||
previous_floor_type = ''
|
previous_floor_type = ''
|
||||||
@ -114,11 +130,13 @@ class BALLANCE_OT_add_floors(bpy.types.Operator):
|
|||||||
UTILS_functions.add_into_scene_and_move_to_cursor(obj)
|
UTILS_functions.add_into_scene_and_move_to_cursor(obj)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
wm = context.window_manager
|
# yyc marked. Blumia reported.
|
||||||
return wm.invoke_props_dialog(self)
|
# prepare settings before registing
|
||||||
|
# otherwise the mesh will not be created when first run.
|
||||||
|
# (do not change any properties)
|
||||||
|
|
||||||
def draw(self, context):
|
|
||||||
# get floor prototype
|
# get floor prototype
|
||||||
floor_prototype = UTILS_constants.floor_blockDict[self.floor_type]
|
floor_prototype = UTILS_constants.floor_blockDict[self.floor_type]
|
||||||
|
|
||||||
@ -134,6 +152,13 @@ class BALLANCE_OT_add_floors(bpy.types.Operator):
|
|||||||
self.use_3d_top = default_sides['UseThreeDTop']
|
self.use_3d_top = default_sides['UseThreeDTop']
|
||||||
self.use_3d_bottom = default_sides['UseThreeDBottom']
|
self.use_3d_bottom = default_sides['UseThreeDBottom']
|
||||||
|
|
||||||
|
return self.execute(context)
|
||||||
|
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
# get floor prototype
|
||||||
|
floor_prototype = UTILS_constants.floor_blockDict[self.floor_type]
|
||||||
|
|
||||||
# show property
|
# show property
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
col = layout.column()
|
col = layout.column()
|
||||||
@ -154,7 +179,7 @@ class BALLANCE_OT_add_floors(bpy.types.Operator):
|
|||||||
grids.label(text=UTILS_constants.floor_expandDirectionMap[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][0])
|
grids.label(text=UTILS_constants.floor_expandDirectionMap[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][0])
|
||||||
grids.separator()
|
grids.separator()
|
||||||
grids.label(text=UTILS_constants.floor_expandDirectionMap[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][3])
|
grids.label(text=UTILS_constants.floor_expandDirectionMap[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][3])
|
||||||
grids.template_icon(icon_value = UTILS_constants.icons_floorDict[self.floor_type])
|
grids.template_icon(icon_value = UTILS_icons_manager.get_floor_icon(self.floor_type))
|
||||||
grids.label(text=UTILS_constants.floor_expandDirectionMap[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][1])
|
grids.label(text=UTILS_constants.floor_expandDirectionMap[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][1])
|
||||||
grids.separator()
|
grids.separator()
|
||||||
grids.label(text=UTILS_constants.floor_expandDirectionMap[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][2])
|
grids.label(text=UTILS_constants.floor_expandDirectionMap[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][2])
|
||||||
@ -173,7 +198,7 @@ class BALLANCE_OT_add_floors(bpy.types.Operator):
|
|||||||
grids.prop(self, "use_2d_top")
|
grids.prop(self, "use_2d_top")
|
||||||
grids.separator()
|
grids.separator()
|
||||||
grids.prop(self, "use_2d_left")
|
grids.prop(self, "use_2d_left")
|
||||||
grids.template_icon(icon_value = UTILS_constants.icons_floorDict[self.floor_type])
|
grids.template_icon(icon_value = UTILS_icons_manager.get_floor_icon(self.floor_type))
|
||||||
grids.prop(self, "use_2d_right")
|
grids.prop(self, "use_2d_right")
|
||||||
grids.separator()
|
grids.separator()
|
||||||
grids.prop(self, "use_2d_bottom")
|
grids.prop(self, "use_2d_bottom")
|
||||||
|
@ -290,11 +290,6 @@ for walk_root, walk_dirs, walk_files in os.walk(os.path.join(os.path.dirname(__f
|
|||||||
floor_derivedBlockList.append(item["Type"])
|
floor_derivedBlockList.append(item["Type"])
|
||||||
floor_blockDict[item["Type"]] = item
|
floor_blockDict[item["Type"]] = item
|
||||||
|
|
||||||
icons_floor = None
|
|
||||||
icons_floorDict = {}
|
|
||||||
# blenderIcon_elements = None
|
|
||||||
# blenderIcon_elements_dict = {}
|
|
||||||
|
|
||||||
rename_normalComponentsGroupName = set([
|
rename_normalComponentsGroupName = set([
|
||||||
"P_Extra_Life",
|
"P_Extra_Life",
|
||||||
"P_Extra_Point",
|
"P_Extra_Point",
|
||||||
|
30
ballance_blender_plugin/UTILS_icons_manager.py
Normal file
30
ballance_blender_plugin/UTILS_icons_manager.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import bpy
|
||||||
|
import bpy.utils.previews
|
||||||
|
import os
|
||||||
|
from . import UTILS_constants
|
||||||
|
|
||||||
|
# ImagePreviewCollection ccreated by Blender
|
||||||
|
floor_icons = None
|
||||||
|
# a map. key is block name, value is loaded icon id
|
||||||
|
floor_icons_map: dict = {}
|
||||||
|
|
||||||
|
def register_icons():
|
||||||
|
global floor_icons, floor_icons_map
|
||||||
|
|
||||||
|
icon_path = os.path.join(os.path.dirname(__file__), "icons")
|
||||||
|
floor_icons = bpy.utils.previews.new()
|
||||||
|
for key, value in UTILS_constants.floor_blockDict.items():
|
||||||
|
blockIconName = "Ballance_FloorIcon_" + key
|
||||||
|
floor_icons.load(blockIconName, os.path.join(icon_path, "floor", value["BindingDisplayTexture"]), 'IMAGE')
|
||||||
|
floor_icons_map[key] = floor_icons[blockIconName].icon_id
|
||||||
|
|
||||||
|
def unregister_icons():
|
||||||
|
global floor_icons, floor_icons_map
|
||||||
|
|
||||||
|
bpy.utils.previews.remove(floor_icons)
|
||||||
|
floor_icons_map.clear()
|
||||||
|
|
||||||
|
def get_floor_icon(floor_blk_name: str):
|
||||||
|
global floor_icons_map
|
||||||
|
|
||||||
|
return floor_icons_map[floor_blk_name]
|
@ -13,9 +13,8 @@ bl_info={
|
|||||||
|
|
||||||
# =============================================
|
# =============================================
|
||||||
# import system
|
# import system
|
||||||
import bpy, bpy_extras
|
import bpy
|
||||||
import bpy.utils.previews
|
|
||||||
import os
|
|
||||||
# import my code (with reload)
|
# import my code (with reload)
|
||||||
if "bpy" in locals():
|
if "bpy" in locals():
|
||||||
import importlib
|
import importlib
|
||||||
@ -33,6 +32,8 @@ if "bpy" in locals():
|
|||||||
importlib.reload(UTILS_virtools_prop)
|
importlib.reload(UTILS_virtools_prop)
|
||||||
if "UTILS_safe_eval" in locals():
|
if "UTILS_safe_eval" in locals():
|
||||||
importlib.reload(UTILS_safe_eval)
|
importlib.reload(UTILS_safe_eval)
|
||||||
|
if "UTILS_icons_manager" in locals():
|
||||||
|
importlib.reload(UTILS_icons_manager)
|
||||||
|
|
||||||
if "BMFILE_export" in locals():
|
if "BMFILE_export" in locals():
|
||||||
importlib.reload(BMFILE_export)
|
importlib.reload(BMFILE_export)
|
||||||
@ -63,7 +64,7 @@ if "bpy" in locals():
|
|||||||
if "PROPS_virtools_material" in locals():
|
if "PROPS_virtools_material" in locals():
|
||||||
importlib.reload(PROPS_virtools_material)
|
importlib.reload(PROPS_virtools_material)
|
||||||
|
|
||||||
from . import UTILS_constants, UTILS_functions, UTILS_preferences, UTILS_virtools_prop, UTILS_safe_eval
|
from . import UTILS_constants, UTILS_functions, UTILS_preferences, UTILS_virtools_prop, UTILS_safe_eval, UTILS_icons_manager
|
||||||
from . import BMFILE_export, BMFILE_import
|
from . import BMFILE_export, BMFILE_import
|
||||||
from . import MODS_3dsmax_align, MODS_flatten_uv, MODS_rail_uv
|
from . import MODS_3dsmax_align, MODS_flatten_uv, MODS_rail_uv
|
||||||
from . import OBJS_add_components, OBJS_add_floors, OBJS_add_rails, OBJS_group_opers
|
from . import OBJS_add_components, OBJS_add_floors, OBJS_add_rails, OBJS_group_opers
|
||||||
@ -97,7 +98,7 @@ class BALLANCE_MT_AddFloorMenu(bpy.types.Menu):
|
|||||||
for item in UTILS_constants.floor_basicBlockList:
|
for item in UTILS_constants.floor_basicBlockList:
|
||||||
cop = layout.operator(
|
cop = layout.operator(
|
||||||
OBJS_add_floors.BALLANCE_OT_add_floors.bl_idname,
|
OBJS_add_floors.BALLANCE_OT_add_floors.bl_idname,
|
||||||
text=item, icon_value = UTILS_constants.icons_floorDict[item])
|
text=item, icon_value = UTILS_icons_manager.get_floor_icon(item))
|
||||||
cop.floor_type = item
|
cop.floor_type = item
|
||||||
|
|
||||||
layout.separator()
|
layout.separator()
|
||||||
@ -105,7 +106,7 @@ class BALLANCE_MT_AddFloorMenu(bpy.types.Menu):
|
|||||||
for item in UTILS_constants.floor_derivedBlockList:
|
for item in UTILS_constants.floor_derivedBlockList:
|
||||||
cop = layout.operator(
|
cop = layout.operator(
|
||||||
OBJS_add_floors.BALLANCE_OT_add_floors.bl_idname,
|
OBJS_add_floors.BALLANCE_OT_add_floors.bl_idname,
|
||||||
text=item, icon_value = UTILS_constants.icons_floorDict[item])
|
text=item, icon_value = UTILS_icons_manager.get_floor_icon(item))
|
||||||
cop.floor_type = item
|
cop.floor_type = item
|
||||||
|
|
||||||
class BALLANCE_MT_AddRailMenu(bpy.types.Menu):
|
class BALLANCE_MT_AddRailMenu(bpy.types.Menu):
|
||||||
@ -208,12 +209,7 @@ def menu_func_ballance_grouping(self, context):
|
|||||||
|
|
||||||
def register():
|
def register():
|
||||||
# we need init all icon first
|
# we need init all icon first
|
||||||
icon_path = os.path.join(os.path.dirname(__file__), "icons")
|
UTILS_icons_manager.register_icons()
|
||||||
UTILS_constants.icons_floor = bpy.utils.previews.new()
|
|
||||||
for key, value in UTILS_constants.floor_blockDict.items():
|
|
||||||
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
|
|
||||||
|
|
||||||
for cls in classes:
|
for cls in classes:
|
||||||
bpy.utils.register_class(cls)
|
bpy.utils.register_class(cls)
|
||||||
@ -254,7 +250,7 @@ def unregister():
|
|||||||
bpy.utils.unregister_class(cls)
|
bpy.utils.unregister_class(cls)
|
||||||
|
|
||||||
# we need uninstall all icon after all classes unregister
|
# we need uninstall all icon after all classes unregister
|
||||||
bpy.utils.previews.remove(UTILS_constants.icons_floor)
|
UTILS_icons_manager.unregister_icons()
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
register()
|
register()
|
Loading…
Reference in New Issue
Block a user