public AffineMesh ToZoom(AffineZoom Zoom)
		{
			var n = new AffineMesh();

			foreach (var p in this.Points)
			{
				n.Add(p.Zoom(Zoom));
			}

			var v = new List<AffineVertex>();

			foreach (var k in this.Vertecies)
			{
				var kn = new AffineVertex
				{
					Element = k.Element,
					ElementWidth = k.ElementWidth,
					ElementHeight = k.ElementHeight,
					A = k.A.Zoom(Zoom),
					B = k.B.Zoom(Zoom),
					C = k.C.Zoom(Zoom),
					//Tag = k.Tag

				};

				v.Add(kn);
			}

			n.Vertecies = v;


			return n;
		}
		public AffineMesh ToRotation(AffineRotation Rotation)
		{
			//var yawn = Math.Cos(Yawn);
			//var yawn2 = Math.Sin(Yawn);

			var n = new AffineMesh();

			foreach (var p in this.Points)
			{
				n.Add(p.Rotate(Rotation));
			}

			var v = new List<AffineVertex>();

			foreach (var k in this.Vertecies)
			{
				var kn = new AffineVertex
				{
					Element = k.Element,
					ElementWidth = k.ElementWidth,
					ElementHeight = k.ElementHeight,
					A = k.A.Rotate(Rotation),
					B = k.B.Rotate(Rotation),
					C = k.C.Rotate(Rotation),
					//Tag = k.Tag
				};

				v.Add(kn);
			}

			n.Vertecies = v.OrderBy(k => k.Center.Z).ToList();
			//n.Vertecies = v;

			return n;
		}
		public AffineMesh ToRotation(AffineRotation Rotation)
		{
			//var yawn = Math.Cos(Yawn);
			//var yawn2 = Math.Sin(Yawn);

			var n = new AffineMesh();

			foreach (var p in this.Points)
			{
				n.Points.Add(p.Rotate(Rotation));
			}

		
			foreach (var k in this.Vertecies)
			{
				var kn = new AffineVertex
				{
					Element = k.Element,
					ElementWidth = k.ElementWidth,
					ElementHeight = k.ElementHeight,
					A = k.A.Rotate(Rotation),
					B = k.B.Rotate(Rotation),
					C = k.C.Rotate(Rotation),
					//Tag = k.Tag
				};

				n.Vertecies.Add(kn);
			}

			

			foreach (var p in this.Meshes)
			{
				n.Meshes.Add(p.ToRotation(Rotation));
			}

			return n;
		}
		public AffineMesh ToTranslation(AffinePoint Translation)
		{
			var n = new AffineMesh();

			foreach (var p in this.Points)
			{
				n.Points.Add(p.Translation(Translation));
			}


			foreach (var k in this.Vertecies)
			{
				var kn = new AffineVertex
				{
					Element = k.Element,
					ElementWidth = k.ElementWidth,
					ElementHeight = k.ElementHeight,
					A = k.A.Translation(Translation),
					B = k.B.Translation(Translation),
					C = k.C.Translation(Translation),
					//Tag = k.Tag

				};

				n.Vertecies.Add(kn);
			}


			foreach (var p in this.Meshes)
			{
				n.Meshes.Add(p.ToTranslation(Translation));
			}


			return n;
		}
        private void AddCubeFace(AffineMesh a, string t, AffinePoint A, AffinePoint B, AffinePoint C, AffinePoint D)
        {
            var v1 =
               new AffineVertex
               {
                   A = A,
                   B = B,
                   C = C,

                   Element = new Avalon.Images._17
                   {
                       Width = 100,
                       Height = 100,
                   }.AttachTo(AffineContent),
                   ElementWidth = 100,
                   ElementHeight = 100
               };

            a.Vertecies.Add(v1);

            var v2 =
                new AffineVertex
                {
                    A = D,
                    B = C,
                    C = B,

                    Element = new Avalon.Images._17g
                    {
                        Width = 100,
                        Height = 100,
                    }.AttachTo(AffineContent),
                    ElementWidth = 100,
                    ElementHeight = 100
                };



            a.Vertecies.Add(v2);

        }
        private void AddCubeFace(AffineMesh a, ImageSource Source, ImageSource Source2, AffinePoint A, AffinePoint B, AffinePoint C, AffinePoint D)
        {
            var v1 =
               new AffineVertex
               {
                   A = A,
                   B = B,
                   C = C,

                   Element = new Image
                   {
                       Width = 100,
                       Height = 100,
                       Source = Source
                   }.AttachTo(AffineContent),
                   ElementWidth = 100,
                   ElementHeight = 100
               };



            a.Vertecies.Add(v1);

            var v2 =
                new AffineVertex
                {
                    A = D,
                    B = C,
                    C = B,

                    Element = new Image
                    {
                        Width = 100,
                        Height = 100,
                        Source = Source2
                    }.AttachTo(AffineContent),
                    ElementWidth = 100,
                    ElementHeight = 100
                };



            a.Vertecies.Add(v2);

        }
        private void AddCubeFace(AffineMesh a, string t, AffinePoint A, AffinePoint B, AffinePoint C, AffinePoint D)
        {
            var v1 =
               new AffineVertex
               {
                   A = A,
                   B = B,
                   C = C,

                   Element = new Avalon.Images._17 {
                       Width = 100,
                       Height = 100,
                   
                   }.AttachTo(AffineContent),
                   ElementWidth = 100,
                   ElementHeight = 100
               };

            //var t1 = new TextBox { Text = t, Foreground = Brushes.Blue }.AttachTo(InfoContent);

            //v1.Tag = new Action<AffineVertex>(
            //    k =>
            //    {
            //        t1.Text = t + " " + Convert.ToInt32(k.Center.Z);
            //        t1.MoveTo(k.Center.X + DefaultWidth / 2, k.Center.Y + DefaultHeight / 2);

            //    }
            //);

            a.Add(v1);

            var v2 =
                new AffineVertex
                {
                    A = D,
                    B = C,
                    C = B,

                    Element = new Avalon.Images._19g
                        {
                            Width = 100,
                            Height = 100,
                        }
                    .AttachTo(AffineContent),
                    ElementWidth = 100,
                    ElementHeight = 100
                };

            //v2.Element.Opacity = 0.5;

            //var t2 = new TextBox { Text = t }.AttachTo(InfoContent);

            //v2.Tag = new Action<AffineVertex>(
            //    k =>
            //    {
            //        t2.Text = t + " " + Convert.ToInt32(k.Center.Z);
            //        t2.MoveTo(k.Center.X + DefaultWidth / 2, k.Center.Y + DefaultHeight / 2);

            //    }
            //);

            a.Add(v2);

        }
		public void MergeTo(AffineMesh n)
		{
			foreach (var p in this.Points)
			{
				n.Points.Add(p);
			}


			foreach (var k in this.Vertecies)
			{
				var kn = new AffineVertex
				{
					Element = k.Element,
					ElementWidth = k.ElementWidth,
					ElementHeight = k.ElementHeight,
					A = k.A,
					B = k.B,
					C = k.C,
					//Tag = k.Tag

				};

				n.Vertecies.Add(kn);
			}


			foreach (var p in this.Meshes)
			{
				p.MergeTo(n);
			}
		}
		static void GetSortedCombinedVertices(AffineMesh m, AffineVertex[] a)
		{
			foreach (var v in m.Vertecies)
			{
				var i = Convert.ToInt32(v.B.Z + v.C.Z) + SortBuffer / 2;

				while (a[i] != null)
					i++;

				a[i] = v;
			}

			foreach (var k in m.Meshes)
			{
				GetSortedCombinedVertices(k, a);
			}
		}
		public AffineVertex[] GetSortedCombinedVertices()
		{
			// da buffer
			var a = new AffineVertex[SortBuffer];

			GetSortedCombinedVertices(this, a);

			return a;
		}
		public void Add(AffineVertex v)
		{
			Vertecies.Add(v);

		}