voxflat
Loading...
Searching...
No Matches
voxflat.h
Go to the documentation of this file.
1#ifndef VOXFLAT_H
2#define VOXFLAT_H
3#include <stdint.h>
4#include <stdio.h>
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
16typedef struct VxfFile VxfFile;
17
33
44VxfFile *vxf_open_file(const char *filename, VxfError *error);
45
57VxfFile *vxf_open_stream(FILE *stream, VxfError *error);
58
70VxfFile *vxf_open_memory(size_t size, const char buffer[], VxfError *error);
71
82void vxf_calculate_bounds(const VxfFile* vf, int32_t xyz_min[3], int32_t xyz_max[3]);
83
93uintmax_t vxf_count_voxels(const VxfFile* vf);
94
105void vxf_get_palette(const VxfFile *vf, uint8_t rgba_buf[256][4]);
106
126size_t vxf_read_xyz_rgba(VxfFile *vf, size_t max_count, int32_t xyz_buf[][3], uint8_t rgba_buf[][4], VxfError *error);
127
145size_t vxf_read_xyz_coloridx(VxfFile *vf, size_t max_count, int32_t xyz_buf[][3], uint8_t coloridx_buf[], VxfError *error);
146
156
162const char *vxf_error_string(VxfError error);
163
164#ifdef __cplusplus
165}
166#endif
167#endif // VOXFLAT_H
VxfFile * vxf_open_stream(FILE *stream, VxfError *error)
Opens a MagicaVoxel vox file from a stdio file stream.
size_t vxf_read_xyz_coloridx(VxfFile *vf, size_t max_count, int32_t xyz_buf[][3], uint8_t coloridx_buf[], VxfError *error)
Reads voxel positions and color indices.
struct VxfFile VxfFile
Opaque struct representing an opened MagicaVoxel vox file.
Definition voxflat.h:16
uintmax_t vxf_count_voxels(const VxfFile *vf)
Counts the total number of voxels in the file.
VxfError
Error codes for open and read functions.
Definition voxflat.h:21
@ VXF_ERROR_FILE_SEEK
Definition voxflat.h:25
@ VXF_ERROR_FILE_OPEN
Definition voxflat.h:23
@ VXF_ERROR_FILE_READ
Definition voxflat.h:24
@ VXF_ERROR_OUT_OF_MEMORY
Definition voxflat.h:30
@ VXF_SUCCESS
Definition voxflat.h:22
@ VXF_ERROR_UNEXPECTED_EOF
Definition voxflat.h:27
@ VXF_ERROR_INVALID_FILE_STRUCTURE
Definition voxflat.h:28
@ VXF_ERROR_INVALID_SCENE
Definition voxflat.h:29
@ VXF_ERROR_INVALID_ARGUMENT
Definition voxflat.h:31
@ VXF_ERROR_UNRECOGNIZED_FILE_FORMAT
Definition voxflat.h:26
VxfFile * vxf_open_file(const char *filename, VxfError *error)
Opens a MagicaVoxel vox file from a filename.
void vxf_get_palette(const VxfFile *vf, uint8_t rgba_buf[256][4])
Retrieves the color palette.
void vxf_close(VxfFile *vf)
Destroys a VxfFile instance.
VxfFile * vxf_open_memory(size_t size, const char buffer[], VxfError *error)
Opens a MagicaVoxel vox file from a memory buffer.
void vxf_calculate_bounds(const VxfFile *vf, int32_t xyz_min[3], int32_t xyz_max[3])
Calculates the bounding box of the voxel data.
size_t vxf_read_xyz_rgba(VxfFile *vf, size_t max_count, int32_t xyz_buf[][3], uint8_t rgba_buf[][4], VxfError *error)
Reads voxel positions and RGBA colors.
const char * vxf_error_string(VxfError error)
Converts an error code to a human-readable string.