diff --git a/i_scene_cp77_gltf/importers/__init__.py b/i_scene_cp77_gltf/importers/__init__.py index 52be0bd..cea7750 100644 --- a/i_scene_cp77_gltf/importers/__init__.py +++ b/i_scene_cp77_gltf/importers/__init__.py @@ -110,7 +110,7 @@ def execute(self, context): bob=self.filepath inColl=self.inColl #print('Bob - ',bob) - importEnt( bob, apps, excluded, props.with_materials, self.include_collisions, self.include_phys, self.include_entCollider, inColl, props.remap_depot) + importEnt(props.with_materials, bob, apps, excluded, self.include_collisions, self.include_phys, self.include_entCollider, inColl, props.remap_depot) return {'FINISHED'} @@ -152,7 +152,7 @@ def execute(self, context): bob=self.filepath props = context.scene.cp77_panel_props print('Importing Sectors from project - ',bob) - importSectors( bob, self.want_collisions, self.am_modding, props.with_materials , props.remap_depot) + importSectors( bob, props.with_materials, props.remap_depot, self.want_collisions, self.am_modding) return {'FINISHED'} @@ -191,57 +191,33 @@ class CP77Import(Operator, ImportHelper): default="ALL" ) - #kwekmaster: refactor UI layout from the operator. + # switch back to operator draw function to align with other UI features def draw(self, context): - pass + cp77_addon_prefs = bpy.context.preferences.addons['i_scene_cp77_gltf'].preferences + props = context.scene.cp77_panel_props + layout = self.layout + col = layout.column() + col.prop(props, 'with_materials') + if props.with_materials: + col.prop(self, 'image_format') + col.prop(self, 'exclude_unused_mats') + col.prop(props, 'use_cycles') + if props.use_cycles: + col.prop(props, 'update_gi') + col.prop(self, 'hide_armatures') + col.prop(self, 'import_garmentsupport') + if cp77_addon_prefs.experimental_features: + col.prop(props,"remap_depot") + def execute(self, context): props = context.scene.cp77_panel_props SetCyclesRenderer(props.use_cycles, props.update_gi) - CP77GLBimport(self, self.exclude_unused_mats, self.image_format, props.with_materials, self.filepath, self.hide_armatures, self.import_garmentsupport, self.files, self.directory, self.appearances, props.remap_depot) + CP77GLBimport(self, props.with_materials, props.remap_depot, self.exclude_unused_mats, self.image_format, self.filepath, self.hide_armatures, self.import_garmentsupport, self.files, self.directory, self.appearances) return {'FINISHED'} - -# Material Sub-panel -class CP77_PT_ImportWithMaterial(Panel): - bl_space_type = 'FILE_BROWSER' - bl_region_type = 'TOOL_PROPS' - bl_label = "With Materials" - - @classmethod - def poll(cls, context): - operator = context.space_data.active_operator - return operator.bl_idname == "IO_SCENE_GLTF_OT_cp77" - - def draw_header(self, context): - props = context.scene.cp77_panel_props - self.layout.prop(props, "with_materials", text="") - - def draw(self, context): - cp77_addon_prefs = bpy.context.preferences.addons['i_scene_cp77_gltf'].preferences - props = context.scene.cp77_panel_props - operator = context.space_data.active_operator - layout = self.layout - row = layout.row(align=True) - layout.enabled = props.with_materials - row.prop(operator, 'exclude_unused_mats') - row = layout.row(align=True) - row.prop(operator, 'image_format') - row = layout.row(align=True) - row.prop(operator, 'hide_armatures') - row = layout.row(align=True) - row.prop(props, 'use_cycles') - if cp77_addon_prefs.experimental_features: - row = layout.row(align=True) - row.prop(props,"remap_depot") - if props.use_cycles: - row = layout.row(align=True) - row.prop(props, 'update_gi') - row = layout.row(align=True) - row.prop(operator, 'import_garmentsupport') - - + def menu_func_import(self, context): self.layout.operator(CP77Import.bl_idname, text="Cyberpunk GLTF (.gltf/.glb)", icon_value=get_icon('WKIT')) self.layout.operator(CP77EntityImport.bl_idname, text="Cyberpunk Entity (.json)", icon_value=get_icon('WKIT')) diff --git a/i_scene_cp77_gltf/importers/entity_import.py b/i_scene_cp77_gltf/importers/entity_import.py index 1b4e699..52398a4 100644 --- a/i_scene_cp77_gltf/importers/entity_import.py +++ b/i_scene_cp77_gltf/importers/entity_import.py @@ -33,8 +33,9 @@ def create_axes(ent_coll,name): # if you've already imported the body/head and set the rig up you can exclude them by putting them in the exclude_meshes list #presto_stash=[] -def importEnt( filepath='', appearances=[], exclude_meshes=[], with_materials=True, include_collisions=False, include_phys=False, include_entCollider=False, inColl='', remapdepot=False): +def importEnt(with_materials, filepath='', appearances=[], exclude_meshes=[], include_collisions=False, include_phys=False, include_entCollider=False, inColl='', remapdepot=False): cp77_addon_prefs = bpy.context.preferences.addons['i_scene_cp77_gltf'].preferences + with_materials = with_materials if not cp77_addon_prefs.non_verbose: print('') print('-------------------- Importing Cyberpunk 2077 Entity --------------------') @@ -137,7 +138,7 @@ def importEnt( filepath='', appearances=[], exclude_meshes=[], with_materials=Tr # presto_stash.append(animsinres) if len(animsinres)>0: - bpy.ops.io_scene_gltf.cp77(filepath=animsinres[0]) + bpy.ops.io_scene_gltf.cp77(with_materials, filepath=animsinres[0]) #find what we just loaded arms=[x for x in bpy.data.objects if 'Armature' in x.name and x not in oldarms] rig=arms[0] @@ -328,7 +329,7 @@ def importEnt( filepath='', appearances=[], exclude_meshes=[], with_materials=Tr meshApp=c['meshAppearance']['$value'] #print(meshApp) try: - bpy.ops.io_scene_gltf.cp77(filepath=meshpath, appearances=meshApp) + bpy.ops.io_scene_gltf.cp77(with_materials, filepath=meshpath, appearances=meshApp) for obj in C.selected_objects: obj['componentName'] = c['name']['$value'] obj['sourcePath'] = meshpath diff --git a/i_scene_cp77_gltf/importers/import_with_materials.py b/i_scene_cp77_gltf/importers/import_with_materials.py index 10bc6f9..331bbda 100644 --- a/i_scene_cp77_gltf/importers/import_with_materials.py +++ b/i_scene_cp77_gltf/importers/import_with_materials.py @@ -40,7 +40,7 @@ def objs_in_col(top_coll, objtype): appearances = None collection = None -def CP77GLBimport(self, exclude_unused_mats=True, image_format='png', with_materials=True, filepath='', hide_armatures=True, import_garmentsupport=False, files=[], directory='', appearances=[], remap_depot=False): +def CP77GLBimport(self, with_materials, remap_depot, exclude_unused_mats=True, image_format='png', filepath='', hide_armatures=True, import_garmentsupport=False, files=[], directory='', appearances=[]): cp77_addon_prefs = bpy.context.preferences.addons['i_scene_cp77_gltf'].preferences context=bpy.context obj = None @@ -56,9 +56,11 @@ def CP77GLBimport(self, exclude_unused_mats=True, image_format='png', with_mater else: print('-------------------- Beginning Cyberpunk Model Import --------------------') print('') - print(f"Importing: {os.path.basename(self.filepath)}") if with_materials==True: + print(f"Importing: {os.path.basename(self.filepath)} with materials") print(f"Appearances to Import: {(', '.join(appearances))}") + else: + print(f"Importing: {os.path.basename(self.filepath)}") print('') # prevent crash if no directory supplied when using filepath if len(self.directory)>0: @@ -143,7 +145,7 @@ def CP77GLBimport(self, exclude_unused_mats=True, image_format='png', with_mater if ".anims.glb" in filepath: break else: - if has_material_json: + if with_materials==True and has_material_json: matjsonpath = current_file_base_path + ".Material.json" obj = jsonload(matjsonpath) if obj == None: @@ -173,9 +175,9 @@ def CP77GLBimport(self, exclude_unused_mats=True, image_format='png', with_mater for key in json_apps.keys(): for m in json_apps[key]: validmats[m]=True - - import_mats(current_file_base_path, DepotPath, exclude_unused_mats, existingMeshes, gltf_importer, image_format, obj, - validmats) + if with_materials: + import_mats(current_file_base_path, DepotPath, exclude_unused_mats, existingMeshes, gltf_importer, image_format, obj, validmats) + if not cp77_addon_prefs.non_verbose: print(f"GLB Import Time: {(time.time() - start_time)} Seconds") print('') diff --git a/i_scene_cp77_gltf/importers/sector_import.py b/i_scene_cp77_gltf/importers/sector_import.py index cc91be9..a9c9711 100644 --- a/i_scene_cp77_gltf/importers/sector_import.py +++ b/i_scene_cp77_gltf/importers/sector_import.py @@ -244,7 +244,7 @@ def get_tan_pos(inst): pos[1][2] = inst['Elements'][1]['Z'] return pos -def importSectors( filepath='', want_collisions=False, am_modding=False, with_materials=True, remap_depot=False, with_lights=True ): +def importSectors( filepath, with_mats, remap_depot, want_collisions=False, am_modding=False,with_lights=True ): cp77_addon_prefs = bpy.context.preferences.addons['i_scene_cp77_gltf'].preferences if not cp77_addon_prefs.non_verbose: print('') @@ -368,7 +368,7 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma groupname = groupname[:-1] if groupname not in Masters.children.keys() and os.path.exists(meshpath): try: - bpy.ops.io_scene_gltf.cp77(filepath=meshpath, appearances=impapps) + bpy.ops.io_scene_gltf.cp77(with_mats, filepath=meshpath, appearances=impapps) objs = C.selected_objects move_coll= coll_scene.children.get( objs[0].users_collection[0].name ) coll_target.children.link(move_coll) @@ -450,7 +450,7 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma try: #print('Importing ',entpath, ' using app ',app) incoll='MasterInstances' - bpy.ops.io_scene_gltf.cp77entity(filepath=entpath, appearances=app, inColl=incoll) + bpy.ops.io_scene_gltf.cp77entity(with_mats, filepath=entpath, appearances=app, inColl=incoll) move_coll=Masters.children.get(ent_groupname) imported=True except: @@ -790,7 +790,7 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma #o.empty_display_size = 0.002 #o.empty_display_type = 'IMAGE' - if with_materials: + if with_mats: mipath = o['decal'] jsonpath = os.path.join(path,mipath)+".json" #print(jsonpath) @@ -864,7 +864,7 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma # Roads all have stupid prx0 names so instancing by name wont work. imported=False try: - bpy.ops.io_scene_gltf.cp77(filepath=meshpath, with_materials=True) + bpy.ops.io_scene_gltf.cp77(with_mats, filepath=meshpath) objs = C.selected_objects groupname = objs[0].users_collection[0].name group= coll_scene.children.get( groupname ) @@ -955,7 +955,7 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma new['pivot']=inst['Pivot'] new['meshAppearance']=meshAppearance - print(new['nodeDataIndex']) + #print(new['nodeDataIndex']) # Should do something with the Advertisements lightData bits here for old_obj in group.all_objects: @@ -1263,4 +1263,4 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma filepath = 'F:\\CPMod\\judysApt\\judysApt.cpmodproj' - importSectors( filepath, want_collisions=False, am_modding=False, with_materials=True ) \ No newline at end of file + importSectors( filepath, with_mats=True, want_collisions=False, am_modding=False ) \ No newline at end of file diff --git a/i_scene_cp77_gltf/meshtools/__init__.py b/i_scene_cp77_gltf/meshtools/__init__.py index 7f13119..2e31e91 100644 --- a/i_scene_cp77_gltf/meshtools/__init__.py +++ b/i_scene_cp77_gltf/meshtools/__init__.py @@ -30,85 +30,54 @@ def poll(cls, context): def draw(self, context): layout = self.layout box = layout.box() + box.operator("cp77.rotate_obj", text="Rotate Selected Objects") + box = layout.box() props = context.scene.cp77_panel_props cp77_addon_prefs = bpy.context.preferences.addons['i_scene_cp77_gltf'].preferences if cp77_addon_prefs.show_modtools: - if cp77_addon_prefs.show_meshtools: - box.label(icon_value=get_icon("REFIT"), text="AKL Autofitter:") - row = box.row(align=True) - split = row.split(factor=0.29,align=True) - split.label(text="Shape:") - split.prop(props, 'refit_json', text="") - row = box.row(align=True) - row.operator("cp77.auto_fitter", text="Refit Selected Mesh") - row.prop(props, 'fbx_rot', text="", icon='LOOP_BACK', toggle=1) - - box = layout.box() - box.label(icon_value=get_icon("TECH"), text="Modifiers:") - row = box.row(align=True) - split = row.split(factor=0.35,align=True) - split.label(text="Target:") - split.prop(props, "selected_armature", text="") - row = box.row(align=True) - row.operator("cp77.set_armature", text="Change Armature Target") - - box = layout.box() + if cp77_addon_prefs.show_meshtools: box.label(icon_value=get_icon("SCULPT"), text="Modelling:") - row = box.row(align=True) + col = box.column() + col.operator("cp77.set_armature", text="Change Armature Target") if context.active_object and context.active_object.type == 'MESH' and context.object.active_material and context.object.active_material.name == 'UV_Checker': - row.operator("cp77.uv_unchecker", text="Remove UV Checker") + col.operator("cp77.uv_unchecker", text="Remove UV Checker") else: - row.operator("cp77.uv_checker", text="UV Checker") - row = box.row(align=True) - split = row.split(factor=0.5,align=True) - split.label(text="Source Mesh:") - split.prop(props, "mesh_source", text="") - row = box.row(align=True) - split = row.split(factor=0.5,align=True) - split.label(text="Target Mesh:") - split.prop(props, "mesh_target", text="") - row = box.row(align=True) - box.operator("cp77.trans_weights", text="Transfer Vertex Weights") - row = box.row(align=True) - row.operator("cp77.rotate_obj") - + col.operator("cp77.uv_checker", text="Apply UV Checker") + col.operator("cp77.trans_weights", text="Weight Transfer Tool") + box = layout.box() box.label(text="Mesh Cleanup", icon_value=get_icon("TRAUMA")) - row = box.row(align=True) - split = row.split(factor=0.7,align=True) - split.label(text="Merge Distance:") - split.prop(props,"merge_distance", text="", slider=True) - row = box.row(align=True) - split = row.split(factor=0.7,align=True) - split.label(text="Smooth Factor:") - split.prop(props,"smooth_factor", text="", slider=True) - row = box.row(align=True) - row.operator("cp77.submesh_prep") - row = box.row(align=True) - row.operator("cp77.group_verts", text="Group Ungrouped Verts") - row = box.row(align=True) - row.operator('object.delete_unused_vgroups', text="Delete Unused Vert Groups") + col = box.column() + col.operator("cp77.submesh_prep") + col.operator("cp77.group_verts", text="Group Ungrouped Verts") + col.operator('object.delete_unused_vgroups', text="Delete Unused Vert Groups") + + box = layout.box() + box.label(text="AKL Autofitter", icon_value=get_icon("REFIT")) + col = box.column() + col.operator("cp77.auto_fitter", text="Refit Selected Meshes") box = layout.box() - box.label(text="Vertex Colours", icon="BRUSH_DATA") - row = box.row(align=True) - split = row.split(factor=0.275,align=True) - split.label(text="Preset:") - split.prop(props, "vertex_color_presets", text="") - box.operator("cp77.apply_vertex_color_preset") - box.operator("cp77.add_vertex_color_preset") - box.operator("cp77.delete_vertex_color_preset") + box.label(text="Vertex Colours", icon="BRUSH_DATA") + col = box.column() + col.operator("cp77.apply_vertex_color_preset") + col.operator("cp77.add_vertex_color_preset") + col.operator("cp77.delete_vertex_color_preset") box = layout.box() box.label(text="Material Export", icon="MATERIAL") - box.operator("export_scene.hp") - box.operator("export_scene.mlsetup") + col = box.column() + col.operator("export_scene.hp") + col.operator("export_scene.mlsetup") class CP77DeleteVertexcolorPreset(Operator): bl_idname = "cp77.delete_vertex_color_preset" - bl_label = "Delete Preset" - + bl_label = "Delete Vertex Colour Preset" + + def invoke(self, context, event): + return context.window_manager.invoke_props_dialog(self) + def execute(self, context): props = context.scene.cp77_panel_props preset_name = props.vertex_color_presets @@ -122,10 +91,18 @@ def execute(self, context): return {'CANCELLED'} return {'FINISHED'} + + def draw(self, context): + props = context.scene.cp77_panel_props + layout = self.layout + row = layout.row(align=True) + split = row.split(factor=0.275,align=True) + split.label(text="Preset:") + split.prop(props, "vertex_color_presets", text="") class CP77AddVertexcolorPreset(Operator): bl_idname = "cp77.add_vertex_color_preset" - bl_label = "Save Vertex Color Preset" + bl_label = "Save Vertex Colour Preset" bl_parent_id = "CP77_PT_MeshTools" preset_name: StringProperty(name="Preset Name") @@ -151,23 +128,65 @@ def invoke(self, context, event): self.color = (*color[:3], alpha) # Combine color and alpha print(self.color) return context.window_manager.invoke_props_dialog(self) + + def draw(self, context): + layout = self.layout + col = layout.column() + col.prop(self, "color", text="") + row = layout.row(align=True) + split = row.split(factor=0.3,align=True) + split.label(text="Preset Name:") + split.prop(self, "preset_name", text="") class CP77WeightTransfer(Operator): bl_idname = 'cp77.trans_weights' - bl_label = "Transfer weights from one mesh to another" + bl_label = "Cyberpunk 2077 Weight Transfer Tool" bl_description = "Transfer weights from source mesh to target mesh" bl_options = {'REGISTER', 'UNDO'} + + vertInterop: BoolProperty( + name="Use Nearest Vert Interpolated", + description="Sometimes gives better results when the default mode fails", + default=False) + + bySubmesh: BoolProperty( + name="Transfer by Submesh Order", + description="Because Mana Gets what Mana Wants :D", + default=False) + + + def invoke(self, context, event): + return context.window_manager.invoke_props_dialog(self) def execute(self, context): # Call the trans_weights function with the provided arguments result = trans_weights(self, context) return {"FINISHED"} + def draw(self,context): + props = context.scene.cp77_panel_props + layout = self.layout + row = layout.row(align=True) + split = row.split(factor=0.3,align=True) + split.label(text="Source Mesh:") + split.prop(props, "mesh_source", text="") + row = layout.row(align=True) + split = row.split(factor=0.3,align=True) + split.label(text="Target Mesh:") + split.prop(props, "mesh_target", text="") + row = layout.row(align=True) + row.prop(self, 'vertInterop', text="Use Nearest Vert Interpolation") + row = layout.row(align=True) + row.prop(self, 'bySubmesh') + # Operator to apply a preset class CP77ApplyVertexcolorPreset(Operator): bl_idname = "cp77.apply_vertex_color_preset" - bl_label = "Apply Vertex color Preset" - + bl_label = "Apply Vertex Colour Preset" + + def invoke(self, context, event): + return context.window_manager.invoke_props_dialog(self) + def execute(self, context): props = context.scene.cp77_panel_props preset_name = props.vertex_color_presets @@ -225,6 +244,14 @@ def execute(self, context): self.report({'INFO'}, f"Preset '{preset_name}' applied.") return {'FINISHED'} + def draw(self, context): + props = context.scene.cp77_panel_props + layout = self.layout + row = layout.row(align=True) + split = row.split(factor=0.275,align=True) + split.label(text="Preset:") + split.prop(props, "vertex_color_presets", text="") + class CP77GroupVerts(Operator): bl_idname = "cp77.group_verts" @@ -237,13 +264,21 @@ def execute(self, context): CP77GroupUngroupedVerts(self, context) return {'FINISHED'} - class CP77Autofitter(Operator): bl_idname = "cp77.auto_fitter" - bl_label = "Auto Fit" + bl_label = "AKL Autofitter" bl_description = "Use to automatically fit your mesh to a selection of modified bodies" bl_options = {'REGISTER', 'UNDO'} - + + useAddon: BoolProperty( + name="Use an Addon", + description="If enabled, a base refitter will be applied, followed by an addon", + default=False + ) + + def invoke(self, context, event): + return context.window_manager.invoke_props_dialog(self) + def execute(self, context): props = context.scene.cp77_panel_props target_body_name = props.refit_json @@ -255,8 +290,24 @@ def execute(self, context): CP77Refit(context, refitter, target_body_path, target_body_name, props.fbx_rot) return {'FINISHED'} + + def draw(self,context): + props = context.scene.cp77_panel_props + layout = self.layout + row = layout.row(align=True) + split = row.split(factor=0.2,align=True) + split.label(text="Shape:") + split.prop(props, 'refit_json', text="") + if self.useAddon: + row = layout.row(align=True) + split = row.split(factor=0.2,align=True) + split.label(text="Addon:") + split.prop(props, 'refit_json', text="") + col = layout.column() + col.prop(props, 'fbx_rot', text="Refit a mesh in FBX orientation") + col.prop(self, 'useAddon', text="Use a Refitter Addon") - + class CP77UVTool(Operator): bl_idname = 'cp77.uv_checker' bl_label = "UV Checker" @@ -267,7 +318,6 @@ def execute(self, context): CP77UvChecker(self, context) return {"FINISHED"} - class CP77UVCheckRemover(Operator): bl_idname = 'cp77.uv_unchecker' bl_label = "UV Checker" @@ -282,35 +332,65 @@ def execute(self, context): CP77UvUnChecker(self, context) return {"FINISHED"} - class CP77SetArmature(Operator): bl_idname = "cp77.set_armature" bl_label = "Change Armature Target" bl_parent_id = "CP77_PT_MeshTools" - bl_description = "Change the armature modifier on selected meshes to the target" + bl_description = "Change the armature modifier on selected meshes to the target" + reparent: BoolProperty( + name= "Also Reparent Selected Meshes to the Armature", + default= True + ) + + def invoke(self, context, event): + return context.window_manager.invoke_props_dialog(self) + def execute(self, context): - CP77ArmatureSet(self,context) + CP77ArmatureSet(self,context, self.reparent) return {'FINISHED'} - + + def draw(self, context): + props = context.scene.cp77_panel_props + layout = self.layout + row = layout.row(align=True) + split = row.split(factor=0.35,align=True) + split.label(text="Armature Target:") + split.prop(props, "selected_armature", text="") + col = layout.column() + col.prop(self, 'reparent') class CP77_OT_submesh_prep(Operator): # based on Rudolph2109's function bl_label = "Prep. It!" bl_idname = "cp77.submesh_prep" bl_parent_id = "CP77_PT_MeshTools" - bl_description = "Marking seams based on edges boundary loops, merging vertices, correcting and smoothening the normals based on the direction of the faces" - + bl_description = "Mark seams based on edges boundary loops, merge vertices, correct and smooth normals based on the direction of the faces" + + def invoke(self, context, event): + return context.window_manager.invoke_props_dialog(self) + def execute(self, context): props= context.scene.cp77_panel_props CP77SubPrep(self, context, props.smooth_factor, props.merge_distance) return {'FINISHED'} - + + def draw(self, context): + props= context.scene.cp77_panel_props + layout = self.layout + row = layout.row(align=True) + split = row.split(factor=0.7,align=True) + split.label(text="Merge Distance:") + split.prop(props,"merge_distance", text="", slider=True) + row = layout.row(align=True) + split = row.split(factor=0.7,align=True) + split.label(text="Smooth Factor:") + split.prop(props,"smooth_factor", text="", slider=True) class CP77RotateObj(Operator): bl_label = "Change Orientation" bl_idname = "cp77.rotate_obj" - bl_description = "rotate the selected object" + bl_description = "Rotate the selected object 180 degrees" def execute(self, context): rotate_quat_180(self, context) @@ -327,6 +407,13 @@ def register_meshtools(): if not hasattr(bpy.types, cls.__name__): bpy.utils.register_class(cls) +def unregister_meshtools(): + for cls in reversed(other_classes): + if hasattr(bpy.types, cls.__name__): + bpy.utils.unregister_class(cls) + for cls in reversed(operators): + if hasattr(bpy.types, cls.__name__): + bpy.utils.unregister_class(cls) def unregister_meshtools(): for cls in reversed(other_classes): if hasattr(bpy.types, cls.__name__): diff --git a/i_scene_cp77_gltf/meshtools/meshtools.py b/i_scene_cp77_gltf/meshtools/meshtools.py index a8d2f5f..0bb888a 100644 --- a/i_scene_cp77_gltf/meshtools/meshtools.py +++ b/i_scene_cp77_gltf/meshtools/meshtools.py @@ -48,7 +48,7 @@ def CP77SubPrep(self, context, smooth_factor, merge_distance): if context.mode != current_mode: bpy.ops.object.mode_set(mode=current_mode) -def CP77ArmatureSet(self, context): +def CP77ArmatureSet(self, context, reparent): selected_meshes = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH'] props = context.scene.cp77_panel_props target_armature_name = props.selected_armature @@ -83,21 +83,23 @@ def CP77ArmatureSet(self, context): armature = mesh.modifiers.new('Armature', 'ARMATURE') armature.object = target_armature - # Set parent - mesh.parent = target_armature + if reparent == True: + # Set parent + mesh.parent = target_armature - # Unlink the mesh from its original collections - for col in mesh.users_collection: - col.objects.unlink(mesh) + # Unlink the mesh from its original collections + for col in mesh.users_collection: + col.objects.unlink(mesh) - # Link the mesh to the target armature's collection - target_collection.objects.link(mesh) + # Link the mesh to the target armature's collection + target_collection.objects.link(mesh) def CP77UvChecker(self, context): selected_meshes = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH'] bpy_mats=bpy.data.materials obj = context.object current_mode = context.mode + uv_checker = None if not obj: show_message("No active object. Please Select a Mesh and try again") return {'CANCELLED'}