Skip to content

Commit

Permalink
A bunch of bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Mar 28, 2024
1 parent 74d09cc commit 53ff966
Show file tree
Hide file tree
Showing 40 changed files with 1,008 additions and 282 deletions.
4 changes: 2 additions & 2 deletions Engine/Sandbox.exe
Git LFS file not shown
4 changes: 2 additions & 2 deletions Engine/Scripts/Volt-ScriptCore.dll
Git LFS file not shown
4 changes: 2 additions & 2 deletions Engine/Scripts/Volt-ScriptCore.pdb
Git LFS file not shown
9 changes: 8 additions & 1 deletion Engine/Volt-ScriptCore/Source/Volt/Scene/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ public Entity parent

set
{
GetComponent<RelationshipComponent>().parent = value;
if (value == null)
{
InternalCalls.RelationshipComponent_SetParent(this.Id, 0);
}
else
{
GetComponent<RelationshipComponent>().parent = value;
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions Volt/GraphKey/src/GraphKey/Nodes/Animation/SequenceNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ namespace GraphKey
//const float localTime = Volt::AnimationManager::globalClock - animGraph->GetStartTime();

const uint32_t currentFrame = anim->GetFrameFromStartTime(animGraph->GetStartTime(), speed);
/* ANIMATION EVENT STUFF
const int32_t animationIndex = character->GetAnimationIndexFromHandle(animHandle);
if (myGraph->GetEntity() != Volt::Entity::NullID() && Volt::SceneManager::GetActiveScene() && animationIndex != -1 && character->HasAnimationEvents((uint32_t)animationIndex))

if (myGraph->GetEntity() != Volt::Entity::NullID() && Volt::SceneManager::GetActiveScene() && anim->HasEvents())
{
const auto& animEvents = character->GetAnimationEvents((uint32_t)animationIndex);
const auto& animEvents = anim->GetEvents();

for (const auto& event : animEvents)
{
if (event.frame == currentFrame && (int32_t)currentFrame != myLastFrame)
Expand All @@ -123,7 +123,7 @@ namespace GraphKey
}
}
}
}*/
}

myLastFrame = (int32_t)currentFrame;

Expand Down
154 changes: 107 additions & 47 deletions Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.cpp

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class ProjectUpgradeModal : public Modal
void ConvertAnimationGraphsToV0_1_2();
void ConvertMetaFilesToV011();

void ConvertPrefabsToV113();
void ConvertScenesToV113();
void ConvertPrefabsToV013();
void ConvertScenesToV013();

void ConvertPreV113Prefab(const std::filesystem::path& filePath);
void ConvertPreV013Prefab(const std::filesystem::path& filePath);

void DeserializePreV113SceneLayer(Ref<Volt::Scene> scene, Volt::SceneLayer& sceneLayer, const std::filesystem::path& layerPath, std::map<Volt::EntityID, Volt::EntityID>& entityRemapping);
void DeserializePreV113Entity(Ref<Volt::Scene> scene, Volt::YAMLFileStreamReader& streamReader, std::map<Volt::EntityID, Volt::EntityID>& entityRemapping, bool isPrefabEntity);
void DeserializePreV013Entity(Ref<Volt::Scene> scene, Volt::YAMLFileStreamReader& streamReader, std::map<Volt::EntityID, Volt::EntityID>& entityRemapping, bool isPrefabEntity);
void DeserializePreV113Component(uint8_t* componentData, const Volt::IComponentTypeDesc* componentDesc, Volt::YAMLFileStreamReader& streamReader);
void DeserializePreV113MonoScripts(Ref<Volt::Scene> scene, const Volt::EntityID entityId, Volt::YAMLFileStreamReader& streamReader);

Expand All @@ -50,7 +50,7 @@ class ProjectUpgradeModal : public Modal
void ValidateSceneConversion(Ref<Volt::Scene> scene);
void ValidateSceneConversionArray(Ref<Volt::Scene> scene, const Volt::ComponentMember& componentMember, uint8_t* componentData);

const bool IsPreV113EntityNull(Volt::EntityID entityId);
const bool IsPreV013EntityNull(Volt::EntityID entityId);
void ValidateEntityValidity(Volt::EntityID* entityId);
const Volt::ComponentMember* TryGetComponentMemberFromName(const std::string& memberName, const Volt::IComponentTypeDesc* componentDesc);

Expand Down
62 changes: 16 additions & 46 deletions Volt/Sandbox/src/Sandbox/Sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include "Sandbox/Window/BehaviourGraph/BehaviorPanel.h"
#include "Sandbox/Window/SceneSettingsPanel.h"
#include "Sandbox/Window/WorldEnginePanel.h"
#include "Sandbox/Window/SkeletonEditorPanel.h"
#include "Sandbox/Window/AnimationEditorPanel.h"
#include "Sandbox/VertexPainting/VertexPainterPanel.h"

#include "Sandbox/Utility/EditorResources.h"
Expand Down Expand Up @@ -162,6 +164,8 @@ void Sandbox::OnAttach()
myAssetBrowserPanel = EditorLibrary::Register<AssetBrowserPanel>("", myRuntimeScene, "##Main");

EditorLibrary::RegisterWithType<CharacterEditorPanel>("Animation", Volt::AssetType::AnimatedCharacter);
EditorLibrary::RegisterWithType<SkeletonEditorPanel>("Animation", Volt::AssetType::Skeleton);
EditorLibrary::RegisterWithType<AnimationEditorPanel>("Animation", Volt::AssetType::Animation);
EditorLibrary::RegisterWithType<MaterialEditorPanel>("", Volt::AssetType::Material, myRuntimeScene);
EditorLibrary::RegisterWithType<ParticleEmitterEditor>("", Volt::AssetType::ParticlePreset);
EditorLibrary::RegisterWithType<AnimationGraphPanel>("Animation", Volt::AssetType::AnimationGraph, myRuntimeScene);
Expand Down Expand Up @@ -588,7 +592,13 @@ void Sandbox::NewScene()
Volt::AssetManager::Get().Unload(myRuntimeScene->handle);
}

if (myRuntimeScene)
{
myRuntimeScene->ShutdownEngineScripts();
}

myRuntimeScene = Volt::Scene::CreateDefaultScene("New Scene", true);
myRuntimeScene->InitializeEngineScripts();
SetupNewSceneData();
}

Expand All @@ -606,6 +616,11 @@ void Sandbox::OpenScene(const std::filesystem::path& path)

const auto& metadata = Volt::AssetManager::GetMetadataFromHandle(myRuntimeScene->handle);

if (myRuntimeScene)
{
myRuntimeScene->ShutdownEngineScripts();
}

if (metadata.filePath == path)
{
Volt::AssetManager::Get().ReloadAsset(myRuntimeScene->handle);
Expand All @@ -616,6 +631,7 @@ void Sandbox::OpenScene(const std::filesystem::path& path)
}

myRuntimeScene = Volt::AssetManager::GetAsset<Volt::Scene>(path);
myRuntimeScene->InitializeEngineScripts();

SetupNewSceneData();
}
Expand Down Expand Up @@ -876,52 +892,6 @@ bool Sandbox::OnImGuiUpdateEvent(Volt::AppImGuiUpdateEvent& e)
RenderProgressBar(buildProgess);
}

if (ImGui::Begin("Conversion Window"))
{
if (ImGui::Button("Convert Scene to M"))
{
Volt::Entity mainMenuEntity = myRuntimeScene->GetEntityWithName("PF_MainMenu");

myRuntimeScene->ForEachWithComponents<Volt::TransformComponent, Volt::MeshComponent>([&](const entt::entity id, Volt::TransformComponent& transComp, const Volt::MeshComponent& meshComp)
{
Volt::Entity entity{ id, myRuntimeScene };
entity.SetScale(entity.GetScale() * 0.01f);
});

myRuntimeScene->ForEachWithComponents<Volt::TransformComponent>([&](const entt::entity id, Volt::TransformComponent& transComp)
{
Volt::Entity entity{ id, myRuntimeScene };

if (mainMenuEntity)
{
if (myRuntimeScene->IsRelatedTo(mainMenuEntity, entity))
{
return;
}
}

if (entity == mainMenuEntity)
{
return;
}

entity.SetLocalPosition(entity.GetLocalPosition() * 0.01f);
});

myRuntimeScene->ForEachWithComponents<Volt::PointLightComponent>([&](const entt::entity id, Volt::PointLightComponent& comp)
{
comp.radius *= 0.01f;
});

myRuntimeScene->ForEachWithComponents<Volt::SpotLightComponent>([&](const entt::entity id, Volt::SpotLightComponent& comp)
{
comp.range *= 0.01f;
});
}

ImGui::End();
}

return false;
}

Expand Down
196 changes: 196 additions & 0 deletions Volt/Sandbox/src/Sandbox/Window/AnimationEditorPanel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
#include "sbpch.h"
#include "AnimationEditorPanel.h"

#include <Volt/Asset/AssetManager.h>
#include <Volt/Asset/Animation/Animation.h>
#include <Volt/Utility/UIUtility.h>

AnimationEditorPanel::AnimationEditorPanel()
: EditorWindow("Animation Editor", false)
{
}

void AnimationEditorPanel::UpdateMainContent()
{
if (!m_animation)
{
return;
}

const auto duration = m_animation->GetDuration();
const int32_t stepCount = (int32_t)m_animation->GetFrameCount();

if (ImGui::Button("Save"))
{
Volt::AssetManager::SaveAsset(m_animation);
}

if (ImGui::BeginTable("timelineTable", 2, ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingStretchProp))
{
ImGui::TableNextColumn();
if (ImGui::BeginChild("eventsChild", { ImGui::GetColumnWidth(), ImGui::GetContentRegionAvail().y }, true))
{
UI::Header("Created Events");
ImGui::Separator();
if (m_animation->HasEvents())
{
const auto& events = m_animation->GetEvents();
for (int index = 0; index < events.size(); index++)
{
const auto id = UI::GetID();
bool selected = false;

ImGui::Selectable(std::format("{0}: ", events[index].name).c_str(), &selected, ImGuiSelectableFlags_AllowItemOverlap, ImVec2(150, 25));
ImGui::SameLine();
ImGui::DragInt(std::format("-##rem{0}", id).c_str(), (int*)&events[index].frame);

std::string popupName = "eventPopup" + std::to_string(index);
if (ImGui::IsItemClicked(ImGuiMouseButton_Right))
{
ImGui::OpenPopup(popupName.c_str());
}

std::string rightClickId = "eventRightClick" + std::to_string(index);
if (ImGui::BeginPopupContextItem(rightClickId.c_str(), ImGuiPopupFlags_MouseButtonRight))
{
if (ImGui::MenuItem("Remove"))
{
m_animation->RemoveEvent(events[index].name, events[index].frame);
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
break;
}
ImGui::EndPopup();
}

}
}

ImGui::EndChild();
}

ImGui::TableNextColumn();
if (ImGui::BeginChild("keyframeChild", ImGui::GetContentRegionAvail()))
{
if (ImGui::BeginChild("timeChild", { ImGui::GetContentRegionAvail().x, 35.f }, false, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse))
{
ImGui::TextUnformatted("0.00");
ImGui::SameLine();

auto drawList = ImGui::GetWindowDrawList();
ImVec2 windowPos = ImGui::GetWindowPos();
ImVec2 windowSize = ImGui::GetWindowSize();
ImGuiIO& io = ImGui::GetIO();

drawList->AddRectFilled(windowPos, windowPos + windowSize, IM_COL32(50, 50, 50, 255));

UI::ScopedColor color{ ImGuiCol_Button, { 1.f, 1.f, 1.f, 1.f } };
{
constexpr float padding = 3.f;
UI::ScopedStyleFloat2 itemPadding{ ImGuiStyleVar_ItemSpacing, { 3.f, 0.f } };

const float stepSize = windowSize.x / stepCount;
for (int32_t i = 0; i < stepCount; i++)
{
//ImGui::Button(("K##" + std::to_string(i)).c_str(), { stepSize, 20.f });
ImVec2 keyMinPos = ImVec2(windowPos.x + (stepSize * i) + padding, windowPos.y);
ImVec2 keyMaxPos = ImVec2(windowPos.x + (stepSize * (i + 1)) - padding, windowPos.y + windowSize.y);

if (m_selectedKeyFrame == i)
{
drawList->AddRectFilled(keyMinPos, keyMaxPos, IM_COL32(100, 100, 100, 255));
}
else
{
drawList->AddRectFilled(keyMinPos, keyMaxPos, IM_COL32(255, 255, 255, 255));
}

ImGui::ItemAdd(ImRect(keyMinPos, keyMaxPos), i);

if (ImGui::IsItemClicked(ImGuiMouseButton_Left))
{
m_selectedKeyFrame = i;
}

if (ImGui::IsItemHovered())
{
drawList->AddText(io.MousePos + ImVec2(0, -20), IM_COL32(255, 100, 100, 255), std::to_string(i).c_str());
}

if (ImGui::BeginPopupContextItem(("item##" + std::to_string(i)).c_str(), ImGuiPopupFlags_MouseButtonRight))
{
if (ImGui::MenuItem("Add Event"))
{
UI::OpenModal("Create Animation Event");
m_addAnimEventData = {};
m_addAnimEventData.frame = i;
}

ImGui::EndPopup();
}

ImGui::SameLine();
}
}

ImGui::Text("%.2f", duration);

ImGui::EndChild();
}

ImGui::EndChild();
}

ImGui::EndTable();
}

AddAnimationEventModal();
}

void AnimationEditorPanel::OpenAsset(Ref<Volt::Asset> asset)
{
if (m_animation)
{
Volt::AssetManager::SaveAsset(m_animation);
}

m_animation = std::reinterpret_pointer_cast<Volt::Animation>(asset);
}

void AnimationEditorPanel::OnOpen()
{
}

void AnimationEditorPanel::OnClose()
{
m_animation = nullptr;
}

void AnimationEditorPanel::AddAnimationEventModal()
{
if (UI::BeginModal("Create Animation Event", ImGuiWindowFlags_AlwaysAutoResize))
{
UI::PushID();
if (UI::BeginProperties("animEvent"))
{
UI::Property("Name", m_addAnimEventData.name);
UI::EndProperties();
}
UI::PopID();

if (ImGui::Button("Cancel"))
{
ImGui::CloseCurrentPopup();
}

ImGui::SameLine();

if (ImGui::Button("Add"))
{
m_animation->AddEvent(m_addAnimEventData.name, m_addAnimEventData.frame);
ImGui::CloseCurrentPopup();
}

UI::EndModal();
}
}
Loading

0 comments on commit 53ff966

Please sign in to comment.