2016-09-06 13:15:29 +00:00
|
|
|
#include "Object.h"
|
2016-09-12 14:49:05 +00:00
|
|
|
#include <iostream>
|
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-10 10:34:01 +00:00
|
|
|
// jump into msh2 todo: search for MSH2 if there is a shadowvolume
|
2016-10-09 14:44:35 +00:00
|
|
|
fsMesh.seekg(8);
|
|
|
|
char tempChunkName[5] = { 0 };
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempChunkName[0]), sizeof(tempChunkName) - 1);
|
|
|
|
|
|
|
|
if (strcmp(tempChunkName, "MSH2"))
|
|
|
|
throw std::invalid_argument(std::string("corrupted file MSH2 expected instead of ") += tempChunkName);
|
|
|
|
|
2016-10-10 10:34:01 +00:00
|
|
|
std::uint32_t tempSize;
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
2016-10-09 14:44:35 +00:00
|
|
|
|
2016-10-10 10:34:01 +00:00
|
|
|
// get all sub chunks from MSH2
|
|
|
|
loadChunks(lChunkMsh2, fsMesh.tellg(), tempSize);
|
2016-10-09 14:44:35 +00:00
|
|
|
|
2016-10-10 10:34:01 +00:00
|
|
|
// search for all MODL Chunks
|
2016-10-12 13:55:36 +00:00
|
|
|
for (std::list<ChunkHeader*>::iterator it = lChunkMsh2.begin(); it != lChunkMsh2.end(); it++)
|
2016-10-09 14:44:35 +00:00
|
|
|
{
|
|
|
|
if (!strcmp("MODL", (*it)->name))
|
|
|
|
{
|
2016-10-12 13:55:36 +00:00
|
|
|
Modl* tempModl = new Modl;
|
2016-10-17 15:49:44 +00:00
|
|
|
setModlDefault(tempModl);
|
2016-10-11 11:41:24 +00:00
|
|
|
|
2016-10-12 13:55:36 +00:00
|
|
|
// get all subchunks
|
|
|
|
std::list<ChunkHeader*> tempChunks;
|
2016-10-11 11:41:24 +00:00
|
|
|
loadChunks(tempChunks, (*it)->position, (*it)->size);
|
|
|
|
|
|
|
|
// evaluate MODL subchunks
|
2016-10-12 13:55:36 +00:00
|
|
|
analyseModlChunks(tempModl, tempChunks);
|
2016-10-11 11:41:24 +00:00
|
|
|
|
|
|
|
//clean up
|
|
|
|
while (!tempChunks.empty())
|
|
|
|
{
|
2016-10-12 13:55:36 +00:00
|
|
|
ChunkHeader* tempCursor = tempChunks.front();
|
2016-10-11 11:41:24 +00:00
|
|
|
tempChunks.pop_front();
|
|
|
|
delete tempCursor;
|
|
|
|
}
|
2016-10-12 13:55:36 +00:00
|
|
|
|
|
|
|
// save Model data
|
|
|
|
lModls.push_back(tempModl);
|
2016-10-09 14:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-09-13 17:48:27 +00:00
|
|
|
// close file
|
|
|
|
fsMesh.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
Object::~Object()
|
|
|
|
{
|
|
|
|
//delete Chunk list;
|
|
|
|
}
|
2016-09-06 13:15:29 +00:00
|
|
|
|
|
|
|
|
2016-10-09 14:44:35 +00:00
|
|
|
|
2016-09-13 17:48:27 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// private functions
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-10-16 10:33:25 +00:00
|
|
|
void Object::setModlDefault(Modl * model)
|
|
|
|
{
|
|
|
|
model->name = "";
|
|
|
|
model->parent = "";
|
|
|
|
model->type = null;
|
|
|
|
model->renderFlags = -1;
|
|
|
|
model->tran.scale[0] = 0;
|
|
|
|
model->tran.scale[1] = 0;
|
|
|
|
model->tran.scale[2] = 0;
|
|
|
|
model->tran.rotation[0] = 0;
|
|
|
|
model->tran.rotation[1] = 0;
|
|
|
|
model->tran.rotation[2] = 0;
|
|
|
|
model->tran.rotation[3] = 0;
|
|
|
|
model->tran.translation[0] = 0;
|
|
|
|
model->tran.translation[1] = 0;
|
|
|
|
model->tran.translation[2] = 0;
|
|
|
|
model->swci.type = -1;
|
|
|
|
model->swci.data1 = -1;
|
|
|
|
model->swci.data2 = -1;
|
|
|
|
model->swci.data3 = -1;
|
|
|
|
model->texture = "";
|
|
|
|
model->vertex = NULL;
|
|
|
|
model->uv = NULL;
|
|
|
|
model->mesh = NULL;
|
2016-10-16 14:50:20 +00:00
|
|
|
model->meshSize = 0;
|
2016-10-16 10:33:25 +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-10-09 14:44:35 +00:00
|
|
|
|
|
|
|
std::cout << "got all chunks, totaly found: " << destination.size() << std::endl;
|
2016-09-12 14:49:05 +00:00
|
|
|
|
2016-09-06 13:15:29 +00:00
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
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];
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->tran.scale[0]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->tran.scale[1]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->tran.scale[2]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->tran.rotation[0]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->tran.rotation[1]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->tran.rotation[2]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->tran.rotation[3]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->tran.translation[0]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->tran.translation[1]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->tran.translation[2]), sizeof(float));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("SWCI", (*it)->name))
|
|
|
|
{
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->swci.type), sizeof(dataDestination->swci.type));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->swci.data1), sizeof(dataDestination->swci.data1));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->swci.data2), sizeof(dataDestination->swci.data2));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->swci.data3), sizeof(dataDestination->swci.data3));
|
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)
|
|
|
|
{
|
|
|
|
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
|
|
|
{
|
|
|
|
if (!strcmp("SHDW", (*it)->name))
|
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("MATI", (*it)->name))
|
|
|
|
{
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
// material index index into MATL
|
|
|
|
// long int - 4 - material index
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("POSL", (*it)->name))
|
|
|
|
{
|
2016-10-16 10:33:25 +00:00
|
|
|
readVertex(dataDestination, (*it)->position);
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("NRML", (*it)->name))
|
|
|
|
{
|
|
|
|
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
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("UV0L", (*it)->name))
|
|
|
|
{
|
2016-10-16 10:33:25 +00:00
|
|
|
readUV(dataDestination, (*it)->position);
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-12 13:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("STRP", (*it)->name))
|
|
|
|
{
|
|
|
|
fsMesh.seekg((*it)->position);
|
2016-10-16 14:50:20 +00:00
|
|
|
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->meshSize), sizeof(dataDestination->meshSize));
|
|
|
|
|
|
|
|
dataDestination->mesh = new std::uint32_t[dataDestination->meshSize * 3];
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < dataDestination->meshSize; i += 3)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
dataDestination->mesh[i] = (std::uint32_t)tempValue[0];
|
|
|
|
dataDestination->mesh[i + 1] = (std::uint32_t)tempValue[1];
|
|
|
|
dataDestination->mesh[i + 2] = (std::uint32_t)tempValue[2];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-17 15:49:44 +00:00
|
|
|
std::cout << "triangles: " << dataDestination->meshSize << std::endl;
|
2016-10-16 14:50:20 +00:00
|
|
|
for (int i = 0; i < dataDestination->meshSize; i += 3)
|
2016-10-17 15:49:44 +00:00
|
|
|
std::cout << dataDestination->mesh[i] << " <> " << dataDestination->mesh[i + 1] << " <> " << dataDestination->mesh[i + 2] << std::endl;
|
2016-10-16 14:50:20 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
|
2016-10-12 13:55:36 +00:00
|
|
|
/*
|
|
|
|
List of triangles strips. The start of a strip is indicated by 2 entries
|
|
|
|
with a high bit set (0x8000 or 32768 added). Triangles are listed CW, CCW,
|
|
|
|
CW, CCW... NOTE: In some meshes this chunk has a trailing short which is not
|
|
|
|
calculated into the length/size of this chunk or the # of indices. This
|
|
|
|
short can be ignored. If added to the last polygon it will break it as it
|
|
|
|
always seems to be 0.
|
|
|
|
long int - 4 - number of indicies into POSL
|
|
|
|
short int[] - 2 each - index into POSL the indices will form polygons
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
fsMesh.read(buffer, (*it)->size);
|
|
|
|
dataDestination->texture = 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("CPOS", (*it)->name))
|
2016-10-16 14:50:20 +00:00
|
|
|
{
|
2016-10-16 10:33:25 +00:00
|
|
|
readVertex(dataDestination, (*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-10-16 10:33:25 +00:00
|
|
|
readUV(dataDestination, (*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
|
|
|
{
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->meshSize), sizeof(dataDestination->meshSize));
|
|
|
|
|
|
|
|
dataDestination->mesh = new std::uint32_t[dataDestination->meshSize * 3];
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < dataDestination->meshSize; i += 3)
|
|
|
|
{
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->mesh[i]), sizeof(std::uint32_t));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->mesh[i + 1]), sizeof(std::uint32_t));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->mesh[i + 2]), sizeof(std::uint32_t));
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2016-10-16 10:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Object::readVertex(Modl* dataDestination, std::streampos position)
|
|
|
|
{
|
|
|
|
std::uint32_t tempSize;
|
|
|
|
fsMesh.seekg(position);
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
|
|
|
|
|
|
|
dataDestination->vertex = new float[tempSize * 3];
|
|
|
|
|
2016-10-17 15:49:44 +00:00
|
|
|
for (unsigned int i = 0; i < tempSize * 3; i += 3)
|
2016-10-16 10:33:25 +00:00
|
|
|
{
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i + 1]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i + 2]), sizeof(float));
|
|
|
|
}
|
2016-10-17 15:49:44 +00:00
|
|
|
|
|
|
|
std::cout << "Vertex number: " << tempSize << std::endl;
|
|
|
|
for (int i = 0; i < tempSize * 3; i += 3)
|
|
|
|
std::cout << dataDestination->vertex[i] << " <> " << dataDestination->vertex[i + 1] << " <> " << dataDestination->vertex[i + 2] << std::endl;
|
|
|
|
|
|
|
|
|
2016-10-16 10:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Object::readUV(Modl* dataDestination, std::streampos position)
|
|
|
|
{
|
|
|
|
std::uint32_t tempSize;
|
|
|
|
fsMesh.seekg(position);
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
|
|
|
|
|
|
|
dataDestination->uv = new float[tempSize * 2];
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < tempSize; i += 2)
|
|
|
|
{
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->uv[i]), sizeof(float));
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->uv[i + 1]), sizeof(float));
|
|
|
|
}
|
2016-10-12 13:55:36 +00:00
|
|
|
|
2016-10-16 14:50:20 +00:00
|
|
|
std::cout << "UV" << std::endl;
|
|
|
|
for (int i = 0; i < dataDestination->meshSize; i += 3)
|
|
|
|
std::cout << dataDestination->mesh[i] << " - " << dataDestination->mesh[i + 1] << " - " << dataDestination->mesh[i + 2] << std::endl;
|
2016-10-16 10:33:25 +00:00
|
|
|
|
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-16 10:33:25 +00:00
|
|
|
std::vector<GLfloat> Object::getVertex() const
|
|
|
|
{
|
|
|
|
std::vector<GLfloat> tempData;
|
|
|
|
|
|
|
|
for (std::list<Modl*>::const_iterator it = lModls.begin(); it != lModls.end(); it++)
|
|
|
|
{
|
2016-10-17 15:49:44 +00:00
|
|
|
for (unsigned int i = 0; i < (*it)->meshSize; i++)
|
2016-10-16 10:33:25 +00:00
|
|
|
{
|
2016-10-17 15:49:44 +00:00
|
|
|
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3]);
|
|
|
|
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3 + 1]);
|
|
|
|
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3 + 2]);
|
2016-10-16 10:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tempData;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<GLfloat> Object::getUV() const
|
|
|
|
{
|
|
|
|
std::vector<GLfloat> tempData;
|
|
|
|
|
|
|
|
for (std::list<Modl*>::const_iterator it = lModls.begin(); it != lModls.end(); it++)
|
2016-10-16 14:50:20 +00:00
|
|
|
{
|
|
|
|
if ((*it)->uv == NULL)
|
2016-10-17 15:49:44 +00:00
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < (*it)->meshSize; i++)
|
|
|
|
tempData.push_back(1.0);
|
2016-10-16 14:50:20 +00:00
|
|
|
continue;
|
2016-10-17 15:49:44 +00:00
|
|
|
}
|
|
|
|
for (unsigned int i = 0; i < (*it)->meshSize; i++)
|
2016-10-16 14:50:20 +00:00
|
|
|
{
|
2016-10-16 10:33:25 +00:00
|
|
|
tempData.push_back((GLfloat)(*it)->uv[(*it)->mesh[i]]);
|
2016-10-16 14:50:20 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-16 10:33:25 +00:00
|
|
|
|
|
|
|
return tempData;
|
|
|
|
}
|
2016-09-06 13:15:29 +00:00
|
|
|
|
2016-10-21 16:56:34 +00:00
|
|
|
std::list<std::string> Object::getTexture() const
|
|
|
|
{
|
|
|
|
std::list<std::string> tempData;
|
|
|
|
|
|
|
|
for (std::list<Modl*>::const_iterator it = lModls.begin(); it != lModls.end(); it++)
|
|
|
|
tempData.push_back((*it)->texture);
|
|
|
|
|
|
|
|
return tempData;
|
|
|
|
}
|
|
|
|
|
2016-09-06 13:15:29 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// public functions
|
|
|
|
|