diff --git a/ballance_blender_plugin/__init__.py b/ballance_blender_plugin/__init__.py index c488563..f5de843 100644 --- a/ballance_blender_plugin/__init__.py +++ b/ballance_blender_plugin/__init__.py @@ -13,6 +13,8 @@ bl_info={ # ============================================= import system import bpy,bpy_extras +import bpy.utils.previews +import os # import my code (with reload) if "bpy" in locals(): import importlib @@ -32,7 +34,9 @@ if "bpy" in locals(): importlib.reload(no_uv_checker) if "add_elements" in locals(): importlib.reload(add_elements) -from . import config, utils, bm_import_export, rail_uv, preferences, threedsmax_align, no_uv_checker, add_elements + 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 # ============================================= menu system @@ -48,6 +52,27 @@ class BALLANCE_MT_ThreeDViewerMenu(bpy.types.Menu): layout.operator("ballance.rail_uv") layout.operator("ballance.no_uv_checker") +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 + + # ============================================= blender call system classes = ( @@ -61,7 +86,9 @@ classes = ( BALLANCE_MT_ThreeDViewerMenu, add_elements.BALLANCE_OT_add_elements, - add_elements.BALLANCE_OT_add_rail + add_elements.BALLANCE_OT_add_rail, + add_floor.BALLANCE_OT_add_floor, + BALLANCE_MT_AddFloorMenu ) def menu_func_bm_import(self, context): @@ -77,8 +104,17 @@ def menu_func_ballance_add(self, context): layout.label(text="Ballance") 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") + layout.menu(BALLANCE_MT_AddFloorMenu.bl_idname, icon='MESH_CUBE') def register(): + # 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 + for cls in classes: bpy.utils.register_class(cls) @@ -97,6 +133,9 @@ def unregister(): for cls in classes: bpy.utils.unregister_class(cls) + + # we need uninstall all icon after all classes unregister + bpy.utils.previews.remove(config.blenderIcon_floor) if __name__=="__main__": register() \ No newline at end of file diff --git a/ballance_blender_plugin/add_floor.py b/ballance_blender_plugin/add_floor.py new file mode 100644 index 0000000..3240b7f --- /dev/null +++ b/ballance_blender_plugin/add_floor.py @@ -0,0 +1,104 @@ +import bpy,mathutils +from . import utils, config + +class BALLANCE_OT_add_floor(bpy.types.Operator): + """Add Ballance floor""" + bl_idname = "ballance.add_floor" + bl_label = "Add floor" + bl_options = {'UNDO'} + + floor_type: bpy.props.EnumProperty( + name="Type", + description="Floor type", + items=tuple((x, x, "") for x in config.floor_block_dict.keys()), + ) + + expand_length_1 : bpy.props.IntProperty( + name="D1 length", + description="The length of expand direction 1", + default=0, + ) + + expand_length_2 : bpy.props.IntProperty( + name="D2 length", + description="The length of expand direction 2", + default=0, + ) + + height_multiplier : bpy.props.FloatProperty( + name="Height", + description="The multiplier for height. Default height is 5", + default=1.0, + ) + + rotation_inside_mesh: bpy.props.EnumProperty( + name="Rotation", + description="Rotation inside mesh", + items=( + ("R0", "0 degree", ""), + ("R90", "90 degree", ""), + ("R180", "180 degree", ""), + ("R270", "270 degree", "") + ), + default="R0" + ) + + use_2d_top : bpy.props.BoolProperty( + name="Top side" + ) + use_2d_right : bpy.props.BoolProperty( + name="Right side" + ) + use_2d_bottom : bpy.props.BoolProperty( + name="Bottom side" + ) + use_2d_left : bpy.props.BoolProperty( + name="Left side" + ) + use_3d_top : bpy.props.BoolProperty( + name="Top face" + ) + use_3d_bottom : bpy.props.BoolProperty( + name="Bottom face" + ) + + + def execute(self, context): + return {'FINISHED'} + + def invoke(self, context, event): + wm = context.window_manager + return wm.invoke_props_dialog(self) + + def draw(self, context): + layout = self.layout + col = layout.column() + col.label(text="Basic param") + col.prop(self, "floor_type") + col.prop(self, "expand_length_1") + col.prop(self, "expand_length_2") + col.prop(self, "height_multiplier") + col.prop(self, "rotation_inside_mesh") + + col.separator() + col.label(text="Faces") + row = col.row() + row.prop(self, "use_3d_top") + row.prop(self, "use_3d_bottom") + + col.separator() + col.label(text="Sides") + row = col.row(align=True) + row.label(text="") + row.prop(self, "use_2d_top") + row.label(text="") + row = col.row(align=True) + row.prop(self, "use_2d_left") + row.template_icon(icon_value = config.blenderIcon_floor_dict[self.floor_type]) + row.prop(self, "use_2d_right") + row = col.row(align=True) + row.label(text="") + row.prop(self, "use_2d_bottom") + row.label(text="") + + diff --git a/ballance_blender_plugin/config.py b/ballance_blender_plugin/config.py index 7e6dec7..b5944d6 100644 --- a/ballance_blender_plugin/config.py +++ b/ballance_blender_plugin/config.py @@ -1,3 +1,6 @@ +import json +import os + external_texture_list = set([ "atari.avi", "atari.bmp", @@ -110,4 +113,21 @@ component_list = [ "PE_Balloon", "PR_Resetpoint", "PS_FourFlames" -] \ No newline at end of file +] + +floor_block_dict = {} +floor_basic_block_list = [] +floor_derived_block_list = [] +with open(os.path.join(os.path.dirname(__file__), "json", "VanillaBlock.json")) as fp: + for item in json.load(fp): + floor_basic_block_list.append(item["Type"]) + floor_block_dict[item["Type"]] = item +with open(os.path.join(os.path.dirname(__file__), "json", "DerivedBlock.json")) as fp: + for item in json.load(fp): + floor_derived_block_list.append(item["Type"]) + floor_block_dict[item["Type"]] = item + +blenderIcon_floor = None +blenderIcon_floor_dict = {} +# blenderIcon_elements = None +# blenderIcon_elements_dict = {} \ No newline at end of file diff --git a/ballance_blender_plugin/icons/floor/Flat.png b/ballance_blender_plugin/icons/floor/Flat.png new file mode 100644 index 0000000..8d9ae46 Binary files /dev/null and b/ballance_blender_plugin/icons/floor/Flat.png differ diff --git a/ballance_blender_plugin/icons/floor/NormalBorder.png b/ballance_blender_plugin/icons/floor/NormalBorder.png new file mode 100644 index 0000000..667f0e4 Binary files /dev/null and b/ballance_blender_plugin/icons/floor/NormalBorder.png differ diff --git a/ballance_blender_plugin/icons/floor/NormalFloor.png b/ballance_blender_plugin/icons/floor/NormalFloor.png new file mode 100644 index 0000000..97a3871 Binary files /dev/null and b/ballance_blender_plugin/icons/floor/NormalFloor.png differ diff --git a/ballance_blender_plugin/icons/floor/NormalInnerCorner.png b/ballance_blender_plugin/icons/floor/NormalInnerCorner.png new file mode 100644 index 0000000..708af0c Binary files /dev/null and b/ballance_blender_plugin/icons/floor/NormalInnerCorner.png differ diff --git a/ballance_blender_plugin/icons/floor/NormalOutterCorner.png b/ballance_blender_plugin/icons/floor/NormalOutterCorner.png new file mode 100644 index 0000000..8012a25 Binary files /dev/null and b/ballance_blender_plugin/icons/floor/NormalOutterCorner.png differ diff --git a/ballance_blender_plugin/icons/floor/NormalSinkTransition.png b/ballance_blender_plugin/icons/floor/NormalSinkTransition.png new file mode 100644 index 0000000..fe0ccff Binary files /dev/null and b/ballance_blender_plugin/icons/floor/NormalSinkTransition.png differ diff --git a/ballance_blender_plugin/icons/floor/PaperTrafo.png b/ballance_blender_plugin/icons/floor/PaperTrafo.png new file mode 100644 index 0000000..09d934a Binary files /dev/null and b/ballance_blender_plugin/icons/floor/PaperTrafo.png differ diff --git a/ballance_blender_plugin/icons/floor/SinkBorder.png b/ballance_blender_plugin/icons/floor/SinkBorder.png new file mode 100644 index 0000000..def105c Binary files /dev/null and b/ballance_blender_plugin/icons/floor/SinkBorder.png differ diff --git a/ballance_blender_plugin/icons/floor/SinkFloor.png b/ballance_blender_plugin/icons/floor/SinkFloor.png new file mode 100644 index 0000000..cd61521 Binary files /dev/null and b/ballance_blender_plugin/icons/floor/SinkFloor.png differ diff --git a/ballance_blender_plugin/icons/floor/SinkInnerCorner.png b/ballance_blender_plugin/icons/floor/SinkInnerCorner.png new file mode 100644 index 0000000..602298b Binary files /dev/null and b/ballance_blender_plugin/icons/floor/SinkInnerCorner.png differ diff --git a/ballance_blender_plugin/icons/floor/SinkOutterCorner.png b/ballance_blender_plugin/icons/floor/SinkOutterCorner.png new file mode 100644 index 0000000..cdeb7a2 Binary files /dev/null and b/ballance_blender_plugin/icons/floor/SinkOutterCorner.png differ diff --git a/ballance_blender_plugin/icons/floor/StoneTrafo.png b/ballance_blender_plugin/icons/floor/StoneTrafo.png new file mode 100644 index 0000000..7fa817b Binary files /dev/null and b/ballance_blender_plugin/icons/floor/StoneTrafo.png differ diff --git a/ballance_blender_plugin/icons/floor/WoodTrafo.png b/ballance_blender_plugin/icons/floor/WoodTrafo.png new file mode 100644 index 0000000..77b9bec Binary files /dev/null and b/ballance_blender_plugin/icons/floor/WoodTrafo.png differ diff --git a/ballance_blender_plugin/json/DerivedBlock.json b/ballance_blender_plugin/json/DerivedBlock.json new file mode 100644 index 0000000..1610ea1 --- /dev/null +++ b/ballance_blender_plugin/json/DerivedBlock.json @@ -0,0 +1,3 @@ +[ + +] \ No newline at end of file diff --git a/ballance_blender_plugin/json/VanillaBlock.json b/ballance_blender_plugin/json/VanillaBlock.json new file mode 100644 index 0000000..90afcd1 --- /dev/null +++ b/ballance_blender_plugin/json/VanillaBlock.json @@ -0,0 +1,256 @@ +[ + { + "Type": "SinkBorder", + "BindingDisplayTexture": "SinkBorder.png", + "UnitSize": "Small", + "ExpandType": "Column", + "InitColumnDirection": "PositiveX", + "ThreeDTopFace": { + "Vertices": [ + "2.5,0,0;+d1;;", + "2.5,2.5,-0.7;+d1;;", + "0,2.5,-0.7", + "0,0,0" + ], + "UVs": [ + "0,0;;-d1", + "0.5,0;;-d1", + "0.5,0.5;;", + "0,0.5;;" + ], + "Faces": [ + { + "P1": 0, + "P2": 1, + "P3": 2, + "P4": 3, + "Textures": "FloorTopProfil" + } + ] + }, + "ThreeDBottomFace": { + "Vertices": [ + "2.5,0,-5;+d1;;-d3", + "2.5,2.5,-5;+d1;;-d3", + "0,2.5,-5;;;-d3", + "0,0,-5;;;-d3" + ], + "UVs": [ + "0,0.5;;", + "0.5,0.5;;", + "0.5,0;;-d1", + "0,0;;-d1" + ], + "Faces": [ + { + "P1": 3, + "P2": 2, + "P3": 1, + "P4": 0, + "Textures": "FloorTopBorderless" + } + ] + }, + "TwoDTopSide": { + "Vertices": [ + "0,0,0", + "0,0,-5;;;-d3", + "0,2.5,-5;;;-d3", + "0,2.5,-0.7" + ], + "UVs": [ + "0,0.5;;", + "1,0.5;+d3;", + "1,0;+d3;", + "0,0;;" + ], + "Faces": [ + { + "P1": 3, + "P2": 2, + "P3": 1, + "P4": 0, + "Textures": "FloorSide" + } + ] + }, + "TwoDRightSide": { + "Vertices": [ + "2.5,2.5,-0.7;+d1;;", + "2.5,2.5,-5;+d1;;-d3", + "0,2.5,-5;;;-d3", + "0,2.5,-0.7" + ], + "UVs": [ + "0.14,0;;-d1", + "1,0;+d3;-d1", + "1,0.5;+d3;", + "0.14,0.5;;" + ], + "Faces": [ + { + "P1": 0, + "P2": 1, + "P3": 2, + "P4": 3, + "Textures": "FloorTopBorderless" + } + ] + }, + "TwoDBottomSide": { + "Vertices": [ + "2.5,0,0;+d1;;", + "2.5,0,-5;+d1;;-d3", + "2.5,2.5,-5;+d1;;-d3", + "2.5,2.5,-0.7;+d1;;" + ], + "UVs": [ + "0,0;;", + "1,0;+d3;", + "1,0.5;+d3;", + "0,0.5;;" + ], + "Faces": [ + { + "P1": 0, + "P2": 1, + "P3": 2, + "P4": 3, + "Textures": "FloorSide" + } + ] + }, + "TwoDLeftSide": { + "Vertices": [ + "2.5,0,0;+d1;;", + "2.5,0,-5;+d1;;-d3", + "0,0,-5;;;-d3", + "0,0,0" + ], + "UVs": [ + "0,0.5;;", + "1,0.5;+d3;", + "1,0;+d3;-d1", + "0,0;;-d1" + ], + "Faces": [ + { + "P1": 3, + "P2": 2, + "P3": 1, + "P4": 0, + "Textures": "FloorSide" + } + ] + }, + "TwoDTopSideExpand": { + "Vertices": [ + "0,0,-5;;-d3", + "0,2.5,-5;;-d3", + "0,2.5,-2.5;;;", + "0,0,-2.5;;;", + "0,0,0;;;", + "0,2.5,-0.7;;;" + ], + "UVs": [ + "0.5,0.5;;", + "0.5,0;;", + "0,0;;", + "0,0.5;;", + "0,0;;", + "0,0.5;;", + "0.5,0.5;+d3;", + "0.5,0;+d3;" + ], + "Faces": [ + { + "P1": 2, + "P2": 3, + "P3": 4, + "P4": 5, + "Textures": "FloorSide" + }, + { + "P1": 3, + "P2": 2, + "P3": 1, + "P4": 0, + "Textures": "FloorTopBorderless" + } + ] + }, + "TwoDRightSideExpand": null, + "TwoDBottomSideExpand": { + "Vertices": [ + "2.5,0,-5;+d1;;-d3", + "2.5,2.5,-5;+d1;;-d3", + "2.5,2.5,-2.5;+d1;;", + "2.5,0,-2.5;+d1;;", + "2.5,0,0;+d1;;", + "2.5,2.5,-0.7;+d1;;" + ], + "UVs": [ + "0,0.5;;", + "0,0;;", + "0.5,0;;", + "0.5,0.5;;", + "0.5,0;+d3;", + "0.5,0.5;+d3;", + "0,0.5;;", + "0,0;;" + ], + "Faces": [ + { + "P1": 5, + "P2": 4, + "P3": 3, + "P4": 2, + "Textures": "FloorSide" + }, + { + "P1": 0, + "P2": 1, + "P3": 2, + "P4": 3, + "Textures": "FloorTopBorderless" + } + ] + }, + "TwoDLeftSideExpand": { + "Vertices": [ + "2.5,0,-5;+d1;;-d3", + "0,0,-5;;;-d3", + "0,0,-2.5;;;", + "2.5,0,-2.5;+d1;;", + "2.5,0,0;+d1;;", + "0,0,0;;;" + ], + "UVs": [ + "0.5,0.5;;", + "0.5,0;;-d1", + "0,0;;-d1", + "0,0.5;;", + "0,0;;-d1", + "0,0.5;;", + "0.5,0.5;+d3;", + "0.5,0;+d3;-d1" + ], + "Faces": [ + { + "P1": 2, + "P2": 3, + "P3": 4, + "P4": 5, + "Textures": "FloorSide" + }, + { + "P1": 3, + "P2": 2, + "P3": 1, + "P4": 0, + "Textures": "FloorTopBorderless" + } + ] + } + } +] \ No newline at end of file