[Solved] AssetManager cannot find texture associated to a model

I have a custom hierarchy of assets in a gradle subproject. The custom asset folder is actually the sourceSet main/resources.

For my game, here’s how I include the assets :

compile project(':assets').sourceSets.main.output
compile project(path: ':assets', configuration: 'generated')

I can load everything I want, however the asset manager cannot locate textures associated to a model because it tries to search in jme3’s default asset hierarchy.

GRAVE: Cannot locate texture Models/sword/sw_texture.png (Mipmapped)

Actually, the asset hierarchy looks like this :

I can bypass that by setting manually the texture in the material but it’s just a hassle for something that should be automatic.

How can I make the asset manager follows that hierarchy instead of the default one?

JME provides an AssetLocator interface that the AssetManager uses to locate assets. Look at this interface (and the default implementations that jME provides) and register either a suitable built in locator or a custom one.

1 Like

It’s not the root path that I need to override/set but each individual folders in the default hierarchy :confused:

The default AssetLocator is the ClasspathLocator and its path is “/”. I mean “/” is actually good for my project. It’s the subfolders the problem.

Does a symlink work maybe? Just a stab in the dark…

If it can’t locate that then it’s because the material is referencing that.

If you want to reference the png in a different place then change the material (j3m) to reference it in a different place.

One of the reliable (and sometimes infuriating) part of AssetManager is that it will not ‘search’ for stuff. It will look only where you tell it, basically.

1 Like

The model is an ogre.mesh with a skeleton and a material converted into a j3o. Even when I specifiy a j3m with the right texture which works on screen, the application still shows the GRAVE output searching for its texture in the Models folder, which does not exist.

As I recall, loading a model is supposed to also load its texture. https://jmonkeyengine.github.io/wiki/jme3/beginner/hello_asset.html

Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");

There’s no code for loading the ninja’s texture, yet it has one.

I think that the GRAVE output does not verify if I actually load a different texture.

The model I’m trying to load has the following path : model/man/man.j3o
However, jme3 searches for its texture in Models/man/man.j3o as if the first folder was hardcoded. Why can it identify the man folder but not replace Models by model? It is infuriating.

The material I had to create to patch that links a good texture. So my question is : is my only solution to create a j3m for every model?

So, I’m guessing this is what you did:
-used the SDK to import your model and save it as a j3o
-then copied everything to a new folder structure

…that won’t work because the importer already hard-coded the references to those files.

If you want to import your ogre files in this structure then you will have to import them FROM that structure so that the right paths get embedded into the j3o.

Else, fix it in j3m or programmatically.

1 Like

Ohhhh I didn’t know that! Thank you very much. I’ll try that right away.

What Paul says. Actually the Texture path will be what blender saw and if that path was outside of the assets directory, Textures get placed there (that’s what xbuf does, probably ogre importer won’t do that.
But at least it tries to do something, because it even searches Models/ instead of Textures/.

Another solution would be after loading the model just iterating over each geometry (SceneGraphTraversalAdapter (?)) and adjusting Textures