Locating assets, good practices at work?

I got a simple problem. When a tree is added to Forester and an impostor distance is set, the impostor texture must be either generated or loaded. I am very bad at asset management…



The way I solved this seems to work, but I’m curious if it’s really a good way of working. The first thing I did was to create a texture key with the model name (according to the naming conventions I use):





AssetKey texKey = new AssetKey(modelName);





To find out whether or not the texture exists, I do this:





AssetInfo locateAsset = assetManager.locateAsset(texKey);





If locateAsset is null, that means the texture does not exist and it will be generated. Otherwise it’s just loaded from the assets directory as usual.



I am worried about whether or not this is good practice, and also I am worried about the texture I create. The generated texture is written to disk, for later usage, but the new imagefile is never registered with the assetmanager. This is perfectly fine of course, as I can just get the texture object directly from the stored Texture object, but I am curious if there is some way to register images that are created and written during runtime, and if that should be done. Or more generally, if procedurally generated assets that are stored should be registered with the assetmanager during runtime as well.



I’m sure this is dumb, but I just want to get a heads up if possible. Otherwise I guess it’s not that big a deal.



Thanks!

I think you somehow can create your own asset locator :slight_smile:



See section: Loading Assets From Custom Paths

in https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_asset



Creating a custom locator maybe?

Hmm. I think that is not necessary. The image is put in the Assets/Textures/Impostors catalogue, which is already registered. But I think I get it now. The assets aren’t referenced at all by the assetmanager until you actually load them. So if I start the app, then add a bunch of stuff in the assets dir later and start loading, it will still work. So long as its added to the correct folders it doesn’t matter if you do it during startup or later.



The asset manager isn’t aware of individual assets until they have been loadAsset-ed. It only knows only in what folders it’s supposed to look for them.



EDIT: At least that’s how I think it works, from having read that beginner tutorial (for the 464’th time).

Just make the paths always absolute, never think relative. You can for example always put your tree images in Textures/Forester/Trees or something. If you keep that consistent with your own asset collections and within the users project then everything should work out.

1 Like

Ok. Get it now. Thanks…

Any good place in the docs to put this? Best practices?

Its in the manual.