Better 3D navigator (#5620)

* Initial working impl of face labels

* Improve color

* Remove background
This commit is contained in:
Noisyfox
2024-06-15 12:17:57 +08:00
committed by GitHub
parent aa692b815e
commit dbac0f2919
3 changed files with 80 additions and 4 deletions

View File

@@ -662,10 +662,18 @@ namespace IMGUIZMO_NAMESPACE
Colors[HATCHED_AXIS_LINES] = ImVec4(0.000f, 0.000f, 0.000f, 0.500f);
Colors[TEXT] = ImVec4(1.000f, 1.000f, 1.000f, 1.000f);
Colors[TEXT_SHADOW] = ImVec4(0.000f, 0.000f, 0.000f, 1.000f);
Colors[FACE] = ImVec4(0.776f, 0.804f, 0.839f, 1.000f);
strcpy(AxisLabels[Axis_X], "x");
strcpy(AxisLabels[Axis_Y], "y");
strcpy(AxisLabels[Axis_Z], "z");
strcpy(FaceLabels[FACE_BACK], "back");
strcpy(FaceLabels[FACE_TOP], "top");
strcpy(FaceLabels[FACE_RIGHT], "right");
strcpy(FaceLabels[FACE_FRONT], "front");
strcpy(FaceLabels[FACE_BOTTOM], "bottom");
strcpy(FaceLabels[FACE_LEFT], "left");
}
struct Context
@@ -2885,6 +2893,7 @@ namespace IMGUIZMO_NAMESPACE
const vec_t dx = directionUnary[perpXIndex];
const vec_t dy = directionUnary[perpYIndex];
const vec_t origin = directionUnary[normalIndex] - dx - dy;
ImU32 faceColor = GetColorU32(FACE);
for (int iPanel = 0; iPanel < 9; iPanel++)
{
vec_t boxCoord = boxOrigin + indexVectorX * float(iPanel % 3) + indexVectorY * float(iPanel / 3) + makeVect(1.f, 1.f, 1.f);
@@ -2910,8 +2919,7 @@ namespace IMGUIZMO_NAMESPACE
// draw face with lighter color
if (iPass)
{
ImU32 directionColor = GetColorU32(DIRECTION_X + normalIndex);
gContext.mDrawList->AddConvexPolyFilled(faceCoordsScreen, 4, (directionColor | IM_COL32(0x80, 0x80, 0x80, 0x80)) | (isInside ? IM_COL32(0x08, 0x08, 0x08, 0) : 0));
gContext.mDrawList->AddConvexPolyFilled(faceCoordsScreen, 4, faceColor);
if (boxes[boxCoordInt])
{
gContext.mDrawList->AddConvexPolyFilled(faceCoordsScreen, 4, IM_COL32(0xF0, 0xA0, 0x60, 0x80));
@@ -2929,6 +2937,53 @@ namespace IMGUIZMO_NAMESPACE
}
}
}
if (iPass) {
// Draw face label
ImDrawList* drawList = gContext.mDrawList;
ImDrawVert* vtx_write_start = drawList->_VtxWritePtr;
const auto label = gContext.mStyle.FaceLabels[iFace];
ImVec2 labelSize = ImGui::CalcTextSize(label);
float scaleFactor = 2 / size.y;
auto labelOrigin = labelSize * 0.5;
drawList->AddText(ImVec2(0, 0), GetColorU32(TEXT), label);
ImDrawVert* vtx_write_end = drawList->_VtxWritePtr;
vec_t tdx = directionUnary[perpXIndex];
vec_t tdy = directionUnary[perpYIndex];
ImVec2 invert2 = {1, 1};
switch (iFace) {
case 0: // Back
tdx = directionUnary[2];
tdy = directionUnary[1];
invert2 = {-1, - 1};
break;
case 3: // Front
tdx = directionUnary[2];
tdy = directionUnary[1];
invert2.x = -1;
break;
case 1: // Top
invert2.y = -1;
break;
case 4: // Bottom
invert2 = {-1, -1};
break;
case 2: // Right
invert2.y = -1;
break;
case 5: // Left
break;
}
for (auto v = vtx_write_start; v < vtx_write_end; v++) {
auto pp = ((v->pos - labelOrigin) * scaleFactor * invert2 + ImVec2{0.5, 0.5}) * 2.f;
vec_t pt = tdx * pp.x + tdy * pp.y;
v->pos = worldToPos((pt + origin) * 0.5 * invert, res, position, size);
}
}
}
}
@@ -2962,7 +3017,7 @@ namespace IMGUIZMO_NAMESPACE
if (!visible) {
directionColorV.w *= 0.3f;
}
ImU32 directionColor = ImGui::ColorConvertFloat4ToU32(directionColorV);
ImU32 directionColor = ImGui::ColorConvertFloat4ToU32(directionColorV) | IM_COL32(0x80, 0x80, 0x80, 0x00);
drawList->AddLine(baseSSpace, worldDirSSpace, directionColor, gContext.mStyle.TranslationLineThickness);
// Arrow head begin