Idea/Suggestion/Discussion AssetInterceptor

Basic Idea, when loading a Asset, go trough a supplied List of AssetInterceptors, that can but not must manipulate the AssetKeys.



Why is this usefull? Implementing global switches to all Materials, assets loaded by whatever subsystem. For example I can intercept all Materials that are loaded from a j3o files, and change the textures based on a global constant with a LOW_ or a HIGH_ giving me a easy way to gobally change the texture details. With that system I only need to provide all textures in high and in low resolution, but do not need to construct any meterial for two resolutions wich is kinda a hassle.



Without i would either have to loop trough each loaded model and change for any found material the assetkeys, → First they would be loaded in low than i manually need to change all to high. Or provide two j3o for each model, one with low one with high material.

Now lets say I want to enable disable vertexlighting if a lighting material is requested based on some constant as well → 4 materials or 4 models. Incloude the ability to enable disable parralax mapping 8 materials or 8 models.



I guess using a interceptor would be way simpler here, it would basically onle be a check if the currently loaded object is a meterial, th material i want o change, and then simple change the value. This would be less than 100lines of code.



Other uses: Global level of detail for models, Audioquality, Shaders (just transparently replace a .vert file on assetmanager request with a different one)



Now discussion: Does this make sense? Do you see any problems? If the Idea is agreed to be usefull, I will create a implementation and contribute it :slight_smile:

All of these seem like things I’d want to change at runtime after the asset was already loaded, though. I don’t think I’d want to reload all of my materials and models just because the user selected “low quality” textures in some checkbox somewhere.



Whether your idea has merit or not, I don’t know… but it doesn’t seem to solve the proposed problem, to me.

Well yes i suppose it would not change the ones currently displayed, however all loaded via assetmanager after that will be changed.



Do you have a alternative approach how to do this for the currently displayed as well? Cause I think this is a engine level stuff, that most game engine already have in the core somewhere.

You would have a class that assembles your “Entity Models” or w/e you wanna call them. Its would be a special class with data specific to your models and also allows you to configure them (e.g. material etc.). You can load materials and apply them. You can save materials and load them along with the model. If you don’t want to use what the engine brings to support this then it doesn’t make sense to add systems til we got one that fits your idea. If you want this as you describe it, you can already implement asset locators and loaders yourself to provoke the indicated behavior.

Well you are right the second part i get, i could do this with the loaders and locators already.



But the first one I cant get what you mean? Are you really sugesting that i store somewhere a object for each of my models containing stuff like material, the parameters ect? And then change those a needed? I cant follow could you give a simple example of what you mean?

@EmpirePhoenix said:
But the first one I cant get what you mean? Are you really sugesting that i store somewhere a object for each of my models containing stuff like material, the parameters ect? And then change those a needed? I cant follow could you give a simple example of what you mean?

No I mean you have the data (what material, what model etc.) somewhere and in the moment the entity is actually on screen you have a class that assembles that inside the engine (so loads the model, applies the material etc) and then manages the spatials lifetime on screen til the entity is out of reach.

Ah, well I have that data only in the j3o, since the data is directly from the ogre loader (with very little processing on convertation to j3o). The models(j3o) are then represented as a integer only, since the networking and the server doe actually not care at all about what the model is. Also the j3os can contain from a single cube to a complete 3d world anything, so multiple materials and multiple geometrys)



The way you suggest would involve tons of work, since I must extract all those data from the models into some database or similar. wich is a bit extreme for a few thousand models. Only to prefix some texture names and similar in the end.



Can you imagine a simple way to archive this? or should i go with own locators/loaders?

Your whole game should work without the scenegraph or any spatials. Maximum some markers or locations from manually edited levels. Is that so for you? I am asking because I don’t exactly know your code and the “mistake” of tying actual spatials and “npcs” too close together. For example if you only have the worldTranslation of your Spatial as an indicator where your npc is then you either did something wrong or you wrote a first person shooter :slight_smile:

Actually there is a entity system behind, but it only knows the id of the model, all changes to the models I want to do is only for performance reasons.



So my engine knows a object with id x is at location y. It has no knowledge what that object actually is. Eg material parameters ans such. So im locking for a good way to manipulate the grafical model properties eg. texture resolutions on a global level is what i search for. (mostly to get more performance on slower hardware)

I would probably replace the existing loader with a slightly changes version, which grabs some game settings and load’s the appropriate texture/shader.



Should afaik only be a fairly small amount of change needed… Might not be the best method in terms of reusability but it should work. Since you already have a ES in the background it should even possible to do the changes at runtime if there is a possibility to clear the asset cache. At least it would be possible with my ES. But in terms of user experience i probably would force a restart since the lag while loading all the new assets might be more disturbing than dooing a full restart…



But i have to say that i am not a fan of ‘minimum detail’ modes, and the game i show here mostly is gothic 3… For me playing it is not the same game if played at minimum, and i was really dissapointed when i played it the first time after seeing only the preview’s and press pics claiming ‘In game GFX’…



min:

https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQH86xfvDoDHq7_TOLVx3YL_c4OBsGo-ikcCnH-Ew0exW3ji-ip



max:

https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTK5olnL5hMztS1jKhRfzefqOwsl3vdkCrwbdEKLV_Y4Wm25C8Q

@EmpirePhoenix said:
Well yes i suppose it would not change the ones currently displayed, however all loaded via assetmanager after that will be changed.

Do you have a alternative approach how to do this for the currently displayed as well? Cause I think this is a engine level stuff, that most game engine already have in the core somewhere.


My alternate approach isn't pretty... but when I load assets, I go through and fine the materials so that I can tweak them later. Actually, I change the materials from the j3o into my own and just copy the textures over from blender. So I have some kind of material manager, basically.

I agree with the premise of your issue... I just didn't think that suggested changes necessarily solve the problem that elegantly. My users can adjust the quality at runtime and then everything on the screen changes. In some cases, I just go through and set some material parameters but in other cases I have to completely rebuild my dynamic geometry (something specific to my type of game, I guess).

Well I currently use a restart on change approach. So that is not a problem for me. Of curse while being possible like in gothic, I dont want that extreme detail levels, but some is needed. Eg disable parralax mapping might lead quite to some increase without being to extreme on the perceived level of details. Other necessary is a rough estimation for vram, eg use 512 1 gb or 2gb (in sum for everything) texture resolutions.

…so if you have a system like I outlined it should be easy to just set a flag and it will load the “low quality” materials instead. Ofc theres the issue of restarting for OpenGL1 or such things but you should at least be able to suffix texture names with a _512 / _1024 or so.

Yes, but someone would need to supply that system with all the data, wich needs quite some time. Till all texturenames/modles/materials are enterd into it.

@EmpirePhoenix said:
Yes, but someone would need to supply that system with all the data, wich needs quite some time. Till all texturenames/modles/materials are enterd into it.

If you don't want random space ships you'll have to provide this data anyway :) You can use subfolders in the assets folder and a generated assets file though.