You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Maya Python脚本获取点及顶点的XYZ坐标数值?

Maya Python 获取坐标方法

获取任意点的XYZ坐标

  • 若要获取选中的点组件(如孤立点、曲线控制点等)的坐标,可直接使用cmds.pointPosition():
    # 获取选中点的坐标,返回包含XYZ的列表
    selected_point = cmds.ls(selection=True)[0]
    point_coords = cmds.pointPosition(selected_point)
    print(f"X: {point_coords[0]}, Y: {point_coords[1]}, Z: {point_coords[2]}")
    
  • 若需自定义任意空间点,直接定义坐标元组即可提取分量:
    # 手动指定任意点坐标
    custom_point = (12.4, 8.9, -3.2)
    x, y, z = custom_point
    print(f"X分量: {x}, Y分量: {y}, Z分量: {z}")
    

获取模型顶点的XYZ坐标分量

单个顶点坐标获取

使用cmds.xform或cmds.pointPosition均可,示例如下:

# 指定目标顶点,比如立方体的第一个顶点
target_vertex = "pCube1.vtx[0]"
# 获取世界空间下的坐标
world_coords = cmds.xform(target_vertex, q=True, t=True, ws=True)
# 拆分XYZ分量
x_comp, y_comp, z_comp = world_coords
print(f"顶点{target_vertex}:X={x_comp}, Y={y_comp}, Z={z_comp}")

批量获取所有顶点坐标

如果需要一次性获取模型所有顶点的坐标,可遍历顶点列表:

# 替换为你的模型名称
mesh = "pSphere1"
# 获取模型所有顶点的完整路径
all_vertices = cmds.ls(f"{mesh}.vtx[*]", flatten=True)

# 逐个输出顶点坐标分量
for vtx in all_vertices:
    # 开启worldSpace=True获取世界空间坐标,关闭则为局部空间
    coords = cmds.pointPosition(vtx, worldSpace=True)
    print(f"{vtx} -> X: {coords[0]:.2f}, Y: {coords[1]:.2f}, Z: {coords[2]:.2f}")

关键参数说明

  • worldSpace=True:切换为世界空间坐标,默认是模型局部空间
  • q=True/query=True:在xform中表示查询模式,而非修改

内容的提问来源于stack exchange,提问作者bobobobo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 05:10:14