A bit of context: I'm developing a 3D rendering engine and can't really make much more progress until I get some more interesting and complex meshes loaded in to the scene. So far I have been using built-in simple meshes like cubes and planes. I have written a Mesh
class to take a MeshData
struct which contains Position
, Normal
, Tangent
, Bitangent
, Colour
, Texture Coordinate
, and optional Face
data. The Mesh
class takes this data and depending on a few things it will generate a VBO with all of the available data interleaved, an EBO, and a VAO which has both the VBO and EBO (if one exists) bound to it. I've been pretty happy with this so far and it works fine with a simple .OBJ which contains a relatively straight-forward mesh.
Currently I have an asset management system which allows me to load in assets like this:
Mesh * teapot = AssetManager::loadGlobalAsset<Mesh>("res/meshes/teapot.obj");
If the returned pointer == nullptr
then the assets doesn't exist. If it isn't nullptr
then one of three things just happened: (1) the asset was just newly created and successfully loaded in to the asset manager's pool of assets, (2) the asset was found to already exist in the pool of assets and its pointer returned, (3) the asset was found to already exist in the pool of assets, but was unloaded, so it was loaded and its pointer returned.
As I said this works great for simple meshes but I'm a bit stuck on what to do and what changes I now need to make to load meshes which have multiple sub-meshes which might have individual materials.
For example the Sponza mesh has many sub-meshes which make use of a set of materials.
I could just load the mesh right in to my scene and have the mesh spread across multiple scene nodes all with a common ancestor node, but then this would defeat the purpose of an asset manager and I would have to worry about cleaning up and unloading the mesh outside of the asset manager. I could also just load the mesh as one big combined mesh, but of course then I can't assign individual materials to the sub-meshes without a lot of trouble.
I currently can't load the mesh using my asset manager as assets are identified by the hash of their filepaths, and here we have a situation where many individual meshes technically have the same filepath. If I just create new assets and give them to the asset manager with an ID to later fetch the asset (which isn't necessarily a bad idea for built in assets (I think)), then I feel I have the following issues:
- Easy to add multiple assets with same ID
- Breaks the connection between the meshes contained in a single mesh file
- No way of actually knowing the ID of a mesh which was loaded in via a mesh file
- Would have to manually recreate the whole mesh from its loaded sub meshes if I wanted to simply display the mesh as-is.
There is also the issue of where to store the materials that are included in the material library that a mesh file might reference. Do I create new material assets from this library, add them to the manager, and then have the mesh somehow reference these materials? But then how would I reference these materials manually? It's a similar issue to last point from the above list. Also, meshes don't currently have any knowledge of its material, that's the scene node's job.
Thanks for any thoughts or comments on this issue. I'd be very interested to hear what you guys think.
obj
file that can contain multiple objects? \$\endgroup\$