I threw together a cmds version of this code (but someone please confirm my
results. Maybe I did this wrong). I didn't really do anything to the actual
logic, other than switching from PyMel to cmds, and I also switched to
using a set, for an extra bit of performance increase, since the loop is
doing a lot of membership testing within the collection.
206 verts, 29 groups, speedup of 18.5x
<function test1 at 0x112031b8> 1.5795 sec, 29 groups
<function test4 at 0x105c1cf8> 0.0841 sec, 29 groups
418 verts, 47 groups, speed of 42.12
<function test1 at 0x11203140> 7.2657 sec, 47 groups
<function test4 at 0x1149eb90> 0.1725 sec, 47 groups
def test4():
unmatched_vtxs = cmds.ls(sl=True, fl=True)
vtx_grps = []
while len(unmatched_vtxs) > 0:
# grab a vertex
vtx = unmatched_vtxs.pop()
grp = [vtx]
vtx_grps.append(grp)
# create a list that will contain all of the vertices around
# the edge of the group, starting with all of the connected
# verts for the start vert
edge_vtxs = set(connectedVertices(vtx))
matched_vtx = vtx
# continue to try to find more verts to add to the group if we
# add a new vert, if not we can loop to the creating the next group
while matched_vtx is not None:
matched_vtx = None
for unmatched_vtx in unmatched_vtxs:
if unmatched_vtx in edge_vtxs:
matched_vtx = unmatched_vtx
# if one of the unmatched verts is on the edge of
# our group add it to the group
grp.append(matched_vtx)
# remove it from the edge list
edge_vtxs.remove(matched_vtx)
# add all of the new matched verts connected verts if
# they aren't already in the list
for added_conn_vtx in connectedVertices(matched_vtx):
if added_conn_vtx not in edge_vtxs:
edge_vtxs.add(added_conn_vtx)
break
# remove the matched vert from our list of unmatched ones
if matched_vtx is not None:
unmatched_vtxs.remove(matched_vtx)
return vtx_grps
def connectedVertices(vtx):
edges = cmds.polyListComponentConversion(vtx, fv=True, te=True)
vtxs = cmds.polyListComponentConversion(edges, fe=True, tv=True)
return cmds.ls(vtxs, fl=True)
On Fri, Oct 10, 2014 at 10:28 AM, <[email protected]> wrote:
> Hey Jack,
>
> I noticed that yesterday when playing around with it a bit. In certain
> cases, it would give me some extra groups, depending on how I selected the
> verts. It makes sense.
>
> I'm gonna have to pick apart your code to understand it a bit better. I
> had a feeling this stuff was gonna be fairly slow. It will lend itself to a
> rigging workflow, where someone can select whatever components, and build
> nulls and whatnot at the computed transform of those vert groups. It
> shouldn't ever really receive that many components, and the component
> selections can be simplified to speed it up a bit.
>
> I'd love to see the speed of something similar written with maya.cmds. or
> even mel. I guess I veered towards pymel, since coming from softimage.
> Can't say i'd get very far with cmds ;)
>
> Thanks for all your help
> Kev
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/67a6844f-8682-4ac4-b895-fa5c25e60ab3%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2JZx%2BRNpiaHdusFTXBvnjuM9i4BmqR9KfyOzevJH1ZdA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.