標題有點抽象,但我認爲它對我所尋找的內容是準確的。 具體給出一個多邊形邊的列表,將所有由頂點連接的邊組合在一起。按常用元素排序項目
我知道這應該是一個簡單的問題,但我一直在找到錯誤的解決方案。
例如輸入:
looseComponents = cmds.ls(sl=True, fl=True)
# Result: [u'pCube1.e[3]', u'pCube1.e[6]'] #
獲取輸出:
found 2 component sets
[u'pCube1.e[3]']
[u'pCube1.e[3]']
預計輸出繼電器:
found 2 component sets
[u'pCube1.e[3]']
[u'pCube1.e[6]']
這是我的那一刻,它運行在Maya中,寫在蟒蛇。
looseComponents = cmds.ls(sl=True, fl=True)
#build sub item lookup
componentVerts = {}
for component in looseComponents:
verts = cmds.ls(cmds.polyListComponentConversion(component, toVertex=True), fl=True)
vertIds = []
for vert in verts:
i = int(vert.split('[')[-1].strip(']'))
vertIds.append(i)
componentVerts[component] = set(vertIds)
sortedComponents = 0
totalComponents = len(looseComponents)
componentSets = [ [] ]
componentSets[0].append(looseComponents[0])
sortedComponents += 1
while sortedComponents < totalComponents:
# for each subSetA of setA
foundConnectingSet = False
for i in range(len(componentSets)):
# for each itemA of subSetA
for j in range(len(componentSets[i])):
# for each itemB of setB
for h in range(len(looseComponents)):
# check if itemA and itemB share a sub item
if componentVerts[componentSets[i][j]] & componentVerts[looseComponents[h]]:
# if itemB isn't already part of this subSetA
if looseComponents[h] not in componentSets[i]:
# add itemB to this subSetA
componentSets[i].append(looseComponents[h])
sortedComponents += 1
foundConnectingSet = True
if not foundConnectingSet:
starter = looseComponents[0]
for i in range(len(componentSets)):
looseComponents = list(set(looseComponents) - set(componentSets[i]))
componentSets.append([ starter ])
sortedComponents += 1
print 'found ' +str(len(componentSets))+ ' component sets'
for componentSet in componentSets:
cmds.confirmDialog()
cmds.select(componentSet, replace=True)
print cmds.ls(sl=True)
有了一個邊緣選擇,我得到一組。 選擇了兩個不相連的邊,我得到了兩組,但兩組的邊都有相同的邊。
注意,當DOI ng(因爲我在範圍內(len(foo))',你也可以'爲我,_在枚舉(foo)'。 – Amber
這是如何「排序」?我認爲說你正在分類多邊形是更正確的。另外,如果沒有獲得的輸出以及希望獲得的預期輸出,很難準確理解您想要的結果。 – Bakuriu
true,編輯帖子以添加示例輸入,輸出和預期輸出。 –