Better asset baking + manifest scaning on project load
This commit is contained in:
@@ -384,8 +384,7 @@ namespace Nuake
|
||||
// TODO(antopilo) only generate manifest in editor context
|
||||
|
||||
FileSystem::SetRootDirectory(FileSystem::GetParentPath(project->FullPath));
|
||||
|
||||
GenerateManifest(project);
|
||||
GenerateManifest();
|
||||
|
||||
if (!Engine::SetCurrentScene(currentProject->DefaultScene))
|
||||
{
|
||||
@@ -405,6 +404,7 @@ namespace Nuake
|
||||
|
||||
void Engine::GenerateManifest()
|
||||
{
|
||||
Logger::Log("Generating project manifest", "manifest", VERBOSE);
|
||||
// This will auto generate a manifest entry for all assets in the project
|
||||
ResourceManifest& manifest = ResourceManager::Manifest;
|
||||
ResourceResolverManager& resolverManager = ResourceResolverManager::Get();
|
||||
@@ -415,6 +415,8 @@ namespace Nuake
|
||||
return; // We don't care about this file type, we dont support it.
|
||||
}
|
||||
|
||||
Logger::Log("Adding " + file->GetName() + " to manifest", "manifest", VERBOSE);
|
||||
|
||||
// Register the resource in the manifest
|
||||
const std::string& path = file->GetRelativePath();
|
||||
const UUID uuid = resolverManager.ResolveUUID(file);
|
||||
|
||||
@@ -25,12 +25,12 @@ void FileSystem::ForeachFile(OnFileFunc func)
|
||||
|
||||
void FileSystem::ForeachFile(OnFileFunc func, Ref<Directory> dir)
|
||||
{
|
||||
for(auto& file : RootDirectory->Files)
|
||||
for(auto& file : dir->Files)
|
||||
{
|
||||
func(file);
|
||||
}
|
||||
|
||||
for(auto& dir : RootDirectory->Directories)
|
||||
for(auto& dir : dir->Directories)
|
||||
{
|
||||
ForeachFile(func, dir);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "src/Core/Logger.h"
|
||||
#include "src/Core/String.h"
|
||||
|
||||
#include "src/FileSystem/Directory.h"
|
||||
#include "src/Rendering/Textures/Material.h"
|
||||
#include "src/Rendering/Mesh/Mesh.h"
|
||||
#include "src/Resource/Model.h"
|
||||
@@ -46,9 +46,10 @@ Ref<File> GLTFBaker::Bake(const Ref<File>& file)
|
||||
|
||||
importer.FreeScene();
|
||||
|
||||
// Write those meshes to disk!
|
||||
// Write to disk
|
||||
std::vector<Mesh> meshes;
|
||||
|
||||
std::map<std::string, Ref<Material>> materialCache;
|
||||
Ref<Model> model = CreateRef<Model>();
|
||||
for(auto& meshData : meshesData)
|
||||
{
|
||||
@@ -56,46 +57,58 @@ Ref<File> GLTFBaker::Bake(const Ref<File>& file)
|
||||
mesh->SetData(meshData.vertices, meshData.indices);
|
||||
|
||||
const BakerMaterialData materialData = meshData.material;
|
||||
Ref<Material> material = CreateRef<Material>();
|
||||
|
||||
if(!materialData.albedo.empty())
|
||||
{
|
||||
material->SetAlbedo(absolutePath + "/../" + materialData.albedo);
|
||||
}
|
||||
|
||||
if(!materialData.normal.empty())
|
||||
{
|
||||
material->SetNormal(absolutePath + "/../" + materialData.normal);
|
||||
}
|
||||
|
||||
if(!materialData.ao.empty())
|
||||
{
|
||||
material->SetAO(absolutePath + "/../" + materialData.ao);
|
||||
}
|
||||
|
||||
if(!materialData.metallic.empty())
|
||||
{
|
||||
material->SetMetalness(absolutePath + "/../" + materialData.metallic);
|
||||
}
|
||||
|
||||
if(!materialData.roughness.empty())
|
||||
{
|
||||
material->SetRoughness(absolutePath + "/../" + materialData.roughness);
|
||||
}
|
||||
|
||||
|
||||
std::string materialPath;
|
||||
if(!materialData.albedo.empty())
|
||||
Ref<Material> material;
|
||||
if (!materialData.albedo.empty())
|
||||
{
|
||||
materialPath = file->GetRelativePath() + "." + materialData.albedo + ".material";
|
||||
materialPath = FileSystem::GetParentPath(file->GetRelativePath()) + FileSystem::GetFileNameFromPath(materialData.albedo) + ".material";
|
||||
}
|
||||
ResourceManager::RegisterResource(material);
|
||||
ResourceManager::Manifest.RegisterResource(material->ID, materialPath);
|
||||
|
||||
std::string materialJson = material->Serialize().dump(4);
|
||||
FileSystem::BeginWriteFile(materialPath);
|
||||
FileSystem::WriteLine(materialJson);
|
||||
FileSystem::EndWriteFile();
|
||||
|
||||
|
||||
if (materialCache.find(materialPath) != materialCache.end())
|
||||
{
|
||||
material = materialCache[materialPath];
|
||||
}
|
||||
else
|
||||
{
|
||||
material = CreateRef<Material>();
|
||||
if (!materialData.albedo.empty())
|
||||
{
|
||||
material->SetAlbedo(absolutePath + "/../" + materialData.albedo);
|
||||
}
|
||||
|
||||
if (!materialData.normal.empty())
|
||||
{
|
||||
material->SetNormal(absolutePath + "/../" + materialData.normal);
|
||||
}
|
||||
|
||||
if (!materialData.ao.empty())
|
||||
{
|
||||
material->SetAO(absolutePath + "/../" + materialData.ao);
|
||||
}
|
||||
|
||||
if (!materialData.metallic.empty())
|
||||
{
|
||||
material->SetMetalness(absolutePath + "/../" + materialData.metallic);
|
||||
}
|
||||
|
||||
if (!materialData.roughness.empty())
|
||||
{
|
||||
material->SetRoughness(absolutePath + "/../" + materialData.roughness);
|
||||
}
|
||||
|
||||
|
||||
ResourceManager::RegisterResource(material);
|
||||
ResourceManager::Manifest.RegisterResource(material->ID, materialPath);
|
||||
|
||||
std::string materialJson = material->Serialize().dump(4);
|
||||
FileSystem::BeginWriteFile(materialPath);
|
||||
FileSystem::WriteLine(materialJson);
|
||||
FileSystem::EndWriteFile();
|
||||
|
||||
materialCache[materialPath] = material;
|
||||
}
|
||||
|
||||
mesh->MaterialResource = RID(material->ID);
|
||||
model->AddMesh(std::move(mesh));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <json/json.hpp>
|
||||
|
||||
#include "src/Core/Core.h"
|
||||
#include "src/Resource/UUID.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
@@ -103,6 +104,7 @@ namespace Nuake
|
||||
class ISerializer
|
||||
{
|
||||
public:
|
||||
virtual UUID DeserializeUUID(const std::string& file) = 0;
|
||||
virtual Ref<Material> DeserializeMaterial(const std::string& path) = 0;
|
||||
virtual bool SerializeMaterial(const std::string& path, Ref<Material> material) = 0;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Nuake
|
||||
~BinarySerializer() = default;
|
||||
|
||||
public:
|
||||
UUID DeserializeUUID(const std::string& path);
|
||||
UUID DeserializeUUID(const std::string& path) override;
|
||||
|
||||
Ref<Material> DeserializeMaterial(const std::string& path) override;
|
||||
bool SerializeMaterial(const std::string& path, Ref<Material> material) override;
|
||||
|
||||
Reference in New Issue
Block a user