integrated mesh import class into OpenGL,
Problem with STRP, indices are not logical
This commit is contained in:
parent
b2f174d15f
commit
9700638548
|
@ -3,6 +3,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <gl\glew.h>
|
||||||
|
|
||||||
enum Mtyp {
|
enum Mtyp {
|
||||||
null,
|
null,
|
||||||
|
@ -23,7 +24,6 @@ struct Modl {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string parent;
|
std::string parent;
|
||||||
Mtyp type;
|
Mtyp type;
|
||||||
std::uint32_t zeroBaseIndex;
|
|
||||||
std::uint32_t renderFlags;
|
std::uint32_t renderFlags;
|
||||||
struct {
|
struct {
|
||||||
float scale[3];
|
float scale[3];
|
||||||
|
@ -36,6 +36,11 @@ struct Modl {
|
||||||
float data2;
|
float data2;
|
||||||
float data3;
|
float data3;
|
||||||
} swci;
|
} swci;
|
||||||
|
std::string texture;
|
||||||
|
float* vertex;
|
||||||
|
float* uv;
|
||||||
|
std::uint32_t meshSize;
|
||||||
|
std::uint32_t* mesh;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,12 +58,19 @@ private:
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setModlDefault(Modl* model);
|
||||||
void loadChunks(std::list<ChunkHeader*> &destination, std::streampos start, const std::uint32_t end);
|
void loadChunks(std::list<ChunkHeader*> &destination, std::streampos start, const std::uint32_t end);
|
||||||
void analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
void analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||||
void analyseGeomChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
void analyseGeomChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||||
void analyseSegmChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
void analyseSegmChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||||
void analyseClthChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
void analyseClthChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||||
|
void readVertex(Modl* dataDestination, std::streampos position);
|
||||||
|
void readUV(Modl* dataDestination, std::streampos position);
|
||||||
|
void readMesh(Modl* dataDestination, std::streampos position);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
std::vector<GLfloat> getVertex() const;
|
||||||
|
std::vector<GLfloat> getUV() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -69,6 +69,32 @@ Object::~Object()
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// private functions
|
// 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)
|
void Object::loadChunks(std::list<ChunkHeader*>& destination, std::streampos start, const std::uint32_t end)
|
||||||
{
|
{
|
||||||
// jump to first chunk
|
// jump to first chunk
|
||||||
|
@ -116,12 +142,6 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
|
||||||
dataDestination->type = (Mtyp)tempType;
|
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))
|
if (!strcmp("PRNT", (*it)->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg((*it)->position);
|
||||||
|
@ -133,9 +153,9 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
|
||||||
if (!strcmp("NAME", (*it)->name))
|
if (!strcmp("NAME", (*it)->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg((*it)->position);
|
||||||
char tempName[33] = { 0 };
|
char* buffer = new char[(*it)->size];
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempName[0]), (*it)->size > 32 ? 32 : (*it)->size);
|
fsMesh.read(buffer, (*it)->size);
|
||||||
dataDestination->name = tempName;
|
dataDestination->name = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("FLGS", (*it)->name))
|
if (!strcmp("FLGS", (*it)->name))
|
||||||
|
@ -211,8 +231,7 @@ void Object::analyseGeomChunks(Modl * dataDestination, std::list<ChunkHeader*>&
|
||||||
delete tempCursor;
|
delete tempCursor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!strcmp("CLTH", (*it)->name))
|
||||||
if (!strcmp("CLTH", (*it)->name))
|
|
||||||
{
|
{
|
||||||
// get all subchunks
|
// get all subchunks
|
||||||
std::list<ChunkHeader*> tempClthChunks;
|
std::list<ChunkHeader*> tempClthChunks;
|
||||||
|
@ -263,10 +282,7 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
|
||||||
|
|
||||||
if (!strcmp("POSL", (*it)->name))
|
if (!strcmp("POSL", (*it)->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
readVertex(dataDestination, (*it)->position);
|
||||||
// list of vertex coordinates
|
|
||||||
// long int - 4 - number of coordinates stored in this list
|
|
||||||
// float[3][] - 12 each - XYZ coordinates
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("NRML", (*it)->name))
|
if (!strcmp("NRML", (*it)->name))
|
||||||
|
@ -279,14 +295,12 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
|
||||||
|
|
||||||
if (!strcmp("UV0L", (*it)->name))
|
if (!strcmp("UV0L", (*it)->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
readUV(dataDestination, (*it)->position);
|
||||||
// List of UV
|
|
||||||
// long int - 4 - number of UV
|
|
||||||
// float[2][] - 8 each - UV coordinate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("STRP", (*it)->name))
|
if (!strcmp("STRP", (*it)->name))
|
||||||
{
|
{
|
||||||
|
readMesh(dataDestination, (*it)->position);
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg((*it)->position);
|
||||||
/*
|
/*
|
||||||
List of triangles strips. The start of a strip is indicated by 2 entries
|
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))
|
if (!strcmp("CTEX", (*it)->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg((*it)->position);
|
||||||
// texture name with extension (how long could it be??)
|
char* buffer = new char[(*it)->size];
|
||||||
// ascii
|
fsMesh.read(buffer, (*it)->size);
|
||||||
|
dataDestination->texture = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("CPOS", (*it)->name))
|
if (!strcmp("CPOS", (*it)->name))
|
||||||
{
|
readVertex(dataDestination, (*it)->position);
|
||||||
fsMesh.seekg((*it)->position);
|
|
||||||
// list of Vertex coordinates
|
|
||||||
// long int (4) number of vertex
|
|
||||||
// float[3][] (12 each) XYZ coordinates
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcmp("CUV0", (*it)->name))
|
if (!strcmp("CUV0", (*it)->name))
|
||||||
{
|
readUV(dataDestination, (*it)->position);
|
||||||
fsMesh.seekg((*it)->position);
|
|
||||||
// list of UV coordinates
|
|
||||||
// long int (4) number of UV Coordinates
|
|
||||||
// float[2][] (8 each) UV coordinate
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcmp("CMSH", (*it)->name))
|
if (!strcmp("CMSH", (*it)->name))
|
||||||
{
|
readMesh(dataDestination, (*it)->position);
|
||||||
fsMesh.seekg((*it)->position);
|
|
||||||
// cloth tirangles
|
|
||||||
// long int (4) number of points
|
|
||||||
// long int[3][] (16 each) triangle points defined CCW
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "shader.hpp"
|
#include "shader.hpp"
|
||||||
#include "import.h"
|
#include "import.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
#include "Object.h"
|
||||||
|
|
||||||
#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr"
|
#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr"
|
||||||
#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr"
|
#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr"
|
||||||
|
@ -280,8 +281,21 @@ void OpenGLController::loadMsh(const char * path)
|
||||||
gluiSamplerID = glGetUniformLocation(gluiShaderPrgmID, "textureSampler");
|
gluiSamplerID = glGetUniformLocation(gluiShaderPrgmID, "textureSampler");
|
||||||
|
|
||||||
// get data
|
// get data
|
||||||
vfVertices = loadData();
|
try
|
||||||
vfUV = loadUV();
|
{
|
||||||
|
Object obj(path);
|
||||||
|
vfVertices = obj.getVertex();
|
||||||
|
|
||||||
|
vfUV = obj.getUV();
|
||||||
|
}
|
||||||
|
catch (std::invalid_argument e)
|
||||||
|
{
|
||||||
|
MessageBox(NULL, e.what(), "MeshViewer 2.0 Error", MB_OK | MB_ICONERROR);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//vfVertices = loadData();
|
||||||
|
//vfUV = loadUV();
|
||||||
|
|
||||||
glGenTextures(1, &gluiTextureID);
|
glGenTextures(1, &gluiTextureID);
|
||||||
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
|
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
|
||||||
|
|
|
@ -28,7 +28,7 @@ openGL:
|
||||||
|
|
||||||
OpenGLController *scene = OpenGLController::getInstance();
|
OpenGLController *scene = OpenGLController::getInstance();
|
||||||
|
|
||||||
scene->loadMsh("test.msh");
|
scene->loadMsh("..\\Release\\Msh\\cube.msh");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
scene->updateScene();
|
scene->updateScene();
|
||||||
|
|
Loading…
Reference in New Issue