Object.cpp 16.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
{
Anakin's avatar
Anakin committed
13
	// open file
14
	fsMesh.open(path, std::ios::in | std::ios::binary);
15

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

19
20
	// jump to file size information
	fsMesh.seekg(4);
21

22
23
	std::uint32_t tempFileSize;
	std::list<ChunkHeader*> tempMainChunks;
24

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

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

38
39
40
41
42
			// evaluate MSH2 subchunks
			analyseMsh2Chunks(tempMsh2Chunks);

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

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

60
61
62
63
64
65
	// close file
	fsMesh.close();
}

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

	// clear Model list (don't delete the elements)
	vModls.clear();
71
}
72
73


74
75
/////////////////////////////////////////////////////////////////////////
// private functions
76

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

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

86
87
88
		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();
89

90
		destination.push_back(tempHeader);
91

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

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

		// 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);
107
108
}

109
110
111
112
113
114
void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
{
	for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
	{
		if (!strcmp("MATL", (*it)->name))
		{
115
116
117
118
119
			// "useless" information how many MATD follow
			fsMesh.seekg((*it)->position);
			std::uint32_t tempMatdCount;
			fsMesh.read(reinterpret_cast<char*>(&tempMatdCount), sizeof(std::uint32_t));

Anakin's avatar
Anakin committed
120
121
			// get all MATD from MATL list
			std::list<ChunkHeader*> tempMatlChunks;
122
			loadChunks(tempMatlChunks, fsMesh.tellg(), (*it)->size - 4);
Anakin's avatar
Anakin committed
123
124
125
126
127
128
129
130
131
132
133
134

			// evaluate MATL subchunks
			for (std::list<ChunkHeader*>::iterator it = tempMatlChunks.begin(); it != tempMatlChunks.end(); it++)
			{
				// This shouldn't be anything else than MATD
				if (!strcmp("MATD", (*it)->name))
				{
					// get all subchunks from MATD
					std::list<ChunkHeader*> tempMatdChunks;
					loadChunks(tempMatdChunks, (*it)->position, (*it)->size);

					// analyse MATD subchunks
Anakin's avatar
Anakin committed
135
					analyseMatdChunks(tempMatdChunks);
Anakin's avatar
Anakin committed
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

					// 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;
			}
154
155
156
157
158
159

			continue;
		}

		if (!strcmp("MODL", (*it)->name))
		{
Anakin's avatar
Anakin committed
160
161
			Modl* tempModl = new Modl;

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
			// get all subchunks
			std::list<ChunkHeader*> tempChunks;
			loadChunks(tempChunks, (*it)->position, (*it)->size);

			// 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
177
			// save Model data
Anakin's avatar
Anakin committed
178
			vModls.push_back(tempModl);
Anakin's avatar
Anakin committed
179

Anakin's avatar
Anakin committed
180
181
182
183
			continue;
		}
	}
}
184

Anakin's avatar
Anakin committed
185
void Object::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
Anakin's avatar
Anakin committed
186
187
188
189
190
191
192
193
194
195
196
197
{
	for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
	{
		//TX1D, TX2D, TX3D
		if (!strcmp("TX0D", (*it)->name))
		{
			fsMesh.seekg((*it)->position);
			char* buffer = new char[(*it)->size + 1];
			*buffer = { 0 };
			fsMesh.read(buffer, (*it)->size);
			vTextures.push_back(buffer);
			delete buffer;
198
199
200
201
202
			continue;
		}
	}
}

Anakin's avatar
Anakin committed
203
204
205
206
207
208
209
210
211
212
void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& chunkList)
{
	for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
	{
		if (!strcmp("MTYP", (*it)->name))
		{
			fsMesh.seekg((*it)->position);
			std::uint32_t tempType;
			fsMesh.read(reinterpret_cast<char*>(&tempType), sizeof(tempType));
			dataDestination->type = (Mtyp)tempType;
Anakin's avatar
Anakin committed
213
			continue;
Anakin's avatar
Anakin committed
214
215
216
217
218
		}

		if (!strcmp("PRNT", (*it)->name))
		{
			fsMesh.seekg((*it)->position);
219
			char* buffer = new char[(*it)->size];
Anakin's avatar
Anakin committed
220
			*buffer = { 0 };
221
222
223
			fsMesh.read(buffer, (*it)->size); 
			dataDestination->parent = buffer;
			delete buffer;
Anakin's avatar
Anakin committed
224
			continue;
Anakin's avatar
Anakin committed
225
226
227
228
229
		}

		if (!strcmp("NAME", (*it)->name))
		{
			fsMesh.seekg((*it)->position);
230
			char* buffer = new char[(*it)->size];
Anakin's avatar
Anakin committed
231
			*buffer = { 0 };
232
233
			fsMesh.read(buffer, (*it)->size);
			dataDestination->name = buffer;
234
			delete buffer;
Anakin's avatar
Anakin committed
235
			continue;
Anakin's avatar
Anakin committed
236
237
238
239
240
241
		}

		if (!strcmp("FLGS", (*it)->name))
		{
			fsMesh.seekg((*it)->position);
			fsMesh.read(reinterpret_cast<char*>(&dataDestination->renderFlags), sizeof(dataDestination->renderFlags));
Anakin's avatar
Anakin committed
242
			continue;
Anakin's avatar
Anakin committed
243
244
245
246
		}

		if (!strcmp("TRAN", (*it)->name))
		{
Anakin's avatar
Anakin committed
247
248
249
250
			float tempScale[3];
			float tempRotation[4];
			float tempTrans[3];

Anakin's avatar
Anakin committed
251
			fsMesh.seekg((*it)->position);
Anakin's avatar
Anakin committed
252
253
254
255
256
257
258
259
260
261

			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
262
263
264
265
266
267
268
			//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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
			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
301
			continue;
Anakin's avatar
Anakin committed
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
		}

		if (!strcmp("GEOM", (*it)->name))
		{
			// get all subchunks
			std::list<ChunkHeader*> tempGeomChunks;
			loadChunks(tempGeomChunks, (*it)->position, (*it)->size);

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

			// clean up
			while (!tempGeomChunks.empty())
			{
				ChunkHeader* tempCursor = tempGeomChunks.front();
				tempGeomChunks.pop_front();
				delete tempCursor;
			}
Anakin's avatar
Anakin committed
320
321

			continue;
Anakin's avatar
Anakin committed
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
		}
	}
}

void Object::analyseGeomChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
{
	for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
	{
		if (!strcmp("SEGM", (*it)->name))
		{
			// get all subchunks
			std::list<ChunkHeader*> tempSegmChunks;
			loadChunks(tempSegmChunks, (*it)->position, (*it)->size);

			// 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
346
			continue;
Anakin's avatar
Anakin committed
347
		}
Anakin's avatar
Anakin committed
348
349
		
		if (!strcmp("CLTH", (*it)->name))
Anakin's avatar
Anakin committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
		{
			// get all subchunks
			std::list<ChunkHeader*> tempClthChunks;
			loadChunks(tempClthChunks, (*it)->position, (*it)->size);

			// 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
365
			continue;
Anakin's avatar
Anakin committed
366
367
368
369
370
371
		}
	}
}

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

Anakin's avatar
Anakin committed
374
375
	for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
	{
376
		/*if (!strcmp("SHDW", (*it)->name))
Anakin's avatar
Anakin committed
377
378
379
380
381
382
383
384
385
386
387
388
		{
			fsMesh.seekg((*it)->position);
			/* shadow mesh geometry

			long int - 4 - number of vertex positions
			float[3][] - 12 each - vertex positions (XYZ)
			long int - 4 - number of edges
			short int[4][] - 8 each - edge the following 4 entries from one edge
			> short int - 2 - vertex index of this edge, referes to the vertex list
			> short int - 2 - Reference into an edge. Defines the target vertex (the local edge vertex of the referenced edge) to which the edge should be dran from the local vertex
			> short int - 2 - Second reference into an edge. In all example .msh files I've seen this always refers to the same vertex as the first edge reference
			> short int - 2 - MAX_VALUE of short integers (65535). Indicates the end of this edge
389
			* /
Anakin's avatar
Anakin committed
390
			continue;
391
		}*/
Anakin's avatar
Anakin committed
392
393
394
395

		if (!strcmp("MATI", (*it)->name))
		{
			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
			continue;
Anakin's avatar
Anakin committed
398
399
400
401
		}

		if (!strcmp("POSL", (*it)->name))
		{
Anakin's avatar
Anakin committed
402
			readVertex(tempData, (*it)->position);
Anakin's avatar
Anakin committed
403
			continue;
Anakin's avatar
Anakin committed
404
405
		}

406
		/*if (!strcmp("NRML", (*it)->name))
Anakin's avatar
Anakin committed
407
408
409
410
411
		{
			fsMesh.seekg((*it)->position);
			// List of normals
			// long int - 4 - number of normal vectores stored in this list
			// float[3][] - 12 each - UVW vector for each vertex
Anakin's avatar
Anakin committed
412
			continue;
413
		}*/
Anakin's avatar
Anakin committed
414
415
416

		if (!strcmp("UV0L", (*it)->name))
		{
Anakin's avatar
Anakin committed
417
			readUV(tempData, (*it)->position);
Anakin's avatar
Anakin committed
418
			continue;
Anakin's avatar
Anakin committed
419
420
421
422
		}

		if (!strcmp("STRP", (*it)->name))
		{
423
			// jump to the data section and read the size;
Anakin's avatar
Anakin committed
424
			fsMesh.seekg((*it)->position);
Anakin's avatar
Anakin committed
425
			fsMesh.read(reinterpret_cast<char*>(&tempData->meshSize), sizeof(tempData->meshSize));
Anakin's avatar
Anakin committed
426

427
428
429
430
431
432
433
			// workaround: ignore everything except unhidden static/dynamic mesh
			if (dataDestination->type == null ||
				dataDestination->type == bone ||
				dataDestination->type == shadowMesh ||
				dataDestination->renderFlags == 1)
				continue;

Anakin's avatar
Anakin committed
434
			tempData->mesh = new std::uint32_t[tempData->meshSize];
Anakin's avatar
Anakin committed
435

Anakin's avatar
Anakin committed
436
			for (unsigned int i = 0; i < tempData->meshSize; i += 3)
Anakin's avatar
Anakin committed
437
438
439
440
441
442
443
444
445
446
447
448
			{
				std::uint16_t tempValue[3];
				fsMesh.read(reinterpret_cast<char*>(&tempValue[0]), sizeof(std::uint16_t));
				fsMesh.read(reinterpret_cast<char*>(&tempValue[1]), sizeof(std::uint16_t));
				fsMesh.read(reinterpret_cast<char*>(&tempValue[2]), sizeof(std::uint16_t));

				if (!(tempValue[0] >> 15 && tempValue[1] >> 15 && !(tempValue[2] >> 15)))
					throw std::invalid_argument("invalid file. go and triangulate!");

				tempValue[0] = (std::uint16_t(tempValue[0] << 1) >> 1);
				tempValue[1] = (std::uint16_t(tempValue[1] << 1) >> 1);

Anakin's avatar
Anakin committed
449
450
451
				tempData->mesh[i] = (std::uint32_t)tempValue[0];
				tempData->mesh[i + 1] = (std::uint32_t)tempValue[1];
				tempData->mesh[i + 2] = (std::uint32_t)tempValue[2];
Anakin's avatar
Anakin committed
452
453
454
			}

			continue;
Anakin's avatar
Anakin committed
455
		}
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489

/////////////////////////////////////////////////////////////////////////////////////////
/////DEV ZONE

		if (!strcmp("STRP", (*it)->name))
		{
			// this needs to be a member
			std::vector<std::vector<std::uint32_t>*> tempVector;

			// jump to the data section and read the size;
			fsMesh.seekg((*it)->position);
			fsMesh.read(reinterpret_cast<char*>(&tempData->meshSize), sizeof(tempData->meshSize));

			int highBitCount(0);
			std::vector<uint32_t>* tempPoly = new std::vector<uint32_t>;
			
			for (unsigned int i = 0; i < tempData->meshSize; i++)
			{
				// 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);
				}

				tempPoly->push_back((std::uint32_t)tempValue);

				if (highBitCount == 2)
				{
					// reset highBitCount
Anakin's avatar
Anakin committed
490
					highBitCount = 0;
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516

					// remove the last two values..
					std::uint32_t saveData[2];
					for (int i = 0; i < 2; i++)
					{
						saveData[0] = tempPoly->back();
						tempPoly->pop_back();
					}

					// ..and save them in the new vector
					std::vector<uint32_t>* newPointer = new std::vector<uint32_t>;
					for (int i = 1; i >= 0; i--)
						newPointer->push_back(saveData[i]);

					// save the old vector and set the pointer to the new one
					tempVector.push_back(tempPoly);
					tempPoly = newPointer;
				}	// if high bit set
				
			}	// for all values
			// save the last values (where no 2 high bits follow);
			tempVector.push_back(tempPoly);
			continue;
		}

////////////////////////////////////////////////////////////////////////////////////////
Anakin's avatar
Anakin committed
517
	}
Anakin's avatar
Anakin committed
518
	dataDestination->segmLst.push_back(tempData);
Anakin's avatar
Anakin committed
519
520
521
522
}

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

Anakin's avatar
Anakin committed
525
526
527
528
529
	for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
	{
		if (!strcmp("CTEX", (*it)->name))
		{
			fsMesh.seekg((*it)->position);
530
			char* buffer = new char[(*it)->size];
Anakin's avatar
Anakin committed
531
			*buffer = { 0 };
532
			fsMesh.read(buffer, (*it)->size);
Anakin's avatar
Anakin committed
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551

			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;
			}

552
			delete buffer;
Anakin's avatar
Anakin committed
553
			continue;
Anakin's avatar
Anakin committed
554
555
556
		}

		if (!strcmp("CPOS", (*it)->name))
Anakin's avatar
Anakin committed
557
		{
Anakin's avatar
Anakin committed
558
			readVertex(tempData, (*it)->position);
Anakin's avatar
Anakin committed
559
560
			continue;
		}
Anakin's avatar
Anakin committed
561
562

		if (!strcmp("CUV0", (*it)->name))
Anakin's avatar
Anakin committed
563
		{
Anakin's avatar
Anakin committed
564
			readUV(tempData, (*it)->position);
Anakin's avatar
Anakin committed
565
566
			continue;
		}
Anakin's avatar
Anakin committed
567
568

		if (!strcmp("CMSH", (*it)->name))
Anakin's avatar
Anakin committed
569
570
		{
			fsMesh.seekg((*it)->position);
Anakin's avatar
Anakin committed
571
			fsMesh.read(reinterpret_cast<char*>(&tempData->meshSize), sizeof(tempData->meshSize));
Anakin's avatar
Anakin committed
572

Anakin's avatar
Anakin committed
573
			tempData->mesh = new std::uint32_t[tempData->meshSize * 3];
Anakin's avatar
Anakin committed
574

Anakin's avatar
Anakin committed
575
			for (unsigned int i = 0; i < tempData->meshSize; i += 3)
Anakin's avatar
Anakin committed
576
			{
Anakin's avatar
Anakin committed
577
578
579
				fsMesh.read(reinterpret_cast<char*>(&tempData->mesh[i]), sizeof(std::uint32_t));
				fsMesh.read(reinterpret_cast<char*>(&tempData->mesh[i + 1]), sizeof(std::uint32_t));
				fsMesh.read(reinterpret_cast<char*>(&tempData->mesh[i + 2]), sizeof(std::uint32_t));
Anakin's avatar
Anakin committed
580
581
582
			}
			continue;
		}
583
	}
Anakin's avatar
Anakin committed
584
	dataDestination->segmLst.push_back(tempData);
585
586
}

Anakin's avatar
Anakin committed
587
void Object::readVertex(Segment* dataDestination, std::streampos position)
588
589
590
591
592
593
594
{
	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
595
	for (unsigned int i = 0; i < tempSize * 3; i++)
596
597
598
		fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i]), sizeof(float));
}

Anakin's avatar
Anakin committed
599
void Object::readUV(Segment* dataDestination, std::streampos position)
600
601
602
603
604
605
606
{
	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
607
	for (unsigned int i = 0; i < tempSize * 2; i++)
608
		fsMesh.read(reinterpret_cast<char*>(&dataDestination->uv[i]), sizeof(float));
Anakin's avatar
Anakin committed
609
610
}

611

Anakin's avatar
Anakin committed
612
613
/////////////////////////////////////////////////////////////////////////
// public getter
614

Anakin's avatar
Anakin committed
615
616
617
618
619
std::vector<Modl*> Object::getModels() const
{
	return vModls;
}

Anakin's avatar
Anakin committed
620
621
622
623
624
std::vector<std::string> Object::getTextureList() const
{
	return vTextures;
}

625
626
627
628

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