-
Notifications
You must be signed in to change notification settings - Fork 7
/
GEO_Vox.h
114 lines (90 loc) · 2.8 KB
/
GEO_Vox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once
#include <GEO/GEO_IOTranslator.h>
#include <UT/UT_String.h>
class GEO_PrimPoly;
class GU_Detail;
struct GEO_VoxChunk
{
unsigned int chunk_id;
unsigned int content_size;
unsigned int children_chunk_size;
};
struct GEO_VoxPaletteColor
{
union
{
struct
{
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char a;
};
unsigned char data_c[4];
unsigned int data_u;
};
};
struct GEO_VoxColor
{
union
{
struct
{
float r;
float g;
float b;
float a;
};
float data[4];
};
};
struct GEO_VoxVoxel
{
unsigned char x;
unsigned char y;
unsigned char z;
unsigned char palette_index;
};
class GEO_Vox : public GEO_IOTranslator
{
public:
GEO_Vox();
GEO_Vox(const GEO_Vox& ref);
virtual ~GEO_Vox();
public:
virtual GEO_IOTranslator* duplicate() const;
virtual const char* formatName() const;
virtual int checkExtension(const char* name);
virtual int checkMagicNumber(unsigned magic);
virtual GA_Detail::IOStatus fileLoad(GEO_Detail* detail, UT_IStream& stream, bool ate_magic);
virtual GA_Detail::IOStatus fileSave(const GEO_Detail* detail, std::ostream& stream);
protected:
//! Read a chunk.
bool ReadVoxChunk(UT_IStream& stream, GEO_VoxChunk& chunk, unsigned int& bytes_read);
//! Read a palette entry.
bool ReadPaletteColor(UT_IStream& stream, GEO_VoxPaletteColor& palette_color, unsigned int& bytes_read);
//! Convert palette entry from default palette value.
void ConvertDefaultPaletteColor(unsigned int color, GEO_VoxPaletteColor& palette_color);
//! Read a voxel entry.
bool ReadVoxel(UT_IStream& stream, GEO_VoxVoxel& vox_voxel, unsigned int& bytes_read);
//! Convert palette to a color.
GEO_VoxColor ConvertPaletteColor(const GEO_VoxPaletteColor& palette_color) const;
//! Return true if palette color corresponds to an empty voxel.
bool IsPaletteColorEmpty(const GEO_VoxPaletteColor& palette_color) const;
protected:
//! Magic numbers used by parser.
static const unsigned int s_vox_magic;
static const unsigned int s_vox_main;
static const unsigned int s_vox_size;
static const unsigned int s_vox_xyzi;
static const unsigned int s_vox_rgba;
//! Palette size.
static const unsigned int s_vox_palette_size;
//! Supported version.
static const unsigned int s_vox_version;
//! Default palette data.
static const unsigned int s_vox_default_palette[256];
protected:
//! Cached filename.
UT_String m_filename;
};