2026-07-23 06:27:43 +00:00
|
|
|
#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
|
2026-07-23 08:19:24 +00:00
|
|
|
static std::vector<uint8_t> serialize(const mesh::HalfedgeMesh& mesh);
|
2026-07-23 06:27:43 +00:00
|
|
|
|
|
|
|
|
/// Deserialize mesh from binary buffer
|
2026-07-23 08:19:24 +00:00
|
|
|
static mesh::HalfedgeMesh deserialize(const std::vector<uint8_t>& data);
|
2026-07-23 06:27:43 +00:00
|
|
|
|
|
|
|
|
/// Write to file
|
2026-07-23 08:19:24 +00:00
|
|
|
static bool write_file(const std::string& path, const mesh::HalfedgeMesh& mesh);
|
2026-07-23 06:27:43 +00:00
|
|
|
|
|
|
|
|
/// Read from file
|
2026-07-23 08:19:24 +00:00
|
|
|
static mesh::HalfedgeMesh read_file(const std::string& path);
|
2026-07-23 06:27:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace vde::foundation
|