#ifndef RT_EXP_MESHLET_GENERATOR_H
#define RT_EXP_MESHLET_GENERATOR_H

#include "runtime/runtime.h"

constexpr size_t MESHLET_VERTICES = 64;
constexpr size_t MESHLET_TRIANGLES = 124;
constexpr size_t MESHLET_INDICES   = MESHLET_TRIANGLES * 3;

struct vertex {
    float vx, vy, vz;
};

struct meshlet {
    vertex *vertices;
    uint8_t *indices;
    uint32_t num_vertices;
    uint32_t num_indices;

    float center[3];
    float radius;

    // Normal cone for backface culling
    float cone_apex[3];
    float cone_axis[3];
    float cone_cutoff;

    // child indices
    uint32_t children[8];
    uint32_t num_children;
};

struct meshlet_generator {
    struct mesh_data {
        vertex *vertices;
        uint32_t *indices;
        uint32_t num_vertices;
        uint32_t num_indices;
    };

    meshlet_generator();
    ~meshlet_generator();

    void Release();

    rt_result LoadObj(const char *path);

    rt_result RunFlat(uint32_t mesh_idx = 0);

    rt_result RunHierarchical(uint32_t mesh_idx, uint32_t *out_root);

    mesh_data *m_meshes;
    uint32_t m_num_meshes;

    meshlet *m_meshlets;
    uint32_t m_num_meshlets;
};

#endif
