Page 1 of 1

Set a polygon's vertex as index 0 (zero)

Posted: Wed Oct 22, 2014 12:55 pm
by mixedBarts
This might be a very useful feature for some cases, which I believe it's quite easy to implement.
Basically, there would be a new menu entry under "Vertex", something like "Set as start vertex" or "Set as index 0", that would make that vertex the first (index 0) in a polygon/line/loop fixture.

By the way, R.U.B.E. is awsome, but some of the request features would be really, really helpful.
Mostly "Instantiable objects" and/or "Display layers" IMO.

Thanks.

Re: Set a polygon's vertex as index 0 (zero)

Posted: Thu Oct 23, 2014 12:39 am
by iforce2d
Here is a script to do that:

Code: Select all

vertex v = sv()[0];
fixture f = v.getFixture();
vertex[] vs = f.getVertices();
int index = v.index;

for (int i = 0; i < index; i++) 
	f.addVertex( -1, vs[i].pos );
for (int i = 0; i < index; i++)
	f.deleteVertex(0);
Make sure you have just the one vertex selected when you run it.

Keep in mind that for polygons, the order of vertices in the exported file will not be preserved, because polygons go through a convex decomposition process, and are made into multiple sub-polygons. For lines and loops though, you can expect the vertex ordering to be the same as what you see in the editor.

Re: Set a polygon's vertex as index 0 (zero)

Posted: Thu Oct 23, 2014 11:06 am
by mixedBarts
That's great, thanks a lot.

To be honest, I didn't look into scripts yet, but I guess I have to.