Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
Unterteilungsalgorithmen
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kai Westerkamp
Unterteilungsalgorithmen
Commits
abf7bef2
Commit
abf7bef2
authored
Jun 15, 2016
by
Alisa Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
started precomputation of subdiv table
parent
0c6f77a7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
16 deletions
+103
-16
mainwidget.cpp
QTProject/mainwidget.cpp
+2
-1
mesh.cpp
QTProject/mesh.cpp
+38
-11
mesh.h
QTProject/mesh.h
+15
-4
subdivision.cpp
QTProject/subdivision.cpp
+48
-0
No files found.
QTProject/mainwidget.cpp
View file @
abf7bef2
...
...
@@ -107,7 +107,8 @@ void MainWidget::initializeGL(){
// Shader
subdevisionShader
=
initShaderProgram
();
loadNewMesh
(
"../Models/demon_head.3ds"
);
//loadNewMesh( "../Models/demon_head.3ds");
loadNewMesh
(
"../Models/box.obj"
);
}
void
MainWidget
::
loadNewMesh
(){
...
...
QTProject/mesh.cpp
View file @
abf7bef2
...
...
@@ -5,8 +5,8 @@ Mesh::MeshEntry::MeshEntry()
{
materialIndex
=
0xFFFFFFFF
;
numIndex
=
0
;
VB
=
0xFFFFFFFF
;
IB
=
0xFFFFFFFF
;
VB
_handle
=
0xFFFFFFFF
;
IB
_handle
=
0xFFFFFFFF
;
double
amax
=
std
::
numeric_limits
<
float
>::
max
();
min
=
QVector3D
(
amax
,
amax
,
amax
);
max
=
QVector3D
(
-
amax
,
-
amax
,
-
amax
);
...
...
@@ -17,14 +17,17 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
this
->
f
=
f
;
numIndex
=
Indices
.
size
();
f
->
glGenBuffers
(
1
,
&
VB
);
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
VB
);
f
->
glGenBuffers
(
1
,
&
VB
_handle
);
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
VB
_handle
);
f
->
glBufferData
(
GL_ARRAY_BUFFER
,
sizeof
(
Vertex
)
*
Vertices
.
size
(),
&
Vertices
[
0
],
GL_STATIC_DRAW
);
f
->
glGenBuffers
(
1
,
&
IB
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
IB
);
f
->
glGenBuffers
(
1
,
&
IB
_handle
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
IB
_handle
);
f
->
glBufferData
(
GL_ELEMENT_ARRAY_BUFFER
,
sizeof
(
unsigned
int
)
*
numIndex
,
&
Indices
[
0
],
GL_STATIC_DRAW
);
indices
=
Indices
;
vertices
=
Vertices
;
//calc AABB
for
(
int
i
=
0
;
i
<
Vertices
.
size
();
++
i
)
{
Vertex
v
=
Vertices
[
i
];
...
...
@@ -40,8 +43,8 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
Mesh
::
MeshEntry
::~
MeshEntry
()
{
f
->
glDeleteBuffers
(
1
,
&
VB
);
f
->
glDeleteBuffers
(
1
,
&
IB
);
f
->
glDeleteBuffers
(
1
,
&
VB
_handle
);
f
->
glDeleteBuffers
(
1
,
&
IB
_handle
);
}
Mesh
::
MaterialInfo
::
MaterialInfo
()
...
...
@@ -62,6 +65,19 @@ Mesh::Node::Node()
children
.
clear
();
}
bool
Mesh
::
Node
::
getFirstMeshIndex
(
int
&
index
){
if
(
meshes
.
length
()
>
0
){
index
=
meshes
[
0
];
return
true
;
}
for
(
int
i
=
0
;
i
<
children
.
length
();
i
++
){
if
(
children
[
i
].
getFirstMeshIndex
(
index
)){
return
true
;
}
}
return
false
;
}
Mesh
::
Mesh
(
QOpenGLFunctions_4_3_Core
*
f
,
QString
fileName
)
{
loaded
=
false
;
...
...
@@ -161,12 +177,23 @@ Mesh::~Mesh()
materials
.
clear
();
}
Mesh
::
Node
Mesh
::
getRootNode
(){
return
rootNode
;
}
Mesh
::
MeshEntry
Mesh
::
getMeshEntry
(
int
index
){
return
entries
[
index
];
}
QVector
<
unsigned
int
>
Mesh
::
MeshEntry
::
getIndexBuffer
(){
return
indices
;
}
void
Mesh
::
initNode
(
const
aiScene
*
scene
,
aiNode
*
node
,
Node
&
newNode
,
QString
debugoffset
){
newNode
.
name
=
node
->
mName
.
length
!=
0
?
node
->
mName
.
C_Str
()
:
""
;
newNode
.
transformation
=
QMatrix4x4
(
node
->
mTransformation
[
0
]);
newNode
.
meshes
.
resize
(
node
->
mNumMeshes
);
bool
debug
=
false
;
if
(
debug
)
qDebug
()
<<
debugoffset
.
toStdString
().
c_str
()
<<
"NodeName"
<<
newNode
.
name
;
if
(
debug
)
qDebug
()
<<
debugoffset
.
toStdString
().
c_str
()
<<
" NumMeshes"
<<
newNode
.
meshes
.
size
();
...
...
@@ -331,12 +358,12 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index)
// Draw Vertex Array
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
entries
[
index
].
VB
);
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
entries
[
index
].
VB
_handle
);
f
->
glVertexAttribPointer
(
positionIndex
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
0
);
f
->
glVertexAttribPointer
(
normalIndex
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
(
const
GLvoid
*
)
12
);
//12
f
->
glVertexAttribPointer
(
uvIndex
,
2
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
(
const
GLvoid
*
)
24
);
// 12+12
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
entries
[
index
].
IB
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
entries
[
index
].
IB
_handle
);
f
->
glPatchParameteri
(
GL_PATCH_VERTICES
,
3
);
f
->
glDrawElements
(
GL_PATCHES
,
entries
[
index
].
numIndex
,
GL_UNSIGNED_INT
,
0
);
...
...
QTProject/mesh.h
View file @
abf7bef2
...
...
@@ -38,19 +38,22 @@ public:
void
render
(
QOpenGLShaderProgram
*
shader
,
QMatrix4x4
V
,
QMatrix4x4
P
);
const
aiScene
*
scene
;
private
:
bool
debug
=
true
;
struct
MeshEntry
{
MeshEntry
();
~
MeshEntry
();
QVector
<
unsigned
int
>
getIndexBuffer
();
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices
);
QString
name
;
GLuint
VB
;
GLuint
IB
;
GLuint
VB_handle
;
GLuint
IB_handle
;
QVector
<
unsigned
int
>
indices
;
QVector
<
Vertex
>
vertices
;
int
numIndex
;
int
materialIndex
;
...
...
@@ -78,9 +81,17 @@ private:
QMatrix4x4
transformation
;
QVector
<
int
>
meshes
;
QVector
<
Node
>
children
;
bool
getFirstMeshIndex
(
int
&
index
);
//false if no mesh entry found
};
Mesh
::
Node
getRootNode
();
Mesh
::
MeshEntry
getMeshEntry
(
int
index
);
private
:
Assimp
::
Importer
importer
;
QMatrix4x4
globalInverseTransform
;
QMatrix4x4
screenTransform
;
...
...
QTProject/subdivision.cpp
View file @
abf7bef2
...
...
@@ -16,6 +16,54 @@ Mesh *Subdivision::subdivide(Mesh *mesh) {
}
void
Subdivision
::
precomputeTables
(
Mesh
*
mesh
)
{
Mesh
::
Node
root
=
mesh
->
getRootNode
();
int
firstMeshEntryIndex
=
-
1
;
bool
meshExists
=
root
.
getFirstMeshIndex
(
firstMeshEntryIndex
);
if
(
!
meshExists
){
qDebug
()
<<
"No Mesh found. Abort subdiv table precomputation."
;
return
;
}
qDebug
()
<<
"Mesh found. Index:"
<<
firstMeshEntryIndex
;
//die drei zeilen machen das bild schwarz. wenn man davor returnt tuts.
Mesh
::
MeshEntry
firstMeshEntry
=
mesh
->
getMeshEntry
(
firstMeshEntryIndex
);
QVector
<
unsigned
int
>
ib
=
firstMeshEntry
.
getIndexBuffer
();
qDebug
()
<<
"Index Buffer: "
<<
ib
;
return
;
//todo find adjacent triangles:
/*
for (int i = 0; i < ib.length(); i+=3){
//schaue alle dreiecke an
unsigned int x, y, z;
x_index = ib[i];
y_index = ib[i+1];
z_index = ib[i+2];
//get vertices x,y,z from vertex buffer
for (int j = i+3; j < ib.length(); j+= 3){
//search all following triangles for common edge
a_index = ib[j];
b_index = ib[j+1];
c_index = in[j+2];
//get vertices for a,b,c from vertex buffer
//for xy
//for yz
//for zx
}
}
*
* */
}
void
Subdivision
::
runShader
(
Mesh
*
mesh
)
{
...
...
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