Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
OpenGL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
C-Fu
OpenGL
Commits
6ead5d7b
Commit
6ead5d7b
authored
Jan 15, 2017
by
Anakin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on changing the texture names to materials,
problems with call by value/reference
parent
f469dff6
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
124 additions
and
76 deletions
+124
-76
QtMeshViewer/Header/FileInterface.h
QtMeshViewer/Header/FileInterface.h
+37
-7
QtMeshViewer/Header/GeometryEngine.h
QtMeshViewer/Header/GeometryEngine.h
+2
-3
QtMeshViewer/Header/MainWindow.h
QtMeshViewer/Header/MainWindow.h
+3
-1
QtMeshViewer/Header/MshFile.h
QtMeshViewer/Header/MshFile.h
+2
-0
QtMeshViewer/Source/GeometryEngine.cpp
QtMeshViewer/Source/GeometryEngine.cpp
+15
-51
QtMeshViewer/Source/MainWindow.cpp
QtMeshViewer/Source/MainWindow.cpp
+5
-4
QtMeshViewer/Source/MshFile.cpp
QtMeshViewer/Source/MshFile.cpp
+59
-9
QtMeshViewer/Source/OglViewerWidget.cpp
QtMeshViewer/Source/OglViewerWidget.cpp
+1
-1
No files found.
QtMeshViewer/Header/FileInterface.h
View file @
6ead5d7b
...
...
@@ -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
;
Q
StringList
*
m_textureName
s
;
Q
Vector
<
Material
>*
m_material
s
;
BoundingBox
m_sceneBbox
;
QString
m_filepath
;
virtual
void
import
()
=
0
;
public:
virtual
QVector
<
Model
*>*
getModels
()
const
{
return
m_models
;
};
virtual
Q
StringList
*
getTextureNames
()
const
{
return
m_textureName
s
;
};
virtual
Q
Vector
<
Material
>*
getMaterials
()
const
{
return
m_material
s
;
};
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
);
};
\ No newline at end of file
QtMeshViewer/Header/GeometryEngine.h
View file @
6ead5d7b
...
...
@@ -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
,
Q
StringList
texture
s
,
int
vertices
,
int
triangle
);
void
sendFileInfo
(
QString
name
,
Q
Vector
<
Material
>*
material
s
,
int
vertices
,
int
triangle
);
};
QtMeshViewer/Header/MainWindow.h
View file @
6ead5d7b
...
...
@@ -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
,
Q
StringList
texture
s
,
int
vertices
,
int
triangle
);
void
setFileInfo
(
QString
name
,
Q
Vector
<
Material
>*
material
s
,
int
vertices
,
int
triangle
);
signals:
void
loadFile
(
QString
);
...
...
QtMeshViewer/Header/MshFile.h
View file @
6ead5d7b
...
...
@@ -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
;
};
\ No newline at end of file
QtMeshViewer/Source/GeometryEngine.cpp
View file @
6ead5d7b
...
...
@@ -2,7 +2,6 @@
#include "..\Header\MshFile.h"
#include "..\Header\OglViewerWidget.h"
#include "..\Header\MainWindow.h"
#include "..\Header\tga.h"
#include <cmath>
#include <QRegExp>
...
...
@@ -26,39 +25,6 @@ GeometryEngine::~GeometryEngine()
/////////////////////////////////////////////////////////////////////////
// private functions
void
GeometryEngine
::
loadTexture
(
QString
filePath
,
QString
fileName
)
{
bool
loadSuccess
(
false
);
QImage
img
;
if
(
fileName
.
isEmpty
())
{
loadSuccess
=
true
;
img
=
QImage
(
1
,
1
,
QImage
::
Format_RGB32
);
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
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
);
m_textures
.
push_back
(
new_texture
);
}
void
GeometryEngine
::
clearData
()
{
if
(
m_arrayBuf
.
isCreated
())
...
...
@@ -66,9 +32,13 @@ void GeometryEngine::clearData()
if
(
m_indexBuf
.
isCreated
())
m_indexBuf
.
destroy
();
for
(
auto
it
:
m_textures
)
delete
it
;
m_textures
.
clear
();
if
(
m_materials
!=
Q_NULLPTR
)
{
for
(
auto
it
:
*
m_materials
)
delete
it
.
texture
;
m_materials
->
clear
();
delete
m_materials
;
}
m_drawList
.
clear
();
}
...
...
@@ -90,7 +60,6 @@ void GeometryEngine::loadFile(QString filePath)
try
{
QVector
<
Model
*>*
models
;
QStringList
*
textureNames
;
QVector
<
VertexData
>
vertexData
;
QVector
<
GLuint
>
indexData
;
...
...
@@ -98,10 +67,11 @@ void GeometryEngine::loadFile(QString filePath)
MshFile
file
(
filePath
,
this
);
models
=
file
.
getModels
();
textureNames
=
file
.
getTextureName
s
();
m_materials
=
file
.
getMaterial
s
();
m_boundings
=
file
.
getBoundingBox
();
// collect data
//TODO: sort transparent faces
unsigned
int
indexOffset
(
0
);
unsigned
int
vertexOffset
(
0
);
for
(
auto
&
modelIterator
:
*
models
)
...
...
@@ -140,18 +110,12 @@ void GeometryEngine::loadFile(QString filePath)
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
(
""
,
""
);
//pushback a default material
m_materials
->
push_back
(
FileInterface
::
getDefaultMaterial
());
emit
requestUpdate
();
emit
sendMessage
(
"done.."
,
0
);
emit
sendFileInfo
(
filePath
.
right
(
filePath
.
size
()
-
split
-
1
),
QStringList
(
*
textureNames
)
,
vertexData
.
size
(),
indexData
.
size
()
/
3
);
emit
sendFileInfo
(
filePath
.
right
(
filePath
.
size
()
-
filePath
.
lastIndexOf
(
QRegExp
(
"/|
\\\\
"
))
-
1
),
m_materials
,
vertexData
.
size
(),
indexData
.
size
()
/
3
);
}
catch
(
std
::
invalid_argument
e
)
{
...
...
@@ -209,10 +173,10 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
for
(
auto
&
it
:
m_drawList
)
{
// bind the correct texture
if
(
it
.
textureIndex
<
m_
textures
.
size
())
m_
textures
.
at
(
it
.
textureIndex
)
->
bind
();
if
(
it
.
textureIndex
<
m_
materials
->
size
())
m_
materials
->
at
(
it
.
textureIndex
).
texture
->
bind
();
else
m_
textures
.
last
()
->
bind
();
m_
materials
->
last
().
texture
->
bind
();
// Set model matrix
program
->
setUniformValue
(
"m_matrix"
,
it
.
modelMatrix
);
...
...
QtMeshViewer/Source/MainWindow.cpp
View file @
6ead5d7b
...
...
@@ -143,12 +143,12 @@ void MainWindow::takeScreenShot()
viewer
->
grab
().
save
(
destination
);
}
void
MainWindow
::
setFileInfo
(
QString
name
,
Q
StringList
texture
s
,
int
vertices
,
int
triangle
)
void
MainWindow
::
setFileInfo
(
QString
name
,
Q
Vector
<
Material
>*
material
s
,
int
vertices
,
int
triangle
)
{
m_fileInfo
=
QByteArray
(
"Filename: "
);
m_fileInfo
+=
name
;
m_fileInfo
+=
"
\n
Materials: "
;
m_fileInfo
+=
QByteArray
::
number
(
textures
.
size
());
m_fileInfo
+=
QByteArray
::
number
(
materials
->
size
());
m_fileInfo
+=
"
\n
Vertices: "
;
m_fileInfo
+=
QByteArray
::
number
(
vertices
);
m_fileInfo
+=
"
\n
Triangle: "
;
...
...
@@ -156,12 +156,13 @@ void MainWindow::setFileInfo(QString name, QStringList textures, int vertices, i
m_fileInfo
+=
"<detail>"
;
int
count
(
0
);
for
(
auto
&
it
:
textures
)
//TODO: mark not opened textures
for
(
auto
&
it
:
*
materials
)
{
m_fileInfo
+=
"Material "
;
m_fileInfo
+=
QByteArray
::
number
(
count
++
);
m_fileInfo
+=
" - "
;
m_fileInfo
+=
it
;
m_fileInfo
+=
it
.
name
;
m_fileInfo
+=
"
\n
"
;
}
}
...
...
QtMeshViewer/Source/MshFile.cpp
View file @
6ead5d7b
#include "..\Header\MshFile.h"
#include "..\Header\tga.h"
// helper function to save data from file to any variable type
#define F2V(variableName) reinterpret_cast<char*>(&variableName)
...
...
@@ -160,7 +160,7 @@ void MshFile::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
std
::
list
<
ChunkHeader
*>
tmp_matdChunks
;
loadChunks
(
tmp_matdChunks
,
it
->
position
,
it
->
size
);
m_
textureNames
->
push_back
(
""
);
m_
materials
->
push_back
(
Material
()
);
// analyse MATD subchunks
analyseMatdChunks
(
tmp_matdChunks
);
...
...
@@ -218,12 +218,19 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
{
if
(
!
strcmp
(
"TX0D"
,
it
->
name
))
{
// get the texture name
m_file
.
seekg
(
it
->
position
);
char
*
buffer
=
new
char
[
it
->
size
+
1
];
*
buffer
=
{
0
};
m_file
.
read
(
buffer
,
it
->
size
);
m_
textureNames
->
back
()
=
buffer
;
m_
materials
->
back
().
name
=
buffer
;
delete
[]
buffer
;
// load the texture
if
(
m_materials
->
back
().
name
.
isEmpty
())
loadTexture
(
m_materials
->
back
().
texture
,
""
);
else
loadTexture
(
m_materials
->
back
().
texture
,
m_filepath
+
"/"
+
m_materials
->
back
().
name
);
}
}
}
...
...
@@ -514,14 +521,24 @@ void MshFile::analyseClthChunks(Model * dataDestination, std::list<ChunkHeader*>
// search if it is already known
bool
tmp_found
(
false
);
int
index
=
m_textureNames
->
indexOf
(
QString
::
fromStdString
(
buffer
));
if
(
index
!=
-
1
)
for
(
unsigned
int
index
=
0
;
index
<
m_materials
->
size
();
index
++
)
{
if
(
m_materials
->
at
(
index
).
name
==
QString
(
buffer
))
{
tmp_found
=
true
;
new_segment
->
textureIndex
=
index
;
else
break
;
}
}
if
(
!
tmp_found
)
{
m_textureNames
->
push_back
(
QString
::
fromStdString
(
buffer
));
new_segment
->
textureIndex
=
m_textureNames
->
size
()
-
1
;
m_materials
->
push_back
(
Material
());
m_materials
->
back
().
name
=
QString
(
buffer
);
//TODO: load texture;
loadTexture
(
m_materials
->
back
().
texture
,
m_filepath
+
"/"
+
m_materials
->
back
().
name
);
new_segment
->
textureIndex
=
m_materials
->
size
()
-
1
;
}
delete
[]
buffer
;
...
...
@@ -605,6 +622,39 @@ void MshFile::readUV(Segment * dataDestination, std::streampos position)
m_file
.
read
(
F2V
(
dataDestination
->
vertices
[
i
].
texCoord
[
j
]),
sizeof
(
float
));
}
void
MshFile
::
loadTexture
(
QOpenGLTexture
*
destination
,
QString
filepath
)
{
bool
loadSuccess
(
false
);
QImage
img
;
if
(
filepath
.
isEmpty
())
{
loadSuccess
=
true
;
img
=
QImage
(
1
,
1
,
QImage
::
Format_RGB32
);
img
.
fill
(
Qt
::
red
);
}
else
img
=
loadTga
(
filepath
,
loadSuccess
);
if
(
!
loadSuccess
)
emit
sendMessage
(
"WARNING: texture not found or corrupted: "
+
m_materials
->
back
().
name
,
1
);
// Load image to OglTexture
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
);
destination
=
new_texture
;
}
QMatrix4x4
MshFile
::
getParentMatrix
(
std
::
string
parent
)
const
{
QMatrix4x4
matrix
;
...
...
QtMeshViewer/Source/OglViewerWidget.cpp
View file @
6ead5d7b
...
...
@@ -259,7 +259,7 @@ void OglViewerWidget::setConnections()
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
,
Q
StringList
,
int
,
int
)),
parentWidget
(),
SLOT
(
setFileInfo
(
QString
,
QStringList
,
int
,
int
)));
connect
(
m_dataEngine
,
SIGNAL
(
sendFileInfo
(
QString
,
Q
Vector
<
Material
>*
,
int
,
int
)),
parentWidget
(),
SLOT
(
setFileInfo
(
QString
,
QVector
<
Material
>*
,
int
,
int
)));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment