Core/Animation: Move Sequence and SequenceJoint to Animation
This commit is contained in:
parent
4d77a25a04
commit
f121f32873
|
|
@ -104,7 +104,6 @@
|
|||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/ResourceSaver.hpp>
|
||||
#include <Nazara/Core/Sequence.hpp>
|
||||
#include <Nazara/Core/Serialization.hpp>
|
||||
#include <Nazara/Core/SignalHandlerAppComponent.hpp>
|
||||
#include <Nazara/Core/SkeletalMesh.hpp>
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ namespace Nz
|
|||
{
|
||||
public:
|
||||
using Params = AnimationParams;
|
||||
struct Sequence;
|
||||
struct SequenceJoint;
|
||||
|
||||
Animation();
|
||||
Animation(const Animation&) = delete;
|
||||
|
|
@ -97,6 +99,21 @@ namespace Nz
|
|||
static std::shared_ptr<Animation> LoadFromMemory(const void* data, std::size_t size, const AnimationParams& params = AnimationParams());
|
||||
static std::shared_ptr<Animation> LoadFromStream(Stream& stream, const AnimationParams& params = AnimationParams());
|
||||
|
||||
struct Sequence
|
||||
{
|
||||
std::string name;
|
||||
UInt32 firstFrame;
|
||||
UInt32 frameCount;
|
||||
UInt32 frameRate;
|
||||
};
|
||||
|
||||
struct SequenceJoint
|
||||
{
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f position = Vector3f::Zero();
|
||||
Vector3f scale = Vector3f::Unit();
|
||||
};
|
||||
|
||||
private:
|
||||
std::unique_ptr<AnimationImpl> m_impl;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Export.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_SEQUENCE_HPP
|
||||
#define NAZARA_CORE_SEQUENCE_HPP
|
||||
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct Sequence
|
||||
{
|
||||
std::string name;
|
||||
UInt32 firstFrame;
|
||||
UInt32 frameCount;
|
||||
UInt32 frameRate;
|
||||
};
|
||||
|
||||
struct SequenceJoint
|
||||
{
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f position = Vector3f::Zero();
|
||||
Vector3f scale = Vector3f::Unit();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_SEQUENCE_HPP
|
||||
|
|
@ -35,7 +35,6 @@ SOFTWARE.
|
|||
#include <Nazara/Core/Joint.hpp>
|
||||
#include <Nazara/Core/MaterialData.hpp>
|
||||
#include <Nazara/Core/PixelFormat.hpp>
|
||||
#include <Nazara/Core/Sequence.hpp>
|
||||
#include <Nazara/Core/SkeletalMesh.hpp>
|
||||
#include <Nazara/Core/Skeleton.hpp>
|
||||
#include <Nazara/Core/StaticMesh.hpp>
|
||||
|
|
@ -293,7 +292,7 @@ Nz::Result<std::shared_ptr<Nz::Animation>, Nz::ResourceLoadingError> LoadAnimati
|
|||
|
||||
anim->CreateSkeletal(maxFrameCount, parameters.skeleton->GetJointCount());
|
||||
|
||||
Nz::Sequence sequence;
|
||||
Nz::Animation::Sequence sequence;
|
||||
sequence.firstFrame = 0;
|
||||
sequence.frameCount = maxFrameCount;
|
||||
sequence.frameRate = static_cast<Nz::UInt32>((animation->mTicksPerSecond != 0.0) ? animation->mTicksPerSecond : 24.0);
|
||||
|
|
@ -322,7 +321,7 @@ Nz::Result<std::shared_ptr<Nz::Animation>, Nz::ResourceLoadingError> LoadAnimati
|
|||
|
||||
for (unsigned int frameIndex = 0; frameIndex < maxFrameCount; ++frameIndex)
|
||||
{
|
||||
Nz::SequenceJoint* sequenceJoints = anim->GetSequenceJoints(frameIndex);
|
||||
Nz::Animation::SequenceJoint* sequenceJoints = anim->GetSequenceJoints(frameIndex);
|
||||
|
||||
double frameTime = frameIndex * animation->mDuration / maxFrameCount;
|
||||
|
||||
|
|
@ -376,7 +375,7 @@ Nz::Result<std::shared_ptr<Nz::Animation>, Nz::ResourceLoadingError> LoadAnimati
|
|||
|
||||
for (unsigned int frameIndex = 0; frameIndex < maxFrameCount; ++frameIndex)
|
||||
{
|
||||
Nz::SequenceJoint* sequenceJoints = anim->GetSequenceJoints(frameIndex);
|
||||
Nz::Animation::SequenceJoint* sequenceJoints = anim->GetSequenceJoints(frameIndex);
|
||||
sequenceJoints[jointIndex].position = joint->GetPosition();
|
||||
sequenceJoints[jointIndex].rotation = joint->GetRotation();
|
||||
sequenceJoints[jointIndex].scale = joint->GetScale();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Export.hpp>
|
||||
#include <Nazara/Core/Joint.hpp>
|
||||
#include <Nazara/Core/Sequence.hpp>
|
||||
#include <Nazara/Core/Skeleton.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
|
@ -17,11 +16,11 @@ namespace Nz
|
|||
struct AnimationImpl
|
||||
{
|
||||
std::unordered_map<std::string, std::size_t, StringHash<>, std::equal_to<>> sequenceMap;
|
||||
std::vector<Sequence> sequences;
|
||||
std::vector<SequenceJoint> sequenceJoints; // Uniquement pour les animations squelettiques
|
||||
AnimationType type;
|
||||
std::vector<Animation::Sequence> sequences;
|
||||
std::vector<Animation::SequenceJoint> sequenceJoints; // Uniquement pour les animations squelettiques
|
||||
std::size_t frameCount;
|
||||
std::size_t jointCount; // Uniquement pour les animations squelettiques
|
||||
AnimationType type;
|
||||
};
|
||||
|
||||
bool AnimationParams::IsValid() const
|
||||
|
|
@ -130,7 +129,7 @@ namespace Nz
|
|||
return m_impl->jointCount;
|
||||
}
|
||||
|
||||
Sequence* Animation::GetSequence(std::string_view sequenceName)
|
||||
auto Animation::GetSequence(std::string_view sequenceName) -> Sequence*
|
||||
{
|
||||
NazaraAssert(m_impl, "Animation not created");
|
||||
|
||||
|
|
@ -144,7 +143,7 @@ namespace Nz
|
|||
return &m_impl->sequences[it->second];
|
||||
}
|
||||
|
||||
Sequence* Animation::GetSequence(std::size_t index)
|
||||
auto Animation::GetSequence(std::size_t index) -> Sequence*
|
||||
{
|
||||
NazaraAssert(m_impl, "Animation not created");
|
||||
NazaraAssert(index < m_impl->sequences.size(), "Sequence index out of range");
|
||||
|
|
@ -152,7 +151,7 @@ namespace Nz
|
|||
return &m_impl->sequences[index];
|
||||
}
|
||||
|
||||
const Sequence* Animation::GetSequence(std::string_view sequenceName) const
|
||||
auto Animation::GetSequence(std::string_view sequenceName) const -> const Sequence*
|
||||
{
|
||||
NazaraAssert(m_impl, "Animation not created");
|
||||
|
||||
|
|
@ -166,7 +165,7 @@ namespace Nz
|
|||
return &m_impl->sequences[it->second];
|
||||
}
|
||||
|
||||
const Sequence* Animation::GetSequence(std::size_t index) const
|
||||
auto Animation::GetSequence(std::size_t index) const -> const Sequence*
|
||||
{
|
||||
NazaraAssert(m_impl, "Animation not created");
|
||||
NazaraAssert(index < m_impl->sequences.size(), "Sequence index out of range");
|
||||
|
|
@ -195,20 +194,20 @@ namespace Nz
|
|||
return it->second;
|
||||
}
|
||||
|
||||
SequenceJoint* Animation::GetSequenceJoints(std::size_t frameIndex)
|
||||
auto Animation::GetSequenceJoints(std::size_t frameIndex) -> SequenceJoint*
|
||||
{
|
||||
NazaraAssert(m_impl, "Animation not created");
|
||||
NazaraAssert(m_impl->type == AnimationType::Skeletal, "Animation is not skeletal");
|
||||
|
||||
return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount];
|
||||
return &m_impl->sequenceJoints[frameIndex * m_impl->jointCount];
|
||||
}
|
||||
|
||||
const SequenceJoint* Animation::GetSequenceJoints(std::size_t frameIndex) const
|
||||
auto Animation::GetSequenceJoints(std::size_t frameIndex) const -> const SequenceJoint*
|
||||
{
|
||||
NazaraAssert(m_impl, "Animation not created");
|
||||
NazaraAssert(m_impl->type == AnimationType::Skeletal, "Animation is not skeletal");
|
||||
|
||||
return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount];
|
||||
return &m_impl->sequenceJoints[frameIndex * m_impl->jointCount];
|
||||
}
|
||||
|
||||
AnimationType Animation::GetType() const
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <Nazara/Core/Formats/MD5AnimLoader.hpp>
|
||||
#include <Nazara/Core/Animation.hpp>
|
||||
#include <Nazara/Core/Sequence.hpp>
|
||||
#include <Nazara/Core/Formats/MD5AnimParser.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -45,7 +44,7 @@ namespace Nz
|
|||
std::shared_ptr<Animation> animation = std::make_shared<Animation>();
|
||||
animation->CreateSkeletal(frameCount, jointCount);
|
||||
|
||||
Sequence sequence;
|
||||
Animation::Sequence sequence;
|
||||
sequence.firstFrame = 0;
|
||||
sequence.frameCount = frameCount;
|
||||
sequence.frameRate = frameRate;
|
||||
|
|
@ -53,7 +52,7 @@ namespace Nz
|
|||
|
||||
animation->AddSequence(sequence);
|
||||
|
||||
SequenceJoint* sequenceJoints = animation->GetSequenceJoints();
|
||||
Animation::SequenceJoint* sequenceJoints = animation->GetSequenceJoints();
|
||||
|
||||
// Pour que le squelette soit correctement aligné, il faut appliquer un quaternion "de correction" aux joints à la base du squelette
|
||||
Quaternionf rotationQuat = Quaternionf::RotationBetween(Vector3f::UnitX(), Vector3f::Forward()) *
|
||||
|
|
@ -68,7 +67,7 @@ namespace Nz
|
|||
{
|
||||
for (UInt32 jointIndex = 0; jointIndex < jointCount; ++jointIndex)
|
||||
{
|
||||
SequenceJoint& sequenceJoint = sequenceJoints[frameIndex * jointCount + jointIndex];
|
||||
Animation::SequenceJoint& sequenceJoint = sequenceJoints[frameIndex * jointCount + jointIndex];
|
||||
|
||||
Int32 parentId = joints[jointIndex].parent;
|
||||
if (parentId >= 0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue