当前位置:   article > 正文

maya t-pose 获取所有节点的初始位置

maya t-pose 获取所有节点的初始位置

目录

maya设置t-pose

maya把第1帧设置为t-pose,mel脚本:

maya获取所有节点的初始位置

获取所有节点的 动画旋转位置


maya设置t-pose

maya不支持直接导出bvh,网上有导出bvh脚本,导出后,用blender打开,发现初始姿态是错的

,就是t-pose不对

目前用曲折方法,先用maya导出fbx,然后用blender导入fbx,导出为bvh,

blender会把fbx的第1帧设置为t-pose

maya把第1帧设置为t-pose,mel脚本:

  1. select -r f_avg_Pelvis f_avg_L_Hip f_avg_L_Knee f_avg_L_Ankle f_avg_L_Foot f_avg_R_Hip f_avg_R_Knee f_avg_R_Ankle f_avg_R_Foot f_avg_Spine1 f_avg_Spine2 f_avg_Spine3 f_avg_Neck f_avg_Head f_avg_L_Collar f_avg_L_Shoulder f_avg_L_Elbow f_avg_L_Wrist f_avg_L_Hand f_avg_R_Collar f_avg_R_Shoulder f_avg_R_Elbow f_avg_R_Wrist f_avg_R_Hand ;
  2. string $selToTpose[] =`ls -sl`;
  3. for ($each in $selToTpose)
  4. {
  5. setAttr ($each +".r") 0 0 0 ;
  6. setKeyframe $each;
  7. }
  8. currentTime 0 ;

maya获取所有节点的初始位置

  1. import maya.cmds as cmds
  2. def get_initial_pose(root_node):
  3. """
  4. 获取根节点及其所有子节点的初始姿态位置。
  5. 参数:
  6. - root_node: 根节点的名称。
  7. 返回值:
  8. - 一个包含节点名称及其初始位置、旋转和缩放值的字典。
  9. """
  10. # 将时间设置为第一帧(假设第一帧为初始姿态)
  11. cmds.currentTime(1)
  12. # 包括根节点在内的所有子节点
  13. all_nodes = [root_node] + (cmds.listRelatives(root_node, allDescendents=True, fullPath=True) or [])
  14. # 用于存储每个节点的初始姿态的字典
  15. initial_poses = {}
  16. # 遍历所有节点并获取它们的初始位置、旋转和缩放值
  17. for node in all_nodes:
  18. # 检查节点是否存在(可能的话)
  19. if not cmds.objExists(node):
  20. continue
  21. position = cmds.xform(node, q=True, ws=True, t=True)
  22. rotation = cmds.xform(node, q=True, ws=True, ro=True)
  23. scale = cmds.xform(node, q=True, ws=True, s=True)
  24. initial_poses[node] = {
  25. 'position': position,
  26. 'rotation': rotation,
  27. 'scale': scale
  28. }
  29. return initial_poses
  30. # 示例用法
  31. root_node_name = '根节点名称' # 替换为实际的根节点名称
  32. initial_poses = get_initial_pose(root_node_name)
  33. for node, pose in initial_poses.items():
  34. print(f"Node: {node}, Position: {pose['position']}, Rotation: {pose['rotation']}, Scale: {pose['scale']}")

获取所有节点的 动画旋转位置

  1. import maya.cmds as cmds
  2. def get_animation_rotation_data(root_node):
  3. """
  4. 获取根节点及其所有子节点的动画旋转位置数据。
  5. 参数:
  6. - root_node: 根节点的名称。
  7. 返回值:
  8. - 一个字典,包含节点名称和其所有关键帧的旋转数据。
  9. """
  10. # 包括根节点在内的所有子节点
  11. all_nodes = [root_node] + (cmds.listRelatives(root_node, allDescendents=True, fullPath=True) or [])
  12. # 用于存储每个节点的动画旋转数据的字典
  13. animation_data = {}
  14. # 遍历所有节点并获取它们的动画旋转数据
  15. for node in all_nodes:
  16. # 检查节点是否存在(可能的话)
  17. if not cmds.objExists(node):
  18. continue
  19. # 用于存储当前节点的动画旋转数据
  20. node_data = {'rotateX': [], 'rotateY': [], 'rotateZ': []}
  21. # 获取每个旋转轴的关键帧
  22. for axis in ['rotateX', 'rotateY', 'rotateZ']:
  23. keyframes = cmds.keyframe(node, attribute=axis, query=True) or []
  24. keyframe_values = cmds.keyframe(node, attribute=axis, query=True, valueChange=True) or []
  25. # 存储当前轴的关键帧及其值
  26. for frame, value in zip(keyframes, keyframe_values):
  27. node_data[axis].append((frame, value))
  28. animation_data[node] = node_data
  29. return animation_data
  30. # 示例用法
  31. root_node_name = '根节点名称' # 替换为实际的根节点名称
  32. animation_rotations = get_animation_rotation_data(root_node_name)
  33. # 打印结果
  34. for node, data in animation_rotations.items():
  35. print(f"Node: {node}")
  36. for axis, keyframes in data.items():
  37. print(f" {axis}: {keyframes}")

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/435090
推荐阅读
相关标签
  

闽ICP备14008679号