Blaze/Blaze/ModelLoader.h

83 lines
2.0 KiB
C++

#pragma once
#include <DirectXMath.h>
#include <memory_resource>
#include <vector>
#include "BufferManager.h"
#include "TextureManager.h"
struct RenderDevice;
struct EntityManager;
struct Entity;
struct GlobalMemory;
struct Vertex
{
DirectX::XMFLOAT4 position = { 0.0f, 0.0f, 0.0f, 1.0f };
DirectX::XMFLOAT4 normal = { 1.0f, 1.0f, 1.0f, 0.0f };
DirectX::XMFLOAT2 texCoord0 = { 0.0f, 0.0f };
DirectX::XMFLOAT2 texCoord1 = { 0.0f, 0.0f };
DirectX::XMFLOAT4 color0 = { 1.0f, 1.0f, 1.0f, 1.0f };
};
struct Primitive
{
uint32_t indexStart;
uint32_t indexCount;
uint32_t material;
int32_t vertexOffset;
};
struct ModelMesh
{
uint32_t primitiveStart = 0;
uint32_t primitiveCount = 0;
[[nodiscard]] bool isNull() const
{
return primitiveCount == 0;
}
};
struct Material
{
constexpr static size_t GPU_DATA_OFFSET = sizeof( VkSampler );
constexpr static size_t GPU_DATA_SIZE =
sizeof( TextureID ) + sizeof( uint32_t ) + 2 * sizeof( float ) + sizeof( DirectX::XMFLOAT4 );
VkSampler sampler; // TODO: Reuse
// To copy directly.
TextureID texture;
uint32_t padding0; // FIXME: Wasting space.
float roughness = 1.0f;
float metallic = 1.0f;
DirectX::XMFLOAT4 baseColor = { 1.0f, 1.0f, 1.0f, 1.0f };
[[nodiscard]] bool isNull() const
{
return texture.isNull() or sampler;
}
};
static_assert( sizeof( Material ) == Material::GPU_DATA_OFFSET + Material::GPU_DATA_SIZE );
static constexpr Material DEFAULT_MATERIAL = {};
struct Model
{
std::pmr::monotonic_buffer_resource mem;
BufferID vertexBuffer;
BufferID indexBuffer;
std::pmr::vector<Material> materials;
std::pmr::vector<Primitive> primitives;
[[nodiscard]] bool isNull() const
{
return vertexBuffer.isNull();
}
};
Entity* LoadModel( RenderDevice* renderDevice, EntityManager* entityManager, const char* filename );