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 cclaypool1 · May 17, 2013 at 09:17 PM · cameraterrainverticeslodplanets

Find closest vertices to camera.

I am working on a simple LOD system for my randomly generated spherical terrain and have everything worked out except for how to find the 9 closest vertices to the camera. Is there any way to easily implement this?

Comment
Add comment · Show 5
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 Fattie · May 18, 2013 at 07:43 AM 0
Share

what is "spherical terrain" ?

avatar image cclaypool1 · May 19, 2013 at 05:56 AM 0
Share

Planetary Terrain

avatar image Fattie · May 19, 2013 at 06:06 AM 0
Share

oh, that's a "sphere". further your camera is always equatorial?

yeah just keep all the longitudes and get them from that

if the camera moves around just use ordinary old culindrical projection and draw a square

avatar image cclaypool1 · May 19, 2013 at 06:09 AM 0
Share

It is a 3D cube with its vertices mapped to a sphere. I don't have lighting on my shader so you can,t make out the perspective of it. Here it is with a per vertex shader with lighting.

avatar image Fattie · May 19, 2013 at 07:20 AM 0
Share

yeah if it's a sphere keep the info lat/long with each vert

it's absolutely trivial to then get the verts nearest a satellite, or solve other similar problems

generally whenever you fool about with a sphere ... you keep a Handy List of lat/long for each vert

(I suppose even more generally, whenever you fool with some trivial surface that has a really clear projection to another set of coordinates, you almost always need that other set of coordinates, on hand, for one reason or another!)

it goes without saying: performance is almost never relevant so obviously just brute force it first!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by whydoidoit · May 17, 2013 at 09:19 PM

Using Linq:

    using System.Linq;
    ...
    var pos = Camera.main.transform.position;
    var closest = mesh.vertices.OrderBy(v=>(v - pos).sqrMagnitude).Take(9).ToArray();
Comment
Add comment · Show 2 · 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 whydoidoit · May 17, 2013 at 09:20 PM 0
Share

But it won't be that fast if you have a lot of vertices!

avatar image whydoidoit · May 19, 2013 at 06:29 AM 0
Share

If you have a lot of vertices and the mesh isnt changing then cache it when it's built otherwise mesh.vertices makes a new array every time.

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

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distant terrain level of detail question. 0 Answers

Play mode problem 2 Answers

What can I do to prevent my terrain and camera from disappearing from the hierarchy and project interfaces? 1 Answer

Unity automatically rotate camera on slopes up/down 0 Answers

How is LOD implemented? 3 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