Compare commits
38 Commits
Version_0.
...
Version_0.
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1918d5c844 | ||
![]() |
3118118953 | ||
![]() |
9b3d12dfeb | ||
![]() |
a47eefe92e | ||
![]() |
1c0ed61b34 | ||
![]() |
ef2c341a1a | ||
![]() |
5ab2f2eaf9 | ||
![]() |
5c5b9ac2f1 | ||
![]() |
e1e8e165fe | ||
![]() |
97a38d5260 | ||
![]() |
23ce58291e | ||
![]() |
232acedce7 | ||
![]() |
60cc7bb562 | ||
![]() |
9abd285239 | ||
![]() |
bcdc17c362 | ||
![]() |
b3a8b4bb81 | ||
![]() |
f81f03353d | ||
![]() |
9ac1a25954 | ||
![]() |
57df0a2e15 | ||
![]() |
927ce1cd0a | ||
![]() |
f4d8018f8f | ||
![]() |
806024f4f9 | ||
![]() |
0f379ba04a | ||
![]() |
8929717c9f | ||
![]() |
bbe657d030 | ||
![]() |
1ab385475b | ||
![]() |
9298d88260 | ||
![]() |
91b65bf6e3 | ||
![]() |
b4bd314450 | ||
![]() |
2524971d19 | ||
![]() |
15743e11fa | ||
![]() |
6107b648f9 | ||
![]() |
ee8989b098 | ||
![]() |
2f83d37e12 | ||
![]() |
b4b2538ea6 | ||
![]() |
e5490b9451 | ||
![]() |
9c7691df85 | ||
![]() |
0fd3a7f9c8 |
@@ -3,7 +3,6 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <gl\glew.h>
|
|
||||||
#include <glm\gtc\matrix_transform.hpp>
|
#include <glm\gtc\matrix_transform.hpp>
|
||||||
|
|
||||||
enum Mtyp {
|
enum Mtyp {
|
||||||
@@ -15,34 +14,32 @@ enum Mtyp {
|
|||||||
shadowMesh = 6
|
shadowMesh = 6
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Bbox {
|
||||||
|
float quaternion[4];
|
||||||
|
float center[3];
|
||||||
|
float extents[3];
|
||||||
|
};
|
||||||
|
|
||||||
struct ChunkHeader {
|
struct ChunkHeader {
|
||||||
char name[5];
|
char name[5];
|
||||||
std::uint32_t size;
|
std::uint32_t size;
|
||||||
std::streampos position;
|
std::streampos position;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Segment {
|
||||||
|
std::uint32_t textureIndex = 0;
|
||||||
|
float* vertex = nullptr;
|
||||||
|
float* uv = nullptr;
|
||||||
|
std::vector<std::vector<std::uint32_t>> meshIndices; // indices into vertex array
|
||||||
|
};
|
||||||
|
|
||||||
struct Modl {
|
struct Modl {
|
||||||
std::string name;
|
std::string name = "";
|
||||||
std::string parent;
|
std::string parent = "";
|
||||||
Mtyp type;
|
Mtyp type = null;
|
||||||
std::uint32_t renderFlags;
|
std::int32_t renderFlags = -1;
|
||||||
glm::mat4 m4x4Translation;
|
glm::mat4 m4x4Translation = glm::mat4(1.0f);
|
||||||
struct {
|
std::vector<Segment*> segmLst;
|
||||||
float scale[3];
|
|
||||||
float rotation[4];
|
|
||||||
float translation[3];
|
|
||||||
} tran;
|
|
||||||
struct {
|
|
||||||
std::uint32_t type;
|
|
||||||
float data1;
|
|
||||||
float data2;
|
|
||||||
float data3;
|
|
||||||
} swci;
|
|
||||||
std::string texture;
|
|
||||||
float* vertex;
|
|
||||||
float* uv;
|
|
||||||
std::uint32_t* mesh;
|
|
||||||
std::uint32_t meshSize;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -54,13 +51,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<Modl*> vModls;
|
std::vector<Modl*>* vModls;
|
||||||
std::fstream fsMesh;
|
std::fstream fsMesh;
|
||||||
std::vector<std::string> vTextures;
|
std::vector<std::string> vTextures;
|
||||||
|
Bbox boundingBox;
|
||||||
|
|
||||||
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 analyseMsh2Chunks(std::list<ChunkHeader*> &chunkList);
|
void analyseMsh2Chunks(std::list<ChunkHeader*> &chunkList);
|
||||||
void analyseMatdChunks(std::list<ChunkHeader*> &chunkList);
|
void analyseMatdChunks(std::list<ChunkHeader*> &chunkList);
|
||||||
@@ -68,11 +64,12 @@ private:
|
|||||||
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 readVertex(Segment* dataDestination, std::streampos position);
|
||||||
void readUV(Modl* dataDestination, std::streampos position);
|
void readUV(Segment* dataDestination, std::streampos position);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<Modl*> getModels() const;
|
std::vector<Modl*>* getModels() const;
|
||||||
|
std::vector<std::string> getTextureList() const;
|
||||||
|
Bbox getBoundgBox() const;
|
||||||
};
|
};
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
|
||||||
#include <gl\glew.h>
|
#include <gl\glew.h>
|
||||||
#include <gl\glfw3.h>
|
#include <gl\glfw3.h>
|
||||||
#include <glm\glm.hpp>
|
|
||||||
#include <vector>
|
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
#define VERTEX_INDEX_XYZ 0
|
#define VERTEX_INDEX_XYZ 0
|
||||||
#define VERTEX_INDEX_UV 1
|
#define VERTEX_INDEX_UV 1
|
||||||
@@ -23,6 +22,13 @@ struct Vertex {
|
|||||||
GLfloat uv[2];
|
GLfloat uv[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct textureData {
|
||||||
|
bool alpha;
|
||||||
|
std::uint32_t width;
|
||||||
|
std::uint32_t height;
|
||||||
|
std::vector<std::uint8_t>* data;
|
||||||
|
};
|
||||||
|
|
||||||
class OpenGLController
|
class OpenGLController
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -64,7 +70,9 @@ private:
|
|||||||
// ========================================
|
// ========================================
|
||||||
|
|
||||||
// data
|
// data
|
||||||
std::vector<Modl*> vModels;
|
std::vector<Modl*>* vModels = NULL;
|
||||||
|
std::vector<textureData*> vTextures;
|
||||||
|
Bbox sceneBoundingBox;
|
||||||
|
|
||||||
// transformation =========================
|
// transformation =========================
|
||||||
//values
|
//values
|
||||||
@@ -73,7 +81,7 @@ private:
|
|||||||
float fRotationZ = 0;
|
float fRotationZ = 0;
|
||||||
double dTranslationX = 0;
|
double dTranslationX = 0;
|
||||||
double dTranslationY = 0;
|
double dTranslationY = 0;
|
||||||
double dTranslationZ = 5;
|
double dTranslationZ = 3;
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
|
|
||||||
@@ -87,12 +95,14 @@ private:
|
|||||||
// private functions
|
// private functions
|
||||||
private:
|
private:
|
||||||
void processInit();
|
void processInit();
|
||||||
|
void deleteVectors();
|
||||||
|
|
||||||
void startGLFW();
|
void startGLFW();
|
||||||
void createWindow();
|
void createWindow();
|
||||||
void startGLEW();
|
void startGLEW();
|
||||||
void setCallbackFunctions();
|
void setCallbackFunctions();
|
||||||
|
|
||||||
|
glm::mat4 getModelMatrix(unsigned int index);
|
||||||
glm::mat4 getMVPMatrix(unsigned int index);
|
glm::mat4 getMVPMatrix(unsigned int index);
|
||||||
|
|
||||||
|
|
||||||
@@ -107,6 +117,7 @@ public:
|
|||||||
void addTransX(double value);
|
void addTransX(double value);
|
||||||
void addTransY(double value);
|
void addTransY(double value);
|
||||||
void addTransZ(double value);
|
void addTransZ(double value);
|
||||||
|
void resetView();
|
||||||
|
|
||||||
// main routine
|
// main routine
|
||||||
GLFWwindow* getWindow() const;
|
GLFWwindow* getWindow() const;
|
||||||
|
@@ -9,22 +9,13 @@ public:
|
|||||||
~TextureTGA();
|
~TextureTGA();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::uint8_t> vui8Pixels;
|
std::vector<std::uint8_t>* vui8Pixels;
|
||||||
bool bCompressed;
|
std::uint32_t ui32BpP;
|
||||||
std::uint32_t ui32IDLength;
|
|
||||||
bool bColorTabel;
|
|
||||||
std::uint32_t ui32PicType;
|
|
||||||
std::uint32_t ui32PaletteBegin;
|
|
||||||
std::uint32_t ui32PaletteLength;
|
|
||||||
std::uint32_t ui32PaletteBpP;
|
|
||||||
std::uint32_t ui32Width;
|
std::uint32_t ui32Width;
|
||||||
std::uint32_t ui32Height;
|
std::uint32_t ui32Height;
|
||||||
std::uint32_t ui32Size;
|
|
||||||
std::uint32_t ui32BpP;
|
|
||||||
std::uint32_t ui32Attribut;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<std::uint8_t> getData() const;
|
std::vector<std::uint8_t>* getData() const;
|
||||||
bool hasAlpha() const;
|
bool hasAlpha() const;
|
||||||
std::uint32_t getWidth() const;
|
std::uint32_t getWidth() const;
|
||||||
std::uint32_t getHeight() const;
|
std::uint32_t getHeight() const;
|
||||||
|
@@ -8,4 +8,6 @@ extern void mouseMove(GLFWwindow *window, double xpos, double ypos);
|
|||||||
|
|
||||||
extern void mouseWheel(GLFWwindow *window, double xoffset, double yoffset);
|
extern void mouseWheel(GLFWwindow *window, double xoffset, double yoffset);
|
||||||
|
|
||||||
extern void keyPress(GLFWwindow *window, int key, int scancode, int action, int mods);
|
extern void keyPress(GLFWwindow *window, int key, int scancode, int action, int mods);
|
||||||
|
|
||||||
|
extern void dragNdrop(GLFWwindow* window, int count, const char** paths);
|
@@ -1,5 +1,7 @@
|
|||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
#define PI (4.0*atan(1.0))
|
#define PI (4.0*atan(1.0))
|
||||||
|
|
||||||
|
|
||||||
@@ -8,6 +10,8 @@
|
|||||||
|
|
||||||
Object::Object(const char* path)
|
Object::Object(const char* path)
|
||||||
{
|
{
|
||||||
|
vModls = new std::vector<Modl*>;
|
||||||
|
|
||||||
// open file
|
// open file
|
||||||
fsMesh.open(path, std::ios::in | std::ios::binary);
|
fsMesh.open(path, std::ios::in | std::ios::binary);
|
||||||
|
|
||||||
@@ -63,43 +67,12 @@ Object::~Object()
|
|||||||
{
|
{
|
||||||
// clear texture list
|
// clear texture list
|
||||||
vTextures.clear();
|
vTextures.clear();
|
||||||
|
|
||||||
// clear Model list (don't delete the elements)
|
|
||||||
vModls.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// private functions
|
// private functions
|
||||||
|
|
||||||
void Object::setModlDefault(Modl * model)
|
|
||||||
{
|
|
||||||
model->name = "";
|
|
||||||
model->parent = "";
|
|
||||||
model->type = null;
|
|
||||||
model->renderFlags = -1;
|
|
||||||
model->m4x4Translation = glm::mat4(1.0f);
|
|
||||||
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;
|
|
||||||
model->meshSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
@@ -134,28 +107,59 @@ void Object::loadChunks(std::list<ChunkHeader*>& destination, std::streampos sta
|
|||||||
|
|
||||||
void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
||||||
{
|
{
|
||||||
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
for (auto& it : chunkList)
|
||||||
{
|
{
|
||||||
if (!strcmp("MATL", (*it)->name))
|
if (!strcmp("SINF", it->name))
|
||||||
|
{
|
||||||
|
std::list<ChunkHeader*> tempSinfChunks;
|
||||||
|
loadChunks(tempSinfChunks, it->position, it->size);
|
||||||
|
|
||||||
|
// evaluate MATL subchunks
|
||||||
|
for (auto& it : tempSinfChunks)
|
||||||
|
{
|
||||||
|
if (!strcmp("BBOX", it->name))
|
||||||
|
{
|
||||||
|
fsMesh.seekg(it->position);
|
||||||
|
|
||||||
|
// read in the quaternion
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
fsMesh.read(reinterpret_cast<char*>(&boundingBox.quaternion[i]), sizeof(float));
|
||||||
|
|
||||||
|
//read in the center
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
fsMesh.read(reinterpret_cast<char*>(&boundingBox.center[i]), sizeof(float));
|
||||||
|
|
||||||
|
//read in the extents
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
fsMesh.read(reinterpret_cast<char*>(&boundingBox.extents[i]), sizeof(float));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ChunkHeader* it : tempSinfChunks)
|
||||||
|
delete it;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (!strcmp("MATL", it->name))
|
||||||
{
|
{
|
||||||
// "useless" information how many MATD follow
|
// "useless" information how many MATD follow
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg(it->position);
|
||||||
std::uint32_t tempMatdCount;
|
fsMesh.seekg(sizeof(std::uint32_t), std::ios_base::cur);
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempMatdCount), sizeof(std::uint32_t));
|
|
||||||
|
|
||||||
// get all MATD from MATL list
|
// get all MATD from MATL list
|
||||||
std::list<ChunkHeader*> tempMatlChunks;
|
std::list<ChunkHeader*> tempMatlChunks;
|
||||||
loadChunks(tempMatlChunks, fsMesh.tellg(), (*it)->size - 4);
|
loadChunks(tempMatlChunks, fsMesh.tellg(), it->size - 4);
|
||||||
|
|
||||||
// evaluate MATL subchunks
|
// evaluate MATL subchunks
|
||||||
for (std::list<ChunkHeader*>::iterator it = tempMatlChunks.begin(); it != tempMatlChunks.end(); it++)
|
for (auto& it : tempMatlChunks)
|
||||||
{
|
{
|
||||||
// This shouldn't be anything else than MATD
|
// This shouldn't be anything else than MATD
|
||||||
if (!strcmp("MATD", (*it)->name))
|
if (!strcmp("MATD", it->name))
|
||||||
{
|
{
|
||||||
// get all subchunks from MATD
|
// get all subchunks from MATD
|
||||||
std::list<ChunkHeader*> tempMatdChunks;
|
std::list<ChunkHeader*> tempMatdChunks;
|
||||||
loadChunks(tempMatdChunks, (*it)->position, (*it)->size);
|
loadChunks(tempMatdChunks, it->position, it->size);
|
||||||
|
|
||||||
|
vTextures.push_back("");
|
||||||
|
|
||||||
// analyse MATD subchunks
|
// analyse MATD subchunks
|
||||||
analyseMatdChunks(tempMatdChunks);
|
analyseMatdChunks(tempMatdChunks);
|
||||||
@@ -177,18 +181,15 @@ void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
|||||||
tempMatlChunks.pop_front();
|
tempMatlChunks.pop_front();
|
||||||
delete tempCursor;
|
delete tempCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("MODL", (*it)->name))
|
else if (!strcmp("MODL", it->name))
|
||||||
{
|
{
|
||||||
Modl* tempModl = new Modl;
|
Modl* tempModl = new Modl;
|
||||||
setModlDefault(tempModl);
|
|
||||||
|
|
||||||
// get all subchunks
|
// get all subchunks
|
||||||
std::list<ChunkHeader*> tempChunks;
|
std::list<ChunkHeader*> tempChunks;
|
||||||
loadChunks(tempChunks, (*it)->position, (*it)->size);
|
loadChunks(tempChunks, it->position, it->size);
|
||||||
|
|
||||||
// evaluate MODL subchunks
|
// evaluate MODL subchunks
|
||||||
analyseModlChunks(tempModl, tempChunks);
|
analyseModlChunks(tempModl, tempChunks);
|
||||||
@@ -202,81 +203,75 @@ void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save Model data
|
// save Model data
|
||||||
vModls.push_back(tempModl);
|
vModls->push_back(tempModl);
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
void Object::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
||||||
{
|
{
|
||||||
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
for (auto& it : chunkList)
|
||||||
{
|
{
|
||||||
//TX1D, TX2D, TX3D
|
//TX1D, TX2D, TX3D
|
||||||
if (!strcmp("TX0D", (*it)->name))
|
if (!strcmp("TX0D", it->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg(it->position);
|
||||||
char* buffer = new char[(*it)->size + 1];
|
char* buffer = new char[it->size + 1];
|
||||||
*buffer = { 0 };
|
*buffer = { 0 };
|
||||||
fsMesh.read(buffer, (*it)->size);
|
fsMesh.read(buffer, it->size);
|
||||||
vTextures.push_back(buffer);
|
vTextures.back() = buffer;
|
||||||
delete buffer;
|
delete[] buffer;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& chunkList)
|
void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& chunkList)
|
||||||
{
|
{
|
||||||
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
for (auto& it : chunkList)
|
||||||
{
|
{
|
||||||
if (!strcmp("MTYP", (*it)->name))
|
if (!strcmp("MTYP", it->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg(it->position);
|
||||||
std::uint32_t tempType;
|
std::uint32_t tempType;
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempType), sizeof(tempType));
|
fsMesh.read(reinterpret_cast<char*>(&tempType), sizeof(tempType));
|
||||||
dataDestination->type = (Mtyp)tempType;
|
dataDestination->type = (Mtyp)tempType;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("PRNT", (*it)->name))
|
else if (!strcmp("PRNT", it->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg(it->position);
|
||||||
char* buffer = new char[(*it)->size];
|
char* buffer = new char[it->size];
|
||||||
*buffer = { 0 };
|
*buffer = { 0 };
|
||||||
fsMesh.read(buffer, (*it)->size);
|
fsMesh.read(buffer, it->size);
|
||||||
dataDestination->parent = buffer;
|
dataDestination->parent = buffer;
|
||||||
delete buffer;
|
delete[] buffer;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("NAME", (*it)->name))
|
else if (!strcmp("NAME", it->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg(it->position);
|
||||||
char* buffer = new char[(*it)->size];
|
char* buffer = new char[it->size];
|
||||||
*buffer = { 0 };
|
*buffer = { 0 };
|
||||||
fsMesh.read(buffer, (*it)->size);
|
fsMesh.read(buffer, it->size);
|
||||||
dataDestination->name = buffer;
|
dataDestination->name = buffer;
|
||||||
delete buffer;
|
delete[] buffer;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("FLGS", (*it)->name))
|
else if (!strcmp("FLGS", it->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg(it->position);
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->renderFlags), sizeof(dataDestination->renderFlags));
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->renderFlags), sizeof(dataDestination->renderFlags));
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("TRAN", (*it)->name))
|
else if (!strcmp("TRAN", it->name))
|
||||||
{
|
{
|
||||||
float tempScale[3];
|
float tempScale[3];
|
||||||
float tempRotation[4];
|
float tempRotation[4];
|
||||||
float tempTrans[3];
|
float tempTrans[3];
|
||||||
|
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg(it->position);
|
||||||
|
|
||||||
|
//TODO: use loop
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempScale[0]), sizeof(float));
|
fsMesh.read(reinterpret_cast<char*>(&tempScale[0]), sizeof(float));
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempScale[1]), 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*>(&tempScale[2]), sizeof(float));
|
||||||
@@ -286,6 +281,7 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
|
|||||||
fsMesh.read(reinterpret_cast<char*>(&tempRotation[2]), sizeof(float));
|
fsMesh.read(reinterpret_cast<char*>(&tempRotation[2]), sizeof(float));
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempRotation[3]), sizeof(float));
|
fsMesh.read(reinterpret_cast<char*>(&tempRotation[3]), sizeof(float));
|
||||||
|
|
||||||
|
//TODO: make a function for this
|
||||||
//calculate x,y,z rotation
|
//calculate x,y,z rotation
|
||||||
tempRotation[0] = atan2(2 * (tempRotation[0] * tempRotation[1] + tempRotation[2] * tempRotation[3]),
|
tempRotation[0] = atan2(2 * (tempRotation[0] * tempRotation[1] + tempRotation[2] * tempRotation[3]),
|
||||||
1 - 2 * (pow(tempRotation[1], 2) + pow(tempRotation[2], 2)));
|
1 - 2 * (pow(tempRotation[1], 2) + pow(tempRotation[2], 2)));
|
||||||
@@ -325,14 +321,13 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
|
|||||||
glm::vec3(0, 0, 1)
|
glm::vec3(0, 0, 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("GEOM", (*it)->name))
|
else if (!strcmp("GEOM", it->name))
|
||||||
{
|
{
|
||||||
// get all subchunks
|
// get all subchunks
|
||||||
std::list<ChunkHeader*> tempGeomChunks;
|
std::list<ChunkHeader*> tempGeomChunks;
|
||||||
loadChunks(tempGeomChunks, (*it)->position, (*it)->size);
|
loadChunks(tempGeomChunks, it->position, it->size);
|
||||||
|
|
||||||
// evaluate GEOM subchunks
|
// evaluate GEOM subchunks
|
||||||
analyseGeomChunks(dataDestination, tempGeomChunks);
|
analyseGeomChunks(dataDestination, tempGeomChunks);
|
||||||
@@ -344,31 +339,19 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
|
|||||||
tempGeomChunks.pop_front();
|
tempGeomChunks.pop_front();
|
||||||
delete tempCursor;
|
delete tempCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::analyseGeomChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
|
void Object::analyseGeomChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
|
||||||
{
|
{
|
||||||
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
for (auto& it : chunkList)
|
||||||
{
|
{
|
||||||
if (!strcmp("SEGM", (*it)->name))
|
if (!strcmp("SEGM", it->name))
|
||||||
{
|
{
|
||||||
// get all subchunks
|
// get all subchunks
|
||||||
std::list<ChunkHeader*> tempSegmChunks;
|
std::list<ChunkHeader*> tempSegmChunks;
|
||||||
loadChunks(tempSegmChunks, (*it)->position, (*it)->size);
|
loadChunks(tempSegmChunks, it->position, it->size);
|
||||||
|
|
||||||
// evaluate SEGM subchunks
|
// evaluate SEGM subchunks
|
||||||
analyseSegmChunks(dataDestination, tempSegmChunks);
|
analyseSegmChunks(dataDestination, tempSegmChunks);
|
||||||
@@ -383,11 +366,11 @@ void Object::analyseGeomChunks(Modl * dataDestination, std::list<ChunkHeader*>&
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("CLTH", (*it)->name))
|
if (!strcmp("CLTH", it->name))
|
||||||
{
|
{
|
||||||
// get all subchunks
|
// get all subchunks
|
||||||
std::list<ChunkHeader*> tempClthChunks;
|
std::list<ChunkHeader*> tempClthChunks;
|
||||||
loadChunks(tempClthChunks, (*it)->position, (*it)->size);
|
loadChunks(tempClthChunks, it->position, it->size);
|
||||||
|
|
||||||
// evaluate CLTH subchunks
|
// evaluate CLTH subchunks
|
||||||
analyseClthChunks(dataDestination, tempClthChunks);
|
analyseClthChunks(dataDestination, tempClthChunks);
|
||||||
@@ -406,139 +389,177 @@ void Object::analyseGeomChunks(Modl * dataDestination, std::list<ChunkHeader*>&
|
|||||||
|
|
||||||
void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
|
void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
|
||||||
{
|
{
|
||||||
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
Segment* tempData = new Segment;
|
||||||
|
|
||||||
|
for (auto& it : chunkList)
|
||||||
{
|
{
|
||||||
/*if (!strcmp("SHDW", (*it)->name))
|
if (!strcmp("MATI", it->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg(it->position);
|
||||||
/* shadow mesh geometry
|
fsMesh.read(reinterpret_cast<char*>(&tempData->textureIndex), sizeof(tempData->textureIndex));
|
||||||
|
|
||||||
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
|
|
||||||
* /
|
|
||||||
continue;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (!strcmp("MATI", (*it)->name))
|
|
||||||
{
|
|
||||||
fsMesh.seekg((*it)->position);
|
|
||||||
std::uint32_t tempIndex;
|
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempIndex), sizeof(tempIndex));
|
|
||||||
if (vTextures.size() <= tempIndex)
|
|
||||||
{
|
|
||||||
std::cout << "warning texture index <" << tempIndex << "> unknown" << std::endl;
|
|
||||||
dataDestination->texture = "";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
dataDestination->texture = vTextures[tempIndex];
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("POSL", (*it)->name))
|
else if (!strcmp("POSL", it->name))
|
||||||
{
|
{
|
||||||
readVertex(dataDestination, (*it)->position);
|
readVertex(tempData, it->position);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if (!strcmp("NRML", (*it)->name))
|
/*else if (!strcmp("NRML", it->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg(it->position);
|
||||||
|
std::uint32_t tempSize;
|
||||||
|
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
||||||
// List of normals
|
// List of normals
|
||||||
// long int - 4 - number of normal vectores stored in this list
|
// long int - 4 - number of normal vectores stored in this list
|
||||||
// float[3][] - 12 each - UVW vector for each vertex
|
// float[3][] - 12 each - UVW vector for each vertex
|
||||||
continue;
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (!strcmp("UV0L", (*it)->name))
|
else if (!strcmp("UV0L", it->name))
|
||||||
{
|
{
|
||||||
readUV(dataDestination, (*it)->position);
|
readUV(tempData, it->position);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("STRP", (*it)->name))
|
else if (!strcmp("STRP", it->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
// don't get null, bone, shadowMesh and hidden mesh indices
|
||||||
|
if (dataDestination->type == null ||
|
||||||
|
dataDestination->type == bone ||
|
||||||
|
dataDestination->type == shadowMesh ||
|
||||||
|
dataDestination->renderFlags == 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
fsMesh.seekg((*it)->position);
|
// jump to the data section and read the size;
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->meshSize), sizeof(dataDestination->meshSize));
|
std::uint32_t tempSize;
|
||||||
|
fsMesh.seekg(it->position);
|
||||||
|
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
||||||
|
|
||||||
dataDestination->mesh = new std::uint32_t[dataDestination->meshSize];
|
int highBitCount(0);
|
||||||
|
std::vector<uint32_t> tempPoly; // = new std::vector<uint32_t>;
|
||||||
for (unsigned int i = 0; i < dataDestination->meshSize; i += 3)
|
|
||||||
|
for (unsigned int i = 0; i < tempSize; i++)
|
||||||
{
|
{
|
||||||
std::uint16_t tempValue[3];
|
// ReadData
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempValue[0]), sizeof(std::uint16_t));
|
std::uint16_t tempValue;
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempValue[1]), sizeof(std::uint16_t));
|
fsMesh.read(reinterpret_cast<char*>(&tempValue), 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)))
|
// Check for highbit
|
||||||
throw std::invalid_argument("invalid file. go and triangulate!");
|
if (tempValue >> 15)
|
||||||
|
{
|
||||||
|
highBitCount++;
|
||||||
|
tempValue = (std::uint16_t(tempValue << 1) >> 1);
|
||||||
|
}
|
||||||
|
|
||||||
tempValue[0] = (std::uint16_t(tempValue[0] << 1) >> 1);
|
tempPoly.push_back((std::uint32_t)tempValue);
|
||||||
tempValue[1] = (std::uint16_t(tempValue[1] << 1) >> 1);
|
|
||||||
|
|
||||||
dataDestination->mesh[i] = (std::uint32_t)tempValue[0];
|
// new Polygon found
|
||||||
dataDestination->mesh[i + 1] = (std::uint32_t)tempValue[1];
|
if (highBitCount == 2)
|
||||||
dataDestination->mesh[i + 2] = (std::uint32_t)tempValue[2];
|
{
|
||||||
}
|
// reset highBitCount
|
||||||
|
highBitCount = 0;
|
||||||
|
|
||||||
continue;
|
// remove the last two values..
|
||||||
|
std::uint32_t saveData[2];
|
||||||
|
for (int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
saveData[i] = tempPoly.back();
|
||||||
|
tempPoly.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ..and save them in the new vector
|
||||||
|
tempData->meshIndices.push_back(tempPoly);
|
||||||
|
|
||||||
|
tempPoly.clear();
|
||||||
|
for (int i = 1; i >= 0; i--)
|
||||||
|
tempPoly.push_back(saveData[i]);
|
||||||
|
|
||||||
|
} // if high bit set
|
||||||
|
|
||||||
|
} // for all values
|
||||||
|
|
||||||
|
// save the last values (where no 2 high bits follow);
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dataDestination->segmLst.push_back(tempData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
|
void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
|
||||||
{
|
{
|
||||||
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
Segment* tempData = new Segment;
|
||||||
|
|
||||||
|
for (auto& it : chunkList)
|
||||||
{
|
{
|
||||||
if (!strcmp("CTEX", (*it)->name))
|
if (!strcmp("CTEX", it->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg(it->position);
|
||||||
char* buffer = new char[(*it)->size];
|
char* buffer = new char[it->size];
|
||||||
*buffer = { 0 };
|
*buffer = { 0 };
|
||||||
fsMesh.read(buffer, (*it)->size);
|
fsMesh.read(buffer, it->size);
|
||||||
dataDestination->texture = buffer;
|
|
||||||
delete buffer;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcmp("CPOS", (*it)->name))
|
bool tempFound(false);
|
||||||
{
|
|
||||||
readVertex(dataDestination, (*it)->position);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcmp("CUV0", (*it)->name))
|
for (unsigned int index = 0; index < vTextures.size(); index++)
|
||||||
{
|
|
||||||
readUV(dataDestination, (*it)->position);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcmp("CMSH", (*it)->name))
|
|
||||||
{
|
|
||||||
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));
|
if (!strcmp(buffer, vTextures[index].c_str()))
|
||||||
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));
|
tempData->textureIndex = index;
|
||||||
|
tempFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tempFound)
|
||||||
|
{
|
||||||
|
vTextures.push_back(std::string(buffer));
|
||||||
|
tempData->textureIndex = vTextures.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (!strcmp("CPOS", it->name))
|
||||||
|
{
|
||||||
|
readVertex(tempData, it->position);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (!strcmp("CUV0", it->name))
|
||||||
|
{
|
||||||
|
readUV(tempData, it->position);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (!strcmp("CMSH", it->name))
|
||||||
|
{
|
||||||
|
// jump to the data section and read the size;
|
||||||
|
std::uint32_t tempSize;
|
||||||
|
fsMesh.seekg(it->position);
|
||||||
|
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
||||||
|
|
||||||
|
std::vector<uint32_t> tempPoly;
|
||||||
|
|
||||||
|
// for every triangle..
|
||||||
|
for (unsigned int i = 0; i < tempSize; i += 3)
|
||||||
|
{
|
||||||
|
tempPoly.clear();
|
||||||
|
|
||||||
|
// ..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);
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dataDestination->segmLst.push_back(tempData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::readVertex(Modl* dataDestination, std::streampos position)
|
void Object::readVertex(Segment* dataDestination, std::streampos position)
|
||||||
{
|
{
|
||||||
std::uint32_t tempSize;
|
std::uint32_t tempSize;
|
||||||
fsMesh.seekg(position);
|
fsMesh.seekg(position);
|
||||||
@@ -550,7 +571,7 @@ void Object::readVertex(Modl* dataDestination, std::streampos position)
|
|||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i]), sizeof(float));
|
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i]), sizeof(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::readUV(Modl* dataDestination, std::streampos position)
|
void Object::readUV(Segment* dataDestination, std::streampos position)
|
||||||
{
|
{
|
||||||
std::uint32_t tempSize;
|
std::uint32_t tempSize;
|
||||||
fsMesh.seekg(position);
|
fsMesh.seekg(position);
|
||||||
@@ -566,11 +587,21 @@ void Object::readUV(Modl* dataDestination, std::streampos position)
|
|||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// public getter
|
// public getter
|
||||||
|
|
||||||
std::vector<Modl*> Object::getModels() const
|
std::vector<Modl*>* Object::getModels() const
|
||||||
{
|
{
|
||||||
return vModls;
|
return vModls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Object::getTextureList() const
|
||||||
|
{
|
||||||
|
return vTextures;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bbox Object::getBoundgBox() const
|
||||||
|
{
|
||||||
|
return boundingBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// public functions
|
// public functions
|
||||||
|
@@ -1,17 +1,14 @@
|
|||||||
#include <gl\glew.h>
|
|
||||||
#include <gl\glfw3.h>
|
|
||||||
#include <Windows.h>
|
|
||||||
#include "OpenGLController.h"
|
#include "OpenGLController.h"
|
||||||
#include "callback.h"
|
#include "callback.h"
|
||||||
|
|
||||||
#include <glm\gtc\matrix_transform.hpp>
|
|
||||||
#include "shader.hpp"
|
#include "shader.hpp"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include <iostream>
|
#include <Windows.h>
|
||||||
|
#include <string>
|
||||||
|
#include <glm\gtc\matrix_transform.hpp>
|
||||||
|
|
||||||
|
|
||||||
#define VERTEX_SHADER "Shader/TextureShader.vert"
|
#define VERTEX_SHADER "Shader/TextureShader.vert"
|
||||||
#define FRAGMENT_SHADER "Shader/TextureShader.frag"
|
#define FRAGMENT_SHADER "Shader/TextureShader.frag"
|
||||||
#define MAX_MODEL_COUNT 1000
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// public constructor/destructor
|
// public constructor/destructor
|
||||||
@@ -31,16 +28,7 @@ OpenGLController::~OpenGLController()
|
|||||||
glDeleteTextures(1, &gluiSamplerID);
|
glDeleteTextures(1, &gluiSamplerID);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
while (!vModels.empty())
|
deleteVectors();
|
||||||
{
|
|
||||||
Modl* cursor = vModels.back();
|
|
||||||
vModels.pop_back();
|
|
||||||
|
|
||||||
delete cursor->uv;
|
|
||||||
delete cursor->mesh;
|
|
||||||
delete cursor->vertex;
|
|
||||||
delete cursor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -104,8 +92,63 @@ void OpenGLController::processInit()
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get some shader IDs
|
||||||
gluiMatrixID = glGetUniformLocation(gluiShaderPrgmID, "MVP");
|
gluiMatrixID = glGetUniformLocation(gluiShaderPrgmID, "MVP");
|
||||||
gluiSamplerID = glGetUniformLocation(gluiShaderPrgmID, "textureSampler");
|
gluiSamplerID = glGetUniformLocation(gluiShaderPrgmID, "textureSampler");
|
||||||
|
|
||||||
|
// generate texture
|
||||||
|
glGenTextures(1, &gluiTextureID);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
|
||||||
|
|
||||||
|
// set some texture parameters
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLController::deleteVectors()
|
||||||
|
{
|
||||||
|
//TODO: does .clear() work, too??
|
||||||
|
if (vModels != NULL)
|
||||||
|
{
|
||||||
|
while (!vModels->empty())
|
||||||
|
{
|
||||||
|
Modl* cursor = vModels->back();
|
||||||
|
vModels->pop_back();
|
||||||
|
|
||||||
|
while (!cursor->segmLst.empty())
|
||||||
|
{
|
||||||
|
Segment* segmCuror = cursor->segmLst.back();
|
||||||
|
cursor->segmLst.pop_back();
|
||||||
|
|
||||||
|
delete[] segmCuror->uv;
|
||||||
|
delete[] segmCuror->vertex;
|
||||||
|
|
||||||
|
while (!segmCuror->meshIndices.empty())
|
||||||
|
{
|
||||||
|
while (!segmCuror->meshIndices.back().empty())
|
||||||
|
segmCuror->meshIndices.back().pop_back();
|
||||||
|
|
||||||
|
segmCuror->meshIndices.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete segmCuror;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete cursor;
|
||||||
|
}
|
||||||
|
delete vModels;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!vTextures.empty())
|
||||||
|
{
|
||||||
|
textureData* cursor = vTextures.back();
|
||||||
|
vTextures.pop_back();
|
||||||
|
cursor->data->clear();
|
||||||
|
delete cursor->data;
|
||||||
|
delete cursor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLController::startGLFW()
|
void OpenGLController::startGLFW()
|
||||||
@@ -163,6 +206,23 @@ void OpenGLController::setCallbackFunctions()
|
|||||||
glfwSetWindowSizeCallback(pWindow, windowResize);
|
glfwSetWindowSizeCallback(pWindow, windowResize);
|
||||||
glfwSetScrollCallback(pWindow, mouseWheel);
|
glfwSetScrollCallback(pWindow, mouseWheel);
|
||||||
glfwSetKeyCallback(pWindow, keyPress);
|
glfwSetKeyCallback(pWindow, keyPress);
|
||||||
|
glfwSetDropCallback(pWindow, dragNdrop);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 OpenGLController::getModelMatrix(unsigned int index)
|
||||||
|
{
|
||||||
|
glm::mat4 tempParentMatrix = glm::mat4(1.0f);
|
||||||
|
|
||||||
|
for (unsigned int loop = 0; loop < vModels->size(); loop++)
|
||||||
|
{
|
||||||
|
if (!strcmp(vModels->at(index)->parent.c_str(), vModels->at(loop)->name.c_str()))
|
||||||
|
{
|
||||||
|
tempParentMatrix = getModelMatrix(loop);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tempParentMatrix * vModels->at(index)->m4x4Translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
|
glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
|
||||||
@@ -177,18 +237,25 @@ glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
|
|||||||
glm::vec3(0, 1, 0)
|
glm::vec3(0, 1, 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Model
|
|
||||||
//TODO for all
|
|
||||||
glm::mat4 m4x4Model = vModels[index]->m4x4Translation;
|
|
||||||
|
|
||||||
// User controlled rotation
|
// User controlled rotation
|
||||||
glm::mat4 m4x4ModelRot = glm::mat4(1.0f);
|
glm::mat4 m4x4ModelRot = glm::mat4(1.0f);
|
||||||
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationX, glm::vec3(1, 0, 0));
|
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationX, glm::vec3(1, 0, 0));
|
||||||
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationY, glm::vec3(0, 1, 0));
|
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationY, glm::vec3(0, 1, 0));
|
||||||
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationZ, glm::vec3(0, 0, 1));
|
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationZ, glm::vec3(0, 0, 1));
|
||||||
|
|
||||||
|
// move to center
|
||||||
|
glm::mat4 m4x4ModelCenter = glm::translate(
|
||||||
|
glm::mat4(1.0f),
|
||||||
|
glm::vec3(-sceneBoundingBox.center[0], -sceneBoundingBox.center[1], -sceneBoundingBox.center[2])
|
||||||
|
);
|
||||||
|
|
||||||
|
//scale to 1
|
||||||
|
float maxExtent = max(max(sceneBoundingBox.extents[0], sceneBoundingBox.extents[1]), sceneBoundingBox.extents[2]);
|
||||||
|
glm::mat4 m4x4Normalize = glm::mat4(1.0f);
|
||||||
|
m4x4Normalize = glm::scale(m4x4Normalize, glm::vec3(1/maxExtent, 1 / maxExtent, 1 / maxExtent));
|
||||||
|
|
||||||
// Return MVP
|
// Return MVP
|
||||||
return m4x4Projection * m4x4View * m4x4ModelRot * m4x4Model;
|
return m4x4Projection * m4x4View * m4x4ModelRot * m4x4Normalize * m4x4ModelCenter * getModelMatrix(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -235,6 +302,16 @@ void OpenGLController::addTransZ(double value)
|
|||||||
dTranslationZ += value;
|
dTranslationZ += value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenGLController::resetView()
|
||||||
|
{
|
||||||
|
dTranslationX = 0;
|
||||||
|
dTranslationY = 0;
|
||||||
|
dTranslationZ = 5;
|
||||||
|
fRotationX = 0;
|
||||||
|
fRotationY = 0;
|
||||||
|
fRotationZ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void OpenGLController::updateScene()
|
void OpenGLController::updateScene()
|
||||||
{
|
{
|
||||||
// get new matrices
|
// get new matrices
|
||||||
@@ -249,108 +326,127 @@ void OpenGLController::updateScene()
|
|||||||
// tell sampler to use texture unit 0
|
// tell sampler to use texture unit 0
|
||||||
glUniform1i(gluiSamplerID, 0);
|
glUniform1i(gluiSamplerID, 0);
|
||||||
|
|
||||||
int instanceOffset(0);
|
if (vModels != NULL)
|
||||||
|
|
||||||
for (int modelIndex = 0; modelIndex < vModels.size(); modelIndex++)
|
|
||||||
{
|
{
|
||||||
glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]);
|
int instanceOffset(0);
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, instanceOffset, vModels[modelIndex]->meshSize);
|
for (unsigned int modelIndex = 0; modelIndex < vModels->size(); modelIndex++)
|
||||||
|
{
|
||||||
|
// skip null, bones, shadowMesh, hidden things (don't increase textrue index!!)
|
||||||
|
if (vModels->at(modelIndex)->type == null ||
|
||||||
|
vModels->at(modelIndex)->type == bone ||
|
||||||
|
vModels->at(modelIndex)->type == shadowMesh ||
|
||||||
|
vModels->at(modelIndex)->renderFlags == 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
instanceOffset += vModels[modelIndex]->meshSize;
|
for (auto& segIt : vModels->at(modelIndex)->segmLst)
|
||||||
|
{
|
||||||
|
// give texture to the shader
|
||||||
|
std::uint32_t tempTexIndex = segIt->textureIndex >= vTextures.size() ? vTextures.size() - 1 : segIt->textureIndex;
|
||||||
|
|
||||||
|
glTexImage2D(
|
||||||
|
GL_TEXTURE_2D,
|
||||||
|
0,
|
||||||
|
vTextures[tempTexIndex]->alpha ? GL_RGBA : GL_RGB,
|
||||||
|
vTextures[tempTexIndex]->width,
|
||||||
|
vTextures[tempTexIndex]->height,
|
||||||
|
0,
|
||||||
|
vTextures[tempTexIndex]->alpha ? GL_BGRA : GL_BGR,
|
||||||
|
GL_UNSIGNED_BYTE,
|
||||||
|
vTextures[tempTexIndex]->data->data()
|
||||||
|
);
|
||||||
|
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
// give the MVP to the shader
|
||||||
|
glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]);
|
||||||
|
|
||||||
|
// calculate the number of vertex
|
||||||
|
unsigned int vertexCount(0);
|
||||||
|
for (auto& it : segIt->meshIndices)
|
||||||
|
vertexCount += (it.size() - 2) * 3;
|
||||||
|
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLES, instanceOffset, vertexCount);
|
||||||
|
|
||||||
|
// increase the offset
|
||||||
|
instanceOffset += vertexCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSwapBuffers(pWindow);
|
glfwSwapBuffers(pWindow);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLController::loadMsh(const char * path)
|
void OpenGLController::loadMsh(const char * path)
|
||||||
{
|
{
|
||||||
// get data
|
// clean up old stuff first
|
||||||
|
deleteVectors();
|
||||||
|
|
||||||
|
std::vector<std::string> tempTexList;
|
||||||
|
|
||||||
|
// get all models
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object obj(path);
|
Object obj(path);
|
||||||
vModels = obj.getModels();
|
vModels = obj.getModels();
|
||||||
|
tempTexList = obj.getTextureList();
|
||||||
|
sceneBoundingBox = obj.getBoundgBox();
|
||||||
}
|
}
|
||||||
catch (std::invalid_argument e)
|
catch (std::invalid_argument e)
|
||||||
{
|
{
|
||||||
MessageBox(NULL, e.what(), "MeshViewer 2.0 Error", MB_OK | MB_ICONERROR);
|
MessageBox(NULL, e.what(), "MeshViewer 2.0 Error", MB_OK | MB_ICONERROR);
|
||||||
exit(1);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenTextures(1, &gluiTextureID);
|
// collect vertex data of all models
|
||||||
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
////TODO: for all
|
|
||||||
if (vModels.front()->texture == "")
|
|
||||||
throw std::invalid_argument("no texture name");
|
|
||||||
|
|
||||||
std::string tempPath = path;
|
|
||||||
|
|
||||||
while (tempPath.back() != '/' && tempPath.back() != '\\')
|
|
||||||
tempPath.pop_back();
|
|
||||||
|
|
||||||
TextureTGA tempTex(std::string(tempPath + vModels.front()->texture).c_str());
|
|
||||||
glTexImage2D(GL_TEXTURE_2D,
|
|
||||||
0,
|
|
||||||
tempTex.hasAlpha() ? GL_RGBA : GL_RGB,
|
|
||||||
tempTex.getWidth(),
|
|
||||||
tempTex.getHeight(),
|
|
||||||
0, tempTex.hasAlpha() ? GL_BGRA : GL_BGR,
|
|
||||||
GL_UNSIGNED_BYTE,
|
|
||||||
tempTex.getData().data()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch (std::invalid_argument e)
|
|
||||||
{
|
|
||||||
GLubyte solidColor[4] = { 255, 0, 0, 255};
|
|
||||||
glTexImage2D(GL_TEXTURE_2D,
|
|
||||||
0,
|
|
||||||
GL_RGBA,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
GL_RGBA,
|
|
||||||
GL_UNSIGNED_BYTE,
|
|
||||||
(const GLvoid*)solidColor
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
|
||||||
|
|
||||||
////TODO: for all
|
|
||||||
std::vector<Vertex> tempBufferData;
|
std::vector<Vertex> tempBufferData;
|
||||||
|
|
||||||
for (auto& it : vModels)
|
for (auto& modIt : *vModels) // for every model chunk
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < it->meshSize; i++)
|
for (auto& segIt : modIt->segmLst) // for every cluster
|
||||||
{
|
{
|
||||||
Vertex tempVertex;
|
for (auto& mshIt : segIt->meshIndices) // for every polygon
|
||||||
tempVertex.position[0] = (GLfloat)it->vertex[it->mesh[i] * 3];
|
|
||||||
tempVertex.position[1] = (GLfloat)it->vertex[it->mesh[i] * 3 + 1];
|
|
||||||
tempVertex.position[2] = (GLfloat)it->vertex[it->mesh[i] * 3 + 2];
|
|
||||||
|
|
||||||
if (it->uv == NULL)
|
|
||||||
{
|
{
|
||||||
tempVertex.uv[0] = 1.0;
|
if (mshIt.size() >= 3) // multipoly
|
||||||
tempVertex.uv[1] = 1.0;
|
{
|
||||||
}
|
// for every triangle of the multi polygon
|
||||||
else
|
for (unsigned int tri = 0; tri < mshIt.size() - 2; tri++)
|
||||||
{
|
{
|
||||||
tempVertex.uv[0] = (GLfloat)it->uv[it->mesh[i] * 2];
|
// for every edge of the triangle
|
||||||
tempVertex.uv[1] = (GLfloat)it->uv[it->mesh[i] * 2 + 1];
|
for (int triEdge = 0; triEdge < 3; triEdge++)
|
||||||
}
|
{
|
||||||
|
Vertex tempVertex;
|
||||||
|
// every edge has 3 coordinates
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
tempVertex.position[j] = (GLfloat)segIt->vertex[mshIt[tri + triEdge - ((tri % 2) * (triEdge - 1) * 2)] * 3 + j];
|
||||||
|
|
||||||
tempBufferData.push_back(tempVertex);
|
// and 2 UV
|
||||||
|
if (segIt->uv == NULL)
|
||||||
|
{
|
||||||
|
tempVertex.uv[0] = 1.0;
|
||||||
|
tempVertex.uv[1] = 1.0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 2; j++)
|
||||||
|
tempVertex.uv[j] = (GLfloat)segIt->uv[mshIt[tri + triEdge - ((tri % 2) * (triEdge - 1) * 2)] * 2 + j];
|
||||||
|
}
|
||||||
|
tempBufferData.push_back(tempVertex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // this shouldn't happen (polygon with less then 3 vertex)
|
||||||
|
{
|
||||||
|
deleteVectors();
|
||||||
|
MessageBox(NULL, "You have polygons with less then 3 vertices!", "MeshViewer 2.0 Error", MB_OK | MB_ICONERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fill the buffer
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, gluiVertexBufferID);
|
glBindBuffer(GL_ARRAY_BUFFER, gluiVertexBufferID);
|
||||||
glBufferData(
|
glBufferData(
|
||||||
GL_ARRAY_BUFFER,
|
GL_ARRAY_BUFFER,
|
||||||
@@ -360,4 +456,47 @@ void OpenGLController::loadMsh(const char * path)
|
|||||||
);
|
);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
|
tempBufferData.clear();
|
||||||
|
|
||||||
|
|
||||||
|
// get textures path
|
||||||
|
std::string tempPath = path;
|
||||||
|
|
||||||
|
while (tempPath.back() != '/' && tempPath.back() != '\\')
|
||||||
|
tempPath.pop_back();
|
||||||
|
|
||||||
|
// load all textures;
|
||||||
|
for (auto& texIt : tempTexList)
|
||||||
|
{
|
||||||
|
textureData* tempData = new textureData;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TextureTGA tempTex(std::string(tempPath + texIt).c_str());
|
||||||
|
|
||||||
|
tempData->alpha = tempTex.hasAlpha();
|
||||||
|
tempData->width = tempTex.getWidth();
|
||||||
|
tempData->height = tempTex.getHeight();
|
||||||
|
tempData->data = tempTex.getData();
|
||||||
|
}
|
||||||
|
catch (std::invalid_argument e)
|
||||||
|
{
|
||||||
|
tempData->alpha = true;
|
||||||
|
tempData->width = 1;
|
||||||
|
tempData->height = 1;
|
||||||
|
tempData->data = new std::vector<std::uint8_t>({ 0, 0, 255, 255 });
|
||||||
|
}
|
||||||
|
|
||||||
|
vTextures.push_back(tempData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add a solid default color at the end (maybe there is an invalid index later)
|
||||||
|
textureData* tempData = new textureData;
|
||||||
|
tempData->alpha = true;
|
||||||
|
tempData->width = 1;
|
||||||
|
tempData->height = 1;
|
||||||
|
tempData->data = new std::vector<std::uint8_t>({ 0, 0, 255, 255 });
|
||||||
|
vTextures.push_back(tempData);
|
||||||
|
|
||||||
|
tempTexList.clear();
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
TextureTGA::TextureTGA(const char * filePath)
|
TextureTGA::TextureTGA(const char * filePath)
|
||||||
{
|
{
|
||||||
@@ -15,35 +13,26 @@ TextureTGA::TextureTGA(const char * filePath)
|
|||||||
std::uint8_t ui8x18Header[19] = { 0 };
|
std::uint8_t ui8x18Header[19] = { 0 };
|
||||||
fsPicture.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header)-1);
|
fsPicture.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header)-1);
|
||||||
|
|
||||||
|
//get variables
|
||||||
|
vui8Pixels = new std::vector<std::uint8_t>;
|
||||||
|
bool bCompressed;
|
||||||
|
std::uint32_t ui32IDLength;
|
||||||
|
std::uint32_t ui32PicType;
|
||||||
|
std::uint32_t ui32PaletteLength;
|
||||||
|
std::uint32_t ui32Size;
|
||||||
|
|
||||||
// extract all information from header
|
// extract all information from header
|
||||||
ui32IDLength = ui8x18Header[0];
|
ui32IDLength = ui8x18Header[0];
|
||||||
bColorTabel = ui8x18Header[1] == 1;
|
|
||||||
ui32PicType = ui8x18Header[2];
|
ui32PicType = ui8x18Header[2];
|
||||||
ui32PaletteBegin = ui8x18Header[4] * 0x100 + ui8x18Header[3];
|
|
||||||
ui32PaletteLength = ui8x18Header[6] * 0x100 + ui8x18Header[5];
|
ui32PaletteLength = ui8x18Header[6] * 0x100 + ui8x18Header[5];
|
||||||
ui32PaletteBpP = ui8x18Header[7];
|
|
||||||
ui32Width = ui8x18Header[13] * 0x100 + ui8x18Header[12];
|
ui32Width = ui8x18Header[13] * 0x100 + ui8x18Header[12];
|
||||||
ui32Height = ui8x18Header[15] * 0x100 + ui8x18Header[14];
|
ui32Height = ui8x18Header[15] * 0x100 + ui8x18Header[14];
|
||||||
ui32BpP = ui8x18Header[16];
|
ui32BpP = ui8x18Header[16];
|
||||||
ui32Attribut = ui8x18Header[17];
|
|
||||||
|
|
||||||
// calculate some more information
|
// calculate some more information
|
||||||
ui32Size = ui32Width * ui32Height * ui32BpP/8;
|
ui32Size = ui32Width * ui32Height * ui32BpP/8;
|
||||||
bCompressed = ui32PicType == 9 || ui32PicType == 10;
|
bCompressed = ui32PicType == 9 || ui32PicType == 10;
|
||||||
vui8Pixels.resize(ui32Size);
|
vui8Pixels->resize(ui32Size);
|
||||||
|
|
||||||
/* consol output of the header
|
|
||||||
std::cout << "Header\n"
|
|
||||||
<< "ID l<>nge: " << ui32IDLength << std::endl
|
|
||||||
<< "Farbtabelle: " << (int)bColorTabel << std::endl
|
|
||||||
<< "Bildtype: " << ui32PicType << std::endl
|
|
||||||
<< "Palletenbegin: " << ui32PaletteBegin << std::endl
|
|
||||||
<< "Palletenl<6E>ngen: " << ui32PaletteLength << std::endl
|
|
||||||
<< "Bits pro Palleteneintrag: " << ui32PaletteBpP << std::endl
|
|
||||||
<< "Breite: " << ui32Width << std::endl
|
|
||||||
<< "H<>he: " << ui32Height << std::endl
|
|
||||||
<< "Bit pro Pixel: " << ui32BpP << std::endl
|
|
||||||
<< "Bild Attribute: " << ui32Attribut << std::endl;*/
|
|
||||||
|
|
||||||
// jump to the data block
|
// jump to the data block
|
||||||
fsPicture.seekg(ui32IDLength + ui32PaletteLength, std::ios_base::cur);
|
fsPicture.seekg(ui32IDLength + ui32PaletteLength, std::ios_base::cur);
|
||||||
@@ -51,15 +40,14 @@ TextureTGA::TextureTGA(const char * filePath)
|
|||||||
// If not compressed 24 or 32 bit
|
// If not compressed 24 or 32 bit
|
||||||
if (ui32PicType == 2 && (ui32BpP == 24 || ui32BpP == 32))
|
if (ui32PicType == 2 && (ui32BpP == 24 || ui32BpP == 32))
|
||||||
{
|
{
|
||||||
fsPicture.read(reinterpret_cast<char*>(vui8Pixels.data()), ui32Size);
|
fsPicture.read(reinterpret_cast<char*>(vui8Pixels->data()), ui32Size);
|
||||||
}
|
}
|
||||||
// else if compressed 24 or 32 bit
|
// else if compressed 24 or 32 bit
|
||||||
else if (ui32PicType == 10 && (ui32BpP == 24 || ui32BpP == 32)) // compressed
|
else if (ui32PicType == 10 && (ui32BpP == 24 || ui32BpP == 32)) // compressed
|
||||||
{
|
{
|
||||||
std::uint8_t tempChunkHeader;
|
std::uint8_t tempChunkHeader;
|
||||||
std::uint8_t tempData[5];
|
std::uint8_t tempData[5];
|
||||||
int tempByteIndex = 0;
|
unsigned int tempByteIndex = 0;
|
||||||
std::size_t tempPixelIndex = 0;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
fsPicture.read(reinterpret_cast<char*>(&tempChunkHeader), sizeof(tempChunkHeader));
|
fsPicture.read(reinterpret_cast<char*>(&tempChunkHeader), sizeof(tempChunkHeader));
|
||||||
@@ -73,10 +61,10 @@ TextureTGA::TextureTGA(const char * filePath)
|
|||||||
|
|
||||||
for (int i = 0; i <= tempChunkHeader; i++)
|
for (int i = 0; i <= tempChunkHeader; i++)
|
||||||
{
|
{
|
||||||
vui8Pixels[tempByteIndex++] = tempData[0];
|
vui8Pixels->at(tempByteIndex++) = tempData[0];
|
||||||
vui8Pixels[tempByteIndex++] = tempData[1];
|
vui8Pixels->at(tempByteIndex++) = tempData[1];
|
||||||
vui8Pixels[tempByteIndex++] = tempData[2];
|
vui8Pixels->at(tempByteIndex++) = tempData[2];
|
||||||
if(ui32BpP == 32) vui8Pixels[tempByteIndex++] = tempData[3];
|
if(ui32BpP == 32) vui8Pixels->at(tempByteIndex++) = tempData[3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // data count
|
else // data count
|
||||||
@@ -88,10 +76,10 @@ TextureTGA::TextureTGA(const char * filePath)
|
|||||||
{
|
{
|
||||||
fsPicture.read(reinterpret_cast<char*>(&tempData), ui32BpP/8);
|
fsPicture.read(reinterpret_cast<char*>(&tempData), ui32BpP/8);
|
||||||
|
|
||||||
vui8Pixels[tempByteIndex++] = tempData[0];
|
vui8Pixels->at(tempByteIndex++) = tempData[0];
|
||||||
vui8Pixels[tempByteIndex++] = tempData[1];
|
vui8Pixels->at(tempByteIndex++) = tempData[1];
|
||||||
vui8Pixels[tempByteIndex++] = tempData[2];
|
vui8Pixels->at(tempByteIndex++) = tempData[2];
|
||||||
if (ui32BpP == 32) vui8Pixels[tempByteIndex++] = tempData[3];
|
if (ui32BpP == 32) vui8Pixels->at(tempByteIndex++) = tempData[3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (tempByteIndex < ui32Size);
|
} while (tempByteIndex < ui32Size);
|
||||||
@@ -108,10 +96,9 @@ TextureTGA::TextureTGA(const char * filePath)
|
|||||||
|
|
||||||
TextureTGA::~TextureTGA()
|
TextureTGA::~TextureTGA()
|
||||||
{
|
{
|
||||||
vui8Pixels.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::uint8_t> TextureTGA::getData() const
|
std::vector<std::uint8_t>* TextureTGA::getData() const
|
||||||
{
|
{
|
||||||
return vui8Pixels;
|
return vui8Pixels;
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,3 @@
|
|||||||
//#include "callback.h"
|
|
||||||
#include <gl\glew.h>
|
|
||||||
#include <gl\glfw3.h>
|
|
||||||
#include "OpenGLController.h"
|
#include "OpenGLController.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -81,6 +78,8 @@ void mouseWheel(GLFWwindow *window, double xoffset, double yoffset)
|
|||||||
|
|
||||||
void keyPress(GLFWwindow *window, int key, int scancode, int action, int mods)
|
void keyPress(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
|
OpenGLController* controller = reinterpret_cast<OpenGLController*>(glfwGetWindowUserPointer(window));
|
||||||
|
|
||||||
if (action == GLFW_PRESS || action == GLFW_REPEAT)
|
if (action == GLFW_PRESS || action == GLFW_REPEAT)
|
||||||
{
|
{
|
||||||
switch (key)
|
switch (key)
|
||||||
@@ -96,8 +95,22 @@ void keyPress(GLFWwindow *window, int key, int scancode, int action, int mods)
|
|||||||
case GLFW_KEY_PLUS_GER: case GLFW_KEY_KP_ADD:
|
case GLFW_KEY_PLUS_GER: case GLFW_KEY_KP_ADD:
|
||||||
mouse.speed += 0.1;
|
mouse.speed += 0.1;
|
||||||
break;
|
break;
|
||||||
|
case GLFW_KEY_SPACE:
|
||||||
|
controller->resetView();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dragNdrop(GLFWwindow* window, int count, const char** paths)
|
||||||
|
{
|
||||||
|
OpenGLController* controller = reinterpret_cast<OpenGLController*>(glfwGetWindowUserPointer(window));
|
||||||
|
|
||||||
|
if (count < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
controller->resetView();
|
||||||
|
controller->loadMsh(paths[0]);
|
||||||
|
}
|
||||||
|
@@ -3,9 +3,6 @@
|
|||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
#include "OpenGLController.h"
|
#include "OpenGLController.h"
|
||||||
#include "Object.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@@ -20,25 +17,9 @@ int main(int argc, char** argv)
|
|||||||
else
|
else
|
||||||
scene = OpenGLController::getInstance();
|
scene = OpenGLController::getInstance();
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
goto openGL;
|
scene->loadMsh("..\\Release\\Msh\\quadPoly.msh");
|
||||||
|
#endif // DEBUG
|
||||||
try {
|
|
||||||
Object obj("..\\Release\\Msh\\cubeTex.msh");
|
|
||||||
}
|
|
||||||
catch (std::invalid_argument e)
|
|
||||||
{
|
|
||||||
std::cout << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
system("pause");
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
openGL:
|
|
||||||
|
|
||||||
scene->loadMsh("..\\Release\\Msh\\multipleModels.msh");
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
scene->updateScene();
|
scene->updateScene();
|
||||||
|
12
README.md
@@ -13,12 +13,8 @@ Feel free to use my code the way you like. But remember i used some public libra
|
|||||||
licence, too.
|
licence, too.
|
||||||
|
|
||||||
### To Do
|
### To Do
|
||||||
- draw multiple models of one mesh,
|
- cloth not working correctly
|
||||||
- crashing sometimes - no idea why,
|
- optional display bones, shadow, collision,...
|
||||||
- bones are not triangulated,
|
|
||||||
- nulls are not triangulated,
|
|
||||||
- crash when loading trooper,
|
|
||||||
- display cloth testing
|
|
||||||
- integrate into a software:
|
- integrate into a software:
|
||||||
-> gui open file ( + drag and drop),
|
-> gui open file ( + drag and drop),
|
||||||
-> list all msh under a directory,
|
-> list all msh under a directory,
|
||||||
@@ -26,6 +22,4 @@ licence, too.
|
|||||||
-> display colisions,
|
-> display colisions,
|
||||||
-> lights,
|
-> lights,
|
||||||
-> handle render flags,
|
-> handle render flags,
|
||||||
- draw more then one model,
|
|
||||||
- use different textures for one or multiple models,
|
|
||||||
- take a look at destruction
|
|
||||||
|
BIN
Release/Msh/1.tga
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/128x128Braun.tga
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/128x128Grau.tga
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/128x128Gruen.tga
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/128x128Rot.tga
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/2.tga
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/3.tga
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/4-Poly.msh
Normal file
BIN
Release/Msh/4.tga
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/5-Poly.msh
Normal file
BIN
Release/Msh/5.tga
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/6-poly.msh
Normal file
BIN
Release/Msh/6.tga
Normal file
After Width: | Height: | Size: 48 KiB |