refactor: reorganize Resources module into Core/Asset, Core/IO and Resources subdirectories
- Split core resource architecture into Core/Asset/ (IResource, ResourceManager, ResourceCache, etc.)
- Moved IO layer into Core/IO/ (IResourceLoader, ResourceFileSystem, etc.)
- Reorganized concrete resource types into Resources/{Texture,Mesh,Material,Shader,AudioClip}/
- Updated all include paths from relative to <XCEngine/...> format
- Fixed circular dependency in Material.h (removed unnecessary ResourceManager.h include)
- Fixed malformed include syntax in ResourceManager.h and AsyncLoader.h
- Fixed glad.h path issues in CMakeLists.txt
This commit is contained in:
73
engine/src/Resources/Material/MaterialLoader.cpp
Normal file
73
engine/src/Resources/Material/MaterialLoader.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "Resources/MaterialLoader.h"
|
||||
#include "Resources/ResourceManager.h"
|
||||
#include "Resources/ResourceTypes.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Resources {
|
||||
|
||||
MaterialLoader::MaterialLoader() = default;
|
||||
|
||||
MaterialLoader::~MaterialLoader() = default;
|
||||
|
||||
Containers::Array<Containers::String> MaterialLoader::GetSupportedExtensions() const {
|
||||
Containers::Array<Containers::String> extensions;
|
||||
extensions.PushBack("mat");
|
||||
extensions.PushBack("material");
|
||||
extensions.PushBack("json");
|
||||
return extensions;
|
||||
}
|
||||
|
||||
bool MaterialLoader::CanLoad(const Containers::String& path) const {
|
||||
Containers::String ext = GetExtension(path);
|
||||
return ext == "mat" || ext == "material" || ext == "json";
|
||||
}
|
||||
|
||||
LoadResult MaterialLoader::Load(const Containers::String& path, const ImportSettings* settings) {
|
||||
Containers::Array<Core::uint8> data = ReadFileData(path);
|
||||
if (data.Empty()) {
|
||||
return LoadResult("Failed to read material file: " + path);
|
||||
}
|
||||
|
||||
Material* material = new Material();
|
||||
material->m_path = path;
|
||||
material->m_name = path;
|
||||
material->m_guid = ResourceGUID::Generate(path);
|
||||
|
||||
Containers::String jsonStr;
|
||||
jsonStr.Reserve(data.Size());
|
||||
for (size_t i = 0; i < data.Size(); ++i) {
|
||||
jsonStr += static_cast<char>(data[i]);
|
||||
}
|
||||
|
||||
size_t shaderPos = jsonStr.Find("\"shader\"");
|
||||
if (shaderPos != Containers::String::npos) {
|
||||
size_t colonPos = jsonStr.Find(":", shaderPos);
|
||||
if (colonPos != Containers::String::npos) {
|
||||
size_t quoteStart = jsonStr.Find("\"", colonPos);
|
||||
size_t quoteEnd = jsonStr.Find("\"", quoteStart + 1);
|
||||
if (quoteStart != Containers::String::npos && quoteEnd != Containers::String::npos) {
|
||||
Containers::String shaderPath = jsonStr.Substring(quoteStart + 1, quoteEnd - quoteStart - 1);
|
||||
auto shaderHandle = ResourceManager::Get().Load<Shader>(shaderPath);
|
||||
if (shaderHandle.IsValid()) {
|
||||
material->SetShader(shaderHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
material->m_isValid = true;
|
||||
material->m_memorySize = sizeof(Material) + material->m_name.Length() + material->m_path.Length();
|
||||
|
||||
return LoadResult(material);
|
||||
}
|
||||
|
||||
ImportSettings* MaterialLoader::GetDefaultSettings() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool MaterialLoader::ParseMaterialData(const Containers::Array<Core::uint8>& data, Material* material) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Resources
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user