Object.cpp 1.33 KB
Newer Older
1
#include "Object.h"
Anakin's avatar
Anakin committed
2
#include <iostream>
3
4
5
6
7
8



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

Anakin's avatar
Anakin committed
9
Object::Object(const char* path)
10
{
Anakin's avatar
Anakin committed
11
	// open file
12
	fsMesh.open(path, std::ios::in | std::ios::binary);
13

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

17
18
	// get Chunks
	readChunks();
19

20
21
22
23
24
25
26
27
	// close file
	fsMesh.close();
}

Object::~Object()
{
	//delete Chunk list;	
}
28
29


30
31
/////////////////////////////////////////////////////////////////////////
// private functions
32

33
34
35
36
void Object::readChunks()
{
	// Jump into Mesh2
	fsMesh.seekg(16, std::ios_base::cur);
37

Anakin's avatar
Anakin committed
38
39
	do
	{
40
		chunkHeader* tempHeader = new chunkHeader();
41

42
43
44
		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();
45

46
		lChunk.push_back(tempHeader);
47

48
		fsMesh.seekg(tempHeader->size, std::ios_base::cur);
49

50
		if (!std::strcmp(tempHeader->name, "CL1L"))
Anakin's avatar
Anakin committed
51
52
53
			break;
	} while (!fsMesh.eof());

54
	std::cout << "got all chunks, totaly found: " << lChunk.size() << std::endl;
55
56
57
}


Anakin's avatar
Anakin committed
58
59
/////////////////////////////////////////////////////////////////////////
// public getter
60
61
62
63
64
65



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