maya_mel语言中多边形点的提取和遍历操作方法

一、问题分析:

有老同事问我,想用maya mel语言为模型选择点,沿法向方向移动。如下图:
在这里插入图片描述
并使用了如下代码操作单个定点,成功了,:

string $pp[];
string $obj;
$pp = `ls -sl`;
for ($obj in $pp)
{   
    select -cl;
    select $obj;
    move -r -cs -ls -wd  1 0 0 ;
}

之后,又同时选择多个点操作,出现了如下错误。
请添加图片描述
点不再沿着法线移动而是垂直向上了。

二、解决方法:

分析研究后发现,maya对元素点线面的选择时,会以一种集合方式操作。必须使用 filterExpand 命令来转化为独立的单个元素,才能在for循环里调用:

用editplus文本编辑器,批量文件搜索工具在maya官方scripts脚本中查找filterExpand 用法:如下图:
在这里插入图片描述
发现了各类元素的分解方法:
看看多边形点的分解方式:

// Copyright 2017 Autodesk, Inc. All rights reserved.
//
// Use of this software is subject to the terms of the Autodesk license
// agreement provided at the time of installation or download, or which
// otherwise accompanies this software in either electronic or hard copy form.
// 
global proc string[] getVerts()
{
	select -r `polyListComponentConversion -tv`;
	string $result[]=`filterExpand -ex true -sm 31`;
	return $result;
}

以上程序可以把选择多边形元素转换为独立点集合。之后在用for就可以操作了。如下代码再测试一下:

string $pp[];
string $v;
$pp =` getVerts `;

for ($v in $pp)
{    
    select -cl;
    select $v;
    move -r -cs -ls -wd  1 0 0 ;   
}

成功了!阿弥陀佛
在这里插入图片描述

三、官方的filterExpand 命令文档如下:(通过edge浏览器翻译为中文)

命令 (MEL)	
过滤器展开
在类别中: 建模, NURBS
无帧

转到:剧情简介。返回值。相关。标志。MEL 示例。

概要
filterExpand [-expand boolean] [-fullPath boolean] [-selectionMask int] [-symActive] [-symNegative] [-symPositive] [-symSeam]

filterExpand 是不可操作、不可查询且不可编辑的。

根据选定的组件(或在命令行上指定的组件),命令将筛选和/或扩展给定选项的列表。返回包含所有匹配选择项的字符串数组。选择蒙版如下所示:
对象类型	面具
处理	0
努尔斯曲线	9
努尔布斯表面	10
努尔布斯曲面曲线	11
多边形	12
定位器 XYZ	22
方向定位器	23
紫外线定位器	24
控制顶点 (CV)	28
编辑点	30
多边形顶点	31
多边形边	32
多边形面	34
多边形 UV	35
细分网格点	36
细分网格边	37
细分网格面	38
曲线参数点	39
曲线结	40
曲面参数点	41
表面结	42
表面范围	43
修剪表面边缘	44
表面等臂	45
晶格点	46
粒子	47
缩放透视表	49
旋转枢轴	50
选择手柄	51
细分曲面	68
多边形顶点面	70
NURBS 表面面	72
细分网格 UV	73
返回值
字符串[]	命令结果
相关
选择类型
标志
expand, fullPath, selectionMask, symActive, symNegative, symPositive, symSeam
长名称(短名称)	参数类型	性能
-expand(-ex)	boolean	创造
如果这是真的,则每个项目都是一个实体。默认值为 true。
-fullPath(-fp)	boolean	创造
如果为 true 并且选择项是 DAG 对象,则仅当此值为 false 时,才返回其完整的选择路径,而不是对象的名称。默认值为 false。
-selectionMask(-sm)	int	创造多用途
指定选择蒙版
-symActive(-sma)		创造
如果启用了对称性,则仅返回对象活动对称侧的组件。如果对称性不处于活动状态,则此标志不起作用。
-symNegative(-smn)		创造
如果启用了对称性,则仅返回对象负侧相对于当前对称平面的分量。如果对称性不处于活动状态,则此标志不起作用。
-symPositive(-smp)		创造
If symmetry is enabled only return the components on the positive side of the object relative to the current symmetry plane. This flag has no effect if symmetry is not active.
-symSeam(-sms)		create
If symmetry is enabled only return the components that lie equally on both sides of the object relative to the current symmetry plane. This flag has no effect if symmetry is not active.
 Flag can appear in Create mode of command	 Flag can appear in Edit mode of command
 Flag can appear in Query mode of command	 Flag can be used more than once in a command.
MEL examples
// Returns any selected isoparms (mask 45) as individual items
// (because of "-ex true").
filterExpand -ex true -sm 45;

// Returns any selected CVs (mask 28) as compact items.  For example,
//   if curve.cv[0:3] is selected, then "curve.cv[0:3]" is returned.
//   If "-ex true", then four items are returned, one for each CV.
filterExpand -ex false -sm 28;

// Returns any selected CVs (mask 28) and edit points (mask 30).
filterExpand -sm 28 -sm 30;

// Returns any selected nurbs curves.
filterExpand -sm 9;

// Returns any selected nurbs curves-on-surface.
filterExpand -sm 11;

// return the poly faces (mask 34) from the specified arguments
filterExpand -sm 34 "pCube1.f[1]" "pCube1.f[4]" "pCube1.vtx[0:3]";

南无阿弥陀佛,哈哈哈。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Maya动画技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值