Exemplo n.º 1
0
 Solid Retesselated()
 {
     if (IsRetesselated)
     {
         return(this);
     }
     else
     {
         var csg = this;
         var polygonsPerPlane = new Dictionary <string, List <Polygon> >();
         var isCanonicalized  = csg.IsCanonicalized;
         var fuzzyFactory     = new FuzzyCsgFactory();
         foreach (var polygon in csg.Polygons)
         {
             var plane  = polygon.Plane;
             var shared = polygon.Shared;
             if (!isCanonicalized)
             {
                 plane  = fuzzyFactory.GetPlane(plane);
                 shared = fuzzyFactory.GetPolygonShared(shared);
             }
             var            tag = plane.Tag + "/" + shared.Tag;
             List <Polygon> ppp;
             if (polygonsPerPlane.TryGetValue(tag, out ppp))
             {
                 ppp.Add(polygon);
             }
             else
             {
                 ppp = new List <Polygon>();
                 ppp.Add(polygon);
                 polygonsPerPlane.Add(tag, ppp);
             }
         }
         var destpolygons = new List <Polygon>();
         foreach (var planetag in polygonsPerPlane)
         {
             var sourcepolygons = planetag.Value;
             if (sourcepolygons.Count < 2)
             {
                 destpolygons.AddRange(sourcepolygons);
             }
             else
             {
                 var retesselatedpolygons = new List <Polygon>();
                 Solid.RetesselateCoplanarPolygons(sourcepolygons, retesselatedpolygons);
                 destpolygons.AddRange(retesselatedpolygons);
             }
         }
         var result = Solid.FromPolygons(destpolygons);
         result.IsRetesselated = true;
         result.Properties     = Properties;
         return(result);
     }
 }
Exemplo n.º 2
0
 Solid Canonicalized()
 {
     if (IsCanonicalized)
     {
         return(this);
     }
     else
     {
         var factory = new FuzzyCsgFactory();
         var result  = factory.GetCsg(Polygons);
         return(new Solid(result, true, this.IsRetesselated));
     }
 }
Exemplo n.º 3
0
 Solid Canonicalized()
 {
     if (IsCanonicalized)
     {
         return(this);
     }
     else
     {
         var factory = new FuzzyCsgFactory();
         var result  = factory.GetCsg(this);
         result.IsCanonicalized = true;
         result.IsRetesselated  = IsRetesselated;
         result.Properties      = Properties;
         return(result);
     }
 }
Exemplo n.º 4
0
        public List <Solid> SubtractAndPartition(params Solid[] csgs)
        {
            var  a             = new Tree(Bounds, Polygons);
            bool reteselate    = !IsRetesselated;
            bool cannonicalize = !IsCanonicalized;

            foreach (var csg in csgs)
            {
                if (!csg.IsCanonicalized)
                {
                    cannonicalize = true;
                }
                if (!csg.IsRetesselated)
                {
                    reteselate = true;
                }

                var b = new Tree(csg.Bounds, csg.Polygons);
                a.Invert();
                a.ClipTo(b);
                b.ClipTo(a, true);
                a.AddPolygons(b.AllPolygons());
                a.Invert();
            }

            IEnumerable <IReadOnlyList <Polygon> > result = PartitionPolygons(a.AllPolygons());

            if (reteselate)
            {
                result = result.Select(poly => Reteselate(poly, cannonicalize));
            }
            else
            {
                if (cannonicalize)
                {
                    result = result.Select(polys => {
                        var factory = new FuzzyCsgFactory();
                        return(factory.GetCsg(polys));
                    });
                }
            }

            return(result.Select(polys => new Solid(polys, true, true)).ToList());
        }