I'm trying to collect the edges of all borders (open edges) in my mesh and store these edges in an array. More specifically I would like to seperate the edges into as many arrays as there are borders in the mesh.
Example: we have a mesh with 2 holes in it (see attached files for an image of the mesh), therefore it has 2 borders, I'd like the script to produce an array with 2 subarrays, 1 subarray for each hole/'open edge loop'. Image of this mesh: test mesh, vertex numbers indicated in blue/purple, edge numbers indicated in red
If anyone could tell me what the proper way to collect the edges into an array is that'd be very much appreciated. If you know/can think of a good way of separating the edges into their respective sub arrays (corresponding to the holes/border in the mesh) please let me know.
Images:
What I've tried:
I've tried selecting the open edges using the command
polyOp.getOpenEdges $
I did get this working for selecting the open edges, unfortunately I was not able to 'get' the edge numbers of said open edges using this command since the result of the getOpenEdges command is a bitarray(here and here).
I've written some pseudocode which should work for seperating the edges into their respective subarrays after all open edges have been stored in an array:
--NOTE: open_edges is the array in which all open/border edges of the mesh are stored
i = 0; edge_found = true
while open_edges.count > 0 do(
current_loop = #()
while edge_found == true do(
i += 1
if i==1 do( append current_loop open_edges[1]; Deleteitem open_edges 1 )
-- Select 2nd vertex of current_loop[-1]
-- Find edge in 'open_edges' which has this vertex
--if(no edge is found)then( edge_found = false )
--else(
-- Append the found edge to 'current_loop'
-- Remove the found edge from 'open_edges'
--)
) --end while edge_found == true do(
) --end while open_edges.count > 0 do(
If you spot a mistake in my code/approach for separating the edges into their respective sub arrays (corresponding to the holes/border in the mesh) or can think of a better/more efficient method of performing this process please let me know.
Thank you!
Note: in the attached image: 'edge_and_vertex_nums.png' I've indicated the edge numbers in red and the vertex numbers in blue/purple.
Try this. You can also simply compare the firstHole array with allOpenEdges and remove the duplicates.
allOpenEdges = (polyop.getOpenEdges $) as array
firstHole = (polyop.getBorderFromEdge $ allOpenEdges[1]) as array
select $
subobjectlevel = 2
polyop.setEdgeSelection $ firstHole
subobjectLevel = 3
max select invert
secondHole = (polyop.getedgeselection $) as array
subobjectLevel = 0
format "count1: %, count2: %\n" firstHole.count secondHole.count