-
Notifications
You must be signed in to change notification settings - Fork 0
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
53036da
commit e1a8aa7
Showing
13 changed files
with
258 additions
and
5 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,69 @@ | ||
#include <fstream> | ||
#include <nlohmann/json.hpp> | ||
|
||
#include "AnimationSerializer.h" | ||
|
||
namespace Arcane | ||
{ | ||
AnimationSerializer::AnimationSerializer(Animation* animation) | ||
{ | ||
m_Animation = animation; | ||
} | ||
|
||
void AnimationSerializer::Serialize(std::filesystem::path path) | ||
{ | ||
nlohmann::json jsonObject; | ||
|
||
// Set name of animation | ||
jsonObject["name"] = m_Animation->GetName(); | ||
|
||
nlohmann::json keyframeArray = nlohmann::json::array(); | ||
|
||
for (auto const& [key, val] : m_Animation->GetKeyFrames()) | ||
{ | ||
nlohmann::json keyFrameObject = nlohmann::json::array(); | ||
KeyFrameType type = val->GetType(); | ||
|
||
keyFrameObject["type"] = type == KeyFrameType::TWO_DIMENSIONAL ? "2D" : "3D"; | ||
|
||
if (type == KeyFrameType::TWO_DIMENSIONAL) { | ||
KeyFrame2D* keyFrame2D = static_cast<KeyFrame2D*>(val); | ||
|
||
keyFrameObject["ImageIndexX"] = keyFrame2D->GetImageIndexX(); | ||
keyFrameObject["ImageIndexY"] = keyFrame2D->GetImageIndexY(); | ||
keyFrameObject["KeyframeLength"] = keyFrame2D->GetKeyFrameLength(); | ||
} | ||
|
||
keyFrameObject["order"] = key; | ||
keyframeArray.push_back(keyFrameObject); | ||
} | ||
|
||
jsonObject["Keyframes"] = keyframeArray; | ||
|
||
std::ofstream o(path); | ||
o << std::setw(4) << jsonObject << std::endl; | ||
} | ||
|
||
void AnimationSerializer::Deserialize(std::filesystem::path path) | ||
{ | ||
nlohmann::json jsonObject; | ||
std::ifstream i(path); | ||
i >> jsonObject; | ||
|
||
m_Animation->SetName(jsonObject["name"]); | ||
|
||
for (auto& element : jsonObject["Keyframes"]) | ||
{ | ||
KeyFrameType type = element["type"] == "3D" ? KeyFrameType::THREE_DIMENSIONAL : KeyFrameType::TWO_DIMENSIONAL; | ||
|
||
if (type == KeyFrameType::TWO_DIMENSIONAL) | ||
{ | ||
KeyFrame2D* newKeyFrame = new KeyFrame2D(); | ||
newKeyFrame->SetImageIndexX(element["ImageIndexX"]); | ||
newKeyFrame->SetImageIndexY(element["ImageIndexY"]); | ||
newKeyFrame->SetKeyFrameLength(element["KeyframeLength"]); | ||
m_Animation->AddKeyFrame(element["order"], newKeyFrame); | ||
} | ||
} | ||
} | ||
} |
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,17 @@ | ||
#pragma once | ||
|
||
#include "Animation.h" | ||
|
||
namespace Arcane | ||
{ | ||
class AnimationSerializer | ||
{ | ||
public: | ||
AnimationSerializer(Animation* animation); | ||
|
||
void Serialize(std::filesystem::path path); | ||
void Deserialize(std::filesystem::path path); | ||
private: | ||
Animation* m_Animation; | ||
}; | ||
} |
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 |
---|---|---|
|
@@ -14,7 +14,8 @@ namespace Arcane | |
SCRIPT, | ||
SHADER, | ||
MATERIAL, | ||
SCENE | ||
SCENE, | ||
ANIMATION | ||
}; | ||
|
||
class Asset | ||
|
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,13 +1,81 @@ | ||
#include "AnimationPanel.h" | ||
#include "PanelStructs.h" | ||
|
||
AnimationPanel::AnimationPanel() | ||
{ | ||
m_AnimationSequencer = AnimationSequencer(); | ||
m_AnimationSequencer.m_FrameMin = 0; | ||
m_AnimationSequencer.m_FrameMax = 100; | ||
} | ||
|
||
void AnimationPanel::OnImGuiRender() | ||
{ | ||
ImGui::Begin("Animation"); | ||
{ | ||
if (ImGui::BeginDragDropTarget()) | ||
{ | ||
const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("CURRENT_SELECTED_ASSET"); | ||
|
||
if (payload != nullptr) { | ||
// Get Asset Id | ||
AssetInfo assetInfo = *static_cast<AssetInfo*>(payload->Data); | ||
Arcane::Asset* animationAsset = Arcane::Application::Get().GetAssetDatabase().GetAsset(assetInfo.id); | ||
|
||
if (animationAsset != nullptr && animationAsset->GetAssetType() == Arcane::AssetType::ANIMATION) { | ||
Arcane::Animation* animation = static_cast<Arcane::Animation*>(animationAsset); | ||
m_Animation = animation; | ||
} | ||
} | ||
ImGui::EndDragDropTarget(); | ||
} | ||
|
||
if (m_Animation == nullptr) { | ||
if (ImGui::Button("Create Animation")) | ||
CreateAnimation(); | ||
} | ||
else { | ||
for (const auto& [key, val] : m_Animation->GetKeyFrames()) | ||
{ | ||
if (val->GetType() == Arcane::KeyFrameType::TWO_DIMENSIONAL) | ||
{ | ||
Arcane::KeyFrame2D* keyFrame2D = static_cast<Arcane::KeyFrame2D*>(val); | ||
AnimationSequencer::KeyFrameItem newItem; | ||
if (key != 0) { | ||
AnimationSequencer::KeyFrameItem prevItem = m_AnimationSequencer.keyFrameItems[key - 1]; | ||
newItem.frameStart = prevItem.frameEnd; | ||
newItem.frameEnd = newItem.frameStart + keyFrame2D->GetKeyFrameLength(); | ||
} | ||
else { | ||
newItem.frameStart = 0; | ||
newItem.frameEnd = keyFrame2D->GetKeyFrameLength(); | ||
} | ||
|
||
m_AnimationSequencer.keyFrameItems.push_back(newItem); | ||
} | ||
} | ||
|
||
int currentFrame = 0; | ||
int selectedEntry = -1; | ||
bool expanded = true; | ||
ImSequencer::Sequencer(&m_AnimationSequencer, ¤tFrame, &expanded, &selectedEntry, 0, ImSequencer::SEQUENCER_EDIT_STARTEND | ImSequencer::SEQUENCER_ADD | ImSequencer::SEQUENCER_DEL | ImSequencer::SEQUENCER_COPYPASTE | ImSequencer::SEQUENCER_CHANGE_FRAME); | ||
} | ||
} | ||
ImGui::End(); | ||
} | ||
|
||
void AnimationPanel::CreateAnimation() | ||
{ | ||
std::string filename = Arcane::FileDialog::SaveFile(); | ||
|
||
if (!filename.empty()) { | ||
m_Animation = new Arcane::Animation(); | ||
Arcane::AnimationSerializer serializer(m_Animation); | ||
std::filesystem::path animationPath(filename); | ||
|
||
std::string name = animationPath.stem().string(); | ||
m_Animation->SetName(name); | ||
|
||
serializer.Serialize(animationPath); | ||
|
||
} | ||
} |
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
Oops, something went wrong.