• AIGC笔记--Maya提取和修改FBX动作文件


    目录

    1--Maya数据解析

    2--FBX SDK导出6D数据

    3--6D数据映射和Maya可视化


    完整项目代码:Data-Processing/FBX_SDK_Maya

    1--Maya数据解析

    在软件Maya中直接拖入FBX文件,可以播放和查看人体各个骨骼关节点的数据:

            对于上图来说,平移X、平移Y和平移Z表示关节点的Local Transaction的坐标,而旋转X、旋转Y、旋转Z表示关节点的Euler Rotation坐标;对于一个固定的人体模型,修改每一帧中各个关节点的上述六个坐标,即可改变人体表现的动作;

            在Maya中,可以通过以下脚本在Python编辑器(窗口→常规编辑器→脚本编辑器)中打印所有帧所有关节的上述6D坐标数据:

    1. '''
    2. @File : print_joint_6Ddata_maya.py
    3. @Time : 2024/03/07 20:05:00
    4. @Author : Jinfu Liu
    5. @Version : 1.0
    6. @Desc : print 6D data of joint in FBX file
    7. '''
    8. import maya.cmds as cmds
    9. joint_names = ["root", "pelvis", "spine_00", "spine_01", "spine_02", "spine_03", "clavicle_l", "upperarm_l", "lowerarm_l", "hand_l", "index_01_l",
    10. "index_02_l", "index_03_l", "middle_01_l", "middle_02_l", "middle_03_l", "pinky_01_l", "pinky_02_l", "pinky_03_l", "ring_01_l", "ring_02_l",
    11. "ring_03_l", "thumb_01_l", "thumb_02_l", "thumb_03_l", "Slot_hand_L_bone", "clavicle_r", "upperarm_r", "lowerarm_r", "hand_r", "index_01_r",
    12. "index_02_r", "index_03_r", "middle_01_r", "middle_02_r", "middle_03_r", "pinky_01_r", "pinky_02_r", "pinky_03_r", "ring_01_r", "ring_02_r",
    13. "ring_03_r", "thumb_01_r", "thumb_02_r", "thumb_03_r", "Slot_hand_R_bone", "Slot_spine_bone", "neck_01", "head", "thigh_l", "calf_l","foot_l",
    14. "ball_l", "thigh_r", "calf_r", "foot_r", "ball_r", "Slot_waist_L_bone", "Slot_waist_R_bone", "Slot_pelvis_bone", "ik_foot_root", "ik_foot_l",
    15. "ik_foot_r", "ik_hand_root", "ik_hand_gun", "ik_hand_l", "ik_hand_r"]
    16. for joint in joint_names:
    17. obj = cmds.ls(joint)
    18. print("process ", obj)
    19. keyframes = cmds.keyframe(obj, query=True)
    20. for frame in keyframes:
    21. local_trans_X = cmds.getAttr(joint + ".translateX", time = frame)
    22. local_trans_Y = cmds.getAttr(joint + ".translateY", time = frame)
    23. local_trans_Z = cmds.getAttr(joint + ".translateZ", time = frame)
    24. local_rotate_X = cmds.getAttr(joint + ".rotateX", time = frame)
    25. local_rotate_Y = cmds.getAttr(joint + ".rotateY", time = frame)
    26. local_rotate_Z = cmds.getAttr(joint + ".rotateZ", time = frame)
    27. print(local_trans_X, local_trans_Y, local_trans_Z)
    28. print(local_rotate_X, local_rotate_Y, local_rotate_Z)

    2--FBX SDK导出6D数据

    通过Python FBX SDK,我们可以提取和保存在一个原始FBX文件中对应于Maya可视化的6D坐标,具体的脚本如下:FBX_SDK_Maya/Extract_local_TR.py

    3--6D数据映射和Maya可视化

            通过第2步的脚本可以提取人体运动的关键6D坐标数据,这些6D坐标数据可以进行一些动作生成任务,生成相同意义的坐标数据。原始6D或生成的6D坐标数据可以使用以下脚本,并在Maya中进行可视化:

    1. '''
    2. @File : set_joint_6Ddata_maya.py
    3. @Time : 2024/03/07 20:10:00
    4. @Author : Jinfu Liu
    5. @Version : 1.0
    6. @Desc : set 6D data of joint in FBX file
    7. '''
    8. # you must install numpy by: mayapy.exe -m pip install numpy
    9. import numpy as np
    10. import maya.cmds as cmds
    11. Joint_to_idx = {
    12. "root": 0,
    13. "pelvis": 1,
    14. "spine_00": 2,
    15. "spine_01": 3,
    16. "spine_02": 4,
    17. "spine_03": 5,
    18. "clavicle_l": 6,
    19. "upperarm_l": 7,
    20. "lowerarm_l": 8,
    21. "hand_l": 9,
    22. "index_01_l": 10,
    23. "index_02_l": 11,
    24. "index_03_l": 12,
    25. "middle_01_l": 13,
    26. "middle_02_l": 14,
    27. "middle_03_l": 15,
    28. "pinky_01_l": 16,
    29. "pinky_02_l": 17,
    30. "pinky_03_l": 18,
    31. "ring_01_l": 19,
    32. "ring_02_l": 20,
    33. "ring_03_l": 21,
    34. "thumb_01_l": 22,
    35. "thumb_02_l": 23,
    36. "thumb_03_l": 24,
    37. "Slot_hand_L_bone": 25,
    38. "clavicle_r": 26,
    39. "upperarm_r": 27,
    40. "lowerarm_r": 28,
    41. "hand_r": 29,
    42. "index_01_r": 30,
    43. "index_02_r": 31,
    44. "index_03_r": 32,
    45. "middle_01_r": 33,
    46. "middle_02_r": 34,
    47. "middle_03_r": 35,
    48. "pinky_01_r": 36,
    49. "pinky_02_r": 37,
    50. "pinky_03_r": 38,
    51. "ring_01_r": 39,
    52. "ring_02_r": 40,
    53. "ring_03_r": 41,
    54. "thumb_01_r": 42,
    55. "thumb_02_r": 43,
    56. "thumb_03_r": 44,
    57. "Slot_hand_R_bone": 45,
    58. "Slot_spine_bone": 46,
    59. "neck_01": 47,
    60. "head": 48,
    61. "thigh_l": 49,
    62. "calf_l": 50,
    63. "foot_l": 51,
    64. "ball_l": 52,
    65. "thigh_r": 53,
    66. "calf_r": 54,
    67. "foot_r": 55,
    68. "ball_r": 56,
    69. "Slot_waist_L_bone": 57,
    70. "Slot_waist_R_bone": 58,
    71. "Slot_pelvis_bone": 59,
    72. "ik_foot_root": 60,
    73. "ik_foot_l": 61,
    74. "ik_foot_r": 62,
    75. "ik_hand_root": 63,
    76. "ik_hand_gun": 64,
    77. "ik_hand_l": 65,
    78. "ik_hand_r": 66
    79. }
    80. Local_Trans_data = np.load("C:/Users/jinfullliu/Desktop/test_maya/Local_Trans.npy", allow_pickle = True)
    81. local_Rotate_data = np.load("C:/Users/jinfullliu/Desktop/test_maya/local_Rotate.npy", allow_pickle = True)
    82. for joint in Joint_to_idx:
    83. joint_idx = Joint_to_idx[joint]
    84. obj = cmds.ls(joint)
    85. print("process ", obj)
    86. for frame in range(Local_Trans_data.shape[0]):
    87. cmds.setKeyframe(joint + '.translateX', value = Local_Trans_data[frame, joint_idx, 0], time=frame)
    88. cmds.setKeyframe(joint + '.translateY', value = Local_Trans_data[frame, joint_idx, 1], time=frame)
    89. cmds.setKeyframe(joint + '.translateZ', value = Local_Trans_data[frame, joint_idx, 2], time=frame)
    90. cmds.setKeyframe(joint + '.rotateX', value = local_Rotate_data[frame, joint_idx, 0], time=frame)
    91. cmds.setKeyframe(joint + '.rotateY', value = local_Rotate_data[frame, joint_idx, 1], time=frame)
    92. cmds.setKeyframe(joint + '.rotateZ', value = local_Rotate_data[frame, joint_idx, 2], time=frame)

  • 相关阅读:
    spring cloud gateway整合security实现统一权鉴
    Firewall Analyzer防火墙管理
    java计算机毕业设计高校医务管理系统源程序+mysql+系统+lw文档+远程调试
    交换机和路由器技术-16-生成树协议
    Vue3+vite中引入Echarts图表
    微信小程序云开发笔记-初始化商城小程序
    NumLevels
    扩大减产,NAND Flash市场迎来涨价潮 | 百能云芯
    AndroidUtil - 强大易用的安卓工具类库
    两款适合职场小白的实用软件推荐
  • 原文地址:https://blog.csdn.net/weixin_43863869/article/details/136616823