Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign cluster to each shell in an object - Maya Python

Tags:

python

loops

maya

I'm quite a noob in Python. I can write a simple script to assign a cluster to vertexes of the selected objects.

Like this:

import maya.cmds as cmds

activeSelection = cmds.ls(selection=True)

for i in activeSelection:
  cmds.polyListComponentConversion( i, ff=True, tv=True, internal=True ) 
  cmds.cluster( i, rel=True )  

But it turned out I need to assign a cluster to vertexes of each individual polygon shell of the object. I've spent few hours searching and trying different scripts and trying to modify them but nothing seems to really work. Would you guys be so kind to give a hint?

Thank you,

Anton

like image 816
user7983923 Avatar asked Dec 05 '25 10:12

user7983923


1 Answers

If you don't want to separate and then re-combine your mesh (to keep clean history, or you're restricted from modifying the geo in any way except deformers for some reason...), you could use this to "separate" your shells out non-destructively

import maya.cmds as mc

shells = []
face_count = mc.polyEvaluate(geom, f=True)
faces = set(range(face_count))
for face in xrange(face_count):
    if face in faces:
        shell_indices = mc.polySelect(geom, q=True, extendToShell=face)
        shell_faces = ['%s.f[%d]' %(geom, i) for i in shell_indices]
        shells.append(mc.polyListComponentConversion(shell_faces, toVertex=True))
        faces -= set(shell_indices)
    elif not faces:
        break

this will give you a list where each item is a list of cps for a shell. All that's left to do is to cluster each item of the shells list

like image 174
silent_sight Avatar answered Dec 07 '25 16:12

silent_sight



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!