示例#1
0
        private static void AddMeshTile(MeshTile tile, List <Point3D> vertices, List <int> indices)
        {
            byte[] detailTris  = tile.GetAllDetailIndices();
            var    verts       = tile.GetAllVertices();
            var    detailVerts = tile.GetAllDetailVertices();

            var vertMap = new Dictionary <uint, int>();

            for (int i = 0; i < tile.Header.PolyCount; i++)
            {
                Poly p = tile.GetPoly(i);
                if (p.Type == 1)                 // DT_POLYTYPE_OFFMESH_CONNECTION
                {
                    continue;
                }

                PolyDetail pd = tile.GetPolyDetail(i);

                for (int j = 0; j < pd.TriCount; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        int  index = detailTris[(pd.TriBase + j) * 4 + k];
                        uint vertIndex;
                        if (index < p.VertCount)
                        {
                            vertIndex = p.GetVert(index);
                        }
                        else
                        {
                            var val = verts.Length + pd.VertBase + index - p.VertCount;
                            Debug.Assert(val <= uint.MaxValue);
                            vertIndex = (uint)val;
                        }

                        if (!vertMap.ContainsKey(vertIndex))
                        {
                            var pos = vertIndex >= verts.Length ? detailVerts[vertIndex - verts.Length] : verts[vertIndex];
                            pos.Y += 0.03f;
                            vertices.Add(new Point3D(pos.X, pos.Z, pos.Y + 0.5));
                            vertMap[vertIndex] = vertices.Count - 1;
                        }

                        indices.Add(vertMap[vertIndex]);
                    }
                }
            }
        }