-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ae4ca5
commit e25e21d
Showing
13 changed files
with
404 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include "vtpch.h" | ||
#include "MotionWeaver.h" | ||
#include "Volt/Log/Log.h" | ||
|
||
#include "Volt/Animation/AnimationManager.h" | ||
|
||
#include "Volt/Asset/Animation/Animation.h" | ||
#include "Volt/Asset/Animation/Skeleton.h" | ||
#include "Volt/Asset/AssetManager.h" | ||
|
||
namespace Volt | ||
{ | ||
|
||
MotionWeaver::MotionWeaver(Ref<MotionWeaveAsset> motionWeaveAsset, Ref<Skeleton> skeleton) | ||
: m_MotionWeaveAsset(motionWeaveAsset), m_Skeleton(skeleton) | ||
{ | ||
assert(m_MotionWeaveAsset); | ||
assert(m_Skeleton); | ||
} | ||
|
||
MotionWeaver::~MotionWeaver() | ||
{ | ||
} | ||
|
||
void MotionWeaver::Update(float deltaTime) | ||
{ | ||
if (m_MotionWeaveAsset->GetMotionWeaveAssetEntries().empty()) | ||
{ | ||
return; | ||
} | ||
|
||
if (m_Entries.empty()) | ||
{ | ||
MotionWeaveAssetEntry& entry = m_MotionWeaveAsset->GetMotionWeaveAssetEntries()[0]; | ||
|
||
MotionWeaveEntry newEntry; | ||
newEntry.animation = AssetManager::GetAsset<Animation>(entry.animation); | ||
newEntry.speed = 1; | ||
newEntry.weight = 1; | ||
newEntry.looping = true; | ||
newEntry.startTime = 0; | ||
|
||
m_Entries.push_back(newEntry); | ||
} | ||
} | ||
|
||
const std::vector<glm::mat4> MotionWeaver::Sample() | ||
{ | ||
if (m_Entries.empty()) | ||
{ | ||
return std::vector<glm::mat4>(); | ||
} | ||
|
||
auto targetEntry = m_Entries.front(); | ||
const Animation::Pose sample = targetEntry.animation->SamplePose(targetEntry.startTime, AnimationManager::globalClock, m_Skeleton, targetEntry.looping, targetEntry.speed); | ||
const auto& invBindPose = m_Skeleton->GetInverseBindPose(); | ||
|
||
if(sample.localTRS.size() != invBindPose.size()) | ||
{ | ||
VT_CORE_ERROR("Sampled pose size does not match inverse bind pose size"); | ||
return std::vector<glm::mat4>(); | ||
} | ||
if (sample.localTRS.empty()) | ||
{ | ||
VT_CORE_ERROR("Sampled pose is empty"); | ||
return std::vector<glm::mat4>(); | ||
} | ||
|
||
std::vector<glm::mat4> result{}; | ||
result.resize(sample.localTRS.size()); | ||
|
||
glm::vec3 rootMotion = sample.localTRS[0].position - m_PrevRootPosition; | ||
m_PrevRootPosition = sample.localTRS[0].position; | ||
|
||
for (size_t i = 0; i < sample.localTRS.size(); i++) | ||
{ | ||
const auto& trs = sample.localTRS.at(i); | ||
|
||
const glm::mat4 transform = glm::translate(glm::mat4{ 1.f }, trs.position)* glm::mat4_cast(trs.rotation)* glm::scale(glm::mat4{ 1.f }, trs.scale); | ||
result[i] = transform * invBindPose[i]; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
|
||
#include "Volt/Asset/Animation/MotionWeaveAsset.h" | ||
|
||
#include <glm/glm.hpp> | ||
|
||
//this class will be used to control the animation of a character | ||
//It works by having a main animation and a list of all the previous animations, the main animation has a weight that increases to 1 over time, the previous animations have a weight that decreases to 0 over time | ||
//when the weight of a previous animation reaches 0, it is removed from the list | ||
namespace Volt | ||
{ | ||
class Animation; | ||
class Skeleton; | ||
|
||
struct MotionWeaveEntry | ||
{ | ||
Ref<Animation> animation; | ||
float weight = 0.f; | ||
float speed = 1.f; | ||
float startTime = 0.f; | ||
bool looping = true; | ||
}; | ||
class MotionWeaver | ||
{ | ||
public: | ||
MotionWeaver(Ref<MotionWeaveAsset> motionWeaveAsset, Ref<Skeleton> skeleton); | ||
~MotionWeaver(); | ||
|
||
void Update(float deltaTime); | ||
|
||
const std::vector<glm::mat4> Sample(); | ||
|
||
private: | ||
Ref<MotionWeaveAsset> m_MotionWeaveAsset; | ||
Ref<Skeleton> m_Skeleton; | ||
|
||
glm::vec3 m_PrevRootPosition; | ||
|
||
std::vector<MotionWeaveEntry> m_Entries; | ||
|
||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "vtpch.h" | ||
#include "MotionWeaveAsset.h" | ||
|
||
namespace Volt | ||
{ | ||
MotionWeaveAsset::MotionWeaveAsset(Volt::AssetHandle targetSkeletonHandle) | ||
:m_TargetSkeletonHandle(targetSkeletonHandle) | ||
{ | ||
} | ||
std::vector<MotionWeaveAssetEntry> Volt::MotionWeaveAsset::GetMotionWeaveAssetEntries() | ||
{ | ||
return m_MotionWeaveAssetEntries; | ||
} | ||
} |
Oops, something went wrong.