Implemented Animation Clip asset and animation controller #410
|
@ -22,6 +22,7 @@ namespace SHADE
|
||||||
SHRawAnimation::SHRawAnimation(const SHAnimAsset& asset)
|
SHRawAnimation::SHRawAnimation(const SHAnimAsset& asset)
|
||||||
: ticksPerSecond { static_cast<int>(asset.ticksPerSecond) }
|
: ticksPerSecond { static_cast<int>(asset.ticksPerSecond) }
|
||||||
, totalTime { static_cast<float>(asset.duration) / static_cast<int>(asset.ticksPerSecond) }
|
, totalTime { static_cast<float>(asset.duration) / static_cast<int>(asset.ticksPerSecond) }
|
||||||
|
, totalFrames { static_cast<int>(asset.duration) }
|
||||||
{
|
{
|
||||||
// Populate keyframes
|
// Populate keyframes
|
||||||
for (const auto& channel : asset.nodeChannels)
|
for (const auto& channel : asset.nodeChannels)
|
||||||
|
|
|
@ -67,6 +67,7 @@ namespace SHADE
|
||||||
const std::vector<Channel>& GetChannels() const noexcept { return channels; }
|
const std::vector<Channel>& GetChannels() const noexcept { return channels; }
|
||||||
int GetTicksPerSecond() const noexcept { return ticksPerSecond; }
|
int GetTicksPerSecond() const noexcept { return ticksPerSecond; }
|
||||||
float GetTotalTime() const noexcept { return totalTime; }
|
float GetTotalTime() const noexcept { return totalTime; }
|
||||||
|
int GetTotalFrames() const noexcept { return totalFrames; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -75,6 +76,7 @@ namespace SHADE
|
||||||
std::vector<Channel> channels;
|
std::vector<Channel> channels;
|
||||||
int ticksPerSecond;
|
int ticksPerSecond;
|
||||||
float totalTime;
|
float totalTime;
|
||||||
|
int totalFrames;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
|
|
|
@ -12,6 +12,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STL Includes
|
// STL Includes
|
||||||
|
#include <vector>
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "Resource/SHHandle.h"
|
#include "Resource/SHHandle.h"
|
||||||
#include "Editor/EditorWindow/SHEditorWindow.h"
|
#include "Editor/EditorWindow/SHEditorWindow.h"
|
||||||
|
@ -19,6 +20,9 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Editor for modifying the Animation Controller state machine.
|
||||||
|
/// </summary>
|
||||||
class SHAnimationControllerEditor final : public SHEditorWindow
|
class SHAnimationControllerEditor final : public SHEditorWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -36,10 +40,35 @@ namespace SHADE
|
||||||
void Exit() override;
|
void Exit() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
union NodeAttributeIndex
|
||||||
|
{
|
||||||
|
int16_t Raw;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint8_t OwnerNodeIndex;
|
||||||
|
uint8_t AttributeIndex;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
union NodeLinkIndex
|
||||||
|
{
|
||||||
|
int32_t Raw;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
NodeAttributeIndex SourceAttribute;
|
||||||
|
NodeAttributeIndex DestinationAttribute;
|
||||||
|
};
|
||||||
|
}; // What about same source and destination but different link?
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
SHAnimationController controller;
|
SHAnimationController controller;
|
||||||
|
std::vector<std::vector<NodeAttributeIndex>> inputNodesMap;
|
||||||
|
std::vector<std::vector<NodeAttributeIndex>> outputNodesMap;
|
||||||
|
std::vector<NodeLinkIndex> linkIndices; // Encodes details of the link in the node index
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "Serialization/SHSerialization.h"
|
#include "Serialization/SHSerialization.h"
|
||||||
#include <Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h>
|
#include <Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h>
|
||||||
#include "Serialization/Prefab/SHPrefabManager.h"
|
#include "Serialization/Prefab/SHPrefabManager.h"
|
||||||
|
#include "Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -371,14 +372,18 @@ namespace SHADE
|
||||||
case AssetType::SHADER: break;
|
case AssetType::SHADER: break;
|
||||||
case AssetType::SHADER_BUILT_IN: break;
|
case AssetType::SHADER_BUILT_IN: break;
|
||||||
case AssetType::TEXTURE: break;
|
case AssetType::TEXTURE: break;
|
||||||
|
case AssetType::MODEL:
|
||||||
|
if (auto animInspector = SHEditorWindowManager::GetEditorWindow<SHRawAnimInspector>())
|
||||||
|
{
|
||||||
|
animInspector->Open(asset->id);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case AssetType::MESH: break;
|
case AssetType::MESH: break;
|
||||||
case AssetType::SCENE:
|
case AssetType::SCENE:
|
||||||
{
|
|
||||||
if (editor->LoadScene(asset->id))
|
if (editor->LoadScene(asset->id))
|
||||||
{
|
{
|
||||||
editor->editorConfig->workingSceneID = asset->id;
|
editor->editorConfig->workingSceneID = asset->id;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case AssetType::PREFAB: break;
|
case AssetType::PREFAB: break;
|
||||||
case AssetType::MATERIAL:
|
case AssetType::MATERIAL:
|
||||||
|
|
|
@ -0,0 +1,170 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHRawAnimInspector.cpp
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Mar 1, 2023
|
||||||
|
\brief Contains the definition of SHRawAnimInspector's functions.
|
||||||
|
|
||||||
|
|
||||||
|
Copyright (C) 2023 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHRawAnimInspector.h"
|
||||||
|
|
||||||
|
// STL Includes
|
||||||
|
#include <format>
|
||||||
|
// External Dependencies
|
||||||
|
#include <imgui.h>
|
||||||
|
#include <misc/cpp/imgui_stdlib.h>
|
||||||
|
// Project Includes
|
||||||
|
#include "Editor/IconsMaterialDesign.h"
|
||||||
|
#include "Animation/SHAnimationClip.h"
|
||||||
|
#include "Resource/SHResourceManager.h"
|
||||||
|
#include "Editor/EditorWindow/SHEditorWindowManager.h"
|
||||||
|
#include "Editor/SHEditorUI.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* SHAnimClipCreatePrompt - Cosntructors/Destructors */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
SHAnimClipCreatePrompt::SHAnimClipCreatePrompt()
|
||||||
|
: SHPopUpWindow("Create Animation Clip", true, 0, 0) {}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* SHAnimClipCreatePrompt - Lifecycle Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void SHAnimClipCreatePrompt::Init(Handle<SHRawAnimation> rawAnim)
|
||||||
|
{
|
||||||
|
rawAnimation = rawAnim;
|
||||||
|
|
||||||
|
// Set default parameters
|
||||||
|
if (rawAnimation)
|
||||||
|
{
|
||||||
|
newAssetName.clear();
|
||||||
|
firstIndex = 0;
|
||||||
|
lastIndex = rawAnimation->GetTotalFrames();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHAnimClipCreatePrompt::Draw()
|
||||||
|
{
|
||||||
|
if (Begin())
|
||||||
|
{
|
||||||
|
// Properties
|
||||||
|
SHEditorUI::InputTextField("Name", newAssetName);
|
||||||
|
SHEditorUI::PushID(0);
|
||||||
|
SHEditorUI::InputSlider("First Frame Index", 0, rawAnimation->GetTotalFrames(), firstIndex);
|
||||||
|
SHEditorUI::PopID();
|
||||||
|
SHEditorUI::PushID(1);
|
||||||
|
SHEditorUI::InputSlider("Last Frame Index", 0, rawAnimation->GetTotalFrames(), lastIndex);
|
||||||
|
SHEditorUI::PopID();
|
||||||
|
|
||||||
|
// Invalid values
|
||||||
|
const bool INVALID_CONFIG = newAssetName.empty() || firstIndex > lastIndex || lastIndex < firstIndex;
|
||||||
|
|
||||||
|
// Buttons
|
||||||
|
ImGui::BeginDisabled(INVALID_CONFIG);
|
||||||
|
{
|
||||||
|
if (ImGui::Button("Save"))
|
||||||
|
{
|
||||||
|
// Generate new asset
|
||||||
|
|
||||||
|
|
||||||
|
// Close
|
||||||
|
isOpen = false;
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndDisabled();
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Cancel"))
|
||||||
|
{
|
||||||
|
// Close
|
||||||
|
isOpen = false;
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Cosntructors/Destructors */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
SHRawAnimInspector::SHRawAnimInspector()
|
||||||
|
: SHEditorWindow("Animation Editor", ImGuiWindowFlags_MenuBar)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Lifecycle Functions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
void SHRawAnimInspector::Init()
|
||||||
|
{
|
||||||
|
SHEditorWindow::Init();
|
||||||
|
|
||||||
|
SHEditorWindowManager::CreatePopupWindow<SHAnimClipCreatePrompt>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHRawAnimInspector::Update()
|
||||||
|
{
|
||||||
|
SHEditorWindow::Update();
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
if (Begin())
|
||||||
|
{
|
||||||
|
|
||||||
|
// Ignore if no asset
|
||||||
|
if (currRawAnim)
|
||||||
|
{
|
||||||
|
drawMenuBar();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Button to add a new clip
|
||||||
|
if (ImGui::Button(std::format("{} Add", ICON_MD_ADD).data()))
|
||||||
|
{
|
||||||
|
auto prompt = SHEditorWindowManager::GetPopupWindow<SHAnimClipCreatePrompt>();
|
||||||
|
prompt->Init(currRawAnim);
|
||||||
|
prompt->isOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render all clips
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHRawAnimInspector::Exit()
|
||||||
|
{
|
||||||
|
SHEditorWindow::Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Usage Functions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
void SHRawAnimInspector::Open(AssetID assetId)
|
||||||
|
{
|
||||||
|
currRawAnim = SHResourceManager::LoadOrGet<SHRawAnimation>(assetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Helper Functions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
void SHRawAnimInspector::drawMenuBar()
|
||||||
|
{
|
||||||
|
if (ImGui::BeginMenuBar())
|
||||||
|
{
|
||||||
|
if (ImGui::Button(std::format("{} Save", ICON_MD_SAVE).data()))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& ASSET_NAME = SHResourceManager::GetAssetName<SHRawAnimation>(currRawAnim).value_or("Unnamed Asset");
|
||||||
|
ImGui::Text(ASSET_NAME.c_str());
|
||||||
|
|
||||||
|
ImGui::EndMenuBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHRawAnimInspector.h
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Mar 2, 2023
|
||||||
|
\brief Contains the definition of SHRawAnimInspector.
|
||||||
|
|
||||||
|
Copyright (C) 2023 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Project Includes
|
||||||
|
#include "Assets/SHAssetMacros.h"
|
||||||
|
#include "Editor/EditorWindow/SHEditorWindow.h"
|
||||||
|
#include "Resource/SHHandle.h"
|
||||||
|
#include "Animation/SHRawAnimation.h"
|
||||||
|
#include "Editor/EditorWindow/SHPopUpWindow.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Prompt for creating an animation clip. Init() must be called to pass in the correct
|
||||||
|
/// SHRawAnimation that the created clip will use.
|
||||||
|
/// </summary>
|
||||||
|
class SHAnimClipCreatePrompt : public SHPopUpWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Constructors/Destructors */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
SHAnimClipCreatePrompt();
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Lifecycle Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void Init(Handle<SHRawAnimation> rawAnim);
|
||||||
|
void Draw() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
std::string newAssetName;
|
||||||
|
int firstIndex;
|
||||||
|
int lastIndex;
|
||||||
|
Handle<SHRawAnimation> rawAnimation;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Editor for generating SHAnimationClips from a single SHRawAnimation object.
|
||||||
|
/// </summary>
|
||||||
|
class SHRawAnimInspector final : public SHEditorWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Constructors/Destructors */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
SHRawAnimInspector();
|
||||||
|
~SHRawAnimInspector() = default;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Lifecycle Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void Init() override;
|
||||||
|
void Update() override;
|
||||||
|
void Exit() override;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Usage Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void Open(AssetID assetId);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Handle<SHRawAnimation> currRawAnim;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Helper Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void drawMenuBar();
|
||||||
|
};
|
||||||
|
}
|
|
@ -9,3 +9,4 @@
|
||||||
#include "ColliderTagPanel/SHColliderTagPanel.h" // Collider Tag Panel
|
#include "ColliderTagPanel/SHColliderTagPanel.h" // Collider Tag Panel
|
||||||
#include "InputBindings/SHInputBindingsPanel.h" // Input Bindings
|
#include "InputBindings/SHInputBindingsPanel.h" // Input Bindings
|
||||||
#include "EditorWindow/Animation/SHAnimationControllerEditor.h" // Animation Controller Editor
|
#include "EditorWindow/Animation/SHAnimationControllerEditor.h" // Animation Controller Editor
|
||||||
|
#include "EditorWindow/RawAnimationInspector/SHRawAnimInspector.h" // Raw Animation Inspector
|
||||||
|
|
|
@ -118,6 +118,7 @@ namespace SHADE
|
||||||
|
|
||||||
SHEditorWindowManager::CreateEditorWindow<SHEditorViewport>();
|
SHEditorWindowManager::CreateEditorWindow<SHEditorViewport>();
|
||||||
SHEditorWindowManager::CreateEditorWindow<SHAnimationControllerEditor>();
|
SHEditorWindowManager::CreateEditorWindow<SHAnimationControllerEditor>();
|
||||||
|
SHEditorWindowManager::CreateEditorWindow<SHRawAnimInspector>();
|
||||||
|
|
||||||
//Add popup windows
|
//Add popup windows
|
||||||
SHEditorWindowManager::CreatePopupWindow<SHSceneSavePrompt>();
|
SHEditorWindowManager::CreatePopupWindow<SHSceneSavePrompt>();
|
||||||
|
|
Loading…
Reference in New Issue