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
3
Question by Zebibto · Aug 15, 2013 at 02:42 PM · meshbounds

Getting actual AABB of an object

I'm trying to get the actual AABB of an object in the editor.

The mesh.bounds are an AABB for the object in it's default transform. (Magenta)

If you transform the mesh.bounds using the objects transform matrix, (red) you get the results of the object.renderbounds (yellow)

What I want is an AABB that extents to the min and max of the actual mesh (green)

Right now I loop through every vertex in the mesh. I transform it by the objects transform matrix. Then check for minimum and maximum values. Is there a better way to do this?

I only need it in the editor, but I'm assuming it's not very efficient looping through mesh verts like that.

Pseudocode:

 for each vertex in mesh
     point = vertex.position * object.worldMatrix
 
     if (point > max)
         max = point 
 
     if (point < min)
         min = point 

alt text

2013-08-15_22-15-49.png (35.9 kB)
Comment
Add comment · Show 2
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 numberkruncher · Aug 15, 2013 at 02:49 PM 0
Share

If you compute vertex positions for each corner of the red bounding box, you could just enumerate those to deter$$anonymous$$e the render bounds? This way there are only 8 vertices to consider rather than each mesh vertex.

avatar image robertbu · Aug 15, 2013 at 02:55 PM 0
Share

I ran across this answer by @bunny83 a couple of weeks ago that suggested that to produce the bounds you specify, the way is to loop through the vertices:

http://answers.unity3d.com/questions/297453/finding-locations-of-vertices-on-a-mesh.html.

Given that procedural meshes that modify the mesh every frame run in real time, I doubt you will have performance issues with checking the vertices.

BTW: Great picture.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Zebibto · Aug 16, 2013 at 04:17 AM

@robertbu Thanks for the link. That's pretty much what I'm doing at the moment. Was just wondering if there is something built-in that might be faster/more optimized. I'll just keep using what I have then.

@numberkruncher Yes, but you don't have to compute a bounding box from the transformed mesh bounds. Each object already has renderbounds built-in (object.renderer.bounds) that you can use. I used that for illustration purposes since I didn't know at first why the render bounds were bigger than the actual object.

Thanks for the replies. I'll consider my question answered then.

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 kopsidam · Oct 21, 2016 at 04:15 PM 0
Share

Could you please tell me how did you take the transformed mesh bounds? I am interested in finding the same but I struggle...Thanks!

avatar image Bunny83 kopsidam · Oct 21, 2016 at 04:30 PM 0
Share

Your question isn't clear. Renderer.bounds gives you the transformed mesh bounds in worldspace. But as you can see in the image above, the transformed mesh bounds might not be the optimal axis aligned bounding box as it's usually larger. If you want an exact axis aligned bounding box there's no way around transfor$$anonymous$$g every vertex yourself and calculating the bounding box the way as i showed in the answer robertbu linked above.

Btw: You just woke a three years old question. If you have a similar question that isn't answered by the information provided here, ask your own seperate question ins$$anonymous$$d of commenting on old questions. Feel free to post a link to this question in your question as reference, but make sure you describe your problem more detailed.

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

18 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

Related Questions

Bounds Finding Box 1 Answer

Generate Bounding Box, In Game 1 Answer

Getting Bounding box from a collider with children 1 Answer

Mesh.RecalculateBounds 1 Answer

when should Mesh.Optimize() be called 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