Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
angryzor committed Nov 25, 2023
1 parent 5e173bf commit 01f2ab8
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 34 deletions.
6 changes: 4 additions & 2 deletions devtools/DllMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,17 @@ 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);
a2->BindAxisMapping("HHFreeCameraMoveVertical", 0x2004eu, -1.0, -1);

// Speed
a2->BindActionMapping("HHFreeCameraSpeedChange", 0x200e1u, -1);
a2->BindActionMapping("HHFreeCameraSpeedChange", 0x200e5u, -1);

// Reset
a2->BindActionMapping("HHFreeCameraReset", 0x2003au, -1);
Expand Down
4 changes: 2 additions & 2 deletions devtools/Mod.ini
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
2 changes: 1 addition & 1 deletion devtools/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
84 changes: 78 additions & 6 deletions devtools/common/ObjectDataEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float, 3, Eigen::Affine> absoluteTransform{};
Eigen::Transform<float, 3, Eigen::Affine> localTransform{};
Eigen::Transform<float, 3, Eigen::Affine> 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<float, 3, Eigen::Affine> parentTransform = absoluteTransform * localTransform.inverse();
Eigen::Transform<float, 3, Eigen::Affine> 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) {
Expand Down
Binary file modified devtools/devtools.rc
Binary file not shown.
2 changes: 2 additions & 0 deletions devtools/devtools.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<LanguageStandard>stdcpp17</LanguageStandard>
<PreprocessorDefinitions>_WINDLL;USE_STD_FILESYSTEM;MGUI_ENABLE_FREETYPE;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4068;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<AdditionalOptions>/w34996 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -176,6 +177,7 @@
<ForcedIncludeFiles>Pch.h</ForcedIncludeFiles>
<LanguageStandard>stdcpp17</LanguageStandard>
<PreprocessorDefinitions>_WINDLL;USE_STD_FILESYSTEM;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/w34996 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
42 changes: 21 additions & 21 deletions devtools/operation-modes/LevelEditor/LevelEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
);

Expand All @@ -107,36 +107,36 @@ 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;

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<GOCTransform>();

// 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<GOCTransform>();

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))
Expand Down
6 changes: 5 additions & 1 deletion devtools/operation-modes/LevelEditor/ObjectLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion devtools/serialization/resource-rfls/ResObjectWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ RflClassMember objectDataMembers[]{
{ "objInfo", reinterpret_cast<RflClass*>(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 },
Expand Down

0 comments on commit 01f2ab8

Please sign in to comment.