首页 > 其他分享 >maya获取所有节点的初始位置

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

时间:2024-04-08 22:32:38浏览次数:20  
标签:node maya root cmds data True 节点 初始

目录

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

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


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

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}")

标签:node,maya,root,cmds,data,True,节点,初始
From: https://blog.csdn.net/jacke121/article/details/137502124

相关文章

  • Acwing 681. 疏散人群(dfs)(记录根节点下有几个子节点)
    输入样例:62132435261输出样例:4#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;typedefpair<LL,LL>PII;constLLN=100200,M=2020;constLLmod=998244353;vector<LL>g[N];LLsum[N];LLdfs(LLidx,LLfa){LL......
  • 递归寻找节点
    publicclassFileNode:PropertyChangedBase{publicFileNode(){this.Files=newObservableCollection<FileNode>();this.IsFile=false;}privatestring_name=string.Empty;......
  • C#实现的下拉多选框,下拉多选树,多级节点
    今天给大家上个硬货,下拉多选框,同时也是下拉多选树,支持父节点跟子节点!该控件是基于Telerik控件封装实现的,所以大家在使用的过程中需要引用Telerik.WinControls.dll、Telerik.WinControls.UI.dll,还有一些相关的类库,大家有需要的可以去网上自己找,另外我也会把一些动态库放到CSDN......
  • [INS-30131] 执行安装程序验证所需的初始设置失败
    一、基础环境  操作系统:MicrosoftWindowsServer2012R2Standard(64位)  数据库版本:OracleDatabase11.2.0.4.0(64位)二、问题详情    在安装过程中,报错:[INS-30131]执行安装程序验证所需的初始设置失败。点击【详细信息】,弹出以下内容:附加信息:所有节点上的框架设置检......
  • c++类与对象<三>初始化列表,静态成员,友元,匿名对象
    目录前言一:再次认识构造函数之成员初始化列表初始化成员变量1.类对象整体的定义与对象中每个成员变量的定义2.初始化列表3.explicit 关键字二:static成员 1.概念2.经典实例:实现一个类,计算程序中创建出了多少个类对象3.特点总结 三:匿名对象 1.匿名对象就像结构体......
  • 单节点部署K8S
    K使用Kubeadm搭建单节点安装前注意进行快照,方便多次安装练习。虚拟机基础信息系统:Ubuntu20.04.6LTS内核:5.15.0-67-generic硬盘:60G内存:12GCPU:4C4U本次安装参考博客地址:https://glory.blog.csdn.net/article/details/120606787安装前准备1.关闭防火墙systemctlstat......
  • 最小化安装Ubutun后的初始化操作
    最小化安装Ubutun后的初始化操作由于Ubutub相关配置路径与红帽系操作系统有些差异,这边进行一些简单初始化记录。使用的操作系统镜像为:ubuntu-20.04.6-desktop-amd64.iso1.root账户配置使用该镜像安装系统,没有红帽系安装过程中对root用户的配置。需要进入系统后使用sudopassw......
  • XML文档节点导航与选择指南 | XPath基础知识
    XPath(XMLPathLanguage)是XSLT标准的主要组成部分。它用于在XML文档中浏览元素和属性,提供了一种强大的定位和选择节点的方式。XPath的基本特点代表XML路径语言:XPath是一种用于在XML文档中导航和选择节点的语言。路径样式语法:XPath使用路径表达式的“路径样式”语......
  • 【完美复现】面向配电网韧性提升的移动储能预布局与动态调度策略【IEEE33节点】(Matlab
     ......
  • 初始SQLAlemy
    安装#通过包管理工具安装pipinstallsqlalchemy#查看安装的版本In[4]:sqlalchemy.__version__Out[4]:'2.0.28'链接数据库#链接MySQL#链接MySQL的前提是已经安装了mysqlclient#pipinstallmysqlclientIn[6]:fromsqlalchemyimportcreate_engine #......