Graphics/Model: Add mesh callback parameter

It allows to query/save/update the mesh before it's used to create a GraphicalMesh and disposed of
This commit is contained in:
SirLynix 2024-02-07 15:56:16 +01:00
parent 5a46ebda36
commit 18b6d14670
2 changed files with 10 additions and 0 deletions

View File

@ -20,6 +20,8 @@
#include <Nazara/Renderer/RenderPipeline.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <NazaraUtils/FunctionRef.hpp>
#include <NazaraUtils/Result.hpp>
#include <memory>
namespace Nz
@ -27,6 +29,7 @@ namespace Nz
struct NAZARA_GRAPHICS_API ModelParams : ResourceParameters
{
bool loadMaterials = true;
FunctionRef<Result<void, ResourceLoadingError>(const std::shared_ptr<Mesh>& mesh)> meshCallback = nullptr;
MeshParams mesh;
bool IsValid() const;

View File

@ -26,6 +26,13 @@ namespace Nz::Loaders
if (!mesh)
return Err(ResourceLoadingError::Unrecognized);
if (parameters.meshCallback)
{
Result res = parameters.meshCallback(mesh);
if (!res)
return Err(res.GetError());
}
std::shared_ptr<GraphicalMesh> gfxMesh = GraphicalMesh::BuildFromMesh(*mesh);
if (!gfxMesh)
return Err(ResourceLoadingError::Internal);