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
+41
View File
@@ -0,0 +1,41 @@
import bpy
import numpy as np
from bpy.types import Object, ShapeKey
from functools import lru_cache
### Clean up material names in the given mesh by removing the '.001' suffix.
def clean_material_names(mesh):
for j, mat in enumerate(mesh.material_slots):
if mat.name.endswith(('.0+', ' 0+')):
mesh.active_material_index = j
mesh.active_material.name = mat.name[:-len(mat.name.rstrip('0')) - 1]
# This will fix faulty uv coordinates, cats did this a other way which can have unintended consequences,
# this is the best way i could of think of doing this for the time being, however may need improvements.
def fix_uv_coordinates(context):
obj = context.object
# Check if the object is in Edit Mode
if obj.mode != 'EDIT':
bpy.ops.object.mode_set(mode='EDIT')
# Check if the object has any mesh data
if obj.type == 'MESH' and obj.data:
bpy.context.view_layer.objects.active = obj
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.average_islands_scale()
# Switch back to Object Mode
bpy.ops.object.mode_set(mode='OBJECT')
else:
print("Object is not a valid mesh with UV data")
def has_shapekeys(mesh_obj: Object) -> bool:
return mesh_obj.data.shape_keys is not None
@lru_cache(maxsize=None)
def _get_shape_key_co(shape_key: ShapeKey) -> np.ndarray:
return np.array([v.co for v in shape_key.data])