/* hmap/hmap_c.h - plain C API over libhmap for engines, scripting languages and FFI. * * hmap_map* m = hmap_load("level.hmap", err, sizeof err); * for (uint32_t i = 0; i < hmap_batch_count(m); ++i) { * hmap_batch b; hmap_get_batch(m, i, &b); * // upload b.vertices / b.indices, bind texture hmap_material_texture(m, b.material) * } * hmap_trace t; hmap_trace_segment(m, from, to, HMAP_CONTENTS_SOLID, &t); * hmap_free(m); * * Units: map units, +Y up, forward -Z. Pointers stay valid until hmap_free(). */ #ifndef HMAP_C_H #define HMAP_C_H #include #include #ifdef __cplusplus extern "C" { #endif #define HMAP_CONTENTS_SOLID 1u #define HMAP_CONTENTS_WATER 2u #define HMAP_CONTENTS_CLIP 4u #define HMAP_CONTENTS_TRIGGER 8u #define HMAP_CONTENTS_SKY 16u typedef struct hmap_map hmap_map; typedef struct { float pos[3]; float normal[3]; float uv[2]; uint32_t color; /* 0xAABBGGRR, baked vertex light */ } hmap_vertex; typedef struct { int32_t material; int32_t model; /* 0 = world, >0 = brush-entity sub-model */ int32_t is_mesh; /* 0 = BSP/brush geometry, 1 = mesh object */ uint32_t vertex_count; const hmap_vertex* vertices; uint32_t index_count; /* triangle list */ const uint32_t* indices; } hmap_batch; typedef struct { int hit; float fraction; float point[3]; float normal[3]; uint32_t contents; uint32_t object_id; int start_solid; } hmap_trace; /* Loads a .hmap file (compiled data is used when present, otherwise the source is compiled). */ hmap_map* hmap_load(const char* path, char* err, size_t err_len); void hmap_free(hmap_map* m); uint32_t hmap_batch_count(const hmap_map* m); int hmap_get_batch(const hmap_map* m, uint32_t index, hmap_batch* out); uint32_t hmap_material_count(const hmap_map* m); const char* hmap_material_name(const hmap_map* m, uint32_t index); const char* hmap_material_texture(const hmap_map* m, uint32_t index); uint32_t hmap_entity_count(const hmap_map* m); const char* hmap_entity_classname(const hmap_map* m, uint32_t index); void hmap_entity_origin(const hmap_map* m, uint32_t index, float out[3]); void hmap_entity_angles(const hmap_map* m, uint32_t index, float out[3]); /* pitch, yaw, roll degrees */ const char* hmap_entity_get(const hmap_map* m, uint32_t index, const char* key); /* NULL if missing */ uint32_t hmap_point_contents(const hmap_map* m, const float p[3]); int hmap_trace_segment(const hmap_map* m, const float from[3], const float to[3], uint32_t mask, hmap_trace* out); int hmap_export_fbx(const hmap_map* m, const char* path); /* 1 on success */ #ifdef __cplusplus } #endif #endif /* HMAP_C_H */