Object.cpp 14.6 KB
Newer Older
1
#include "Object.h"
Anakin's avatar
Anakin committed
2
#include <iostream>
Anakin's avatar
Anakin committed
3
4


Anakin's avatar
Anakin committed
5
#define PI (4.0*atan(1.0))
6
7
8
9
10


/////////////////////////////////////////////////////////////////////////
// public constructor/destructor

Anakin's avatar
Anakin committed
11
Object::Object(const char* path)
12
{
13
14
	vModls = new std::vector<Modl*>;

Anakin's avatar
Anakin committed
15
	// open file
16
	fsMesh.open(path, std::ios::in | std::ios::binary);
17

Anakin's avatar
Anakin committed
18
19
	if (!fsMesh.is_open())
		throw std::invalid_argument(std::string("file not found: ") += path);
20

21
22
	// jump to file size information
	fsMesh.seekg(4);
23

24
25
	std::uint32_t tempFileSize;
	std::list<ChunkHeader*> tempMainChunks;
26

27
28
29
	// get all chunks under HEDR
	fsMesh.read(reinterpret_cast<char*>(&tempFileSize), sizeof(tempFileSize));
	loadChunks(tempMainChunks, fsMesh.tellg(), tempFileSize);
30

Anakin's avatar
Anakin committed
31
	// evaluate HEDR subchunks (= find MSH2)
32
	for (std::list<ChunkHeader*>::iterator it = tempMainChunks.begin(); it != tempMainChunks.end(); it++)
33
	{
34
		if (!strcmp("MSH2", (*it)->name))
35
		{
Anakin's avatar
Anakin committed
36
			// get all subchunks
37
38
			std::list<ChunkHeader*> tempMsh2Chunks;
			loadChunks(tempMsh2Chunks, (*it)->position, (*it)->size);
Anakin's avatar
Anakin committed
39

40
41
42
43
44
			// evaluate MSH2 subchunks
			analyseMsh2Chunks(tempMsh2Chunks);

			// clean up
			while (!tempMsh2Chunks.empty())
Anakin's avatar
Anakin committed
45
			{
46
47
				ChunkHeader* tempCursor = tempMsh2Chunks.front();
				tempMsh2Chunks.pop_front();
Anakin's avatar
Anakin committed
48
49
				delete tempCursor;
			}
50
			continue;
51
52
		}
	}
53

54
55
56
57
58
59
60
61
	// clean up
	while (!tempMainChunks.empty())
	{
		ChunkHeader* tempCursor = tempMainChunks.front();
		tempMainChunks.pop_front();
		delete tempCursor;
	}

62
63
64
65
66
67
	// close file
	fsMesh.close();
}

Object::~Object()
{
Anakin's avatar
Anakin committed
68
69
	// clear texture list
	vTextures.clear();
70
}
71
72


73
74
/////////////////////////////////////////////////////////////////////////
// private functions
75

Anakin's avatar
Anakin committed
76
void Object::loadChunks(std::list<ChunkHeader*>& destination, std::streampos start, const std::uint32_t end)
77
{
78
	// jump to first chunk
79
	fsMesh.seekg(start);
80

Anakin's avatar
Anakin committed
81
82
	do
	{
Anakin's avatar
Anakin committed
83
		ChunkHeader* tempHeader = new ChunkHeader();
84

85
86
87
		fsMesh.read(reinterpret_cast<char*>(&tempHeader->name[0]), sizeof(tempHeader->name) - 1);
		fsMesh.read(reinterpret_cast<char*>(&tempHeader->size), sizeof(tempHeader->size));
		tempHeader->position = fsMesh.tellg();
88

89
		destination.push_back(tempHeader);
90

91
		fsMesh.seekg(tempHeader->size, std::ios_base::cur);
92

93
94
		// reached end
		if (fsMesh.tellg() - start == end)
Anakin's avatar
Anakin committed
95
			break;
96
97
98
99
100
101
102
103
104
105

		// error. Maybe the size information is corrupted
		if (!fsMesh.good())
		{
			std::cout << "WARNING: corrupted file. Trying to continue" << std::endl;
			fsMesh.clear();
			break;
		}

	} while (true);
106
107
}

108
109
void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
{
Anakin's avatar
Anakin committed
110
	for (auto& it : chunkList)
111
	{
Anakin's avatar
Anakin committed
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
		if (!strcmp("SINF", it->name))
		{
			std::list<ChunkHeader*> tempSinfChunks;
			loadChunks(tempSinfChunks, it->position, it->size);

			// evaluate MATL subchunks
			for (auto& it : tempSinfChunks)
			{
				if (!strcmp("BBOX", it->name))
				{
					fsMesh.seekg(it->position);

					// read in the quaternion
					for (int i = 0; i < 4; i++)
						fsMesh.read(reinterpret_cast<char*>(&boundingBox.quaternion[i]), sizeof(float));

					//read in the center
					for (int i = 0; i < 3; i++)
						fsMesh.read(reinterpret_cast<char*>(&boundingBox.center[i]), sizeof(float));

					//read in the extents
					for (int i = 0; i < 3; i++)
						fsMesh.read(reinterpret_cast<char*>(&boundingBox.extents[i]), sizeof(float));
				}
			}
		}

		else if (!strcmp("MATL", it->name))
140
		{
141
			// "useless" information how many MATD follow
Anakin's avatar
Anakin committed
142
			fsMesh.seekg(it->position);
Anakin's avatar
Anakin committed
143
			fsMesh.seekg(sizeof(std::uint32_t), std::ios_base::cur);
144

Anakin's avatar
Anakin committed
145
146
			// get all MATD from MATL list
			std::list<ChunkHeader*> tempMatlChunks;
Anakin's avatar
Anakin committed
147
			loadChunks(tempMatlChunks, fsMesh.tellg(), it->size - 4);
Anakin's avatar
Anakin committed
148
149

			// evaluate MATL subchunks
Anakin's avatar
Anakin committed
150
			for (auto& it : tempMatlChunks)
Anakin's avatar
Anakin committed
151
152
			{
				// This shouldn't be anything else than MATD
Anakin's avatar
Anakin committed
153
				if (!strcmp("MATD", it->name))
Anakin's avatar
Anakin committed
154
155
156
				{
					// get all subchunks from MATD
					std::list<ChunkHeader*> tempMatdChunks;
Anakin's avatar
Anakin committed
157
					loadChunks(tempMatdChunks, it->position, it->size);
Anakin's avatar
Anakin committed
158

159
160
					vTextures.push_back("");

Anakin's avatar
Anakin committed
161
					// analyse MATD subchunks
Anakin's avatar
Anakin committed
162
					analyseMatdChunks(tempMatdChunks);
Anakin's avatar
Anakin committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180

					// clean up
					while (!tempMatdChunks.empty())
					{
						ChunkHeader* tempCursor = tempMatdChunks.front();
						tempMatdChunks.pop_front();
						delete tempCursor;
					}
				}
			}

			// clean up
			while (!tempMatlChunks.empty())
			{
				ChunkHeader* tempCursor = tempMatlChunks.front();
				tempMatlChunks.pop_front();
				delete tempCursor;
			}
181
182
		}

Anakin's avatar
Anakin committed
183
		else if (!strcmp("MODL", it->name))
184
		{
Anakin's avatar
Anakin committed
185
186
			Modl* tempModl = new Modl;

187
188
			// get all subchunks
			std::list<ChunkHeader*> tempChunks;
Anakin's avatar
Anakin committed
189
			loadChunks(tempChunks, it->position, it->size);
190
191
192
193
194
195
196
197
198
199
200
201

			// evaluate MODL subchunks
			analyseModlChunks(tempModl, tempChunks);

			//clean up
			while (!tempChunks.empty())
			{
				ChunkHeader* tempCursor = tempChunks.front();
				tempChunks.pop_front();
				delete tempCursor;
			}

Anakin's avatar
Anakin committed
202
			// save Model data
203
			vModls->push_back(tempModl);
Anakin's avatar
Anakin committed
204
205
206
		}
	}
}
207

Anakin's avatar
Anakin committed
208
void Object::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
Anakin's avatar
Anakin committed
209
{
Anakin's avatar
Anakin committed
210
	for (auto& it : chunkList)
Anakin's avatar
Anakin committed
211
212
	{
		//TX1D, TX2D, TX3D
Anakin's avatar
Anakin committed
213
		if (!strcmp("TX0D", it->name))
Anakin's avatar
Anakin committed
214
		{
Anakin's avatar
Anakin committed
215
216
			fsMesh.seekg(it->position);
			char* buffer = new char[it->size + 1];
Anakin's avatar
Anakin committed
217
			*buffer = { 0 };
Anakin's avatar
Anakin committed
218
			fsMesh.read(buffer, it->size);
219
			vTextures.back() = buffer;
Anakin's avatar
Anakin committed
220
			delete buffer;
221
222
223
224
		}
	}
}

Anakin's avatar
Anakin committed
225
226
void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& chunkList)
{
Anakin's avatar
Anakin committed
227
	for (auto& it : chunkList)
Anakin's avatar
Anakin committed
228
	{
Anakin's avatar
Anakin committed
229
		if (!strcmp("MTYP", it->name))
Anakin's avatar
Anakin committed
230
		{
Anakin's avatar
Anakin committed
231
			fsMesh.seekg(it->position);
Anakin's avatar
Anakin committed
232
233
234
235
236
			std::uint32_t tempType;
			fsMesh.read(reinterpret_cast<char*>(&tempType), sizeof(tempType));
			dataDestination->type = (Mtyp)tempType;
		}

Anakin's avatar
Anakin committed
237
		else if (!strcmp("PRNT", it->name))
Anakin's avatar
Anakin committed
238
		{
Anakin's avatar
Anakin committed
239
240
			fsMesh.seekg(it->position);
			char* buffer = new char[it->size];
Anakin's avatar
Anakin committed
241
			*buffer = { 0 };
Anakin's avatar
Anakin committed
242
			fsMesh.read(buffer, it->size); 
243
244
			dataDestination->parent = buffer;
			delete buffer;
Anakin's avatar
Anakin committed
245
246
		}

Anakin's avatar
Anakin committed
247
		else if (!strcmp("NAME", it->name))
Anakin's avatar
Anakin committed
248
		{
Anakin's avatar
Anakin committed
249
250
			fsMesh.seekg(it->position);
			char* buffer = new char[it->size];
Anakin's avatar
Anakin committed
251
			*buffer = { 0 };
Anakin's avatar
Anakin committed
252
			fsMesh.read(buffer, it->size);
253
			dataDestination->name = buffer;
254
			delete buffer;
Anakin's avatar
Anakin committed
255
256
		}

Anakin's avatar
Anakin committed
257
		else if (!strcmp("FLGS", it->name))
Anakin's avatar
Anakin committed
258
		{
Anakin's avatar
Anakin committed
259
			fsMesh.seekg(it->position);
Anakin's avatar
Anakin committed
260
261
262
			fsMesh.read(reinterpret_cast<char*>(&dataDestination->renderFlags), sizeof(dataDestination->renderFlags));
		}

Anakin's avatar
Anakin committed
263
		else if (!strcmp("TRAN", it->name))
Anakin's avatar
Anakin committed
264
		{
Anakin's avatar
Anakin committed
265
266
267
268
			float tempScale[3];
			float tempRotation[4];
			float tempTrans[3];

Anakin's avatar
Anakin committed
269
			fsMesh.seekg(it->position);
Anakin's avatar
Anakin committed
270

Anakin's avatar
Anakin committed
271
			//TODO: use loop
Anakin's avatar
Anakin committed
272
273
274
275
276
277
278
279
280
			fsMesh.read(reinterpret_cast<char*>(&tempScale[0]), sizeof(float));
			fsMesh.read(reinterpret_cast<char*>(&tempScale[1]), sizeof(float));
			fsMesh.read(reinterpret_cast<char*>(&tempScale[2]), sizeof(float));

			fsMesh.read(reinterpret_cast<char*>(&tempRotation[0]), sizeof(float));
			fsMesh.read(reinterpret_cast<char*>(&tempRotation[1]), sizeof(float));
			fsMesh.read(reinterpret_cast<char*>(&tempRotation[2]), sizeof(float));
			fsMesh.read(reinterpret_cast<char*>(&tempRotation[3]), sizeof(float));

Anakin's avatar
Anakin committed
281
			//TODO: make a function for this
Anakin's avatar
Anakin committed
282
283
284
285
286
287
288
			//calculate x,y,z rotation
			tempRotation[0] = atan2(2 * (tempRotation[0] * tempRotation[1] + tempRotation[2] * tempRotation[3]),
									1 - 2 * (pow(tempRotation[1], 2) + pow(tempRotation[2], 2)));
			tempRotation[1] = asin(2 * (tempRotation[0] * tempRotation[2] - tempRotation[3] * tempRotation[1]));
			tempRotation[2] = atan2(2 * (tempRotation[0] * tempRotation[3] + tempRotation[1] * tempRotation[2]),
									1 - 2 * (pow(tempRotation[2], 2) + pow(tempRotation[3], 2))) - PI;

Anakin's avatar
Anakin committed
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
			fsMesh.read(reinterpret_cast<char*>(&tempTrans[0]), sizeof(float));
			fsMesh.read(reinterpret_cast<char*>(&tempTrans[1]), sizeof(float));
			fsMesh.read(reinterpret_cast<char*>(&tempTrans[2]), sizeof(float));

			dataDestination->m4x4Translation = glm::scale(
				dataDestination->m4x4Translation,
				glm::vec3(tempScale[0], tempScale[1], tempScale[2])
			);

			dataDestination->m4x4Translation = glm::translate(
				dataDestination->m4x4Translation,
				glm::vec3(tempTrans[0], tempTrans[1], tempTrans[2])
			);

			dataDestination->m4x4Translation = glm::rotate(
				dataDestination->m4x4Translation,
				tempRotation[0],
				glm::vec3(1, 0, 0)
			);

			dataDestination->m4x4Translation = glm::rotate(
				dataDestination->m4x4Translation,
				tempRotation[1],
				glm::vec3(0, 1, 0)
			);

			dataDestination->m4x4Translation = glm::rotate(
				dataDestination->m4x4Translation,
				tempRotation[2],
				glm::vec3(0, 0, 1)
			);

Anakin's avatar
Anakin committed
321
322
		}

Anakin's avatar
Anakin committed
323
		else if (!strcmp("GEOM", it->name))
Anakin's avatar
Anakin committed
324
325
326
		{
			// get all subchunks
			std::list<ChunkHeader*> tempGeomChunks;
Anakin's avatar
Anakin committed
327
			loadChunks(tempGeomChunks, it->position, it->size);
Anakin's avatar
Anakin committed
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344

			// evaluate GEOM subchunks
			analyseGeomChunks(dataDestination, tempGeomChunks);

			// clean up
			while (!tempGeomChunks.empty())
			{
				ChunkHeader* tempCursor = tempGeomChunks.front();
				tempGeomChunks.pop_front();
				delete tempCursor;
			}
		}
	}
}

void Object::analyseGeomChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
{
Anakin's avatar
Anakin committed
345
	for (auto& it : chunkList)
Anakin's avatar
Anakin committed
346
	{
Anakin's avatar
Anakin committed
347
		if (!strcmp("SEGM", it->name))
Anakin's avatar
Anakin committed
348
349
350
		{
			// get all subchunks
			std::list<ChunkHeader*> tempSegmChunks;
Anakin's avatar
Anakin committed
351
			loadChunks(tempSegmChunks, it->position, it->size);
Anakin's avatar
Anakin committed
352
353
354
355
356
357
358
359
360
361
362

			// evaluate SEGM subchunks
			analyseSegmChunks(dataDestination, tempSegmChunks);

			// clean up
			while (!tempSegmChunks.empty())
			{
				ChunkHeader* tempCursor = tempSegmChunks.front();
				tempSegmChunks.pop_front();
				delete tempCursor;
			}
Anakin's avatar
Anakin committed
363
			continue;
Anakin's avatar
Anakin committed
364
		}
Anakin's avatar
Anakin committed
365
		
Anakin's avatar
Anakin committed
366
		if (!strcmp("CLTH", it->name))
Anakin's avatar
Anakin committed
367
368
369
		{
			// get all subchunks
			std::list<ChunkHeader*> tempClthChunks;
Anakin's avatar
Anakin committed
370
			loadChunks(tempClthChunks, it->position, it->size);
Anakin's avatar
Anakin committed
371
372
373
374
375
376
377
378
379
380
381

			// evaluate CLTH subchunks
			analyseClthChunks(dataDestination, tempClthChunks);

			// clean up
			while (!tempClthChunks.empty())
			{
				ChunkHeader* tempCursor = tempClthChunks.front();
				tempClthChunks.pop_front();
				delete tempCursor;
			}
Anakin's avatar
Anakin committed
382
			continue;
Anakin's avatar
Anakin committed
383
384
385
386
387
388
		}
	}
}

void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
{
Anakin's avatar
Anakin committed
389
390
	Segment* tempData = new Segment;

Anakin's avatar
Anakin committed
391
	for (auto& it : chunkList)
Anakin's avatar
Anakin committed
392
	{
Anakin's avatar
Anakin committed
393
		if (!strcmp("MATI", it->name))
Anakin's avatar
Anakin committed
394
		{
Anakin's avatar
Anakin committed
395
			fsMesh.seekg(it->position);
Anakin's avatar
Anakin committed
396
			fsMesh.read(reinterpret_cast<char*>(&tempData->textureIndex), sizeof(tempData->textureIndex));
Anakin's avatar
Anakin committed
397
398
		}

Anakin's avatar
Anakin committed
399
		else if (!strcmp("POSL", it->name))
Anakin's avatar
Anakin committed
400
		{
Anakin's avatar
Anakin committed
401
			readVertex(tempData, it->position);
Anakin's avatar
Anakin committed
402
403
		}

Anakin's avatar
Anakin committed
404
		/*else if (!strcmp("NRML", it->name))
Anakin's avatar
Anakin committed
405
		{
Anakin's avatar
Anakin committed
406
			fsMesh.seekg(it->position);
407
408
			std::uint32_t tempSize;
			fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
Anakin's avatar
Anakin committed
409
410
411
			// List of normals
			// long int - 4 - number of normal vectores stored in this list
			// float[3][] - 12 each - UVW vector for each vertex
412
		}*/
Anakin's avatar
Anakin committed
413

Anakin's avatar
Anakin committed
414
		else if (!strcmp("UV0L", it->name))
Anakin's avatar
Anakin committed
415
		{
Anakin's avatar
Anakin committed
416
			readUV(tempData, it->position);
Anakin's avatar
Anakin committed
417
418
		}

Anakin's avatar
Anakin committed
419
		else if (!strcmp("STRP", it->name))
420
		{
421
422
423
424
425
426
			// don't get null, bone, shadowMesh and hidden mesh indices
			if (dataDestination->type == null ||
				dataDestination->type == bone ||
				dataDestination->type == shadowMesh ||
				dataDestination->renderFlags == 1)
				continue;
427
428

			// jump to the data section and read the size;
429
			std::uint32_t tempSize;
Anakin's avatar
Anakin committed
430
			fsMesh.seekg(it->position);
431
			fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
432
433

			int highBitCount(0);
Anakin's avatar
Anakin committed
434
			std::vector<uint32_t> tempPoly; // = new std::vector<uint32_t>;
435
			
436
			for (unsigned int i = 0; i < tempSize; i++)
437
438
439
440
441
442
443
444
445
446
447
448
			{
				// ReadData
				std::uint16_t tempValue;
				fsMesh.read(reinterpret_cast<char*>(&tempValue), sizeof(std::uint16_t));

				// Check for highbit
				if (tempValue >> 15)
				{
					highBitCount++;
					tempValue = (std::uint16_t(tempValue << 1) >> 1);
				}

Anakin's avatar
Anakin committed
449
				tempPoly.push_back((std::uint32_t)tempValue);
450

451
				// new Polygon found
452
453
454
				if (highBitCount == 2)
				{
					// reset highBitCount
Anakin's avatar
Anakin committed
455
					highBitCount = 0;
456
457
458
459
460

					// remove the last two values..
					std::uint32_t saveData[2];
					for (int i = 0; i < 2; i++)
					{
Anakin's avatar
Anakin committed
461
462
						saveData[i] = tempPoly.back();
						tempPoly.pop_back();
463
464
465
					}

					// ..and save them in the new vector
Anakin's avatar
Anakin committed
466
467
468
					tempData->meshIndices.push_back(tempPoly);

					tempPoly.clear();
469
					for (int i = 1; i >= 0; i--)
Anakin's avatar
Anakin committed
470
						tempPoly.push_back(saveData[i]);
471
472
473
474

				}	// if high bit set
				
			}	// for all values
475

476
			// save the last values (where no 2 high bits follow);
477
478
479
480
			tempData->meshIndices.push_back(tempPoly);

			// kick the first element, it's empty as a reason of the algo above;
			tempData->meshIndices.erase(tempData->meshIndices.begin());
481
		}
Anakin's avatar
Anakin committed
482
	}
Anakin's avatar
Anakin committed
483

Anakin's avatar
Anakin committed
484
	dataDestination->segmLst.push_back(tempData);
Anakin's avatar
Anakin committed
485
486
487
488
}

void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
{
Anakin's avatar
Anakin committed
489
490
	Segment* tempData = new Segment;

Anakin's avatar
Anakin committed
491
	for (auto& it : chunkList)
Anakin's avatar
Anakin committed
492
	{
Anakin's avatar
Anakin committed
493
		if (!strcmp("CTEX", it->name))
Anakin's avatar
Anakin committed
494
		{
Anakin's avatar
Anakin committed
495
496
			fsMesh.seekg(it->position);
			char* buffer = new char[it->size];
Anakin's avatar
Anakin committed
497
			*buffer = { 0 };
Anakin's avatar
Anakin committed
498
			fsMesh.read(buffer, it->size);
Anakin's avatar
Anakin committed
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

			bool tempFound(false);

			for (unsigned int index = 0; index < vTextures.size(); index++)
			{
				if (!strcmp(buffer, vTextures[index].c_str()))
				{
					tempData->textureIndex = index;
					tempFound = true;
					break;
				}
			}

			if (!tempFound)
			{
				vTextures.push_back(std::string(buffer));
				tempData->textureIndex = vTextures.size() - 1;
			}

518
			delete buffer;
Anakin's avatar
Anakin committed
519
520
		}

Anakin's avatar
Anakin committed
521
		else if (!strcmp("CPOS", it->name))
Anakin's avatar
Anakin committed
522
		{
Anakin's avatar
Anakin committed
523
			readVertex(tempData, it->position);
Anakin's avatar
Anakin committed
524
		}
Anakin's avatar
Anakin committed
525

Anakin's avatar
Anakin committed
526
		else if (!strcmp("CUV0", it->name))
Anakin's avatar
Anakin committed
527
		{
Anakin's avatar
Anakin committed
528
			readUV(tempData, it->position);
Anakin's avatar
Anakin committed
529
		}
Anakin's avatar
Anakin committed
530

Anakin's avatar
Anakin committed
531
		else if (!strcmp("CMSH", it->name))
Anakin's avatar
Anakin committed
532
		{
533
534
			// jump to the data section and read the size;
			std::uint32_t tempSize;
Anakin's avatar
Anakin committed
535
			fsMesh.seekg(it->position);
536
			fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
Anakin's avatar
Anakin committed
537

Anakin's avatar
Anakin committed
538
			std::vector<uint32_t> tempPoly;
Anakin's avatar
Anakin committed
539

540
541
			// for every triangle..
			for (unsigned int i = 0; i < tempSize; i += 3)
Anakin's avatar
Anakin committed
542
			{
Anakin's avatar
Anakin committed
543
				tempPoly.clear();
544
545
546
547
548
549

				// ..get the 3 indices and save them
				for (int j = 0; j < 3; j++)
				{
					std::uint32_t tempValue;
					fsMesh.read(reinterpret_cast<char*>(&tempValue), sizeof(std::uint32_t));
Anakin's avatar
Anakin committed
550
					tempPoly.push_back(tempValue);
551
552
				}
				tempData->meshIndices.push_back(tempPoly);
Anakin's avatar
Anakin committed
553
554
			}
		}
555
	}
Anakin's avatar
Anakin committed
556
	dataDestination->segmLst.push_back(tempData);
557
558
}

Anakin's avatar
Anakin committed
559
void Object::readVertex(Segment* dataDestination, std::streampos position)
560
561
562
563
564
565
566
{
	std::uint32_t tempSize;
	fsMesh.seekg(position);
	fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));

	dataDestination->vertex = new float[tempSize * 3];

Anakin's avatar
Anakin committed
567
	for (unsigned int i = 0; i < tempSize * 3; i++)
568
569
570
		fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i]), sizeof(float));
}

Anakin's avatar
Anakin committed
571
void Object::readUV(Segment* dataDestination, std::streampos position)
572
573
574
575
576
577
578
{
	std::uint32_t tempSize;
	fsMesh.seekg(position);
	fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));

	dataDestination->uv = new float[tempSize * 2];

Anakin's avatar
Anakin committed
579
	for (unsigned int i = 0; i < tempSize * 2; i++)
580
		fsMesh.read(reinterpret_cast<char*>(&dataDestination->uv[i]), sizeof(float));
Anakin's avatar
Anakin committed
581
582
}

583

Anakin's avatar
Anakin committed
584
585
/////////////////////////////////////////////////////////////////////////
// public getter
586

587
std::vector<Modl*>* Object::getModels() const
Anakin's avatar
Anakin committed
588
589
590
591
{
	return vModls;
}

Anakin's avatar
Anakin committed
592
593
594
595
596
std::vector<std::string> Object::getTextureList() const
{
	return vTextures;
}

597
598
599
600

/////////////////////////////////////////////////////////////////////////
// public functions