JSON Export polygonfixture to many triangular fixtures

General discussion about the R.U.B.E editor
Post Reply
JesusR
Posts: 7
Joined: Fri Mar 31, 2017 10:58 am

JSON Export polygonfixture to many triangular fixtures

Post 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.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: JSON Export polygonfixture to many triangular fixtures

Post 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.
JesusR
Posts: 7
Joined: Fri Mar 31, 2017 10:58 am

Re: JSON Export polygonfixture to many triangular fixtures

Post 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
gilloub
Posts: 4
Joined: Fri Oct 14, 2016 1:16 pm

Re: JSON Export polygonfixture to many triangular fixtures

Post 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.
Post Reply