11
« on: May 30, 2018, 11:49:33 am »
I'm about to post a little project for anyone unable to export either Ogre or MD2-animated versions of their models but are able to export OBJ or 3ds. I found a little maxscript that automates the exporting of the frames, and I'm writing the jpct end of it. Problem is I keep getting a size difference of 1 between frame 1 and all the rest ("ERROR: The sizes of the Animation's Meshes (26938) and the object's Mesh (26937) don't match!").
/**
Written by AGP (BR) on May, 2018
*/
import java.io.*;
import com.threed.jpct.*;
public class MergeAndSerialize {
public static void main(String[] args) {
Logger.setLogLevel(Logger.LL_ERRORS_AND_WARNINGS);
float SCALE = 3.6f;
String animationName = "Idle";
if (args == null || args.length < 1) {
System.err.println("USAGE: java MergeAndSerialize [baseFileName] where the file name needs no extension.\nFOR OBJs ONLY.");
return;
}
String fileName = args[0].trim();
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return (name.startsWith(fileName) && name.toLowerCase().endsWith(".obj"));
}
};
String[] frames = new File("./").list(filter);
Object3D model = Object3D.mergeAll(Loader.loadOBJ(frames[0], frames[0].substring(0, frames[0].lastIndexOf("."))+".mtl", SCALE));
Animation animation = new Animation(frames.length);
animation.createSubSequence(animationName);
System.out.println("\n\n\nFrames length: "+frames.length);
model.build();
for (int i = 1; i < frames.length; i++) {
System.out.println("I: "+i);
Object3D frame = Object3D.mergeAll(Loader.loadOBJ(frames[i], frames[i].substring(0, frames[i].lastIndexOf("."))+".mtl", SCALE));
frame.build();
Mesh mesh = frame.getMesh();
animation.addKeyFrame(mesh);
}
model.setAnimationSequence(animation);
try {
new DeSerializer().serialize(model, new java.io.FileOutputStream(fileName.substring(0, fileName.lastIndexOf("."))+".serialized"), false);
}
catch (java.io.IOException ex) {System.err.println("Trouble saving file: "+ex.getMessage());}
java.awt.Toolkit.getDefaultToolkit().beep();
}
}