From 7307a6e0b560249237333b284ccecde4f92e3dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20J=C3=B6nsson?= Date: Mon, 2 Oct 2023 21:52:49 +0200 Subject: [PATCH] Vertex painted stuff is now also imported --- .../Volt/Asset/Importers/PrefabImporter.cpp | 2 +- .../Volt/Asset/Importers/SceneImporter.cpp | 43 +++++++++++++++++++ Volt/Volt/src/Volt/Scene/Scene.h | 2 +- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Volt/Volt/src/Volt/Asset/Importers/PrefabImporter.cpp b/Volt/Volt/src/Volt/Asset/Importers/PrefabImporter.cpp index d30b8bb60..a16f1531a 100644 --- a/Volt/Volt/src/Volt/Asset/Importers/PrefabImporter.cpp +++ b/Volt/Volt/src/Volt/Asset/Importers/PrefabImporter.cpp @@ -81,7 +81,7 @@ namespace Volt { for (const auto id : prefab->m_prefabScene->GetAllEntities()) { - SceneImporter::Get().SerializeEntity(id, prefab->m_prefabScene, streamWriter); + SceneImporter::Get().SerializeEntity(id, metadata, prefab->m_prefabScene, streamWriter); } } streamWriter.EndSequence(); diff --git a/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.cpp b/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.cpp index 9bbfcd839..8078f2acc 100644 --- a/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.cpp +++ b/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.cpp @@ -14,6 +14,8 @@ #include "Volt/Scripting/Mono/MonoScriptClass.h" #include "Volt/Scripting/Mono/MonoScriptEngine.h" +#include "Volt/Core/BinarySerializer.h" + namespace Volt { template @@ -313,6 +315,12 @@ namespace Volt using std::filesystem::perms; std::filesystem::permissions(vpPath, perms::_All_write); } + + BinarySerializer binaryVp(vpPath, sizeof(uint32_t) * vpComp.vertexColors.size() + sizeof(vpComp.meshHandle)); + + binaryVp.Serialize(vpComp.vertexColors.data(), sizeof(uint32_t) * vpComp.vertexColors.size()); + binaryVp.Serialize(vpComp.meshHandle); + binaryVp.WriteToFile(); } streamWriter.EndMap(); @@ -535,6 +543,41 @@ namespace Volt DeserializeMono(entityId, scene, streamReader); } + if (scene->GetRegistry().any_of(entityId)) + { + std::filesystem::path vpPath = metadata.filePath.parent_path(); + vpPath = ProjectManager::GetDirectory() / vpPath / "Layers" / ("ent_" + std::to_string((uint32_t)entityId) + ".entVp"); + + if (std::filesystem::exists(vpPath)) + { + auto& vpComp = scene->GetRegistry().get(entityId); + + std::ifstream vpFile(vpPath, std::ios::in | std::ios::binary); + if (!vpFile.is_open()) + { + VT_CORE_ERROR("Could not open entVp file!"); + } + + std::vector totalData; + const size_t srcSize = vpFile.seekg(0, std::ios::end).tellg(); + totalData.resize(srcSize); + vpFile.seekg(0, std::ios::beg); + vpFile.read(reinterpret_cast(totalData.data()), totalData.size()); + vpFile.close(); + + memcpy_s(&vpComp.meshHandle, sizeof(vpComp.meshHandle), totalData.data() + totalData.size() - sizeof(vpComp.meshHandle), sizeof(vpComp.meshHandle)); + totalData.resize(totalData.size() - sizeof(vpComp.meshHandle)); + + vpComp.vertexColors.reserve(totalData.size() / sizeof(uint32_t)); + for (size_t offset = 0; offset < totalData.size(); offset += sizeof(uint32_t)) + { + uint32_t vpColor; + memcpy_s(&vpColor, sizeof(uint32_t), totalData.data() + offset, sizeof(uint32_t)); + vpComp.vertexColors.push_back(vpColor); + } + } + } + streamReader.ExitScope(); } diff --git a/Volt/Volt/src/Volt/Scene/Scene.h b/Volt/Volt/src/Volt/Scene/Scene.h index f437b6108..fe2eccdc4 100644 --- a/Volt/Volt/src/Volt/Scene/Scene.h +++ b/Volt/Volt/src/Volt/Scene/Scene.h @@ -116,7 +116,7 @@ namespace Volt void ParentEntity(Entity parent, Entity child); void UnparentEntity(Entity entity); - void InvalidateEntityTransform(entt::entity entity); // #TODO_Ivar: Change to Volt::Entity + void InvalidateEntityTransform(entt::entity entity); Vision& GetVision() { return *m_visionSystem; } TimelinePlayer& GetTimelinePlayer() { return m_timelinePlayer; };