39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
|
|
#pragma once
|
||
|
|
#include "vde/mesh/halfedge_mesh.h"
|
||
|
|
#include <vector>
|
||
|
|
#include <cstdint>
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
namespace vde::foundation {
|
||
|
|
|
||
|
|
// Versioned binary format for fast save/load
|
||
|
|
// Header: 8 bytes magic + 4 bytes version + 4 bytes flags
|
||
|
|
|
||
|
|
constexpr uint64_t VDE_MAGIC = 0x56444547454F4D00ULL; // "VDEGEOM\0"
|
||
|
|
constexpr uint32_t VDE_FORMAT_VERSION = 1;
|
||
|
|
|
||
|
|
struct SerializedMesh {
|
||
|
|
uint32_t vertex_count;
|
||
|
|
uint32_t face_count;
|
||
|
|
std::vector<double> vertices; // xyz xyz ... (flat)
|
||
|
|
std::vector<int32_t> face_indices; // v0 v1 v2 ...
|
||
|
|
std::vector<int32_t> face_valence; // 3 for all triangles
|
||
|
|
};
|
||
|
|
|
||
|
|
class BinarySerializer {
|
||
|
|
public:
|
||
|
|
/// Serialize mesh to binary buffer
|
||
|
|
static std::vector<uint8_t> serialize(const HalfedgeMesh& mesh);
|
||
|
|
|
||
|
|
/// Deserialize mesh from binary buffer
|
||
|
|
static HalfedgeMesh deserialize(const std::vector<uint8_t>& data);
|
||
|
|
|
||
|
|
/// Write to file
|
||
|
|
static bool write_file(const std::string& path, const HalfedgeMesh& mesh);
|
||
|
|
|
||
|
|
/// Read from file
|
||
|
|
static HalfedgeMesh read_file(const std::string& path);
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace vde::foundation
|