示例#1
0
 public void BuildVertices()
 {
     if ((Nodes != null) && (Nodes.Count > 0))
     {
         var nc  = Nodes.Count;
         var lc  = nc - 1;
         var lvc = lc * 2;
         var np  = new Vector4[nc];
         var lv  = new EditorVertex[lvc];
         for (int i = 0; i < nc; i++)
         {
             np[i] = new Vector4(Nodes[i].Position, 1.0f);
             if (i > 0)
             {
                 var l  = i - 1;
                 var li = l * 2;
                 var ni = li + 1;
                 lv[li].Position = Nodes[l].Position;
                 lv[ni].Position = Nodes[i].Position;
                 lv[li].Colour   = (uint)Nodes[l].GetColour();
                 lv[ni].Colour   = (uint)Nodes[i].GetColour();
             }
         }
         NodePositions = np;
         LinkedVerts   = lv;
     }
 }
示例#2
0
        public void BuildVertices()
        {
            var vlist = new List <EditorVertex>();
            var v1    = new EditorVertex();
            var v2    = new EditorVertex();
            var v3    = new EditorVertex();
            var v4    = new EditorVertex();

            foreach (var group in Groups.Values)
            {
                var  hash = JenkHash.GenHash(group.NameLabel.ToLowerInvariant());
                byte cr   = (byte)((hash >> 8) & 0xFF);
                byte cg   = (byte)((hash >> 16) & 0xFF);
                byte cb   = (byte)((hash >> 24) & 0xFF);
                byte ca   = 60;
                uint cv   = (uint)new Color(cr, cg, cb, ca).ToRgba();
                v1.Colour = cv;
                v2.Colour = cv;
                v3.Colour = cv;
                v4.Colour = cv;

                foreach (var box in group.Boxes)
                {
                    var min = box.Box.Minimum;
                    var max = box.Box.Maximum;

                    v1.Position = new Vector3(min.X, min.Y, 0);
                    v2.Position = new Vector3(max.X, min.Y, 0);
                    v3.Position = new Vector3(min.X, max.Y, 0);
                    v4.Position = new Vector3(max.X, max.Y, 0);

                    vlist.Add(v1);
                    vlist.Add(v2);
                    vlist.Add(v3);
                    vlist.Add(v3);
                    vlist.Add(v2);
                    vlist.Add(v4);
                }
            }

            if (vlist.Count > 0)
            {
                TriangleVerts = vlist.ToArray();
            }
            else
            {
                TriangleVerts = null;
            }
        }
示例#3
0
        private void BuildHeightmapVertices(HeightmapFile hmf, List <EditorVertex> vl, List <Vector4> nl)
        {
            var v1 = new EditorVertex();
            var v2 = new EditorVertex();
            var v3 = new EditorVertex();
            var v4 = new EditorVertex();

            uint cgrn = (uint)new Color(0, 128, 0, 60).ToRgba();
            uint cyel = (uint)new Color(128, 128, 0, 200).ToRgba();

            var w    = hmf.Width;
            var h    = hmf.Height;
            var hmin = hmf.MinHeights;
            var hmax = hmf.MaxHeights;
            var min  = hmf.BBMin;
            var max  = hmf.BBMax;
            var siz  = max - min;
            var step = siz / new Vector3(w - 1, h - 1, 255);

            v1.Colour = v2.Colour = v3.Colour = v4.Colour = cyel;
            for (int yi = 1; yi < h; yi++)
            {
                var yo = yi - 1;
                for (int xi = 1; xi < w; xi++)
                {
                    var xo = xi - 1;
                    var o1 = yo * w + xo;
                    var o2 = yo * w + xi;
                    var o3 = yi * w + xo;
                    var o4 = yi * w + xi;
                    v1.Position = min + step * new Vector3(xo, yo, hmin[o1]);
                    v2.Position = min + step * new Vector3(xi, yo, hmin[o2]);
                    v3.Position = min + step * new Vector3(xo, yi, hmin[o3]);
                    v4.Position = min + step * new Vector3(xi, yi, hmin[o4]);
                    vl.Add(v1); vl.Add(v2); vl.Add(v3);
                    vl.Add(v3); vl.Add(v2); vl.Add(v4);
                }
            }
            v1.Colour = v2.Colour = v3.Colour = v4.Colour = cgrn;
            for (int yi = 1; yi < h; yi++)
            {
                var yo = yi - 1;
                for (int xi = 1; xi < w; xi++)
                {
                    var xo = xi - 1;
                    var o1 = yo * w + xo;
                    var o2 = yo * w + xi;
                    var o3 = yi * w + xo;
                    var o4 = yi * w + xi;
                    v1.Position = min + step * new Vector3(xo, yo, hmax[o1]);
                    v2.Position = min + step * new Vector3(xi, yo, hmax[o2]);
                    v3.Position = min + step * new Vector3(xo, yi, hmax[o3]);
                    v4.Position = min + step * new Vector3(xi, yi, hmax[o4]);
                    vl.Add(v1); vl.Add(v2); vl.Add(v3);
                    vl.Add(v3); vl.Add(v2); vl.Add(v4);
                }
            }

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    var o = y * w + x;
                    nl.Add(new Vector4(min + step * new Vector3(x, y, hmin[o]), 10));
                    nl.Add(new Vector4(min + step * new Vector3(x, y, hmax[o]), 10));
                }
            }
        }
示例#4
0
        private void BuildWatermapVertices(WatermapFile wmf, List <EditorVertex> vl, List <Vector4> nl)
        {
            var v1 = new EditorVertex();
            var v2 = new EditorVertex();
            var v3 = new EditorVertex();
            var v4 = new EditorVertex();

            uint cblu = (uint)new Color(0, 0, 128, 60).ToRgba();


            float getHeight(int o)
            {
                var harr = wmf.GridWatermapRefs[o];

                if (harr == null)
                {
                    return(0);
                }
                if (harr.Length == 0)
                {
                    return(0);
                }
                var h0 = harr[0];
                var i0 = h0.Item;

                if (h0.Type == WatermapFile.WaterItemType.River)
                {
                    return(h0.Vector.Z);
                }
                if (h0.Type == WatermapFile.WaterItemType.Lake)
                {
                    if (i0 != null)
                    {
                        return(i0.Position.Z);
                    }
                }
                if (h0.Type == WatermapFile.WaterItemType.Pool)
                {
                    if (i0 != null)
                    {
                        return(i0.Position.Z);
                    }
                }
                return(h0.Vector.Z);
            }

            uint getColour(int o)
            {
                var harr = wmf.GridWatermapRefs[o];

                if (harr == null)
                {
                    return(cblu);
                }
                if (harr.Length == 0)
                {
                    return(cblu);
                }
                var i0 = harr[0].Item;

                if (i0 == null)
                {
                    return(cblu);
                }
                var c = i0.Colour;

                c.A = 128;
                return((uint)c.ToRgba());
            }

            var w    = wmf.Width;
            var h    = wmf.Height;
            var min  = new Vector3(wmf.CornerX, wmf.CornerY, 0.0f);
            var step = new Vector3(wmf.TileX, -wmf.TileY, 1.0f);

            //var siz = new Vector3(w, h, 1) * step;
            for (int yi = 1; yi < h; yi++)
            {
                var yo = yi - 1;
                for (int xi = 1; xi < w; xi++)
                {
                    var xo = xi - 1;
                    var o1 = yi * w + xo;
                    var o2 = yi * w + xi;
                    var o3 = yo * w + xo;
                    var o4 = yo * w + xi;
                    v1.Position = min + step * new Vector3(xo, yi, getHeight(o1));
                    v2.Position = min + step * new Vector3(xi, yi, getHeight(o2));
                    v3.Position = min + step * new Vector3(xo, yo, getHeight(o3));
                    v4.Position = min + step * new Vector3(xi, yo, getHeight(o4));
                    v1.Colour   = getColour(o1);
                    v2.Colour   = getColour(o2);
                    v3.Colour   = getColour(o3);
                    v4.Colour   = getColour(o4);
                    //vl.Add(v1); vl.Add(v2); vl.Add(v3);
                    //vl.Add(v3); vl.Add(v2); vl.Add(v4);
                }
            }
            //for (int y = 0; y < h; y++)
            //{
            //    for (int x = 0; x < w; x++)
            //    {
            //        var o = y * w + x;
            //        nl.Add(new Vector4(min + step * new Vector3(x, y, getHeight(o)), 10));
            //    }
            //}


            void addQuad(Quad q)
            {
                v1.Position = q.P1;
                v2.Position = q.P2;
                v3.Position = q.P3;
                v4.Position = q.P4;
                vl.Add(v1); vl.Add(v2); vl.Add(v3);
                vl.Add(v3); vl.Add(v2); vl.Add(v4);
            }

            void addRivEnd(Vector3 p, Vector3 s, Vector3 d, float r)
            {
                v1.Position = p;
                v2.Position = p + s * r;
                v3.Position = p + d * r;
                v4.Position = p - s * r;
                vl.Add(v1); vl.Add(v2); vl.Add(v3);
                vl.Add(v1); vl.Add(v3); vl.Add(v4);
            }

            var rivers = wmf.Rivers;

            if (rivers != null)
            {
                foreach (var river in rivers)
                {
                    if ((river.Vectors == null) || (river.VectorCount <= 1))
                    {
                        continue;
                    }

                    var rwid = 20.0f;
                    var rc   = river.Colour;
                    rc.A      = 128;
                    v1.Colour = v2.Colour = v3.Colour = v4.Colour = (uint)rc.ToRgba();
                    var quads = new Quad[river.Vectors.Length - 1];
                    var li    = river.Vectors.Length - 1;
                    for (int i = 1; i < river.Vectors.Length; i++)
                    {
                        var o   = i - 1;
                        var vo  = river.Vectors[o];
                        var vi  = river.Vectors[i];
                        var dif = vi.XYZ() - vo.XYZ();
                        var dir = Vector3.Normalize(dif);
                        var sid = Vector3.Normalize(Vector3.Cross(dir, Vector3.UnitZ));
                        if (Math.Abs(dir.Z) > 0.95f)
                        {
                            dir = Vector3.UnitY;
                            sid = Vector3.UnitX;
                        }
                        quads[o].P1 = vo.XYZ() - sid * rwid;
                        quads[o].P2 = vo.XYZ() + sid * rwid;
                        quads[o].P3 = vi.XYZ() - sid * rwid;
                        quads[o].P4 = vi.XYZ() + sid * rwid;
                        if (i == 1)
                        {
                            addRivEnd(vo.XYZ(), -sid, -dir, rwid);
                        }
                        if (i == li)
                        {
                            addRivEnd(vi.XYZ(), sid, dir, rwid);
                        }
                    }
                    for (int i = 1; i < quads.Length; i++)
                    {
                        var o = i - 1;
                        quads[o].P3 = quads[i].P1 = (quads[o].P3 + quads[i].P1) * 0.5f;
                        quads[o].P4 = quads[i].P2 = (quads[o].P4 + quads[i].P2) * 0.5f;
                    }
                    for (int i = 0; i < quads.Length; i++)
                    {
                        addQuad(quads[i]);
                    }
                }
            }
            var lakes = wmf.Lakes;

            if (lakes != null)
            {
                foreach (var lake in lakes)
                {
                    if ((lake.Vectors == null) || (lake.VectorCount == 0))
                    {
                        continue;
                    }

                    var lp = lake.Position;
                    var lc = lake.Colour;
                    lc.A      = 128;
                    v1.Colour = v2.Colour = v3.Colour = v4.Colour = (uint)lc.ToRgba();
                    for (int i = 0; i < lake.Vectors.Length; i++)
                    {
                        var vi = lake.Vectors[i];
                        var vp = new Vector3(vi.X, vi.Y, lp.Z);
                        var q  = new Quad();
                        q.P1 = vp + new Vector3(vi.Z, -vi.W, 0);
                        q.P2 = vp + new Vector3(vi.Z, vi.W, 0);
                        q.P3 = vp + new Vector3(-vi.Z, -vi.W, 0);
                        q.P4 = vp + new Vector3(-vi.Z, vi.W, 0);
                        addQuad(q);
                    }
                }
            }
            var pools = wmf.Pools;

            if (pools != null)
            {
                foreach (var pool in pools)
                {
                    var pp = pool.Position;
                    var ps = pool.Size;
                    var pc = pool.Colour;
                    pc.A      = 128;
                    v1.Colour = v2.Colour = v3.Colour = v4.Colour = (uint)pc.ToRgba();
                    var q = new Quad();
                    q.P1 = pp + new Vector3(ps.X, -ps.Y, 0);
                    q.P2 = pp + new Vector3(ps.X, ps.Y, 0);
                    q.P3 = pp + new Vector3(-ps.X, -ps.Y, 0);
                    q.P4 = pp + new Vector3(-ps.X, ps.Y, 0);
                    addQuad(q);
                }
            }
        }