80 lines
1.9 KiB
C++
80 lines
1.9 KiB
C++
#pragma once
|
|
#include <cstdint>
|
|
|
|
#include "Deer/Path.h"
|
|
|
|
namespace Deer {
|
|
|
|
// This struct represents the data save in a position vertex, this is
|
|
// defined by: integerPart.decimalPart, where each decimal part represents
|
|
// 1 / 256. And the integer part is substracted 128
|
|
// Example: integerPart = 129; decimalPart = 32;
|
|
// Result = (129-128).(32/256) = 1.125f
|
|
struct PositionAxis {
|
|
uint8_t integerPart = 0;
|
|
uint8_t decimalPart = 0;
|
|
|
|
PositionAxis() = default;
|
|
PositionAxis(uint8_t ip, uint8_t dp)
|
|
: integerPart(ip), decimalPart(dp) {}
|
|
};
|
|
|
|
struct VertexPosition {
|
|
PositionAxis x;
|
|
PositionAxis y;
|
|
PositionAxis z;
|
|
|
|
VertexPosition() = default;
|
|
VertexPosition(PositionAxis _x, PositionAxis _y, PositionAxis _z)
|
|
: x(_x), y(_y), z(_z) {}
|
|
};
|
|
|
|
// Vertex normal is represented with a number fromn [-64,64], and then its
|
|
// divided by 64 to know the decimal number
|
|
struct VertexNormal {
|
|
int8_t x = 0;
|
|
int8_t y = 0;
|
|
int8_t z = 0;
|
|
|
|
VertexNormal() = default;
|
|
VertexNormal(int8_t _x, int8_t _y, int8_t _z) : x(_x), y(_y), z(_z) {}
|
|
};
|
|
|
|
struct MeshData {
|
|
uint16_t vertexCount = 0;
|
|
VertexPosition* vertexPositionsData = nullptr;
|
|
VertexNormal* vertexNormalData = nullptr;
|
|
|
|
uint16_t indexCount = 0;
|
|
uint16_t* indexData = nullptr;
|
|
|
|
MeshData() = default;
|
|
~MeshData() {
|
|
delete[] vertexPositionsData;
|
|
delete[] vertexNormalData;
|
|
delete[] indexData;
|
|
}
|
|
MeshData(const MeshData&) = delete;
|
|
MeshData& operator=(const MeshData&) = delete;
|
|
|
|
void freeData() {
|
|
delete[] vertexPositionsData;
|
|
vertexPositionsData = nullptr;
|
|
delete[] vertexNormalData;
|
|
vertexNormalData = nullptr;
|
|
delete[] indexData;
|
|
indexData = nullptr;
|
|
vertexCount = 0;
|
|
indexCount = 0;
|
|
}
|
|
};
|
|
|
|
namespace DataStore {
|
|
void saveModel(const MeshData&, const Path& name);
|
|
void loadModel(MeshData&, const Path& name);
|
|
|
|
void saveBinModel(const MeshData&, const Path& name);
|
|
|
|
void createExampleMeshData();
|
|
} // namespace DataStore
|
|
} // namespace Deer
|