|
|
|
@@ -69,6 +69,32 @@ Object::~Object()
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// private functions
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::loadChunks(std::list<ChunkHeader*>& destination, std::streampos start, const std::uint32_t end)
|
|
|
|
|
{
|
|
|
|
|
// jump to first chunk
|
|
|
|
@@ -116,12 +142,6 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
|
|
|
|
|
dataDestination->type = (Mtyp)tempType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp("MNDX", (*it)->name))
|
|
|
|
|
{
|
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->zeroBaseIndex), sizeof(dataDestination->zeroBaseIndex));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp("PRNT", (*it)->name))
|
|
|
|
|
{
|
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
@@ -133,9 +153,9 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
|
|
|
|
|
if (!strcmp("NAME", (*it)->name))
|
|
|
|
|
{
|
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
|
char tempName[33] = { 0 };
|
|
|
|
|
fsMesh.read(reinterpret_cast<char*>(&tempName[0]), (*it)->size > 32 ? 32 : (*it)->size);
|
|
|
|
|
dataDestination->name = tempName;
|
|
|
|
|
char* buffer = new char[(*it)->size];
|
|
|
|
|
fsMesh.read(buffer, (*it)->size);
|
|
|
|
|
dataDestination->name = buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp("FLGS", (*it)->name))
|
|
|
|
@@ -211,8 +231,7 @@ void Object::analyseGeomChunks(Modl * dataDestination, std::list<ChunkHeader*>&
|
|
|
|
|
delete tempCursor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp("CLTH", (*it)->name))
|
|
|
|
|
else if (!strcmp("CLTH", (*it)->name))
|
|
|
|
|
{
|
|
|
|
|
// get all subchunks
|
|
|
|
|
std::list<ChunkHeader*> tempClthChunks;
|
|
|
|
@@ -263,10 +282,7 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
|
|
|
|
|
|
|
|
|
|
if (!strcmp("POSL", (*it)->name))
|
|
|
|
|
{
|
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
|
// list of vertex coordinates
|
|
|
|
|
// long int - 4 - number of coordinates stored in this list
|
|
|
|
|
// float[3][] - 12 each - XYZ coordinates
|
|
|
|
|
readVertex(dataDestination, (*it)->position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp("NRML", (*it)->name))
|
|
|
|
@@ -279,14 +295,12 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
|
|
|
|
|
|
|
|
|
|
if (!strcmp("UV0L", (*it)->name))
|
|
|
|
|
{
|
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
|
// List of UV
|
|
|
|
|
// long int - 4 - number of UV
|
|
|
|
|
// float[2][] - 8 each - UV coordinate
|
|
|
|
|
readUV(dataDestination, (*it)->position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp("STRP", (*it)->name))
|
|
|
|
|
{
|
|
|
|
|
readMesh(dataDestination, (*it)->position);
|
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
|
/*
|
|
|
|
|
List of triangles strips. The start of a strip is indicated by 2 entries
|
|
|
|
@@ -309,42 +323,105 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>&
|
|
|
|
|
if (!strcmp("CTEX", (*it)->name))
|
|
|
|
|
{
|
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
|
// texture name with extension (how long could it be??)
|
|
|
|
|
// ascii
|
|
|
|
|
char* buffer = new char[(*it)->size];
|
|
|
|
|
fsMesh.read(buffer, (*it)->size);
|
|
|
|
|
dataDestination->texture = buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp("CPOS", (*it)->name))
|
|
|
|
|
{
|
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
|
// list of Vertex coordinates
|
|
|
|
|
// long int (4) number of vertex
|
|
|
|
|
// float[3][] (12 each) XYZ coordinates
|
|
|
|
|
}
|
|
|
|
|
readVertex(dataDestination, (*it)->position);
|
|
|
|
|
|
|
|
|
|
if (!strcmp("CUV0", (*it)->name))
|
|
|
|
|
{
|
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
|
// list of UV coordinates
|
|
|
|
|
// long int (4) number of UV Coordinates
|
|
|
|
|
// float[2][] (8 each) UV coordinate
|
|
|
|
|
}
|
|
|
|
|
readUV(dataDestination, (*it)->position);
|
|
|
|
|
|
|
|
|
|
if (!strcmp("CMSH", (*it)->name))
|
|
|
|
|
{
|
|
|
|
|
fsMesh.seekg((*it)->position);
|
|
|
|
|
// cloth tirangles
|
|
|
|
|
// long int (4) number of points
|
|
|
|
|
// long int[3][] (16 each) triangle points defined CCW
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readMesh(dataDestination, (*it)->position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < tempSize; i += 3)
|
|
|
|
|
{
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::readMesh(Modl* dataDestination, std::streampos position)
|
|
|
|
|
{
|
|
|
|
|
fsMesh.seekg(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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < dataDestination->meshSize; i += 3)
|
|
|
|
|
std::cout << dataDestination->mesh[i] << " " << dataDestination->mesh[i + 1] << " " << dataDestination->mesh[i + 2] << std::endl;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// public getter
|
|
|
|
|
|
|
|
|
|
std::vector<GLfloat> Object::getVertex() const
|
|
|
|
|
{
|
|
|
|
|
std::vector<GLfloat> tempData;
|
|
|
|
|
|
|
|
|
|
for (std::list<Modl*>::const_iterator it = lModls.begin(); it != lModls.end(); it++)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < (*it)->meshSize; i++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int tempIndex = (*it)->mesh[i];
|
|
|
|
|
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i]]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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++)
|
|
|
|
|
for (int i = 0; i < (*it)->meshSize; i++)
|
|
|
|
|
tempData.push_back((GLfloat)(*it)->uv[(*it)->mesh[i]]);
|
|
|
|
|
|
|
|
|
|
return tempData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|