@@ -182,6 +182,15 @@ private void DrawFooterOverlay(Vector2 contentPos, Vector2 contentSize, float bo
182182 ImGui . PopFont ( ) ;
183183 }
184184
185+ private bool IsGizmoVisible ( CameraComponent camera , in Matrix4x4 matrix )
186+ {
187+ if ( ImGuizmo . IsUsing ( ) ) return true ;
188+ if ( camera . ProjectionMode == CameraMode . Orthographic ) return true ;
189+
190+ var viewPosition = Vector3 . Transform ( matrix . Translation , camera . ViewMatrix ) ;
191+ return viewPosition . Z < - camera . NearClipPlane ;
192+ }
193+
185194 private void DrawComponentControlsOverlay ( CameraComponent camera , ActorComponent ? component , Vector2 contentPos , Vector2 contentSize )
186195 {
187196 var view = camera . ViewMatrix ;
@@ -204,7 +213,7 @@ private void DrawComponentControlsOverlay(CameraComponent camera, ActorComponent
204213 if ( manager . _splineOverlay . SelectedHandle != - 1 && manager . _splineOverlay . SelectedSpline is not null )
205214 {
206215 var handleMatrix = manager . _splineOverlay . SelectedHandleMatrix ;
207- if ( ImGuizmo . Manipulate ( ref view . M11 , ref proj . M11 , OPERATION . TRANSLATE , MODE . WORLD , ref handleMatrix . M11 ) )
216+ if ( IsGizmoVisible ( camera , handleMatrix ) && ImGuizmo . Manipulate ( ref view . M11 , ref proj . M11 , OPERATION . TRANSLATE , MODE . WORLD , ref handleMatrix . M11 ) )
208217 {
209218 manager . _splineOverlay . ApplyGizmoMatrix ( handleMatrix ) ;
210219 manager . _splineOverlay . SelectedSpline . MarkDirty ( DirtyFlags . Spline ) ;
@@ -222,7 +231,7 @@ private void DrawComponentControlsOverlay(CameraComponent camera, ActorComponent
222231 {
223232 var matrix = skeleton . BoneMatrices [ boneIndex ] * mesh . GizmoMatrix ;
224233
225- if ( ImGuizmo . Manipulate ( ref view . M11 , ref proj . M11 , _gizmoOperation , MODE . LOCAL , ref matrix . M11 ) )
234+ if ( IsGizmoVisible ( camera , matrix ) && ImGuizmo . Manipulate ( ref view . M11 , ref proj . M11 , _gizmoOperation , MODE . LOCAL , ref matrix . M11 ) )
226235 {
227236 Matrix4x4 . Invert ( mesh . GizmoMatrix , out var invGizmo ) ;
228237 skeleton . MoveBone ( boneIndex , matrix * invGizmo ) ;
@@ -234,7 +243,7 @@ private void DrawComponentControlsOverlay(CameraComponent camera, ActorComponent
234243 case DirectionalLightComponent light :
235244 {
236245 var matrix = light . GizmoMatrix ;
237- if ( ImGuizmo . Manipulate ( ref view . M11 , ref proj . M11 , OPERATION . ROTATE_X | OPERATION . ROTATE_Y | OPERATION . ROTATE_SCREEN | OPERATION . TRANSLATE_Z , MODE . LOCAL , ref matrix . M11 ) )
246+ if ( IsGizmoVisible ( camera , matrix ) && ImGuizmo . Manipulate ( ref view . M11 , ref proj . M11 , OPERATION . ROTATE_X | OPERATION . ROTATE_Y | OPERATION . ROTATE_SCREEN | OPERATION . TRANSLATE_Z , MODE . LOCAL , ref matrix . M11 ) )
238247 {
239248 light . ApplyGizmoMatrix ( matrix ) ;
240249 }
@@ -243,7 +252,7 @@ private void DrawComponentControlsOverlay(CameraComponent camera, ActorComponent
243252 case SpatialComponent spatial when ! _selectMode :
244253 {
245254 var matrix = spatial . GizmoMatrix ;
246- if ( ImGuizmo . Manipulate ( ref view . M11 , ref proj . M11 , _gizmoOperation , _localSpace ? MODE . LOCAL : MODE . WORLD , ref matrix . M11 ) )
255+ if ( IsGizmoVisible ( camera , matrix ) && ImGuizmo . Manipulate ( ref view . M11 , ref proj . M11 , _gizmoOperation , _localSpace ? MODE . LOCAL : MODE . WORLD , ref matrix . M11 ) )
247256 {
248257 spatial . ApplyGizmoMatrix ( matrix ) ;
249258 }
0 commit comments