Can I convert ogremesh xml to j3o WITHOUT using the SDK?

I can’t even see a project when I use the SDK and after about 1.5 days I gave up and solved all my problems in another way.

But now I’m using android, and my models needs to be j3o. Can I go to the SDK exe directory with cmd and do some command like:SDK -convert myfile or something?



This is one of the last problems im facing until i can finaly see my game on my cellphone and my dream comes true :stuck_out_tongue:

You can load the asset with the AssetManager.loadModel(), then save your Scene, Geometry, whatever to j3o using BinaryExporter.

At least this is how I convert my Blender files. :slight_smile:

Smart!

I made a program for those who don’t know how to do this:

[java]import java.io.File;

import java.io.IOException;



import com.jme3.app.SimpleApplication;

import com.jme3.asset.plugins.FileLocator;

import com.jme3.export.binary.BinaryExporter;

import com.jme3.scene.Spatial;



public class MainClass extends SimpleApplication{



public static void main(String[] args){

new MainClass().start();

}



public MainClass(){

this.showSettings = false;

}



private static String source = “C:/Users/Ägaren/Desktop/”;

private static String name = “rocket”;



@Override

public void simpleInitApp() {

assetManager.registerLocator(MainClass.source, FileLocator.class.getName());

Spatial model = assetManager.loadModel(name+".mesh.xml");

BinaryExporter ex = BinaryExporter.getInstance();

File f = new File(source+name+".j3o");

try {

ex.save(model, f);

System.out.println("


");
System.out.println("File "+name+" was successfully converted to j3o.");
System.out.println("Path to j3o: "+source+name+".j3o");
System.out.println("
");
this.stop();
} catch (IOException e) {
e.printStackTrace();
}
}
}[/java]

Simply replace source with the path to the folder of your model
Then the model name WITHOUT the .mesh.xml.

Nice @Addez !



I’m actually doing something similar for a Radiant (.map) compiler that i’m writing.



I modified your above code to allow for selection of the model via JFileChooser dialog instead of having to hard code it into the app:



[java]import java.io.File;

import java.io.IOException;

import javax.swing.filechooser.FileFilter;

import javax.swing.JFileChooser;



import com.jme3.app.SimpleApplication;

import com.jme3.asset.plugins.FileLocator;

import com.jme3.export.binary.BinaryExporter;

import com.jme3.scene.Spatial;



public class MainClass extends SimpleApplication{



public static void main(String[] args){

new MainClass().start();

}



public MainClass(){

this.showSettings = false;

}









@Override

public void simpleInitApp() {



JFileChooser ofDialog = new JFileChooser();



ofDialog.setCurrentDirectory(new File("."));



FileFilter filter = new FileFilter() {





@Override

public boolean accept(File f) {



if(f.isFile() && !f.getAbsolutePath().endsWith(".mesh.xml")) { //You can add multiple filetype

//filters here…



return false;



}



return true;



}





@Override

public String getDescription() {

return “OGRE XML (.mesh.xml) Files”;

//throw new UnsupportedOperationException(“Not supported yet.”);

}



};





ofDialog.setFileFilter( filter);



ofDialog.showOpenDialog(ofDialog);



if(!ofDialog.getSelectedFile().exists()){

//Invalid File



System.err.println(“No file selected OR file does not exist!n Aborting…”);



this.stop();



}



String filepath = ofDialog.getSelectedFile().toString();

String newpath = filepath.substring(0,filepath.indexOf(".") - 1);





assetManager.registerLocator(MainClass.source, FileLocator.class.getName());

Spatial model = assetManager.loadModel();

BinaryExporter ex = BinaryExporter.getInstance();

File f = new File(newpath + “.j3o”);



try {



ex.save(model, f);



System.out.println("


");
System.out.println("File " + newpath.substring(newpath.lastIndexOf("\"), newpath.length() -1) +" was successfully converted to j3o.");
System.out.println("Path to j3o: "+ newpath +".j3o");
System.out.println("
");

this.stop();

} catch (IOException e) {
e.printStackTrace();
}
}
}[/java]

This way you can just compile the jar and run it as is.

NOTE: This wasn't tested, I just wrote it on the fly.

-Feen
1 Like

ALSO, it looks like the filters on the forum don’t care for the ‘backslash’ so in the above code…



Line 59 should have a newline character in it instead of just !n…



Line 78 should have an escaped backslash in the .lastIndexOf() part…



HTH

-Feen

Referring to the first piece of code posted here by “Ägaren”
You need to add some escape characters to those bbcode_rule strings to be able to run them

Otherwise, it works. Helped me run my thing on android. Thanks!

Does the j3o format include bones and animations?

Note that j3o is not an exchange file format, the image paths will be stored absolute so you can only load the j3o file in the same folder configuration that you saved them in. This is why the SDK handles the assets folder for the project.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.