Asset Loader Class
There's a discussion on the forum that sort of veered into talking about Khronos' GLTF file format specification:
Some of this gave me some ideas for changes in the art pipeline in Turbo Game Engine. I was not feeling very concentrated today so I decided to do some easy work and implement a loader class:
class Loader : public SharedObject { public: std::vector<wstring> extensions; virtual bool Reload(shared_ptr<Stream> stream, shared_ptr<SharedObject> o, const int flags = 0)=0; };
Then I created a TEX texture loader class:
class TEXTextureLoader : public Loader { public: virtual bool Reload(shared_ptr<Stream> stream, shared_ptr<SharedObject> o, const int flags = 0)=0; };
When the engine is initialized it creates a TEXTexLoader object and saves it in a list of texture loaders:
GameEngine::Initialize() { textureloaders.push_back(make_shared<TEXTextureLoader>()); }
And the class constructor itself creates an array of file extensions the loader supports:
TEXTextureLoader::TEXTextureLoader() { extensions = { "tex" }; }
When a texture is loaded, the engine looks for a texture loader that matches the extension or the loaded file path.
At this point, all we have done is restructured the engine to do the same thing it did before, with more code. But now we can add new loaders for other file formats. And that is exactly what I did. You can now load textures directly from PNG files:
class PNGTextureLoader : public Loader { public: virtual bool Reload(shared_ptr<Stream> stream, shared_ptr<SharedObject> o, const int flags = 0)=0; };
I've done the same thing for model file loading as well, although I have not yet added support for any other file types.
If we can add a C++ loader, we should be able to add one with Lua too. I haven't worked out the details yet, but it could work something like this:
function LoadModelObj( stream, model ) while stream:EOF() == false do -------------- end end AddModelLoader(LoadModelObj)
So with that, you could download a Lua script that would add support for loading a new file format.
I think in the new engine we will support all common image formats, including Photoshop PSD, as well as DDS, KTX, and our existing TEX files. Textures loaded from image formats will be less optimal because mipmaps will be generated on loading. Settings like clamping and filter modes will be stored in the associated .meta files, which means these files will start getting published along with your game asset files. This is a change from the Leadwerks 4 way of doing things.
- 1
- 2
3 Comments
Recommended Comments