Big skeletal animation update
Added MeshInfos demo Added MD5Mesh/MD5Anim loader support Added Node class Fixed ResourceParams not being exported Added support for skeletal animation (Animation/Mesh/Joint/SkeletalMesh/Skeleton) Meshes are now only stored with VertexStruct_XYZ_Normal_UV_Tangent type Moved Sequence declaration to Sequence.hpp -Animation: Renamed Create to Create[Keyframe|Skeletal] -AxisAlignedBox: Added Contains method Added GetCorner method Added GetCube method Added Transform method -Cube/Rect: Added GetPosition method Added GetSize method (Almost) Fixed ExtendTo method Fixed GetCenter method -File: Added GetDirectory static function Added GetPath method Renamed GetDirectoryPath method to GetDirectory -Math module: Fixed constructor/methods taking a non-const array GetNormal/Normalize methods now takes an optionnal integer pointer (returning length) Made all classes default constructor trivial Inverse, MakeIdentity, MakeZero, Normalize, Set methods now returns reference to object -Matrix4: Modified methods to avoid copies Removed COW (Too much overhead) Removed Concatenate[Affine] static function -Mesh: Renamed Create to Create[Keyframe|Skeletal|Static] Renamed Skin to Material -MeshParams: No longer takes declaration argument Renamed loadAnimations to animated Storage default to BufferStorage_Hardware if supported and BufferStorage_Software otherwise -OpenGL: Added glGetBooleanv function Added glIsEnabled function -Quaternion: Added ComputeW method Added Conjugate method -Renderer: Added IsEnabled static function Fixed GetLineWidth function not being static Removed SetVertexDeclaration -RenderWindow: Made CopyTo[Image|Texture] method constant -Resource Fixed RemoveResourceListener crash -ResourceLoader: Loaders are now used in a LIFO context -Stream: Renamed GetLine method to ReadLine -String: Fixed Simplified -Utility module Added configuration define for strict resource parsing -VertexBuffer Now takes a VertexDeclaration pointer -VertexDeclaration No longer throw an error when getting a non-existing element Former-commit-id: f7358c1231d6af48b799d2f24f077a001e16785b
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <Nazara/Utility/Animation.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
@@ -13,15 +14,17 @@ struct NzAnimationImpl
|
||||
{
|
||||
std::map<NzString, unsigned int> sequenceMap;
|
||||
std::vector<NzSequence> sequences;
|
||||
std::vector<NzSequenceJoint> sequenceJoints; // Uniquement pour les animations squelettiques
|
||||
nzAnimationType type;
|
||||
unsigned int frameCount;
|
||||
unsigned int jointCount; // Uniquement pour les animations squelettiques
|
||||
};
|
||||
|
||||
bool NzAnimationParams::IsValid() const
|
||||
{
|
||||
if (startFrame > endFrame)
|
||||
{
|
||||
NazaraError("Start frame must be lower than end frame");
|
||||
NazaraError("Start frame index must be smaller than end frame index");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -41,9 +44,34 @@ bool NzAnimation::AddSequence(const NzSequence& sequence)
|
||||
NazaraError("Animation not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sequence.frameCount == 0)
|
||||
{
|
||||
NazaraError("Sequence frame count must be over 0");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned int index = m_impl->sequences.size();
|
||||
if (m_impl->type == nzAnimationType_Skeletal)
|
||||
{
|
||||
unsigned int endFrame = sequence.firstFrame + sequence.frameCount - 1;
|
||||
if (endFrame >= m_impl->frameCount)
|
||||
{
|
||||
m_impl->frameCount = endFrame+1;
|
||||
m_impl->sequenceJoints.resize(m_impl->frameCount*m_impl->jointCount);
|
||||
}
|
||||
}
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
else
|
||||
{
|
||||
unsigned int endFrame = sequence.firstFrame + sequence.frameCount - 1;
|
||||
if (endFrame >= m_impl->frameCount)
|
||||
{
|
||||
NazaraError("Sequence end frame is over animation end frame");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!sequence.name.IsEmpty())
|
||||
{
|
||||
@@ -56,7 +84,7 @@ bool NzAnimation::AddSequence(const NzSequence& sequence)
|
||||
}
|
||||
#endif
|
||||
|
||||
m_impl->sequenceMap[sequence.name] = index;
|
||||
m_impl->sequenceMap[sequence.name] = m_impl->sequences.size();
|
||||
}
|
||||
|
||||
m_impl->sequences.push_back(sequence);
|
||||
@@ -64,17 +92,72 @@ bool NzAnimation::AddSequence(const NzSequence& sequence)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzAnimation::Create(nzAnimationType type, unsigned int frameCount)
|
||||
void NzAnimation::AnimateSkeleton(NzSkeleton* targetSkeleton, unsigned int frameA, unsigned int frameB, float interpolation) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Animation not created");
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_impl->type != nzAnimationType_Skeletal)
|
||||
{
|
||||
NazaraError("Animation is not skeletal");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!targetSkeleton || !targetSkeleton->IsValid())
|
||||
{
|
||||
NazaraError("Target skeleton is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetSkeleton->GetJointCount() != m_impl->jointCount)
|
||||
{
|
||||
NazaraError("Target skeleton joint count must match animation joint count");
|
||||
return;
|
||||
}
|
||||
|
||||
if (frameA >= m_impl->frameCount)
|
||||
{
|
||||
NazaraError("Frame A is out of range (" + NzString::Number(frameA) + " >= " + NzString::Number(m_impl->frameCount) + ')');
|
||||
return;
|
||||
}
|
||||
|
||||
if (frameB >= m_impl->frameCount)
|
||||
{
|
||||
NazaraError("Frame B is out of range (" + NzString::Number(frameB) + " >= " + NzString::Number(m_impl->frameCount) + ')');
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < 0.f || interpolation > 1.f)
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')');
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (unsigned int i = 0; i < m_impl->jointCount; ++i)
|
||||
{
|
||||
NzJoint* joint = targetSkeleton->GetJoint(i);
|
||||
|
||||
NzSequenceJoint& sequenceJointA = m_impl->sequenceJoints[frameA*m_impl->jointCount + i];
|
||||
NzSequenceJoint& sequenceJointB = m_impl->sequenceJoints[frameB*m_impl->jointCount + i];
|
||||
|
||||
joint->SetRotation(NzQuaternionf::Slerp(sequenceJointA.rotation, sequenceJointB.rotation, interpolation));
|
||||
joint->SetScale(NzVector3f::Lerp(sequenceJointA.scale, sequenceJointB.scale, interpolation));
|
||||
joint->SetTranslation(NzVector3f::Lerp(sequenceJointA.translation, sequenceJointB.translation, interpolation));
|
||||
}
|
||||
}
|
||||
|
||||
bool NzAnimation::CreateKeyframe(unsigned int frameCount)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (type == nzAnimationType_Static)
|
||||
{
|
||||
NazaraError("Invalid type");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (frameCount == 0)
|
||||
{
|
||||
NazaraError("Frame count must be over zero");
|
||||
@@ -84,7 +167,29 @@ bool NzAnimation::Create(nzAnimationType type, unsigned int frameCount)
|
||||
|
||||
m_impl = new NzAnimationImpl;
|
||||
m_impl->frameCount = frameCount;
|
||||
m_impl->type = type;
|
||||
m_impl->type = nzAnimationType_Keyframe;
|
||||
|
||||
NotifyCreated();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzAnimation::CreateSkeletal(unsigned int frameCount, unsigned int jointCount)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (frameCount == 0)
|
||||
{
|
||||
NazaraError("Frame count must be over zero");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_impl = new NzAnimationImpl;
|
||||
m_impl->frameCount = frameCount;
|
||||
m_impl->jointCount = jointCount;
|
||||
m_impl->sequenceJoints.resize(frameCount*jointCount);
|
||||
m_impl->type = nzAnimationType_Skeletal;
|
||||
|
||||
NotifyCreated();
|
||||
return true;
|
||||
@@ -122,18 +227,19 @@ NzSequence* NzAnimation::GetSequence(const NzString& sequenceName)
|
||||
NazaraError("Animation not created");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
auto it = m_impl->sequenceMap.find(sequenceName);
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (it == m_impl->sequenceMap.end())
|
||||
{
|
||||
NazaraError("Sequence not found");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return &m_impl->sequences[it->second];
|
||||
#else
|
||||
return &m_impl->sequences[m_impl->sequenceMap[sequenceName]];
|
||||
#endif
|
||||
}
|
||||
|
||||
NzSequence* NzAnimation::GetSequence(unsigned int index)
|
||||
@@ -163,18 +269,19 @@ const NzSequence* NzAnimation::GetSequence(const NzString& sequenceName) const
|
||||
NazaraError("Animation not created");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
auto it = m_impl->sequenceMap.find(sequenceName);
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (it == m_impl->sequenceMap.end())
|
||||
{
|
||||
NazaraError("Sequence not found");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return &m_impl->sequences[it->second];
|
||||
#else
|
||||
return &m_impl->sequences[m_impl->sequenceMap[sequenceName]];
|
||||
#endif
|
||||
}
|
||||
|
||||
const NzSequence* NzAnimation::GetSequence(unsigned int index) const
|
||||
@@ -217,18 +324,57 @@ int NzAnimation::GetSequenceIndex(const NzString& sequenceName) const
|
||||
NazaraError("Animation not created");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
auto it = m_impl->sequenceMap.find(sequenceName);
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (it == m_impl->sequenceMap.end())
|
||||
{
|
||||
NazaraError("Sequence not found");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return it->second;
|
||||
#else
|
||||
return m_impl->sequenceMap[sequenceName];
|
||||
}
|
||||
|
||||
NzSequenceJoint* NzAnimation::GetSequenceJoints(unsigned int frameIndex)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Animation not created");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (m_impl->type != nzAnimationType_Skeletal)
|
||||
{
|
||||
NazaraError("Animation is not skeletal");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount];
|
||||
}
|
||||
|
||||
const NzSequenceJoint* NzAnimation::GetSequenceJoints(unsigned int frameIndex) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Animation not created");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (m_impl->type != nzAnimationType_Skeletal)
|
||||
{
|
||||
NazaraError("Animation is not skeletal");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount];
|
||||
}
|
||||
|
||||
nzAnimationType NzAnimation::GetType() const
|
||||
|
||||
Reference in New Issue
Block a user