BallanceBlenderHelper/ballance_blender_plugin/add_floor.py

146 lines
4.8 KiB
Python
Raw Normal View History

2020-10-05 22:30:06 +08:00
import bpy,mathutils
2020-10-06 12:57:25 +08:00
import os
2020-10-05 22:30:06 +08:00
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",
2020-10-06 12:57:25 +08:00
min=0,
2020-10-05 22:30:06 +08:00
default=0,
)
expand_length_2 : bpy.props.IntProperty(
name="D2 length",
description="The length of expand direction 2",
2020-10-06 12:57:25 +08:00
min=0,
2020-10-05 22:30:06 +08:00
default=0,
)
height_multiplier : bpy.props.FloatProperty(
name="Height",
description="The multiplier for height. Default height is 5",
2020-10-06 12:57:25 +08:00
min=0.0,
2020-10-05 22:30:06 +08:00
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"
)
2020-10-07 15:49:12 +08:00
previous_floor_type = ''
2020-10-06 12:57:25 +08:00
@classmethod
def poll(self, context):
prefs = bpy.context.preferences.addons[__package__].preferences
return os.path.isdir(prefs.external_folder)
2020-10-05 22:30:06 +08:00
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):
2020-10-07 15:49:12 +08:00
# get floor prototype
floor_prototype = config.floor_block_dict[self.floor_type]
# try sync default value
if self.previous_floor_type != self.floor_type:
self.previous_floor_type = self.floor_type
default_sides = floor_prototype['DefaultSideConfig']
self.use_2d_top = default_sides['UseTwoDTop']
self.use_2d_right = default_sides['UseTwoDRight']
self.use_2d_bottom = default_sides['UseTwoDBottom']
self.use_2d_left = default_sides['UseTwoDLeft']
self.use_3d_top = default_sides['UseThreeDTop']
self.use_3d_bottom = default_sides['UseThreeDBottom']
# show property
2020-10-05 22:30:06 +08:00
layout = self.layout
col = layout.column()
col.label(text="Basic param")
col.prop(self, "floor_type")
2020-10-06 12:57:25 +08:00
col.prop(self, "rotation_inside_mesh")
col.prop(self, "height_multiplier")
col.separator()
col.label(text="Expand")
2020-10-07 15:49:12 +08:00
if floor_prototype['ExpandType'] == 'Column' or floor_prototype['ExpandType'] == 'Freedom':
col.prop(self, "expand_length_1")
if floor_prototype['ExpandType'] == 'Freedom':
col.prop(self, "expand_length_2")
col.label(text="Unit size: " + floor_prototype['UnitSize'])
col.label(text="Expand mode: " + floor_prototype['ExpandType'])
grids = col.grid_flow(row_major=True, columns=3)
2020-10-06 12:57:25 +08:00
grids.separator()
2020-10-07 15:49:12 +08:00
grids.label(text=config.floor_expand_direction_map[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][0])
2020-10-06 12:57:25 +08:00
grids.separator()
2020-10-07 15:49:12 +08:00
grids.label(text=config.floor_expand_direction_map[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][3])
2020-10-06 12:57:25 +08:00
grids.template_icon(icon_value = config.blenderIcon_floor_dict[self.floor_type])
2020-10-07 15:49:12 +08:00
grids.label(text=config.floor_expand_direction_map[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][1])
2020-10-06 12:57:25 +08:00
grids.separator()
2020-10-07 15:49:12 +08:00
grids.label(text=config.floor_expand_direction_map[floor_prototype['InitColumnDirection']][floor_prototype['ExpandType']][2])
2020-10-06 12:57:25 +08:00
grids.separator()
2020-10-05 22:30:06 +08:00
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")
2020-10-07 15:49:12 +08:00
grids = col.grid_flow(row_major=True, columns=3)
2020-10-06 12:57:25 +08:00
grids.separator()
grids.prop(self, "use_2d_top")
grids.separator()
grids.prop(self, "use_2d_left")
grids.template_icon(icon_value = config.blenderIcon_floor_dict[self.floor_type])
grids.prop(self, "use_2d_right")
grids.separator()
grids.prop(self, "use_2d_bottom")
grids.separator()
2020-10-05 22:30:06 +08:00