コード例 #1
0
        private void GetChunkData(TriangleCollection triangles, int chunk_x, int chunk_y, SparseMatrix3D <WMO> instances)
        {
            if (chunk_x < 0)
            {
                return;
            }
            if (chunk_y < 0)
            {
                return;
            }
            if (chunk_x > 63)
            {
                return;
            }
            if (chunk_y > 63)
            {
                return;
            }


            if (triangles == null)
            {
                return;
            }

            if (wdtf == null)
            {
                return;
            }
            if (wdt == null)
            {
                return;
            }
            wdtf.LoadMapTile(chunk_x, chunk_y);


            MapTile t = wdt.maptiles[chunk_x, chunk_y];

            if (t != null)
            {
                //Console.Write(" render");
                // Map tiles
                for (int ci = 0; ci < 16; ci++)
                {
                    for (int cj = 0; cj < 16; cj++)
                    {
                        MapChunk c = t.chunks[ci, cj];
                        if (c != null)
                        {
                            AddTriangles(triangles, c);
                        }
                    }
                }

                // World objects

                foreach (WMOInstance wi in t.wmois)
                {
                    if (wi != null && wi.wmo != null)
                    {
                        String fn   = wi.wmo.fileName;
                        int    last = fn.LastIndexOf('\\');
                        fn = fn.Substring(last + 1);
                        // Console.WriteLine("    wmo: " + fn + " at " + wi.pos);
                        if (fn != null)
                        {
                            WMO old = instances.Get((int)wi.pos.x, (int)wi.pos.y, (int)wi.pos.z);
                            if (old == wi.wmo)
                            {
                                //Console.WriteLine("Already got " + fn);
                            }
                            else
                            {
                                instances.Set((int)wi.pos.x, (int)wi.pos.y, (int)wi.pos.z, wi.wmo);
                                AddTriangles(triangles, wi);
                            }
                        }
                    }
                }

                foreach (ModelInstance mi in t.modelis)
                {
                    if (mi != null && mi.model != null)
                    {
                        String fn   = mi.model.fileName;
                        int    last = fn.LastIndexOf('\\');
                        // fn = fn.Substring(last + 1);
                        //Console.WriteLine("    wmi: " + fn + " at " + mi.pos);
                        AddTriangles(triangles, mi);

                        //Console.WriteLine("    model: " + fn);
                    }
                }



                Console.WriteLine("wee");

                /*Console.WriteLine(
                 *      String.Format(" Triangles - Map: {0,6} Objects: {1,6} Models: {2,6}",
                 *                                map_triangles.GetNumberOfTriangles(),
                 *                                obj_triangles.GetNumberOfTriangles(),
                 *                                model_triangles.GetNumberOfTriangles()));
                 */
            }
            Console.WriteLine(" done");
            wdt.maptiles[chunk_x, chunk_y] = null;             // clear it atain
            //myChunk.triangles.ClearVertexMatrix(); // not needed anymore
            //return myChunk;
        }