2020-06-02 11:46:18 +02:00
|
|
|
#include "MeshAsset.h"
|
2023-01-29 18:58:59 +01:00
|
|
|
#include "Graphics/Graphics.h"
|
2020-06-02 11:46:18 +02:00
|
|
|
#include "Graphics/Mesh.h"
|
2023-02-13 14:56:13 +01:00
|
|
|
#include "AssetRegistry.h"
|
2020-06-02 11:46:18 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
|
|
|
|
MeshAsset::MeshAsset()
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-06-08 01:44:47 +02:00
|
|
|
|
2023-02-13 14:56:13 +01:00
|
|
|
MeshAsset::MeshAsset(std::string_view folderPath, std::string_view name)
|
|
|
|
|
: Asset(folderPath, name)
|
2020-06-02 11:46:18 +02:00
|
|
|
{
|
2020-06-08 01:44:47 +02:00
|
|
|
}
|
2023-02-13 14:56:13 +01:00
|
|
|
|
2020-06-08 01:44:47 +02:00
|
|
|
MeshAsset::~MeshAsset()
|
|
|
|
|
{
|
|
|
|
|
}
|
2023-02-13 14:56:13 +01:00
|
|
|
|
|
|
|
|
void MeshAsset::save(ArchiveBuffer& buffer) const
|
2020-06-08 01:44:47 +02:00
|
|
|
{
|
2023-02-13 14:56:13 +01:00
|
|
|
uint64 numMeshes = meshes.size();
|
|
|
|
|
Serialization::save(buffer, numMeshes);
|
|
|
|
|
for (auto mesh : meshes)
|
|
|
|
|
{
|
|
|
|
|
mesh->vertexInput->save(buffer);
|
|
|
|
|
Array<uint8> rawIndices;
|
|
|
|
|
mesh->indexBuffer->download(rawIndices);
|
|
|
|
|
Serialization::save(buffer, rawIndices);
|
|
|
|
|
Serialization::save(buffer, mesh->indexBuffer->getIndexType());
|
|
|
|
|
Serialization::save(buffer, mesh->referencedMaterial->getAssetIdentifier());
|
|
|
|
|
}
|
2020-06-08 01:44:47 +02:00
|
|
|
}
|
2023-02-13 14:56:13 +01:00
|
|
|
|
|
|
|
|
void MeshAsset::load(ArchiveBuffer& buffer)
|
2020-06-08 01:44:47 +02:00
|
|
|
{
|
2023-02-13 14:56:13 +01:00
|
|
|
uint64 numMeshes = 0;
|
|
|
|
|
Serialization::load(buffer, numMeshes);
|
|
|
|
|
meshes.resize(numMeshes);
|
|
|
|
|
for (auto& mesh : meshes)
|
|
|
|
|
{
|
|
|
|
|
PVertexShaderInput vertexInput = new StaticMeshVertexInput("");
|
|
|
|
|
vertexInput->load(buffer);
|
|
|
|
|
Array<uint8> rawIndices;
|
|
|
|
|
Serialization::load(buffer, rawIndices);
|
|
|
|
|
Gfx::SeIndexType indexType;
|
|
|
|
|
Serialization::load(buffer, indexType);
|
|
|
|
|
IndexBufferCreateInfo createInfo = {
|
|
|
|
|
.resourceData = {
|
|
|
|
|
.size = rawIndices.size(),
|
|
|
|
|
.data = rawIndices.data(),
|
|
|
|
|
},
|
|
|
|
|
.indexType = indexType,
|
|
|
|
|
};
|
|
|
|
|
Gfx::PIndexBuffer indexBuffer = buffer.getGraphics()->createIndexBuffer(createInfo);
|
|
|
|
|
mesh = new Mesh(vertexInput, indexBuffer);
|
|
|
|
|
std::string matname;
|
|
|
|
|
Serialization::load(buffer, matname);
|
|
|
|
|
mesh->referencedMaterial = AssetRegistry::findMaterial(matname);
|
|
|
|
|
}
|
2020-08-06 00:54:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MeshAsset::addMesh(PMesh mesh)
|
|
|
|
|
{
|
2022-11-30 10:19:45 +01:00
|
|
|
meshes.add(mesh);
|
2020-08-06 00:54:43 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-30 10:19:45 +01:00
|
|
|
const Array<PMesh> MeshAsset::getMeshes()
|
2020-08-06 00:54:43 +02:00
|
|
|
{
|
|
|
|
|
return meshes;
|
2020-06-02 11:46:18 +02:00
|
|
|
}
|