diff --git a/ballance_blender_plugin/add_elements.py b/ballance_blender_plugin/add_elements.py index d50c5b2..f5f99da 100644 --- a/ballance_blender_plugin/add_elements.py +++ b/ballance_blender_plugin/add_elements.py @@ -36,7 +36,7 @@ class BALLANCE_OT_add_elements(bpy.types.Operator): # create object loadedMesh = bm_import_export.load_component(config.component_list.index(self.elements_type)) obj = bpy.data.objects.new(finalObjectName, loadedMesh) - addSceneAndChangePos(obj) + utils.AddSceneAndMove2Cursor(obj) return {'FINISHED'} @@ -125,10 +125,3 @@ class BALLANCE_OT_add_rail(bpy.types.Operator): layout.prop(self, "rail_radius") if self.rail_type == 'DOUBLE': 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) \ No newline at end of file diff --git a/ballance_blender_plugin/add_floor.py b/ballance_blender_plugin/add_floor.py index 82b1127..1348de5 100644 --- a/ballance_blender_plugin/add_floor.py +++ b/ballance_blender_plugin/add_floor.py @@ -77,6 +77,41 @@ class BALLANCE_OT_add_floor(bpy.types.Operator): return os.path.isdir(prefs.external_folder) def execute(self, context): + # load mesh + objmesh = bpy.data.meshes.new('done_') + if self.floor_type in config.floor_basic_block_list: + load_basic_floor( + objmesh, + self.floor_type, + self.rotation_inside_mesh, + self.height_multiplier, + self.expand_length_1, + self.expand_length_2, + (self.use_2d_top, + self.use_2d_right, + self.use_2d_bottom, + self.use_2d_left, + self.use_3d_top, + self.use_3d_bottom), + (0.0, 0.0)) + elif self.floor_type in config.floor_derived_block_list: + load_derived_floor( + objmesh, + self.floor_type, + self.rotation_inside_mesh, + self.height_multiplier, + self.expand_length_1, + self.expand_length_2, + (self.use_2d_top, + self.use_2d_right, + self.use_2d_bottom, + self.use_2d_left, + self.use_3d_top, + self.use_3d_bottom)) + + # create object and link it + obj=bpy.data.objects.new('A_Floor_BMERevenge_', objmesh) + utils.AddSceneAndMove2Cursor(obj) return {'FINISHED'} def invoke(self, context, event): @@ -189,8 +224,8 @@ def create_or_get_material(material_name): return m def solve_vec_data(str_data, d1, d2, d3, unit, unit_height): - sp = str_data.splite(';') - sp_point = sp[0].splite(',') + sp = str_data.split(';') + sp_point = sp[0].split(',') vec = [float(sp_point[0]), float(sp_point[1]), float(sp_point[2])] for i in range(3): @@ -209,7 +244,7 @@ def solve_vec_data(str_data, d1, d2, d3, unit, unit_height): return vec -def rotate_vec(vec, rotation, unit): +def rotate_translate_vec(vec, rotation, unit, extra_translate): vec[0] -= unit / 2 vec[1] -= unit / 2 @@ -227,15 +262,15 @@ def rotate_vec(vec, rotation, unit): sino=-1 return ( - coso * vec[0] - sino * vec[1] + unit / 2, - sino * vec[0] + coso * vec[1] + unit / 2, + coso * vec[0] - sino * vec[1] + unit / 2 + unit * extra_translate[0], + sino * vec[0] + coso * vec[1] + unit / 2 + unit * extra_translate[1], vec[2] ) def solve_uv_data(str_data, d1, d2, d3, unit): - sp = str_data.splite(';') - sp_point = sp[0].splite(',') + sp = str_data.split(';') + sp_point = sp[0].split(',') vec = [float(sp_point[0]), float(sp_point[1])] for i in range(2): @@ -291,7 +326,7 @@ sides_struct should be a tuple and it always have 6 bool items WARNING: this code is shared with bm import export ''' -def load_basic_floor(mesh, floor_type, rotation, height_multiplier, d1, d2, sides_struct): +def load_basic_floor(mesh, floor_type, rotation, height_multiplier, d1, d2, sides_struct, extra_translate): floor_prototype = config.floor_block_dict[floor_type] # set some unit @@ -340,9 +375,9 @@ def load_basic_floor(mesh, floor_type, rotation, height_multiplier, d1, d2, side for face_define in needCreatedFaces: base_indices = len(vecList) for vec in face_define['Vertices']: - vecList.append(rotate_vec( + vecList.append(rotate_translate_vec( solve_vec_data(vec, d1, d2, height_multiplier, block_3dworld_unit, height_unit), - rotation, block_3dworld_unit)) + rotation, block_3dworld_unit, extra_translate)) for uv in face_define['UVs']: uvList.append(solve_uv_data(uv, d1, d2, height_multiplier, block_uvworld_unit)) @@ -355,7 +390,7 @@ def load_basic_floor(mesh, floor_type, rotation, height_multiplier, d1, d2, side face['P4'] + base_indices) # we need calc normal and push it into list - four_point_normal = solve_normal_data(vecList[vec_indices[0]]), vecList[vec_indices[1]], vecList[vec_indices[2]]) + four_point_normal = solve_normal_data(vecList[vec_indices[0]], vecList[vec_indices[1]], vecList[vec_indices[2]]) for i in range(4): normalList.append(four_point_normal) diff --git a/ballance_blender_plugin/json/BasicBlock.json b/ballance_blender_plugin/json/BasicBlock.json index 4f42b57..64612b4 100644 --- a/ballance_blender_plugin/json/BasicBlock.json +++ b/ballance_blender_plugin/json/BasicBlock.json @@ -17,8 +17,8 @@ "Vertices": [ "2.5,0,0;+d1;;", "2.5,2.5,-0.7;+d1;;", - "0,2.5,-0.7", - "0,0,0" + "0,2.5,-0.7;;;", + "0,0,0;;;" ], "UVs": [ "0,0;;-d1", @@ -61,10 +61,10 @@ }, "TwoDTopSide": { "Vertices": [ - "0,0,0", + "0,0,0;;;", "0,0,-5;;;-d3", "0,2.5,-5;;;-d3", - "0,2.5,-0.7" + "0,2.5,-0.7;;;" ], "UVs": [ "0,0.5;;", @@ -87,7 +87,7 @@ "2.5,2.5,-0.7;+d1;;", "2.5,2.5,-5;+d1;;-d3", "0,2.5,-5;;;-d3", - "0,2.5,-0.7" + "0,2.5,-0.7;;;" ], "UVs": [ "0.14,0;;-d1", @@ -133,7 +133,7 @@ "2.5,0,0;+d1;;", "2.5,0,-5;+d1;;-d3", "0,0,-5;;;-d3", - "0,0,0" + "0,0,0;;;" ], "UVs": [ "0,0.5;;", @@ -153,8 +153,8 @@ }, "TwoDTopSideExpand": { "Vertices": [ - "0,0,-5;;-d3", - "0,2.5,-5;;-d3", + "0,0,-5;;;-d3", + "0,2.5,-5;;;-d3", "0,2.5,-2.5;;;", "0,0,-2.5;;;", "0,0,0;;;", @@ -176,7 +176,7 @@ "P2": 3, "P3": 4, "P4": 5, - "Textures": "FloorSide" + "Textures": "FloorTopBorder" }, { "P1": 3, @@ -213,7 +213,7 @@ "P2": 4, "P3": 3, "P4": 2, - "Textures": "FloorSide" + "Textures": "FloorTopBorder" }, { "P1": 0, @@ -249,7 +249,7 @@ "P2": 3, "P3": 4, "P4": 5, - "Textures": "FloorSide" + "Textures": "FloorTopBorder" }, { "P1": 3, diff --git a/ballance_blender_plugin/utils.py b/ballance_blender_plugin/utils.py index b75112a..a61b6ab 100644 --- a/ballance_blender_plugin/utils.py +++ b/ballance_blender_plugin/utils.py @@ -9,3 +9,10 @@ def ShowMessageBox(message, title, icon): layout.label(text=item, translate=False) bpy.context.window_manager.popup_menu(draw, title = title, icon = icon) + +def AddSceneAndMove2Cursor(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)