Commit e3c9a72d by Kai Westerkamp

start & ende

parent 6cba67dc
...@@ -118,7 +118,7 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName) ...@@ -118,7 +118,7 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName)
} }
qDebug()<<"Mesh Read"; qDebug()<<"Mesh Read";
//TODO init Nodes //init Nodes
if(scene->mRootNode != NULL) if(scene->mRootNode != NULL)
{ {
initNode(scene, scene->mRootNode, rootNode, QString()); initNode(scene, scene->mRootNode, rootNode, QString());
...@@ -138,22 +138,55 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName) ...@@ -138,22 +138,55 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName)
globalInverseTransform = rootNode.transformation.inverted(); globalInverseTransform = rootNode.transformation.inverted();
//Test Interpolation: // //Test Interpolation:
if(false){ // if(false){
const aiAnimation* animation = scene->mAnimations[0]; // const aiAnimation* animation = scene->mAnimations[0];
const aiNodeAnim *nodeAnimation = findAnimOfNode(animation,"upperarm.R"); // const aiNodeAnim *nodeAnimation = findAnimOfNode(animation,"upperarm.R");
qDebug()<<"KeyFrames"; // qDebug()<<"KeyFrames";
for(uint i = 0; i < nodeAnimation->mNumPositionKeys; i++){ // for(uint i = 0; i < nodeAnimation->mNumPositionKeys; i++){
qDebug()<<nodeAnimation->mPositionKeys[i].mTime<<convert(nodeAnimation->mPositionKeys[i].mValue); // qDebug()<<nodeAnimation->mPositionKeys[i].mTime<<convert(nodeAnimation->mPositionKeys[i].mValue);
} // }
qDebug()<<"Interpolated"; // qDebug()<<"Interpolated";
for(float f = 0.0; f < (float)animation->mDuration; f += 0.5f){ // for(float f = 0.0; f < (float)animation->mDuration; f += 0.5f){
qDebug()<<f<<calcInterpolatedTranslation(f,nodeAnimation); // qDebug()<<f<<calcInterpolatedTranslation(f,nodeAnimation);
} // }
} // }
// for (int i = 0; i < scene->mNumAnimations; ++i) {
// const aiAnimation* animation = scene->mAnimations[i];
//Todo read skeleton // qDebug()<<"Animation"<<animation->mName.C_Str();
// switch (animation->mChannels[0]->mPreState) {
// case aiAnimBehaviour_CONSTANT:
// qDebug()<<"Pre"<<"aiAnimBehaviour_CONSTANT";
// break;
// case aiAnimBehaviour_REPEAT: // use start or end
// qDebug()<<"Pre"<<"aiAnimBehaviour_REPEAT";
// break;
// case aiAnimBehaviour_LINEAR: // linear interpolate
// qDebug()<<"Pre"<<"aiAnimBehaviour_LINEAR";
// break;
// case aiAnimBehaviour_DEFAULT: // take default node transformation
// qDebug()<<"Pre"<<"aiAnimBehaviour_DEFAULT";
// break;
// default:
// qDebug()<<"Pre"<<"not";
// }
// switch (animation->mChannels[0]->mPostState) {
// case aiAnimBehaviour_CONSTANT:
// qDebug()<<"Post"<<"aiAnimBehaviour_CONSTANT";
// break;
// case aiAnimBehaviour_REPEAT: // use start or end
// qDebug()<<"Post"<<"aiAnimBehaviour_REPEAT";
// break;
// case aiAnimBehaviour_LINEAR: // linear interpolate
// qDebug()<<"Post"<<"aiAnimBehaviour_LINEAR";
// break;
// case aiAnimBehaviour_DEFAULT: // take default node transformation
// qDebug()<<"Post"<<"aiAnimBehaviour_DEFAULT";
// break;
// default:
// qDebug()<<"Post"<<"not";
// }
// }
loaded = true; loaded = true;
} }
...@@ -168,6 +201,7 @@ Mesh::~Mesh() ...@@ -168,6 +201,7 @@ Mesh::~Mesh()
void Mesh::initNode(const aiScene *scene, aiNode *node, Node &newNode,QString debugoffset){ void Mesh::initNode(const aiScene *scene, aiNode *node, Node &newNode,QString debugoffset){
newNode.name = node->mName.length != 0 ? node->mName.C_Str() : ""; newNode.name = node->mName.length != 0 ? node->mName.C_Str() : "";
newNode.transformation = QMatrix4x4(node->mTransformation[0]); newNode.transformation = QMatrix4x4(node->mTransformation[0]);
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;
...@@ -400,7 +434,6 @@ void Mesh::updateBoneTransform(float TimeInSeconds, int animIndex){ ...@@ -400,7 +434,6 @@ void Mesh::updateBoneTransform(float TimeInSeconds, int animIndex){
float TimeInTicks = TimeInSeconds * TicksPerSecond; float TimeInTicks = TimeInSeconds * TicksPerSecond;
float AnimationTime = fmod(TimeInTicks, (float)animation->mDuration); float AnimationTime = fmod(TimeInTicks, (float)animation->mDuration);
//TODO calc time and get Anaimation;
updateBoneHeirachy(AnimationTime,animation,this->rootNode,QMatrix4x4()); updateBoneHeirachy(AnimationTime,animation,this->rootNode,QMatrix4x4());
...@@ -417,18 +450,9 @@ void Mesh::updateBoneHeirachy(float AnimTime,const aiAnimation* animation, Node ...@@ -417,18 +450,9 @@ void Mesh::updateBoneHeirachy(float AnimTime,const aiAnimation* animation, Node
//calc Tcurrent Trasnformation; //calc Tcurrent Trasnformation;
if (nodeAnimation) { if (nodeAnimation) {
// if(node.name.endsWith("upperarm.L")){ QVector3D scale = calcInterpolatedScaling(AnimTime,nodeAnimation,node);
// qDebug()<<node.name;
// for (uint i = 0 ; i < nodeAnimation->mNumPositionKeys ; i++) {
// qDebug()<<convert(nodeAnimation->mPositionKeys[i].mValue)<<nodeAnimation->mPositionKeys[i].mTime;
// }
// }
QVector3D scale = calcInterpolatedScaling(AnimTime,nodeAnimation);
QQuaternion rot = calcInterpolatedRotation(AnimTime,nodeAnimation); QQuaternion rot = calcInterpolatedRotation(AnimTime,nodeAnimation);
QVector3D trans = calcInterpolatedTranslation(AnimTime,nodeAnimation); QVector3D trans = calcInterpolatedTranslation(AnimTime,nodeAnimation,node);
//qDebug()<<"calc"<<scale<<rot<<trans; //qDebug()<<"calc"<<scale<<rot<<trans;
nodeTransformation.setToIdentity(); nodeTransformation.setToIdentity();
...@@ -527,27 +551,35 @@ QVector3D Mesh::calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeA ...@@ -527,27 +551,35 @@ QVector3D Mesh::calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeA
return start; return start;
} }
if(index == 0 ){ if(linear){
return linInterpolate(start,end,Factor);
}
if(index == 0 ){ //Start
switch (nodeAnimation->mPreState) { switch (nodeAnimation->mPreState) {
case aiAnimBehaviour_CONSTANT: // nearest Key case aiAnimBehaviour_CONSTANT: // nearest Key
return Factor <0.5f ? start : end; return Factor <0.5f ? start : end;
break; break;
case aiAnimBehaviour_REPEAT: // use start or end case aiAnimBehaviour_REPEAT: // use start or end
//TODO 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 case aiAnimBehaviour_LINEAR: // linear interpolate
return linInterpolate(start,end,Factor); return linInterpolate(start,end,Factor);
case aiAnimBehaviour_DEFAULT: // take default node transformation case aiAnimBehaviour_DEFAULT: // take default node transformation
//TODO //TODO aiNodes haben nur translation rotation und scalierung nicht getrennt gespeichert
default: default:
return linInterpolate(start,end,Factor); return linInterpolate(start,end,Factor);
} }
} else if((index+2)== numberOfKeys){ } else if((index+2)== numberOfKeys){ // Ende
switch (nodeAnimation->mPostState) { switch (nodeAnimation->mPostState) {
case aiAnimBehaviour_CONSTANT: // nearest Key case aiAnimBehaviour_CONSTANT: // nearest Key
return Factor <0.5f ? start : end; return Factor <0.5f ? start : end;
break; break;
case aiAnimBehaviour_REPEAT: // use start or end case aiAnimBehaviour_REPEAT: // use start or end
//TODO 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 case aiAnimBehaviour_LINEAR: // linear interpolate
return linInterpolate(start,end,Factor); return linInterpolate(start,end,Factor);
case aiAnimBehaviour_DEFAULT: // take default node transformation case aiAnimBehaviour_DEFAULT: // take default node transformation
...@@ -555,23 +587,10 @@ QVector3D Mesh::calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeA ...@@ -555,23 +587,10 @@ QVector3D Mesh::calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeA
default: default:
return linInterpolate(start,end,Factor); return linInterpolate(start,end,Factor);
} }
} else{ } else{
if(linear)
return linInterpolate(start,end,Factor);
QVector3D before = convert(keys[index-1].mValue); QVector3D before = convert(keys[index-1].mValue);
QVector3D after = convert(keys[index+2].mValue); QVector3D after = convert(keys[index+2].mValue);
return Catmul(before,start,end,after,Factor);
// if(before.distanceToPoint(start) == 0|| end.distanceToPoint(after) == 0){
// qDebug()<<"Zeror before or after"<<AnimTime;
// return linInterpolate(start,end,Factor);
// }
QVector3D interpolated = Catmul(before,start,end,after,Factor);
//qDebug()<<nodeAnimation->mNodeName.C_Str()<<AnimTime<<start<<end<<interpolated;
return interpolated;
} }
} }
......
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