Recast: better slider limits and layout for primitive shape editor

This commit is contained in:
Kawe Mazidjatari 2024-09-23 12:09:54 +02:00
parent 1bd47494bf
commit 5cb0e93766

View File

@ -26,6 +26,8 @@
#include "coordsize.h" #include "coordsize.h"
#define VALUE_ADJUST_WINDOW 4000.f
// Quick and dirty convex hull. // Quick and dirty convex hull.
// Returns true if 'c' is left of line 'a'-'b'. // Returns true if 'c' is left of line 'a'-'b'.
@ -192,37 +194,37 @@ void ShapeVolumeTool::handleMenu()
ImGui::EndCombo(); ImGui::EndCombo();
} }
handleBrushTypes(m_areaType, "ShapeVolumeCreate");
switch (m_selectedPrimitive) switch (m_selectedPrimitive)
{ {
case VOLUME_BOX: case VOLUME_BOX:
ImGui::SliderFloat("Descent##ShapeVolumeCreate", &m_boxDescent, 0.1f, 4000); ImGui::SliderFloat("Descent##ShapeVolumeCreate", &m_boxDescent, 0.1f, VALUE_ADJUST_WINDOW);
ImGui::SliderFloat("Ascent##ShapeVolumeCreate", &m_boxAscent, 0.1f, 4000); ImGui::SliderFloat("Ascent##ShapeVolumeCreate", &m_boxAscent, 0.1f, VALUE_ADJUST_WINDOW);
break; break;
case VOLUME_CYLINDER: case VOLUME_CYLINDER:
ImGui::SliderFloat("Radius##ShapeVolumeCreate", &m_cylinderRadius, 0.1f, 4000); ImGui::SliderFloat("Radius##ShapeVolumeCreate", &m_cylinderRadius, 0.1f, VALUE_ADJUST_WINDOW);
ImGui::SliderFloat("Height##ShapeVolumeCreate", &m_cylinderHeight, 0.1f, 4000); ImGui::SliderFloat("Height##ShapeVolumeCreate", &m_cylinderHeight, 0.1f, VALUE_ADJUST_WINDOW);
break; break;
case VOLUME_CONVEX: case VOLUME_CONVEX:
ImGui::SliderFloat("Height##ShapeVolumeCreate", &m_convexHeight, 0.1f, 4000); ImGui::SliderFloat("Height##ShapeVolumeCreate", &m_convexHeight, 0.1f, VALUE_ADJUST_WINDOW);
ImGui::SliderFloat("Descent##ShapeVolumeCreate", &m_convexDescent, 0.1f, 4000); ImGui::SliderFloat("Descent##ShapeVolumeCreate", &m_convexDescent, 0.1f, VALUE_ADJUST_WINDOW);
ImGui::SliderFloat("Offset##ShapeVolumeCreate", &m_convexOffset, 0.0f, 2000); ImGui::SliderFloat("Offset##ShapeVolumeCreate", &m_convexOffset, 0.0f, VALUE_ADJUST_WINDOW/2);
break; break;
} }
if (m_areaType == DT_POLYAREA_TRIGGER)
{
ImGui::Separator();
handleVolumeFlags(m_polyFlags, "ShapeVolumeCreate");
}
if ((m_npts || m_nhull) && ImGui::Button("Clear Shape##ShapeVolumeCreate")) if ((m_npts || m_nhull) && ImGui::Button("Clear Shape##ShapeVolumeCreate"))
{ {
m_npts = 0; m_npts = 0;
m_nhull = 0; m_nhull = 0;
} }
handleBrushTypes(m_areaType, "ShapeVolumeCreate");
if (m_areaType == DT_POLYAREA_TRIGGER)
{
ImGui::Separator();
handleVolumeFlags(m_polyFlags, "ShapeVolumeCreate");
}
InputGeom* geom = m_editor->getInputGeom(); InputGeom* geom = m_editor->getInputGeom();
if (!geom || !isValidVolumeIndex(m_selectedVolumeIndex, geom)) if (!geom || !isValidVolumeIndex(m_selectedVolumeIndex, geom))
@ -245,35 +247,24 @@ void ShapeVolumeTool::handleMenu()
if (volArea != vol.area) if (volArea != vol.area)
vol.area = (unsigned char)volArea; vol.area = (unsigned char)volArea;
if (vol.area == DT_POLYAREA_TRIGGER)
{
ImGui::Separator();
int flags = vol.flags;
handleVolumeFlags(flags, "ShapeVolumeModify");
if (flags != vol.flags)
vol.flags = (unsigned short)flags;
}
switch (vol.type) switch (vol.type)
{ {
case VOLUME_BOX: case VOLUME_BOX:
ImGui::PushItemWidth(60); ImGui::PushItemWidth(60);
ImGui::SliderFloat("##ShapeBoxMinsX", &vol.verts[0], m_shapeCopy.verts[0]-4000, vol.verts[3]); ImGui::SliderFloat("##ShapeBoxMinsX", &vol.verts[0], m_shapeCopy.verts[0]-(VALUE_ADJUST_WINDOW/2), vol.verts[3]);
ImGui::SameLine(); ImGui::SameLine();
ImGui::SliderFloat("##ShapeBoxMinsY", &vol.verts[1], m_shapeCopy.verts[1]-4000, vol.verts[4]); ImGui::SliderFloat("##ShapeBoxMinsY", &vol.verts[1], m_shapeCopy.verts[1]-(VALUE_ADJUST_WINDOW/2), vol.verts[4]);
ImGui::SameLine(); ImGui::SameLine();
ImGui::SliderFloat("##ShapeBoxMinsZ", &vol.verts[2], m_shapeCopy.verts[2]-4000, vol.verts[5]); ImGui::SliderFloat("##ShapeBoxMinsZ", &vol.verts[2], m_shapeCopy.verts[2]-(VALUE_ADJUST_WINDOW/2), vol.verts[5]);
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text("Mins"); ImGui::Text("Mins");
ImGui::SliderFloat("##ShapeBoxMaxsX", &vol.verts[3], vol.verts[0], m_shapeCopy.verts[3]+4000); ImGui::SliderFloat("##ShapeBoxMaxsX", &vol.verts[3], vol.verts[0], m_shapeCopy.verts[3]+(VALUE_ADJUST_WINDOW/2));
ImGui::SameLine(); ImGui::SameLine();
ImGui::SliderFloat("##ShapeBoxMaxsY", &vol.verts[4], vol.verts[1], m_shapeCopy.verts[4]+4000); ImGui::SliderFloat("##ShapeBoxMaxsY", &vol.verts[4], vol.verts[1], m_shapeCopy.verts[4]+(VALUE_ADJUST_WINDOW/2));
ImGui::SameLine(); ImGui::SameLine();
ImGui::SliderFloat("##ShapeBoxMaxsZ", &vol.verts[5], vol.verts[2], m_shapeCopy.verts[5]+4000); ImGui::SliderFloat("##ShapeBoxMaxsZ", &vol.verts[5], vol.verts[2], m_shapeCopy.verts[5]+(VALUE_ADJUST_WINDOW/2));
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text("Maxs"); ImGui::Text("Maxs");
ImGui::PopItemWidth(); ImGui::PopItemWidth();
@ -281,21 +272,21 @@ void ShapeVolumeTool::handleMenu()
case VOLUME_CYLINDER: case VOLUME_CYLINDER:
ImGui::PushItemWidth(55); ImGui::PushItemWidth(55);
ImGui::SliderFloat("##ShapeCylinderX", &vol.verts[0], m_shapeCopy.verts[0]-4000, m_shapeCopy.verts[0]+4000); ImGui::SliderFloat("##ShapeCylinderX", &vol.verts[0], m_shapeCopy.verts[0]-(VALUE_ADJUST_WINDOW/2), m_shapeCopy.verts[0]+(VALUE_ADJUST_WINDOW/2));
ImGui::SameLine(); ImGui::SameLine();
ImGui::SliderFloat("##ShapeCylinderY", &vol.verts[1], m_shapeCopy.verts[1]-4000, m_shapeCopy.verts[1]+4000); ImGui::SliderFloat("##ShapeCylinderY", &vol.verts[1], m_shapeCopy.verts[1]-(VALUE_ADJUST_WINDOW/2), m_shapeCopy.verts[1]+(VALUE_ADJUST_WINDOW/2));
ImGui::SameLine(); ImGui::SameLine();
ImGui::SliderFloat("##ShapeCylinderZ", &vol.verts[2], m_shapeCopy.verts[2]-4000, m_shapeCopy.verts[2]+4000); ImGui::SliderFloat("##ShapeCylinderZ", &vol.verts[2], m_shapeCopy.verts[2]-(VALUE_ADJUST_WINDOW/2), m_shapeCopy.verts[2]+(VALUE_ADJUST_WINDOW/2));
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text("Position"); ImGui::Text("Position");
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::SliderFloat("Radius##ShapeVolumeModify", &vol.verts[3], 0.1f, 4000); ImGui::SliderFloat("Radius##ShapeVolumeModify", &vol.verts[3], 0.1f, VALUE_ADJUST_WINDOW);
ImGui::SliderFloat("Height##ShapeVolumeModify", &vol.verts[4], 0.1f, 4000); ImGui::SliderFloat("Height##ShapeVolumeModify", &vol.verts[4], 0.1f, VALUE_ADJUST_WINDOW);
break; break;
case VOLUME_CONVEX: case VOLUME_CONVEX:
ImGui::SliderFloat("Descent##ShapeVolumeModify", &vol.hmin, m_shapeCopy.hmin-4000, m_shapeCopy.hmin+4000); ImGui::SliderFloat("Descent##ShapeVolumeModify", &vol.hmin, m_shapeCopy.hmin-(VALUE_ADJUST_WINDOW/2), m_shapeCopy.hmax);
ImGui::SliderFloat("Ascent##ShapeVolumeModify", &vol.hmax, m_shapeCopy.hmax-4000, m_shapeCopy.hmax+4000); ImGui::SliderFloat("Ascent##ShapeVolumeModify", &vol.hmax, m_shapeCopy.hmin, m_shapeCopy.hmax+(VALUE_ADJUST_WINDOW/2));
char sliderId[64]; char sliderId[64];
@ -309,13 +300,13 @@ void ShapeVolumeTool::handleMenu()
} }
ImGui::PushItemWidth(60); ImGui::PushItemWidth(60);
ImGui::SliderFloat(sliderId, &vol.verts[(i*3)+0], m_shapeCopy.verts[(i*3)+0]-4000, m_shapeCopy.verts[(i*3)+0]+4000); ImGui::SliderFloat(sliderId, &vol.verts[(i*3)+0], m_shapeCopy.verts[(i*3)+0]-(VALUE_ADJUST_WINDOW/2), m_shapeCopy.verts[(i*3)+0]+(VALUE_ADJUST_WINDOW/2));
ImGui::SameLine(); ImGui::SameLine();
sliderId[len] = 'Y'; sliderId[len] = 'Y';
ImGui::SliderFloat(sliderId, &vol.verts[(i*3)+1], m_shapeCopy.verts[(i*3)+1]-4000, m_shapeCopy.verts[(i*3)+1]+4000); ImGui::SliderFloat(sliderId, &vol.verts[(i*3)+1], m_shapeCopy.verts[(i*3)+1]-(VALUE_ADJUST_WINDOW/2), m_shapeCopy.verts[(i*3)+1]+(VALUE_ADJUST_WINDOW/2));
ImGui::SameLine(); ImGui::SameLine();
sliderId[len] = 'Z'; sliderId[len] = 'Z';
ImGui::SliderFloat(sliderId, &vol.verts[(i*3)+2], m_shapeCopy.verts[(i*3)+2]-4000, m_shapeCopy.verts[(i*3)+2]+4000); ImGui::SliderFloat(sliderId, &vol.verts[(i*3)+2], m_shapeCopy.verts[(i*3)+2]-(VALUE_ADJUST_WINDOW/2), m_shapeCopy.verts[(i*3)+2]+(VALUE_ADJUST_WINDOW/2));
ImGui::SameLine(); ImGui::SameLine();
snprintf(sliderId, sizeof(sliderId), "Vert #%d", i); snprintf(sliderId, sizeof(sliderId), "Vert #%d", i);
@ -326,6 +317,17 @@ void ShapeVolumeTool::handleMenu()
break; break;
} }
if (vol.area == DT_POLYAREA_TRIGGER)
{
ImGui::Separator();
int flags = vol.flags;
handleVolumeFlags(flags, "ShapeVolumeModify");
if (flags != vol.flags)
vol.flags = (unsigned short)flags;
}
if (ImGui::Button("Delete Shape##ShapeVolumeModify")) if (ImGui::Button("Delete Shape##ShapeVolumeModify"))
{ {
geom->deleteConvexVolume(m_selectedVolumeIndex); geom->deleteConvexVolume(m_selectedVolumeIndex);