Last active
December 21, 2015 04:48
-
-
Save warrenseine/6251739 to your computer and use it in GitHub Desktop.
Get the bounding box of a group with Minko.
This file contains 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
public function getBoundingBoxOfGroup(group : Group) : BoundingBox | |
{ | |
var min : Vector4 = new Vector4(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE); | |
var max : Vector4 = new Vector4(Number.MIN_VALUE, Number.MIN_VALUE, Number.MIN_VALUE); | |
for each (var mesh : Mesh in group.getDescendantsByType(Mesh)) | |
{ | |
var worldMin : Vector4 = mesh.localToWorld( | |
mesh.geometry.boundingBox.min, null, false, true | |
); | |
var worldMax : Vector4 = mesh.localToWorld( | |
mesh.geometry.boundingBox.max, null, false, true | |
); | |
if (worldMin.x < min.x) | |
min.x = worldMin.x; | |
if (worldMax.x > max.x) | |
max.x = worldMax.x; | |
if (worldMin.y < min.y) | |
min.y = worldMin.y; | |
if (worldMax.y > max.y) | |
max.y = worldMax.y; | |
if (worldMin.z < min.z) | |
min.z = worldMin.z; | |
if (worldMax.z > max.z) | |
max.z = worldMax.z; | |
} | |
return new BoundingBox(min, max); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment