Screen-Space Positioning for UI Controls in 3D Scenes
A delete button anchored with a world-space offset quietly collapsed into the model center in top-down view — the real bug was projection degeneracy, not a special top-view case.
The Problem
UI controls in a 3D scene often need to follow an object: a delete button, dimension label, or contextual action placed next to the selected model.
A simple implementation is to take the object's world position and add a fixed 3D offset. The problem is that the projected length of that offset changes with the camera angle.
In one prototype, a delete button was anchored at the cube center plus a vertical world-space offset. During real-device testing, I noticed that in a top-down view the button moved into the center of the cube and covered the center handle of the Gizmo.
At first, this looked like a special top-view bug. Claude Code's diagnosis was different: the offset itself was degenerating in screen space. When the camera looks almost directly along the vertical axis, that 3D offset projects to nearly zero pixels, so the button collapses back toward the center.
That also means the problem is continuous rather than view-specific. As the camera approaches a vertical angle, the button gradually moves inward; the top-down view is only the extreme case.
So the fix could not be "use another position in top view." The positioning rule itself needed to change: instead of relying on a world-space direction, calculate the control from the geometry that is actually visible on screen.
Screen-Space Positioning
The final rule uses screen-space coordinates and starts from the lowest visible element rather than from the model center.
Step 1 anchorY = max(A, B, C) + 35px
A = bottom of the cube's projected bounding box
B = lowest visible Gizmo arrow endpoint + 16px
C = lowest dimension-label anchor + 16px
Step 2 button center Y = clamp(anchorY, 28px, viewport height - 28px)
Step 3 button center X = clamp(projected bounding-box center X, 48px, viewport width - 48px)