Skip to content

Instantly share code, notes, and snippets.

@warrenseine
Last active December 21, 2015 04:48
Show Gist options
  • Save warrenseine/6251739 to your computer and use it in GitHub Desktop.
Save warrenseine/6251739 to your computer and use it in GitHub Desktop.
Get the bounding box of a group with Minko.
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