Ejemplo n.º 1
0
        void generateObjFile(uint mapID, uint tileX, uint tileY, MeshData meshData)
        {
            string fileName = $"mmaps/meshes/{mapID:D4}{tileY:D2}{tileX:D2}.obj";

            using (TextWriter writer = File.CreateText(fileName))
            {
                List <float> allVerts = meshData.liquidVerts;
                List <int>   allTris  = meshData.liquidTris;

                TerrainBuilder.copyIndices(meshData.solidTris, allTris, allVerts.Count / 3);
                allVerts.AddRange(meshData.solidVerts);

                float[] verts     = allVerts.ToArray();
                int     vertCount = allVerts.Count / 3;
                int[]   tris      = allTris.ToArray();
                int     triCount  = allTris.Count / 3;

                for (int i = 0; i < allVerts.Count / 3; i++)
                {
                    writer.Write(string.Format("v {0} {1} {2}", verts[i * 3], verts[i * 3 + 1], verts[i * 3 + 2]) + "\n");
                }

                for (int i = 0; i < allTris.Count / 3; i++)
                {
                    writer.Write(string.Format("f {0} {1} {2}", tris[i * 3] + 1, tris[i * 3 + 1] + 1, tris[i * 3 + 2] + 1) + "\n");
                }
            }
        }
Ejemplo n.º 2
0
        public MapBuilder()
        {
            m_maxWalkableAngle = 70.0f;

            m_terrainBuilder = new TerrainBuilder();
            m_rcContext      = new rcContext(false);

            discoverTiles();
        }
Ejemplo n.º 3
0
        public MapBuilder(VMapManager2 vm)
        {
            _vmapManager = vm;

            m_maxWalkableAngle = 70.0f;

            m_terrainBuilder = new TerrainBuilder(vm);
            m_rcContext      = new rcContext(false);

            discoverTiles();
        }
Ejemplo n.º 4
0
        public MapBuilder(VMapManager2 vm, bool debugMaps)
        {
            _vmapManager = vm;
            _debugMaps   = debugMaps;

            m_maxWalkableAngle = 70.0f;

            m_terrainBuilder = new TerrainBuilder(vm);
            m_rcContext      = new rcContext();

            discoverTiles();
        }
Ejemplo n.º 5
0
        void buildTile(uint mapID, uint tileX, uint tileY, dtNavMesh navMesh)
        {
            Console.WriteLine($"{m_totalTilesProcessed * 100 / m_totalTiles}% [Map {mapID:D4}] Building tile [{tileX:D2},{tileY:D2}]]");

            MeshData meshData = new MeshData();

            // get heightmap data
            m_terrainBuilder.loadMap(mapID, tileX, tileY, meshData, _vmapManager);

            // get model data
            m_terrainBuilder.loadVMap(mapID, tileY, tileX, meshData);

            // if there is no data, give up now
            if (meshData.solidVerts.Count == 0 && meshData.liquidVerts.Count == 0)
            {
                return;
            }

            // remove unused vertices
            TerrainBuilder.cleanVertices(meshData.solidVerts, meshData.solidTris);
            TerrainBuilder.cleanVertices(meshData.liquidVerts, meshData.liquidTris);

            // gather all mesh data for final data check, and bounds calculation
            float[] allVerts = new float[meshData.liquidVerts.Count + meshData.solidVerts.Count];
            Array.Copy(meshData.liquidVerts.ToArray(), allVerts, meshData.liquidVerts.Count);
            Array.Copy(meshData.solidVerts.ToArray(), 0, allVerts, meshData.liquidVerts.Count, meshData.solidVerts.Count);

            if (allVerts.Length == 0)
            {
                return;
            }

            // get bounds of current tile
            getTileBounds(tileX, tileY, allVerts, allVerts.Length / 3, out float[] bmin, out float[] bmax);

            m_terrainBuilder.loadOffMeshConnections(mapID, tileX, tileY, meshData, null);

            // build navmesh tile
            buildMoveMapTile(mapID, tileX, tileY, meshData, bmin, bmax, navMesh);
        }
Ejemplo n.º 6
0
        void buildTile(uint mapID, uint tileX, uint tileY, dtNavMesh navMesh)
        {
            MeshData meshData = new MeshData();

            // get heightmap data
            m_terrainBuilder.loadMap(mapID, tileX, tileY, meshData, _vmapManager);

            // get model data
            m_terrainBuilder.loadVMap(mapID, tileY, tileX, meshData);

            // if there is no data, give up now
            if (meshData.solidVerts.Count == 0 && meshData.liquidVerts.Count == 0)
            {
                return;
            }

            // remove unused vertices
            TerrainBuilder.cleanVertices(meshData.solidVerts, meshData.solidTris);
            TerrainBuilder.cleanVertices(meshData.liquidVerts, meshData.liquidTris);

            // gather all mesh data for final data check, and bounds calculation
            List <float> allVerts = new List <float>();

            allVerts.AddRange(meshData.liquidVerts);
            allVerts.AddRange(meshData.solidVerts);

            if (allVerts.Count == 0)
            {
                return;
            }

            // get bounds of current tile
            getTileBounds(tileX, tileY, allVerts.ToArray(), allVerts.Count / 3, out float[] bmin, out float[] bmax);

            m_terrainBuilder.loadOffMeshConnections(mapID, tileX, tileY, meshData, null);

            // build navmesh tile
            buildMoveMapTile(mapID, tileX, tileY, meshData, bmin, bmax, navMesh);
        }