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 SUBMESH_COUNT = 0;
|
---|
56 | const unsigned short GEOMESH_BUILD = 1;
|
---|
57 |
|
---|
58 | enum VertexElementType
|
---|
59 | {
|
---|
60 | VET_FLOAT1,
|
---|
61 | VET_FLOAT2,
|
---|
62 | VET_FLOAT3,
|
---|
63 | VET_FLOAT4,
|
---|
64 | VET_COLOUR,
|
---|
65 | VET_SHORT1,
|
---|
66 | VET_SHORT2,
|
---|
67 | VET_SHORT3,
|
---|
68 | VET_SHORT4,
|
---|
69 | VET_UBYTE4
|
---|
70 | };
|
---|
71 |
|
---|
72 | enum VertexElementSemantic
|
---|
73 | {
|
---|
74 | /// Position, 3 reals per vertex
|
---|
75 | VES_POSITION = 1,
|
---|
76 | /// Blending weights
|
---|
77 | VES_BLEND_WEIGHTS = 2,
|
---|
78 | /// Blending indices
|
---|
79 | VES_BLEND_INDICES = 3,
|
---|
80 | /// Normal, 3 reals per vertex
|
---|
81 | VES_NORMAL = 4,
|
---|
82 | /// Diffuse colours
|
---|
83 | VES_DIFFUSE = 5,
|
---|
84 | /// Specular colours
|
---|
85 | VES_SPECULAR = 6,
|
---|
86 | /// Texture coordinates
|
---|
87 | VES_TEXTURE_COORDINATES = 7,
|
---|
88 | /// Binormal (Y axis if normal is Z)
|
---|
89 | VES_BINORMAL = 8,
|
---|
90 | /// Tangent (X axis if normal is Z)
|
---|
91 | VES_TANGENT = 9
|
---|
92 | };
|
---|
93 |
|
---|
94 | /*
|
---|
95 | // Bounding Box data.
|
---|
96 | struct GeometryBounds
|
---|
97 | {
|
---|
98 | float minx;
|
---|
99 | float miny;
|
---|
100 | float minz;
|
---|
101 | float maxx;
|
---|
102 | float maxy;
|
---|
103 | float maxz;
|
---|
104 | float radius;
|
---|
105 | };
|
---|
106 | */
|
---|
107 |
|
---|
108 | /// Mesh class interface
|
---|
109 | class GEOLODLIBRARYDLL_API GeoMeshLoader
|
---|
110 | {
|
---|
111 | private:
|
---|
112 |
|
---|
113 | Mesh *geoMesh;
|
---|
114 | size_t mFileSize;
|
---|
115 | unsigned int numVertices;
|
---|
116 | unsigned long long_actual;
|
---|
117 | size_t currentSubMesh;
|
---|
118 | bool mError;
|
---|
119 |
|
---|
120 | struct GeometryElement
|
---|
121 | {
|
---|
122 | unsigned short offset;
|
---|
123 | unsigned short semantic;
|
---|
124 | unsigned short type;
|
---|
125 | unsigned short index;
|
---|
126 | };
|
---|
127 |
|
---|
128 | struct GT
|
---|
129 | {
|
---|
130 | unsigned short source; //bindIndex
|
---|
131 | std::vector <GeometryElement> list;
|
---|
132 | };
|
---|
133 |
|
---|
134 | std::vector <GT> list;
|
---|
135 |
|
---|
136 | // Jump a chunk.
|
---|
137 | void jumpChunk(FILE *f);
|
---|
138 |
|
---|
139 | // Read a chunk.
|
---|
140 | unsigned short readChunk(FILE *f);
|
---|
141 |
|
---|
142 | // Read geometry vertex element.
|
---|
143 | void readGeometryVertexElement(FILE *f, Mesh *geoMesh);
|
---|
144 |
|
---|
145 | // Read geometry vertex declaration.
|
---|
146 | void readGeometryVertexDeclaration(FILE *f, Mesh *geoMesh);
|
---|
147 |
|
---|
148 | // Read geometry vertex buffer.
|
---|
149 | void readGeometryVertexBuffer(FILE *f,
|
---|
150 | Mesh *geoMesh,
|
---|
151 | int option);
|
---|
152 |
|
---|
153 | // Read geometry.
|
---|
154 | void readGeometry(FILE *f, Mesh *geoMesh, int option);
|
---|
155 |
|
---|
156 | // Read a submesh operation.
|
---|
157 | void readSubMeshOperation(FILE *f, Mesh *geoMesh, int option);
|
---|
158 |
|
---|
159 | // Read a submesh.
|
---|
160 | void readSubMesh(FILE *f, Mesh *geoMesh, int option);
|
---|
161 |
|
---|
162 | // Read skeleton name.
|
---|
163 | void readSkeletonLink(FILE *f, Mesh *geoMesh, int option);
|
---|
164 |
|
---|
165 | // Read bone assignment.
|
---|
166 | void readMeshBoneAssignment(FILE *f, Mesh *geoMesh, int option);
|
---|
167 |
|
---|
168 | // Read bone assignment.
|
---|
169 | void readSubMeshBoneAssignment(FILE *f, SubMesh *geoSubMesh, int option);
|
---|
170 |
|
---|
171 | // Read a mesh lod information.
|
---|
172 | void readMeshLodInfo(FILE *f, Mesh *geoMesh);
|
---|
173 |
|
---|
174 | // Read a submesh name table.
|
---|
175 | void readSubMeshNameTable(FILE *f, Mesh *geoMesh);
|
---|
176 |
|
---|
177 | // Read a mesh file.
|
---|
178 | void readMesh(FILE *f, Mesh *geoMesh, int option);
|
---|
179 |
|
---|
180 | // Read bounding box settings.
|
---|
181 | void readMeshBounds(FILE *f, Mesh *geoMesh, int option);
|
---|
182 |
|
---|
183 | // Writes the strips list.
|
---|
184 | SubMesh* GeoMeshLoader::BuildStripsGeoSubMesh(SubMesh *geoSubMesh);
|
---|
185 |
|
---|
186 | // Remove degenerate triangles of a submesh given.
|
---|
187 | SubMesh * removeDegenerateTriangles(SubMesh *geoSubMesh);
|
---|
188 |
|
---|
189 | // Sets coods between -1 and 1.
|
---|
190 | void normalizeModel(Mesh *geoMesh);
|
---|
191 |
|
---|
192 | // Imports an OBJ object
|
---|
193 | void importOBJ(FILE *f, Mesh *geoMesh);
|
---|
194 |
|
---|
195 | Geometry::LodStripsLibraryData *lodstripsdata;
|
---|
196 | Geometry::TreeSimplificationSequence *treesimpseq;
|
---|
197 |
|
---|
198 | public:
|
---|
199 |
|
---|
200 | // Constructor.
|
---|
201 | GeoMeshLoader();
|
---|
202 |
|
---|
203 | // Destroyer.
|
---|
204 | ~GeoMeshLoader();
|
---|
205 |
|
---|
206 | // Loads a Mesh file.
|
---|
207 | Mesh* load(char *fileNameMesh);
|
---|
208 |
|
---|
209 | // Get the size in bytes of the file.
|
---|
210 | size_t getFileSize();
|
---|
211 |
|
---|
212 | // if the loaded .mesh file doesn't contain LOD data this will return NULL
|
---|
213 | const Geometry::LodStripsLibraryData * GetLodStripsData(void) const { return lodstripsdata; }
|
---|
214 | const Geometry::TreeSimplificationSequence * GetTreeSimpSeq(void) const { return treesimpseq; }
|
---|
215 | };
|
---|
216 | }
|
---|
217 | #endif
|
---|
218 |
|
---|