Troubles converting gltf to j3o

I’m using the below code to load a model. It saves successfully and I dont see anything in the BinaryExporter.save() that indicates its running async or in a background thread. And I dont see any listeners so when it completes it should be there to load. I have also tried using Thread.sleep() in between saving and loading without success. Exception in thread "Thread-2" com.jme3.asset.AssetNotFoundException: conversions/SK_Mummy.j3o. I’m sure I’m missing something simple but I cant seem to find it yet.

fun loadModel(path: String) {
    Thread {
        val model: Spatial = assetManager.loadModel(path)
        var j3o: Spatial? = null

        val filename = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."))
        val j3oPath = "conversions/$filename.j3o"

        val conversion = File((j3oPath))
        val be = BinaryExporter()
        try {
                be.save(model, conversion)// successfully completes successfully
                j3o = assetManager.loadModel(j3oPath)// AssetNotFoundException
            } catch (e: IOException) {
                e.printStackTrace()
            }

            listener.onModelReady(j3o!!)
        }.start()
    }

I think the assetmanager and binary exporter have different roots (the asset manager being for loading from resources after all). Have you looked in the file system to see if the j3o is there?

(I assume this is just a minimal example to demonstrate the issue? There isn’t really a good reason to save then immediately reload an asset)

1 Like

I was trying to load and convert the asset in one step. This makes sense however. Can the BinaryExporter save to the resources directory?

richtea is right. By default, asset manager will be reading assets from the application jar (or assets.jar).

This is somewhere on disk.

You’d have to configure the asset manager to read from there using an asset locator.

Note that if you just want to convert models and potentially run some scripts to clean them up then there is the jmec utility: GitHub - Simsilica/JmeConvert: A command line utility for converting models to J3O and copying their dependencies to a new target structure.

2 Likes

I was trying to load and convert the asset in one step.

But why? The reason to have a j3o is it loads faster. Saving then reloading is obviously slower than just having it already loaded.

You create j3o on your development machine then ship them to the end user so the end user has a faster load time

I read that assets should be converted to j3o to improve performance. If its only because it loads faster then I probably dont need to convert it. Things may have improved now.

Yeah, it improves load performance. It doesnt affect performance beyond that. If you want to ship another model format nothing terrible will happen, your users will just have a load screen for a little longer (or little hiccups as models are loaded during runtime if you aren’t loading async)

1 Like

Good to know thank both for the assistance.