76 lines
2.2 KiB
C++
76 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include <SFML/Graphics/Color.hpp>
|
|
|
|
//#include "../Utils/3DMaths.hpp" // Using PCH instead
|
|
|
|
|
|
#define MHELPER_INDICES_TRI_ADD(array, i1, i2, i3) \
|
|
array.push_back(i1); \
|
|
array.push_back(i2); \
|
|
array.push_back(i3);
|
|
|
|
struct Vertex {
|
|
Vertex() = default;
|
|
|
|
Vertex(const Vertex&) = default;
|
|
Vertex& operator=(const Vertex&) = default;
|
|
Vertex(Vertex&&) = default;
|
|
Vertex& operator=(Vertex&&) = default;
|
|
|
|
Vertex(M3D_F3 const& _pos) noexcept : pos(_pos) {}
|
|
Vertex(M3D_F3 const& _pos, sf::Color const& _color) noexcept : pos(_pos), color(_color) {}
|
|
Vertex(const float _x, const float _y, const float _z) noexcept : pos(M3D_F3(_x,_y,_z)) {}
|
|
Vertex(M3D_VECTOR const _pos) noexcept {
|
|
M3D_V4StoreF3(&this->pos, _pos);
|
|
}
|
|
|
|
M3D_F3 pos = {0.0f, 0.0f, 0.0f};
|
|
sf::Color color = sf::Color::White;
|
|
|
|
};
|
|
|
|
struct MeshPart{
|
|
MeshPart() = default;
|
|
|
|
std::vector<uint32_t> indices = {};
|
|
M3D_F4X4 transform = M3D_MIdentity4x4();
|
|
/*
|
|
M3D_F3 offsetTransform = M3D_F3(0.0f, 0.0f, 0.0f);
|
|
M3D_F3 scaleTransform = M3D_F3(1.0f, 1.0f, 1.0f);
|
|
M3D_F3 rotateTransform = M3D_F3(0.0f, 0.0f, 0.0f);
|
|
M3D_F3 translateTransform = M3D_F3(0.0f, 0.0f, 0.0f);
|
|
*/
|
|
std::vector<MeshPart> subparts;
|
|
|
|
inline constexpr size_t GetIndexStride() const noexcept { return sizeof(uint32_t); }
|
|
inline const uint32_t GetIndicesCount() const { return indices.size(); }
|
|
inline const uint32_t GetRootIndicesCount() const { return RecursiveIndicesCount(this); }
|
|
|
|
private:
|
|
inline static const uint32_t RecursiveIndicesCount(const MeshPart* mp) {
|
|
uint32_t sum = 0;
|
|
for (auto& sb : mp->subparts) {
|
|
sum += RecursiveIndicesCount(&sb);
|
|
}
|
|
sum += mp->indices.size();
|
|
return sum;
|
|
}
|
|
|
|
};
|
|
|
|
struct Mesh {
|
|
std::vector<Vertex> vertices;
|
|
std::vector<MeshPart> parts;
|
|
|
|
inline constexpr size_t GetVertexStride() const noexcept { return sizeof(Vertex); }
|
|
inline const size_t GetVerticesCount() const noexcept { return vertices.size(); }
|
|
inline const uint32_t GetRootIndicesCount() const {
|
|
uint32_t sum = 0;
|
|
for (auto& sb : parts)
|
|
sum += sb.GetRootIndicesCount();
|
|
return sum;
|
|
}
|
|
|
|
};
|