finish add elements
This commit is contained in:
parent
08eb6dcff9
commit
79a04f1496
@ -60,8 +60,7 @@ classes = (
|
||||
no_uv_checker.BALLANCE_OT_no_uv_checker,
|
||||
BALLANCE_MT_ThreeDViewerMenu,
|
||||
|
||||
add_elements.BALLANCE_OT_add_sector_related_elements,
|
||||
add_elements.BALLANCE_OT_add_unique_elements,
|
||||
add_elements.BALLANCE_OT_add_elements,
|
||||
add_elements.BALLANCE_OT_add_rail
|
||||
)
|
||||
|
||||
@ -76,8 +75,7 @@ def menu_func_ballance_add(self, context):
|
||||
layout = self.layout
|
||||
layout.separator()
|
||||
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_unique_elements", "elements_type", icon='MESH_ICOSPHERE', text="Unique 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")
|
||||
|
||||
def register():
|
||||
|
@ -1,53 +1,23 @@
|
||||
import bpy,mathutils
|
||||
from . import utils
|
||||
|
||||
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"
|
||||
]
|
||||
from . import utils, config, bm_import_export
|
||||
|
||||
# ================================================= actual add
|
||||
|
||||
class BALLANCE_OT_add_sector_related_elements(bpy.types.Operator):
|
||||
class BALLANCE_OT_add_elements(bpy.types.Operator):
|
||||
"""Add sector related elements"""
|
||||
bl_idname = "ballance.add_sector_related_elements"
|
||||
bl_label = "Add normal elements"
|
||||
bl_idname = "ballance.add_elements"
|
||||
bl_label = "Add elements"
|
||||
bl_options = {'UNDO'}
|
||||
|
||||
elements_type: bpy.props.EnumProperty(
|
||||
name="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(
|
||||
name="Sector",
|
||||
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):
|
||||
# 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'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
@ -66,30 +47,10 @@ class BALLANCE_OT_add_sector_related_elements(bpy.types.Operator):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.prop(self, "elements_type")
|
||||
if self.elements_type not in self.uniqueElements:
|
||||
layout.prop(self, "elements_sector")
|
||||
|
||||
class BALLANCE_OT_add_unique_elements(bpy.types.Operator):
|
||||
"""Add unique elements"""
|
||||
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")
|
||||
if self.elements_type in self.attentionElements:
|
||||
layout.label(text="Please note that sector is suffix.")
|
||||
|
||||
class BALLANCE_OT_add_rail(bpy.types.Operator):
|
||||
"""Add rail"""
|
||||
@ -129,3 +90,10 @@ class BALLANCE_OT_add_rail(bpy.types.Operator):
|
||||
layout.prop(self, "rail_type")
|
||||
layout.prop(self, "rail_radius")
|
||||
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)
|
@ -622,6 +622,7 @@ class info_block_helper():
|
||||
self.offset = offset
|
||||
self.blenderData = None
|
||||
|
||||
# NOTE: this function also used by add_elements.py
|
||||
def load_component(component_id):
|
||||
# get file first
|
||||
compName = config.component_list[component_id]
|
||||
|
@ -1,4 +1,5 @@
|
||||
import bpy
|
||||
from bpy_extras.io_utils import unpack_list
|
||||
|
||||
def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user