PbBody body = PbBody.parseFrom(argInput);
return deserializeBody(argWorld, body);
}
public Body deserializeBody(World argWorld, PbBody argBody) {
PbBody b = argBody;
BodyDef bd = new BodyDef();
bd.position.set(pbToVec(b.getPosition()));
bd.angle = b.getAngle();
bd.linearDamping = b.getLinearDamping();
bd.angularDamping = b.getAngularDamping();
bd.gravityScale = b.getGravityScale();
// velocities are populated after fixture addition
bd.bullet = b.getBullet();
bd.allowSleep = b.getAllowSleep();
bd.awake = b.getAwake();
bd.active = b.getActive();
bd.fixedRotation = b.getFixedRotation();
switch (b.getType()) {
case DYNAMIC:
bd.type = BodyType.DYNAMIC;
break;
case KINEMATIC:
bd.type = BodyType.KINEMATIC;
break;
case STATIC:
bd.type = BodyType.STATIC;
break;
default:
UnsupportedObjectException e =
new UnsupportedObjectException("Unknown body type: " + argBody.getType(), Type.BODY);
if (ulistener == null || ulistener.isUnsupported(e)) {
throw e;
}
return null;
}
Body body = argWorld.createBody(bd);
for (int i = 0; i < b.getFixturesCount(); i++) {
deserializeFixture(body, b.getFixtures(i));
}
// adding fixtures can change this, so we put this here and set it directly in the body
body.m_linearVelocity.set(pbToVec(b.getLinearVelocity()));
body.m_angularVelocity = b.getAngularVelocity();
if (listener != null && b.hasTag()) {
listener.processBody(body, b.getTag());
}
return body;
}