似乎沒有乾淨的方式來與API做到這一點。
由於我需要分離網格以刪除不需要的部分,因此我決定維護要從網格中移除的頂點和多邊形,並在沒有它們的情況下創建新的網格。
正如你在這個函數中看到的,我只是保持「好」的頂點和多邊形,然後我更新poly_connects列表中的頂點ID。
def regenerate_mesh(source_mesh, vertices_to_delete, poly_to_delete):
points = source_mesh.getPoints(om.MSpace.kWorld)
num_points = len(points)
i = 0
while i < num_points:
p1 = points[i]
for p2 in vertices_to_delete['points']:
if p1.x == p2.x and p1.y == p2.y and p1.z == p2.z:
points.remove(i)
num_points -= 1
break
else:
i += 1
polygon_counts, polygon_connects = source_mesh.getVertices()
i = j = 0
polygon_counts_length = len(polygon_counts)
while i < polygon_counts_length:
k = 0
for poly in poly_to_delete:
if poly == polygon_connects[j:j+polygon_counts[i]]:
for l in range(polygon_counts[i]):
polygon_connects.remove(j)
polygon_counts.remove(i)
polygon_counts_length -= 1
break
else:
while k < polygon_counts[i]:
if polygon_connects[j+k] in vertices_to_delete['indices']:
for l in range(polygon_counts[i]):
polygon_connects.remove(j)
polygon_counts.remove(i)
polygon_counts_length -= 1
break
k += 1
else:
j += k
i += 1
# update indices
for vertex in sorted(vertices_to_delete['indices'], reverse=True):
for index, new_vertex in enumerate(polygon_connects):
if new_vertex > vertex:
polygon_connects[index] -= 1
new_mesh = om.MFnMesh()
new_mesh.create(points, polygon_counts, polygon_connects)
如果有人找到更清潔的方式,我會很高興知道並將其標記爲解決方案!
我希望我更喜歡使用API方法來幫助你。看起來'extractFaces'就是那個,但它也不適合我。如果我找到任何東西,我會盡力深入挖掘並告訴你。 –
@GreenCell謝謝你的試用!我真的很感激 – Jiloc