-
Notifications
You must be signed in to change notification settings - Fork 1
/
BlenderMesh.h
145 lines (121 loc) · 3.14 KB
/
BlenderMesh.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#pragma once
#include "BlenderFileBlock.h"
///////////////////////////////
// Blender Object Structures
///////////////////////////////
struct MVert
{
float co[3];
short no[3];
char flag;
char mat_nr;
char bweight;
char pad[3];
// Extended fields
float uv[2]; // Blender stores UV in faces, but we need them at the vertex level
bool isUVSet; // set to true for first texture coord pair set (to prevent overwriting in later faces)
long nextSupplVert; // used in duplicteVertex mode to to point to next additional vertex
};
struct MLoop {
unsigned int v;
unsigned int e;
};
struct MLoopUV {
float uv[2];
int flag;
};
struct MPoly {
int loopstart;
int totloop;
short mat_nr;
char flag, pad;
};
struct MTexPoly {
void *tpage;
char flag;
char transp;
short mode;
short tile;
short pad;
};
struct MFace {
/*int v1;
int v2;
int v3;
int v4; // note: D3D only uses triangles*/
int v[4];
char pad[1];
short mat_nr;
char edcode;
char flag;
// Extended fields
bool isQuad;
bool supplV1; // true if v1 is index from duplicated vertices
bool supplV2; // true if v2 is index from duplicated vertices
bool supplV3; // true if v3 is index from duplicated vertices
};
struct MTFace {
float uv[4][2];
void *tpage;
char flag;
char transp;
short mode;
short tile;
short unwrap;
};
struct MDeformVert {
//void *dw;
int totWeight;
int flag;
};
struct MDeformWeight {
int def_nr;
float weight;
};
class BlenderMesh {
public:
BlenderMesh();
~BlenderMesh() {}
int m_TotalVerts;
int m_TotalEdges;
int m_TotalLoops;
int m_TotalPolygons;
// Old versions
int m_TotalFaces;
std::string m_Name;
MVert *m_Vertices;
MLoop *m_Loops;
MLoopUV *m_LoopUVs;
MPoly *m_Polygons;
MTexPoly *m_TexPolygons;
MDeformVert *m_DeformVerts;
MDeformWeight *m_DeformWeights;
// Old files
MFace *m_Faces;
MTFace *m_TexFaces;
std::string GetMeshInfo();
int GetTotalFaces() { return m_TotalFaces; }
int GetTotalVertices() { return m_TotalVerts; }
MVert *GetVertices() { return m_Vertices; }
MFace *GetFaces() { return m_Faces; }
bool LoadMesh(StructureDNA *sdna, std::vector<BlenderFileBlock> &blocks, bool triangulate, bool vertexUVs, bool flipYZ);
void ReleaseMesh();
private:
MVert *ExtractVertices(StructureDNA *sdna, std::vector<BlenderFileBlock> &blocks, bool flipYZ);
MFace *ExtractFaces(StructureDNA *sdna, std::vector<BlenderFileBlock> &blocks);
MLoop *ExtractLoops(StructureDNA *sdna, std::vector<BlenderFileBlock> &blocks);
MLoopUV *ExtractLoopUVs(StructureDNA *sdna, std::vector<BlenderFileBlock> &blocks);
MPoly *ExtractPolys(StructureDNA *sdna, std::vector<BlenderFileBlock> &blocks);
MTexPoly *ExtractTexPolys(StructureDNA *sdna, std::vector<BlenderFileBlock> &blocks);
MDeformVert *ExtractDeformVerts(StructureDNA *sdna, std::vector<BlenderFileBlock> &blocks);
MDeformWeight *ExtractDeformWeights(StructureDNA *sdna, std::vector<BlenderFileBlock> &blocks);
// Convert blender's MPoly format
// to the older MFace format
// for ease of use
void ConvertPolysToFaces();
// Triangulate quads
void Triangulate();
// Extract UVs from faces and assign
// to vertices, duplicating as necessary
void UVsToVerts();
};