Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rotation tool renders incorrectly with non-identity Handles.matrix

Discussion in 'Immediate Mode GUI (IMGUI)' started by karl_, Jan 21, 2015.

  1. karl_

    karl_

    Joined:
    Mar 4, 2010
    Posts:
    464
    When transforming the `Handles.matrix`, it looks like the rotation handle is being depth tested in the wrong view space. It behaves correctly, and draws the colors in the right orientation, but culls the wrong sides.

    Here's a little editor script showing this behavior. First, draw the rotation handle by passing rotation and translation in the `Handles.RotationHandle()` function. Next, render it in the same position, but instead transform the Handles matrix and pass identity and zero to the RotationHandle method. The latter is in the correct place with the right orientation, but renders half missing in the wrong direction.



    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4. using System.Collections;
    5.  
    6. [CustomEditor(typeof(HandlesMatrix))]
    7. public class HandlesMatrixEditor : Editor
    8. {
    9.     bool useMatrix = true;
    10.  
    11.     void OnSceneGUI()
    12.     {
    13.         Handles.BeginGUI();
    14.  
    15.             if(GUILayout.Button("Toggle Matrix", GUILayout.MaxWidth(128)))
    16.                 useMatrix = !useMatrix;
    17.         Handles.EndGUI();
    18.  
    19.         Quaternion right = Quaternion.LookRotation(Vector3.up, Vector3.right);
    20.  
    21.         /**
    22.          * If not modifying the Handles.matrix, things render properly.
    23.          */
    24.         if(!useMatrix)
    25.         {
    26.             Handles.RotationHandle(right, Vector3.one);
    27.             Handles.PositionHandle(Vector3.one, right);
    28.         }
    29.         else
    30.         {
    31.             /**
    32.              * Change the handles matrix, and the rotation handle renders incorrectly (position is fine, but the little plane grabbies are off)
    33.              */
    34.             Matrix4x4 mat = Matrix4x4.TRS(Vector3.one, right, Vector3.one);
    35.             Handles.matrix = mat;
    36.                 Handles.RotationHandle(Quaternion.identity, Vector3.zero);
    37.                 Handles.PositionHandle(Vector3.zero, Quaternion.identity);
    38.             Handles.matrix = Matrix4x4.identity;
    39.         }
    40.     }
    41. }
    42.  
    43.  
     
  2. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,891
    Getting this behavior in 2018.2.0. Has anyone found a workaround for this bug?