Ok, apologies for the complete newbie question.
I've been through the user guide, I read the api docs, I searched the forums, but I don't see any obvious way to do something that I expect should be very basic - How can I detect collisions on mesh based attachments?
I'm using libgdx with box2d physics, so I'm expecting to create some sort of polygon based body for the mesh. But the following totally doesn't work:
private Body makeBodyFor(final MeshAttachment attachment) {
final PolygonShape meshPoly = new PolygonShape();
final float[] vertices = attachment.getVertices();
meshPoly.set(vertices);
final BodyDef meshBodyDef = new BodyDef();
meshBodyDef.type = BodyType.DynamicBody;
final Body body = world.createBody(meshBodyDef);
body.createFixture(meshPoly, 1);
meshPoly.dispose();
return body;
}
This crashes the jvm at meshPoly.set(vertices). My guess is the vertices returned by attachment.getVertices() does not return a valid polygon outline. I've tried attachment.getWorldVertices() as well, with the same results.
My other thought was to try use a bounding box instead, rather than trying to find the perimeter polygon of the mesh itself. But how would I get the changes to the mesh to affect the bounding box in the right way? Attaching bounding box to bones means the bounding box is regularly quite far away from the mesh, even though the mesh is affected by the same bones.
I guess I must be totally missing something obvious.