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 Noam · Jan 06, 2011 at 10:16 AM · graphicsscreenspacedrawmesh

Drawing a screen space rectangle with Graphics.DrawMeshNow

Hi,

I want to draw a screen space rect based on a unity rect. Currently I do this :

Vector3[] vertices = new Vector3[4]; vertices[0] = new Vector3(testPos.xMin, testPos.yMin, Camera.current.nearClipPlane); vertices[1] = new Vector3(testPos.xMin, testPos.yMax, Camera.current.nearClipPlane); vertices[2] = new Vector3(testPos.xMax, testPos.yMax, Camera.current.nearClipPlane); vertices[3] = new Vector3(testPos.xMax, testPos.yMin, Camera.current.nearClipPlane); for (int i = 0; i < 4; i++) { vertices[i] = Camera.current.ViewportToWorldPoint(vertices[i]); } mesh.vertices = vertices;

     testMaterial.SetPass(0);
     Graphics.DrawMeshNow(mesh, Matrix4x4.identity);

This works as expected. However, I would prefer not to set the vertices each time, but rather set the world matrix of the object differently each frame. That way I could create the mesh once and use it each time. I don't understand exactly how to work it out. Can someone lend a hand?

Thanks!

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 cjmarsh · Jan 06, 2011 at 11:37 AM

If your goal is to simply render the mesh in the same scale in front of the camera, I don't think you need the matrix at all. You should be able to draw the mesh using only this:

Graphics.DrawMeshNow(mesh, Camera.current.transform.position, Camera.current.transform.rotation);

If your mesh is initially positioned on the camera's nearClipPlane the way that you want it then it should work as intended. I believe this works because the scale is the extra dimension that the matrix is capable of handling but the constant z-value of the camera's plane negates the need for it. Let me know if my math is rusty or if it doesn't work the way you had in mind.

Comment
Add comment · Show 1 · 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 Noam · Jan 09, 2011 at 11:45 AM 0
Share

Yea, thats what I ended up doing pretty much. Thanks!

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

1 Person is following this question.

avatar image

Related Questions

Where to call Graphics.DrawMesh to successfully draw during editor pause? 0 Answers

Changing draw order of meshes in Graphics.DrawMesh() 1 Answer

Will Camera.RenderWithShader work with Graphics.DrawMesh (and DrawMeshInstanced)? 0 Answers

How to attach a mesh created with Graphics.DrawMesh to a GameObject? 1 Answer

How to access full Shuriken simulation mesh for use with DrawMeshNow? 0 Answers


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