Exemple #1
0
        public IEnumerable <Face> GetBoxFaces()
        {
            var faces = new List <Face>();

            if (Children.Any())
            {
                return(faces);
            }

            var box        = BoundingBox.GetBoxFaces();
            var dummySolid = new Solid(-1)
            {
                IsCodeHidden     = IsCodeHidden,
                IsRenderHidden2D = IsRenderHidden2D,
                IsSelected       = IsSelected,
                IsRenderHidden3D = IsRenderHidden3D,
                IsVisgroupHidden = IsVisgroupHidden
            };

            foreach (var ca in box)
            {
                var face = new Face(0)
                {
                    Plane      = new Plane(ca[0], ca[1], ca[2]),
                    Colour     = Colour,
                    IsSelected = IsSelected,
                    Parent     = dummySolid
                };
                face.Vertices.AddRange(ca.Select(x => new Vertex(x, face)));
                face.UpdateBoundingBox();
                faces.Add(face);
            }
            return(faces);
        }
Exemple #2
0
        public static Solid CreateFromIntersectingPlanes(IEnumerable <Plane> planes, IDGenerator generator)
        {
            var solid = new Solid(generator.GetNextObjectID());
            var list  = planes.ToList();

            for (var i = 0; i < list.Count; i++)
            {
                // Split the polygon by all the other planes
                var poly = new Polygon(list[i]);
                for (var j = 0; j < list.Count; j++)
                {
                    if (i != j)
                    {
                        poly.Split(list[j]);
                    }
                }

                // The final polygon is the face
                var face = new Face(generator.GetNextFaceID())
                {
                    Plane = poly.Plane, Parent = solid
                };
                face.Vertices.AddRange(poly.Vertices.Select(x => new Vertex(x.Round(2), face))); // Round vertices a bit for sanity
                face.UpdateBoundingBox();
                face.AlignTexture();
                solid.Faces.Add(face);
            }

            // Ensure all the faces point outwards
            var origin = solid.GetOrigin();

            foreach (var face in solid.Faces)
            {
                if (face.Plane.OnPlane(origin) >= 0)
                {
                    face.Flip();
                }
            }

            solid.UpdateBoundingBox();
            return(solid);
        }