- Home /
The question is answered, right answer was accepted
Graphics.DrawMeshNow in Editor Windows OnGUI clipping problem
Hello folks,
I'm currently working on an editor extension. For that I need to render a Mesh inside an Editor Window. I tried using Graphics.DrawMeshNow and it works surprisingly well in terms of just displaying the mesh. By the way, I'm only calling DrawMeshNow during the GUI's Repaint event.
The Mesh is automatically rendered at a position relative to the current GUI area, which is just perfect. However, there is a crucial problem with this.
Even though the positioning works as expected, DrawMeshNow completely ignores clipping, i. e. if it is used inside, say, GUI.BeginGroup or GUI.BeginScrollView it overlaps the given bounds.
But what's even worse, is that it is even drawn ABOVE the editor window's title bar.
Is there a way to sort of set a clipping area for Graphics.DrawMeshNow? Maybe trough the GL class or something?
Thank you very much in advance!
EDIT:
Nevermind, I found a good workaround. Instead of drawing the Mesh directly, I use Handles.DrawCamera to render a temporary scene camera into my editor window. The camera shows another temporary gameobject with the mesh I want to display. However, it was a real struggle to get this to work, since all cameras are always stretched to the currently selected aspect ratio. Therefore, I had a really hard time getting the camera view to fit into my window the way I wanted it.
Thought I'd share the solution to this problem in case someone else finds himself in the same exhausting situation:
The aspect ratio will NOT be automatically enforced if the hideflags of the camera's gameobject are set to at least Hideflags.Hide. The camera will then perfectly fit into the rect passed into the Handles.DrawCamera method.
Really nice. I hope this is intended behavior and does not get "fixed" in a future update.
:)
Follow this Question
Related Questions
How do I make a progress bar in the editor lock the background? 0 Answers
How do I get a reference to the default editor windows (Hierarchy, Console, and Inspector)? 1 Answer
How to force Unity to Repaint an EditorWindow? 1 Answer
EditorWindow not properly drawing 1 Answer
How to stop GUI Text from cutting off half a letter? 1 Answer