Commit bcc29328 by Kai Westerkamp

BONES

parent 20755150
......@@ -5,6 +5,8 @@ layout(location = 0) out vec3 color;
in vec3 vCamPosition;
in vec3 vCamNormal;
in vec2 vUV;
in vec4 debugout;
uniform sampler2D colorTexture;
uniform vec3 LightPos;
......@@ -40,6 +42,7 @@ vec3 phong(vec3 lightPos){
void main(void)
{
color = phong(LightPos);
//color = debugout.xyz;
//color = texture2D(colorTexture,vUV).xyz;
}
......@@ -2,27 +2,44 @@
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
layout(location = 2) in vec2 UV;
layout(location = 2) in ivec4 BoneIDs;
layout(location = 2) in vec4 Weights;
layout(location = 3) in ivec4 BoneIDs;
layout(location = 4) in vec4 Weights;
out vec3 vCamPosition;
out vec3 vCamNormal;
out vec2 vUV;
out vec4 debugout;
uniform mat4x4 MV;
uniform mat4x4 MVP;
uniform mat3x3 N;
uniform mat4x4 Bones[100];
void main(void)
{
vCamPosition = vec4(MV*vec4(Position,1.0)).xyz;
debugout = vec4(BoneIDs)/60;
debugout = Weights;
//debugout = vec4(1);
mat4x4 BoneTransform = Bones[BoneIDs[0]] * Weights[0];
BoneTransform += Bones[BoneIDs[1]] * Weights[1];
BoneTransform += Bones[BoneIDs[2]] * Weights[2];
BoneTransform += Bones[BoneIDs[3]] * Weights[3];
vec4 Pos = BoneTransform*vec4(Position,1.0);
//Pos = vec4(Position,1.0);
vCamPosition = vec4(MV*Pos).xyz;
vCamNormal = N*Normal;
vUV = UV;
gl_Position = MVP * vec4(Position,1.0);
gl_Position = MVP * Pos;
}
......
......@@ -23,21 +23,20 @@ struct Vertex
uint IDs[4];
float weights[4];
Vertex() {
Vertex(){}
Vertex(const QVector3D& pos, const QVector3D& normal, const QVector2D& tex)
{
for(int i = 0; i < 4; i++){
IDs[i] = 0;
weights[i] = 0;
}
}
Vertex(const QVector3D& pos, const QVector3D& normal, const QVector2D& tex)
{
this->pos = pos;
this->tex = tex;
this->normal = normal;
}
void AddBoneData(uint BoneID, float Weight);
void AddBoneData(uint BoneID, float Weight);
};
class Mesh
......@@ -86,6 +85,18 @@ private:
QVector3D Intensity;
};
struct BoneInfo
{
QMatrix4x4 BoneOffset;
QMatrix4x4 FinalTransformation;
BoneInfo()
{
BoneOffset.setToIdentity();
FinalTransformation.setToIdentity();
}
};
struct Node
{
Node();
......@@ -96,18 +107,33 @@ private:
};
const aiScene *scene;
Assimp::Importer importer;
QMatrix4x4 globalInverseTransform;
QVector<MeshEntry> entries;
QVector<MaterialInfo> materials;
QVector<BoneInfo> bones;
QMap<QString,int> boneMap;
int numberOfBones;
Node rootNode;
QOpenGLFunctions_4_3_Core *f;
bool loaded;
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);
void initNode(const aiScene *scene, aiNode *node, Node &newNode, QString debugoffset);
void updateBoneTransform(float TimeInSeconds);
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);
void renderNode(QOpenGLShaderProgram *shader, Node &node, QMatrix4x4 V,QMatrix4x4 P,QMatrix4x4 M);
void renderMesh(QOpenGLShaderProgram *shader, int index);
......
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