How to do it the other way around ?

Allrighty, so my way to build a b2d level in my game, is to put boxes, put circles, create joins, and so on.

Now, I hear there's a way that you can create the ground visually, and have a code that will recognize it and make it work as a level.

How does that go ?
With maths.
I use this type of approach in my motobike game. I set up numerous dots on the stage, and have them call a function to add their x and y values onto the doc class and then i run a for loop looking like this:

Code:
var height:Number = 10 / Vals.RATIO
         var Friction:Number = 0.5
         var Elasticity:Number = 0
         
         var fixtureD:b2FixtureDef = new b2FixtureDef ()
         
         fixtureD.friction = Friction
         fixtureD.restitution = Elasticity
         fixtureD.density = 1.0
         fixtureD.filter.categoryBits = 0x00FF00
         fixtureD.filter.maskBits = 0x0000FF
         for (var i:int = 0;  i < l - 1;  i += 1)
         {
            var r:Number = Math.atan2 (points [i + 1].y - points [i].y, points [i + 1].x - points [i].x)
            
            var L:Number = Math.sqrt (Math.pow (points [i + 1].x - points [i].x, 2) + Math.pow (points [i + 1].y - points [i].y, 2)) / Vals.RATIO
            var w:Number = (points [i + 1].x - points [i].x) / Vals.RATIO
            
            var Def:b2PolygonShape = new b2PolygonShape ()
            Def.SetAsBox (L/2, height/2)
            
            fixtureD.shape = Def
            
            
            var BodyDef:b2BodyDef = new b2BodyDef();
            BodyDef.position.Set (points [i].x / Vals.RATIO + w/2, points [i].y / Vals.RATIO + ((points [i + 1].y - points [i].y) / 2) / Vals.RATIO);
            BodyDef.angle = r;
            BodyDef.type = b2Body.b2_staticBody;
            
            var Body:b2Body = Vals._world.CreateBody(BodyDef);
            Body.CreateFixture (fixtureD)
         }
I see.
And you do the terrain manually aswell ?
I mean "drawing".
i just drag dots from my library onto the stage, then the code draws the box for me using their points

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