コード例 #1
0
        private static void RemoveInteriorPolygons(LinkedList <BrushChunk> brushChunks, BrushCache removee, List <Polygon> excludedPolygons, int[] polygonsRemoved)
        {
            // TODO: If a polygon is in a subtract last rather than an add it shold not be removed
            Polygon[] polygons    = removee.Polygons;
            Vector3   brushCenter = removee.Bounds.center;

            for (LinkedListNode <BrushChunk> current = brushChunks.First; current != null; current = current.Next)
            {
#if !NO_EARLYOUT
                if (!current.Value.GetBounds().IntersectsApproximate(removee.Bounds))
                {
                    continue;
                }
#endif

                List <Polygon> chunkPolygons = current.Value.Polygons;
                for (int i = 0; i < chunkPolygons.Count; i++)
                {
                    if (chunkPolygons[i].ExcludeFromFinal == false)
                    {
                        Vector3 polygonCenter  = chunkPolygons[i].GetCenterPoint();
                        float   distanceInside = GeometryHelper.PolyhedronContainsPointDistance(polygons, polygonCenter);
                        if (distanceInside > 1E-05)
                        {
                            int relativeIndex = chunkPolygons[i].UniqueIndex - firstPolygonUID;
                            MarkPolygonRemoved(relativeIndex, polygonsRemoved);

                            // Well inside the brush, so remove it
                            chunkPolygons[i].ExcludeFromFinal = true;
                            excludedPolygons.Add(chunkPolygons[i]);
                        }
                        else if (distanceInside >= -1E-05)
                        {
                            // Edge case, make sure the face is towards the brush
                            if (Vector3.Dot(brushCenter - polygonCenter, chunkPolygons[i].Plane.normal) > 0)
                            {
                                int relativeIndex = chunkPolygons[i].UniqueIndex - firstPolygonUID;
                                MarkPolygonRemoved(relativeIndex, polygonsRemoved);

                                chunkPolygons[i].ExcludeFromFinal = true;
                                excludedPolygons.Add(chunkPolygons[i]);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        private static void RestoreInteriorPolygons(LinkedList <BrushChunk> brushChunks, BrushCache removee, List <Polygon> excludedPolygons, int[] polygonsRemoved)
        {
            // TODO: If a polygon is in a subtract last rather than an add it shold not be removed
            Polygon[] polygons    = removee.Polygons;
            Vector3   brushCenter = removee.Bounds.center;

            for (int i = 0; i < excludedPolygons.Count; i++)
            {
                Vector3 polygonCenter = excludedPolygons[i].GetCenterPoint();

#if !NO_EARLYOUT
                if (!removee.Bounds.ContainsApproximate(polygonCenter))
                {
                    continue;
                }
#endif

                float distanceInside = GeometryHelper.PolyhedronContainsPointDistance(polygons, polygonCenter);
                if (distanceInside > 1E-05)
                {
                    int relativeIndex = excludedPolygons[i].UniqueIndex - firstPolygonUID;
                    MarkPolygonRestored(relativeIndex, polygonsRemoved);

                    // Well inside the brush, so restore it
                    excludedPolygons[i].ExcludeFromFinal = false;
                    excludedPolygons.Remove(excludedPolygons[i]);
                    i--;
                }
                else if (distanceInside >= -1e-5f)
                {
                    // Edge case, make sure the face is towards the brush
                    if (Vector3.Dot(brushCenter - polygonCenter, excludedPolygons[i].Plane.normal) > 0)
                    {
                        int relativeIndex = excludedPolygons[i].UniqueIndex - firstPolygonUID;
                        MarkPolygonRestored(relativeIndex, polygonsRemoved);

                        excludedPolygons[i].ExcludeFromFinal = false;
                        excludedPolygons.Remove(excludedPolygons[i]);
                        i--;
                    }
                }
            }
        }