-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created a motion weave asset and updated imgui to the newest version #50
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
#include <Volt/Asset/ParticlePreset.h> | ||
#include <Volt/Asset/Rendering/PostProcessingMaterial.h> | ||
#include <Volt/Asset/Rendering/PostProcessingStack.h> | ||
#include <Volt/Asset/Animation/MotionWeaveAsset.h> | ||
|
||
#include <Volt/Animation/BlendSpace.h> | ||
|
||
|
@@ -316,6 +317,7 @@ void AssetBrowserPanel::UpdateMainContent() | |
|
||
CreateNewShaderModal(); | ||
CreateNewMonoScriptModal(); | ||
CreateNewMotionWeaveGraphModal(); | ||
DeleteFilesModal(); | ||
} | ||
|
||
|
@@ -926,20 +928,29 @@ void AssetBrowserPanel::RenderWindowRightClickPopup() | |
|
||
if (ImGui::BeginMenu("Animation##Menu")) | ||
{ | ||
if (ImGui::MenuItem("Animated Character")) | ||
if (ImGui::MenuItem("Motion Weave Graph")) | ||
{ | ||
CreateNewAssetInCurrentDirectory(Volt::AssetType::AnimatedCharacter); | ||
CreateNewAssetInCurrentDirectory(Volt::AssetType::MotionWeave); | ||
} | ||
|
||
if (ImGui::MenuItem("Animation Graph")) | ||
if (ImGui::BeginMenu("Legacy##Menu")) | ||
{ | ||
CreateNewAssetInCurrentDirectory(Volt::AssetType::AnimationGraph); | ||
} | ||
if (ImGui::MenuItem("Animated Character")) | ||
{ | ||
CreateNewAssetInCurrentDirectory(Volt::AssetType::AnimatedCharacter); | ||
} | ||
|
||
if (ImGui::MenuItem("Blend Space")) | ||
{ | ||
CreateNewAssetInCurrentDirectory(Volt::AssetType::BlendSpace); | ||
if (ImGui::MenuItem("Animation Graph")) | ||
{ | ||
CreateNewAssetInCurrentDirectory(Volt::AssetType::AnimationGraph); | ||
} | ||
|
||
if (ImGui::MenuItem("Blend Space")) | ||
{ | ||
CreateNewAssetInCurrentDirectory(Volt::AssetType::BlendSpace); | ||
} | ||
} | ||
|
||
ImGui::EndMenu(); | ||
} | ||
|
||
|
@@ -1316,6 +1327,7 @@ void AssetBrowserPanel::CreateNewAssetInCurrentDirectory(Volt::AssetType type) | |
case Volt::AssetType::MonoScript: originalName = "idk.cs"; break; | ||
case Volt::AssetType::PostProcessingStack: originalName = "PPS_NewPostStack"; break; | ||
case Volt::AssetType::PostProcessingMaterial: originalName = "PPM_NewPostMaterial"; break; | ||
case Volt::AssetType::MotionWeave: originalName = "MW_NewMotionWeave"; break; | ||
} | ||
|
||
tempName = originalName; | ||
|
@@ -1422,6 +1434,13 @@ void AssetBrowserPanel::CreateNewAssetInCurrentDirectory(Volt::AssetType type) | |
newAssetHandle = postStack->handle; | ||
break; | ||
} | ||
|
||
case Volt::AssetType::MotionWeave: | ||
{ | ||
UI::OpenModal("New Motion Weave Graph##assetBrowser"); | ||
m_MotionWeaveTargetSkeleton = 0; | ||
break; | ||
} | ||
} | ||
|
||
Reload(); | ||
|
@@ -1691,3 +1710,54 @@ void AssetBrowserPanel::CreateNewMonoScriptModal() | |
UI::EndModal(); | ||
} | ||
} | ||
|
||
void AssetBrowserPanel::CreateNewMotionWeaveGraphModal() | ||
{ | ||
if (UI::BeginModal("New Motion Weave Graph##assetBrowser")) | ||
{ | ||
static std::string name; | ||
|
||
if (UI::BeginProperties("MotionWeaveProperties")) | ||
{ | ||
UI::Property("Name", name); | ||
EditorUtils::Property("Target Skeleton", m_MotionWeaveTargetSkeleton, Volt::AssetType::Skeleton); | ||
|
||
UI::EndProperties(); | ||
} | ||
|
||
const bool cantCreate = m_MotionWeaveTargetSkeleton == 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be compared to Asset::Null() |
||
ImGui::BeginDisabled(cantCreate); | ||
if (ImGui::Button("Create")) | ||
{ | ||
const std::string extension = Volt::AssetManager::GetExtensionFromAssetType(Volt::AssetType::MotionWeave); | ||
Ref<Volt::MotionWeaveAsset> motionWeave = Volt::AssetManager::CreateAsset<Volt::MotionWeaveAsset>( | ||
Volt::AssetManager::GetRelativePath(myCurrentDirectory->path), name + extension, m_MotionWeaveTargetSkeleton); | ||
Volt::AssetManager::SaveAsset(motionWeave); | ||
|
||
ImGui::CloseCurrentPopup(); | ||
} | ||
ImGui::EndDisabled(); | ||
if (cantCreate) | ||
{ | ||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) | ||
{ | ||
ImGui::BeginTooltip(); | ||
if (m_MotionWeaveTargetSkeleton == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be compared to Asset::Null() |
||
{ | ||
ImGui::Text("Need to select a skeleton to create"); | ||
} | ||
ImGui::EndTooltip(); | ||
} | ||
|
||
} | ||
ImGui::SameLine(); | ||
|
||
if (ImGui::Button("Cancel")) | ||
{ | ||
name = ""; | ||
ImGui::CloseCurrentPopup(); | ||
} | ||
|
||
UI::EndModal(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ class AssetBrowserPanel : public EditorWindow | |
void CreateNewAssetInCurrentDirectory(Volt::AssetType type); | ||
void CreateNewShaderModal(); | ||
void CreateNewMonoScriptModal(); | ||
void CreateNewMotionWeaveGraphModal(); | ||
|
||
struct NewShaderData | ||
{ | ||
|
@@ -119,6 +120,9 @@ class AssetBrowserPanel : public EditorWindow | |
///// Animation Graph creation ///// | ||
NewAnimationGraphData myNewAnimationGraphData{}; | ||
|
||
///// Motion Weave creation ///// | ||
Volt::AssetHandle m_MotionWeaveTargetSkeleton = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be = Asset::Null() |
||
|
||
Ref<AssetBrowser::DirectoryItem> ProcessDirectory(const std::filesystem::path& path, AssetBrowser::DirectoryItem* parent); | ||
std::unordered_map <std::filesystem::path, Ref<AssetBrowser::DirectoryItem>> myDirectories; | ||
Ref<AssetBrowser::SelectionManager> mySelectionManager; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,7 +309,6 @@ void ThemesPanel::SetMinecraftTheme() | |
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.4f, 0.67f, 1.000f, 1.000f); | ||
|
||
style.Colors[ImGuiCol_Tab] = ImVec4(0.137f, 0.137f, 0.137f, 1.000f); | ||
style.Colors[ImGuiCol_TabTop] = ImVec4(0.4f, 0.67f, 1.000f, 1.000f); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this removed? |
||
style.Colors[ImGuiCol_TabHovered] = ImVec4(0.352f, 0.352f, 0.352f, 1.000f); | ||
style.Colors[ImGuiCol_TabActive] = ImVec4(0.258f, 0.258f, 0.258f, 1.000f); | ||
style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.137f, 0.137f, 0.137f, 1.000f); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,5 @@ | |
|
||
#include <glm/glm.hpp> | ||
#include <Volt/Log/Log.h> | ||
|
||
#define IMGUI_DEFINE_MATH_OPERATORS |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could use emplace_back instead |
||
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; | ||
} | ||
|
||
} |
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; | ||
|
||
}; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be = Asset::Null()