public AxisAlignedBoundingBox GetAxisAlignedBoundingBox(Mesh mesh, Matrix4X4 transform)
        {
            lock (locker)
            {
                var cacheCount = cache.Count();
                if (cacheCount > 100)
                {
                    cache.Clear();
                }

                // if we already have the transform with exact bounds than return it
                AxisAlignedBoundingBox aabb;
                if (cache.TryGetValue(transform, out aabb))
                {
                    // return, the fast cache for this transform is correct
                    return(aabb);
                }

                var positions = mesh.Vertices;

                var convexHull = mesh.GetConvexHull(true);
                if (convexHull != null)
                {
                    positions = convexHull.Vertices;
                }

                return(CalculateBounds(positions, transform));
            }
        }
예제 #2
0
        public AxisAlignedBoundingBox GetAxisAlignedBoundingBox(Mesh mesh, AxisAlignedBoundingBox verticesBounds, Matrix4X4 transform)
        {
            // if we already have the transform with exact bounds than return it
            if (aabbTransform == transform && cachedAabb != null)
            {
                // return, the fast cache for this transform is correct
                return(cachedAabb);
            }

            IEnumerable <Vector3> positions = mesh.Vertices.Select((v) => v.Position);

            lock (locker)
            {
                var convexHull = mesh.GetConvexHull(true);
                if (convexHull != null)
                {
                    positions = convexHull.Vertices.Select((v) => v.Position);
                }
            }

            CalculateBounds(positions, transform);
            return(cachedAabb);
        }