Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Physics Collision Geometry Debug Visualization Test1

Discussion in 'Physics' started by MortenSkaaning, Apr 28, 2016.

  1. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    TL;DR: An X-ray view into the physics world.

    Update [5.4]:
    5.4 beta 23 build http://beta.unity3d.com/download/f810054e2680/public_download.html


    Video:

    Build: http://beta.unity3d.com/download/ed1c50496a9c/public_download.html


    Inspector:


    Scene View overlay:


    Hi, we're making a debug view mode for physics collision geometry.

    The idea is to enable the user to quickly inspect the collision geometry in their scene to decide whether collisions should, or should not, happen. This is usually an issue when the Render mesh and Collider mesh gets out of sync.

    Scenes are often arranged by Collision Layer, so this tool allows you to quickly ignore layers to find out where the issues are.

    The tool also enables the user to quickly select GameObjects that own the collision geometry, for further inspection or changes. This will be improved to select individual Collider components in the future.

    The tool also enables the user to debug physics performance issues as it can highlight simulating Rigidbodies. This will have improved support in the future.

    The build is based on Unity 5.3.4p4 so it should be stable for most users.

    Limitations:
    • Cloth, Joints and WheelColliders are not supported yet.
    • Toggling Enable on a TerrainCollider many times causes random selection raycast failures.
    • When using multiple scene views, only the last scene view can effectively do picking.
    • Tree Colliders don't highlight individual trees when hovering over terrains.
    • Drag-rectangle-to-select is not supported.
    Q&A:
    • Q: Isn't this like the PhysX Visual Debugger (PVD)?
      A: It's a light version of PVD with the advantage that we can select GameObjects and Assets directly inside Unity. Ease-of-use was our primary motivation for making the view mode. PVD can be tricky to work with because it is a separate application with different UI/UX conventions. PVD also has performance issues with large terrains.
    • Q: When will this be in a real Unity release?
      A: Earliest in Unity 5.5, but I can probably supply you with custom per-version builds if you are interested. There is a good chance it can get backported as well.
    • Q: You made the drawings in mspaint, didn't you?
      A: Yes I did.
    Future ideas:
    • User defined colors per Layer.
    • Show contact points
    • Improve curvature information by doing light-from-viewpoint shading, like in Maya.
    • Timeline recording and scrubbing.
    • Show more information, like Layer, when hover over a Collider.
    • Network support.
    • Expose more render control to user scripts.
    C# API:
    • The name is expected to change from "PhysicsVisualizationSettings" to "Physics.DebugVis".
    • Cannot be used without the Editor. Standalone players not supported.
    Code (CSharp):
    1. public class PhysicsVisualizationSettings
    2. {
    3.   public static void Reset ();
    4.  
    5.   // properties
    6.   public static bool showCollisionGeometry;
    7.   public static bool enableMouseSelect;
    8.   public static bool useSceneCam;
    9.   public static float viewDistance;
    10.   public static int terrainTilesMax;
    11.   public static bool forceOverdraw;
    12.   public static bool showStaticColliders;
    13.   public static bool showTriggers;
    14.   public static bool showRigidbodies;
    15.   public static Color staticColor;
    16.   public static Color rigidbodyColor;
    17.   public static Color kinematicColor;
    18.   public static float baseAlpha; // (1 - transparency)
    19.   public static bool devOptions;
    20.   public static int dirtyCount;
    21.  
    22.   public static bool GetShowCollisionLayer (int layer);
    23.   public static void SetShowCollisionLayer (int layer, bool show);
    24.  
    25.   public static void UpdateMouseHighlight (Vector2 pos);
    26.   public static void ClearMouseHighlight ();
    27.   public static bool HasMouseHighlight ();
    28. }
    29.  
    Viking Village on Asset Store: https://www.assetstore.unity3d.com/en/#!/content/29140

    Regards,
    Morten,
    Unity physics team.

    Feedback:
    • Visualize raycasts/sweeps.
    • What does this object collide with? Potentially add a checkbox to the little scene view overlay to isolate the visualization to the current selection's collision matrix. If I select an object in the scene (e.g., my character controller) then I would only see colliders on layers that will interact with the selected object's collider.
    • What collision messages will be sent? Similar to previous point, but take into account presence/absence of a Rigidbody, kinematic/non-kinematic state. Potentially reveal a new checkbox in scene view overlay when "isolation mode" is enabled to further limit to only those objects that will send collision messages with the current selection.
    • Other default colors
    • Don't use triangle/wire meshes to display colliders that are not triangle meshes or convex meshes. Make separate button for Convex Colliders.
     
    Last edited: Jun 23, 2016
  2. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    (missing pictures)
     

    Attached Files:

  3. Adam-Mechtley

    Adam-Mechtley

    Unity Technologies

    Joined:
    Feb 5, 2007
    Posts:
    171
    Thanks for sharing, Morten! I think this will be a useful tool. It occurs to me that it could help provide information to help customers with some common problems/questions. For example:
    1. What does this object collide with? Potentially add a checkbox to the little scene view overlay to isolate the visualization to the current selection's collision matrix. If I select an object in the scene (e.g., my character controller) then I would only see colliders on layers that will interact with the selected object's collider.
    2. What collision messages will be sent? Similar to previous point, but take into account presence/absence of a Rigidbody, kinematic/non-kinematic state. Potentially reveal a new checkbox in scene view overlay when "isolation mode" is enabled to further limit to only those objects that will send collision messages with the current selection.
     
  4. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Hi Adam,

    #1 I was already planning on. #2 is a good idea!
     
    Last edited: Apr 28, 2016
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,432
    Thank you very much! Downloading now...
     
  6. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,078
  7. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    Looks interesting. Might have a play later
     
  8. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,432
    Hey Morten,

    I've been testing the build and here's my feedback:

    2016-05-29_231327.png
    • I'd suggest exchanging the Red and Green colors for the visualization. We all are used to see colliders and physics-related objects in green, and I've found that using green for static colliders (scenario) and red for simulating bodies makes a lot more visual sense. Check out the pic. The red simulating bodies get a better highlight in red over the green static scenario.
    • There is some problem when the colliders have some rotation wrt the rigidbody. The rigidibody in the picture (car) hasn't any rotation, but the collider resides in a child gameobject with rotation X -90. The collider is rotated correctly (green wireframe at the car) but the PhysX visualization seems to be applying that rotation twice and the collider ends facing up.
    • Colliders that are far away from the camera position aren't visualized in the PhysX view. Maybe there's some cull by distance, so I'm not sure if this is the intended behavior. In the picture below you can see the large object at the upper left part of the view not getting the physx view. It also has a static collider.
    Hope this helps! Let me know if I can help you further.
    Edy
     
  9. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Thanks, I'll have a look at it. Is the car from the Standard Examples package?

    How far away do you have to go for the colliders to stop showing?
     
  10. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,432
    No, it's one of my development models. But the bug can be easily reproduced:
    1. Create an empty GameObject, then add a Rigidbody to it.
    2. Create a 3D Cube and put it as child of the GameObject
    3. At the cube, remove the Box Collider and add a Mesh Collider.
    4. Mark the Mesh Collider as Convex
    5. Rotate the Cube
    You'll see how the PhysX collider and the Unity collider rotate at different rates.

    Nevermind, I've just realized about the "View Distance" setting :p
     
  11. Le_Tai

    Le_Tai

    Joined:
    Jun 20, 2014
    Posts:
    272
    Which version of window are you using? 98?
     
  12. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
  13. Le_Tai

    Le_Tai

    Joined:
    Jun 20, 2014
    Posts:
    272
    Is there any particular reason you use that theme?
     
  14. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    it has less distractions than Aero
     
  15. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Update: Link added for a build based on 5.4 beta 23.
     
    Edy likes this.
  16. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    @Edy I can't reproduce your rotation on my latest version, so let's see if you can repro it later on.
     
  17. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,432
    @MortenSkaaning Great, is that the latest build? (based on 5.4 beta 23)
     
  18. Orangy-Tang

    Orangy-Tang

    Joined:
    Jul 24, 2013
    Posts:
    12
    So I gave this a whirl on one of our levels and it seemed pretty good, which is nice. :) It let me see a few places where objects that should be sleeping aren't sleeping which is what I was trying to track down (although just changing the wireframe colour is not super obvious, something more visible at a distance would be good).

    Things I'd like to see:
    - Show contact points. The profiler shows we have a lot of contact points even on a supposedly 'still' scene. Would be good to see what's actually happening here.

    - We drive lots of gameplay from physics callbacks, it would be good to see a representation of when these are firing and how often (usually we have custom code to explicitly ignore repeat events, but would like to see when / where this is happening as it's wasted perf).

    - Lots of our non-sleeping objects seem to be due to hinges. Better visualisation of what hinges are up to would be great.

    Looking forward to this being in a proper unity release! Thanks :D
     
  19. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Hi,

    We made a new forum for feedback on the Physics Debug Visualization for Unity 5.5.

    https://forum.unity3d.com/threads/physics-debug-visualization.442106/

    Once Unity 5.5 is released I will update the build with the Physics Debug Visualization.
    New features in the visualizer is filtering per Collider type and sleeping status. This enables the visualizer to function as an easy-to-use profiler.

    Regards,
    Morten