Exemplo n.º 1
0
    // Generate a uniform grid of vertices, elevate them according to a texture, and apply a normal map.
    private void CreateMeshByHeightMap()
    {
        Action createMeshAction = () =>
        {
            MeshData = MeshDataProvider.GenerateMeshData(HeightMap, Settings.TERRAIN_TILE_OFFSET, Settings.MESH_COLOR, Size);

            Action updateMeshAction = () =>
            {
                // Apply or remove the normal map from our material, based on the option set in the editor.

                GameObject g1 = TileGenerator.CreateMeshGO(transform);
                GameObject g2 = TileGenerator.CreateMeshGO(transform);

                Mesh mesh1 = g1.GetComponent <MeshFilter>().mesh;
                Mesh mesh2 = g2.GetComponent <MeshFilter>().mesh;


                var material1 = g1.GetComponent <MeshRenderer>().material;
                var material2 = g2.GetComponent <MeshRenderer>().material;
                if (UseNormalMap)
                {
                    ApplyNormalTexture(material1);
                    ApplyNormalTexture(material2);
                }
                else
                {
                    RemoveNormalTexture(material2);
                    RemoveNormalTexture(material1);
                }

                TileGenerator.AddNewLoadedTerrainTile(Coordinate, this);
                TileGenerator.CheckNeighBour(Coordinate);

                MeshData.UpdateHalfMesh(mesh1, true);
                MeshData.UpdateHalfMesh(mesh2, false);
            };

            ThreadQueue.StartFunctionInMainThread(updateMeshAction);
        };

        ThreadQueue.StartThreadFunction(createMeshAction);
    }