Skip to content

Commit

Permalink
Vertex painted stuff is now also imported
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Oct 2, 2023
1 parent 77e9b8e commit 7307a6e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Volt/Volt/src/Volt/Asset/Importers/PrefabImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
43 changes: 43 additions & 0 deletions Volt/Volt/src/Volt/Asset/Importers/SceneImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "Volt/Scripting/Mono/MonoScriptClass.h"
#include "Volt/Scripting/Mono/MonoScriptEngine.h"

#include "Volt/Core/BinarySerializer.h"

namespace Volt
{
template<typename T>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -535,6 +543,41 @@ namespace Volt
DeserializeMono(entityId, scene, streamReader);
}

if (scene->GetRegistry().any_of<VertexPaintedComponent>(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<VertexPaintedComponent>(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<uint8_t> 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<char*>(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();
}

Expand Down
2 changes: 1 addition & 1 deletion Volt/Volt/src/Volt/Scene/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand Down

0 comments on commit 7307a6e

Please sign in to comment.