Add some Basic Functions

- Added functions folder.
- Added Combine Materials (Basic and needs imporvements.
- Added common file, this is where any common things that could be used by multiple functions will live.
- Clean materials, basic at the minute it cleans up material names in the given mesh by removing the '.001' suffix.
- Added fix UV Cords in which is in common, this should fix faulty uv coordinates, may need improvements as it's was the best way i could think of for the time being.
- Added join all meshes and selected meshes functions, this will use the fix uv cords while joining mehses. This is pretty basic as blender is quite good at doing the mesh joining itself. We may want to expand it in the future though.
This commit is contained in:
Yusarina
2024-06-18 03:54:10 +01:00
parent 7d60d285ea
commit 1d507ddaa0
6 changed files with 275 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
import bpy
from ..core.register import register_wrap
from ..core.common import fix_uv_coordinates
@register_wrap
class JoinAllMeshes(bpy.types.Operator):
bl_idname = "avatar_toolkit.join_all_meshes"
bl_label = "Join All Meshes"
bl_description = "Join all meshes in the scene"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.mode == 'OBJECT'
def execute(self, context):
self.join_all_meshes(context)
return {'FINISHED'}
def join_all_meshes(self, context):
if not bpy.data.objects:
self.report({'INFO'}, "No objects in the scene")
return
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
meshes = [obj for obj in bpy.data.objects if obj.type == 'MESH']
for mesh in meshes:
mesh.select_set(True)
if bpy.context.selected_objects:
bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]
bpy.ops.object.join()
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
fix_uv_coordinates(context)
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
self.report({'INFO'}, "Meshes joined successfully")
else:
self.report({'WARNING'}, "No mesh objects selected")
@register_wrap
class JoinSelectedMeshes(bpy.types.Operator):
bl_idname = "avatar_toolkit.join_selected_meshes"
bl_label = "Join Selected Meshes"
bl_description = "Join selected meshes"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.mode == 'OBJECT'
def execute(self, context):
self.join_selected_meshes(context)
return {'FINISHED'}
def join_selected_meshes(self, context):
selected_objects = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
if not selected_objects:
self.report({'WARNING'}, "No mesh objects selected")
return
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
for obj in selected_objects:
obj.select_set(True)
if bpy.context.selected_objects:
bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]
bpy.ops.object.join()
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
fix_uv_coordinates(context)
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
self.report({'INFO'}, "Selected meshes joined successfully")
else:
self.report({'WARNING'}, "No mesh objects selected")