赞
踩
目录
- import maya.cmds as cmds
-
- def get_initial_pose(root_node):
- """
- 获取根节点及其所有子节点的初始姿态位置。
- 参数:
- - root_node: 根节点的名称。
- 返回值:
- - 一个包含节点名称及其初始位置、旋转和缩放值的字典。
- """
- # 将时间设置为第一帧(假设第一帧为初始姿态)
- cmds.currentTime(1)
-
- # 包括根节点在内的所有子节点
- all_nodes = [root_node] + (cmds.listRelatives(root_node, allDescendents=True, fullPath=True) or [])
-
- # 用于存储每个节点的初始姿态的字典
- initial_poses = {}
-
- # 遍历所有节点并获取它们的初始位置、旋转和缩放值
- for node in all_nodes:
- # 检查节点是否存在(可能的话)
- if not cmds.objExists(node):
- continue
- position = cmds.xform(node, q=True, ws=True, t=True)
- rotation = cmds.xform(node, q=True, ws=True, ro=True)
- scale = cmds.xform(node, q=True, ws=True, s=True)
- initial_poses[node] = {
- 'position': position,
- 'rotation': rotation,
- 'scale': scale
- }
-
- return initial_poses
-
- # 示例用法
- root_node_name = '根节点名称' # 替换为实际的根节点名称
- initial_poses = get_initial_pose(root_node_name)
- for node, pose in initial_poses.items():
- print(f"Node: {node}, Position: {pose['position']}, Rotation: {pose['rotation']}, Scale: {pose['scale']}")
- import maya.cmds as cmds
-
- def get_animation_rotation_data(root_node):
- """
- 获取根节点及其所有子节点的动画旋转位置数据。
- 参数:
- - root_node: 根节点的名称。
- 返回值:
- - 一个字典,包含节点名称和其所有关键帧的旋转数据。
- """
- # 包括根节点在内的所有子节点
- all_nodes = [root_node] + (cmds.listRelatives(root_node, allDescendents=True, fullPath=True) or [])
-
- # 用于存储每个节点的动画旋转数据的字典
- animation_data = {}
-
- # 遍历所有节点并获取它们的动画旋转数据
- for node in all_nodes:
- # 检查节点是否存在(可能的话)
- if not cmds.objExists(node):
- continue
-
- # 用于存储当前节点的动画旋转数据
- node_data = {'rotateX': [], 'rotateY': [], 'rotateZ': []}
-
- # 获取每个旋转轴的关键帧
- for axis in ['rotateX', 'rotateY', 'rotateZ']:
- keyframes = cmds.keyframe(node, attribute=axis, query=True) or []
- keyframe_values = cmds.keyframe(node, attribute=axis, query=True, valueChange=True) or []
-
- # 存储当前轴的关键帧及其值
- for frame, value in zip(keyframes, keyframe_values):
- node_data[axis].append((frame, value))
-
- animation_data[node] = node_data
-
- return animation_data
-
- # 示例用法
- root_node_name = '根节点名称' # 替换为实际的根节点名称
- animation_rotations = get_animation_rotation_data(root_node_name)
-
- # 打印结果
- for node, data in animation_rotations.items():
- print(f"Node: {node}")
- for axis, keyframes in data.items():
- print(f" {axis}: {keyframes}")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。