finish add elements

This commit is contained in:
yyc12345 2020-09-03 13:57:06 +08:00
parent 08eb6dcff9
commit 79a04f1496
4 changed files with 36 additions and 68 deletions

View File

@ -60,8 +60,7 @@ classes = (
no_uv_checker.BALLANCE_OT_no_uv_checker, no_uv_checker.BALLANCE_OT_no_uv_checker,
BALLANCE_MT_ThreeDViewerMenu, BALLANCE_MT_ThreeDViewerMenu,
add_elements.BALLANCE_OT_add_sector_related_elements, add_elements.BALLANCE_OT_add_elements,
add_elements.BALLANCE_OT_add_unique_elements,
add_elements.BALLANCE_OT_add_rail add_elements.BALLANCE_OT_add_rail
) )
@ -76,8 +75,7 @@ def menu_func_ballance_add(self, context):
layout = self.layout layout = self.layout
layout.separator() layout.separator()
layout.label(text="Ballance") layout.label(text="Ballance")
layout.operator_menu_enum("ballance.add_sector_related_elements", "elements_type", icon='MESH_ICOSPHERE', text="Normal elements") layout.operator_menu_enum("ballance.add_elements", "elements_type", icon='MESH_ICOSPHERE', text="Elements")
layout.operator_menu_enum("ballance.add_unique_elements", "elements_type", icon='MESH_ICOSPHERE', text="Unique elements")
layout.operator("ballance.add_rail", icon='MESH_CUBE', text="Rail section") layout.operator("ballance.add_rail", icon='MESH_CUBE', text="Rail section")
def register(): def register():

View File

@ -1,53 +1,23 @@
import bpy,mathutils import bpy,mathutils
from . import utils from . import utils, config, bm_import_export
sectorRelatedElements = [
"P_Extra_Life",
"P_Extra_Point",
"P_Trafo_Paper",
"P_Trafo_Stone",
"P_Trafo_Wood",
"P_Ball_Paper",
"P_Ball_Stone",
"P_Ball_Wood",
"P_Box",
"P_Dome",
"P_Modul_01",
"P_Modul_03",
"P_Modul_08",
"P_Modul_17",
"P_Modul_18",
"P_Modul_19",
"P_Modul_25",
"P_Modul_26",
"P_Modul_29",
"P_Modul_30",
"P_Modul_34",
"P_Modul_37",
"P_Modul_41",
"PR_Resetpoint",
"PC_TwoFlames"
]
uniqueElements = [
"PE_Balloon",
"PS_FourFlames"
]
# ================================================= actual add # ================================================= actual add
class BALLANCE_OT_add_sector_related_elements(bpy.types.Operator): class BALLANCE_OT_add_elements(bpy.types.Operator):
"""Add sector related elements""" """Add sector related elements"""
bl_idname = "ballance.add_sector_related_elements" bl_idname = "ballance.add_elements"
bl_label = "Add normal elements" bl_label = "Add elements"
bl_options = {'UNDO'} bl_options = {'UNDO'}
elements_type: bpy.props.EnumProperty( elements_type: bpy.props.EnumProperty(
name="Type", name="Type",
description="This element type", description="This element type",
items=tuple(map(lambda x: (x, x, ""), sectorRelatedElements)), items=tuple(map(lambda x: (x, x, ""), config.component_list)),
) )
attentionElements = ["PC_TwoFlames", "PR_Resetpoint"]
uniqueElements = ["PS_FourFlames", "PE_Balloon"]
elements_sector: bpy.props.IntProperty( elements_sector: bpy.props.IntProperty(
name="Sector", name="Sector",
description="Define which sector the object will be grouped in", description="Define which sector the object will be grouped in",
@ -57,6 +27,17 @@ class BALLANCE_OT_add_sector_related_elements(bpy.types.Operator):
) )
def execute(self, context): def execute(self, context):
# get name
if self.elements_type in self.uniqueElements:
finalObjectName = self.elements_type + "_01"
else:
finalObjectName = self.elements_type + "_0" + str(self.elements_sector) + "_"
# create object
loadedMesh = bm_import_export.load_component(config.component_list.index(self.elements_type))
obj = bpy.data.objects.new(finalObjectName, loadedMesh)
addSceneAndChangePos(obj)
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event): def invoke(self, context, event):
@ -66,30 +47,10 @@ class BALLANCE_OT_add_sector_related_elements(bpy.types.Operator):
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
layout.prop(self, "elements_type") layout.prop(self, "elements_type")
layout.prop(self, "elements_sector") if self.elements_type not in self.uniqueElements:
layout.prop(self, "elements_sector")
class BALLANCE_OT_add_unique_elements(bpy.types.Operator): if self.elements_type in self.attentionElements:
"""Add unique elements""" layout.label(text="Please note that sector is suffix.")
bl_idname = "ballance.add_unique_elements"
bl_label = "Add unique elements"
bl_options = {'UNDO'}
elements_type: bpy.props.EnumProperty(
name="Type",
description="This element type",
items=tuple(map(lambda x: (x, x, ""), uniqueElements)),
)
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
layout.prop(self, "elements_type")
class BALLANCE_OT_add_rail(bpy.types.Operator): class BALLANCE_OT_add_rail(bpy.types.Operator):
"""Add rail""" """Add rail"""
@ -128,4 +89,11 @@ class BALLANCE_OT_add_rail(bpy.types.Operator):
layout = self.layout layout = self.layout
layout.prop(self, "rail_type") layout.prop(self, "rail_type")
layout.prop(self, "rail_radius") layout.prop(self, "rail_radius")
layout.prop(self, "rail_span") layout.prop(self, "rail_span")
def addSceneAndChangePos(obj):
obj.matrix_world = bpy.context.scene.cursor.matrix
view_layer = bpy.context.view_layer
collection = view_layer.active_layer_collection.collection
collection.objects.link(obj)

View File

@ -622,6 +622,7 @@ class info_block_helper():
self.offset = offset self.offset = offset
self.blenderData = None self.blenderData = None
# NOTE: this function also used by add_elements.py
def load_component(component_id): def load_component(component_id):
# get file first # get file first
compName = config.component_list[component_id] compName = config.component_list[component_id]

View File

@ -1,8 +1,9 @@
import bpy import bpy
from bpy_extras.io_utils import unpack_list
def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'): def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):
def draw(self, context): def draw(self, context):
self.layout.label(text=message) self.layout.label(text=message)
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon) bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)