Attach Meshes

This commit is contained in:
Yusarina
2024-12-16 12:29:35 +00:00
parent 847bf68f9d
commit c081b89233
6 changed files with 300 additions and 152 deletions
+24
View File
@@ -1,5 +1,6 @@
import bpy
import numpy as np
from mathutils import Vector
from bpy.types import Context, Object, Modifier, EditBone, Operator
from typing import Optional, Tuple, List, Set, Dict, Any, Generator, Callable
from ..core.logging_setup import logger
@@ -592,3 +593,26 @@ def fix_zero_length_bones(armature: Object) -> None:
bpy.ops.object.mode_set(mode='OBJECT')
def calculate_bone_orientation(mesh, vertices):
"""Calculate optimal bone orientation based on mesh geometry."""
if not vertices:
return Vector((0, 0, 0.1)), 0.0
coords = [mesh.data.vertices[v.index].co for v in vertices]
min_co = Vector(map(min, zip(*coords)))
max_co = Vector(map(max, zip(*coords)))
dimensions = max_co - min_co
roll_angle = 0.0
return dimensions, roll_angle
def add_armature_modifier(mesh: Object, armature: Object):
"""Add armature modifier to mesh."""
for mod in mesh.modifiers:
if mod.type == 'ARMATURE':
mesh.modifiers.remove(mod)
modifier = mesh.modifiers.new('Armature', 'ARMATURE')
modifier.object = armature
+28 -18
View File
@@ -304,59 +304,69 @@ class AvatarToolkitSceneProperties(PropertyGroup):
)
merge_armature_into: StringProperty(
name=t('CustomPanel.merge_into'),
description=t('CustomPanel.merge_into_desc'),
name=t('MergeArmature.into'),
description=t('MergeArmature.into_desc'),
default=""
)
merge_armature: StringProperty(
name=t('CustomPanel.merge_from'),
description=t('CustomPanel.merge_from_desc'),
name=t('MergeArmature.from'),
description=t('MergeArmature.from_desc'),
default=""
)
attach_mesh: StringProperty(
name=t('CustomPanel.attach_mesh'),
description=t('CustomPanel.attach_mesh_desc'),
name=t('AttachMesh.select'),
description=t('AttachMesh.select_desc'),
default=""
)
attach_bone: StringProperty(
name=t('CustomPanel.attach_bone'),
description=t('CustomPanel.attach_bone_desc'),
name=t('AttachBone.select'),
description=t('AttachBone.select_desc'),
default=""
)
merge_all_bones: BoolProperty(
name=t('CustomPanel.merge_all_bones'),
description=t('CustomPanel.merge_all_bones_desc'),
name=t('MergeArmature.merge_all'),
description=t('MergeArmature.merge_all_desc'),
default=True
)
apply_transforms: BoolProperty(
name=t('CustomPanel.apply_transforms'),
description=t('CustomPanel.apply_transforms_desc'),
name=t('MergeArmature.apply_transforms'),
description=t('MergeArmature.apply_transforms_desc'),
default=True
)
join_meshes: BoolProperty(
name=t('CustomPanel.join_meshes'),
description=t('CustomPanel.join_meshes_desc'),
name=t('MergeArmature.join_meshes'),
description=t('MergeArmature.join_meshes_desc'),
default=True
)
remove_zero_weights: BoolProperty(
name=t('CustomPanel.remove_zero_weights'),
description=t('CustomPanel.remove_zero_weights_desc'),
name=t('MergeArmature.remove_zero_weights'),
description=t('MergeArmature.remove_zero_weights_desc'),
default=True
)
cleanup_shape_keys: BoolProperty(
name=t('CustomPanel.cleanup_shape_keys'),
description=t('CustomPanel.cleanup_shape_keys_desc'),
name=t('MergeArmature.cleanup_shape_keys'),
description=t('MergeArmature.cleanup_shape_keys_desc'),
default=True
)
attach_mesh: StringProperty(
name=t("Tools.attach_mesh_select"),
description=t("Tools.attach_mesh_select_desc")
)
attach_bone: StringProperty(
name=t("Tools.attach_bone_select"),
description=t("Tools.attach_bone_select_desc")
)
def register() -> None:
"""Register the Avatar Toolkit property group"""
logger.info("Registering Avatar Toolkit properties")