如何摆脱三角测量的选择顺序

时间:2014-11-03 02:15:41

标签: python selection maya

我正在尝试创建一个三角测量(不确定这是否是正确的单词)脚本?基本上我想要实现的是从定位器的选择中创建一个多边形(它必须是3个或更多定位器)

虽然我能够这样做,但我有这个选择问题的顺序。 例如。在我的场景中,有4个定位器 - loc1,loc2,loc3,loc4

如果我将loc1向上拖动到loc4,而不是像img01那样创建多边形,那么它是按照定位器编号排序的img02所示创建的? 在我看来,它是基于其定位器创建顺序对选择进行排序,其中这不是我想要做的事情

我错过了什么吗?

我的代码:

import maya.cmds as cmds

pts = []

cmds.select( cmds.listRelatives( type = 'locator', fullPath = True, allDescendents = True ) )
cmds.select( cmds.listRelatives( parent = True, fullPath = True ) )
sel = cmds.ls ( selection = True, type = 'transform' )

if not sel:
    cmds.warning( "Please select a locator / No locators in selection " )


for loc in sorted(sel):
    coords = cmds.xform (loc, query=True, worldSpace=True, pivots=True)[0:3]
    print coords
    pts.append(coords)

cmds.polyCreateFacet(p = pts)

img01 img02

1 个答案:

答案 0 :(得分:0)

快速解决方案是根据用户的判断给出选择顺序。为此,请在cmds.ls()中使用orderedSelection标志而不是selection标志,并删除sorted()循环定义中的for方法。这样,基于用户的选择顺序创建多边形。

如果你想更深入地研究无论如何都能工作的三角测量算法,请看@Basilevs提到的答案:Create non-intersecting polygon passing through all given points