HI all,
Just started using JME after a long time using JOGL and Java3D. Like it a lot so far but have run into a problem.
I'm trying to write a batch converter that will take a directory as reference, index all the .obj files in there and then convert them all out as .jme binaries. Problem I have right now is that whenever I call convert on the format converter I get a NullPointerException. I'm creating an InputStream using FileInputStream(new File("Blah")) and this is creating a valid InputStream. Have also checked that the files exist and are readable and that is fine.
My suspicion here is that the problem is caused by me not having created any sort of BaseGame for it all to run in. Can anyone confirm if this is the problem? If so what for of Game would be best as I don't want to do any rendering so I don't need a timing loop. This is just to batch convert a few hundred files.
Code (Sorry it's messy, what happens when you try and bug fix for 3 hours) is as follows:
Line causing the problem is in bold
private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {
File from = openFileChooser.getSelectedFile();
File to = saveFileChooser.getSelectedFile();
if (from != null && from.canRead() && to != null)
{
System.out.println("Fine go process from = " + from + " to = " + to);
try
{
// Convert obj format to jme format
FormatConverter converter = new ObjToJme();
// Tell the converter where the mtl file is
converter.setProperty("mtllib", from.toURI().toURL());
// Create an array to hold the jme file
ByteArrayOutputStream bo = new ByteArrayOutputStream(64);
BinaryImporter bi = new BinaryImporter();
Spatial mesh = null;
FileInputStream fis = new FileInputStream(from);
converter.convert(fis, bo);
mesh = (Spatial) bi.load(new ByteArrayInputStream(bo.toByteArray()));
// Create output file name
String inputFileName = from.getName();
String outputFileName = inputFileName.replaceAll(".obj", ".jme");
BinaryExporter be = new BinaryExporter();
File outputFile = new File(to.getPath(), outputFileName);
FileOutputStream fos = new FileOutputStream(outputFile);
be.save(mesh, fos);
fos.flush();
fos.close();
}
catch(IOException ioe)
{
System.out.println("IOException " + ioe);
}
catch (Exception e)
{
System.out.println("Error " + e);
}
}
else
{
System.out.println("Missing file fail from = " + from + " to = " + to);
}
}
You can probably create a DummyDisplaySystem… since creating Nodes and RenderStates does require a DisplaySystem to initialize them… If this is not solving your problem, then you should post the exact exception so we can trace it.
Thanks for the help, worked like a dream.