- Home /
Is it possible to use DrawMesh or DrawMeshNow in an editor window?
Hi,
I'm trying to render 'advanced' geometries in an editor window.
I was able to use the GL class, like it is described in the documentation, to display simple things like QUADS or LINES. But I would like to directly render meshes (more efficient if multiple instances & same result as in game if you cook some data).
The candidate I found is the Graphics class. But whatever I'm trying, I can't see anything in my editor window. I'm not sure of the meaning of the parameters you can give to Graphics: Matrix? But relative to which Camera, if you are in an editor window? Is it really something you can use here?
Did anyone already successfully use Graphics in an Editor window?
Thanks in advance!
Answer by Bunny83 · Nov 11, 2014 at 01:44 AM
As far as i remember the Graphics class is a pro only feature, at least most methods in it. Also make sure you draw them during the Repaint event. However for free users you can still simply use a camera to draw something to an EditorWindow. Just call cam.Render inside your OnGUI method during the repaint event. Keep in mind when setting up temporary cameras / lights / objects to create them with hideflags "dontsave". Also when no longer using those objects you should destroy them with DestroyImmediate.
if you have Unity pro and want to use DrawMeshNow, make sure you have:
set a shader pass of a material
have setup the viewport (GL.Viewport)
have setup some projection (GL.LoadOrtho / GL.LoadPixelMatrix / GL.LoadProjectionMatrix)
Thanks Bunny.
Actually, I might prefer to use a camera, it would be more straightforward, but all the examples I have seen are using a render texture as an intermediate, which is also a pro feature, isn't it? I couldn't find a real time example of rendering of the scene, in a part of a unity editor window.
Or did you mean that it's actually possible to directly render the camera in the editor gui?
Thanks
Hey Bunny, I just tried to call Render as you described, you're right, it worked! Sometimes, the simplest things ... :) Thanks!
Do you know how to control where the camera is renderered? At the moment, it's using the settings of the game/scene view. I'm going to try rendering it in a given Rect.
@kher: You have to use the camera's pixelRect. It's relative to the editor window. Unfortunately to the whole editor window including the tab / title bar at the top. Also as far as i remember the pixelRect is in screen space while the rest of your GUI is in gui space. They are actually almost the same but y is reversed. So screen space has it's origin at the bottom left corner and the gui at the top left corner.
Unity provides two helper methods: GUIUtility.GUIToScreenPoint and GUIUtility.ScreenToGUIPoint which might be useful :)
Your answer
Follow this Question
Related Questions
How can I invoke code on the Editor GUI thread from a worker? 1 Answer
How do i get Mountains to look Smooth? 0 Answers
Remove or disable an EditorGUILayout.PropertyField 0 Answers
What are the drawbacks/limitations of using an Editor Class? 1 Answer
Making an RPG Maker VX esque database using ScriptableObject, with custom editor 1 Answer