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
9e817f2e
Commit
9e817f2e
authored
8 years ago
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed Animation
parent
17e76809
Pipeline
#72
skipped
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
18 additions
and
432 deletions
+18
-432
mainwidget.cpp
QTProject/mainwidget.cpp
+11
-47
mainwidget.h
QTProject/mainwidget.h
+3
-10
mainwindow.cpp
QTProject/mainwindow.cpp
+0
-17
mainwindow.h
QTProject/mainwindow.h
+0
-3
mesh.cpp
QTProject/mesh.cpp
+3
-298
mesh.h
QTProject/mesh.h
+1
-57
No files found.
QTProject/mainwidget.cpp
View file @
9e817f2e
...
@@ -6,10 +6,7 @@ MainWidget::MainWidget(Camera *cam)
...
@@ -6,10 +6,7 @@ MainWidget::MainWidget(Camera *cam)
startTime
=
QTime
::
currentTime
();
startTime
=
QTime
::
currentTime
();
rotTime
=
QTime
::
currentTime
();
rotTime
=
QTime
::
currentTime
();
linear
=
false
;
rotation
=
true
;
rotation
=
true
;
animate
=
true
;
Animation
=
0
;
}
}
QSize
MainWidget
::
minimumSizeHint
()
const
QSize
MainWidget
::
minimumSizeHint
()
const
...
@@ -96,7 +93,7 @@ QVector3D* MainWidget::trackballPoint(int x, int y){
...
@@ -96,7 +93,7 @@ QVector3D* MainWidget::trackballPoint(int x, int y){
void
MainWidget
::
initializeGL
(){
void
MainWidget
::
initializeGL
(){
bool
glFunctionsOK
=
initializeOpenGLFunctions
();
bool
glFunctionsOK
=
initializeOpenGLFunctions
();
//
Q_ASSERT(glFunctionsOK);
Q_ASSERT
(
glFunctionsOK
);
if
(
!
glFunctionsOK
){
if
(
!
glFunctionsOK
){
qDebug
()
<<
"ContextFormat"
<<
this
->
context
()
->
format
();
qDebug
()
<<
"ContextFormat"
<<
this
->
context
()
->
format
();
exit
(
4
);
exit
(
4
);
...
@@ -107,7 +104,7 @@ void MainWidget::initializeGL(){
...
@@ -107,7 +104,7 @@ void MainWidget::initializeGL(){
glDisable
(
GL_CULL_FACE
);
glDisable
(
GL_CULL_FACE
);
// Shader
// Shader
animationShader
=
initShader
(
QLatin1String
(
":/animate.frag"
),
QLatin1String
(
":/animate.vert"
)
);
subdevisionShader
=
initShader
(
);
loadNewMesh
();
loadNewMesh
();
}
}
...
@@ -122,15 +119,6 @@ void MainWidget::loadNewMesh(){
...
@@ -122,15 +119,6 @@ void MainWidget::loadNewMesh(){
qDebug
()
<<
"Opening File:"
<<
fn
;
qDebug
()
<<
"Opening File:"
<<
fn
;
Mesh
*
temp
=
new
Mesh
(
this
,
fn
);
Mesh
*
temp
=
new
Mesh
(
this
,
fn
);
mesh
=
temp
;
mesh
=
temp
;
mesh
->
setAnimation
(
linear
);
}
void
MainWidget
::
setInterpolation
(
bool
linear
){
qDebug
()
<<
"linear"
<<
linear
;
this
->
linear
=
linear
;
if
(
mesh
)
mesh
->
setAnimation
(
linear
);
}
}
void
MainWidget
::
setRotation
(
bool
started
){
void
MainWidget
::
setRotation
(
bool
started
){
...
@@ -141,28 +129,11 @@ void MainWidget::setRotation(bool started){
...
@@ -141,28 +129,11 @@ void MainWidget::setRotation(bool started){
}
}
void
MainWidget
::
setAnimating
(
bool
started
){
QOpenGLShaderProgram
*
MainWidget
::
initShader
(){
qDebug
()
<<
"animating"
<<
started
;
QString
fragSource
=
QLatin1String
(
":/animate.frag"
);
this
->
animate
=
started
;
QString
vertSource
=
QLatin1String
(
":/animate.vert"
);
if
(
started
){
startTime
=
QTime
::
currentTime
();
}
}
void
MainWidget
::
nextAnimation
(){
Animation
++
;
Animation
=
Animation
%
mesh
->
scene
->
mNumAnimations
;
startTime
=
QTime
::
currentTime
();
qDebug
()
<<
"Animation"
<<
Animation
;
}
QOpenGLShader
*
vert
=
new
QOpenGLShader
(
QOpenGLShader
::
Vertex
);
QOpenGLShaderProgram
*
MainWidget
::
initShader
(
QString
fragSource
,
QString
vertSource
){
QOpenGLShader
*
vert
=
new
QOpenGLShader
(
QOpenGLShader
::
Vertex
);
if
(
!
vert
->
compileSourceFile
(
vertSource
)){
if
(
!
vert
->
compileSourceFile
(
vertSource
)){
qCritical
()
<<
"Fragment Shader"
<<
vertSource
<<
"failed"
<<
vert
->
log
();
qCritical
()
<<
"Fragment Shader"
<<
vertSource
<<
"failed"
<<
vert
->
log
();
exit
(
5
);
exit
(
5
);
...
@@ -200,18 +171,13 @@ void MainWidget::paintGL(){
...
@@ -200,18 +171,13 @@ void MainWidget::paintGL(){
rot
.
rotate
(
time
/
100.0
*
36
/
5
,
QVector3D
(
0
,
1
,
0
));
rot
.
rotate
(
time
/
100.0
*
36
/
5
,
QVector3D
(
0
,
1
,
0
));
}
}
animat
ionShader
->
bind
();
subdevis
ionShader
->
bind
();
animat
ionShader
->
setUniformValue
(
"colorTexture"
,
0
);
subdevis
ionShader
->
setUniformValue
(
"colorTexture"
,
0
);
animat
ionShader
->
setUniformValue
(
"LightPos"
,
QVector3D
(
0
,
100
,
100
));
subdevis
ionShader
->
setUniformValue
(
"LightPos"
,
QVector3D
(
0
,
100
,
100
));
float
ftime
=
startTime
.
msecsTo
(
QTime
::
currentTime
())
/
1000.0
;
mesh
->
render
(
subdevisionShader
,
cam
->
getMatrix
()
*
rot
,
m_projection
);
if
(
!
animate
)
ftime
=
0
;
subdevisionShader
->
release
();
mesh
->
render
(
animationShader
,
cam
->
getMatrix
()
*
rot
,
m_projection
,(
float
)
ftime
,
Animation
);
animationShader
->
release
();
update
();
update
();
}
}
...
@@ -220,7 +186,5 @@ void MainWidget::resizeGL(int width, int height){
...
@@ -220,7 +186,5 @@ void MainWidget::resizeGL(int width, int height){
m_projection
=
QMatrix4x4
();
m_projection
=
QMatrix4x4
();
m_projection
.
perspective
(
45.0
f
,
1.0
*
width
/
height
,
0.01
f
,
1000.0
f
);
m_projection
.
perspective
(
45.0
f
,
1.0
*
width
/
height
,
0.01
f
,
1000.0
f
);
}
}
This diff is collapsed.
Click to expand it.
QTProject/mainwidget.h
View file @
9e817f2e
...
@@ -24,10 +24,8 @@ public:
...
@@ -24,10 +24,8 @@ public:
public
slots
:
public
slots
:
void
loadNewMesh
();
void
loadNewMesh
();
void
setInterpolation
(
bool
linear
);
void
setRotation
(
bool
started
);
void
setRotation
(
bool
started
);
void
setAnimating
(
bool
started
);
void
nextAnimation
();
protected
:
protected
:
...
@@ -46,7 +44,7 @@ private:
...
@@ -46,7 +44,7 @@ private:
Camera
*
cam
;
Camera
*
cam
;
QOpenGLShaderProgram
*
animat
ionShader
;
QOpenGLShaderProgram
*
subdevis
ionShader
;
QMatrix4x4
m_projection
;
QMatrix4x4
m_projection
;
QTime
startTime
;
QTime
startTime
;
QTime
rotTime
;
QTime
rotTime
;
...
@@ -56,16 +54,11 @@ private:
...
@@ -56,16 +54,11 @@ private:
QVector3D
*
lastSpeherePos
;
QVector3D
*
lastSpeherePos
;
QPointF
*
lastScreenPos
;
QPointF
*
lastScreenPos
;
boolean
linear
;
boolean
rotation
;
boolean
rotation
;
boolean
animate
;
int
Animation
;
Mesh
*
mesh
;
Mesh
*
mesh
;
QOpenGLShaderProgram
*
initShader
(
QString
fragSource
,
QString
vertSource
);
QOpenGLShaderProgram
*
initShader
();
};
};
#endif // MAINWIDGET_H
#endif // MAINWIDGET_H
This diff is collapsed.
Click to expand it.
QTProject/mainwindow.cpp
View file @
9e817f2e
...
@@ -16,28 +16,12 @@ MainWindow::MainWindow(QWidget *parent) :
...
@@ -16,28 +16,12 @@ MainWindow::MainWindow(QWidget *parent) :
connect
(
loadMesh
,
SIGNAL
(
triggered
()),
m_centralWidget
,
SLOT
(
loadNewMesh
()));
connect
(
loadMesh
,
SIGNAL
(
triggered
()),
m_centralWidget
,
SLOT
(
loadNewMesh
()));
toolBar
->
addAction
(
loadMesh
);
toolBar
->
addAction
(
loadMesh
);
switchInterpolation
=
new
QAction
(
"Lin Interpol"
,
this
);
switchInterpolation
->
setCheckable
(
true
);
switchInterpolation
->
setChecked
(
false
);
connect
(
switchInterpolation
,
SIGNAL
(
triggered
(
bool
)),
m_centralWidget
,
SLOT
(
setInterpolation
(
bool
)));
toolBar
->
addAction
(
switchInterpolation
);
switchRotation
=
new
QAction
(
"Rotation"
,
this
);
switchRotation
=
new
QAction
(
"Rotation"
,
this
);
switchRotation
->
setCheckable
(
true
);
switchRotation
->
setCheckable
(
true
);
switchRotation
->
setChecked
(
true
);
switchRotation
->
setChecked
(
true
);
connect
(
switchRotation
,
SIGNAL
(
triggered
(
bool
)),
m_centralWidget
,
SLOT
(
setRotation
(
bool
)));
connect
(
switchRotation
,
SIGNAL
(
triggered
(
bool
)),
m_centralWidget
,
SLOT
(
setRotation
(
bool
)));
toolBar
->
addAction
(
switchRotation
);
toolBar
->
addAction
(
switchRotation
);
stopAnimation
=
new
QAction
(
"Start/Stop"
,
this
);
stopAnimation
->
setCheckable
(
true
);
stopAnimation
->
setChecked
(
true
);
connect
(
stopAnimation
,
SIGNAL
(
triggered
(
bool
)),
m_centralWidget
,
SLOT
(
setAnimating
(
bool
)));
toolBar
->
addAction
(
stopAnimation
);
nextAnimation
=
new
QAction
(
"Next"
,
this
);
nextAnimation
->
setCheckable
(
false
);
connect
(
nextAnimation
,
SIGNAL
(
triggered
()),
m_centralWidget
,
SLOT
(
nextAnimation
()));
toolBar
->
addAction
(
nextAnimation
);
CamHome
=
new
QAction
(
"Cam"
,
this
);
CamHome
=
new
QAction
(
"Cam"
,
this
);
CamHome
->
setCheckable
(
false
);
CamHome
->
setCheckable
(
false
);
...
@@ -45,7 +29,6 @@ MainWindow::MainWindow(QWidget *parent) :
...
@@ -45,7 +29,6 @@ MainWindow::MainWindow(QWidget *parent) :
toolBar
->
addAction
(
CamHome
);
toolBar
->
addAction
(
CamHome
);
this
->
setCentralWidget
(
m_centralWidget
);
this
->
setCentralWidget
(
m_centralWidget
);
// showMaximized();
// showMaximized();
...
...
This diff is collapsed.
Click to expand it.
QTProject/mainwindow.h
View file @
9e817f2e
...
@@ -23,10 +23,7 @@ private:
...
@@ -23,10 +23,7 @@ private:
QToolBar
*
toolBar
;
QToolBar
*
toolBar
;
QAction
*
loadMesh
;
QAction
*
loadMesh
;
QAction
*
switchInterpolation
;
QAction
*
switchRotation
;
QAction
*
switchRotation
;
QAction
*
stopAnimation
;
QAction
*
nextAnimation
;
QAction
*
CamHome
;
QAction
*
CamHome
;
...
...
This diff is collapsed.
Click to expand it.
QTProject/mesh.cpp
View file @
9e817f2e
#include "mesh.h"
#include "mesh.h"
void
Vertex
::
AddBoneData
(
uint
BoneID
,
float
Weight
){
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
if
(
weights
[
i
]
==
0.0
)
{
IDs
[
i
]
=
BoneID
;
weights
[
i
]
=
Weight
;
//qDebug()<<"Add"<<i<<BoneID<<Weight<<pos;
return
;
}
}
qCritical
()
<<
"More tahn 4 Bones at Vertex"
<<
pos
<<
BoneID
<<
Weight
<<
"added:"
<<
IDs
[
0
]
<<
weights
[
0
]
<<
IDs
[
1
]
<<
weights
[
1
]
<<
IDs
[
2
]
<<
weights
[
2
]
<<
IDs
[
3
]
<<
weights
[
3
];
}
Mesh
::
MeshEntry
::
MeshEntry
()
Mesh
::
MeshEntry
::
MeshEntry
()
{
{
...
@@ -79,9 +65,8 @@ Mesh::Node::Node()
...
@@ -79,9 +65,8 @@ Mesh::Node::Node()
Mesh
::
Mesh
(
QOpenGLFunctions_4_3_Core
*
f
,
QString
fileName
)
Mesh
::
Mesh
(
QOpenGLFunctions_4_3_Core
*
f
,
QString
fileName
)
{
{
loaded
=
false
;
loaded
=
false
;
linear
=
false
;
this
->
f
=
f
;
this
->
f
=
f
;
numberOfBones
=
0
;
scene
=
NULL
;
scene
=
NULL
;
scene
=
importer
.
ReadFile
(
fileName
.
toStdString
(),
scene
=
importer
.
ReadFile
(
fileName
.
toStdString
(),
//aiProcess_CalcTangentSpace |
//aiProcess_CalcTangentSpace |
...
@@ -128,9 +113,6 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName)
...
@@ -128,9 +113,6 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName)
return
;
return
;
}
}
if
(
scene
->
HasLights
()){
qDebug
()
<<
"Ligths found"
;
}
qDebug
()
<<
"Mesh Read"
;
qDebug
()
<<
"Mesh Read"
;
//init Nodes
//init Nodes
...
@@ -186,10 +168,6 @@ void Mesh::initNode(const aiScene *scene, aiNode *node, Node &newNode,QString de
...
@@ -186,10 +168,6 @@ void Mesh::initNode(const aiScene *scene, aiNode *node, Node &newNode,QString de
newNode
.
meshes
.
resize
(
node
->
mNumMeshes
);
newNode
.
meshes
.
resize
(
node
->
mNumMeshes
);
bool
debug
=
false
;
bool
debug
=
false
;
if
(
debug
)
qDebug
()
<<
debugoffset
.
toStdString
().
c_str
()
<<
"NodeName"
<<
newNode
.
name
;
if
(
debug
)
qDebug
()
<<
debugoffset
.
toStdString
().
c_str
()
<<
"NodeName"
<<
newNode
.
name
;
if
(
boneMap
.
find
(
newNode
.
name
)
!=
boneMap
.
end
()){
if
(
debug
)
qDebug
()
<<
debugoffset
.
toStdString
().
c_str
()
<<
"hasBone"
;
}
if
(
debug
)
qDebug
()
<<
debugoffset
.
toStdString
().
c_str
()
<<
" NumMeshes"
<<
newNode
.
meshes
.
size
();
if
(
debug
)
qDebug
()
<<
debugoffset
.
toStdString
().
c_str
()
<<
" NumMeshes"
<<
newNode
.
meshes
.
size
();
for
(
uint
i
=
0
;
i
<
node
->
mNumMeshes
;
++
i
)
for
(
uint
i
=
0
;
i
<
node
->
mNumMeshes
;
++
i
)
...
@@ -288,71 +266,27 @@ void Mesh::initMeshEntry(int index, aiMesh * entry){
...
@@ -288,71 +266,27 @@ void Mesh::initMeshEntry(int index, aiMesh * entry){
qDebug
()
<<
"Loaded Mesh:"
<<
entries
[
index
].
name
<<
"HasBones:"
<<
entry
->
HasBones
();
qDebug
()
<<
"Loaded Mesh:"
<<
entries
[
index
].
name
<<
"HasBones:"
<<
entry
->
HasBones
();
if
(
entry
->
HasBones
()){
for
(
uint
i
=
0
;
i
<
entry
->
mNumBones
;
i
++
){
int
index
=
0
;
QString
BoneName
=
QString
(
entry
->
mBones
[
i
]
->
mName
.
data
);
if
(
boneMap
.
find
(
BoneName
)
==
boneMap
.
end
())
{
// Allocate an index for a new bone
index
=
numberOfBones
;
numberOfBones
++
;
BoneInfo
bi
;
bones
.
push_back
(
bi
);
bones
[
index
].
BoneOffset
=
QMatrix4x4
(
entry
->
mBones
[
i
]
->
mOffsetMatrix
[
0
]);
boneMap
[
BoneName
]
=
index
;
}
else
{
index
=
boneMap
[
BoneName
];
}
for
(
uint
j
=
0
;
j
<
entry
->
mBones
[
i
]
->
mNumWeights
;
j
++
)
{
uint
VertexID
=
entry
->
mBones
[
i
]
->
mWeights
[
j
].
mVertexId
;
float
Weight
=
entry
->
mBones
[
i
]
->
mWeights
[
j
].
mWeight
;
Vertices
[
VertexID
].
AddBoneData
(
index
,
Weight
);
}
}
}
entries
[
index
].
init
(
f
,
Vertices
,
Indices
);
entries
[
index
].
init
(
f
,
Vertices
,
Indices
);
}
}
void
Mesh
::
render
(
QOpenGLShaderProgram
*
shader
,
QMatrix4x4
V
,
QMatrix4x4
P
,
float
TimeInSeconds
,
int
animation
){
void
Mesh
::
render
(
QOpenGLShaderProgram
*
shader
,
QMatrix4x4
V
,
QMatrix4x4
P
){
if
(
!
loaded
)
if
(
!
loaded
)
return
;
return
;
if
(
f
==
NULL
){
if
(
f
==
NULL
){
qDebug
()
<<
"
f
= null"
;
qDebug
()
<<
"
OpenGL Funktions
= null"
;
return
;
return
;
}
}
f
->
glEnableVertexAttribArray
(
positionIndex
);
f
->
glEnableVertexAttribArray
(
positionIndex
);
f
->
glEnableVertexAttribArray
(
normalIndex
);
f
->
glEnableVertexAttribArray
(
normalIndex
);
f
->
glEnableVertexAttribArray
(
uvIndex
);
f
->
glEnableVertexAttribArray
(
uvIndex
);
f
->
glEnableVertexAttribArray
(
boneIndex
);
f
->
glEnableVertexAttribArray
(
boneweightIndex
);
updateBoneTransform
(
TimeInSeconds
,
animation
);
QVector
<
QMatrix4x4
>
boneTransforms
=
QVector
<
QMatrix4x4
>
(
bones
.
size
());
for
(
int
i
=
0
;
i
<
bones
.
size
();
i
++
){
boneTransforms
[
i
]
=
bones
[
i
].
FinalTransformation
;
}
if
(
boneTransforms
.
size
()
==
0
){
boneTransforms
.
push_back
(
QMatrix4x4
());
}
shader
->
setUniformValueArray
(
"Bones"
,
boneTransforms
.
constData
(),
boneTransforms
.
size
());
renderNode
(
shader
,
rootNode
,
V
*
screenTransform
,
P
,
QMatrix4x4
());
renderNode
(
shader
,
rootNode
,
V
*
screenTransform
,
P
,
QMatrix4x4
());
f
->
glDisableVertexAttribArray
(
positionIndex
);
f
->
glDisableVertexAttribArray
(
positionIndex
);
f
->
glDisableVertexAttribArray
(
normalIndex
);
f
->
glDisableVertexAttribArray
(
normalIndex
);
f
->
glDisableVertexAttribArray
(
uvIndex
);
f
->
glDisableVertexAttribArray
(
uvIndex
);
f
->
glDisableVertexAttribArray
(
boneIndex
);
f
->
glDisableVertexAttribArray
(
boneweightIndex
);
...
@@ -399,240 +333,11 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index)
...
@@ -399,240 +333,11 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index)
f
->
glVertexAttribPointer
(
positionIndex
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
0
);
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
(
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
->
glVertexAttribPointer
(
uvIndex
,
2
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
(
const
GLvoid
*
)
24
);
// 12+12
f
->
glVertexAttribIPointer
(
boneIndex
,
4
,
GL_INT
,
sizeof
(
Vertex
),
(
const
GLvoid
*
)
32
);
// 12+12+8
f
->
glVertexAttribPointer
(
boneweightIndex
,
4
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
(
const
GLvoid
*
)
48
);
//12+12+8+16
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
entries
[
index
].
IB
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
entries
[
index
].
IB
);
f
->
glDrawElements
(
GL_TRIANGLES
,
entries
[
index
].
numIndex
,
GL_UNSIGNED_INT
,
0
);
f
->
glDrawElements
(
GL_TRIANGLES
,
entries
[
index
].
numIndex
,
GL_UNSIGNED_INT
,
0
);
}
}
//Bone Update
void
Mesh
::
updateBoneTransform
(
float
TimeInSeconds
,
int
animIndex
){
if
(
!
scene
||
bones
.
size
()
==
0
||
!
scene
->
HasAnimations
())
return
;
animIndex
=
animIndex
%
scene
->
mNumAnimations
;
const
aiAnimation
*
animation
=
scene
->
mAnimations
[
animIndex
];
float
TicksPerSecond
=
(
float
)(
animation
->
mTicksPerSecond
!=
0
?
animation
->
mTicksPerSecond
:
25.0
f
);
float
TimeInTicks
=
TimeInSeconds
*
TicksPerSecond
;
float
AnimationTime
=
fmod
(
TimeInTicks
,
(
float
)
animation
->
mDuration
);
updateBoneHeirachy
(
AnimationTime
,
animation
,
this
->
rootNode
,
QMatrix4x4
());
}
void
Mesh
::
updateBoneHeirachy
(
float
AnimTime
,
const
aiAnimation
*
animation
,
Node
node
,
QMatrix4x4
parentTransform
){
QMatrix4x4
nodeTransformation
=
node
.
transformation
;
//Find channel
const
aiNodeAnim
*
nodeAnimation
=
findAnimOfNode
(
animation
,
node
.
name
);
//calc Tcurrent Trasnformation;
if
(
nodeAnimation
)
{
QVector3D
scale
=
calcInterpolatedScaling
(
AnimTime
,
nodeAnimation
);
QQuaternion
rot
=
calcInterpolatedRotation
(
AnimTime
,
nodeAnimation
);
QVector3D
trans
=
calcInterpolatedTranslation
(
AnimTime
,
nodeAnimation
);
//qDebug()<<"calc"<<scale<<rot<<trans;
nodeTransformation
.
setToIdentity
();
nodeTransformation
.
translate
(
trans
);
nodeTransformation
.
rotate
(
rot
);
nodeTransformation
.
scale
(
scale
);
}
//Update Bone and children
QMatrix4x4
GlobalTransform
=
parentTransform
*
nodeTransformation
;
if
(
boneMap
.
find
(
node
.
name
)
!=
boneMap
.
end
())
{
int
index
=
boneMap
[
node
.
name
];
bones
[
index
].
FinalTransformation
=
globalInverseTransform
*
GlobalTransform
*
bones
[
index
].
BoneOffset
;
}
for
(
int
i
=
0
;
i
<
node
.
children
.
size
();
++
i
)
{
updateBoneHeirachy
(
AnimTime
,
animation
,
node
.
children
[
i
],
GlobalTransform
);
}
}
const
aiNodeAnim
*
Mesh
::
findAnimOfNode
(
const
aiAnimation
*
animation
,
QString
NodeName
){
for
(
uint
i
=
0
;
i
<
animation
->
mNumChannels
;
i
++
)
{
const
aiNodeAnim
*
nodeanim
=
animation
->
mChannels
[
i
];
if
(
QString
(
nodeanim
->
mNodeName
.
data
)
==
NodeName
)
{
return
nodeanim
;
}
}
return
NULL
;
}
//Interpolarisation
QQuaternion
Mesh
::
calcInterpolatedRotation
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
){
if
(
nodeAnimation
->
mNumRotationKeys
==
1
){
return
convert
(
nodeAnimation
->
mRotationKeys
[
0
].
mValue
);
}
//Index find
int
index
=
0
;
for
(
uint
i
=
0
;
i
<
nodeAnimation
->
mNumRotationKeys
-
1
;
i
++
)
{
if
(
AnimTime
<
(
float
)
nodeAnimation
->
mRotationKeys
[
i
+
1
].
mTime
)
{
index
=
i
;
break
;
}
}
float
DeltaTime
=
(
float
)(
nodeAnimation
->
mRotationKeys
[
index
+
1
].
mTime
-
nodeAnimation
->
mRotationKeys
[
index
].
mTime
);
float
Factor
=
(
AnimTime
-
(
float
)
nodeAnimation
->
mRotationKeys
[
index
].
mTime
)
/
DeltaTime
;
// qDebug()<<AnimTime<<DeltaTime<<Factor;
const
aiQuaternion
start
=
nodeAnimation
->
mRotationKeys
[
index
].
mValue
;
const
aiQuaternion
end
=
nodeAnimation
->
mRotationKeys
[
index
+
1
].
mValue
;
aiQuaternion
RotationQ
;
aiQuaternion
::
Interpolate
(
RotationQ
,
start
,
end
,
Factor
);
return
convert
(
RotationQ
);
//return convert(start);
}
QVector3D
Mesh
::
calcInterpolatedScaling
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
){
return
calcInterpolatedVectorKey
(
AnimTime
,
nodeAnimation
,
nodeAnimation
->
mScalingKeys
,
nodeAnimation
->
mNumScalingKeys
);
}
QVector3D
Mesh
::
calcInterpolatedTranslation
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
){
return
calcInterpolatedVectorKey
(
AnimTime
,
nodeAnimation
,
nodeAnimation
->
mPositionKeys
,
nodeAnimation
->
mNumPositionKeys
);
}
QVector3D
Mesh
::
calcInterpolatedVectorKey
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
,
const
aiVectorKey
*
keys
,
const
int
numberOfKeys
){
if
(
numberOfKeys
==
1
){
return
convert
(
keys
[
0
].
mValue
);
}
//Index find
int
index
=
0
;
for
(
int
i
=
0
;
i
<
numberOfKeys
-
1
;
i
++
)
{
if
(
AnimTime
<
(
float
)
keys
[
i
+
1
].
mTime
)
{
index
=
i
;
break
;
}
}
float
DeltaTime
=
(
float
)(
keys
[
index
+
1
].
mTime
-
keys
[
index
].
mTime
);
float
Factor
=
(
AnimTime
-
(
float
)
keys
[
index
].
mTime
)
/
DeltaTime
;
QVector3D
start
=
convert
(
keys
[
index
].
mValue
);
QVector3D
end
=
convert
(
keys
[
index
+
1
].
mValue
);
if
(
start
.
distanceToPoint
(
end
)
<
EPSILON
){
// same keyframe
return
start
;
}
if
(
linear
){
return
linInterpolate
(
start
,
end
,
Factor
);
}
if
(
index
==
0
){
//Start
switch
(
nodeAnimation
->
mPreState
)
{
case
aiAnimBehaviour_CONSTANT
:
// nearest Key
return
Factor
<
0.5
f
?
start
:
end
;
break
;
case
aiAnimBehaviour_REPEAT
:
// use start or end
{
QVector3D
before
=
convert
(
keys
[
index
-
1
].
mValue
);
QVector3D
after
=
convert
(
keys
[
numberOfKeys
-
1
].
mValue
);
return
Catmul
(
before
,
start
,
end
,
after
,
Factor
);
}
case
aiAnimBehaviour_LINEAR
:
// linear interpolate
return
linInterpolate
(
start
,
end
,
Factor
);
case
aiAnimBehaviour_DEFAULT
:
// take default node transformation
//TODO aiNodes haben nur translation rotation und scalierung nicht getrennt gespeichert
default
:
return
linInterpolate
(
start
,
end
,
Factor
);
}
}
else
if
((
index
+
2
)
==
numberOfKeys
){
// Ende
switch
(
nodeAnimation
->
mPostState
)
{
case
aiAnimBehaviour_CONSTANT
:
// nearest Key
return
Factor
<
0.5
f
?
start
:
end
;
break
;
case
aiAnimBehaviour_REPEAT
:
// use start or end
{
QVector3D
before
=
convert
(
keys
[
index
-
1
].
mValue
);
QVector3D
after
=
convert
(
keys
[
0
].
mValue
);
return
Catmul
(
before
,
start
,
end
,
after
,
Factor
);
}
case
aiAnimBehaviour_LINEAR
:
// linear interpolate
return
linInterpolate
(
start
,
end
,
Factor
);
case
aiAnimBehaviour_DEFAULT
:
// take default node transformation
//TODO
default
:
return
linInterpolate
(
start
,
end
,
Factor
);
}
}
else
{
QVector3D
before
=
convert
(
keys
[
index
-
1
].
mValue
);
QVector3D
after
=
convert
(
keys
[
index
+
2
].
mValue
);
if
(
before
.
distanceToPoint
(
start
)
<
EPSILON
||
end
.
distanceToPoint
(
after
)
<
EPSILON
){
// keyframes before or after are the same. No Nomal computation
//TODO
return
linInterpolate
(
start
,
end
,
Factor
);
}
return
Catmul
(
before
,
start
,
end
,
after
,
Factor
);
}
}
QVector3D
Mesh
::
Catmul
(
QVector3D
P0
,
QVector3D
P1
,
QVector3D
P2
,
QVector3D
P3
,
float
Factor
){
double
t0
=
0
;
double
t1
=
timeCatmul
(
P0
,
P1
,
t0
);
double
t2
=
timeCatmul
(
P1
,
P2
,
t1
);
double
t3
=
timeCatmul
(
P2
,
P3
,
t2
);
double
t
=
Factor
;
t
=
(
1
-
Factor
)
*
t1
+
Factor
*
t2
;
//qDebug()<<before<<start<<end<<after;
//qDebug()<<t0<<t1<<t2<<t3<<t;
QVector3D
A1
=
(
t1
-
t
)
/
(
t1
-
t0
)
*
P0
+
(
t
-
t0
)
/
(
t1
-
t0
)
*
P1
;
QVector3D
A2
=
(
t2
-
t
)
/
(
t2
-
t1
)
*
P1
+
(
t
-
t1
)
/
(
t2
-
t1
)
*
P2
;
QVector3D
A3
=
(
t3
-
t
)
/
(
t3
-
t2
)
*
P2
+
(
t
-
t2
)
/
(
t3
-
t2
)
*
P3
;
QVector3D
B1
=
(
t2
-
t
)
/
(
t2
-
t0
)
*
A1
+
(
t
-
t0
)
/
(
t2
-
t0
)
*
A2
;
QVector3D
B2
=
(
t3
-
t
)
/
(
t3
-
t1
)
*
A2
+
(
t
-
t1
)
/
(
t3
-
t1
)
*
A3
;
QVector3D
C
=
(
t2
-
t
)
/
(
t2
-
t1
)
*
B1
+
(
t
-
t1
)
/
(
t2
-
t1
)
*
B2
;
if
(
C
.
isNull
()
||
qIsNaN
(
C
.
x
())){
qCritical
()
<<
"Catmul bad:"
<<
C
<<
"from"
<<
P0
<<
P1
<<
P2
<<
P3
;
}
return
C
;
}
double
Mesh
::
timeCatmul
(
QVector3D
p1
,
QVector3D
p2
,
double
t_1
){
double
dist
=
p1
.
distanceToPoint
(
p2
);
double
alpha
=
0.0
;
//uniform
alpha
=
0.5
;
//centripetal
//float alpha = 1.0; //chordal
double
t
=
qPow
(
dist
,
alpha
)
+
t_1
;
// qDebug()<<dist<<t;
return
t
;
}
void
Mesh
::
findObjectDimension
(
Node
node
,
QMatrix4x4
transform
,
QVector3D
&
min
,
QVector3D
&
max
){
void
Mesh
::
findObjectDimension
(
Node
node
,
QMatrix4x4
transform
,
QVector3D
&
min
,
QVector3D
&
max
){
transform
*=
node
.
transformation
;
transform
*=
node
.
transformation
;
...
...
This diff is collapsed.
Click to expand it.
QTProject/mesh.h
View file @
9e817f2e
...
@@ -11,8 +11,6 @@
...
@@ -11,8 +11,6 @@
#define positionIndex 0
#define positionIndex 0
#define normalIndex 1
#define normalIndex 1
#define uvIndex 2
#define uvIndex 2
#define boneIndex 3
#define boneweightIndex 4
#define EPSILON 0.00001
#define EPSILON 0.00001
...
@@ -21,23 +19,15 @@ struct Vertex
...
@@ -21,23 +19,15 @@ struct Vertex
QVector3D
pos
;
QVector3D
pos
;
QVector3D
normal
;
QVector3D
normal
;
QVector2D
tex
;
QVector2D
tex
;
uint
IDs
[
4
];
float
weights
[
4
];
Vertex
(){}
Vertex
(){}
Vertex
(
const
QVector3D
&
pos
,
const
QVector3D
&
normal
,
const
QVector2D
&
tex
)
Vertex
(
const
QVector3D
&
pos
,
const
QVector3D
&
normal
,
const
QVector2D
&
tex
)
{
{
for
(
int
i
=
0
;
i
<
4
;
i
++
){
IDs
[
i
]
=
0
;
weights
[
i
]
=
0
;
}
this
->
pos
=
pos
;
this
->
pos
=
pos
;
this
->
tex
=
tex
;
this
->
tex
=
tex
;
this
->
normal
=
normal
;
this
->
normal
=
normal
;
}
}
void
AddBoneData
(
uint
BoneID
,
float
Weight
);
};
};
class
Mesh
class
Mesh
...
@@ -46,15 +36,11 @@ public:
...
@@ -46,15 +36,11 @@ public:
Mesh
(
QOpenGLFunctions_4_3_Core
*
f
,
QString
filename
);
Mesh
(
QOpenGLFunctions_4_3_Core
*
f
,
QString
filename
);
~
Mesh
();
~
Mesh
();
void
render
(
QOpenGLShaderProgram
*
shader
,
QMatrix4x4
V
,
QMatrix4x4
P
);
void
render
(
QOpenGLShaderProgram
*
shader
,
QMatrix4x4
V
,
QMatrix4x4
P
,
float
TimeInSeconds
,
int
animation
);
void
setAnimation
(
bool
linear
){
this
->
linear
=
linear
;}
const
aiScene
*
scene
;
const
aiScene
*
scene
;
private
:
private
:
struct
MeshEntry
{
struct
MeshEntry
{
MeshEntry
();
MeshEntry
();
~
MeshEntry
();
~
MeshEntry
();
...
@@ -85,24 +71,6 @@ private:
...
@@ -85,24 +71,6 @@ private:
float
Shininess
;
float
Shininess
;
};
};
struct
LightInfo
{
QVector4D
Position
;
QVector3D
Intensity
;
};
struct
BoneInfo
{
QMatrix4x4
BoneOffset
;
QMatrix4x4
FinalTransformation
;
BoneInfo
()
{
BoneOffset
.
setToIdentity
();
FinalTransformation
.
setToIdentity
();
}
};
struct
Node
struct
Node
{
{
Node
();
Node
();
...
@@ -117,45 +85,21 @@ private:
...
@@ -117,45 +85,21 @@ private:
QMatrix4x4
globalInverseTransform
;
QMatrix4x4
globalInverseTransform
;
QMatrix4x4
screenTransform
;
QMatrix4x4
screenTransform
;
QVector
<
MeshEntry
>
entries
;
QVector
<
MeshEntry
>
entries
;
QVector
<
MaterialInfo
>
materials
;
QVector
<
MaterialInfo
>
materials
;
QVector
<
BoneInfo
>
bones
;
QMap
<
QString
,
int
>
boneMap
;
int
numberOfBones
;
Node
rootNode
;
Node
rootNode
;
QOpenGLFunctions_4_3_Core
*
f
;
QOpenGLFunctions_4_3_Core
*
f
;
bool
loaded
;
bool
loaded
;
bool
linear
;
void
initMeshEntry
(
int
i
,
aiMesh
*
entry
);
void
initMeshEntry
(
int
i
,
aiMesh
*
entry
);
void
initMaterial
(
QString
dir
,
unsigned
int
i
,
const
aiMaterial
*
material
);
void
initMaterial
(
QString
dir
,
unsigned
int
i
,
const
aiMaterial
*
material
);
void
initNode
(
const
aiScene
*
scene
,
aiNode
*
node
,
Node
&
newNode
,
QString
debugoffset
);
void
initNode
(
const
aiScene
*
scene
,
aiNode
*
node
,
Node
&
newNode
,
QString
debugoffset
);
void
updateBoneTransform
(
float
TimeInSeconds
,
int
animation
);
void
updateBoneHeirachy
(
float
AnimTime
,
const
aiAnimation
*
animation
,
Node
node
,
QMatrix4x4
parentTransform
);
const
aiNodeAnim
*
findAnimOfNode
(
const
aiAnimation
*
animation
,
QString
NodeName
);
QVector3D
calcInterpolatedScaling
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
);
QQuaternion
calcInterpolatedRotation
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
);
QVector3D
calcInterpolatedTranslation
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
);
QVector3D
calcInterpolatedVectorKey
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
,
const
aiVectorKey
*
keys
,
const
int
numberOfKeys
);
void
renderNode
(
QOpenGLShaderProgram
*
shader
,
Node
&
node
,
QMatrix4x4
V
,
QMatrix4x4
P
,
QMatrix4x4
M
);
void
renderNode
(
QOpenGLShaderProgram
*
shader
,
Node
&
node
,
QMatrix4x4
V
,
QMatrix4x4
P
,
QMatrix4x4
M
);
void
renderMesh
(
QOpenGLShaderProgram
*
shader
,
int
index
);
void
renderMesh
(
QOpenGLShaderProgram
*
shader
,
int
index
);
QVector3D
convert
(
aiVector3D
in
){
return
QVector3D
(
in
.
x
,
in
.
y
,
in
.
z
);}
QQuaternion
convert
(
aiQuaternion
quat
){
return
QQuaternion
(
quat
.
w
,
quat
.
x
,
quat
.
y
,
quat
.
z
);}
QVector3D
linInterpolate
(
QVector3D
start
,
QVector3D
end
,
float
Factor
){
return
(
1
.
0
-
Factor
)
*
start
+
Factor
*
end
;}
QVector3D
Catmul
(
QVector3D
before
,
QVector3D
start
,
QVector3D
end
,
QVector3D
after
,
float
Factor
);
double
timeCatmul
(
QVector3D
p1
,
QVector3D
p2
,
double
t_1
);
void
findObjectDimension
(
Node
node
,
QMatrix4x4
transform
,
QVector3D
&
min
,
QVector3D
&
max
);
void
findObjectDimension
(
Node
node
,
QMatrix4x4
transform
,
QVector3D
&
min
,
QVector3D
&
max
);
...
...
This diff is collapsed.
Click to expand it.
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