From 751ff15b957c5ef771c684ffbf7b6fd50510b4cf Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 31 Aug 2020 21:56:08 +0800 Subject: [PATCH] fix some name error and add no uv checker --- ballance_blender_plugin/__init__.py | 20 +++++---- ballance_blender_plugin/no_uv_checker.py | 45 +++++++++++++++++++ .../{floor_rail_uv.py => rail_uv.py} | 17 ++----- .../{super_align.py => threedsmax_align.py} | 4 +- 4 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 ballance_blender_plugin/no_uv_checker.py rename ballance_blender_plugin/{floor_rail_uv.py => rail_uv.py} (83%) rename ballance_blender_plugin/{super_align.py => threedsmax_align.py} (98%) diff --git a/ballance_blender_plugin/__init__.py b/ballance_blender_plugin/__init__.py index d3324ef..dd2e6d1 100644 --- a/ballance_blender_plugin/__init__.py +++ b/ballance_blender_plugin/__init__.py @@ -18,17 +18,19 @@ if "bpy" in locals(): import importlib if "bm_import_export" in locals(): importlib.reload(bm_import_export) - if "floor_rail_uv" in locals(): - importlib.reload(floor_rail_uv) + if "rail_uv" in locals(): + importlib.reload(rail_uv) if "utils" in locals(): importlib.reload(utils) if "config" in locals(): importlib.reload(config) if "preferences" in locals(): importlib.reload(preferences) - if "super_align" in locals(): - importlib.reload(super_align) -from . import config, utils, bm_import_export, floor_rail_uv, preferences, super_align + if "threedsmax_align" in locals(): + importlib.reload(threedsmax_align) + if "no_uv_checker" in locals(): + importlib.reload(no_uv_checker) +from . import config, utils, bm_import_export, rail_uv, preferences, threedsmax_align, no_uv_checker # ============================================= menu system @@ -40,8 +42,9 @@ class ThreeDViewerMenu(bpy.types.Menu): def draw(self, context): layout = self.layout - layout.operator("ballance.super_align") + layout.operator("ballance.threedsmax_align") layout.operator("ballance.rail_uv") + layout.operator("ballance.no_uv_checker") # ============================================= blender call system @@ -49,8 +52,9 @@ classes = ( preferences.BallanceBlenderPluginPreferences, bm_import_export.ImportBM, bm_import_export.ExportBM, - floor_rail_uv.RailUVOperator, - super_align.SuperAlignOperator, + rail_uv.RailUVOperator, + threedsmax_align.SuperAlignOperator, + no_uv_checker.NoUVCheckerOperator, ThreeDViewerMenu ) diff --git a/ballance_blender_plugin/no_uv_checker.py b/ballance_blender_plugin/no_uv_checker.py new file mode 100644 index 0000000..b1c6b12 --- /dev/null +++ b/ballance_blender_plugin/no_uv_checker.py @@ -0,0 +1,45 @@ +import bpy,bmesh +from . import utils + +class NoUVCheckerOperator(bpy.types.Operator): + """Check whether the currently selected object has UV""" + bl_idname = "ballance.no_uv_checker" + bl_label = "Check UV" + bl_options = {'UNDO'} + + @classmethod + def poll(self, context): + return check_valid_target() + + def execute(self, context): + check_target() + return {'FINISHED'} + +# ====================== method + +def check_valid_target(): + return (len(bpy.context.selected_objects) > 0) + +def check_target(): + noUVObject = [] + invalidObjectCount = 0 + for obj in bpy.context.selected_objects: + if obj.type != 'MESH': + invalidObjectCount+=1 + continue + if obj.mode != 'OBJECT': + invalidObjectCount+=1 + continue + if obj.data.uv_layers.active is None: + noUVObject.append(obj.name) + + result = ("All objects: {}, Skipped: {}, No UV Count: {}. Following object don't have UV: ".format(len(bpy.context.selected_objects), invalidObjectCount, len(noUVObject)) + + ", ".join(noUVObject[:4]) + + (". Too much objects don't have UV. Please open terminal to browse them." if len(noUVObject) > 4 else "")) + + if len(noUVObject) > 4: + print("Following object don't have UV:") + for item in noUVObject: + print(item) + + utils.ShowMessageBox(result, "Check result", 'INFO') diff --git a/ballance_blender_plugin/floor_rail_uv.py b/ballance_blender_plugin/rail_uv.py similarity index 83% rename from ballance_blender_plugin/floor_rail_uv.py rename to ballance_blender_plugin/rail_uv.py index 9694317..bf09fd0 100644 --- a/ballance_blender_plugin/floor_rail_uv.py +++ b/ballance_blender_plugin/rail_uv.py @@ -23,7 +23,7 @@ def check_rail_target(): continue if obj.mode != 'OBJECT': continue - if obj.data.uv_layers.active.data == None: + if obj.data.uv_layers.active is None: continue return True return False @@ -38,7 +38,7 @@ def create_rail_uv(): if obj.mode != 'OBJECT': ignoredObj.append(obj.name) continue - if obj.data.uv_layers.active.data == None: + if obj.data.uv_layers.active is None: ignoredObj.append(obj.name) continue @@ -54,15 +54,4 @@ def create_rail_uv(): uv_layer[loop_index].uv[1] = 1 # vecList[index].co[1] if len(ignoredObj) != 0: - utils.ShowMessageBox("Following objects are not processed due to they are not suit for this function now: " + ', '.join(ignoredObj), "No processed object", 'WARNING') - - -def virtoolize_floor_uv(): - pass - -def mesh_triangulate(me): - bm = bmesh.new() - bm.from_mesh(me) - bmesh.ops.triangulate(bm, faces=bm.faces) - bm.to_mesh(me) - bm.free() \ No newline at end of file + utils.ShowMessageBox("Following objects are not processed due to they are not suit for this function now: " + ', '.join(ignoredObj), "Check result", 'INFO') diff --git a/ballance_blender_plugin/super_align.py b/ballance_blender_plugin/threedsmax_align.py similarity index 98% rename from ballance_blender_plugin/super_align.py rename to ballance_blender_plugin/threedsmax_align.py index f05a7b5..9b4ebfa 100644 --- a/ballance_blender_plugin/super_align.py +++ b/ballance_blender_plugin/threedsmax_align.py @@ -3,8 +3,8 @@ from . import utils class SuperAlignOperator(bpy.types.Operator): """Align object with 3ds Max way""" - bl_idname = "ballance.super_align" - bl_label = "Super Align" + bl_idname = "ballance.threedsmax_align" + bl_label = "3ds Max Align" bl_options = {'UNDO'} align_x: bpy.props.BoolProperty(name="X position")