BoxCutter

Image
http://daid.mine.nu/pub/BoxCutter.zip (packed with 7z this time...)

The function I noticed was public, so I kept the code inside the test class.

I moved the cutting part into it's own function, away from the initial trace. I've copied over the assert tests from the poly shape creator as check if my newly created shapes are ok. And I added a "splitSize" parameter. Which makes wider cuts (example uses 0.1 cut size)

Also made it trace trough multiple shapes, so you can cut up the two boxes into tiny parts really fast.

I've placed the new files on the old location. So the links in the top post are still the same. Files are new.
Great work!
If anybody has the latest file...

The link: daid.mine.nu/BoxCutter.zip doesn't work no more. Please upload it again. If not, email me it please: william at babybluebox com. Thanks!
My mistake should be http://daid.mine.nu/pub/BoxCutter.zip
Has there been any progress with this? I've noticed that cutting a box into a polygon with more than 8 vertices kills it - I'm not sure what the best way to handle this would be, though? Perhaps if the code was adapted to cope with bodies with multiple shapes, it could detect if a cut was going to create a shape with >8 vertices, and if so it could break the shape up into multiple triangle shapes to attach to the body instead of the one 8-vert shape, and then try to do the cut. Or something? Even just detecting that it's going to create an invalid shape and refusing to do the cut would be good.
ElectroDruid wrote:
Has there been any progress with this? I've noticed that cutting a box into a polygon with more than 8 vertices kills it - I'm not sure what the best way to handle this would be, though? Perhaps if the code was adapted to cope with bodies with multiple shapes, it could detect if a cut was going to create a shape with >8 vertices, and if so it could break the shape up into multiple triangle shapes to attach to the body instead of the one 8-vert shape, and then try to do the cut. Or something? Even just detecting that it's going to create an invalid shape and refusing to do the cut would be good.


Since the shape will always be convex because you're cutting it, you can just split it down the middle along any two non-adjacent vertices (although youd ideally want them to be near opposite each other). For example if you need to create a 9 sided shape with vertices v1, v2 ... v9, then just create two shapes v1, v2, v3, v4, v5 and v1, v5, v6, v7, v8, v9.
You could upgrade the maximum number of vertexes in the settings to allow more cuts, and a small check in the cut function for the maximum number would be in order.

Making multiple shapes on a single body out if it should also work, but then you also need to attach them to the same body again, and if you go around and make the cutter work on bodies instead of shapes it should work.
I'd love to see this, but the link still doesn't work. Any chance of a re-upload?
bb_vb wrote:
I'd love to see this, but the link still doesn't work. Any chance of a re-upload?
The ISP where I host it is down. Working on that...

Luckily, I have the code right here, so I dumped it in pastebin:
http://pastebin.com/d2ff54de1
Hiya,

I've just got round to updating my Box2D libraries to the latest SVN version so I could have a play about with this. I'm confused about this line, in the top of CheckPolyShape():

Code:
b2Vec2 m_normals[poly->vertexCount];


I don't see how that can compile for you. C++ doesn't do dynamic array allocation like that, you'd need b2Vec2* m_normals = new b2Vec2[poly->vertexCount], and then remember to delete[] m_normals before returning from the function. Is this what the code is supposed to do, or am I missing something?

Original thread: https://box2d.org/forum/viewtopic.php?t=1473