problem with my poly shapes

Hello!

I am using the box2djs library (as found here: http://box2d-js.sourceforge.net/) and i have been working with it for a couple of weeks now. I have a function that imports svg data and creates shapes and bodies out of it. All the boxes seem to work just fine, but the poly shapes seem to glitch quite a bit. I have determined that the vertex order is correct (the same as for my box-shapes) for the shapes.

As i create my world i have a row of boxes falling through it, and basically what happens is that every box shape collides just fine, but the polyshapes behave weird, most boxes fall througg them, but if they come close to the edges, they are pushed out-side of the shape (as would normaly be expected if an object is inside another). Also i noticed that the first poly-shape i create seem to work correctly. If i let the poly-shapes fall they behave weirdly but occasionally seem to collide as expected.

I read somewhere that there where constraints on poly-shapes and that there is some kind of validate() function for poly-shapes, but there is not one in the js lib from what i have found.

As i create my shapes i iterate a list of parsed json data and create polyshapes, this is the function that creates the shapes:
Code:
box2dFactory.createPolyShape = function(thePoints) {
   box2dFactory.shapesCounter++;
   var polySd1 = new b2PolyDef();
   
   var count = thePoints.length;
   
//because of how the svg data is laid out, the first pos is world location, the rest is relative
   var origin = {x:0, y:0};
   
   polySd1.vertexCount = count;
   
   for (var k = 0; k < count; k++) {
      
      var posX = ((origin.x + parseFloat(thePoints[k].x)) + box2dFactory.world_offset_x) * box2dFactory.world_scale;
      var posY = ((origin.y + parseFloat(thePoints[k].y)) + box2dFactory.world_offset_y) * box2dFactory.world_scale;
      
      polySd1.vertices[k].Set(posX , posY);
      
      origin.x = parseFloat(thePoints[k].x) + origin.x;
      origin.y = parseFloat(thePoints[k].y) + origin.y;
         
   }
   
   polySd1.density = 0;
   
   return polySd1;
};



Does anyone have any hints or advice ? Thanx
If your polygons have incorrect winding, then what I've seen is that a dynamic body will sink into the polygon and then be popped out. All points in your polygon should stick out convexly. Ive even found that having a point that is halfway between two other points on the polygon's path will cause the polygon to be glitchy. See: http://ptymn.blogspot.com for a decent polygon decomposition algorithm in AS3. It is fast and will be easier than the C++ version to convert to JS.

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