示例#1
0
        public override Bounds CalculateBounds()
        {
            if (!brushMeshAsset)
            {
                return(CSGHierarchyItem.EmptyBounds);
            }

            var modelMatrix = CSGNodeHierarchyManager.FindModelTransformMatrixOfTransform(hierarchyItem.Transform);
            var bounds      = CSGHierarchyItem.EmptyBounds;

            var foundBrushes = new HashSet <CSGTreeBrush>();

            GetAllTreeBrushes(foundBrushes, false);
            foreach (var brush in foundBrushes)
            {
                var transformation = modelMatrix * brush.NodeToTreeSpaceMatrix;
                var assetBounds    = brushMeshAsset.CalculateBounds(transformation);
                var magnitude      = assetBounds.size.sqrMagnitude;
                if (float.IsInfinity(magnitude) ||
                    float.IsNaN(magnitude))
                {
                    var center = transformation.GetColumn(3);
                    assetBounds = new Bounds(center, Vector3.zero);
                }
                if (assetBounds.size.sqrMagnitude != 0)
                {
                    if (bounds.size.sqrMagnitude == 0)
                    {
                        bounds = assetBounds;
                    }
                    else
                    {
                        bounds.Encapsulate(assetBounds);
                    }
                }
            }

            return(bounds);
        }