Removing unused verts

 
 
 
Posted by:jcdeblok
Data created:18 October 2012

Here is a tricky one..

I have a test that only shows the Nth polygon, but it leaves all the verts in, some aren't used and Id like to filter those out.

I can check the 'contiguousPolygonData' from the input mesh against the output mesh and  detect which verts aren't used anymore. But removing them will mess up the polygon data since it will point to indexes that no longer exits. there I get stuck :)

Is this just a complex thing to do or is there a trick to it?

Hmm, yes this is a less trivial case. I had to deal with a similar scenario when writing a "graph-only" extrude faces implementation (as a test for Lab).

One of the ways I removed unneeded verts was by creating two arrays - initial and destination, where destination only contained used vertices. Then I created a dictrionary (System.Collections.Generic.Dictionary<int,int>) to map indices from one array to another, and then I created a predicate sub-graph which did the actual mapping and produced face indices into the reduced vertex array. It is a bit too much to describe here and I'm sure there is probably an easier approach. Maybe I'll make a tutorial on this scenario sometime.

Meanwhile I'll try to think of a simpler solution.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

I think this might be relativly simpel to remove a vertex and keep the polygons correct:

If you remove a vertex at index=X from the vertex array, then you can go through all vertexindexes  in the polygon array and decrease by 1 if it's greater then X to compensate for the index-shift. get/setContigiousPolygondata will make this quite easy I hope :) I'll try to set something up too if I can find some time.

 

EDIT: Mmm somehow it doesnt work anymore when you (re)load the ctx..  bug?

 

Attached a GeometryModifier graph that removes a vertexID = N   ('myInput' spinner) and fixes the polygon table to compensate for altered vertex data.

 

1) The 'removeAt' method deletes the vertex at index=N  from the vertex array, this cause all higer indexed vertices to shift one index down.

2) The ContPolyData array is checked for affectes entries (all IDs greater then N )

3) 'higherThen' boolean output is converted to Int, so it is 0 or 1

4) This int is subtracted from the value in the ContPolyData array to compensate the shift from step 1.

5) Finally the vertexArray output by the 'removeAt' method and the modified ContPolyData array are fed into a mesh type node and connect to the output.

6) if you change the spinner value you can see a vertex disappear and the polygon structure remaing intact.

 

So.. it would be great if anyone can make this work for an array of removed vertexes! :)


Attached Files:

>remvert.ctx (32335 bytes),