Skip to content

Commit

Permalink
Animation Workflow Working, need to allow changing of animation data …
Browse files Browse the repository at this point in the history
…in sequencer
  • Loading branch information
tomheeleynz committed Jul 31, 2023
1 parent 551d273 commit a032271
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 37 deletions.
10 changes: 10 additions & 0 deletions Arcane/src/Arcane/Animation/AnimationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

namespace Arcane
{
struct AnimationLink
{
Animation* from;
Animation* to;
};

class AnimationController : public Asset
{
public:
Expand All @@ -19,7 +25,11 @@ namespace Arcane
void AddAnimation(std::string name, Animation* animation) { m_Animations[name] = animation; };

std::map<std::string, Animation*> GetAnimations() { return m_Animations; }

std::vector<AnimationLink> GetLinks() { return m_AnimationLinks; }
void AddLink(AnimationLink& link) { m_AnimationLinks.push_back(link); }
private:
std::vector<AnimationLink> m_AnimationLinks;
std::map<std::string, Animation*> m_Animations;
std::string m_CurrentAnimation;
};
Expand Down
3 changes: 2 additions & 1 deletion Arcane/src/Arcane/Platform/Vulkan/VulkanImGuiLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ namespace Arcane {

ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking for ImGui
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking for ImGui
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows

float fontSize = 18.0f;

Expand Down
44 changes: 26 additions & 18 deletions Arcane/src/Arcane/Renderer/SceneRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ namespace Arcane
s_Data.quadCount++;
}

void SceneRenderer::SubmitAnimatedQuad(TransformComponent& transformComponent, SpriteRendererComponent& spriteRendererComponent, Animator& animatorComponent)
void SceneRenderer::SubmitAnimatedQuad(TransformComponent& transformComponent, SpriteRendererComponent& spriteRendererComponent, Animator& animatorComponent, bool playAnimation)
{
int quadSize = 4;

Expand All @@ -653,29 +653,37 @@ namespace Arcane
}

AnimData newData;

Animation* currentAnimation = animatorComponent.controller->GetCurrentAnimation();
KeyFrame* currentKeyFrame = currentAnimation->GetCurrentKeyFrame();

if (currentKeyFrame->GetType() == KeyFrameType::TWO_DIMENSIONAL)
{
KeyFrame2D* currentKeyFrame2D = static_cast<KeyFrame2D*>(currentKeyFrame);

if (currentAnimation->CurrentFrameCount >= currentKeyFrame2D->GetKeyFrameLength()) {
currentAnimation->SetNextKeyFrame();
currentAnimation->CurrentFrameCount = 0;
}
else {
currentAnimation->CurrentFrameCount += 1;
if (currentAnimation == nullptr || animatorComponent.controller == nullptr || playAnimation == false) {
newData.currentFrameCountX = 0;
newData.currentFrameCountY = 0;
newData.totalFrameCountX = 6;
newData.totalFrameCountY = 1;
}
else {
KeyFrame* currentKeyFrame = currentAnimation->GetCurrentKeyFrame();

if (currentKeyFrame->GetType() == KeyFrameType::TWO_DIMENSIONAL)
{
KeyFrame2D* currentKeyFrame2D = static_cast<KeyFrame2D*>(currentKeyFrame);

if (currentAnimation->CurrentFrameCount >= currentKeyFrame2D->GetKeyFrameLength()) {
currentAnimation->SetNextKeyFrame();
currentAnimation->CurrentFrameCount = 0;
}
else {
currentAnimation->CurrentFrameCount += 1;
}

newData.currentFrameCountX = currentKeyFrame2D->GetImageIndexX();
newData.currentFrameCountY = currentKeyFrame2D->GetImageIndexY();
}

newData.currentFrameCountX = currentKeyFrame2D->GetImageIndexX();
newData.currentFrameCountY = currentKeyFrame2D->GetImageIndexY();
newData.totalFrameCountX = 6;
newData.totalFrameCountY = 1;
}

newData.totalFrameCountX = 6;
newData.totalFrameCountY = 1;

if (spriteRendererComponent.sprite == nullptr)
s_Data.AnimatedQuadTextures[s_Data.animatedQuadCount] = s_Data.QuadBaseTexture;
else
Expand Down
2 changes: 1 addition & 1 deletion Arcane/src/Arcane/Renderer/SceneRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Arcane
void SetCamera(Camera* camera);
void SubmitMesh(Mesh* mesh, TransformComponent& component, Material* material);
void SubmitQuad(TransformComponent& transformComponent, SpriteRendererComponent& spriteRendererComponent);
void SubmitAnimatedQuad(TransformComponent& transformComponent, SpriteRendererComponent& spriteRendererComponent, Animator& animatorComponent);
void SubmitAnimatedQuad(TransformComponent& transformComponent, SpriteRendererComponent& spriteRendererComponent, Animator& animatorComponent, bool playAnimation);

// Lighting code
void SetDirectionalLight(LightComponent& light, TransformComponent& transform);
Expand Down
10 changes: 8 additions & 2 deletions Arcane/src/Arcane/Scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace Arcane
Entity entityHandle = Entity(entity, this);

if (entityHandle.HasComponent<Animator>())
m_SceneRenderer->SubmitAnimatedQuad(transformComponent, spriteRendererComponent, entityHandle.GetComponent<Animator>());
m_SceneRenderer->SubmitAnimatedQuad(transformComponent, spriteRendererComponent, entityHandle.GetComponent<Animator>(), false);
else
m_SceneRenderer->SubmitQuad(transformComponent, spriteRendererComponent);
}
Expand Down Expand Up @@ -285,7 +285,13 @@ namespace Arcane
{
auto& spriteRendererComponent = view.get<SpriteRendererComponent>(entity);
auto& transformComponent = view.get<TransformComponent>(entity);
m_SceneRenderer->SubmitQuad(transformComponent, spriteRendererComponent);

Entity entityHandle = Entity(entity, this);

if (entityHandle.HasComponent<Animator>())
m_SceneRenderer->SubmitAnimatedQuad(transformComponent, spriteRendererComponent, entityHandle.GetComponent<Animator>(), true);
else
m_SceneRenderer->SubmitQuad(transformComponent, spriteRendererComponent);
}
}

Expand Down
22 changes: 11 additions & 11 deletions EnchantingTable/src/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,23 +290,23 @@ void EditorLayer::OnScenePlay()
{
m_State = SceneState::PLAY;

m_RuntimeScene = Arcane::Scene::Copy(m_EditorScene);
m_ActiveScene = m_RuntimeScene;
//m_RuntimeScene = Arcane::Scene::Copy(m_EditorScene);
//m_ActiveScene = m_RuntimeScene;

m_ActiveScene->SetSceneRenderer(m_SceneRenderer);
//m_ActiveScene->SetSceneRenderer(m_SceneRenderer);

m_ActiveScene->OnRuntimeStart();

m_ScenePanel->SetContext(m_ActiveScene);
//m_ActiveScene->OnRuntimeStart();
//
//m_ScenePanel->SetContext(m_ActiveScene);
}

void EditorLayer::OnSceneStop()
{
m_State = SceneState::EDIT;
m_ActiveScene = m_EditorScene;
//m_ActiveScene = m_EditorScene;

delete m_RuntimeScene;
m_RuntimeScene = nullptr;

m_ScenePanel->SetContext(m_ActiveScene);
//delete m_RuntimeScene;
//m_RuntimeScene = nullptr;
//
//m_ScenePanel->SetContext(m_ActiveScene);
}
3 changes: 3 additions & 0 deletions EnchantingTable/src/Panels/AnimationControllerPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void AnimationControllerPanel::OnImGuiRender()
newNode.templateIndex = 1;
newNode.x = 300.0f;
newNode.y = 0.0f;
newNode.animation = val;

m_Delegate.mNodes.push_back(newNode);
}
Expand All @@ -64,6 +65,7 @@ void AnimationControllerPanel::OnImGuiRender()
newNode.templateIndex = 1;
newNode.x = 300.0f;
newNode.y = 0.0f;
newNode.animation = animation;

m_Delegate.mNodes.push_back(newNode);
m_AnimationController->AddAnimation(animation->GetName(), animation);
Expand All @@ -88,6 +90,7 @@ void AnimationControllerPanel::OnImGuiRender()
{
Arcane::AnimationController* controller = static_cast<Arcane::AnimationController*>(asset);
m_AnimationController = controller;
m_Delegate.controller = controller;
}
}
ImGui::EndDragDropTarget();
Expand Down
25 changes: 23 additions & 2 deletions EnchantingTable/src/Panels/AnimationControllerPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ struct GraphEditorDelegate : public GraphEditor::Delegate
void AddLink(GraphEditor::NodeIndex inputNodeIndex, GraphEditor::SlotIndex inputSlotIndex, GraphEditor::NodeIndex outputNodeIndex, GraphEditor::SlotIndex outputSlotIndex) override
{
mLinks.push_back({ inputNodeIndex, inputSlotIndex, outputNodeIndex, outputSlotIndex });

// This is if we are connecting to the entry node
if (inputNodeIndex == 0) {
Node currentNode = mNodes[outputNodeIndex];
controller->SetCurrentAnimation(currentNode.animation->GetName());
}
else {
Node fromNode = mNodes[inputNodeIndex];
Node toNode = mNodes[outputNodeIndex];

Arcane::AnimationLink newLink;
newLink.from = fromNode.animation;
newLink.to = toNode.animation;

controller->AddLink(newLink);
}
}

void DelLink(GraphEditor::LinkIndex linkIndex) override
Expand Down Expand Up @@ -87,7 +103,7 @@ struct GraphEditorDelegate : public GraphEditor::Delegate
myNode.name,
myNode.templateIndex,
ImRect(ImVec2(myNode.x, myNode.y), ImVec2(myNode.x + 200, myNode.y + 200)),
myNode.mSelected
myNode.mSelected,
};
}

Expand All @@ -103,6 +119,7 @@ struct GraphEditorDelegate : public GraphEditor::Delegate

// Graph datas
static const inline GraphEditor::Template mTemplates[] = {
// Entry Node Template
{
IM_COL32(160, 160, 180, 255),
IM_COL32(100, 100, 140, 255),
Expand All @@ -113,7 +130,9 @@ struct GraphEditorDelegate : public GraphEditor::Delegate
1,
Array{"Output"},
nullptr
},{
},
// Other node index
{
IM_COL32(160, 160, 180, 255),
IM_COL32(100, 100, 140, 255),
IM_COL32(110, 110, 150, 255),
Expand All @@ -132,6 +151,7 @@ struct GraphEditorDelegate : public GraphEditor::Delegate
GraphEditor::TemplateIndex templateIndex;
float x, y;
bool mSelected;
Arcane::Animation* animation;
};

std::vector<Node> mNodes = {
Expand All @@ -144,6 +164,7 @@ struct GraphEditorDelegate : public GraphEditor::Delegate
};

std::vector<GraphEditor::Link> mLinks = { };
Arcane::AnimationController* controller = nullptr;
};


Expand Down
3 changes: 1 addition & 2 deletions EnchantingTable/src/Panels/AnimationPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ void AnimationPanel::OnImGuiRender()
Arcane::KeyFrame2D* newKeyFrame = new Arcane::KeyFrame2D();
newKeyFrame->SetImageIndexX(i);
newKeyFrame->SetImageIndexY(1);
newKeyFrame->SetKeyFrameLength(1);
newKeyFrame->SetKeyFrameLength(15);
m_Animation->AddKeyFrame(i, newKeyFrame);

}
}
}
Expand Down

0 comments on commit a032271

Please sign in to comment.