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 Caiuse · Dec 17, 2012 at 10:57 PM · boundscullingfrustrum

Detect if bounds are "partially" inside camera frustum

So I'm using the useful convenience methods within Unity's API to find if my object is inside the camera view frustum, but I'm wanting to detect if it is partially inside. I'm creating my own quadtree culling system.

 public void Update(){
     planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
     if(GeometryUtility.TestPlanesAABB(planes, renderer.bounds)){
         Debug.Log("is inside");    
     } else {
         Debug.Log("isn't inside");    
     }
 }

Anyone got any ideas or will I have to create my own TestPlanesAABB method?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by CodeMasterMike · Dec 18, 2012 at 09:44 AM

I don't have a code for it, but use the Bounds structure.

In the Bounds structure you have the min, max and size. And with those you can easily calculate all corners of your boundingbox.

When you have those corners you can check each individual position of the corners to see if they are inside the boundaries you have (in your case inside the frustum). And if all corners are inside, then the whole object is inside. If only 1,2 or 3 are inside, then its only partial inside.

Documentation for Bounds structure.

Good luck!

Comment
Add comment · 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 Caiuse · Dec 18, 2012 at 10:28 AM 0
Share

Thanks that a great solution, thanks. I'm wondering, once I have the corner positions, how would I best go about checking them against the frustum plane array?

avatar image CodeMasterMike · Dec 18, 2012 at 11:15 AM 2
Share

If you know which plane is which, then you know that a corner should be to the right of the rightside plane, in front of the nearplane etc.

I've never used the frustum calculation so I don't know how it creates the frustum planes.

$$anonymous$$aybe the Plane.GetSide() function can help you there. http://docs.unity3d.com/Documentation/ScriptReference/Plane.GetSide.html

avatar image Caiuse · Dec 18, 2012 at 09:24 PM 0
Share

Perfect, got it working great. Thanks @Code$$anonymous$$aster$$anonymous$$ike

avatar image IndieForger · Jul 25, 2013 at 11:29 AM 0
Share

@Caiuse - any chance you can post working code here? I am dealing with similar problem right now.

avatar image SantaKlaus · May 04, 2014 at 06:47 AM 0
Share

However note that, contrary to intuition, if all corners are outside the object might still intersect with the frustum.

avatar image
0

Answer by KevinCodes4Food · May 05, 2014 at 07:55 PM

For some of our apps, we create a plane game object at each frustum plane position. A bounding box or other collider can then be added to these planes easily:

I posted code for this on another answer here:

http://answers.unity3d.com/questions/454457/which-plane-is-which-with-calculatefrustumplanes.html#answer-701445

Comment
Add comment · 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

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

13 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

Related Questions

Frustum Cull problem on animated objects 1 Answer

Custom localBounds for MeshRenderer 0 Answers

Custom frustum culling with scissoring 0 Answers

Mesh pop-in/cull with Blender animation. 1 Answer

Checking frustrum against Bounds per Object VS Player&List? 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