AddPolygon() public method

Adds a polygon.
If the number of points is greater than 4, a triangle fan is used.
public AddPolygon ( IList points ) : void
points IList /// The points of the polygon. ///
return void
        public void AddGroup(bool canShowFace)
        {
            MeshBuilder mesh = new MeshBuilder(false, false);
            if (canShowFace)
            {
                foreach (Point3D pt in this.Points)
                    mesh.Positions.Add(pt);

                foreach (List<int> pts in this.faces)
                {
                    if (pts != null)
                        mesh.AddPolygon(pts);
                }
            }
            else
            {
                foreach (Point3D pt in this.Points)
                    mesh.AddSphere(pt, pointRaduis);
            }
            var mesh1 = mesh.ToMesh(true);
            var redMaterial = MaterialHelper.CreateMaterial(Colors.Green);
            var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);

            // Add 3 models to the group (using the same mesh, that's why we had to freeze it)
            mg.Children.Add(new GeometryModel3D { Geometry = mesh1, Material = redMaterial, BackMaterial = insideMaterial });
        }
Exemplo n.º 2
0
        private void AppearanceChanged()
        {
            var y0 = 0d;
            var wallBuilder = new MeshBuilder(false, false);
            for (int i = 0; i < this.Stories; i++)
            {
                if (i > 0 && this.FloorThickness > 0)
                {
                    wallBuilder.AddBox(new Point3D(0, 0, y0 + this.FloorThickness / 2), this.Length + 0.2, this.Width + 0.2, this.FloorThickness);
                    y0 += this.FloorThickness;
                }

                wallBuilder.AddBox(new Point3D(0, 0, y0 + this.StoryHeight / 2), this.Length, this.Width, this.StoryHeight);
                y0 += this.StoryHeight;
            }

            var theta = Math.PI / 180 * this.RoofAngle;
            var roofBuilder = new MeshBuilder(false, false);
            var y1 = y0 + Math.Tan(theta) * this.Width / 2;
            var p0 = new Point(0, y1);
            var p1 = new Point(this.Width / 2 + 0.2 * Math.Cos(theta), y0 - 0.2 * Math.Sin(theta));
            var p2 = new Point(p1.X + this.RoofThickness * Math.Sin(theta), p1.Y + this.RoofThickness * Math.Cos(theta));
            var p3 = new Point(0, y1 + this.RoofThickness / Math.Cos(theta));
            var p4 = new Point(-p2.X, p2.Y);
            var p5 = new Point(-p1.X, p1.Y);
            var roofSection = new[] { p0, p1, p1, p2, p2, p3, p3, p4, p4, p5, p5, p0 };
            roofBuilder.AddExtrudedSegments(roofSection, new Vector3D(0, -1, 0), new Point3D(-this.Length / 2, 0, 0), new Point3D(this.Length / 2, 0, 0));
            var cap = new[] { p0, p1, p2, p3, p4, p5 };
            roofBuilder.AddPolygon(cap, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), new Point3D(-this.Length / 2, 0, 0));
            roofBuilder.AddPolygon(cap, new Vector3D(0, 1, 0), new Vector3D(0, 0, 1), new Point3D(this.Length / 2, 0, 0));
            var p6 = new Point(this.Width / 2, y0);
            var p7 = new Point(-this.Width / 2, y0);
            wallBuilder.AddPolygon(new[] { p0, p6, p7 }, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), new Point3D(-this.Length / 2, 0, 0));
            wallBuilder.AddPolygon(new[] { p0, p6, p7 }, new Vector3D(0, 1, 0), new Vector3D(0, 0, 1), new Point3D(this.Length / 2, 0, 0));
            this.walls.Geometry = wallBuilder.ToMesh(true);
            this.roof.Geometry = roofBuilder.ToMesh(true);
        }