Model conversion outside SDK

I am having trouble using the Jmonkey SDK. I have started to use netbeans and I am able to build the samples and run them. However , I want to load in some 3d models. I’m looking for a tool that can convert from blend/obj to j3o. Is there any way to do this outside the automated Jmonkey SDK imports ?

Thank you,
Jojoofu

1 Like
<cite>@jojoofu said:</cite> I am having trouble using the Jmonkey SDK. I have started to use netbeans and I am able to build the samples and run them. However , I want to load in some 3d models. I'm looking for a tool that can convert from blend/obj to j3o. Is there any way to do this outside the automated Jmonkey SDK imports ?

Thank you,
Jojoofu

I’m almost 100% sure that the answer is NO.
It is recomended to use .j3o for final release but you can load blend/obj file on your game in the meantime. I think you should fix you Jmonkey SDK (at least to use the convertion to j3o fuctionality) or you should continue loading your models from blend/obj file on your game.

What do you mean by “automated” imports?

I don’t want to answer for @jojoofu but the “automated” stuff should be the feature in SDK that transform .obj or .xml file to .j3o
His question is still valid, is there a way to do it outside SDK?

.j3o is not an exchange format that you could convert outside of a project. If you have no project folders you cannot make j3o files. The wiki tells you how to write .j3o files but you cannot use them like exchange format files, e.g. in multiple projects or so as the internal paths point at locations specific to the project.

I managed to get the SDK working. However , it crashes constantly. I think it might be my crappy intel graphics card set. I am still having trouble getting textures to render on .mesh.xml files. All I see is red textures.

@jojoofu, I don’t use Intel card but Geforce and SDK RC2 also crashes (Linux 64-bit).

<cite>@jojoofu said:</cite> I managed to get the SDK working. However , it crashes constantly. I think it might be my crappy intel graphics card set. I am still having trouble getting textures to render on .mesh.xml files. All I see is red textures.

Thats the exact issue I mentioned with the paths. If you want to do it your own way without the project templates I suggest reading the whole wiki on asset management and trying to understand whats happening, e.g.
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_asset
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:intermediate:multi-media_asset_pipeline#create_textures_and_materials
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:external:blender

<cite>@normen said:</cite> Thats the exact issue I mentioned with the paths. If you want to do it your own way without the project templates I suggest reading the whole wiki on asset management and trying to understand whats happening, e.g.

I’m still trying to figure out of how to unwrap textures from an already textured model. I assume that’s the process of taking your already textured model and getting a map of the textures and putting said map into one material/texture.

I also still haven’t figured out why .obj files can have multiple textures and still render fine but .mesh.xml files can only have one. Is there something different in the format ?

I’m slowly working this out and once I’m done I am going to put all I learned in a video so hopefully no one else makes the same mistakes I did.

Back to the drawing board (literally)

1 Like

@normen

Good video , wish I would have had that before. I finally got my cow to animate with the textures , however there is one last problem. The animation only works as .mesh file. When I convert it to .j3o I get an error when loading the model. I’m using blender 2.6 with the latest ogre exporter. Has the jme format been updated to 2.6 yet ?

At least I can continue making my sample game. I will figure out why the j3o files will not load later.

The problem was it seems .mesh files only support one texture. I made a map then hand painted the textures on and use that as my only texture for my model.

<cite>@jojoofu said:</cite> Good video , wish I would have had that before.

We can’t do more than put it on the first page of the documentation wiki and link the documentation where you download the SDK, can we? :slight_smile:

@normen

lol , I didn’t make it that far yet. I started at the first tutorial and worked my way down. I have everything working now. I learned a lot about how 3d modeling works in the process. Now to get to some coding :>

For those of you who are having problems with Jmonkey SDK crashes still or you just want to use Netbeans for some other reason. Here is some code that will convert your models. Once converted you cannot move the .j3o file. Make sure you create the file in whatever folder its final destination will be. The only things you need to change is the directory where the model is located and the file name. Then change the save file location. Works so far on .obj models haven’t had time to test it on anything else , enjoy.

Updated so it works properly —

[java]package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.scene.Spatial;
import com.jme3.export.binary.BinaryExporter;
import com.jme3.light.DirectionalLight;
import com.jme3.math.Vector3f;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.applet.Main;

public class ManualConverter extends SimpleApplication {

public static void main(String[] args){
    ManualConverter app = new ManualConverter();
    app.start(); // start the game
}

@Override
public void simpleInitApp() {
 //register the folder where the file is located. Change this to the folder where you model
 // is located. This will be the same folder the new .j30 is output to. Once the .j3o is
 // is saved , you cannot move it to another folder.
    assetManager.registerLocator("C:/Users/Owner/Documents/NetBeansProjects/simplegame/assets/models", FileLocator.class);
    Spatial conversion = assetManager.loadModel("/lowpolycow/lowpolycow.obj");
    rootNode.attachChild(conversion);
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);
    
     BinaryExporter exporter = BinaryExporter.getInstance();
     // This will be the name of the output file. This should match the name of your model. The
     // only change is the extension will now be .j3o
     // For example troll.obj should be troll.j3o
     File file = new File("C:/Users/Owner/Documents/NetBeansProjects/simplegame/assets/models/lowpolycow/lowpolycow.j3o");
    try {
   exporter.save(rootNode, file);
     } catch (IOException ex) {
       Logger.getLogger(Main.class.getName()).log(Level.SEVERE, "Error: Failed to save game!", ex);
     }

}

}[/java]

It is important to note since this model is saved as a node it must be loaded as a node. To load new model

 [java]   Node loadedNode = (Node)assetManager.loadModel("/lowpolycow/lowpolycow.j3o");
    loadedNode.setName("loaded node");
    rootNode.attachChild(loadedNode);[/java]

@jojoofu, thanks for this tool, I’ll use it. But could we also manage the material and create .j3m files as well?

@jrijri I didn’t think about materials. I managed to get it to work with the mesh and obj files that have mtl files with them. I don’t think j3m actually changes the format but just puts it into binary for fast reading. Hopefully the bug with scene window causing crashes will be fully fixed soon so no one has to worry about manual conversion.