Misinterpreting polygons (box2d)


#1

I’m using the paid version of PhysicsEditor and export my Polygons as Lime + Corona (JSON).
As I’m developing for different devices, I scale the phaser world and the ptmratio of box2d to use the same physics feeling across the devices.
Unfortunately, some polygons are messed up. While the polygons are drawn correctly for my desktop, an additional rectangle is added to my polygon. The added rectangle is too big, way too big.
This impact is too huge to let it unhandled.

Problem: I paid for PhysicsEditor, Phaser and the box2d plugin and I cannot find a reason why this is happening. Codeandweb do not pay attention to this problem and Phaser 2 is not fixed anymore (and I guess therefore box2d is out too), so I hope someone can help me out here. I assume that this is a phaser/box2d problem when interpreting the polygons as the problem occurs only for small resolutions (as far as I tested).
As I’m not authorized to publish the content or specific code/screenshots, I’m interested in the possibilities that can lead to this error.

I scale down the body as I scale down the world to fit into every viewport.
To scale down the body, I use:

function resizePolygon(originalPhysicsKey, newPhysicsKey, shapeKey, scale) {
var newData = [];
var data = this.game.cache.getPhysicsData(originalPhysicsKey, shapeKey);

for (var i = 0; i < data.length; i++) {
	var vertices = [];
	for (var j = 0; j < data[i].shape.length; j += 2) {
		vertices[j] = data[i].shape[j] * scale;
		vertices[j + 1] = data[i].shape[j + 1] * scale;
	}

	newData.push({
		bounce : data[i].bounce,
		density : data[i].density,
		friction : data[i].friction,
		filter : data[i].filter,
		shape : vertices
	});
}

var item = {};
item[shapeKey] = newData;
game.load.physics(newPhysicsKey, '', item);

}

Then I use

sprite.body.loadPolygon(....)

to load the scaled body with the new physics key. However, this works for my desktop but not for smartphone devices. I assume that the problem may be related to the scaling.

So … is here someone who can make a guess about it? Why could it happen?

I appreciate your ideas.

Edit: New knowledge. I increased the tolerance within the PhysicsEditor (higher values mean less vertices which are not hitting the edge perfectly]) and removed single vertices that were too near to each other or looked complicated (like a triangle [actually not complicated but let’s start simple, aight]).
Right now, it seems like it’s working. But this needs further testing.

Someone got an explanation why it seems like some vertices are interpreted wrong when they are too near to each other and scaled down?