[SOLVED] How do you add new asset *types* to the engine?

Long ago, when i first decided i would make a 3D game, and looked at JME3, I learned that the models are made with tools like Blender.

So I set about to learn Blender first, and after about one month, I came to the conclusion that it, and probably any other similar tool, was too much for my little brain, (and non-existent artistic talent), and that it would be quicker to create my own “model editor”, and use that to create my models. So far, it still seems I’m right. In fact, I’m going to make editors for all my specific asset types, and there will be at least a dozen of them.

So I would like to know how I should go about extending the AssetManager to manage new asset types. Ideally using composition instead of inheritance, so that new asset types could be added through some kind of plugin at runtime. Once done, some of those assets would be converted to 3D models, textures, … (existing asset types), while the reset would become part of the “game logic”.

I would also need to create my own “asset database”, but I think there is some info about that in the wiki already.

My “concept”, is that it should be possible to create the game assets from within the game, with a few exceptions, like sounds/music. And it should be as easy as possible, so that even “players” can do it.

The main road-block I can see ahead is when I get to animating the models. But since my models will have to be converted to “standard models”, so they are usable by JME, I can still use something like Blender for the animation, if all else fails.

OK, a quick browse through the code tells me at least this:

For an “Asset DB”, I need at least:

  • An AssetLocator implementation.
  • An AssetInfo implementation

Per asset type I need:

  • An AssetLoader implementation
  • An AssetKey implementation.

I’m having issues with JME (NetBeans) to find out where what is used (“Find Usages”). In Eclipse, the search searches both in the project sources, and all the dependencies/libraries. It seems like JME/NetBeans only search in the project source, but not in the dependencies/libraries. If I knew how to find usages in the libraries, it would be easier for me to know what else I need to implement, and where to “register it”. Googling did not help me on this one. :frowning:

How would a library depend on code from the project its added to :? Also for me the find class etc. works, also within external libs (if they supply the sources).

Maybe I wasn’t clear. To put it very concretely, here is an example:

I was wondering if I should extend Application directly, instead of SimpleApplication, so I asked myself, who/what uses “SimpleApplication” in the JME libraries. Using “Find Usages” never returns anything outside of the projects own code, and I don’t see any checkbox saying to search in “dependency” (maybe I’m blind?). Maybe there is another alternative to “Find Usages” that search for usage in the libraries. Also, Eclipse searches in the compiled jars too, so it should find all occurrences, which is a “good thing”. :slight_smile: But it’s not about bashing NetBeans; since I decided to use the JME SDK, I just want to know how to get productive in it, and “searching for all references” is how I normally explore new third-party code that I’m trying to learn.

Your way to deduce the usage of SimpleApplication doesn’t really work for the most common situations. Any external access should be done via the lowest common denominator anyway, so even if it works it doesn’t give you the info you want actually. Also, you don’t need to extend any application at all to make a model loader or locator :? I suggest you learn a bit more about asset handling in jme before you attempt to write a loader :wink:
A simple example of loaders and locators is NeoTexture:

We really named these classes incorrectly.

We should have called Application: ClassThatMakesYouDoEverythingYourselfAlmostMightAsWellBeUsingLwjglDirectly

And we should have called SimpleApplication: Application

There is 0 reason not to extend SimpleApplication. If you don’t you will have to manage your own app states, your own root node updates, etc… then you will have some problem that turns out you forgot to cut and paste a part from SimpleApplication.

1 Like

@pspeed OK. I think I got the message. :slight_smile:

And I solved my “search-only-works-on-source-files” problem by downloading the JME3 source into the SDK. Now the search shows everything. :slight_smile:

To answer my own question, I tried to look at all the code related to assets, and it eventually became clear that the AssetManager is fully generic, and does not need to be extended. What confused me into thinking I needed to, was the fact that it contains methods like “Texture loadTexture(TextureKey)”; I thought I therefore had to extend it, and add my Thingy loadThingy(ThingyKey) methods.

But if fact, it seems like I probably only need one implementation of:

  • AssetLoader
  • AssetKey
  • AssetProcessor (if my assets are CloneableSmartAsset)
    per new asset type. And the call AssetManager.registerLoader(ThingyLoader)

Many assets implement CloneableSmartAsset, but not all, in particular: Shader, Filter, OgreMaterial and Model.
Presumably, immutable assets don’t need to be cloned, and maybe some simply cannot be cloned, if they come from third-party APIs, …

1 Like

Isn’t that what I said? Or what should have become apparent by looking at the examples I posted? ^^

I followed your suggestion: “I suggest you learn a bit more about asset handling in jme”. And then I learned how it went, and that my assumptions were wrong. I just thought that your answer was a bit, well, short, and that re-iterating my conclusion in details might benefit someone else who would ask themselves the same question, and find this thread while searching. I think it’s just a habit I got from using StackOverflow, which follow the principles of: 1) Search first, to make sure that question wasn’t asked before. 2) Don’t ask a question, if it was asked before and already has a useful answer. 3) Make sure the answer is general enough, so that it can be useful to other people as well. I wasn’t trying to contradict you in any way; just trying to make the answer clear, explicit and detailed. Does that go against this “forum culture”? :-? In some places, is is regarded acceptable for novice to ask old questions again, as it allows for more “interaction”. In that case, specific answers are preferred over general ones. I’m not really sure what is more appropriate here.

1 Like

Sounds like a good policy to me @monster :slight_smile:

The response to repeated questions depends on just how repeated they are. If something is covered in the tutorials or easy to find on the search then people will generally get pointed to the tutorials/search functionality. Something more specific or harder to find gets a fuller answer.

Hehe, I was referring to “answering your own question”, it sounded like you were disappointed with the answers you got. Yes, it is the best way to solve these issues ^^