PbShape s = PbShape.parseFrom(argInput);
return deserializeShape(s);
}
public Shape deserializeShape(PbShape argShape) {
PbShape s = argShape;
Shape shape = null;
switch (s.getType()) {
case CIRCLE:
CircleShape c = new CircleShape();
c.m_p.set(pbToVec(s.getCenter()));
shape = c;
break;
case POLYGON:
PolygonShape p = new PolygonShape();
p.m_centroid.set(pbToVec(s.getCentroid()));
p.m_count = s.getPointsCount();
for (int i = 0; i < p.m_count; i++) {
p.m_vertices[i].set(pbToVec(s.getPoints(i)));
p.m_normals[i].set(pbToVec(s.getNormals(i)));
}
shape = p;
break;
case EDGE:
EdgeShape edge = new EdgeShape();
edge.m_vertex0.set(pbToVec(s.getV0()));
edge.m_vertex1.set(pbToVec(s.getV1()));
edge.m_vertex2.set(pbToVec(s.getV2()));
edge.m_vertex3.set(pbToVec(s.getV3()));
edge.m_hasVertex0 = s.getHas0();
edge.m_hasVertex3 = s.getHas3();
shape = edge;
break;
case CHAIN: {
ChainShape chain = new ChainShape();
chain.m_count = s.getPointsCount();
chain.m_vertices = new Vec2[chain.m_count];
for (int i = 0; i < chain.m_count; i++) {
chain.m_vertices[i] = new Vec2(pbToVec(s.getPoints(i)));
}
chain.m_hasPrevVertex = s.getHas0();
chain.m_hasNextVertex = s.getHas3();
chain.m_prevVertex.set(pbToVec(s.getPrev()));
chain.m_nextVertex.set(pbToVec(s.getNext()));
shape = chain;
break;
}
default: {
UnsupportedObjectException e =
new UnsupportedObjectException("Unknown shape type: " + s.getType(), Type.SHAPE);
if (ulistener == null || ulistener.isUnsupported(e)) {
throw e;
}
return null;
}
}
shape.m_radius = s.getRadius();
if (listener != null && s.hasTag()) {
listener.processShape(shape, s.getTag());
}
return shape;
}