final Mesh[] meshes = new Mesh[header.numFrames];
MeshData mData;
for (int i = 0; i < header.numFrames; i++) {
final Md2Frame frame = frames[i];
meshes[i] = new Mesh(frames[i].name);
mData = meshes[i].getMeshData();
mData.setIndexLengths(counts);
mData.setIndexModes(modes);
final FloatBufferData verts = new FloatBufferData(vertexCount * 3, 3);
final FloatBufferData norms = new FloatBufferData(vertexCount * 3, 3);
final FloatBufferData texs = new FloatBufferData(vertexCount * 3, 2);
mData.setVertexCoords(verts);
mData.setNormalCoords(norms);
mData.setTextureCoords(texs, 0);
// go through the triangle strips/fans and add them in
// first the strips
if (stripIndices.size() != 0) {
for (int maxJ = stripIndices.size(), j = 0; j < maxJ; j++) {
cmd = commands[stripIndices.get(j)];
if (cmd.vertIndices.length < 3) {
continue;
}
addVert(cmd, frame, 0, verts);
norms.getBuffer().put(0).put(0).put(0);
texs.getBuffer().put(0).put(0);
// add strip verts / normals
for (int k = 0; k < cmd.vertIndices.length; k++) {
addVert(cmd, frame, k, verts);
addNormal(cmd, frame, k, norms);
}
// add strip tex coords
texs.getBuffer().put(cmd.texCoords);
// if we're not the last strip, add a vert or two for degenerate triangle connector
if (j != maxJ - 1) {
addVert(cmd, frame, cmd.vertIndices.length - 1, verts);
norms.getBuffer().put(0).put(0).put(0);
texs.getBuffer().put(0).put(0);
if (cmd.vertIndices.length % 2 == 1) {
// extra vert to maintain wind order
addVert(cmd, frame, cmd.vertIndices.length - 1, verts);
norms.getBuffer().put(0).put(0).put(0);
texs.getBuffer().put(0).put(0);
}
}
}
}
// Now the fans
// XXX: could add these to the strip instead
for (final int j : fanIndices) {
cmd = commands[j];
texs.getBuffer().put(cmd.texCoords[0]).put(cmd.texCoords[1]);
addNormal(cmd, frame, 0, norms);
addVert(cmd, frame, 0, verts);
for (int k = cmd.vertIndices.length; --k >= 1;) {
texs.getBuffer().put(cmd.texCoords[k * 2]).put(cmd.texCoords[k * 2 + 1]);
addNormal(cmd, frame, k, norms);
addVert(cmd, frame, k, verts);
}
}
}
// Clone frame 0 as mesh for initial mesh
final Mesh mesh = meshes[0].makeCopy(false);
mesh.setModelBound(new BoundingBox());
// Use resource name for mesh
mesh.setName(resource.getName());
// Add controller
final KeyframeController<Mesh> controller = new KeyframeController<Mesh>();
mesh.addController(controller);
controller.setMorphingMesh(mesh);
controller.setInterpTex(false);
int i = 0;
for (final Mesh meshX : meshes) {
controller.setKeyframe(i, meshX);
i++;
}
// Make a store object to return
final Md2DataStore store = new Md2DataStore(mesh, controller);
// store names
for (final Md2Frame frame : frames) {
store.getFrameNames().add(frame.name);
}
// store skin names
for (final String name : texNames) {
store.getSkinNames().add(name);
}
// Apply our texture
if (isLoadTextures()) {
Texture tex = null;
for (final String name : texNames) {
tex = loadTexture(name);
if (tex != null) {
break;
}
}
// try using model name
if (tex == null) {
tex = loadTexture(resource.getName());
}
if (tex != null) {
final TextureState ts = new TextureState();
ts.setTexture(tex);
mesh.setRenderState(ts);
}
}
return store;
} catch (final Exception e) {