fix: material serialization
This commit is contained in:
@@ -32,6 +32,8 @@ public:
|
||||
|
||||
[[nodiscard]] std::filesystem::path GetCookedPathForFile(std::string_view vpath) const;
|
||||
|
||||
[[nodiscard]] std::optional<std::string> ToVirtualPath(const std::filesystem::path& fullPath) const;
|
||||
|
||||
private:
|
||||
static std::vector<uint8_t> ReadFile(const std::filesystem::path& fullPath);
|
||||
|
||||
|
||||
@@ -19,6 +19,13 @@ class ImageCache {
|
||||
friend class ResourcesInspector;
|
||||
|
||||
public:
|
||||
struct LoadedImageInfo {
|
||||
std::filesystem::path path;
|
||||
TextureIntent intent;
|
||||
VkImageUsageFlags usage;
|
||||
bool mipMap;
|
||||
};
|
||||
|
||||
explicit ImageCache(GfxDevice& gfxDevice);
|
||||
|
||||
ImageID loadImageFromFile(
|
||||
@@ -29,6 +36,7 @@ public:
|
||||
ImageID addImage(GPUImage image);
|
||||
ImageID addImage(ImageID id, GPUImage image);
|
||||
[[nodiscard]] const GPUImage& getImage(ImageID id) const;
|
||||
[[nodiscard]] const LoadedImageInfo* findLoadedImageInfo(ImageID id) const;
|
||||
void removeImage(ImageID id);
|
||||
|
||||
[[nodiscard]] ImageID getFreeImageId() const;
|
||||
@@ -57,12 +65,6 @@ private:
|
||||
std::shared_ptr<std::vector<ImageID>> freeIds = std::make_shared<std::vector<ImageID>>();
|
||||
GfxDevice& gfxDevice;
|
||||
|
||||
struct LoadedImageInfo {
|
||||
std::filesystem::path path;
|
||||
TextureIntent intent;
|
||||
VkImageUsageFlags usage;
|
||||
bool mipMap;
|
||||
};
|
||||
std::unordered_map<ImageID, LoadedImageInfo> loadedImagesInfo;
|
||||
ImageID errorImageId{NULL_IMAGE_ID};
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
void cleanup(GfxDevice& gfxDevice);
|
||||
|
||||
MaterialID addMaterial(Material material);
|
||||
MaterialID addMaterial(Material material, std::string key = {});
|
||||
MaterialID addSimpleColorMaterial(
|
||||
glm::vec3 color,
|
||||
std::string name = {});
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef DESTRUM_MATERIALSERIALIZATION_H
|
||||
#define DESTRUM_MATERIALSERIALIZATION_H
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <destrum/Graphics/Material.h>
|
||||
|
||||
namespace MaterialSerialization {
|
||||
using TextureWriter = std::function<nlohmann::json(ImageID)>;
|
||||
using TextureReader = std::function<ImageID(const nlohmann::json&)>;
|
||||
|
||||
[[nodiscard]] nlohmann::json ToJson(const Material& material, const TextureWriter& writeTexture);
|
||||
[[nodiscard]] Material FromJson(const nlohmann::json& data, const TextureReader& readTexture);
|
||||
|
||||
[[nodiscard]] std::optional<std::string> Validate(const nlohmann::json& materials);
|
||||
|
||||
// Materials that only exist at runtime (no source file) are stored in the scene or prefab
|
||||
// file under their cache key, so the materialKeys in its objects resolve after a restart
|
||||
[[nodiscard]] nlohmann::json CollectEmbedded(const nlohmann::json& objects);
|
||||
void RegisterEmbedded(const nlohmann::json& materials);
|
||||
}
|
||||
|
||||
#endif //DESTRUM_MATERIALSERIALIZATION_H
|
||||
Reference in New Issue
Block a user