随笔 - 633,  文章 - 0,  评论 - 13,  阅读 - 48万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

1.选中骨骼,进入姿态模式

2.全选所有骨骼

3.运行代码

代码:

复制代码
import bpy
import csv
import os

# 获取当前活动的骨架对象
armature = bpy.context.view_layer.objects.active

# 检查选择的对象是否是骨架
if armature.type != 'ARMATURE' or not armature.pose.bones:
    print("The active object is not an armature or does not have pose bones.")
else:
    # 获取骨架的所有姿势骨骼
    pose_bones = armature.pose.bones

    # 获取动画的帧范围
    frame_start = bpy.context.scene.frame_start
    frame_end = bpy.context.scene.frame_end

    # 定义CSV文件的名称和路径
    csv_filename = "bones_data.csv"
    csv_path = os.path.join(os.path.dirname(bpy.data.filepath), csv_filename)  # 使用项目路径

    # 打开CSV文件进行写入
    with open(csv_path, 'w', newline='') as csvfile:
        csvwriter = csv.writer(csvfile)
        # 写入标题行
        csvwriter.writerow(['Frame', 'Bone Name', 'Bone Position X', 'Bone Position Y', 'Bone Position Z', 'Rotation W', 'Rotation X', 'Rotation Y', 'Rotation Z', 'Scale X', 'Scale Y', 'Scale Z'])

        # 遍历所有帧
        for frame in range(frame_start, frame_end + 1):
            # 设置当前帧
            bpy.context.scene.frame_set(frame)

            # 遍历骨架中的所有姿势骨骼
            for bone in pose_bones:
                # 计算骨骼的近似位置(head和tail的中点)
                bone_position = (bone.head + bone.tail) / 2.0
                
                # 获取骨骼的四元数
                rotation_quat = bone.rotation_quaternion
                
                # 获取骨骼的缩放
                scale = bone.scale
                
                # 将骨骼信息写入CSV文件
                csvwriter.writerow([
                    frame,
                    bone.name,
                    bone_position.x, bone_position.y, bone_position.z,
                    rotation_quat.w, rotation_quat.x, rotation_quat.y, rotation_quat.z,
                    scale.x, scale.y, scale.z
                ])

    print(f"Data has been written to {csv_path}")
复制代码

 

posted on   大话人生  阅读(165)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2022-04-19 ubuntu设置数据库远程登录
点击右上角即可分享
微信分享提示