photonstorm/phaser — pull request #749 by georgiee (2014-04-22 18:16:18+00:00)
Title: fixed loadPolygon center of mass

This fixes the problem of `loadPolygon` with the center of mass. See http://www.html5gamedevs.com/topic/5854-p2-collision-mesh-misaligned/?p=35121.

loadPolygon delegates the creation of the vertices to addPolygon (which itself uses p2's fromPolygon method) whenever it finds only a single convex shape. This is not necessary. The parsing in loadPolygon can construct 1..n vertices.

I just removed the if branching around `data.length === 1` and it works as expected.

The problem with addPolygon itself is not fixed with this. As it's used at several other places in phaser like
`createBody` or `createParticle` we should move the vertices creating logic from `loadPolygon` into `addPolygon`. So that loadPolygon only iterates over the data- this would be a clean solution. Let's use this as the first step, I need more time than I currently have to validate to desirable clean solution.

Regards
George

Testcase with the appropriate data (attached) present.
```javascript

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create});

function preload() {
game.load.image('ship', 'assets/sprites/ship.png');
game.load.physics('physicsData', 'assets/physics/ship.json');
}

var contra;
var start = false;

function create() {
game.physics.startSystem(Phaser.Physics.P2JS);
ship1 = game.add.sprite(400, 300, 'ship');
ship2 = game.add.sprite(500, 300, 'ship');

game.physics.p2.enable(ship1, true);
game.physics.p2.enable(ship2, true);

ship1.body.clearShapes()
ship1.body.loadPolygon('physicsData', 'ship');

ship2.body.clearShapes()
ship2.body.addPhaserPolygon('physicsData', 'ship2');
}

function update() {

}

function render() {

}

```
![ship](https://cloud.githubusercontent.com/assets/1701755/2768813/e28869d2-ca49-11e3-904f-be5736970cc7.png)

ship.json
```javascript
{

"ship": [
{
"density": 2, "friction": 0, "bounce": 0,
"shape": [
16, 31,
0, 29,
16, 0,
31, 29
]
}
],

"ship2":[
{
"isSensor": false,
"filter": {
"group": 0,
"categoryBits": 1,
"maskBits": 65535
},
"polygons":[
[16, 31,0, 29,16, 0,31, 29]
]
}
]

}
```

![screen shot 2014-04-22 at 20 13 42](https://cloud.githubusercontent.com/assets/1701755/2768856/2ebcad2c-ca4a-11e3-9dd5-822a5dfacc54.png)