Exemple #1
0
//		internal bool ContainsPoint(Vector3 point)
//		{
//			return GeometryHelper.PolyhedronContainsPoint(this.polygons, point);
//		}

        //		internal bool ContainsPointEpsilon1(Vector3 point)
//		{
//			return GeometryHelper.PolyhedronContainsPointEpsilon1(this.polygons, point);
//		}

        //		internal bool SplitByPlaneNew(Plane splitPlane, out BrushChunk chunkFront, out BrushChunk chunkBack)
//		{
//			Polygon createdPolygon1;
//			Polygon createdPolygon2;
//
//			List<Polygon> polygons1 = PolygonFactory.ClipPolygons(this.Polygons.ToArray().DeepCopy(), splitPlane, out createdPolygon1);
//			splitPlane = splitPlane.Flip();
//			List<Polygon> polygons2 = PolygonFactory.ClipPolygons(this.Polygons.ToArray().DeepCopy(), splitPlane, out createdPolygon2);
//
//			if(createdPolygon1 != null)
//			{
//				createdPolygon1.ExcludeFromFinal = true;
//			}
//			if(createdPolygon2 != null)
//			{
//				createdPolygon2.ExcludeFromFinal = true;
//			}
//
//			if(polygons1.Count > 0 && polygons2.Count > 0)
//			{
//				chunkFront = new BrushChunk(polygons1);
//				chunkBack = new BrushChunk(polygons2);
//
//				return true;
//			}
//			else
//			{
//				chunkFront = null;
//				chunkBack = null;
//				return false;
//			}
//		}

        internal bool SplitByPlane(Plane splitPlane, out BrushChunk chunkFront, out BrushChunk chunkBack)
        {
            List <Polygon> polygonsFront;
            List <Polygon> polygonsBack;

            if (PolygonFactory.SplitPolygonsByPlane(polygons, splitPlane, true, out polygonsFront, out polygonsBack))
            {
                if (polygonsFront.Count > 0)
                {
                    chunkFront = new BrushChunk(polygonsFront, this.splitPlanes);
                }
                else
                {
                    Debug.LogError("SplitPolygonsByPlane said it succeeded but returned an empty list");
                    chunkFront = null;
                    chunkBack  = null;
                    return(false);
                }

                if (polygonsBack.Count > 0)
                {
                    chunkBack = new BrushChunk(polygonsBack, this.splitPlanes);
                }
                else
                {
                    Debug.LogError("SplitPolygonsByPlane said it succeeded but returned an empty list");
                    chunkFront = null;
                    chunkBack  = null;
                    return(false);
                }
                return(true);
            }
            else
            {
                chunkFront = null;
                chunkBack  = null;
                return(false);
            }
        }
Exemple #2
0
        private static void SplitAndRemove(LinkedList <BrushChunk> brushChunks, BrushCache removee, int[] polygonsRemoved)
        {
            Polygon[] polygons    = removee.Polygons;
            Plane[]   splitPlanes = removee.SplitPlanes;

            for (int polygonIndex = 0; polygonIndex < polygons.Length; polygonIndex++)
            {
                Plane splitPlane = splitPlanes[polygonIndex];

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

                    BrushChunk chunkIn;
                    BrushChunk chunkOut;

                    if (current.Value.SplitByPlane(splitPlane, out chunkIn, out chunkOut))
                    {
                        // TODO: If chunkIn is fully inside polygons, delete it
                        current.Value = chunkOut;

                        if (!GeometryHelper.PolyhedronContainsPolyhedron(polygons, chunkIn.Polygons))
                        {
                            current = brushChunks.AddAfter(current, chunkIn);
                        }
                        else
                        {
                            for (int i = 0; i < chunkIn.Polygons.Count; i++)
                            {
                                if (chunkIn.Polygons[i].UniqueIndex != -1)
                                {
                                    int relativeIndex = chunkIn.Polygons[i].UniqueIndex - firstPolygonUID;
                                    MarkPolygonRemoved(relativeIndex, polygonsRemoved);
                                }
                            }
                        }

                        // Next iteration
                        current = current.Next;
                    }
                    else
                    {
                        LinkedListNode <BrushChunk> next = current.Next;
                        BrushChunk chunk = current.Value;
                        if (GeometryHelper.PolyhedronContainsPolyhedron(polygons, chunk.Polygons))
                        {
                            for (int i = 0; i < chunk.Polygons.Count; i++)
                            {
                                if (chunk.Polygons[i].UniqueIndex != -1)
                                {
                                    int relativeIndex = chunk.Polygons[i].UniqueIndex - firstPolygonUID;
                                    MarkPolygonRemoved(relativeIndex, polygonsRemoved);
                                }
                            }

                            brushChunks.Remove(current);
                        }
                        // Next iteration
                        current = next;
                    }
                }
            }
        }