How to order vert array by edgeloop.


#1

I have an array of edges that lying on a mesh, forming a closed loop.

If I convert the edges to verts, I get an array of verts.

How can I sort the vert array so that as I move around the ring of edges, they are in order?

At the moment, because the verts are returned as a bitarray they are obviously ordered from smallest to largest which bears no relation to their position on the mesh.

I suspect this might be quite a tricky question!

Thanks in advance for any help.


#2

this should be work, but mabe need some adjustments;)


fn getSortedVertsFromEdgeLoop obj =
(
	--get edge selection as array
	local edges = polyOp.getEdgeSelection obj as array
	--get edge verts #(#(140, 141), #(141, 142), #(142, 143), ect...)	
	local vertPair = #()
	for i=1 to edges.count do 
	(
		vertPair += #(polyOp.getEdgeVerts obj edges[i])
	)
	--set first pair
	local sortedVerts = vertPair[1]
	deleteItem vertPair 1
	--sort rest verts
	while (vertPair.count != 0 and not keyboard.escPressed) do
	(
		for i=1 to vertPair.count do
		(
			--format "pairs:%
" vertPair
			if vertPair[i] == undefined do continue
			if (local pos = findItem vertPair[i] sortedVerts[sortedVerts.count]) != 0 do
			(
				case pos of
				(
					1: sortedVerts += #(vertPair[i][2])
					2: sortedVerts += #(vertPair[i][1])
				)
				deleteItem vertPair i 
			)
		)
	)
	return sortedVerts
)

getSortedVertsFromEdgeLoop $


#3

Thats great!

Much simpler than the path I had embarked on. For some reason, I didn’t think of keeping the vert pairs.

Thanks very much for the help.

Rhys.


#4

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.