1 | /* ==========================================================================
|
---|
2 | * (C) 2005 Universitat Jaume I
|
---|
3 | * ==========================================================================
|
---|
4 | * PROYECT: GAME TOOLS
|
---|
5 | * ==========================================================================
|
---|
6 | * CONTENT:
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * @file GeoMeshLoader.h
|
---|
10 | *===========================================================================*/
|
---|
11 | #ifndef __GEO_MESH_LOADER__
|
---|
12 | #define __GEO_MESH_LOADER__
|
---|
13 |
|
---|
14 | #include <stdio.h>
|
---|
15 | #include <stdlib.h>
|
---|
16 | #include <string>
|
---|
17 | #include <vector>
|
---|
18 | #include <memory.h>
|
---|
19 | #include <time.h>
|
---|
20 | #include <iostream>
|
---|
21 | #include <iomanip>
|
---|
22 | #include "GeoBase.h"
|
---|
23 | #include "GeoMesh.h"
|
---|
24 | #include "GeoLodStripsLibrary.h"
|
---|
25 | #include "GeoLodTreeLibrary.h"
|
---|
26 |
|
---|
27 | namespace Geometry
|
---|
28 | {
|
---|
29 | const unsigned short CHUNK_OVERHEAD_SIZE = sizeof(unsigned short)
|
---|
30 | +
|
---|
31 | sizeof(unsigned long);
|
---|
32 |
|
---|
33 | const unsigned short M_HEADER = 0x1000;
|
---|
34 | const unsigned short M_MESH = 0x3000;
|
---|
35 | const unsigned short M_SUBMESH = 0x4000;
|
---|
36 | const unsigned short M_SUBMESH_OPERATION = 0x4010;
|
---|
37 | const unsigned short M_SUBMESH_BONE_ASSIGNMENT = 0x4100;
|
---|
38 | const unsigned short M_GEOMETRY = 0x5000;
|
---|
39 | const unsigned short M_GEOMETRY_VERTEX_DECLARATION = 0x5100;
|
---|
40 | const unsigned short M_GEOMETRY_VERTEX_ELEMENT = 0x5110;
|
---|
41 | const unsigned short M_GEOMETRY_VERTEX_BUFFER = 0x5200;
|
---|
42 | const unsigned short M_GEOMETRY_VERTEX_BUFFER_DATA = 0x5210;
|
---|
43 | const unsigned short M_MESH_SKELETON_LINK = 0x6000;
|
---|
44 | const unsigned short M_MESH_BONE_ASSIGNMENT = 0x7000;
|
---|
45 | const unsigned short M_MESH_LOD = 0x8000;
|
---|
46 | const unsigned short M_MESH_LOD_USAGE = 0x8100;
|
---|
47 | const unsigned short M_MESH_LOD_MANUAL = 0x8110;
|
---|
48 | const unsigned short M_MESH_LOD_GENERATED = 0x8120;
|
---|
49 | const unsigned short M_MESH_BOUNDS = 0x9000;
|
---|
50 | const unsigned short M_SUBMESH_NAME_TABLE = 0xA000;
|
---|
51 | const unsigned short M_SUBMESH_NAME_TABLE_ELEMENT = 0xA100;
|
---|
52 | const unsigned short M_EDGE_LISTS = 0xB000;
|
---|
53 | const unsigned short M_EDGE_LIST_LOD = 0xB100;
|
---|
54 | const unsigned short M_EDGE_GROUP = 0xB110;
|
---|
55 | const unsigned short M_POSES = 0xC000;
|
---|
56 | const unsigned short M_ANIMATIONS = 0xD000;
|
---|
57 | const unsigned short M_LODSTRIPS = 0xABCD;
|
---|
58 | const unsigned short M_LODTREES = 0xDCBA;
|
---|
59 | const unsigned short SUBMESH_COUNT = 0;
|
---|
60 | const unsigned short GEOMESH_BUILD = 1;
|
---|
61 |
|
---|
62 | enum VertexElementType
|
---|
63 | {
|
---|
64 | VET_FLOAT1,
|
---|
65 | VET_FLOAT2,
|
---|
66 | VET_FLOAT3,
|
---|
67 | VET_FLOAT4,
|
---|
68 | VET_COLOUR,
|
---|
69 | VET_SHORT1,
|
---|
70 | VET_SHORT2,
|
---|
71 | VET_SHORT3,
|
---|
72 | VET_SHORT4,
|
---|
73 | VET_UBYTE4
|
---|
74 | };
|
---|
75 |
|
---|
76 | enum VertexElementSemantic
|
---|
77 | {
|
---|
78 | /// Position, 3 reals per vertex
|
---|
79 | VES_POSITION = 1,
|
---|
80 | /// Blending weights
|
---|
81 | VES_BLEND_WEIGHTS = 2,
|
---|
82 | /// Blending indices
|
---|
83 | VES_BLEND_INDICES = 3,
|
---|
84 | /// Normal, 3 reals per vertex
|
---|
85 | VES_NORMAL = 4,
|
---|
86 | /// Diffuse colours
|
---|
87 | VES_DIFFUSE = 5,
|
---|
88 | /// Specular colours
|
---|
89 | VES_SPECULAR = 6,
|
---|
90 | /// Texture coordinates
|
---|
91 | VES_TEXTURE_COORDINATES = 7,
|
---|
92 | /// Binormal (Y axis if normal is Z)
|
---|
93 | VES_BINORMAL = 8,
|
---|
94 | /// Tangent (X axis if normal is Z)
|
---|
95 | VES_TANGENT = 9
|
---|
96 | };
|
---|
97 |
|
---|
98 | /*
|
---|
99 | // Bounding Box data.
|
---|
100 | struct GeometryBounds
|
---|
101 | {
|
---|
102 | float minx;
|
---|
103 | float miny;
|
---|
104 | float minz;
|
---|
105 | float maxx;
|
---|
106 | float maxy;
|
---|
107 | float maxz;
|
---|
108 | float radius;
|
---|
109 | };
|
---|
110 | */
|
---|
111 |
|
---|
112 | /// Mesh class interface
|
---|
113 | class GEOLODLIBRARYDLL_API GeoMeshLoader
|
---|
114 | {
|
---|
115 | private:
|
---|
116 |
|
---|
117 | Mesh *geoMesh;
|
---|
118 | size_t mFileSize;
|
---|
119 | unsigned int numVertices;
|
---|
120 | unsigned long long_actual;
|
---|
121 | size_t currentSubMesh;
|
---|
122 | bool mError;
|
---|
123 |
|
---|
124 | struct GeometryElement
|
---|
125 | {
|
---|
126 | unsigned short offset;
|
---|
127 | unsigned short semantic;
|
---|
128 | unsigned short type;
|
---|
129 | unsigned short index;
|
---|
130 | };
|
---|
131 |
|
---|
132 | struct GT
|
---|
133 | {
|
---|
134 | unsigned short source; //bindIndex
|
---|
135 | std::vector <GeometryElement> list;
|
---|
136 | };
|
---|
137 |
|
---|
138 | std::vector <GT> list;
|
---|
139 |
|
---|
140 | // Jump a chunk.
|
---|
141 | void jumpChunk(FILE *f);
|
---|
142 |
|
---|
143 | // Read a chunk.
|
---|
144 | unsigned short readChunk(FILE *f);
|
---|
145 |
|
---|
146 | // Read geometry vertex element.
|
---|
147 | void readGeometryVertexElement(FILE *f, Mesh *geoMesh);
|
---|
148 |
|
---|
149 | // Read geometry vertex declaration.
|
---|
150 | void readGeometryVertexDeclaration(FILE *f, Mesh *geoMesh);
|
---|
151 |
|
---|
152 | // Read geometry vertex buffer.
|
---|
153 | void readGeometryVertexBuffer(FILE *f,
|
---|
154 | Mesh *geoMesh,
|
---|
155 | int option);
|
---|
156 |
|
---|
157 | // Read geometry.
|
---|
158 | void readGeometry(FILE *f, Mesh *geoMesh, int option);
|
---|
159 |
|
---|
160 | // Read a submesh operation.
|
---|
161 | void readSubMeshOperation(FILE *f, Mesh *geoMesh, int option);
|
---|
162 |
|
---|
163 | // Read a submesh.
|
---|
164 | void readSubMesh(FILE *f, Mesh *geoMesh, int option);
|
---|
165 |
|
---|
166 | // Read skeleton name.
|
---|
167 | void readSkeletonLink(FILE *f, Mesh *geoMesh, int option);
|
---|
168 |
|
---|
169 | // Read bone assignment.
|
---|
170 | void readMeshBoneAssignment(FILE *f, Mesh *geoMesh, int option);
|
---|
171 |
|
---|
172 | // Read bone assignment.
|
---|
173 | void readSubMeshBoneAssignment(FILE *f, SubMesh *geoSubMesh, int option);
|
---|
174 |
|
---|
175 | // Read a mesh lod information.
|
---|
176 | void readMeshLodInfo(FILE *f, Mesh *geoMesh);
|
---|
177 |
|
---|
178 | // Read a submesh name table.
|
---|
179 | void readSubMeshNameTable(FILE *f, Mesh *geoMesh);
|
---|
180 |
|
---|
181 | // Read a mesh file.
|
---|
182 | void readMesh(FILE *f, Mesh *geoMesh, int option);
|
---|
183 |
|
---|
184 | // Read bounding box settings.
|
---|
185 | void readMeshBounds(FILE *f, Mesh *geoMesh, int option);
|
---|
186 |
|
---|
187 | // Writes the strips list.
|
---|
188 | SubMesh* GeoMeshLoader::BuildStripsGeoSubMesh(SubMesh *geoSubMesh);
|
---|
189 |
|
---|
190 | // Remove degenerate triangles of a submesh given.
|
---|
191 | SubMesh * removeDegenerateTriangles(SubMesh *geoSubMesh);
|
---|
192 |
|
---|
193 | // Sets coods between -1 and 1.
|
---|
194 | void normalizeModel(Mesh *geoMesh);
|
---|
195 |
|
---|
196 | // Imports an OBJ object
|
---|
197 | void importOBJ(FILE *f, Mesh *geoMesh);
|
---|
198 |
|
---|
199 | Geometry::LodStripsLibraryData *lodstripsdata;
|
---|
200 | Geometry::TreeSimplificationSequence *treesimpseq;
|
---|
201 |
|
---|
202 | public:
|
---|
203 |
|
---|
204 | // Constructor.
|
---|
205 | GeoMeshLoader();
|
---|
206 |
|
---|
207 | // Destroyer.
|
---|
208 | ~GeoMeshLoader();
|
---|
209 |
|
---|
210 | // Loads a Mesh file.
|
---|
211 | Mesh* load(char *fileNameMesh);
|
---|
212 |
|
---|
213 | // Get the size in bytes of the file.
|
---|
214 | size_t getFileSize();
|
---|
215 |
|
---|
216 | // if the loaded .mesh file doesn't contain LOD data this will return NULL
|
---|
217 | const Geometry::LodStripsLibraryData * GetLodStripsData(void) const { return lodstripsdata; }
|
---|
218 | const Geometry::TreeSimplificationSequence * GetTreeSimpSeq(void) const { return treesimpseq; }
|
---|
219 | };
|
---|
220 | }
|
---|
221 | #endif
|
---|
222 |
|
---|