Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Rotation tool renders incorrectly with non-identity Handles.matrix

Discussion in 'Extensions & OnGUI' 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:
    602
    Getting this behavior in 2018.2.0. Has anyone found a workaround for this bug?