Import material textures with mesh assets
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include <XCEngine/Resources/Mesh/Mesh.h>
|
||||
#include <XCEngine/Resources/Material/Material.h>
|
||||
#include <XCEngine/Resources/Texture/Texture.h>
|
||||
#include <cstring>
|
||||
|
||||
namespace XCEngine {
|
||||
@@ -11,6 +13,8 @@ void Mesh::Release() {
|
||||
m_vertexData.Clear();
|
||||
m_indexData.Clear();
|
||||
m_sections.Clear();
|
||||
m_materials.Clear();
|
||||
m_textures.Clear();
|
||||
m_vertexCount = 0;
|
||||
m_vertexStride = 0;
|
||||
m_attributes = VertexAttribute::Position;
|
||||
@@ -52,10 +56,41 @@ void Mesh::AddSection(const MeshSection& section) {
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Mesh::AddMaterial(Material* material) {
|
||||
m_materials.PushBack(material);
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Mesh::AddTexture(Texture* texture) {
|
||||
m_textures.PushBack(texture);
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
Material* Mesh::GetMaterial(Core::uint32 index) const {
|
||||
if (index >= m_materials.Size()) {
|
||||
return nullptr;
|
||||
}
|
||||
return m_materials[index];
|
||||
}
|
||||
|
||||
void Mesh::UpdateMemorySize() {
|
||||
m_memorySize = m_vertexData.Size() +
|
||||
m_indexData.Size() +
|
||||
m_sections.Size() * sizeof(MeshSection);
|
||||
m_sections.Size() * sizeof(MeshSection) +
|
||||
m_materials.Size() * sizeof(Material*) +
|
||||
m_textures.Size() * sizeof(Texture*);
|
||||
|
||||
for (const Material* material : m_materials) {
|
||||
if (material != nullptr) {
|
||||
m_memorySize += material->GetMemorySize();
|
||||
}
|
||||
}
|
||||
|
||||
for (const Texture* texture : m_textures) {
|
||||
if (texture != nullptr) {
|
||||
m_memorySize += texture->GetMemorySize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Resources
|
||||
|
||||
Reference in New Issue
Block a user