- Home /
What polygonization algorithm does unity use for PolygonCollider2D?
It doesn't seem to be bayazit (which farseer uses) because they produce different results.
Wish the source code were available to see
Answer by Bunny83 · May 08, 2018 at 10:39 PM
Unity uses Box2d as 2d physics engine. Also what is a "polygonization algorithm"? Since the input is a polygon, what do you think the output should be? A collider is not a mesh and need to be triangulated
Sorry for replying late. Box2d (which farseer is based on) can't work with concave polygons (it actually creates a convex hull whenever you give it vertices to make a "polygon" shape class (other such are "circle", "edge" classes) out of (which is then used to create a "fixture" class, which attaches the "shape" to the rigidbody)), so it decomposes them to convex polygons (you can see with a polygoncollider2d, it makes extra lines if the polygon is concave, that is how unity has polygonized it).
Farseer comes with a utility script that decomposes concave polygons to convex polygons (so that we can attach them to rigidbodies with shapes and fixtures as several convex polygons, a "composite collider"). The algorithm in farseer is called bayazit. I tested the results from bayazit, and looking at the polygoncollider2d in the scene view with the same input vertices, and the convex subpolygons were different between them; the 2 algorithms sliced up the concave polygon differently.
Answer by TanselAltinel · May 08, 2018 at 12:08 PM
Is this a question or a wish from Unity?
Unity source code is available for read-only purposes: https://github.com/Unity-Technologies/UnityCsReference
Sorry for replying late, but the code they made public is only the c# code, whereas most of Unity code is written in c++, as well as their polygonization (I already looked). I was looking to try their algorithm in straight comparison to see the speed difference between the one Unity uses and the one that comes with Farseer (based on box2d) called Bayazit. I really needed speed for my polygonization.
Your answer
![](https://koobas.hobune.stream/wayback/20220612161026im_/https://answers.unity.com/themes/thub/images/avi.jpg)