This project has moved and is read-only. For the latest updates, please go here.

Cutting Textured Polygons

Topics: Developer Forum, User Forum
Jun 19, 2011 at 3:39 PM

Hello I'm a bit new to Farseer and upon taking a look at the cutting test in the TestBed started to wonder is it possible to cut textured polygons and if yes are there any tips on how to implement this
Thank you in advance.

Jun 21, 2011 at 1:58 AM

You will need to transform the world intersection points into texture space. I don't have time to give an example, but I'm sure you can find one on the internet.

Jun 21, 2011 at 2:11 PM

Thank you for the reply the thing is how do I easily differentiate the cut pieces of the polygon also didn’t have any luck searching.the question might be elementary or something but the thing is I’m a tad new so hehe.

Jun 22, 2011 at 11:59 PM

You would basically be writing a UV mapper. So I will break it down as best as I know. Please understand that I have not done this yet and I'm going on pure graphics programming knowledge.

  1. When you initially set up your polygon you need to set the UV of each point. This will require an extra list of Vector2's.
  2. When you cut a polygon you'll need to feed the original polygon and each of the new polygons and the new points created to a polygon mapper function.
    1. Inside this function you'll need to transform the new points into texture space. I'm assuming they are already in local space.
    2. Now you need to find the edge that the new point lies on.
    3. Using that edges endpoints, interpolate the UV coordinates of those two endpoints. To find out what percent to interpolate to you'll need to find the distance between the two endpoints. And the distance between one endpoint and the new point. A little division and you'll know how far to interpolate your UV coords.

That should be about it. I've been wanting to do this myself so I'll probably whip up a demo. Also, this can be made way faster by rewriting the cut methods included in Farseer to do the UV interpolation while splitting polygons. You'll have to give me at least a week to get a sample ready though.

Jun 23, 2011 at 9:14 AM

Thanks for the detailed reply .You gave a lot for me to think about will look into it ,also a demo would be great for everyone ,if you have time for it that is .not like I’m demanding one ,but I might just build a statue commemorating you actions if you do hehe).

Jun 26, 2011 at 2:38 PM

OK, so I got a very hacked together example for you. Click and drag to slice off parts of the crate.


  • This is not a finished example.
  • There isn't much commenting. 
  • There are still some bugs. Most will be easy to fix.
  • Currently only one texture is supported.
  • I didn't end up using the technique I described above.
  • I tried to make sure all dependencies are included, but if not please let me know.
  • I am working on a better example.
Jun 26, 2011 at 4:01 PM

K thanks loads i will start going threw it now ,will report if i find something .And thanks again

Jun 26, 2011 at 7:30 PM

very cool :)

but yea there are some bugs.

sometimes i just can't cut the polygon :(

this would be awesome with a shatter algorithm :D

Jun 26, 2011 at 7:43 PM
Edited Jun 26, 2011 at 8:03 PM

I'm working on a much better sample. This was mostly just a teaser.

Also here is a quick YouTube.

Jun 27, 2011 at 2:52 AM

Quick progress update.  I rewrote the TexturedPolygon code and it's quite a bit more streamlined now. On to making a much better sample.

Jun 27, 2011 at 3:44 AM

OK, here is the sample as of tonight.

Should have a much better structure and be much more understandable hopefully.

I still need to test multiple different textures and a few other things. Also need to check for garbage generation.

Jun 27, 2011 at 1:06 PM

WoW thanks Matt a really nice sample thank you ,much easier to understand .

Jun 27, 2011 at 1:25 PM

The only thing that i found (which you prob already know about) is that if say yuo can the box horizontally threw the niddle that try cutting at and angle with the cut line going threew the cut part it will only work for one part of the body not both of them was this intended or?

Jun 27, 2011 at 2:34 PM

I'm currently limiting the cutting to one object at a time. But that limitation will not remain.

Jun 27, 2011 at 4:16 PM

K cool thought it was smth like that havent had the chance to fully look threw the latest example code  or might have figured that out myself

Jun 27, 2011 at 4:21 PM
Edited Jun 27, 2011 at 4:30 PM

Still need to work on:

  • Automatic decomposition of cut polygons that have > max polygon points.
  • Circle to polygon conversion, so the cutting will also work on circles.
  • Allow multiple bodies to be cut.
  • Ensure only first body will be cut, in one body mode, regardless of where end point is. (currently if the endpoint is inside a fixture then we simply don't cut)
  • Test out multiple textures, fixtures, etc.
  • Add a rendering method.
Jun 27, 2011 at 8:43 PM

Here is a quick YouTube of this texture mapping adapted to the breakable bodies sample.

Jun 27, 2011 at 10:06 PM

Do you need any help on this r smth ?

Jun 28, 2011 at 1:23 AM
Edited Jun 28, 2011 at 1:32 AM

Not really. Just writing up a sample and looking for possible problems and I decided that this should be a feature added to the Samples. Everyone always wants to know how to do texture mapping ;)

One thing on the breakable bodies is that you currently can't an unbroken body without deleting the rest of the chunks. It's an easy fix though. Instead of just cutting the affected fixtures and 'removing' the rest with the original, we need to create two new breakable bodies. Or just break it up when it gets cut.

Also I'm working on my own game so any features I can add is cool.

Jun 28, 2011 at 2:29 PM

K cool this may add so much variety to any game

Jun 29, 2011 at 8:46 PM

I just randomly came across this thread. I was looking to do exactly what you did in your 3rd youtube video. Any chance that you can post the code? I got pretty close but hit a bit of a road block then I saw this thread!

Jun 30, 2011 at 4:04 PM

Sure, but consider this in alpha state. It still has a bunch of errors that need fixing.

Sep 9, 2011 at 5:40 PM

Hey Matt, has there been any progress in this textured breakable bodies sample? If so, I'd like to take a look at it. :)

Sep 12, 2011 at 2:10 AM

Not really. I've been pretty busy working on something completely different for some time now and haven't had time to do any work on this at all. Honestly, this is a simple rendering technique and has nothing to do with Farseer Physics.

Nothing against anyone, but we need to keep this forum more focused on physics based stuff, not rendering techniques.