In my toy engine I currently have a MeshComponent
and a MaterialComponent
.
psuedo:
struct MeshComponent
{
Ptr<Mesh> Mesh;
};
struct MaterialComponent
{
Ptr<Texture> DiffuseTexture;
Ptr<Texture> NormalsTexture;
};
This is fine, for when a single mesh uses a single material.
pseudo:
Entity entity = CreateEntity();
AddComponentToEntity(entity, meshComponent);
AddComponentToEntity(entity, materialComponent);
But now I want to consider the concept of “sub-meshes” (regions of a mesh that are rendered with a different material, but each sub-mesh shares the parent vertex list). I don’t want my Mesh
class to know anything about materials, and vice-versa.
What good approaches are there for “joining” multiple MaterialComponent
to a single MeshComponent
?
I’ve considered having an entity for each sub-mesh, but that seems brittle (not to mention overkill, as I’m only interested in MaterialComponent
s).
pseudo:
struct MeshComponent
{
Ptr<Mesh> Mesh;
std::vector<Entity> SubMeshEntities; // Would need to ensure the indices match those of the sub-meshes
};
What other approaches are there?