【问题标题】:How to get rid of selection order for triangulation如何摆脱三角测量的选择顺序
【发布时间】:2014-12-29 16:09:23
【问题描述】:

我正在尝试创建一个三角测量(不确定这是否是正确的词)脚本?基本上我想要实现的是从定位器的选择中创建一个多边形(它必须是 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)

【问题讨论】:

标签: python selection maya


【解决方案1】:

一个快速的解决方案是让用户自行决定选择顺序。为此,在cmds.ls() 中使用orderedSelection 标志而不是selection 标志,并在for 循环定义中去掉sorted() 方法。这样就根据用户的选择顺序创建了一个多边形。

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

【讨论】:

  • 抱歉回复晚了,我试过你说的方法,对纠正手头的问题没有帮助。它仍然给了我第二张照片中的“交叉”多边形。不过,感谢您提供的链接。目前,做这样的算法有点遥不可及:)
  • 使用 orderedSelection 的技术只是让用户以正确的顺序选择定位器。除非用户随机选择定位器或只是通过任意拖动选择,否则它不会失败。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-07
  • 1970-01-01
  • 1970-01-01
  • 2015-08-03
  • 2011-08-24
相关资源
最近更新 更多