示例#1
0
        public void UpdateTriangleVertices()
        {
            //need position and colour for each vertex.
            //render as a triangle list... (no indices needed)

            //go through the nav mesh polys and generate verts to render...

            if ((Polys == null) || (Polys.Count == 0))
            {
                return;
            }


            int vc = Vertices.Count;

            List <EditorVertex> rverts = new List <EditorVertex>();
            EditorVertex        p0     = new EditorVertex();
            EditorVertex        p1     = new EditorVertex();
            EditorVertex        p2     = new EditorVertex();

            foreach (var ypoly in Polys)
            {
                if ((ypoly.Vertices == null) || (ypoly.Vertices.Length < 3))
                {
                    continue;
                }

                var colour    = ypoly.GetColour();
                var colourval = (uint)colour.ToRgba();

                p0.Colour = colourval;
                p1.Colour = colourval;
                p2.Colour = colourval;

                p0.Position = ypoly.Vertices[0];

                //build triangles for the poly.
                int tricount = ypoly.Vertices.Length - 2;
                for (int t = 0; t < tricount; t++)
                {
                    p1.Position = ypoly.Vertices[t + 1];
                    p2.Position = ypoly.Vertices[t + 2];
                    rverts.Add(p0);
                    rverts.Add(p1);
                    rverts.Add(p2);
                }
            }

            TriangleVerts = rverts.ToArray();
        }
示例#2
0
        public void UpdateAllNodePositions()
        {
            if (Nav == null)
            {
                return;
            }


            Vector3 posoffset = Nav.SectorTree.AABBMin.XYZ();
            Vector3 aabbsize  = Nav.AABBSize;

            EditorVertex v = new EditorVertex();

            v.Colour = 0xFF0000FF;
            var lv = new List <EditorVertex>();
            var nv = new List <Vector4>();


            ////### add portal positions to the node list, also add links to the link vertex array
            int cnt = Portals?.Count ?? 0;

            if (cnt > 0)
            {
                for (int i = 0; i < cnt; i++)
                {
                    var portal = Portals[i];
                    nv.Add(new Vector4(portal.PositionFrom, 1.0f));
                    v.Position = portal.PositionFrom; lv.Add(v);
                    v.Position = portal.PositionTo; lv.Add(v);
                }
            }


            ////### add point positions to the node list
            cnt = Points?.Count ?? 0;
            if (cnt >= 0)
            {
                for (int i = 0; i < cnt; i++)
                {
                    var point = Points[i];
                    nv.Add(new Vector4(point.Position, 1.0f));
                }
            }


            NodePositions = (nv.Count > 0) ? nv.ToArray() : null;
            PathVertices  = (lv.Count > 0) ? lv.ToArray() : null;
        }
示例#3
0
        public void UpdateTriangleVertices()
        {
            //need position and colour for each vertex.
            //render as a triangle list... (no indices needed)

            //go through the nav mesh polys and generate verts to render...

            if ((Vertices == null) || (Vertices.Count == 0))
            {
                return;
            }
            if ((Indices == null) || (Indices.Count == 0))
            {
                return;
            }
            if ((Polys == null) || (Polys.Count == 0))
            {
                return;
            }


            int vc = Vertices.Count;

            List <EditorVertex> rverts = new List <EditorVertex>();

            foreach (var ypoly in Polys)
            {
                var poly      = ypoly.RawData;
                var colour    = ypoly.GetColour();
                var colourval = (uint)colour.ToRgba();

                var ic      = poly.IndexCount;
                var startid = poly.IndexID;
                var endid   = startid + ic;
                if (startid >= Indices.Count)
                {
                    continue;
                }
                if (endid > Indices.Count)
                {
                    continue;
                }


                if (ic < 3)
                {
                    continue;
                }            //not enough verts to make a triangle...

                if (ic > 15)
                {
                }


                EditorVertex p0 = new EditorVertex();
                EditorVertex p1 = new EditorVertex();
                EditorVertex p2 = new EditorVertex();
                p0.Colour = colourval;
                p1.Colour = colourval;
                p2.Colour = colourval;

                var startind = Indices[startid];
                if (startind >= vc)
                {
                    continue;
                }

                p0.Position = Vertices[startind];

                //build triangles for the poly.
                int tricount = ic - 2;
                for (int t = 0; t < tricount; t++)
                {
                    int tid  = startid + t;
                    int ind1 = Indices[tid + 1];
                    int ind2 = Indices[tid + 2];
                    if ((ind1 >= vc) || (ind2 >= vc))
                    {
                        continue;
                    }

                    p1.Position = Vertices[ind1];
                    p2.Position = Vertices[ind2];

                    rverts.Add(p0);
                    rverts.Add(p1);
                    rverts.Add(p2);
                }
            }

            TriangleVerts = rverts.ToArray();
        }
示例#4
0
        private void UpdateJunctionTriangleVertices()
        {
            //build triangles for the junctions bytes display....

            int vc = 0;

            if (Junctions != null)
            {
                foreach (var j in Junctions)
                {
                    var d = j.Heightmap;
                    if (d == null)
                    {
                        continue;
                    }
                    vc += d.CountX * d.CountY * 6;
                }
            }

            List <EditorVertex> verts = new List <EditorVertex>(vc);
            EditorVertex        v0    = new EditorVertex();
            EditorVertex        v1    = new EditorVertex();
            EditorVertex        v2    = new EditorVertex();
            EditorVertex        v3    = new EditorVertex();

            if (Nodes != null)
            {
                foreach (var node in Nodes)
                {
                    if (node.Junction == null)
                    {
                        continue;
                    }
                    var j = node.Junction;
                    var d = j.Heightmap;
                    if (d == null)
                    {
                        continue;
                    }

                    float maxz = j.MaxZ / 32.0f;
                    float minz = j.MinZ / 32.0f;
                    float rngz = maxz - minz;
                    float posx = j.PositionX / 4.0f;
                    float posy = j.PositionY / 4.0f;

                    Vector3 pos = new Vector3(posx, posy, 0.0f);
                    Vector3 siz = new Vector3(d.CountX, d.CountY, 0.0f) * 2.0f;
                    //Vector3 siz = new Vector3(jx, jy, 0.0f);
                    Vector3 cnr = pos;// - siz * 0.5f;
                    //Vector3 inc = new Vector3(1.0f/jx)

                    cnr.Z = minz;                      // + 2.0f;

                    for (int y = 1; y < d.CountY; y++) //rows progress up the Y axis.
                    {
                        var   row0 = d.Rows[y - 1];
                        var   row1 = d.Rows[y];
                        float offy = y * 2.0f;

                        for (int x = 1; x < d.CountX; x++) //values progress along the X axis.
                        {
                            var   val0 = row0.Values[x - 1] / 255.0f;
                            var   val1 = row0.Values[x] / 255.0f;
                            var   val2 = row1.Values[x - 1] / 255.0f;
                            var   val3 = row1.Values[x] / 255.0f;
                            float offx = x * 2.0f;
                            v0.Position = cnr + new Vector3(offx - 2.0f, offy - 2.0f, val0 * rngz);
                            v1.Position = cnr + new Vector3(offx + 0.0f, offy - 2.0f, val1 * rngz);
                            v2.Position = cnr + new Vector3(offx - 2.0f, offy + 0.0f, val2 * rngz);
                            v3.Position = cnr + new Vector3(offx + 0.0f, offy + 0.0f, val3 * rngz);
                            v0.Colour   = (uint)new Color4(val0, 1.0f - val0, 0.0f, 1.0f).ToRgba();
                            v1.Colour   = (uint)new Color4(val1, 1.0f - val1, 0.0f, 1.0f).ToRgba();
                            v2.Colour   = (uint)new Color4(val2, 1.0f - val2, 0.0f, 1.0f).ToRgba();
                            v3.Colour   = (uint)new Color4(val3, 1.0f - val3, 0.0f, 1.0f).ToRgba();
                            verts.Add(v0);
                            verts.Add(v1);
                            verts.Add(v2);
                            verts.Add(v2);
                            verts.Add(v1);
                            verts.Add(v3);
                        }
                    }
                }
            }

            if (verts.Count > 0)
            {
                TriangleVerts = verts.ToArray();
            }
            else
            {
                TriangleVerts = null;
            }
        }
示例#5
0
        private void UpdateLinkTriangleVertices()
        {
            //build triangles for the path links display


            int vc = 0;

            if (Links != null)
            {
                vc = Links.Length * 6;
            }

            List <EditorVertex> verts = new List <EditorVertex>(vc);
            EditorVertex        v0    = new EditorVertex();
            EditorVertex        v1    = new EditorVertex();
            EditorVertex        v2    = new EditorVertex();
            EditorVertex        v3    = new EditorVertex();

            if ((Links != null) && (Nodes != null))
            {
                foreach (var node in Nodes)
                {
                    foreach (var link in node.Links)
                    {
                        var p0   = link.Node1?.Position ?? Vector3.Zero;
                        var p1   = link.Node2?.Position ?? Vector3.Zero;
                        var diff = p1 - p0;
                        var dir  = Vector3.Normalize(diff);
                        var ax   = Vector3.Cross(dir, Vector3.UnitZ);


                        float lanestot = link.LaneCountForward + link.LaneCountBackward;
                        //float backfrac = Math.Min(Math.Max(link.LaneCountBackward / lanestot, 0.1f), 0.9f);
                        //float lanewidth = 7.0f;
                        //float inner = totwidth*(backfrac-0.5f);
                        //float outer = totwidth*0.5f;

                        float lanewidth = node.IsPedNode ? 0.5f : 5.5f;
                        float inner     = link.LaneOffset * lanewidth;// 0.0f;
                        float outer     = inner + Math.Max(lanewidth * link.LaneCountForward, 0.5f);

                        float totwidth  = lanestot * lanewidth;
                        float halfwidth = totwidth * 0.5f;
                        if (link.LaneCountBackward == 0)
                        {
                            inner -= halfwidth;
                            outer -= halfwidth;
                        }
                        if (link.LaneCountForward == 0)
                        {
                            inner += halfwidth;
                            outer += halfwidth;
                        }


                        v0.Position = p1 + ax * inner;
                        v1.Position = p0 + ax * inner;
                        v2.Position = p1 + ax * outer;
                        v3.Position = p0 + ax * outer;
                        var c = (uint)link.GetColour().ToRgba();
                        v0.Colour = c;
                        v1.Colour = c;
                        v2.Colour = c;
                        v3.Colour = c;
                        verts.Add(v0);
                        verts.Add(v1);
                        verts.Add(v2);
                        verts.Add(v2);
                        verts.Add(v1);
                        verts.Add(v3);
                    }
                }
            }


            if (verts.Count > 0)
            {
                TriangleVerts = verts.ToArray();
            }
            else
            {
                TriangleVerts = null;
            }
        }