From 01f2ab84b91d331b26375c691a6a67abf46304a1 Mon Sep 17 00:00:00 2001 From: angryzor Date: Sat, 25 Nov 2023 13:33:50 +0100 Subject: [PATCH] v0.1.0 --- devtools/DllMain.cpp | 6 +- devtools/Mod.ini | 4 +- devtools/ToolBar.cpp | 2 +- devtools/common/ObjectDataEditor.cpp | 84 ++++++++++++++++-- devtools/devtools.rc | Bin 4694 -> 4694 bytes devtools/devtools.vcxproj | 2 + .../LevelEditor/LevelEditor.cpp | 42 ++++----- .../LevelEditor/ObjectLibrary.cpp | 6 +- .../resource-rfls/ResObjectWorld.cpp | 2 +- 9 files changed, 114 insertions(+), 34 deletions(-) diff --git a/devtools/DllMain.cpp b/devtools/DllMain.cpp index 4948906..b48c5aa 100644 --- a/devtools/DllMain.cpp +++ b/devtools/DllMain.cpp @@ -159,8 +159,9 @@ void BindMapsDetour(hh::game::GameManager* a1, hh::hid::InputMapSettings* a2) { a2->BindAxisMapping("HHFreeCameraMoveSubHorizontal", 0x2005cu, -1.0, -1); a2->BindAxisMapping("HHFreeCameraMoveSubHorizontal", 0x2005eu, 1.0, -1); - // Up/down: hold alt + move & pgup/dn - a2->BindActionMapping("HHFreeCameraUpDown", 0x200e2u, -1); + // Up/down: hold ctrl + move & pgup/dn + a2->BindActionMapping("HHFreeCameraUpDown", 0x200e0u, -1); + a2->BindActionMapping("HHFreeCameraUpDown", 0x200e4u, -1); a2->BindActionMapping("HHFreeCameraUpDown", 0x2004bu, -1); a2->BindActionMapping("HHFreeCameraUpDown", 0x2004eu, -1); a2->BindAxisMapping("HHFreeCameraMoveVertical", 0x2004bu, 1.0, -1); @@ -168,6 +169,7 @@ void BindMapsDetour(hh::game::GameManager* a1, hh::hid::InputMapSettings* a2) { // Speed a2->BindActionMapping("HHFreeCameraSpeedChange", 0x200e1u, -1); + a2->BindActionMapping("HHFreeCameraSpeedChange", 0x200e5u, -1); // Reset a2->BindActionMapping("HHFreeCameraReset", 0x2003au, -1); diff --git a/devtools/Mod.ini b/devtools/Mod.ini index 09b246a..d6f7810 100644 --- a/devtools/Mod.ini +++ b/devtools/Mod.ini @@ -1,9 +1,9 @@ [Desc] -Version=0.0.6 +Version=0.1.0 Author="angryzor" Title="Sonic Frontiers DevTools" Description="In-engine development kit for Sonic Frontiers" -Date="2023-11-15" +Date="2023-11-25" AuthorURL="https://github.com/angryzor" [Main] UpdateServer="https://raw.githubusercontent.com/angryzor/hmm-update-server/main/sonic-frontiers/devtools/" diff --git a/devtools/ToolBar.cpp b/devtools/ToolBar.cpp index e0ae7ab..847e97e 100644 --- a/devtools/ToolBar.cpp +++ b/devtools/ToolBar.cpp @@ -114,7 +114,7 @@ void ToolBar::Render() { "Keyboard + mouse:\n" "WASD / arrow keys: move camera\n" "Mouse / numpad arrow keys: rotate camera\n" - "Hold LALT + move forward backward OR PgUp/PgDn: move camera up/down\n" + "Hold LCTRL/RCTRL + move forward backward OR PgUp/PgDn: move camera up/down\n" "Keypad +/-: zoom in/out\n" "Q/E: roll camera\n" "Home/End: change fov\n" diff --git a/devtools/common/ObjectDataEditor.cpp b/devtools/common/ObjectDataEditor.cpp index 80492b6..6c307c5 100644 --- a/devtools/common/ObjectDataEditor.cpp +++ b/devtools/common/ObjectDataEditor.cpp @@ -12,16 +12,88 @@ void ObjectDataEditor::Render(ObjectData* obj) ImGui::Text("Id: %016zx%016zx", obj->id.groupId, obj->id.objectId); InputText("Name", &obj->name); ImGui::Text("Class: %s", obj->gameObjectClass); + ImGui::Text("Parent object id: %016zx%016zx", obj->parentID.groupId, obj->parentID.objectId); + ImGui::SeparatorText("Transform"); - ImGui::PushID("Transform"); - ImGui::DragFloat3("Position", obj->transform.position.data(), 0.05f); - ImGui::DragFloat3("Rotation", obj->transform.rotation.data(), 0.005f); - ImGui::PopID(); + if (ImGui::BeginTable("Transform", 4)) + { + ImGui::TableSetupColumn("X"); + ImGui::TableSetupColumn("Y"); + ImGui::TableSetupColumn("Z"); + ImGui::TableSetupColumn(""); + + ImGui::TableHeadersRow(); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("%f", obj->transform.position.x()); + ImGui::TableNextColumn(); + ImGui::Text("%f", obj->transform.position.y()); + ImGui::TableNextColumn(); + ImGui::Text("%f", obj->transform.position.z()); + ImGui::TableNextColumn(); + ImGui::Text("Position"); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("%f", obj->transform.rotation.x()); + ImGui::TableNextColumn(); + ImGui::Text("%f", obj->transform.rotation.y()); + ImGui::TableNextColumn(); + ImGui::Text("%f", obj->transform.rotation.z()); + ImGui::TableNextColumn(); + ImGui::Text("Rotation"); + + ImGui::EndTable(); + } + + csl::math::Position localPosition{ obj->localTransform.position }; + csl::math::Position localRotation{ obj->localTransform.rotation }; + ImGui::SeparatorText("Local transform"); ImGui::PushID("Local Transform"); - ImGui::DragFloat3("Position", obj->localTransform.position.data(), 0.05f); - ImGui::DragFloat3("Rotation", obj->localTransform.rotation.data(), 0.005f); + ImGui::DragFloat3("Position", localPosition.data(), 0.05f); + ImGui::DragFloat3("Rotation", localRotation.data(), 0.005f); ImGui::PopID(); + + if (localPosition != obj->localTransform.position || localRotation != obj->localTransform.rotation) { + Eigen::Transform absoluteTransform{}; + Eigen::Transform localTransform{}; + Eigen::Transform updatedLocalTransform{}; + + absoluteTransform.fromPositionOrientationScale( + obj->transform.position, + Eigen::AngleAxisf(obj->transform.rotation[1], Eigen::Vector3f::UnitY()) * Eigen::AngleAxisf(obj->transform.rotation[0], Eigen::Vector3f::UnitX()) * Eigen::AngleAxisf(obj->transform.rotation[2], Eigen::Vector3f::UnitZ()), + csl::math::Vector3{ 1.0f, 1.0f, 1.0f } + ); + + localTransform.fromPositionOrientationScale( + localPosition, + Eigen::AngleAxisf(localRotation[1], Eigen::Vector3f::UnitY()) * Eigen::AngleAxisf(localRotation[0], Eigen::Vector3f::UnitX()) * Eigen::AngleAxisf(localRotation[2], Eigen::Vector3f::UnitZ()), + csl::math::Vector3{ 1.0f, 1.0f, 1.0f } + ); + + updatedLocalTransform.fromPositionOrientationScale( + obj->localTransform.position, + Eigen::AngleAxisf(obj->localTransform.rotation[1], Eigen::Vector3f::UnitY()) * Eigen::AngleAxisf(obj->localTransform.rotation[0], Eigen::Vector3f::UnitX()) * Eigen::AngleAxisf(obj->localTransform.rotation[2], Eigen::Vector3f::UnitZ()), + csl::math::Vector3{ 1.0f, 1.0f, 1.0f } + ); + + Eigen::Transform parentTransform = absoluteTransform * localTransform.inverse(); + Eigen::Transform updatedAbsoluteTransform = parentTransform * updatedLocalTransform; + + Eigen::Matrix3f updatedAbsoluteRotation; + Eigen::Matrix3f updatedAbsoluteScaling; + + updatedAbsoluteTransform.computeRotationScaling(&updatedAbsoluteRotation, &updatedAbsoluteScaling); + + obj->transform.position = { updatedAbsoluteTransform.translation() }; + auto updatedAbsoluteEuler = updatedAbsoluteRotation.eulerAngles(1, 0, 2); + obj->transform.rotation = { updatedAbsoluteEuler[1], updatedAbsoluteEuler[0], updatedAbsoluteEuler[2] }; + obj->localTransform.position = localPosition; + obj->localTransform.rotation = localRotation; + } + ImGui::SeparatorText("Component configuration"); for (auto* componentConfig : obj->componentData) { diff --git a/devtools/devtools.rc b/devtools/devtools.rc index 27285577e59166f12bf959bf700dbe2ad5cff5e2..546ced5fbfc9edc48252cddcbe3f0bfda402bfff 100644 GIT binary patch delta 58 zcmcbna!qAJ9|x-;gARkistdcpp17 _WINDLL;USE_STD_FILESYSTEM;MGUI_ENABLE_FREETYPE;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;%(PreprocessorDefinitions) 4068;%(DisableSpecificWarnings) + /w34996 %(AdditionalOptions) Console @@ -176,6 +177,7 @@ Pch.h stdcpp17 _WINDLL;USE_STD_FILESYSTEM;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;%(PreprocessorDefinitions) + /w34996 %(AdditionalOptions) Console diff --git a/devtools/operation-modes/LevelEditor/LevelEditor.cpp b/devtools/operation-modes/LevelEditor/LevelEditor.cpp index 5dcdacf..8819d83 100644 --- a/devtools/operation-modes/LevelEditor/LevelEditor.cpp +++ b/devtools/operation-modes/LevelEditor/LevelEditor.cpp @@ -82,13 +82,13 @@ void LevelEditor::Render() { absoluteTransform.fromPositionOrientationScale( focusedObject->transform.position, - Eigen::AngleAxisf(focusedObject->transform.rotation[0], Eigen::Vector3f::UnitZ()) * Eigen::AngleAxisf(-focusedObject->transform.rotation[2], Eigen::Vector3f::UnitX()) * Eigen::AngleAxisf(focusedObject->transform.rotation[1], Eigen::Vector3f::UnitY()), + Eigen::AngleAxisf(focusedObject->transform.rotation[1], Eigen::Vector3f::UnitY()) * Eigen::AngleAxisf(focusedObject->transform.rotation[0], Eigen::Vector3f::UnitX()) * Eigen::AngleAxisf(focusedObject->transform.rotation[2], Eigen::Vector3f::UnitZ()), csl::math::Vector3{ 1.0f, 1.0f, 1.0f } ); localTransform.fromPositionOrientationScale( focusedObject->localTransform.position, - Eigen::AngleAxisf(focusedObject->localTransform.rotation[0], Eigen::Vector3f::UnitZ()) * Eigen::AngleAxisf(-focusedObject->localTransform.rotation[2], Eigen::Vector3f::UnitX()) * Eigen::AngleAxisf(focusedObject->localTransform.rotation[1], Eigen::Vector3f::UnitY()), + Eigen::AngleAxisf(focusedObject->localTransform.rotation[1], Eigen::Vector3f::UnitY()) * Eigen::AngleAxisf(focusedObject->localTransform.rotation[0], Eigen::Vector3f::UnitX()) * Eigen::AngleAxisf(focusedObject->localTransform.rotation[2], Eigen::Vector3f::UnitZ()), csl::math::Vector3{ 1.0f, 1.0f, 1.0f } ); @@ -107,8 +107,8 @@ void LevelEditor::Render() { absoluteTransform.computeRotationScaling(&absoluteRotation, &absoluteScaling); focusedObject->transform.position = { absoluteTransform.translation() }; - auto absoluteEuler = absoluteRotation.canonicalEulerAngles(2, 0, 1); - focusedObject->transform.rotation = { absoluteEuler[0], absoluteEuler[2], -absoluteEuler[1] }; + auto absoluteEuler = absoluteRotation.eulerAngles(1, 0, 2); + focusedObject->transform.rotation = { absoluteEuler[1], absoluteEuler[0], absoluteEuler[2] }; Eigen::Matrix3f updatedLocalRotation; Eigen::Matrix3f updatedLocalScaling; @@ -116,27 +116,27 @@ void LevelEditor::Render() { updatedLocalTransform.computeRotationScaling(&updatedLocalRotation, &updatedLocalScaling); focusedObject->localTransform.position = { updatedLocalTransform.translation() }; - auto localEuler = updatedLocalRotation.canonicalEulerAngles(2, 0, 1); - focusedObject->localTransform.rotation = { localEuler[0], localEuler[2], -localEuler[1] }; + auto localEuler = updatedLocalRotation.eulerAngles(1, 0, 2); + focusedObject->localTransform.rotation = { localEuler[1], localEuler[0], localEuler[2] }; int idx = focusedChunk->GetObjectIndexById(focusedObject->id); if (idx != -1) { - focusedChunk->DespawnByIndex(idx); - focusedChunk->GetWorldObjectStatusByIndex(idx).Restart(); - //auto* obj = focusedChunk->GetObjectByIndex(idx); - - //if (obj) { - // auto* gocTransform = obj->GetComponent(); - - // if (gocTransform) { - // // Depending on whether the parent was able to be spawned, the object uses the local or the absolute transform as the GOC transform, so we have to replicate that here. - // if (gocTransform->IsExistParent()) - // gocTransform->SetLocalTransform({ { updatedLocalTransform.translation() }, { Eigen::Quaternionf{ updatedLocalRotation } }, { Eigen::Vector3f{ 1.0f, 1.0f, 1.0f } } }); - // else - // gocTransform->SetLocalTransform({ { absoluteTransform.translation() }, { Eigen::Quaternionf{ absoluteRotation } }, { Eigen::Vector3f{ 1.0f, 1.0f, 1.0f } } }); - // } - //} + //focusedChunk->DespawnByIndex(idx); + //focusedChunk->GetWorldObjectStatusByIndex(idx).Restart(); + auto* obj = focusedChunk->GetObjectByIndex(idx); + + if (obj) { + auto* gocTransform = obj->GetComponent(); + + if (gocTransform) { + // Depending on whether the parent was able to be spawned, the object uses the local or the absolute transform as the GOC transform, so we have to replicate that here. + if (gocTransform->IsExistParent()) + gocTransform->SetLocalTransform({ { updatedLocalTransform.translation() }, { Eigen::Quaternionf{ updatedLocalRotation } }, { Eigen::Vector3f{ 1.0f, 1.0f, 1.0f } } }); + else + gocTransform->SetLocalTransform({ { absoluteTransform.translation() }, { Eigen::Quaternionf{ absoluteRotation } }, { Eigen::Vector3f{ 1.0f, 1.0f, 1.0f } } }); + } + } } if ((ImGui::IsKeyDown(ImGuiKey_LeftAlt) || ImGui::IsKeyDown(ImGuiKey_RightAlt)) && ImGui::IsKeyPressed(ImGuiKey_Space)) diff --git a/devtools/operation-modes/LevelEditor/ObjectLibrary.cpp b/devtools/operation-modes/LevelEditor/ObjectLibrary.cpp index 9093d97..77f71e8 100644 --- a/devtools/operation-modes/LevelEditor/ObjectLibrary.cpp +++ b/devtools/operation-modes/LevelEditor/ObjectLibrary.cpp @@ -57,8 +57,12 @@ void ObjectLibrary::Render() { } if (ImGui::BeginChild("List of objects")) { for (auto* obj : registry->GetGameObjectClasses()) { - if (ImGui::Selectable(obj->pName, selectedClass == obj)) + if (ImGui::Selectable(obj->pName, selectedClass == obj)) { selectedClass = obj; + + if (levelEditor.objectClassToPlace) + levelEditor.objectClassToPlace = selectedClass; + } if (selectedClass == obj) ImGui::SetItemDefaultFocus(); } diff --git a/devtools/serialization/resource-rfls/ResObjectWorld.cpp b/devtools/serialization/resource-rfls/ResObjectWorld.cpp index f3e3f29..f507cc9 100644 --- a/devtools/serialization/resource-rfls/ResObjectWorld.cpp +++ b/devtools/serialization/resource-rfls/ResObjectWorld.cpp @@ -78,7 +78,7 @@ RflClassMember objectDataMembers[]{ { "objInfo", reinterpret_cast(handleObjInfo), nullptr, RflClassMember::TYPE_POINTER, RflClassMember::TYPE_VOID, 0, 0, offsetof(ObjectData, objInfo), nullptr }, }; -RflClass objectData{ "ObjectData", nullptr, sizeof(ObjectData), nullptr, 0, objectDataMembers, 10, nullptr }; +RflClass objectData{ "ObjectData", nullptr, sizeof(ObjectData), nullptr, 0, objectDataMembers, 9, nullptr }; RflClassMember objectDataArrayEntryMembers[]{ { "ptr", &objectData, nullptr, RflClassMember::TYPE_POINTER, RflClassMember::TYPE_STRUCT, 0, 0, 0, nullptr },