Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by kher · Nov 11, 2014 at 01:39 AM · editor-classes

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kher · Nov 11, 2014 at 08:50 AM 0
Share

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

avatar image kher · Nov 11, 2014 at 08:50 AM 0
Share

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.

avatar image Bunny83 · Nov 11, 2014 at 02:19 PM 0
Share

@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 :)

avatar image kher · Nov 11, 2014 at 07:27 PM 0
Share

Thank you so much Bunny, working like a charm :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges