Implement mesh recenter to top (#1585)

* Implement mesh recenter to top

* Fix downstream error
This commit is contained in:
Stanislav Denisov
2026-03-10 16:29:18 +01:00
committed by GitHub
parent c4d381001c
commit 7a73dbd49d
4 changed files with 25 additions and 0 deletions
+9
View File
@@ -327,6 +327,14 @@ void MeshWindow::Create(EditorComponent* _editor)
}));
AddWidget(&recenterButton);
recenterToTopButton.Create("Recenter to Top");
recenterToTopButton.SetTooltip("Recenter mesh to AABB top.");
recenterToTopButton.OnClick(changeSelectedMesh([this] (auto mesh) {
mesh->RecenterToTop();
UpdateRecenterInputs(mesh->aabb.getCenter());
}));
AddWidget(&recenterToTopButton);
recenterToBottomButton.Create("Recenter to Bottom");
recenterToBottomButton.SetTooltip("Recenter mesh to AABB bottom.");
recenterToBottomButton.OnClick(changeSelectedMesh([this] (auto mesh) {
@@ -1196,6 +1204,7 @@ void MeshWindow::ResizeLayout()
layout.add_fullwidth(computeNormalsSmoothButton);
layout.add_fullwidth(computeNormalsHardButton);
layout.add_fullwidth(recenterButton);
layout.add_fullwidth(recenterToTopButton);
layout.add_fullwidth(recenterToBottomButton);
const float safe_width = layout.width - 100 - layout.padding;
+1
View File
@@ -30,6 +30,7 @@ public:
wi::gui::Button computeNormalsSmoothButton;
wi::gui::Button computeNormalsHardButton;
wi::gui::Button recenterButton;
wi::gui::Button recenterToTopButton;
wi::gui::Button recenterToBottomButton;
wi::gui::TextInputField recenterToXInput;
wi::gui::TextInputField recenterToYInput;
+14
View File
@@ -1962,6 +1962,20 @@ namespace wi::scene
CreateRenderData();
}
void MeshComponent::RecenterToTop()
{
XMFLOAT3 center = aabb.getCenter();
center.y += aabb.getHalfWidth().y;
for (auto& pos : vertex_positions)
{
pos.x -= center.x;
pos.y -= center.y;
pos.z -= center.z;
}
CreateRenderData();
}
void MeshComponent::RecenterToBottom()
{
XMFLOAT3 center = aabb.getCenter();
+1
View File
@@ -870,6 +870,7 @@ namespace wi::scene
void FlipCulling();
void FlipNormals();
void Recenter();
void RecenterToTop();
void RecenterToBottom();
void RecenterTo(float x, float y, float z);
wi::primitive::Sphere GetBoundingSphere() const;