Skip to content
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

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Volt/Sandbox/src/Sandbox/ImGuiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ void Sandbox::DrawMenuBar()
const ImRect menuBarRect = { ImGui::GetCursorPos(), {ImGui::GetContentRegionAvail().x, ImGui::GetFrameHeightWithSpacing()} };

ImGui::BeginGroup();
ImGui::GetCurrentWindow()->DC.IsSameLine = false; // have to explicitly set this to false, otherwise the menu bar will be offset on y after the first menu since SameLine isnt supported by Selectable
if (UI::BeginMenuBar(menuBarRect))
{
if (ImGui::BeginMenu("File"))
Expand Down Expand Up @@ -575,7 +576,7 @@ void Sandbox::DrawMenuBar()

ImGui::EndMenu();
}

if (ImGui::BeginMenu("Edit"))
{
if (ImGui::MenuItem("Undo", "Ctrl + Z"))
Expand Down Expand Up @@ -729,7 +730,7 @@ void Sandbox::DrawMenuBar()
std::filesystem::path defaultPath = Volt::ProjectManager::GetAudioBanksDirectory();
std::vector<std::string> eventNames = Amp::WwiseAudioManager::GetAllEventNames(defaultPath);

Volt::EnumGenerator generator{ "WWiseEvents"};
Volt::EnumGenerator generator{ "WWiseEvents" };
for (auto& event : eventNames)
{
if (event.empty()) continue;
Expand Down Expand Up @@ -792,7 +793,7 @@ void Sandbox::SaveSceneAsModal()
}

const auto relPath = Volt::AssetManager::Get().GetRelativePath(destPath.string() + "\\" + mySaveSceneData.name + ".vtscene");

//myRuntimeScene->CopyTo(myRuntimeScene);
myRuntimeScene->handle = {};

Expand Down
3 changes: 2 additions & 1 deletion Volt/Sandbox/src/Sandbox/NodeGraph/IONodeGraphEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#include <GraphKey/Nodes/CustomEventNode.h>
#include <GraphKey/TypeTraits.h>

#include <imgui_internal.h>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui.h>
#include <builders.h>
#include <typeindex>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <imgui_internal.h>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui.h>
#include "Sandbox/Utility/EditorResources.h"
#include "Volt/Rendering/Texture/Texture2D.h"
enum class IconType : ImU32
Expand Down Expand Up @@ -59,19 +60,19 @@ inline static void DrawIconKey(ImDrawList* drawList, const ImVec2& a, const ImVe
const auto tip_bottom = ImVec2(canvas_x + canvas_w * 0.5f, bottom);

drawList->PathLineTo(ImVec2(left, top) + ImVec2(0, rounding));
drawList->PathBezierCurveTo(
drawList->PathBezierCubicCurveTo(
ImVec2(left, top),
ImVec2(left, top),
ImVec2(left, top) + ImVec2(rounding, 0));
drawList->PathLineTo(tip_top);
drawList->PathLineTo(tip_top + (tip_right - tip_top) * tip_round);
drawList->PathBezierCurveTo(
drawList->PathBezierCubicCurveTo(
tip_right,
tip_right,
tip_bottom + (tip_right - tip_bottom) * tip_round);
drawList->PathLineTo(tip_bottom);
drawList->PathLineTo(ImVec2(left, bottom) + ImVec2(rounding, 0));
drawList->PathBezierCurveTo(
drawList->PathBezierCubicCurveTo(
ImVec2(left, bottom),
ImVec2(left, bottom),
ImVec2(left, bottom) - ImVec2(0, rounding));
Expand Down
86 changes: 78 additions & 8 deletions Volt/Sandbox/src/Sandbox/Window/AssetBrowser/AssetBrowserPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -316,6 +317,7 @@ void AssetBrowserPanel::UpdateMainContent()

CreateNewShaderModal();
CreateNewMonoScriptModal();
CreateNewMotionWeaveGraphModal();
DeleteFilesModal();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be = Asset::Null()

break;
}
}

Reload();
Expand Down Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The 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)
Copy link
Owner

Choose a reason for hiding this comment

The 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
Expand Up @@ -70,6 +70,7 @@ class AssetBrowserPanel : public EditorWindow
void CreateNewAssetInCurrentDirectory(Volt::AssetType type);
void CreateNewShaderModal();
void CreateNewMonoScriptModal();
void CreateNewMotionWeaveGraphModal();

struct NewShaderData
{
Expand Down Expand Up @@ -119,6 +120,9 @@ class AssetBrowserPanel : public EditorWindow
///// Animation Graph creation /////
NewAnimationGraphData myNewAnimationGraphData{};

///// Motion Weave creation /////
Volt::AssetHandle m_MotionWeaveTargetSkeleton = 0;
Copy link
Owner

Choose a reason for hiding this comment

The 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "BehaviorEditor.h"
#include "BehaviorPanel.h"
#include <Volt/Asset/Importers/BehaviorTreeImporter.h>
#include <imgui_internal.h>
#include <builders.h>
#include <typeindex>
#include <Volt/Utility/UIUtility.h>
Expand Down
1 change: 0 additions & 1 deletion Volt/Sandbox/src/Sandbox/Window/ThemesPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Owner

Choose a reason for hiding this comment

The 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);
Expand Down
2 changes: 1 addition & 1 deletion Volt/Sandbox/src/Sandbox/Window/Timeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ void Timeline::DrawClipsOnTrack(int trackIndex)

drawlist->AddRectFilledMultiColor(blendMinPos, blendMaxPos, IM_COL32(100, 100, 100, 90), IM_COL32(100, 100, 100, 90), IM_COL32(50, 50, 50, 90), IM_COL32(50, 50, 50, 90));

drawlist->AddBezierCurve(blendMinPos, ImVec2(blendXMidPos, blendMaxPos.y), ImVec2(blendXMidPos, blendMinPos.y), blendMaxPos, IM_COL32(255, 255, 255, 90), 1);
drawlist->AddBezierCubic(blendMinPos, ImVec2(blendXMidPos, blendMaxPos.y), ImVec2(blendXMidPos, blendMinPos.y), blendMaxPos, IM_COL32(255, 255, 255, 90), 1);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Volt/Sandbox/src/sbpch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

#include <glm/glm.hpp>
#include <Volt/Log/Log.h>

#define IMGUI_DEFINE_MATH_OPERATORS
86 changes: 86 additions & 0 deletions Volt/Volt/src/Volt/Animation/MotionWeaver.cpp
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;
Copy link
Owner

Choose a reason for hiding this comment

The 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;
}

}
43 changes: 43 additions & 0 deletions Volt/Volt/src/Volt/Animation/MotionWeaver.h
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;

};

}
Loading