Answers for "Get EXACT SkinnedMeshRenderer bounds"
http://answers.unity.com/questions/1588910/get-exact-skinnedmeshrenderer-bounds.html
The latest answers for the question "Get EXACT SkinnedMeshRenderer bounds"Answer by punk
http://answers.unity.com/answers/1767688/view.html
Here's they way I got it working, just bear in mind that because the bounds are local just make sure your root bone is pointing up, otherwise the bounds will be at an angle
skinnedMeshRenderer.updateWhenOffscreen = true;
Bounds bounds = new Bounds();
Vector3 center = skinnedMeshRenderer.localBounds.center;
Vector3 extents = skinnedMeshRenderer.localBounds.extents;
bounds.center = center;
bounds.extents = extents;
skinnedMeshRenderer.updateWhenOffscreen = false;
skinnedMeshRenderer.localBounds = bounds;Mon, 31 Aug 2020 18:14:41 GMTpunkAnswer by DaveL99
http://answers.unity.com/answers/1674150/view.html
Here is what I did:
I store a copy of the gameObject's position & rotation, and then set the position to zero and rotation to identity - effectively (temporarily) making local space and world space the same thing.
I then go through all Renderer objects that exist within the gameObject and it's children, and build up the AABB using Bounds.Encapsulate and the Renderer's .bounds property (which returns AA bounds accounting for animations etc. in World-space - but since I've put the object at the origin this is also Local-space).
Finally, I restore the original position & rotation on the gameObject's transform, and then from my "local-space" bounding-box I construct 8 corner vertices and then transform each one into World-space with transform.TransformPoint.
That gives me a non axis-aligned bounding box in world-space, that remains consistent regardless of how the object is rotated in the world etc.
One of the biggest gotchas that people might encounter, is that you can't simply initialise your bounds to zero, or empty. i.e. Don't do this:
boundingBox = new Bounds ();
for (int i = 0; i < renderers.Count; i++)
{
boundingBox.Encapsulate (renderers [i].bounds);
}
Instead you should do this:
boundingBox = renderers [0].bounds;
for (int i = 1; i < renderers.Count; i++)
{
boundingBox.Encapsulate (renderers [i].bounds);
}Fri, 25 Oct 2019 15:34:20 GMTDaveL99