2016-09-06 13:15:29 +00:00
|
|
|
#include "Object.h"
|
2016-09-12 14:49:05 +00:00
|
|
|
#include <iostream>
|
2016-11-12 11:05:03 +00:00
|
|
|
|
|
|
|
|
2016-10-31 09:46:41 +00:00
|
|
|
#define PI (4.0*atan(1.0))
|
2016-09-06 13:15:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// public constructor/destructor
|
|
|
|
|
2016-09-12 14:49:05 +00:00
|
|
|
Object::Object(const char* path)
|
2016-09-06 13:15:29 +00:00
|
|
|
{
|
2016-09-12 14:49:05 +00:00
|
|
|
// open file
|
2016-09-13 17:48:27 +00:00
|
|
|
fsMesh.open(path, std::ios::in | std::ios::binary);
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-09-12 14:49:05 +00:00
|
|
|
if (!fsMesh.is_open())
|
|
|
|
throw std::invalid_argument(std::string("file not found: ") += path);
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-10-21 17:24:30 +00:00
|
|
|
// jump to file size information
|
|
|
|
fsMesh.seekg(4);
|
2016-10-09 14:44:35 +00:00
|
|
|
|
2016-10-21 17:24:30 +00:00
|
|
|
std::uint32_t tempFileSize;
|
|
|
|
std::list<ChunkHeader*> tempMainChunks;
|
2016-10-09 14:44:35 +00:00
|
|
|
|
2016-10-21 17:24:30 +00:00
|
|
|
// get all chunks under HEDR
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempFileSize), sizeof(tempFileSize));
|
|
|
|
loadChunks(tempMainChunks, fsMesh.tellg(), tempFileSize);
|
2016-10-09 14:44:35 +00:00
|
|
|
|
2016-10-22 11:49:45 +00:00
|
|
|
// evaluate HEDR subchunks (= find MSH2)
|
2016-10-21 17:24:30 +00:00
|
|
|
for (std::list<ChunkHeader*>::iterator it = tempMainChunks.begin(); it != tempMainChunks.end(); it++)
|
2016-10-09 14:44:35 +00:00
|
|
|
{
|
2016-10-21 17:24:30 +00:00
|
|
|
if (!strcmp("MSH2", (*it)->name))
|
2016-10-09 14:44:35 +00:00
|
|
|
{
|
2016-10-12 13:55:36 +00:00
|
|
|
// get all subchunks
|
2016-10-21 17:24:30 +00:00
|
|
|
std::list<ChunkHeader*> tempMsh2Chunks;
|
|
|
|
loadChunks(tempMsh2Chunks, (*it)->position, (*it)->size);
|
2016-10-11 11:41:24 +00:00
|
|
|
|
2016-10-21 17:24:30 +00:00
|
|
|
// evaluate MSH2 subchunks
|
|
|
|
analyseMsh2Chunks(tempMsh2Chunks);
|
|
|
|
|
|
|
|
// clean up
|
|
|
|
while (!tempMsh2Chunks.empty())
|
2016-10-11 11:41:24 +00:00
|
|
|
{
|
2016-10-21 17:24:30 +00:00
|
|
|
ChunkHeader* tempCursor = tempMsh2Chunks.front();
|
|
|
|
tempMsh2Chunks.pop_front();
|
2016-10-11 11:41:24 +00:00
|
|
|
delete tempCursor;
|
|
|
|
}
|
2016-10-21 17:24:30 +00:00
|
|
|
continue;
|
2016-10-09 14:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-10-21 17:24:30 +00:00
|
|
|
// clean up
|
|
|
|
while (!tempMainChunks.empty())
|
|
|
|
{
|
|
|
|
ChunkHeader* tempCursor = tempMainChunks.front();
|
|
|
|
tempMainChunks.pop_front();
|
|
|
|
delete tempCursor;
|
|
|
|
}
|
|
|
|
|
2016-09-13 17:48:27 +00:00
|
|
|
// close file
|
|
|
|
fsMesh.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
Object::~Object()
|
|
|
|
{
|
2016-10-31 15:19:12 +00:00
|
|
|
// clear texture list
|
|
|
|
vTextures.clear();
|
|
|
|
|
|
|
|
// clear Model list (don't delete the elements)
|
|
|
|
vModls.clear();
|
2016-09-13 17:48:27 +00:00
|
|
|
}
|
2016-09-06 13:15:29 +00:00
|
|
|
|
|
|
|
|
2016-09-13 17:48:27 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// private functions
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-10-12 13:55:36 +00:00
|
|
|
void Object::loadChunks(std::list<ChunkHeader*>& destination, std::streampos start, const std::uint32_t end)
|
2016-09-13 17:48:27 +00:00
|
|
|
{
|
2016-10-10 10:34:01 +00:00
|
|
|
// jump to first chunk
|
2016-10-09 14:44:35 +00:00
|
|
|
fsMesh.seekg(start);
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-09-12 14:49:05 +00:00
|
|
|
do
|
|
|
|
{
|
2016-10-12 13:55:36 +00:00
|
|
|
ChunkHeader* tempHeader = new ChunkHeader();
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-09-13 17:48:27 +00:00
|
|
|
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();
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-10-09 14:44:35 +00:00
|
|
|
destination.push_back(tempHeader);
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-09-13 17:48:27 +00:00
|
|
|
fsMesh.seekg(tempHeader->size, std::ios_base::cur);
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-10-10 10:34:01 +00:00
|
|
|
// reached end
|
|
|
|
if (fsMesh.tellg() - start == end)
|
2016-09-12 14:49:05 +00:00
|
|
|
break;
|
2016-10-10 10:34:01 +00:00
|
|
|
|
|
|
|
// 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);
|
2016-09-06 13:15:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-21 17:24:30 +00:00
|
|
|
void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
|
|
|
{
|
|
|
|
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
|
|
|
{
|
|
|
|
if (!strcmp("MATL", (*it)->name))
|
|
|
|
{
|
2016-10-22 13:35:06 +00:00
|
|
|
// "useless" information how many MATD follow
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
std::uint32_t tempMatdCount;
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempMatdCount), sizeof(std::uint32_t));
|
|
|
|
|
2016-10-22 11:49:45 +00:00
|
|
|
// get all MATD from MATL list
|
|
|
|
std::list<ChunkHeader*> tempMatlChunks;
|
2016-10-22 13:35:06 +00:00
|
|
|
loadChunks(tempMatlChunks, fsMesh.tellg(), (*it)->size - 4);
|
2016-10-22 11:49:45 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2016-11-21 14:02:33 +00:00
|
|
|
vTextures.push_back("");
|
|
|
|
|
2016-10-22 11:49:45 +00:00
|
|
|
// analyse MATD subchunks
|
2016-10-22 12:05:46 +00:00
|
|
|
analyseMatdChunks(tempMatdChunks);
|
2016-10-22 11:49:45 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2016-10-21 17:24:30 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("MODL", (*it)->name))
|
|
|
|
{
|
2016-10-22 12:05:46 +00:00
|
|
|
Modl* tempModl = new Modl;
|
|
|
|
|
2016-10-21 17:24:30 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2016-10-22 12:05:46 +00:00
|
|
|
// save Model data
|
2016-10-30 13:22:08 +00:00
|
|
|
vModls.push_back(tempModl);
|
2016-10-22 12:05:46 +00:00
|
|
|
|
2016-10-22 11:49:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-21 17:24:30 +00:00
|
|
|
|
2016-10-22 12:05:46 +00:00
|
|
|
void Object::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
2016-10-22 11:49:45 +00:00
|
|
|
{
|
|
|
|
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);
|
2016-11-21 14:02:33 +00:00
|
|
|
vTextures.back() = buffer;
|
2016-10-22 11:49:45 +00:00
|
|
|
delete buffer;
|
2016-10-21 17:24:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-12 13:55:36 +00:00
|
|
|
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;
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("PRNT", (*it)->name))
|
|
|
|
{
|
|
|
|
fsMesh.seekg((*it)->position);
|
2016-10-21 16:56:34 +00:00
|
|
|
char* buffer = new char[(*it)->size];
|
2016-10-22 11:49:45 +00:00
|
|
|
*buffer = { 0 };
|
2016-10-21 16:56:34 +00:00
|
|
|
fsMesh.read(buffer, (*it)->size);
|
|
|
|
dataDestination->parent = buffer;
|
|
|
|
delete buffer;
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("NAME", (*it)->name))
|
|
|
|
{
|
|
|
|
fsMesh.seekg((*it)->position);
|
2016-10-16 10:33:25 +00:00
|
|
|
char* buffer = new char[(*it)->size];
|
2016-10-22 11:49:45 +00:00
|
|
|
*buffer = { 0 };
|
2016-10-16 10:33:25 +00:00
|
|
|
fsMesh.read(buffer, (*it)->size);
|
|
|
|
dataDestination->name = buffer;
|
2016-10-21 16:56:34 +00:00
|
|
|
delete buffer;
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("FLGS", (*it)->name))
|
|
|
|
{
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->renderFlags), sizeof(dataDestination->renderFlags));
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("TRAN", (*it)->name))
|
|
|
|
{
|
2016-10-30 13:22:08 +00:00
|
|
|
float tempScale[3];
|
|
|
|
float tempRotation[4];
|
|
|
|
float tempTrans[3];
|
|
|
|
|
2016-10-12 13:55:36 +00:00
|
|
|
fsMesh.seekg((*it)->position);
|
2016-10-30 13:22:08 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2016-10-31 09:46:41 +00:00
|
|
|
//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;
|
|
|
|
|
2016-10-30 13:22:08 +00:00
|
|
|
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)
|
|
|
|
);
|
|
|
|
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2016-10-16 14:50:20 +00:00
|
|
|
|
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
2016-10-16 14:50:20 +00:00
|
|
|
|
|
|
|
if (!strcmp("CLTH", (*it)->name))
|
2016-10-12 13:55:36 +00:00
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
|
|
|
|
{
|
2016-11-13 11:15:33 +00:00
|
|
|
Segment* tempData = new Segment;
|
|
|
|
|
2016-10-12 13:55:36 +00:00
|
|
|
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
|
|
|
{
|
|
|
|
if (!strcmp("MATI", (*it)->name))
|
|
|
|
{
|
|
|
|
fsMesh.seekg((*it)->position);
|
2016-11-13 14:46:52 +00:00
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempData->textureIndex), sizeof(tempData->textureIndex));
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("POSL", (*it)->name))
|
|
|
|
{
|
2016-11-13 11:15:33 +00:00
|
|
|
readVertex(tempData, (*it)->position);
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
2016-10-23 14:01:06 +00:00
|
|
|
/*if (!strcmp("NRML", (*it)->name))
|
2016-10-12 13:55:36 +00:00
|
|
|
{
|
|
|
|
fsMesh.seekg((*it)->position);
|
2016-11-21 14:02:33 +00:00
|
|
|
std::uint32_t tempSize;
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
2016-10-12 13:55:36 +00:00
|
|
|
// List of normals
|
|
|
|
// long int - 4 - number of normal vectores stored in this list
|
|
|
|
// float[3][] - 12 each - UVW vector for each vertex
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-23 14:01:06 +00:00
|
|
|
}*/
|
2016-10-12 13:55:36 +00:00
|
|
|
|
|
|
|
if (!strcmp("UV0L", (*it)->name))
|
|
|
|
{
|
2016-11-13 11:15:33 +00:00
|
|
|
readUV(tempData, (*it)->position);
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 13:00:51 +00:00
|
|
|
if (!strcmp("STRP", (*it)->name))
|
|
|
|
{
|
2016-11-20 11:26:23 +00:00
|
|
|
// don't get null, bone, shadowMesh and hidden mesh indices
|
|
|
|
if (dataDestination->type == null ||
|
|
|
|
dataDestination->type == bone ||
|
|
|
|
dataDestination->type == shadowMesh ||
|
|
|
|
dataDestination->renderFlags == 1)
|
|
|
|
continue;
|
2016-11-16 13:00:51 +00:00
|
|
|
|
|
|
|
// jump to the data section and read the size;
|
2016-11-20 12:09:02 +00:00
|
|
|
std::uint32_t tempSize;
|
2016-11-16 13:00:51 +00:00
|
|
|
fsMesh.seekg((*it)->position);
|
2016-11-20 12:09:02 +00:00
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
2016-11-16 13:00:51 +00:00
|
|
|
|
|
|
|
int highBitCount(0);
|
|
|
|
std::vector<uint32_t>* tempPoly = new std::vector<uint32_t>;
|
|
|
|
|
2016-11-20 12:09:02 +00:00
|
|
|
for (unsigned int i = 0; i < tempSize; i++)
|
2016-11-16 13:00:51 +00:00
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
|
2016-11-20 11:26:23 +00:00
|
|
|
// new Polygon found
|
2016-11-16 13:00:51 +00:00
|
|
|
if (highBitCount == 2)
|
|
|
|
{
|
|
|
|
// reset highBitCount
|
2016-11-16 13:18:11 +00:00
|
|
|
highBitCount = 0;
|
2016-11-16 13:00:51 +00:00
|
|
|
|
|
|
|
// remove the last two values..
|
|
|
|
std::uint32_t saveData[2];
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
2016-11-20 11:26:23 +00:00
|
|
|
saveData[i] = tempPoly->back();
|
2016-11-16 13:00:51 +00:00
|
|
|
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
|
2016-11-20 11:26:23 +00:00
|
|
|
tempData->meshIndices.push_back(tempPoly);
|
2016-11-16 13:00:51 +00:00
|
|
|
tempPoly = newPointer;
|
|
|
|
} // if high bit set
|
|
|
|
|
|
|
|
} // for all values
|
2016-11-20 11:26:23 +00:00
|
|
|
|
2016-11-16 13:00:51 +00:00
|
|
|
// save the last values (where no 2 high bits follow);
|
2016-11-20 11:26:23 +00:00
|
|
|
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());
|
2016-11-16 13:00:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
2016-11-13 11:15:33 +00:00
|
|
|
dataDestination->segmLst.push_back(tempData);
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
|
|
|
|
{
|
2016-11-13 11:15:33 +00:00
|
|
|
Segment* tempData = new Segment;
|
|
|
|
|
2016-10-12 13:55:36 +00:00
|
|
|
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
|
|
|
{
|
|
|
|
if (!strcmp("CTEX", (*it)->name))
|
|
|
|
{
|
|
|
|
fsMesh.seekg((*it)->position);
|
2016-10-16 10:33:25 +00:00
|
|
|
char* buffer = new char[(*it)->size];
|
2016-10-22 11:49:45 +00:00
|
|
|
*buffer = { 0 };
|
2016-10-16 10:33:25 +00:00
|
|
|
fsMesh.read(buffer, (*it)->size);
|
2016-11-13 14:46:52 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-10-21 16:56:34 +00:00
|
|
|
delete buffer;
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("CPOS", (*it)->name))
|
2016-10-16 14:50:20 +00:00
|
|
|
{
|
2016-11-13 11:15:33 +00:00
|
|
|
readVertex(tempData, (*it)->position);
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-10-12 13:55:36 +00:00
|
|
|
|
|
|
|
if (!strcmp("CUV0", (*it)->name))
|
2016-10-16 14:50:20 +00:00
|
|
|
{
|
2016-11-13 11:15:33 +00:00
|
|
|
readUV(tempData, (*it)->position);
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-10-12 13:55:36 +00:00
|
|
|
|
|
|
|
if (!strcmp("CMSH", (*it)->name))
|
2016-10-16 14:50:20 +00:00
|
|
|
{
|
2016-11-20 12:09:02 +00:00
|
|
|
// jump to the data section and read the size;
|
|
|
|
std::uint32_t tempSize;
|
2016-10-16 14:50:20 +00:00
|
|
|
fsMesh.seekg((*it)->position);
|
2016-11-20 12:09:02 +00:00
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
2016-10-16 14:50:20 +00:00
|
|
|
|
2016-11-20 12:09:02 +00:00
|
|
|
std::vector<uint32_t>* tempPoly;
|
2016-10-16 14:50:20 +00:00
|
|
|
|
2016-11-20 12:09:02 +00:00
|
|
|
// for every triangle..
|
|
|
|
for (unsigned int i = 0; i < tempSize; i += 3)
|
2016-10-16 14:50:20 +00:00
|
|
|
{
|
2016-11-20 12:09:02 +00:00
|
|
|
tempPoly = new std::vector<uint32_t>;
|
|
|
|
|
|
|
|
// ..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));
|
|
|
|
tempPoly->push_back(tempValue);
|
|
|
|
}
|
|
|
|
tempData->meshIndices.push_back(tempPoly);
|
2016-10-16 14:50:20 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2016-10-16 10:33:25 +00:00
|
|
|
}
|
2016-11-13 11:15:33 +00:00
|
|
|
dataDestination->segmLst.push_back(tempData);
|
2016-10-16 10:33:25 +00:00
|
|
|
}
|
|
|
|
|
2016-11-13 11:15:33 +00:00
|
|
|
void Object::readVertex(Segment* dataDestination, std::streampos position)
|
2016-10-16 10:33:25 +00:00
|
|
|
{
|
|
|
|
std::uint32_t tempSize;
|
|
|
|
fsMesh.seekg(position);
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
|
|
|
|
|
|
|
dataDestination->vertex = new float[tempSize * 3];
|
|
|
|
|
2016-10-31 15:19:12 +00:00
|
|
|
for (unsigned int i = 0; i < tempSize * 3; i++)
|
2016-10-16 10:33:25 +00:00
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i]), sizeof(float));
|
|
|
|
}
|
|
|
|
|
2016-11-13 11:15:33 +00:00
|
|
|
void Object::readUV(Segment* dataDestination, std::streampos position)
|
2016-10-16 10:33:25 +00:00
|
|
|
{
|
|
|
|
std::uint32_t tempSize;
|
|
|
|
fsMesh.seekg(position);
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
|
|
|
|
|
|
|
dataDestination->uv = new float[tempSize * 2];
|
|
|
|
|
2016-10-31 15:19:12 +00:00
|
|
|
for (unsigned int i = 0; i < tempSize * 2; i++)
|
2016-10-16 10:33:25 +00:00
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->uv[i]), sizeof(float));
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-09-12 14:49:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// public getter
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-10-30 13:22:08 +00:00
|
|
|
std::vector<Modl*> Object::getModels() const
|
|
|
|
{
|
|
|
|
return vModls;
|
|
|
|
}
|
|
|
|
|
2016-11-13 14:46:52 +00:00
|
|
|
std::vector<std::string> Object::getTextureList() const
|
|
|
|
{
|
|
|
|
return vTextures;
|
|
|
|
}
|
|
|
|
|
2016-09-06 13:15:29 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// public functions
|
|
|
|
|