I am trying to create a triangulation (not sure if this is the right word) script? Basically what I am trying to achieve is selecting the locators and create a polygon out of it.
But currently while I am able to do so, I am having this problem.
Eg. In my scene, there are 4 locators - loc1, loc2, loc3, loc4
If I drag select from the loc1 upwards to loc4, instead of creating the polygon like in img01, it is created as shown in img02 ordered by the locator numbering sort of?
Am I missing something?
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)
your sorted() code presumably would sort the locators by name, giving you the funny results, also, cmds.ls has a flag specifically for ordering based of selection order. See tweaks below, hope this helps!
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 (type = 'transform', orderedSelection = True )
if not sel:
cmds.warning( "Please select a locator / No locators in selection " )
for loc in sel:
coords = cmds.xform (loc, query=True, worldSpace=True, pivots=True)[0:3]
print coords
pts.append(coords)
cmds.polyCreateFacet(p = pts)
your sorted() code presumably would sort the locators by name, giving you the funny results, also, cmds.ls has a flag specifically for ordering based of selection order. See tweaks below, hope this helps!
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 (type = 'transform', orderedSelection = True )
if not sel:
cmds.warning( "Please select a locator / No locators in selection " )
for loc in sel:
coords = cmds.xform (loc, query=True, worldSpace=True, pivots=True)[0:3]
print coords
pts.append(coords)
cmds.polyCreateFacet(p = pts)
[/QUOTE]
Hi Shane, I added in the sorted command, it is just so to make the arrangement/hierarchy looks nice… Even so, having it removed, it is also giving off the same problem as I have listed in my thread itself.
Hmm, and did you try orderedSelection = True in the list flag. The order of the selection will determine the winding order of the points, which is why the second triangle had such a funny shape. To get a correct winding order irrespective of the selection order could be possible by checking where the points are in space relative to each other, but it would be quite a very tricky thing to do in non trivial cases (and way beyond the scope of this thread, and my ability).
[QUOTE=shane;26000]Hmm, and did you try orderedSelection = True in the list flag. The order of the selection will determine the winding order of the points, which is why the second triangle had such a funny shape. To get a correct winding order irrespective of the selection order could be possible by checking where the points are in space relative to each other, but it would be quite a very tricky thing to do in non trivial cases (and way beyond the scope of this thread, and my ability).[/QUOTE]
It is not working either. Probably, I should rephrase the question and come to think of it, my images may also be misleading. I apologize for that.
The selection order may not be the case that I am trying to achieve here. Since I am triangulating it, using the img01 as example, there should exactly be two more lines, from loc2 to loc3 and loc1 to loc4, 4 triangles within these 4 locators boundaries in which I believe this may be over the scope of this thread…
to get a proper polygon with your original code that sorts locators by name, you just need to flip the positions of locator 3 and 4.
You must place your locators in such as way as they form a ring around the polygon you want to create. Your initial placement is incorrect because going from locator 2 to 3 does not create a valid winding order.
[QUOTE=rgkovach123;26003]to get a proper polygon with your original code that sorts locators by name, you just need to flip the positions of locator 3 and 4.
You must place your locators in such as way as they form a ring around the polygon you want to create. Your initial placement is incorrect because going from locator 2 to 3 does not create a valid winding order.[/QUOTE]
Hi rgkovach123, I am going for a triangulation sort of like in this link
I would suppose that the ordering does not really matter in this case. However I do get what you are trying to say :):