Compare commits
14 Commits
Version_0.
...
Version_1.
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e41b831047 | ||
![]() |
948578f506 | ||
![]() |
5c2f5503fc | ||
![]() |
c94a9c3462 | ||
![]() |
3be5793ffc | ||
![]() |
f5ee8a973d | ||
![]() |
8c2ca44f20 | ||
![]() |
e963b7538e | ||
![]() |
b58b7c47e5 | ||
![]() |
44e36b8b0d | ||
![]() |
1d5d20cfb8 | ||
![]() |
0bbc0da324 | ||
![]() |
552f86bf2d | ||
![]() |
a2f5324a3c |
@@ -3,9 +3,12 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QVector2D>
|
#include <QVector2D>
|
||||||
#include <QVector3D>
|
#include <QVector3D>
|
||||||
|
#include <QStringList>
|
||||||
#include <QMatrix4x4>
|
#include <QMatrix4x4>
|
||||||
#include <QQuaternion>
|
#include <QQuaternion>
|
||||||
#include <QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
|
#include <QObject>
|
||||||
|
#include <..\Header\MainWindow.h>
|
||||||
|
|
||||||
|
|
||||||
struct BoundingBox {
|
struct BoundingBox {
|
||||||
@@ -18,6 +21,7 @@ struct VertexData
|
|||||||
{
|
{
|
||||||
QVector3D position;
|
QVector3D position;
|
||||||
QVector2D texCoord;
|
QVector2D texCoord;
|
||||||
|
QVector3D normal;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Segment {
|
struct Segment {
|
||||||
@@ -34,18 +38,27 @@ struct Model {
|
|||||||
std::vector<Segment*> segmList;
|
std::vector<Segment*> segmList;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileInterface
|
class FileInterface : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FileInterface(const char* path)
|
explicit FileInterface(QString path, QObject *parent)
|
||||||
: m_models(new QVector<Model*>)
|
: QObject(parent)
|
||||||
, m_textureNames(new QVector<std::string>)
|
, m_models(new QVector<Model*>)
|
||||||
|
, m_textureNames(new QStringList)
|
||||||
{
|
{
|
||||||
//open file
|
//open file
|
||||||
m_file.open(path, std::ios::in | std::ios::binary);
|
m_file.open(path.toStdString().c_str(), std::ios::in | std::ios::binary);
|
||||||
|
|
||||||
if (!m_file.is_open())
|
if (!m_file.is_open())
|
||||||
throw std::invalid_argument(std::string("file not found: ") += path);
|
throw std::invalid_argument(std::string("ERROR: file not found: ") += path.toStdString());
|
||||||
|
|
||||||
|
MainWindow* tmp = dynamic_cast<MainWindow*>(parent->parent()->parent());
|
||||||
|
if(tmp != NULL)
|
||||||
|
connect(this, SIGNAL(sendMessage(QString, int)), tmp, SLOT(printMessage(QString, int)));
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~FileInterface()
|
virtual ~FileInterface()
|
||||||
@@ -76,13 +89,16 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
QVector<Model*>* m_models;
|
QVector<Model*>* m_models;
|
||||||
std::fstream m_file;
|
std::fstream m_file;
|
||||||
QVector<std::string>* m_textureNames;
|
QStringList* m_textureNames;
|
||||||
BoundingBox m_sceneBbox;
|
BoundingBox m_sceneBbox;
|
||||||
|
|
||||||
virtual void import() = 0;
|
virtual void import() = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual QVector<Model*>* getModels() const { return m_models; };
|
virtual QVector<Model*>* getModels() const { return m_models; };
|
||||||
virtual QVector<std::string>* getTextureNames() const { return m_textureNames; };
|
virtual QStringList* getTextureNames() const { return m_textureNames; };
|
||||||
virtual BoundingBox getBoundingBox() const { return m_sceneBbox; };
|
virtual BoundingBox getBoundingBox() const { return m_sceneBbox; };
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sendMessage(QString msg, int severity);
|
||||||
};
|
};
|
@@ -19,7 +19,7 @@ class GeometryEngine : public QObject, protected QOpenGLFunctions
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GeometryEngine();
|
GeometryEngine(QObject *parent = Q_NULLPTR);
|
||||||
virtual ~GeometryEngine();
|
virtual ~GeometryEngine();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -29,15 +29,17 @@ private:
|
|||||||
QVector<DrawInformation> m_drawList;
|
QVector<DrawInformation> m_drawList;
|
||||||
BoundingBox m_boundings;
|
BoundingBox m_boundings;
|
||||||
|
|
||||||
void loadTexture(const char* filePath);
|
void loadTexture(QString filePath, QString fileName);
|
||||||
void clearData();
|
void clearData();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void loadFile(const char* filePath);
|
void loadFile(QString filePath);
|
||||||
void drawGeometry(QOpenGLShaderProgram *program);
|
void drawGeometry(QOpenGLShaderProgram *program);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void requestResetView();
|
void requestResetView();
|
||||||
|
void sendMessage(QString message, int severity);
|
||||||
|
void requestUpdate();
|
||||||
|
void sendFileInfo(QString name, QStringList textures, int vertices, int triangle);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QtWidgets/QMainWindow>
|
#include <QtWidgets/QMainWindow>
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QStringList>
|
||||||
#include "ui_MainWindow.h"
|
#include "ui_MainWindow.h"
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
@@ -13,12 +15,20 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindowClass* ui;
|
Ui::MainWindowClass* ui;
|
||||||
|
int m_curSeverity;
|
||||||
|
void setupWidgets();
|
||||||
|
QByteArray m_fileInfo;
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void openFile();
|
void openFile();
|
||||||
void aboutFile();
|
void aboutFile();
|
||||||
void aboutTool();
|
void aboutTool();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void printMessage(QString message, int severity);
|
||||||
|
void setFileInfo(QString name, QStringList textures, int vertices, int triangle);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void loadFile(const char*);
|
void loadFile(QString);
|
||||||
};
|
};
|
||||||
|
@@ -20,7 +20,7 @@ enum ModelTyp {
|
|||||||
class MshFile : public FileInterface
|
class MshFile : public FileInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit MshFile(const char* path);
|
explicit MshFile(QString path, QObject *parent = Q_NULLPTR);
|
||||||
virtual ~MshFile();
|
virtual ~MshFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -22,7 +22,7 @@ public:
|
|||||||
~OglViewerWidget();
|
~OglViewerWidget();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void loadFile(const char*);
|
void loadFile(QString);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct {
|
struct {
|
||||||
@@ -31,6 +31,12 @@ private:
|
|||||||
QVector2D position;
|
QVector2D position;
|
||||||
} m_mouse;
|
} m_mouse;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
bool x = true;
|
||||||
|
bool y = true;
|
||||||
|
bool z = true;
|
||||||
|
} m_rotDirections;
|
||||||
|
|
||||||
QOpenGLShaderProgram m_program;
|
QOpenGLShaderProgram m_program;
|
||||||
GeometryEngine *m_dataEngine;
|
GeometryEngine *m_dataEngine;
|
||||||
|
|
||||||
@@ -53,8 +59,12 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void initShaders();
|
void initShaders();
|
||||||
|
void setConnections();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void resetView();
|
void resetView();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void changeDirection(int direction);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
140
QtMeshViewer/Header/tga.h
Normal file
140
QtMeshViewer/Header/tga.h
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <fstream>
|
||||||
|
#include <QImage>
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
QImage loadTga(QString filePath, bool &success)
|
||||||
|
{
|
||||||
|
QImage img;
|
||||||
|
if (!img.load(filePath))
|
||||||
|
{
|
||||||
|
|
||||||
|
// open the file
|
||||||
|
std::fstream fsPicture(filePath.toStdString().c_str(), std::ios::in | std::ios::binary);
|
||||||
|
|
||||||
|
if (!fsPicture.is_open())
|
||||||
|
{
|
||||||
|
img = QImage(1, 1, QImage::Format_RGB32);
|
||||||
|
img.fill(Qt::red);
|
||||||
|
success = false;
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read in the header
|
||||||
|
std::uint8_t ui8x18Header[19] = { 0 };
|
||||||
|
fsPicture.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header) - 1);
|
||||||
|
|
||||||
|
//get variables
|
||||||
|
std::uint32_t ui32BpP;
|
||||||
|
std::uint32_t ui32Width;
|
||||||
|
std::uint32_t ui32Height;
|
||||||
|
std::uint32_t ui32IDLength;
|
||||||
|
std::uint32_t ui32PicType;
|
||||||
|
std::uint32_t ui32PaletteLength;
|
||||||
|
std::uint32_t ui32Size;
|
||||||
|
|
||||||
|
// extract all information from header
|
||||||
|
ui32IDLength = ui8x18Header[0];
|
||||||
|
ui32PicType = ui8x18Header[2];
|
||||||
|
ui32PaletteLength = ui8x18Header[6] * 0x100 + ui8x18Header[5];
|
||||||
|
ui32Width = ui8x18Header[13] * 0x100 + ui8x18Header[12];
|
||||||
|
ui32Height = ui8x18Header[15] * 0x100 + ui8x18Header[14];
|
||||||
|
ui32BpP = ui8x18Header[16];
|
||||||
|
|
||||||
|
// calculate some more information
|
||||||
|
ui32Size = ui32Width * ui32Height * ui32BpP / 8;
|
||||||
|
|
||||||
|
// jump to the data block
|
||||||
|
fsPicture.seekg(ui32IDLength + ui32PaletteLength, std::ios_base::cur);
|
||||||
|
|
||||||
|
img = QImage(ui32Width, ui32Height, ui32BpP == 32? QImage::Format_RGBA8888 : QImage::Format_RGB888);
|
||||||
|
|
||||||
|
// uncompressed
|
||||||
|
if (ui32PicType == 2 && (ui32BpP == 24 || ui32BpP == 32))
|
||||||
|
{
|
||||||
|
std::vector<std::uint8_t> vui8Pixels;
|
||||||
|
vui8Pixels.resize(ui32Size);
|
||||||
|
fsPicture.read(reinterpret_cast<char*>(vui8Pixels.data()), ui32Size);
|
||||||
|
|
||||||
|
for (unsigned int y = 0; y < ui32Height; y++)
|
||||||
|
{
|
||||||
|
for (unsigned int x = 0; x < ui32Width; x++)
|
||||||
|
{
|
||||||
|
int valr = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8 + 2);
|
||||||
|
int valg = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8 + 1);
|
||||||
|
int valb = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8);
|
||||||
|
|
||||||
|
QColor value(valr, valg, valb);
|
||||||
|
img.setPixelColor(x, ui32Width - 1 - y, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// else if compressed 24 or 32 bit
|
||||||
|
else if (ui32PicType == 10 && (ui32BpP == 24 || ui32BpP == 32)) // compressed
|
||||||
|
{
|
||||||
|
std::uint8_t tempChunkHeader;
|
||||||
|
std::uint8_t tempData[5];
|
||||||
|
unsigned int tmp_pixelIndex = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
fsPicture.read(reinterpret_cast<char*>(&tempChunkHeader), sizeof(tempChunkHeader));
|
||||||
|
|
||||||
|
if (tempChunkHeader >> 7) // repeat count
|
||||||
|
{
|
||||||
|
// just use the first 7 bits
|
||||||
|
tempChunkHeader = (uint8_t(tempChunkHeader << 1) >> 1);
|
||||||
|
|
||||||
|
fsPicture.read(reinterpret_cast<char*>(&tempData), ui32BpP / 8);
|
||||||
|
|
||||||
|
for (int i = 0; i <= tempChunkHeader; i++)
|
||||||
|
{
|
||||||
|
QColor color;
|
||||||
|
|
||||||
|
if (ui32BpP == 32)
|
||||||
|
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], tempData[3]));
|
||||||
|
else
|
||||||
|
color.setRgb(qRgb(tempData[2], tempData[1], tempData[0]));
|
||||||
|
|
||||||
|
img.setPixelColor(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color);
|
||||||
|
tmp_pixelIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // data count
|
||||||
|
{
|
||||||
|
// just use the first 7 bits
|
||||||
|
tempChunkHeader = (uint8_t(tempChunkHeader << 1) >> 1);
|
||||||
|
|
||||||
|
for (int i = 0; i <= tempChunkHeader; i++)
|
||||||
|
{
|
||||||
|
fsPicture.read(reinterpret_cast<char*>(&tempData), ui32BpP / 8);
|
||||||
|
|
||||||
|
QColor color;
|
||||||
|
|
||||||
|
if (ui32BpP == 32)
|
||||||
|
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], tempData[3]));
|
||||||
|
else
|
||||||
|
color.setRgb(qRgb(tempData[2], tempData[1], tempData[0]));
|
||||||
|
|
||||||
|
img.setPixelColor(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color);
|
||||||
|
tmp_pixelIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (tmp_pixelIndex < (ui32Width * ui32Height));
|
||||||
|
}
|
||||||
|
// not useable format
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fsPicture.close();
|
||||||
|
img = QImage(1, 1, QImage::Format_RGB32);
|
||||||
|
img.fill(Qt::red);
|
||||||
|
success = false;
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
fsPicture.close();
|
||||||
|
}
|
||||||
|
success = true;
|
||||||
|
return img;
|
||||||
|
}
|
@@ -4,7 +4,9 @@
|
|||||||
<file>vshader.glsl</file>
|
<file>vshader.glsl</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/images">
|
<qresource prefix="/images">
|
||||||
<file>cube.png</file>
|
|
||||||
<file>icon.ico</file>
|
<file>icon.ico</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
|
<qresource prefix="/files">
|
||||||
|
<file>about.txt</file>
|
||||||
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
21
QtMeshViewer/Resources/about.txt
Normal file
21
QtMeshViewer/Resources/about.txt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
This is a viewer for .msh files made by Anakin.
|
||||||
|
questions, bug reports, requests: http://www.gametoast.com/viewtopic.php?f=29&t=32624
|
||||||
|
source code: https://git.rwth-aachen.de/carstenf/OpenGL/tree/master/QtMeshViewer
|
||||||
|
|
||||||
|
===============================================================
|
||||||
|
Controll:
|
||||||
|
left mouse - rotate
|
||||||
|
right mouse - move
|
||||||
|
scroll - zoom
|
||||||
|
space - reset view
|
||||||
|
esc - close
|
||||||
|
|
||||||
|
using the X, Y, Z Button you can activate/deactivate the rotating directions
|
||||||
|
|
||||||
|
tipp: do round movement to rotate the object in z-direction, when all directions are acitvated
|
||||||
|
|
||||||
|
===============================================================
|
||||||
|
Credits:
|
||||||
|
ANDEWEGET
|
||||||
|
opengl.org
|
||||||
|
forum.qt.io
|
Binary file not shown.
Before Width: | Height: | Size: 30 KiB |
@@ -10,6 +10,7 @@ uniform mat4 m_matrix;
|
|||||||
|
|
||||||
attribute vec4 a_position;
|
attribute vec4 a_position;
|
||||||
attribute vec2 a_texcoord;
|
attribute vec2 a_texcoord;
|
||||||
|
attribute vec3 a_normal;
|
||||||
|
|
||||||
varying vec2 v_texcoord;
|
varying vec2 v_texcoord;
|
||||||
|
|
||||||
|
@@ -1,13 +1,18 @@
|
|||||||
#include "..\Header\GeometryEngine.h"
|
#include "..\Header\GeometryEngine.h"
|
||||||
#include "..\Header\MshFile.h"
|
#include "..\Header\MshFile.h"
|
||||||
|
#include "..\Header\OglViewerWidget.h"
|
||||||
|
#include "..\Header\MainWindow.h"
|
||||||
|
#include "..\Header\tga.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// public constructor/destructor
|
// public constructor/destructor
|
||||||
|
|
||||||
GeometryEngine::GeometryEngine()
|
GeometryEngine::GeometryEngine(QObject *parent)
|
||||||
: m_indexBuf(QOpenGLBuffer::IndexBuffer)
|
: QObject(parent)
|
||||||
|
, m_indexBuf(QOpenGLBuffer::IndexBuffer)
|
||||||
{
|
{
|
||||||
initializeOpenGLFunctions();
|
initializeOpenGLFunctions();
|
||||||
}
|
}
|
||||||
@@ -21,100 +26,23 @@ GeometryEngine::~GeometryEngine()
|
|||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// private functions
|
// private functions
|
||||||
|
|
||||||
void GeometryEngine::loadFile(const char* filePath)
|
void GeometryEngine::loadTexture(QString filePath, QString fileName)
|
||||||
{
|
{
|
||||||
// cleanup old stuff and recreate buffers
|
bool loadSuccess(false);
|
||||||
clearData();
|
|
||||||
m_arrayBuf.create();
|
|
||||||
m_indexBuf.create();
|
|
||||||
|
|
||||||
//reset view
|
|
||||||
emit requestResetView();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//TODO normalize
|
|
||||||
|
|
||||||
QVector<Model*>* models;
|
|
||||||
QVector<std::string>* textureNames;
|
|
||||||
QVector<VertexData> vertexData;
|
|
||||||
QVector<GLuint> indexData;
|
|
||||||
|
|
||||||
// open file and get the information
|
|
||||||
MshFile file(filePath);
|
|
||||||
models = file.getModels();
|
|
||||||
textureNames = file.getTextureNames();
|
|
||||||
m_boundings = file.getBoundingBox();
|
|
||||||
|
|
||||||
// collect data
|
|
||||||
unsigned int indexOffset(0);
|
|
||||||
unsigned int vertexOffset(0);
|
|
||||||
for (auto& modelIterator : *models)
|
|
||||||
{
|
|
||||||
for (auto& segmentIterator : modelIterator->segmList)
|
|
||||||
{
|
|
||||||
// get draw information
|
|
||||||
DrawInformation new_info;
|
|
||||||
new_info.offset = indexOffset;
|
|
||||||
new_info.size = segmentIterator->indices.size();
|
|
||||||
new_info.textureIndex = segmentIterator->textureIndex;
|
|
||||||
new_info.modelMatrix = modelIterator->m4x4Translation;
|
|
||||||
new_info.modelMatrix.rotate(modelIterator->quadRotation);
|
|
||||||
|
|
||||||
// add offset to indices, no need to do it for the first one (maybe it's very big)
|
|
||||||
if(vertexOffset != 0)
|
|
||||||
for (auto& it : segmentIterator->indices)
|
|
||||||
it += vertexOffset;
|
|
||||||
|
|
||||||
// save data
|
|
||||||
vertexData += segmentIterator->vertices;
|
|
||||||
indexData += segmentIterator->indices;
|
|
||||||
m_drawList.push_back(new_info);
|
|
||||||
|
|
||||||
// update offset
|
|
||||||
indexOffset += new_info.size;
|
|
||||||
vertexOffset += segmentIterator->vertices.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transfer vertex data to VBO 0
|
|
||||||
m_arrayBuf.bind();
|
|
||||||
m_arrayBuf.allocate(vertexData.data(), vertexData.size() * sizeof(VertexData));
|
|
||||||
|
|
||||||
// Transfer index data to VBO 1
|
|
||||||
m_indexBuf.bind();
|
|
||||||
m_indexBuf.allocate(indexData.data(), indexData.size() * sizeof(GLuint));
|
|
||||||
|
|
||||||
// get textures path
|
|
||||||
std::string path = filePath;
|
|
||||||
|
|
||||||
while (path.back() != '/' && path.back() != '\\')
|
|
||||||
path.pop_back();
|
|
||||||
|
|
||||||
// load the textures
|
|
||||||
for(auto& it : *textureNames)
|
|
||||||
loadTexture(std::string(path + it).c_str());
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (std::invalid_argument e)
|
|
||||||
{
|
|
||||||
//TODO: make a cool message box
|
|
||||||
auto msg = e.what();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void GeometryEngine::loadTexture(const char* filePath)
|
|
||||||
{
|
|
||||||
|
|
||||||
QImage img;
|
QImage img;
|
||||||
if (!img.load(filePath))
|
|
||||||
|
if (fileName.isEmpty())
|
||||||
{
|
{
|
||||||
|
loadSuccess = true;
|
||||||
img = QImage(1, 1, QImage::Format_RGB32);
|
img = QImage(1, 1, QImage::Format_RGB32);
|
||||||
img.fill(Qt::red);
|
img.fill(Qt::red);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
img = loadTga(filePath + "/" + fileName, loadSuccess);
|
||||||
|
|
||||||
|
if (!loadSuccess)
|
||||||
|
emit sendMessage("WARNING: texture not found or corrupted: " + QString(fileName), 1);
|
||||||
|
|
||||||
// Load image to OglTexture
|
// Load image to OglTexture
|
||||||
QOpenGLTexture* new_texture = new QOpenGLTexture(img.mirrored());
|
QOpenGLTexture* new_texture = new QOpenGLTexture(img.mirrored());
|
||||||
|
|
||||||
@@ -146,7 +74,91 @@ void GeometryEngine::clearData()
|
|||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// public functions
|
// public slots
|
||||||
|
|
||||||
|
void GeometryEngine::loadFile(QString filePath)
|
||||||
|
{
|
||||||
|
// cleanup old stuff and recreate buffers
|
||||||
|
clearData();
|
||||||
|
m_arrayBuf.create();
|
||||||
|
m_indexBuf.create();
|
||||||
|
|
||||||
|
//reset view
|
||||||
|
emit requestResetView();
|
||||||
|
emit sendMessage("loading file..", 0);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
QVector<Model*>* models;
|
||||||
|
QStringList* textureNames;
|
||||||
|
QVector<VertexData> vertexData;
|
||||||
|
QVector<GLuint> indexData;
|
||||||
|
|
||||||
|
// open file and get the information
|
||||||
|
MshFile file(filePath, this);
|
||||||
|
|
||||||
|
models = file.getModels();
|
||||||
|
textureNames = file.getTextureNames();
|
||||||
|
m_boundings = file.getBoundingBox();
|
||||||
|
|
||||||
|
// collect data
|
||||||
|
unsigned int indexOffset(0);
|
||||||
|
unsigned int vertexOffset(0);
|
||||||
|
for (auto& modelIterator : *models)
|
||||||
|
{
|
||||||
|
for (auto& segmentIterator : modelIterator->segmList)
|
||||||
|
{
|
||||||
|
// get draw information
|
||||||
|
DrawInformation new_info;
|
||||||
|
new_info.offset = indexOffset;
|
||||||
|
new_info.size = segmentIterator->indices.size();
|
||||||
|
new_info.textureIndex = segmentIterator->textureIndex;
|
||||||
|
new_info.modelMatrix = modelIterator->m4x4Translation;
|
||||||
|
new_info.modelMatrix.rotate(modelIterator->quadRotation);
|
||||||
|
|
||||||
|
// add offset to indices, no need to do it for the first one (maybe it's very big)
|
||||||
|
if (vertexOffset != 0)
|
||||||
|
for (auto& it : segmentIterator->indices)
|
||||||
|
it += vertexOffset;
|
||||||
|
|
||||||
|
// save data
|
||||||
|
vertexData += segmentIterator->vertices;
|
||||||
|
indexData += segmentIterator->indices;
|
||||||
|
m_drawList.push_back(new_info);
|
||||||
|
|
||||||
|
// update offset
|
||||||
|
indexOffset += new_info.size;
|
||||||
|
vertexOffset += segmentIterator->vertices.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transfer vertex data to VBO 0
|
||||||
|
m_arrayBuf.bind();
|
||||||
|
m_arrayBuf.allocate(vertexData.data(), vertexData.size() * sizeof(VertexData));
|
||||||
|
|
||||||
|
// Transfer index data to VBO 1
|
||||||
|
m_indexBuf.bind();
|
||||||
|
m_indexBuf.allocate(indexData.data(), indexData.size() * sizeof(GLuint));
|
||||||
|
|
||||||
|
emit sendMessage("loading textures..", 0);
|
||||||
|
|
||||||
|
// load the textures
|
||||||
|
int split = filePath.lastIndexOf(QRegExp("/|\\\\"));
|
||||||
|
for (auto& it : *textureNames)
|
||||||
|
loadTexture(filePath.left(split), it);
|
||||||
|
|
||||||
|
loadTexture("", "");
|
||||||
|
|
||||||
|
emit requestUpdate();
|
||||||
|
emit sendMessage("done..", 0);
|
||||||
|
emit sendFileInfo(filePath.right(filePath.size() - split - 1), QStringList(*textureNames), vertexData.size(), indexData.size() / 3);
|
||||||
|
}
|
||||||
|
catch (std::invalid_argument e)
|
||||||
|
{
|
||||||
|
clearData();
|
||||||
|
emit sendMessage(QString(e.what()), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
||||||
{
|
{
|
||||||
@@ -184,6 +196,14 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
|||||||
program->enableAttributeArray(texcoordLocation);
|
program->enableAttributeArray(texcoordLocation);
|
||||||
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
|
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
|
||||||
|
|
||||||
|
//Offset for normal
|
||||||
|
offset += sizeof(QVector2D);
|
||||||
|
|
||||||
|
// Tell OpenGL programmable pipeline how to locate vertex normal data
|
||||||
|
int normLocation = program->attributeLocation("a_normal");
|
||||||
|
program->enableAttributeArray(normLocation);
|
||||||
|
program->setAttributeBuffer(normLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||||
|
|
||||||
// Paint
|
// Paint
|
||||||
|
|
||||||
for (auto& it : m_drawList)
|
for (auto& it : m_drawList)
|
||||||
@@ -201,3 +221,4 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
|||||||
glDrawElements(GL_TRIANGLES, it.size, GL_UNSIGNED_INT, (void*)(it.offset * sizeof(GLuint)));
|
glDrawElements(GL_TRIANGLES, it.size, GL_UNSIGNED_INT, (void*)(it.offset * sizeof(GLuint)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,29 +3,34 @@
|
|||||||
#include <QSurfaceFormat>
|
#include <QSurfaceFormat>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QPalette>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QSignalMapper>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QSizePolicy>
|
||||||
|
#include "..\Header\FileInterface.h"
|
||||||
|
|
||||||
#define WINDOW_NAME "Mesh Viewer"
|
#define WINDOW_NAME "Mesh Viewer"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindowClass)
|
, ui(new Ui::MainWindowClass)
|
||||||
|
, m_curSeverity(0)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
setWindowTitle(WINDOW_NAME);
|
setWindowTitle(WINDOW_NAME);
|
||||||
setWindowIcon(QIcon(":/images/icon.ico"));
|
setWindowIcon(QIcon(":/images/icon.ico"));
|
||||||
|
|
||||||
ui->statusBar->showMessage("pre-alpha");
|
|
||||||
|
|
||||||
ui->mainToolBar->addAction("Open File", this, &MainWindow::openFile);
|
|
||||||
ui->mainToolBar->addAction("About File", this, &MainWindow::aboutFile);
|
|
||||||
ui->mainToolBar->addAction("Help", this, &MainWindow::aboutTool);
|
|
||||||
|
|
||||||
QSurfaceFormat format;
|
QSurfaceFormat format;
|
||||||
format.setDepthBufferSize(24);
|
format.setDepthBufferSize(24);
|
||||||
QSurfaceFormat::setDefaultFormat(format);
|
QSurfaceFormat::setDefaultFormat(format);
|
||||||
|
|
||||||
setCentralWidget(new OglViewerWidget(this));
|
setupWidgets();
|
||||||
|
|
||||||
|
ui->statusBar->showMessage("MeshViewer by Anakin", 0);
|
||||||
|
|
||||||
|
m_fileInfo += "Filename: -\nMaterials: -\nVertices: -\nTriangle: -\n<detail>No file is open";
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@@ -36,29 +41,141 @@ MainWindow::~MainWindow()
|
|||||||
void MainWindow::openFile()
|
void MainWindow::openFile()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "", "Mesh (*.msh)");
|
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "", "Mesh (*.msh)");
|
||||||
emit loadFile(fileName.toStdString().c_str());
|
if(!fileName.isEmpty())
|
||||||
|
emit loadFile(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupWidgets()
|
||||||
|
{
|
||||||
|
OglViewerWidget* viewer = new OglViewerWidget(this);
|
||||||
|
setCentralWidget(viewer);
|
||||||
|
|
||||||
|
QAction *openFile = new QAction("Open file", this);
|
||||||
|
connect(openFile, &QAction::triggered, this, &MainWindow::openFile);
|
||||||
|
ui->mainToolBar->addAction(openFile);
|
||||||
|
|
||||||
|
QSignalMapper* signalMapper = new QSignalMapper(this);
|
||||||
|
|
||||||
|
QAction *x = new QAction("X", this);
|
||||||
|
x->setCheckable(true);
|
||||||
|
x->setChecked(true);
|
||||||
|
ui->mainToolBar->addAction(x);
|
||||||
|
|
||||||
|
QAction *y = new QAction("Y", this);
|
||||||
|
y->setCheckable(true);
|
||||||
|
y->setChecked(true);
|
||||||
|
ui->mainToolBar->addAction(y);
|
||||||
|
|
||||||
|
QAction *z = new QAction("Z", this);
|
||||||
|
z->setCheckable(true);
|
||||||
|
z->setChecked(true);
|
||||||
|
ui->mainToolBar->addAction(z);
|
||||||
|
|
||||||
|
connect(x, SIGNAL(triggered()), signalMapper, SLOT(map()));
|
||||||
|
connect(y, SIGNAL(triggered()), signalMapper, SLOT(map()));
|
||||||
|
connect(z, SIGNAL(triggered()), signalMapper, SLOT(map()));
|
||||||
|
|
||||||
|
signalMapper->setMapping(x, 1);
|
||||||
|
signalMapper->setMapping(y, 2);
|
||||||
|
signalMapper->setMapping(z, 3);
|
||||||
|
|
||||||
|
connect(signalMapper, SIGNAL(mapped(int)), viewer, SLOT(changeDirection(int)));
|
||||||
|
|
||||||
|
|
||||||
|
QAction *fileInfo = new QAction("File info", this);
|
||||||
|
connect(fileInfo, &QAction::triggered, this, &MainWindow::aboutFile);
|
||||||
|
ui->mainToolBar->addAction(fileInfo);
|
||||||
|
|
||||||
|
QAction *help = new QAction("Help", this);
|
||||||
|
connect(help, &QAction::triggered, this, &MainWindow::aboutTool);
|
||||||
|
ui->mainToolBar->addAction(help);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::aboutFile()
|
void MainWindow::aboutFile()
|
||||||
{
|
{
|
||||||
QMessageBox* dialog = new QMessageBox(QMessageBox::Information,
|
QMessageBox* dialog = new QMessageBox(QMessageBox::NoIcon,
|
||||||
WINDOW_NAME,
|
WINDOW_NAME,
|
||||||
"When i find some time, i'll add some information about\nthe file in the detailed text",
|
QString(m_fileInfo.left(m_fileInfo.indexOf("<detail>"))),
|
||||||
QMessageBox::StandardButton::Close,
|
QMessageBox::StandardButton::Close,
|
||||||
this,
|
this,
|
||||||
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
||||||
dialog->setDetailedText("This is the cool detailed text\n");
|
|
||||||
|
dialog->setStyleSheet("QLabel{min-width: 200px;}");
|
||||||
|
dialog->setDetailedText(QString(m_fileInfo.right(m_fileInfo.size() - m_fileInfo.indexOf("<detail>") - 8)));
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
|
delete dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::aboutTool()
|
void MainWindow::aboutTool()
|
||||||
{
|
{
|
||||||
QMessageBox* dialog = new QMessageBox(QMessageBox::Question,
|
QFile file(":/files/about.txt");
|
||||||
|
file.open(QIODevice::ReadOnly);
|
||||||
|
QMessageBox* dialog = new QMessageBox(
|
||||||
|
QMessageBox::Question,
|
||||||
WINDOW_NAME,
|
WINDOW_NAME,
|
||||||
"This is the Pre-Alpha version of my Mesh Viewer\nCheck the detailed information",
|
QString(file.readAll()),
|
||||||
QMessageBox::StandardButton::Close,
|
QMessageBox::StandardButton::Close,
|
||||||
this,
|
this,
|
||||||
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
||||||
dialog->setDetailedText("left mouse - rotate\nright mouse - move\nscroll - zoom\nspace - reset view\nesc - close");
|
|
||||||
|
file.close();
|
||||||
|
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
|
|
||||||
|
delete dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setFileInfo(QString name, QStringList textures, int vertices, int triangle)
|
||||||
|
{
|
||||||
|
m_fileInfo = QByteArray("Filename: ");
|
||||||
|
m_fileInfo += name;
|
||||||
|
m_fileInfo += "\nMaterials: ";
|
||||||
|
m_fileInfo += QByteArray::number(textures.size());
|
||||||
|
m_fileInfo += "\nVertices: ";
|
||||||
|
m_fileInfo += QByteArray::number(vertices);
|
||||||
|
m_fileInfo += "\nTriangle: ";
|
||||||
|
m_fileInfo += QByteArray::number(triangle);
|
||||||
|
m_fileInfo += "<detail>";
|
||||||
|
|
||||||
|
int count(0);
|
||||||
|
for (auto& it : textures)
|
||||||
|
{
|
||||||
|
m_fileInfo += "Material ";
|
||||||
|
m_fileInfo += QByteArray::number(count++);
|
||||||
|
m_fileInfo += " - ";
|
||||||
|
m_fileInfo += it;
|
||||||
|
m_fileInfo += "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::printMessage(QString message, int severity)
|
||||||
|
{
|
||||||
|
if (!ui->statusBar->currentMessage().isEmpty() && severity < m_curSeverity)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_curSeverity = severity;
|
||||||
|
int time(0);
|
||||||
|
QPalette palette;
|
||||||
|
|
||||||
|
switch (severity)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
time = 3000;
|
||||||
|
palette.setColor(QPalette::WindowText, Qt::darkYellow);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
time = 3000;
|
||||||
|
palette.setColor(QPalette::WindowText, Qt::red);
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
time = 2000;
|
||||||
|
palette.setColor(QPalette::WindowText, Qt::black);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->statusBar->setPalette(palette);
|
||||||
|
ui->statusBar->showMessage(message, time);
|
||||||
}
|
}
|
@@ -1,5 +1,4 @@
|
|||||||
#include "..\Header\MshFile.h"
|
#include "..\Header\MshFile.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
// helper function to save data from file to any variable type
|
// helper function to save data from file to any variable type
|
||||||
@@ -9,8 +8,8 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// public constructor/destructor
|
// public constructor/destructor
|
||||||
|
|
||||||
MshFile::MshFile(const char * path)
|
MshFile::MshFile(QString path, QObject * parent)
|
||||||
: FileInterface(path)
|
: FileInterface(path, parent)
|
||||||
{
|
{
|
||||||
import();
|
import();
|
||||||
}
|
}
|
||||||
@@ -89,8 +88,7 @@ void MshFile::loadChunks(std::list<ChunkHeader*>& destination, std::streampos st
|
|||||||
// out of file. Maybe a size information is corrupted
|
// out of file. Maybe a size information is corrupted
|
||||||
if (!m_file.good())
|
if (!m_file.good())
|
||||||
{
|
{
|
||||||
//TODO: different way for output
|
emit sendMessage("WARNING: corrupted file. Trying to continue..", 1);
|
||||||
std::cout << "WARNING: corrupted file. Trying to continue" << std::endl;
|
|
||||||
m_file.clear();
|
m_file.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -386,15 +384,31 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list<ChunkHeader*>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// normals
|
// normals
|
||||||
/*else if (!strcmp("NRML", it->name))
|
else if (!strcmp("NRML", it->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg(it->position);
|
std::uint32_t tmp_size;
|
||||||
std::uint32_t tempSize;
|
m_file.seekg(it->position);
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
m_file.read(F2V(tmp_size), sizeof(tmp_size));
|
||||||
// List of normals
|
|
||||||
// long int - 4 - number of normal vectores stored in this list
|
if (tmp_size < new_segment->vertices.size())
|
||||||
// float[3][] - 12 each - UVW vector for each vertex
|
{
|
||||||
}*/
|
emit sendMessage("WARNING: too less normals " + QString::number(tmp_size) + " < " + QString::number(new_segment->vertices.size()), 1);
|
||||||
|
|
||||||
|
for (unsigned int i = new_segment->vertices.size(); i != tmp_size; i--)
|
||||||
|
for (unsigned int j = 0; j < 3; j++)
|
||||||
|
new_segment->vertices[i - 1].normal[j] = 0;
|
||||||
|
}
|
||||||
|
else if (tmp_size > new_segment->vertices.size())
|
||||||
|
{
|
||||||
|
emit sendMessage("WARNING: too many normals " + QString::number(tmp_size) + " > " + QString::number(new_segment->vertices.size()), 1);
|
||||||
|
tmp_size = new_segment->vertices.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < tmp_size; i++)
|
||||||
|
for (unsigned int j = 0; j < 3; j++)
|
||||||
|
m_file.read(F2V(new_segment->vertices[i].normal[j]), sizeof(float));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// uv
|
// uv
|
||||||
else if (!strcmp("UV0L", it->name))
|
else if (!strcmp("UV0L", it->name))
|
||||||
@@ -453,6 +467,8 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list<ChunkHeader*>
|
|||||||
// ..calculate the edge indices
|
// ..calculate the edge indices
|
||||||
for (int triEdge = 0; triEdge < 3; triEdge++)
|
for (int triEdge = 0; triEdge < 3; triEdge++)
|
||||||
new_segment->indices.push_back(tmp_buffer[(tri + triEdge - ((tri % 2) * (triEdge - 1) * 2))]);
|
new_segment->indices.push_back(tmp_buffer[(tri + triEdge - ((tri % 2) * (triEdge - 1) * 2))]);
|
||||||
|
|
||||||
|
tmp_buffer.remove(0, tmp_multiPolySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // if 2 high bits are set
|
} // if 2 high bits are set
|
||||||
@@ -497,21 +513,13 @@ void MshFile::analyseClthChunks(Model * dataDestination, std::list<ChunkHeader*>
|
|||||||
|
|
||||||
// search if it is already known
|
// search if it is already known
|
||||||
bool tmp_found(false);
|
bool tmp_found(false);
|
||||||
for (unsigned int i = 0; i < m_textureNames->size(); i++)
|
|
||||||
{
|
|
||||||
if (!strcmp(buffer, m_textureNames->at(i).c_str()))
|
|
||||||
{
|
|
||||||
// if found, save the index and stop searching
|
|
||||||
new_segment->textureIndex = i;
|
|
||||||
tmp_found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if it was not found add the texturename to the list
|
int index = m_textureNames->indexOf(QString::fromStdString(buffer));
|
||||||
if (!tmp_found)
|
if (index != -1)
|
||||||
|
new_segment->textureIndex = index;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
m_textureNames->push_back(std::string(buffer));
|
m_textureNames->push_back(QString::fromStdString(buffer));
|
||||||
new_segment->textureIndex = m_textureNames->size() - 1;
|
new_segment->textureIndex = m_textureNames->size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,24 +587,21 @@ void MshFile::readUV(Segment * dataDestination, std::streampos position)
|
|||||||
|
|
||||||
if (tmp_size < dataDestination->vertices.size())
|
if (tmp_size < dataDestination->vertices.size())
|
||||||
{
|
{
|
||||||
//TODO: warning
|
emit sendMessage("WARNING: too less UVs " + QString::number(tmp_size) + " < " + QString::number(dataDestination->vertices.size()),1);
|
||||||
std::cout << "WARNING: too less UVs " << tmp_size << " < " << dataDestination->vertices.size() << std::endl;
|
|
||||||
|
|
||||||
//TODO: fill backward with default UVs
|
for (unsigned int i = dataDestination->vertices.size(); i != tmp_size; i--)
|
||||||
|
for (unsigned int j = 0; j < 2; j++)
|
||||||
|
dataDestination->vertices[i - 1].texCoord[j] = 0;
|
||||||
}
|
}
|
||||||
else if (tmp_size > dataDestination->vertices.size())
|
else if (tmp_size > dataDestination->vertices.size())
|
||||||
{
|
{
|
||||||
//TODO: warning
|
emit sendMessage("WARNING: too many UVs " + QString::number(tmp_size) + " > " + QString::number(dataDestination->vertices.size()), 1);
|
||||||
std::cout << "WARNING: too many UVs " << tmp_size << " > " << dataDestination->vertices.size() << std::endl;
|
|
||||||
tmp_size = dataDestination->vertices.size();
|
tmp_size = dataDestination->vertices.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < tmp_size; i++)
|
for (unsigned int i = 0; i < tmp_size; i++)
|
||||||
{
|
|
||||||
float tmp[2];
|
|
||||||
for (unsigned int j = 0; j < 2; j++)
|
for (unsigned int j = 0; j < 2; j++)
|
||||||
m_file.read(F2V(dataDestination->vertices[i].texCoord[j]), sizeof(float));
|
m_file.read(F2V(dataDestination->vertices[i].texCoord[j]), sizeof(float));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QMatrix4x4 MshFile::getParentMatrix(std::string parent) const
|
QMatrix4x4 MshFile::getParentMatrix(std::string parent) const
|
||||||
|
@@ -66,8 +66,64 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
|
|||||||
m_mouse.position = QVector2D(e->localPos());
|
m_mouse.position = QVector2D(e->localPos());
|
||||||
|
|
||||||
// calculate the rotation axis and rotate
|
// calculate the rotation axis and rotate
|
||||||
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(diff.y(), diff.x(), 0.0).normalized(), diff.length() * 0.5) * m_rotation;
|
if (m_rotDirections.x && m_rotDirections.y && m_rotDirections.z)
|
||||||
|
{
|
||||||
|
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(diff.y(), diff.x(), 0.0).normalized(), diff.length() * 0.5) * m_rotation;
|
||||||
|
}
|
||||||
|
else if (m_rotDirections.x && m_rotDirections.y && !m_rotDirections.z)
|
||||||
|
{
|
||||||
|
|
||||||
|
float pitch, yaw, roll;
|
||||||
|
m_rotation.getEulerAngles(&pitch, &yaw, &roll);
|
||||||
|
|
||||||
|
pitch += diff.y() * 0.5;
|
||||||
|
yaw += diff.x() * 0.5;
|
||||||
|
|
||||||
|
if (pitch > 89)
|
||||||
|
pitch = 89;
|
||||||
|
else if (pitch < -89)
|
||||||
|
pitch = -89;
|
||||||
|
|
||||||
|
m_rotation = QQuaternion::fromEulerAngles(pitch, yaw, roll);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (m_rotDirections.x && !m_rotDirections.y && !m_rotDirections.z)
|
||||||
|
{
|
||||||
|
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(0.0, 1.0, 0.0).normalized(), diff.x() * 0.5) * m_rotation;
|
||||||
|
}
|
||||||
|
else if (!m_rotDirections.x && m_rotDirections.y && !m_rotDirections.z)
|
||||||
|
{
|
||||||
|
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0).normalized(), diff.y() * 0.5) * m_rotation;
|
||||||
|
}
|
||||||
|
else if (!m_rotDirections.x && !m_rotDirections.y && m_rotDirections.z)
|
||||||
|
{
|
||||||
|
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(0.0, 0.0, 1.0).normalized(), diff.x() * 0.5) * m_rotation;
|
||||||
|
}
|
||||||
|
else if (m_rotDirections.x && !m_rotDirections.y && m_rotDirections.z)
|
||||||
|
{
|
||||||
|
float pitch, yaw, roll;
|
||||||
|
m_rotation.getEulerAngles(&pitch, &yaw, &roll);
|
||||||
|
roll -= diff.y() * 0.5;
|
||||||
|
yaw += diff.x() * 0.5;
|
||||||
|
|
||||||
|
m_rotation = QQuaternion::fromEulerAngles(pitch, yaw, roll);
|
||||||
|
}
|
||||||
|
else if (!m_rotDirections.x && m_rotDirections.y && m_rotDirections.z)
|
||||||
|
{
|
||||||
|
float pitch, yaw, roll;
|
||||||
|
m_rotation.getEulerAngles(&pitch, &yaw, &roll);
|
||||||
|
pitch += diff.y() * 0.5;
|
||||||
|
roll += diff.x() * 0.5;
|
||||||
|
|
||||||
|
if (pitch > 89)
|
||||||
|
pitch = 89;
|
||||||
|
else if (pitch < -89)
|
||||||
|
pitch = -89;
|
||||||
|
|
||||||
|
m_rotation = QQuaternion::fromEulerAngles(pitch, yaw, roll);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// request an update
|
// request an update
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@@ -104,7 +160,7 @@ void OglViewerWidget::dragEnterEvent(QDragEnterEvent *e)
|
|||||||
|
|
||||||
void OglViewerWidget::dropEvent(QDropEvent * e)
|
void OglViewerWidget::dropEvent(QDropEvent * e)
|
||||||
{
|
{
|
||||||
emit loadFile(e->mimeData()->urls().first().toLocalFile().toStdString().c_str());
|
emit loadFile(e->mimeData()->urls().first().toLocalFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OglViewerWidget::keyPressEvent(QKeyEvent *e)
|
void OglViewerWidget::keyPressEvent(QKeyEvent *e)
|
||||||
@@ -133,11 +189,8 @@ void OglViewerWidget::initializeGL()
|
|||||||
// Enable back face culling
|
// Enable back face culling
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
m_dataEngine = new GeometryEngine;
|
m_dataEngine = new GeometryEngine(this);
|
||||||
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
|
setConnections();
|
||||||
connect(parentWidget(), SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
|
|
||||||
connect(this, SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OglViewerWidget::resizeGL(int w, int h)
|
void OglViewerWidget::resizeGL(int w, int h)
|
||||||
@@ -195,6 +248,17 @@ void OglViewerWidget::initShaders()
|
|||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OglViewerWidget::setConnections()
|
||||||
|
{
|
||||||
|
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
|
||||||
|
connect(parentWidget(), SIGNAL(loadFile(QString)), m_dataEngine, SLOT(loadFile(QString)));
|
||||||
|
connect(this, SIGNAL(loadFile(QString)), m_dataEngine, SLOT(loadFile(QString)));
|
||||||
|
connect(m_dataEngine, SIGNAL(sendMessage(QString, int)), parentWidget(), SLOT(printMessage(QString, int)));
|
||||||
|
connect(m_dataEngine, SIGNAL(requestUpdate()), this, SLOT(update()));
|
||||||
|
connect(m_dataEngine, SIGNAL(sendFileInfo(QString, QStringList, int, int)), parentWidget(), SLOT(setFileInfo(QString, QStringList, int, int)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// private slots
|
// private slots
|
||||||
@@ -205,3 +269,23 @@ void OglViewerWidget::resetView()
|
|||||||
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
|
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// public slots
|
||||||
|
|
||||||
|
void OglViewerWidget::changeDirection(int direction)
|
||||||
|
{
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
m_rotDirections.x = !m_rotDirections.x;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
m_rotDirections.y = !m_rotDirections.y;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
m_rotDirections.z = !m_rotDirections.z;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -13,7 +13,6 @@ 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
|
||||||
- tga with RLE cannot be opend
|
|
||||||
- optional display bones, shadow, collision,...
|
- optional display bones, shadow, collision,...
|
||||||
- integrate into a software:
|
- integrate into a software:
|
||||||
-> list all msh under a directory,
|
-> list all msh under a directory,
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 256 KiB After Width: | Height: | Size: 173 KiB |
Binary file not shown.
BIN
Release/msvcp140.dll
Normal file
BIN
Release/msvcp140.dll
Normal file
Binary file not shown.
BIN
Release/platforms/qwindows.dll
Normal file
BIN
Release/platforms/qwindows.dll
Normal file
Binary file not shown.
Reference in New Issue
Block a user