Commit 87d9d8f0 by Kai Westerkamp

ui update

parent 63e1d174
......@@ -43,6 +43,8 @@ void main(void)
{
color = phong(LightPos);
//color = debugout.xyz;
//color = vec3(1.0,0.0,0.0);
//color = texture2D(colorTexture,vUV).xyz;
//color = vec3(vUV,0.0);
}
......@@ -3,6 +3,12 @@
MainWidget::MainWidget()
{
startTime = QTime::currentTime();
rotTime = QTime::currentTime();
linear = false;
rotation = true;
animate = true;
Animation = 0;
}
QSize MainWidget::minimumSizeHint() const
......@@ -54,15 +60,49 @@ void MainWidget::initializeGL(){
void MainWidget::loadNewMesh(){
QString fn = QFileDialog::getOpenFileName(NULL, tr("Open Mesh..."),
QString("D:\\Projekte\\GraPa\\A5\\Models"),
tr("*.md5mesh *.3ds *.md2 *.obj *.dae *.dxf" ));
tr("*.md5mesh *.3ds *.md2 *.obj *.dae *.dxf *.mesh.xml" ));
if(fn.isEmpty())
return;
qDebug()<<"Opening File:"<<fn;
mesh = new Mesh(this,fn);
mesh->setAnimation(linear);
}
void MainWidget::setInterpolation(bool linear){
qDebug()<<"linear"<<linear;
this->linear = linear;
if(mesh)
mesh->setAnimation(linear);
}
void MainWidget::setRotation(bool started){
qDebug()<<"rotation"<<started;
this->rotation = started;
}
void MainWidget::setAnimating(bool started){
qDebug()<<"animating"<<started;
this->animate = started;
if(started){
startTime = QTime::currentTime();
}
}
void MainWidget::nextAnimation(){
Animation++;
Animation = Animation % mesh->scene->mNumAnimations;
startTime = QTime::currentTime();
qDebug()<<"Animation"<<Animation;
}
QOpenGLShaderProgram* MainWidget::initShader(QString fragSource, QString vertSource){
QOpenGLShader *vert = new QOpenGLShader(QOpenGLShader::Vertex);
......@@ -97,17 +137,22 @@ void MainWidget::paintGL(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
QMatrix4x4 rot;
int time = QTime::currentTime().second()*1000+QTime::currentTime().msec();
//rot.rotate(time/100.0*36/5,QVector3D(0,1,0));
int time = rotTime.msecsTo(QTime::currentTime());
if(rotation){
//TODO schön machen
rot.rotate(time/100.0*36/5,QVector3D(0,1,0));
}
animationShader->bind();
animationShader->setUniformValue("colorTexture",0);
animationShader->setUniformValue("LightPos",QVector3D(0,100,100));
float ftime = startTime.msecsTo(QTime::currentTime()) /1000.0;
if(!animate)
ftime = 0;
mesh->render(animationShader,m_view*rot, m_projection,(float) ftime);
mesh->render(animationShader,m_view*rot, m_projection,(float) ftime,Animation);
animationShader->release();
update();
......
......@@ -23,6 +23,11 @@ public:
public slots:
void loadNewMesh();
void setInterpolation(bool linear);
void setRotation(bool started);
void setAnimating(bool started);
void nextAnimation();
protected:
void initializeGL();
......@@ -36,9 +41,16 @@ private:
QMatrix4x4 m_projection;
QMatrix4x4 m_view;
QTime startTime;
QTime rotTime;
float camDistance;
boolean linear;
boolean rotation;
boolean animate;
int Animation;
Mesh *mesh;
QOpenGLShaderProgram* initShader(QString fragSource, QString vertSource);
......
......@@ -5,10 +5,37 @@ MainWindow::MainWindow(QWidget *parent) :
{
m_centralWidget = new MainWidget();
loadMesh = new QAction("Add Mesh",this);
toolBar = new QToolBar("Animation",this);
addToolBar(toolBar);
loadMesh = new QAction("Load Mesh",this);
loadMesh->setShortcut(QKeySequence("Ctrl+N"));
connect(loadMesh, SIGNAL(triggered()), m_centralWidget, SLOT(loadNewMesh()));
this->addAction(loadMesh);
toolBar->addAction(loadMesh);
switchInterpolation = new QAction("Interpolation",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->setCheckable(true);
switchRotation->setChecked(true);
connect(switchRotation, SIGNAL(triggered(bool)), m_centralWidget, SLOT(setRotation(bool)));
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);
this->setCentralWidget(m_centralWidget);
......
......@@ -19,7 +19,13 @@ public:
private:
MainWidget *m_centralWidget;
QToolBar *toolBar;
QAction *loadMesh;
QAction *switchInterpolation;
QAction *switchRotation;
QAction *stopAnimation;
QAction *nextAnimation;
};
......
......@@ -65,6 +65,7 @@ Mesh::Node::Node()
Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName)
{
loaded = false;
linear = false;
this->f =f;
numberOfBones = 0;
scene = NULL;
......@@ -222,7 +223,7 @@ void Mesh::initMaterial(QString dir, unsigned int i, const aiMaterial* material)
if (material->GetTexture(aiTextureType_DIFFUSE, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) {
QString temp = QString(Path.data);
temp = temp.split("\\").last();
//temp = temp.split("\\").last();
std::string FullPath = dir.toStdString() + "/" + temp.toStdString();
materials[i].texture.Load(GL_TEXTURE_2D, QString(FullPath.c_str()));
materials[i].hasTexture = true;
......@@ -267,7 +268,7 @@ void Mesh::initMeshEntry(int index, aiMesh * entry){
entries[index].name = entry->mName.length != 0 ? entry->mName.C_Str() : "";
entries[index].materialIndex = entry->mMaterialIndex;
qDebug()<<"Loaded Mesh:"<<entries[index].name;
qDebug()<<"Loaded Mesh:"<<entries[index].name<<"HasBones:"<<entry->HasBones();
if(entry->HasBones()){
for(uint i = 0; i< entry->mNumBones; i++){
......@@ -300,7 +301,7 @@ void Mesh::initMeshEntry(int index, aiMesh * entry){
}
void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, float TimeInSeconds){
void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, float TimeInSeconds, int animation){
if(!loaded)
return;
if(f == NULL){
......@@ -315,7 +316,7 @@ void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, float
f->glEnableVertexAttribArray(boneweightIndex);
updateBoneTransform(TimeInSeconds);
updateBoneTransform(TimeInSeconds,animation);
QVector<QMatrix4x4> boneTransforms = QVector<QMatrix4x4>(bones.size());
for(int i = 0; i < bones.size(); i++){
boneTransforms[i] = bones[i].FinalTransformation;
......@@ -387,10 +388,12 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index)
f->glDrawElements(GL_TRIANGLES, entries[index].numIndex, GL_UNSIGNED_INT, 0);
}
void Mesh::updateBoneTransform(float TimeInSeconds){
if(!scene || bones.size() == 0)
void Mesh::updateBoneTransform(float TimeInSeconds, int animIndex){
if(!scene || bones.size() == 0|| !scene->HasAnimations())
return;
const aiAnimation* animation = scene->mAnimations[0];
animIndex = animIndex % scene->mNumAnimations;
const aiAnimation* animation = scene->mAnimations[animIndex];
float TicksPerSecond = (float)(animation->mTicksPerSecond != 0 ? animation->mTicksPerSecond : 25.0f);
......@@ -520,7 +523,8 @@ QVector3D Mesh::calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeA
QVector3D start = convert(keys[index].mValue);
QVector3D end = convert(keys[index+1].mValue);
return linInterpolate(start,end,Factor);
if(linear)
return linInterpolate(start,end,Factor);
if(start.distanceToPoint(end) == 0){ // same keyframse not interpolation
return start;
......
......@@ -47,7 +47,9 @@ public:
void render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, float TimeInSeconds);
void render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, float TimeInSeconds, int animation);
void setAnimation(bool linear){this->linear = linear;}
const aiScene *scene;
private:
......@@ -106,7 +108,7 @@ private:
QVector<Node> children;
};
const aiScene *scene;
Assimp::Importer importer;
QMatrix4x4 globalInverseTransform;
......@@ -122,14 +124,17 @@ private:
QOpenGLFunctions_4_3_Core *f;
bool loaded;
bool linear;
void initMeshEntry(int i,aiMesh * entry);
void initMaterial(QString dir, unsigned int i, const aiMaterial* material);
void initNode(const aiScene *scene, aiNode *node, Node &newNode, QString debugoffset);
void updateBoneTransform(float TimeInSeconds);
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);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
material
{
technique
{
pass
{
}
}
}
material unity_pilot_head_01
{
technique
{
pass
{
ambient 0.588235 0.588235 0.588235
diffuse 0.588235 0.588235 0.588235
specular 0 0 0 0.015625
emissive 0 0 0
texture_unit
{
texture head01.png
filtering point point point
}
}
}
}
material unity_pilot_body_01
{
technique
{
pass
{
ambient 0.588235 0.588235 0.588235
diffuse 0.588235 0.588235 0.588235
specular 0 0 0 0.015625
emissive 0 0 0
texture_unit
{
texture body01.png
filtering point point point
}
}
}
}
material m4
{
technique
{
pass
{
ambient 1 1 1
diffuse 1 1 1
specular 1 1 1 40
emissive 1 1 1
texture_unit
{
texture m4tex.png
filtering point point point
}
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
# Wavefront MTL
# Created by fragMOTION
# http://www.fragmosoft.com
newmtl unity_pilot_head_01
illum 2
d 1
ka 0.588235 0.588235 0.588235
kd 0.588235 0.588235 0.588235
ks 0 0 0
ke 0 0 0
ns 0.015625
map_kd C:\Users\Nathan\Documents\New Project\Assets\Textures\soldier\head01.png
newmtl unity_pilot_body_01
illum 2
d 1
ka 0.588235 0.588235 0.588235
kd 0.588235 0.588235 0.588235
ks 0 0 0
ke 0 0 0
ns 0.015625
map_kd C:\Users\Nathan\Documents\New Project\Assets\Textures\soldier\body01.png
newmtl m4
illum 2
d 1
ka 1 1 1
kd 1 1 1
ks 1 1 1
ke 1 1 1
ns 40
map_kd C:\Users\Nathan\Documents\New Project\Assets\Textures\soldier\m4tex.png
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
21:34:53: Creating resource group General
21:34:53: Creating resource group Internal
21:34:53: Creating resource group Autodetect
21:34:53: Registering ResourceManager for type Mesh
21:34:53: Registering ResourceManager for type Material
21:34:53: Registering ResourceManager for type Skeleton
21:34:53: XMLMeshSerializer reading mesh data from C:\Users\Nathan\Documents\ArmyPilot\ArmyPilot.mesh.xml...
21:34:54: Reading submeshes...
21:34:54: Reading geometry...
21:34:54: Geometry done...
21:34:54: Reading bone assignments...
21:34:54: Bone assignments done.
21:34:54: Reading geometry...
21:34:55: Geometry done...
21:34:55: Reading bone assignments...
21:34:55: Bone assignments done.
21:34:55: Reading geometry...
21:34:55: Geometry done...
21:34:55: Reading bone assignments...
21:34:55: Bone assignments done.
21:34:55: Submeshes done.
21:34:55: Skeleton: Loading ArmyPilot.skeleton
21:34:55: OGRE EXCEPTION(6:FileNotFoundException): Cannot locate resource ArmyPilot.skeleton in resource group General or any other group. in ResourceGroupManager::openResource at ..\..\..\..\OgreMain\src\OgreResourceGroupManager.cpp (line 753)
21:34:55: Unable to load skeleton ArmyPilot.skeleton for Mesh conversion. This Mesh will not be animated. You can ignore this message if you are using an offline tool.
21:34:55: XMLMeshSerializer import successful.
21:34:55: Reorganising vertex buffers to automatic layout..
21:34:55: MeshSerializer writing mesh data to C:\Users\Nathan\Documents\ArmyPilot\ArmyPilot.mesh...
21:34:55: File header written.
21:34:55: Writing mesh data...
21:34:55: Writing submesh...
21:34:55: Exporting submesh texture aliases...
21:34:55: Submesh texture aliases exported.
21:34:55: Exporting dedicated geometry bone assignments...
21:34:55: Dedicated geometry bone assignments exported.
21:34:55: Submesh exported.
21:34:55: Writing submesh...
21:34:55: Exporting submesh texture aliases...
21:34:55: Submesh texture aliases exported.
21:34:55: Exporting dedicated geometry bone assignments...
21:34:55: Dedicated geometry bone assignments exported.
21:34:55: Submesh exported.
21:34:55: Writing submesh...
21:34:55: Exporting submesh texture aliases...
21:34:55: Submesh texture aliases exported.
21:34:55: Exporting dedicated geometry bone assignments...
21:34:55: Dedicated geometry bone assignments exported.
21:34:55: Submesh exported.
21:34:55: Exporting skeleton link...
21:34:55: Skeleton link exported.
21:34:55: Exporting bounds information....
21:34:55: Bounds information exported.
21:34:55: Exporting submesh name table...
21:34:55: Submesh name table exported.
21:34:55: Exporting edge lists...
21:34:55: Edge lists exported
21:34:55: Mesh data exported.
21:34:55: MeshSerializer export successful.
21:34:55: Unregistering ResourceManager for type Skeleton
21:34:55: Unregistering ResourceManager for type Material
21:34:55: Unregistering ResourceManager for type Mesh
Upload Feito por Dark Angel The 3d Free Models.
\ No newline at end of file
# Max2Mtl Version 4.0 Mar 10th, 2001
#
# Multi/Sub SMDImport (1) to come
#
newmtl Material__10
Ka 0.6 0.6 0.6
Kd 0.6 0.6 0.6
Ks 0.9 0.9 0.9
d 1.0
Ns 0.0
illum 2
map_Kd metrocop_sheet.tga
#
# Multi/Sub SMDImport done
#
# EOF
This source diff could not be displayed because it is too large. You can view the blob instead.
Upload By Dark Angle The 3d Free Models.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment