• 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
Question by rustyruss1985 · Aug 10, 2018 at 05:17 PM · meshcollision detectionselectionintersection

fast intersection detection for 10s of thousands of lines?

Hello, i have a project where i render up to 10,000+ individual lines, each made of around 50-60 points.

right now, i'm using a Mesh with MeshTopology.Lines to render my lines (i have to break up my dataset of 10,000+ lines into several different meshes, because each mesh can only hold 64,000 points).

what i want to do now is use some kind of selection object (a simple sphere for example) that the user can move about the scent, to select w$$anonymous$$ch lines will be rendered on the screen - i only want to show lines that intersect with the selection object (sphere).

however, i'm having trouble finding a way to detect w$$anonymous$$ch lines are intersecting with the selection object. obviously, i could just do a giant for loop over all my points, and set any lines whose points intersect with the sphere to 0, but t$$anonymous$$s is not feasible for a real time application.

anyone know how i can quickly detect w$$anonymous$$ch lines (or points) in multiple meshes intersect with another game object?

thanks

ps here's an example of one of my meshes with ~64000 points - i will have dozens of these active in the scene at any one time.

         Mesh mesh = new Mesh();
         mesh.vertices = verts;
         mesh.SetColors(colors);
         mesh.SetIndices(inds, MeshTopology.Lines, 0);
         mesh.RecalculateBounds();
 

Comment

People who like this

0 Show 0
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
Best Answer

Answer by Bunny83 · Aug 10, 2018 at 06:35 PM

There are several t$$anonymous$$ngs not clear. You said you render lines. However a line is a straight connection between two points. How can a line have 50 to 60 points? That sounds more like you draw "line strips". In t$$anonymous$$s case you have much more individual lines. Probably around 50k


Next t$$anonymous$$ng is Unity's Mesh class now supports 32 bit index buffers so you can have more than 64k vertices in a single mesh. You just have to set the index format before you assign your data.


Do you want to draw the whole line (or line strip) when any part is intersecting your sphere or do you only want to draw the line parts w$$anonymous$$ch are inside your sphere? In the second case you can simply use a shader where you define your sphere parameters in global parameters and simply cull your fragments based on the distance from the sphere center.


If you want to draw the whole line / line strip there's no way around checking the intersection on the CPU. If the lines / points are static you can speed up the intersection testing by using some spatial structure (like an octree). However it depends on how those lines are distributed in space.


I'm happy to extend my answer with a more detailed solution once it's clear what exact behaviour you want and how the lines are distributed. A screenshot would help.

Comment
rustyruss1985

People who like this

1 Show 5 · 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 rustyruss1985 · Aug 10, 2018 at 07:10 PM 0
Share

thanks for the response Bunny83. you are correct, i am drawing curves, not lines, i should have specified that better (each curve has around 50-60 points).

good to know that a mesh can now support up to 4 billion vertices, this makes my job much easier in the future, although for now i think i will leave as is.

i want to exclude/include the entire line based on intersection with the sphere. so if any part of the line is touching the sphere, the entire line will be included/excluded. i'm trying to reproduce what you see in this youtube vid at 0:25 https://www.youtube.com/watch?v=tL2AjQ4XEn4 in unity.

the points are static in the sense that they don't move relative to one another, but they can be rotated/translated as a whole by the user changing the view (see the video above).

so basically, i need a fast way to access the points in my mesh and see if they intersect a sphere, and if they do, disable any line that the point is a part of.

i have a very slow solution working at the moment where i just loop all points in all my meshes, but it doesn't really perform well past a couple hundred lines, ideally i would want this running smoothly on 10k+ lines. if you could advise me on how to achieve that, it would be great.

thanks!

avatar image Bunny83 rustyruss1985 · Aug 10, 2018 at 08:09 PM 0
Share

Ok, well, if the line segments of one fiber is short enough you could just forget about calculating an actual intersection but just check which points are inside your selection volume. There might be some edge cases where a line segment actually crosses your selection volume but both endpoints are outside. Though if the size of your selection volume is rather large compared to the length of a single line segment it shouldn't matter.


Since the points are static (at least in the video you showed) you may store all points in an octree for faster intersection testing. As for selecting the right fibers i would probably use a dictionary. As key you could use the index of a point and map it to the fiber index the point belongs to.


avatar image rustyruss1985 Bunny83 · Aug 10, 2018 at 08:48 PM 0
Share

thanks. i'm not really familiar with octrees but i'll read up on them. how exactly would you store the points in the octree for my purposes, and how would that speed up intersection testing?

also, this is a bit off topic from the octree, but once i have my curves enabled/disabled, is there a faster way to set a few points in the mesh without using a loop over all points in the mesh and then using:

     mesh.SetVertices(newVertices);
     mesh.RecalculateBounds();

thanks again

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

102 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 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 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 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 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 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 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

Intersection of two game object 0 Answers

Weird bounce on collision with perfectly aligned (generated) meshes for fast object 3 Answers

How can I make certain parts of my object selectable? 1 Answer

detect if two objects in a list intersect in editor. 0 Answers

OnCollisionEnter detects few contact points 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