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
0
Question by Killhatch · May 01, 2013 at 06:36 PM · raycastmeshmeshfilterhorizontalflat

Finding flat, horizontal regions for reliable object placement?

Hello everyone. I am building a plugin for adding decorations (in form of smaller objects) to an already setup scene. I want these objects to be procedurally placed on surfaces that are big enough for them to stand on (avoiding putting a large object on an inadequately small surface area), there is also a limitation to the slope on which the objects can be placed (the angle between the surface normal and the world up vector should be under 30 degrees).

I have considered using ray-casting from above to look for points on the scene objects that are positioned on the same horizontal plane but this doesn't work with concave objects that cover up valid surfaces.

Another possible solution I thought of was to go through each scene object's mesh, looking for vertices with the correct normal values and then somehow recursively looking for equally valid neighboring vertices - but this method seems like a huge task.

I need the area of these flat, horizontal sub-meshes to tell if I can place an object there without it looking like it is disobeying gravity.

I appreciate you reading this far, thank you! I hope someone has a good idea, because my head hurts from thinking about this.

Edit: I have to add that I am looking for these interesting regions on EVERY object in the scene (perhaps with a few exceptions) NOT just the ground. I am not working with a "terrain mesh" it is an indoor environment consisting of many objects.

Comment
Add comment · Show 14
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 Loius · May 01, 2013 at 06:47 PM 0
Share

raycast down until you hit a surface. if flat enough, X. else, raycast down from there until you hit a surface. if flat enough, X. else, raycast...

And stop raycasting in that spot once you hit nothing. That can solve your concave-object woes.

avatar image Fattie · May 01, 2013 at 06:49 PM 1
Share

a smart-arse solution is drop an invisible cube.

if it sits flat, you know the surface is flat to the relevant fractal dimension.


Whoa, you can't post two answers any more! Here's another answer...


the usual trivial solution is, write a routine that takes a point

imagine that to be the center of a square say a meter across. simply get the altitude of the ground at the four corners of the imaginary square

(ie, very likely cast to do that)

if the four altitudes are the same (or within a tolerance), that's good enough ... "it's flat"

I have no idea what you mean about concave etc, but the above is the simple solution. You should realise what you are asking is a near AI problem .. it depends mightily on what you want, what sizes are involved etc.

like my brother-in-law at nasa probably knows $$anonymous$$ms, dozens, of topologists and research students and AI guys who work on problems like "find flat spot on mars to land on" or some such


Whoa, you can't post three answers any more! Here's another answer...


typical code ...

 private var testHit:RaycastHit;
 function _groundElevationNearby(p:Vector3):float    
     {
     p.y = HigherThanEverything;
     if (Physics.Raycast( p, Vector3.down, testHit, ten$$anonymous$$eters, (1<<8) ))
         return testHit.point.y;
     print("WOE IN GROUND EXTRAS - could not get the ground elevation !!");
     return 0.0;
     // the ground is layer "8" in this example. 'ten$$anonymous$$eters' would simply be
     // far enough to hit the ground from the vantage altitude
     }


to check a few points around you'd just go

 _elevation( p + Vector3(1,1,0) );
 _elevation( p + Vector3(-1,-1,0) );
 _elevation( p + Vector3(1,-1,0) );
 _elevation( p + Vector3(-1,1,0) );

just get the $$anonymous$$-max gap (or whatever) of the four numbers

avatar image Fattie · May 01, 2013 at 06:50 PM 0
Share

just TBC I think Loius means, and get the normal when you raycast (that's really obvious to guns like us :-) )

avatar image Killhatch · May 01, 2013 at 06:57 PM 0
Share

Do you guys think that I might use 4 downward directed (Physics.RaycastAll) placed in the shape of a square and look for quadruple-successes (y-axis-wise close to each other and with valid normals)?

avatar image Killhatch · May 01, 2013 at 06:59 PM 0
Share

This would probably take too much unneeded processing power and still not solve the problem of convex objects (a cube dropped over a table won't register the valid spot under the table).

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

Replace MeshFilter mesh by a other mesh in Editor 1 Answer

How do I export GameObject (including child sub-object) to .obj file? 1 Answer

Creating a custom mesh - Cleaning the mesh failed 2 Answers

Mirror vertices procedurally 2 Answers

Detecting whole gameobject, not just its collider 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