This commit is contained in:
viktorljung
2016-02-17 10:52:50 +01:00
parent 648d864d6e
commit e7118ce8e5
3 changed files with 84 additions and 51 deletions
+3 -2
View File
@@ -108,6 +108,8 @@ public:
void AccumulateBoneTransforms(bool noRootMotion, std::vector<AnimationData> animations, std::map<int, glm::mat4>& frameBones, const Bone* bone, glm::mat4 parentMatrix);
void AccumulateBoneTransforms(bool noRootMotion, std::vector<AnimationData> animations, AnimationOffset animationOffset, std::map<int, glm::mat4>& frameBones, const Bone* bone, glm::mat4 parentMatrix);
glm::mat4 AdditiveBlend(JointFrameTransform addTransform, JointFrameTransform transform);
void PrintSkeleton();
void PrintSkeleton(const Bone* parent, int depthCount);
std::map<std::string, Animation> Animations;
@@ -118,8 +120,7 @@ public:
int GetKeyframe(const Animation& animation, double time);
private:
glm::mat4 GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset);
JointFrameTransform GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset);
std::map<std::string, Bone*> m_BonesByName;
+44 -20
View File
@@ -29,25 +29,19 @@
<Entity name="Running">
<Components>
<c:Animation>
<AnimationName1>Run</AnimationName1>
<Weight1>0.5</Weight1>
<Time1>0.60188997954429357</Time1>
<Speed1>-1</Speed1>
<AnimationName1>AimRifle</AnimationName1>
<Time1>0.94417153407339605</Time1>
<Speed2>1</Speed2>
<Weight2>0.5</Weight2>
<Time2>0.96957233017255007</Time2>
<AnimationName2></AnimationName2>
<Time2>0.032904333143131348</Time2>
<Time3>0.093923612201312068</Time3>
<Speed3>1</Speed3>
</c:Animation>
<c:AnimationOffset>
<AnimationName>AimRifle</AnimationName>
<Time>0.5</Time>
</c:AnimationOffset>
<c:Model>
<Resource>Models/Characters/Assault/AssaultAnimations.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="-0.690088332" Y="0" Z="0"/>
<Position X="-1" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -61,8 +55,8 @@
<Resource>Models/Weapons/Red/AssaultWeaponRed.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0.161975682" Y="1.06281972" Z="-0.216630161"/>
<Orientation X="-0.064812161" Y="-0.0739696771" Z="0.143780142"/>
<Position X="0.110472031" Y="1.3360424" Z="-0.158128098"/>
<Orientation X="0.894863248" Y="0.282616436" Z="-0.203133404"/>
</c:Transform>
</Components>
<Children/>
@@ -108,23 +102,52 @@
<Entity>
<Components>
<c:Animation>
<AnimationName1>ShootFastRifle</AnimationName1>
<Time1>0.056234247235838808</Time1>
<AnimationName1>Idle</AnimationName1>
<Time1>0.17120540274882234</Time1>
<Speed1>1</Speed1>
<Speed2>1</Speed2>
<AnimationName2>Idl</AnimationName2>
<Speed2>0.10000000149011612</Speed2>
<AnimationName2>StrafeRigh</AnimationName2>
<Weight2>0.5</Weight2>
<Time2>1.8308673495784191</Time2>
<AnimationName3>StrafeRigh</AnimationName3>
<Time2>0.518960175468406</Time2>
<Weight3>0.5</Weight3>
<Time3>0.32167823998061529</Time3>
<Speed3>1</Speed3>
</c:Animation>
<c:AnimationOffset>
<AnimationName>AimRifle</AnimationName>
</c:AnimationOffset>
<c:Model>
<Resource>Models/Characters/Assault/AssaultAnimations.mesh</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:BoneAttachment>
<BoneName>R_Arm_Weapon_Joint</BoneName>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Weapons/Red/AssaultWeaponRed.mesh</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity>
<Components>
<c:Animation>
<AnimationName1>AimRifle</AnimationName1>
</c:Animation>
<c:Model>
<Resource>Models/Characters/Assault/AssaultAnimations.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="1" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
@@ -135,7 +158,8 @@
<Resource>Models/Weapons/Red/AssaultWeaponRed.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0" Y="0.803468645" Z="0"/>
<Position X="0.109895043" Y="0.999449849" Z="-0.10118784"/>
<Orientation X="-1.15886247" Y="0.230158985" Z="0.138214692"/>
</c:Transform>
</Components>
<Children/>
+37 -29
View File
@@ -274,26 +274,18 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector<Animation
}
glm::mat4 offset = GetOffsetTransform(bone, animationOffset);
if (JointTransforms.size() == 0) {
if (bone->Parent) {
if (offset != glm::mat4(1)) {
boneMatrix = parentMatrix * offset;// *((glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix));
} else {
boneMatrix = parentMatrix *((glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix));
}
boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix);
boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix;
} else {
boneMatrix = offset * glm::inverse(bone->OffsetMatrix);
boneMatrix = glm::inverse(bone->OffsetMatrix);
boneMatrices[bone->ID] = parentMatrix;
}
} else {
glm::vec3 finalPosInterp;
glm::quat finalRotInterp;
glm::vec3 finalScaleInterp;
JointFrameTransform jointFinalTransform;
float totalWeight = 0;
for (JointFrameTransform jointTransform : JointTransforms) {
@@ -303,26 +295,23 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector<Animation
for (JointFrameTransform jointTransform : JointTransforms) {
if (jointTransform.Weight == 1.0f) {
finalPosInterp = jointTransform.PositionInterp;
finalRotInterp = jointTransform.RotationInterp;
finalScaleInterp = jointTransform.ScaleInterp;
jointFinalTransform.PositionInterp = jointTransform.PositionInterp;
jointFinalTransform.RotationInterp = jointTransform.RotationInterp;
jointFinalTransform.ScaleInterp = jointTransform.ScaleInterp;
break;
} else {
finalPosInterp += jointTransform.PositionInterp * (jointTransform.Weight/totalWeight);
finalRotInterp *= glm::slerp(glm::quat(), jointTransform.RotationInterp, (jointTransform.Weight/totalWeight));
finalScaleInterp += jointTransform.ScaleInterp * (jointTransform.Weight/totalWeight);
jointFinalTransform.PositionInterp += jointTransform.PositionInterp * (jointTransform.Weight/totalWeight);
jointFinalTransform.RotationInterp *= glm::slerp(glm::quat(), jointTransform.RotationInterp, (jointTransform.Weight/totalWeight));
jointFinalTransform.ScaleInterp += jointTransform.ScaleInterp * (jointTransform.Weight/totalWeight);
}
}
JointFrameTransform offsetTransform = GetOffsetTransform(bone, animationOffset);
glm::mat4 boneTransform = AdditiveBlend(offsetTransform, jointFinalTransform);
if (offset != glm::mat4(1)) {
boneMatrix = parentMatrix * ((glm::translate(finalPosInterp) * glm::toMat4(finalRotInterp) * glm::scale(finalScaleInterp)) + offset);
} else {
boneMatrix = parentMatrix * (glm::translate(finalPosInterp) * glm::toMat4(finalRotInterp) * glm::scale(finalScaleInterp));
}
boneMatrix = parentMatrix * boneTransform;
boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix;
}
@@ -331,7 +320,20 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector<Animation
}
}
glm::mat4 Skeleton::GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset)
glm::mat4 Skeleton::AdditiveBlend(JointFrameTransform addTransform, JointFrameTransform transform)
{
addTransform.RotationInterp = glm::normalize(addTransform.RotationInterp);
transform.RotationInterp = glm::normalize(transform.RotationInterp);
glm::vec3 finalPos = addTransform.PositionInterp + (addTransform.PositionInterp - transform.PositionInterp);
glm::quat finalRot = addTransform.RotationInterp * addTransform.RotationInterp * glm::inverse(transform.RotationInterp); // Quaternions man...Who the fuck knows?
glm::vec3 finalScale = addTransform.ScaleInterp + (addTransform.ScaleInterp - transform.ScaleInterp);
return (glm::translate(finalPos) * glm::toMat4(finalRot) * glm::scale(finalScale));
}
Skeleton::JointFrameTransform Skeleton::GetOffsetTransform(const Bone* bone, AnimationOffset animationOffset)
{
const Animation* animation = animationOffset.animation;
float time = animationOffset.time;
@@ -383,7 +385,13 @@ glm::mat4 Skeleton::GetOffsetTransform(const Bone* bone, AnimationOffset animati
}
}
return (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale));
JointFrameTransform jointTransform;
jointTransform.PositionInterp = position;
jointTransform.RotationInterp = rotation;
jointTransform.ScaleInterp = scale;
return jointTransform;
}
@@ -452,7 +460,7 @@ glm::mat4 Skeleton::GetBoneTransform(const Bone* bone, const Animation* animatio
glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector<AnimationData> animations, AnimationOffset animationOffset, glm::mat4 childMatrix)
{
glm::mat4 boneMatrix;
/*
std::vector<JointFrameTransform> JointTransforms;
for (const AnimationData animationData : animations) {
@@ -569,9 +577,9 @@ glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::v
if (bone->Parent != nullptr) {
return GetBoneTransform(noRootMotion, bone->Parent, animations, animationOffset, boneMatrix);
} else {
} else {*/
return boneMatrix;
}
// }
}