2024-01-11 12:09:54 -07:00
|
|
|
#ifndef PLY_H
|
|
|
|
#define PLY_H
|
|
|
|
|
2024-01-11 12:14:02 -07:00
|
|
|
#include <stddef.h>
|
2024-01-11 16:16:10 -07:00
|
|
|
#include <cglm/types.h>
|
|
|
|
#include <stdint.h>
|
2024-01-11 12:14:02 -07:00
|
|
|
|
2024-01-11 12:09:54 -07:00
|
|
|
typedef enum {
|
|
|
|
PLY_FORMAT_INVALID = -1,
|
2024-01-13 02:24:35 -07:00
|
|
|
PLY_FORMAT_ASCII = 0,
|
|
|
|
PLY_FORMAT_LE = 1,
|
|
|
|
PLY_FORMAT_BE = 2,
|
2024-01-11 12:09:54 -07:00
|
|
|
} PlyFormatType;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
PLY_HEADER_INVALID = -1,
|
2024-01-13 02:24:35 -07:00
|
|
|
PLY_HEADER_COMMENT = 0,
|
|
|
|
PLY_HEADER_END = 1,
|
|
|
|
PLY_HEADER_ELEMENT = 2,
|
|
|
|
PLY_HEADER_PROPERTY = 3,
|
2024-01-11 12:09:54 -07:00
|
|
|
} PlyHeaderType;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
PLY_TYPE_INVALID = -1,
|
2024-01-13 02:24:35 -07:00
|
|
|
PLY_TYPE_CHAR = 0,
|
|
|
|
PLY_TYPE_UCHAR = 1,
|
|
|
|
PLY_TYPE_SHORT = 2,
|
|
|
|
PLY_TYPE_USHORT = 3,
|
|
|
|
PLY_TYPE_INT = 4,
|
|
|
|
PLY_TYPE_UINT = 5,
|
|
|
|
PLY_TYPE_FLOAT = 6,
|
|
|
|
PLY_TYPE_DOUBLE = 7,
|
2024-01-11 12:09:54 -07:00
|
|
|
} PlyPropertyType;
|
|
|
|
|
|
|
|
typedef struct PlyPropertyStruct {
|
|
|
|
char* name;
|
|
|
|
PlyPropertyType count;
|
|
|
|
PlyPropertyType element;
|
|
|
|
|
|
|
|
void* elements;
|
|
|
|
void* counts;
|
|
|
|
struct PlyPropertyStruct* next;
|
|
|
|
} PlyProperty;
|
|
|
|
|
|
|
|
typedef struct PlyElementStruct {
|
|
|
|
char* name;
|
|
|
|
int count;
|
|
|
|
PlyProperty* properties;
|
|
|
|
|
|
|
|
struct PlyElementStruct* next;
|
|
|
|
} PlyElement;
|
|
|
|
|
2024-01-11 16:16:10 -07:00
|
|
|
typedef struct PlyMeshStruct {
|
|
|
|
uint32_t vertex_count;
|
|
|
|
vec3* position;
|
|
|
|
vec4* colour;
|
|
|
|
vec3* normal;
|
|
|
|
vec2* uv;
|
|
|
|
|
|
|
|
uint32_t index_count;
|
|
|
|
uint16_t* index;
|
|
|
|
} PlyMesh;
|
|
|
|
|
2024-01-11 21:45:30 -07:00
|
|
|
typedef struct PlyMappingsStruct {
|
|
|
|
char* vertex_element;
|
2024-01-13 02:24:35 -07:00
|
|
|
char* position[3];
|
|
|
|
char* normal[3];
|
|
|
|
char* colour[4];
|
|
|
|
char* texture[2];
|
2024-01-11 21:45:30 -07:00
|
|
|
|
|
|
|
char* face_element;
|
|
|
|
char* index;
|
|
|
|
} PlyMappings;
|
|
|
|
|
|
|
|
extern PlyMappings default_ply_mappings;
|
|
|
|
|
2024-01-11 12:18:52 -07:00
|
|
|
extern const char* const ply_formats[];
|
|
|
|
extern const char* const ply_header_items[];
|
|
|
|
extern const char* const ply_type_strings[];
|
|
|
|
extern const size_t ply_type_sizes[];
|
2024-01-11 12:14:02 -07:00
|
|
|
|
2024-01-11 21:45:30 -07:00
|
|
|
PlyMesh ply_load_mesh(char* filename, PlyMappings mappings);
|
2024-01-11 16:16:10 -07:00
|
|
|
void ply_free_elements(PlyElement* elements_head);
|
2024-01-11 12:09:54 -07:00
|
|
|
|
|
|
|
#endif
|