#ifndef GENESIS_MESH_FACE_MESH_H
#define GENESIS_MESH_FACE_MESH_H

#include <stdint.h>
#include <stddef.h>
#include "material_ids.h"
#include "../blobber/dungeon.h"

typedef struct {
    float px, py, pz;
    float nx, ny, nz;
    float u,  v;
} mesh_vertex_t;

typedef struct {
    int            material;      /* mat_id_t */
    mesh_vertex_t *verts;         /* length = vert_count, tri-list (no index buffer) */
    size_t         vert_count;
    size_t         capacity;
} mesh_group_t;

typedef struct {
    mesh_group_t groups[MAT_COUNT];  /* groups[m].vert_count == 0 means "no geometry" */
    float        cell_size;
    int          n_levels;
} mesh_build_t;

/* Build all meshes from the dungeon using the given cell size (world units).
   Caller must mesh_build_destroy() to free. */
mesh_build_t *mesh_build_from_dungeon(const dungeon_t *d, float cell_size);
void          mesh_build_destroy(mesh_build_t *b);

/* Convenience: write a Wavefront .obj (one object per material) to path. */
int mesh_build_write_obj(const mesh_build_t *b, const char *path);

#endif
