adding and integrating ImGuizmo

This commit is contained in:
2026-10-02 11:36:33 -07:00
parent 379589fe8c
commit 6e48b0605c
28 changed files with 1223 additions and 108 deletions
+32 -5
View File
@@ -6,6 +6,7 @@
#include <sophia/components.hpp>
void InspectorPanel::onUpdate(const sophia::FrameInfo&) {
selected = context.selected;
if (!selected) {
ImGui::TextDisabled("No entity selected");
return;
@@ -16,6 +17,7 @@ void InspectorPanel::onUpdate(const sophia::FrameInfo&) {
drawTransform();
drawCamera();
drawSprite();
drawMesh();
ImGui::Separator();
drawAddComponent();
@@ -40,11 +42,13 @@ void InspectorPanel::drawTransform() {
auto& transform = selected.getComponent<sophia::TransformComponent>();
ImGui::DragFloat3("Position", &transform.position.x, 0.1f);
// 2D only: edits rotation around Z and drops any X/Y rotation.
float degrees = glm::degrees(glm::eulerAngles(transform.rotation).z);
if (ImGui::DragFloat("Rotation", &degrees, 1.0f)) {
transform.rotation =
glm::angleAxis(glm::radians(degrees), glm::vec3{0.f, 0.f, 1.f});
// Euler angles in degrees, recomputed from the quaternion every frame.
// Near 90 degrees of pitch the angles can jump between equivalent values
// while dragging.
// TODO: keep each entity's edited angles, or replace with gizmo rotation.
glm::vec3 degrees = glm::degrees(glm::eulerAngles(transform.rotation));
if (ImGui::DragFloat3("Rotation", &degrees.x, 1.0f)) {
transform.rotation = glm::quat{glm::radians(degrees)};
}
ImGui::DragFloat3("Scale", &transform.scale.x, 0.1f);
@@ -118,6 +122,29 @@ void InspectorPanel::drawSprite() {
}
}
void InspectorPanel::drawMesh() {
if (!selected.hasComponent<sophia::MeshComponent>()) {
return;
}
bool open = true;
if (!ImGui::CollapsingHeader("Mesh", &open, ImGuiTreeNodeFlags_DefaultOpen)) {
if (!open) {
selected.removeComponent<sophia::MeshComponent>();
}
return;
}
auto& mesh = selected.getComponent<sophia::MeshComponent>();
// TODO: pick the mesh once assets have names.
ImGui::Text("Mesh: %u", static_cast<sophia::u32>(mesh.handle.index));
ImGui::ColorEdit3("Color", &mesh.color.x);
if (!open) {
selected.removeComponent<sophia::MeshComponent>();
}
}
void InspectorPanel::drawAddComponent() {
if (ImGui::Button("Add Component")) {
ImGui::OpenPopup("AddComponent");