Creating complex polygons

Oct 30, 2008 at 8:36 AM


I am looking for advice on how to create fairly comlex polygons. The basis for each polygon will be some shape created in Illustrator, so idealy im looking for something that can analyse the picture and create a list of vertices. I have tried the Texture2D to Polygon that is a part of the latest revision but it seems to be faulty when creating fairly large and complex polygons. 

I am using this to create a level on which a ball can roll so there needs to be smooth slopes, and idealy for the ease of creating new levels each polygon should contain several obsticals. So the method for creating a level will be, create an entire level in illustrator with textures and everything, take the level apart so it consists of polygon shapes, use some tool to extract vertices for each polgon shape, then finally reassemble the level in xna and farseer.

I hope you have some nice advice for me ;)

Oct 30, 2008 at 8:44 AM
Hi ogssan.

The texture to polygon code should be your best bet. How is it faulty? Can you upload a picture of the result?
Oct 30, 2008 at 10:08 AM
To make your levels look good, as well as easy for your engine to work with (ie. using simpler polygons), it may be useful to create two level images. Let me explain - the first level image would be your nicely detailed one that looks good for use in the game, while the second would be a highly simplified version of underlying monotone polygons. You'd use this second image to generate your collision polygons - obviously you'd need to split the image into seperate shapes, as you've mentioned, to pass into the Texture2D to Polygon functions. I think (i havent looked at it too closely) that there is a tolerence value in the functions which will help to control the detail of the generated polygon. Then, in your game you'd simply draw the first image as a background or foreground overlay.

Alternatively, you could write a 'level editor' that lets you define the polygons for your level. 
Oct 30, 2008 at 2:31 PM
Edited Oct 30, 2008 at 2:34 PM

Thanks for the replys, i have found out that it isnt an issue with the Texture2D to Polygon but rather an issue with farseer and concave polygons or possible my own incompetence.

Here are a couple of screen shots of the issue.

The areas circled with red are areas where objects kan pass through the wall, the only exception is when they directly hit a vertex.

At the balls current location it collides with something, although there is nothing.

If you wish to try for yourself then here is the texture i am using.

I am just using the advanced demo 4 with the above texture instead of the standard one

Am i doing something wrong or are concave polygons simply not propably supported by farseer?

Oct 30, 2008 at 2:35 PM
Farseer have full support for both concave and convex polygons. Your texture should work, and I think I know what the problem is. I'm going to test it in a few moments.
Oct 30, 2008 at 2:43 PM
@ogssan - I am working on a Physics Editor program that will let you define complex shapes then save and load them easily in your game. There will be a "map texture" feature that will allow either a fully custom Geom to be created vertex by vertex or use the Texture2D to Polygon function and then you can fine tune that. It should be available in an alpha version in 6-8 weeks. 

For what you are describing it seems like you want to be able to import Illustrator shapes into Farseer or export them to some format easily readable by Farseer. I don't use Illustrator so I don't know what formats it can export but you might find something that you can write a tool to convert that format into a Vertex list.

Also as DrDeth stated there is a tolerance value for the Texture2D to Polygon functions. You might try adjusting this until you get the desired result. Also breaking up a super complex texture into smaller chunks will not only keep Texture2D to Polygon working better it will also keep more of your scene in the broadphase collision letting you have more objects. 

All this talk has me thinking up another feature to add to my Physics Editor. I will make a automatic grid-based subdivision of large bodies so as to improve the performance of super large Geoms. By the way this very technique is described in the latest manual written by genbox and myself. 
Oct 30, 2008 at 2:46 PM
I've tested it and yes, there is a problem with it both going into the texture, but also some odd behavior with collisions in places were there should be none.

The first one is easily fixed. Farseer Needs polygons on sides, not too long from each other. You can use SubDivideEdges() in the Vertices class to make Farseer add more polygons. The second problem is not obvious to me, so I'm going to do some investigation. The texture to polygon code is brand new, so there might be some bugs lurking.

By the way: Nice to see someone from ITU using our project. I'm from Denmark and I'm actually in the progress taking the prerequisites to get into ITU. ;)
Oct 30, 2008 at 3:05 PM
As Mattbettcher said, It's a good practice to split up (chunk) your landscape to improve performance. Right now your landscape is one huge AABB (Axis Aligned Bounding Box) that will cause Farseer to consider the geometry for narrow phase collision detection all the time (Expensive operation). You can read all about it in the 2.0 manual under "Performance".

Chunking up the landscape also seems to fix the problem with the "ghost" collisions.

@Mattbettcher - You are an idea creating machine! :) Sounds great with the grid feature. Are you sure 6-8 weeks are enough with all those ideas? ;)
Oct 30, 2008 at 3:28 PM
@genbox - I got to do it for school ;)

@ogssan - genbox is right. You need more vertices on those flat edges.

What and where is ITU? 
Oct 30, 2008 at 4:51 PM
Illustrator is a vector graphics program.  I'd imagine converting vector graphics to a Verticies list would be much simpler than converting rasters.  Now that we have this 'Texture2D to Polygon' tool, we can move on to 'SVG to Polygon'.  SVG is already becoming an internet standard file format.  Free programs like Inkscape use SVG, and I'm sure that Illustrator will save to it.  It's also in XML, so it's easy to read.

Where can we post suggestions for version 2.1? =D
Oct 30, 2008 at 5:19 PM
@Yota - that's a great suggestion. And I've already looked into that briefly, but never made anything from it. My Physics Editor program will go one step further by allowing joint and spring placement and a WYSIWYG environment. It will also allow realtime testing of components and when finished will allow adding the complex models created with it into your own program very easy.

As for the thread I would say go ahead and start one.

Also for anyone that has created an addition to Farseer or something Farseer related lets get it on the list. Ideas are great but me, Ian, and Jeff can only have so much time.
Oct 30, 2008 at 6:48 PM
@Yota: If it can be done easily, we might take a look into it.

I will create a 2.1 thread once we get 2.0 out the door and fix any potential bugs. Thanks for the suggestion :)


ITU is an IT University (hence the name). Very modern and "young" compared to our other universities. It's just my preferences that made me choose ITU instead of one of the other (larger and more famous) ones. :)
Oct 30, 2008 at 8:54 PM

Thanks for all the replies and advice, it looks like i will be creating smaller polygons then.

The SubDivideEdges() did wonders for another issue i was having(you just gotta know these things are there). ;)

You gotta love a fully functional community ready to save you from several hours of frustration. :)

@genbox - so i guess you will be taking the Media Technology and Games - Technical line at the ITU.

@mattbettcher - As genbox said the ITU is a dansih IT University which has a strong focus on game design/programming.

@mattbettcher - Your physics editor sounds really cool and usefull, looking very much forward to trying it out.

Oct 30, 2008 at 10:24 PM

We have been working hard on the new documentation to be released with 2.0. There are a lot of useful stuff in Farseer, the documentation points out a lot of them.

We are here to help. Some of our members are really their weight worth in gold.

And about the university. I already have 5 years IT education and I was thinking of taking a MSc in IT: Software development and technology. (What a fancy name).

But I'll wait and see what appeals to me when I'm done with the prerequisites.
Do you by chance know others using Farseer Physics at ITU?
Nov 3, 2008 at 10:24 AM
"I have tried the Texture2D to Polygon that is a part of the latest revision"

Hi all, i need to know where to find this texture2d to polygon tool.. I searched for it but couldn't find anything!
Thanks for your help..
Nov 3, 2008 at 11:13 AM
Nov 3, 2008 at 12:25 PM

As sickbattery suggested, It's inside the Vertices class.
Just wanted to note that the 2.0 release will contain a demo on how to use this functionality, and the documentation (manual) also descibes it's functionality.


Do you have an idea why this happens? The problem with ghost collisions that is.
Nov 3, 2008 at 1:17 PM
Edited Nov 3, 2008 at 1:27 PM
Nope. Unless the first vertex has to be added twice (at beginning and ending of the polygon) I don't see anythnig wrong with my code.

I already read here about this bug a few days ago and I wanted to add some code to CreatePolygon() to let the user decide over the max lenght between vertices - but then I thought: "Naaaah. There is a subdivide function ..." ... but I'll take a look at it again (subdivide and my code).

But uhm ...isn't that more a probem in the collision handler? edit: (i mean *Collider.cs)

If my leave get's approved then I'll take a more intensive look at it.
Nov 3, 2008 at 1:27 PM
I've not encountered this behavior before when mapping out vertices manually. Could the vertices be mapped in a messed up order? I'll try to map the problematic texture out myself and try to get as close to the result of "texture to vertices" as possible.
Nov 3, 2008 at 1:38 PM
Could the vertices be mapped in a messed up order?

The code moves pixel by pixel, caches a short list of pixels and after a while it adds one of the cached pixels (the most outstanding one). Then the pixels before (and) the last added are removed. I don't see any room for a "messed up order" oO. I'll take a look, too. When I'm at home at 9pm -.- ...
Nov 3, 2008 at 1:57 PM
Indeed. I've mapped out the texture myself by using my old Polygon mapper application. And I had the same ghost collisions, so it is indeed nothing to do with your code sickbattery.

It must be the narrow phase collision detection. I'll ask Jeff after we release 2.0.
Dec 22, 2008 at 7:59 PM
Here's a link to an Illustrator plugin like you originally requested.  You can create a path in Illustrator, select the points, and use the plugin to export a tab-delimited text file of the path coordinates.  I don't know if it handles Beziers or not, but it seems to work pretty well for straight line polygons.

It's called PathToText: