添加旋转旋转约束

import bpy

# 定义骨架中骨骼的映射关系
bone_mapping = {
    "mixamorig:Hips": "Pelvis",
    "mixamorig:LeftUpLeg": "Left_Thigh",
    "mixamorig:LeftLeg": "Left_Calf",
    "mixamorig:LeftFoot": "Left_Foot",
    "mixamorig:LeftHand": "Left_Hand",  # 假设Left_Toe0没有旋转约束
    "mixamorig:RightUpLeg": "Right_Thigh",
    "mixamorig:RightLeg": "Right_Calf",
    "mixamorig:RightFoot": "Right_Foot",
    "mixamorig:RightHand": "Right_Hand",  # 假设Right_Toe0没有旋转约束
    "mixamorig:Spine": "Spine",
    "mixamorig:Spine1": "Spine1",
    "mixamorig:Spine2": "Spine2",
    "mixamorig:RightShoulder": "Right_Clavicle",
    "mixamorig:RightArm": "Right_UpperArm",
    "mixamorig:RightForeArm": "Right_Forearm",
    "mixamorig:Neck": "Neck",
    "mixamorig:Head": "Head",
    "mixamorig:LeftShoulder": "Left_Clavicle",
    "mixamorig:LeftArm": "Left_UpperArm",
    "mixamorig:LeftForeArm": "Left_Forearm",
}

# 要添加约束的骨架名称
source_armature_name = "Armature"
target_armature_name = "Biped_Root"

# 找到源骨架和目标骨架对象
source_armature_obj = bpy.data.objects.get(source_armature_name)
target_armature_obj = bpy.data.objects.get(target_armature_name)

if source_armature_obj and target_armature_obj and source_armature_obj.type == 'ARMATURE' and target_armature_obj.type == 'ARMATURE':
    # 遍历映射关系,为每个骨骼添加复制旋转约束
    for source_bone_name, target_bone_name in bone_mapping.items():
        source_bone = source_armature_obj.pose.bones.get(source_bone_name)
        target_bone = target_armature_obj.pose.bones.get(target_bone_name)
        
        if source_bone and target_bone:
            # 添加复制旋转约束
            constraint = source_bone.constraints.new('COPY_ROTATION')
            constraint.target = target_armature_obj
            constraint.subtarget = target_bone.name
            print(f"Added COPY_ROTATION constraint from {source_bone_name} to {target_bone_name}.")
        else:
            print(f"One or both bones not found: {source_bone_name}, {target_bone_name}")
else:
    print(f"One or both armatures not found or not of type ARMATURE: {source_armature_name}, {target_armature_name}")

添加复制位置约束

 

import bpy

# 定义骨架中骨骼的映射关系
bone_mapping = {
    "mixamorig:Hips": "Pelvis",
    "mixamorig:LeftUpLeg": "Left_Thigh",
    "mixamorig:LeftLeg": "Left_Calf",
    "mixamorig:LeftFoot": "Left_Foot",
    "mixamorig:LeftHand": "Left_Hand",  # 假设Left_Toe0没有旋转约束
    "mixamorig:RightUpLeg": "Right_Thigh",
    "mixamorig:RightLeg": "Right_Calf",
    "mixamorig:RightFoot": "Right_Foot",
    "mixamorig:RightHand": "Right_Hand",  # 假设Right_Toe0没有旋转约束
    "mixamorig:Spine": "Spine",
    "mixamorig:Spine1": "Spine1",
    "mixamorig:Spine2": "Spine2",
    "mixamorig:RightShoulder": "Right_Clavicle",
    "mixamorig:RightArm": "Right_UpperArm",
    "mixamorig:RightForeArm": "Right_Forearm",
    "mixamorig:Neck": "Neck",
    "mixamorig:Head": "Head",
    "mixamorig:LeftShoulder": "Left_Clavicle",
    "mixamorig:LeftArm": "Left_UpperArm",
    "mixamorig:LeftForeArm": "Left_Forearm",
}

# 要添加约束的骨架名称
source_armature_name = "Armature"
target_armature_name = "Biped_Root"

# 找到源骨架和目标骨架对象
source_armature_obj = bpy.data.objects.get(source_armature_name)
target_armature_obj = bpy.data.objects.get(target_armature_name)

if source_armature_obj and target_armature_obj and source_armature_obj.type == 'ARMATURE' and target_armature_obj.type == 'ARMATURE':
    # 遍历映射关系,为每个骨骼添加复制旋转约束
    for source_bone_name, target_bone_name in bone_mapping.items():
        source_bone = source_armature_obj.pose.bones.get(source_bone_name)
        target_bone = target_armature_obj.pose.bones.get(target_bone_name)
        
        if source_bone and target_bone:
            # 添加复制旋转约束
            constraint = source_bone.constraints.new('COPY_LOCATION')
            constraint.target = target_armature_obj
            constraint.subtarget = target_bone.name
            print(f"Added COPY_ROTATION constraint from {source_bone_name} to {target_bone_name}.")
        else:
            print(f"One or both bones not found: {source_bone_name}, {target_bone_name}")
else:
    print(f"One or both armatures not found or not of type ARMATURE: {source_armature_name}, {target_armature_name}")

 视频地址:只用Blender将小k动捕转换为mmd动作数据,超简单,麻瓜都能学会的教程_哔哩哔哩_bilibili

导入骨骼,缩放改为12,

  小K网骨头,骨头编辑模式,spine骨头, alt+F ,翻转骨头,

posted on 2024-06-22 08:44  大话人生  阅读(60)  评论(0编辑  收藏  举报