Page 1 of 1

JSON Export polygonfixture to many triangular fixtures

Posted: Sat Apr 15, 2017 9:50 am
by JesusR
Hello,

When I have in the editor a polygon fixture and I export the scene to a JSON the polygon is mapped as many triangle Fixtures. Is there a way to prevent this behavior? I work with polygons better than with triangles in my code.

Re: JSON Export polygonfixture to many triangular fixtures

Posted: Sat Apr 15, 2017 12:58 pm
by iforce2d
Box2D can only handle polygons up to 8 sides. The exported JSON will automatically generate these, and you can see how the result will turn out in the player view.

Sometimes the polygon decomposition can have problems, if this happens you will see a warning in the message log panel. This can happen if vertices are colinear or extremely close together. You might also be able to avoid the issue by reversing the vertex winding (in the action menu select Fixture->Reverse vertex winding).

For static bodies, maybe you can use a loop type fixture instead of a polygon.

Re: JSON Export polygonfixture to many triangular fixtures

Posted: Sun Apr 16, 2017 12:02 pm
by JesusR
Ahh didn't know that about Box2d. Then I will stick to triangles to get the stuff printed on the screen. Thanks for the help

Re: JSON Export polygonfixture to many triangular fixtures

Posted: Sat Aug 19, 2017 9:12 am
by gilloub
I use a quad to triangle converter in collada exporter :

Here is my exporter : https://github.com/gillesboisson/rube-to-collada

Here is the earcut converter : https://github.com/mapbox/earcut

You can code a nodejs / gulp task that can convert it easily.