working on changing the texture names to materials,
problems with call by value/reference
This commit is contained in:
@@ -3,11 +3,13 @@
|
||||
#include <QVector>
|
||||
#include <QVector2D>
|
||||
#include <QVector3D>
|
||||
#include <QStringList>
|
||||
#include <QMatrix4x4>
|
||||
#include <QQuaternion>
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QOpenGlTexture>
|
||||
#include <QObject>
|
||||
#include <QOpenGLTexture>
|
||||
#include <QRegExp>
|
||||
#include <..\Header\MainWindow.h>
|
||||
|
||||
|
||||
@@ -38,6 +40,12 @@ struct Model {
|
||||
std::vector<Segment*> segmList;
|
||||
};
|
||||
|
||||
struct Material {
|
||||
QString name;
|
||||
QOpenGLTexture* texture = Q_NULLPTR;
|
||||
bool transparent = false;
|
||||
};
|
||||
|
||||
class FileInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -46,7 +54,7 @@ public:
|
||||
explicit FileInterface(QString path, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_models(new QVector<Model*>)
|
||||
, m_textureNames(new QStringList)
|
||||
, m_materials(new QVector<Material>)
|
||||
{
|
||||
//open file
|
||||
m_file.open(path.toStdString().c_str(), std::ios::in | std::ios::binary);
|
||||
@@ -58,6 +66,7 @@ public:
|
||||
if(tmp != NULL)
|
||||
connect(this, SIGNAL(sendMessage(QString, int)), tmp, SLOT(printMessage(QString, int)));
|
||||
|
||||
m_filepath = path.left(path.lastIndexOf(QRegExp("/|\\\\")));
|
||||
|
||||
};
|
||||
|
||||
@@ -67,9 +76,6 @@ public:
|
||||
m_file.close();
|
||||
|
||||
//clean up
|
||||
m_textureNames->clear();
|
||||
delete m_textureNames;
|
||||
|
||||
for (Model* modelIt : *m_models)
|
||||
{
|
||||
for (Segment* segIt : modelIt->segmList)
|
||||
@@ -89,16 +95,40 @@ public:
|
||||
protected:
|
||||
QVector<Model*>* m_models;
|
||||
std::fstream m_file;
|
||||
QStringList* m_textureNames;
|
||||
QVector<Material>* m_materials;
|
||||
BoundingBox m_sceneBbox;
|
||||
QString m_filepath;
|
||||
|
||||
virtual void import() = 0;
|
||||
|
||||
public:
|
||||
virtual QVector<Model*>* getModels() const { return m_models; };
|
||||
virtual QStringList* getTextureNames() const { return m_textureNames; };
|
||||
virtual QVector<Material>* getMaterials() const { return m_materials; };
|
||||
virtual BoundingBox getBoundingBox() const { return m_sceneBbox; };
|
||||
|
||||
static Material getDefaultMaterial() {
|
||||
Material defMaterial;
|
||||
|
||||
QImage img(1, 1, QImage::Format_RGB32);
|
||||
img.fill(Qt::red);
|
||||
|
||||
QOpenGLTexture* new_texture = new QOpenGLTexture(img.mirrored());
|
||||
|
||||
// Set nearest filtering mode for texture minification
|
||||
new_texture->setMinificationFilter(QOpenGLTexture::Nearest);
|
||||
|
||||
// Set bilinear filtering mode for texture magnification
|
||||
new_texture->setMagnificationFilter(QOpenGLTexture::Linear);
|
||||
|
||||
// Wrap texture coordinates by repeating
|
||||
// f.ex. texture coordinate (1.1, 1.2) is same as (0.1, 0.2)
|
||||
new_texture->setWrapMode(QOpenGLTexture::Repeat);
|
||||
|
||||
defMaterial.texture = new_texture;
|
||||
|
||||
return defMaterial;
|
||||
};
|
||||
|
||||
signals:
|
||||
void sendMessage(QString msg, int severity);
|
||||
};
|
@@ -25,11 +25,10 @@ public:
|
||||
private:
|
||||
QOpenGLBuffer m_arrayBuf;
|
||||
QOpenGLBuffer m_indexBuf;
|
||||
QVector<QOpenGLTexture*> m_textures;
|
||||
QVector<Material>* m_materials = Q_NULLPTR;
|
||||
QVector<DrawInformation> m_drawList;
|
||||
BoundingBox m_boundings;
|
||||
|
||||
void loadTexture(QString filePath, QString fileName);
|
||||
void clearData();
|
||||
|
||||
public slots:
|
||||
@@ -40,6 +39,6 @@ signals:
|
||||
void requestResetView();
|
||||
void sendMessage(QString message, int severity);
|
||||
void requestUpdate();
|
||||
void sendFileInfo(QString name, QStringList textures, int vertices, int triangle);
|
||||
void sendFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle);
|
||||
};
|
||||
|
||||
|
@@ -5,6 +5,8 @@
|
||||
#include <QStringList>
|
||||
#include "ui_MainWindow.h"
|
||||
|
||||
struct Material;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -28,7 +30,7 @@ private:
|
||||
|
||||
public slots:
|
||||
void printMessage(QString message, int severity);
|
||||
void setFileInfo(QString name, QStringList textures, int vertices, int triangle);
|
||||
void setFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle);
|
||||
|
||||
signals:
|
||||
void loadFile(QString);
|
||||
|
@@ -43,6 +43,8 @@ private:
|
||||
void readVertex(Segment* dataDestination, std::streampos position);
|
||||
void readUV(Segment* dataDestination, std::streampos position);
|
||||
|
||||
void loadTexture(QOpenGLTexture* destination, QString filepath);
|
||||
|
||||
QMatrix4x4 getParentMatrix(std::string parent) const;
|
||||
QQuaternion getParentRotation(std::string parent) const;
|
||||
};
|
Reference in New Issue
Block a user