Notifications
Clear all
[Closed] Get Selected Edge Verts in order
Jul 14, 2016 1:50 pm
How can I get an array of the vert indices in the order which they are connected?
Does anyone have any maxscript snippets which return the selected edge’s vertices in their order of connection? As you may know, bitArrays are always ordered, which improperly reflects they way the verts are actually connceted.
Mesh A results:
Wrong: #{1…11,23,26}
Desired:: #(1,2,3,4,5,6,26,7,8,9,10,23,11)
Mesh B results:
Wrong: #{1…10,21,24…25}
Desired:: #(6,24,7,8,9,10,21,1,2,3,4,5,25)
Ordering
1 Reply
Jul 14, 2016 1:50 pm
The edge loop regularizer has something like this.
I solved this problem anyways. I would not say that it’s optimized, but at least it’s working. It’s generally a snippet copy pasted out from one of my code I scripts.
function getFirstVert theObject rev = ( -- returns the first vertex of the loop if rev = false, last vertex if rev = true, undefined if it's a closed loop
endVerts = #()
vertLoopArray = #()
edgeLoop = polyop.getEdgeSelection theObject as array
for i = 1 to edgeLoop.count do ( -- get the end vertices of the loop
edgeVerts = polyop.getEdgeVerts theObject edgeLoop[i]
for j = 1 to edgeVerts.count do (
appendifunique vertLoopArray edgeVerts[j]
if appendIfUnique endVerts edgeVerts[j] == false do (
indexOfVert = findItem endVerts edgeVerts[j]
deleteItem endVerts indexOfVert
)
)
)
if endVerts != undefined then (
if rev == true do (
return endVerts[1]
)
if rev == false do (
return endVerts[2]
)
)
else return undefined
)
function getOrderedVertLoop theObject = ( -- generate an array containing the loop vertexes successively in order
firstVert = getFirstVert theObject true
if firstVert == undefined do ( -- if firstVert is undefined it sets the firs vert value to the firs element of the edge loop
firstVert = ((polyop.getVertsUsingEdge theObject edgeLoop[1] as array)[1])
isClosedLoop = true
)
firstEdge = (((polyop.getEdgesUsingVert theObject firstVert) as bitarray * edgeLoop as bitarray) as array)[1]
lastVert = #{firstVert}
lastEdge = #{firstEdge}
orderedVertexLoop = #(firstVert)
orderedEdgeLoop = #(firstEdge)
for i = 1 to edgeLoop.count do (
nextVert = (polyop.getVertsUsingEdge theObject lastEdge) - lastVert as bitarray
lastVert = nextVert
nextEdge = ((polyop.getEdgesUsingVert theObject lastVert) - lastEdge) * edgeLoop as bitarray
lastEdge = nextEdge
lastVert = lastVert as array
append orderedVertexLoop lastVert[1] as array
)
return orderedVertexLoop
)