-
-
Save ViktorKrepelka/d6be603f292bf93042d8c7fd7484d7e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //return visible percentage of object from camera | |
| public float GetVisiblePercentage(Bounds bounds, Camera cam) | |
| { | |
| float totalVolume = bounds.size.x * bounds.size.y * bounds.size.z; | |
| float visibleVolume = 0f; | |
| Plane[] planes = GeometryUtility.CalculateFrustumPlanes(cam); | |
| for (int i = 0; i < planes.Length; i++) | |
| { | |
| visibleVolume += Mathf.Max(0f, Vector3.Dot(planes[i].normal, bounds.max - cam.transform.position)); | |
| } | |
| float visiblePercentage = visibleVolume / totalVolume * 100f; | |
| return visiblePercentage; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment