adding add_floor function WIP

This commit is contained in:
yyc12345 2020-10-05 22:30:06 +08:00
parent c5fc214384
commit da722fe4bb
18 changed files with 425 additions and 3 deletions

View File

@ -13,6 +13,8 @@ bl_info={
# ============================================= import system # ============================================= import system
import bpy,bpy_extras import bpy,bpy_extras
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
@ -32,7 +34,9 @@ if "bpy" in locals():
importlib.reload(no_uv_checker) importlib.reload(no_uv_checker)
if "add_elements" in locals(): if "add_elements" in locals():
importlib.reload(add_elements) 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 # ============================================= menu system
@ -48,6 +52,27 @@ class BALLANCE_MT_ThreeDViewerMenu(bpy.types.Menu):
layout.operator("ballance.rail_uv") layout.operator("ballance.rail_uv")
layout.operator("ballance.no_uv_checker") 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 # ============================================= blender call system
classes = ( classes = (
@ -61,7 +86,9 @@ classes = (
BALLANCE_MT_ThreeDViewerMenu, BALLANCE_MT_ThreeDViewerMenu,
add_elements.BALLANCE_OT_add_elements, 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): def menu_func_bm_import(self, context):
@ -77,8 +104,17 @@ def menu_func_ballance_add(self, context):
layout.label(text="Ballance") layout.label(text="Ballance")
layout.operator_menu_enum("ballance.add_elements", "elements_type", icon='MESH_ICOSPHERE', text="Elements") 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.operator("ballance.add_rail", icon='MESH_CUBE', text="Rail section")
layout.menu(BALLANCE_MT_AddFloorMenu.bl_idname, icon='MESH_CUBE')
def register(): 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: for cls in classes:
bpy.utils.register_class(cls) bpy.utils.register_class(cls)
@ -98,5 +134,8 @@ def unregister():
for cls in classes: for cls in classes:
bpy.utils.unregister_class(cls) bpy.utils.unregister_class(cls)
# we need uninstall all icon after all classes unregister
bpy.utils.previews.remove(config.blenderIcon_floor)
if __name__=="__main__": if __name__=="__main__":
register() register()

View File

@ -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="")

View File

@ -1,3 +1,6 @@
import json
import os
external_texture_list = set([ external_texture_list = set([
"atari.avi", "atari.avi",
"atari.bmp", "atari.bmp",
@ -111,3 +114,20 @@ component_list = [
"PR_Resetpoint", "PR_Resetpoint",
"PS_FourFlames" "PS_FourFlames"
] ]
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 = {}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -0,0 +1,3 @@
[
]

View File

@ -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"
}
]
}
}
]