76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "Base/ICloseable.hpp"
|
|
#include "Math/AABB.hpp"
|
|
#include <string>
|
|
|
|
class aiMesh;
|
|
|
|
namespace OpenVulkano
|
|
{
|
|
struct Vertex;
|
|
|
|
namespace Scene
|
|
{
|
|
enum class VertexIndexType
|
|
{
|
|
UINT16 = sizeof(uint16_t), UINT32 = sizeof(uint32_t)
|
|
};
|
|
|
|
class Geometry : public ICloseable
|
|
{
|
|
public:
|
|
uint32_t vertexCount = 0, indexCount = 0;
|
|
Vertex* vertices;
|
|
void* indices;
|
|
VertexIndexType indexType;
|
|
Math::AABB aabb;
|
|
ICloseable* renderGeo = nullptr;
|
|
|
|
Vertex* GetVertices() const { return vertices; }
|
|
void* GetIndices() const { return indices; }
|
|
uint16_t* GetIndices16() const { return static_cast<uint16_t*>(indices); }
|
|
uint32_t* GetIndices32() const { return static_cast<uint32_t*>(indices); }
|
|
uint32_t GetIndexCount() const { return indexCount; }
|
|
uint32_t GetVertexCount() const { return vertexCount; }
|
|
|
|
static Geometry* LoadFromFile(const std::string& file)
|
|
{
|
|
Geometry* mesh = new Geometry();
|
|
mesh->InitFromFile(file);
|
|
return mesh;
|
|
}
|
|
|
|
Geometry() : vertexCount(0), indexCount(0), vertices(nullptr), indices(nullptr), indexType(VertexIndexType::UINT16) {}
|
|
|
|
~Geometry()
|
|
{
|
|
if (vertices) Geometry::Close();
|
|
}
|
|
|
|
void InitFromFile(const std::string& file);
|
|
|
|
/**
|
|
* \brief Creates the arrays for the vertices and indices. They will not be filled!
|
|
* \param vertexCount The amount of vertices that will be used
|
|
* \param indexCount The amount of indices that will be used
|
|
*/
|
|
void Init(uint32_t vertexCount, uint32_t indexCount);
|
|
|
|
void Init(aiMesh* mesh);
|
|
|
|
void SetIndices(const uint32_t* data, uint32_t size, uint32_t offset = 0) const;
|
|
|
|
void Close() override;
|
|
|
|
void Free();
|
|
};
|
|
}
|
|
}
|