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

What would you like to see in future versions of the editor?
Post Reply
mixedBarts
Posts: 2
Joined: Wed Oct 22, 2014 12:18 pm

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

Post 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.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

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

Post 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.
mixedBarts
Posts: 2
Joined: Wed Oct 22, 2014 12:18 pm

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

Post by mixedBarts »

That's great, thanks a lot.

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