示例#1
0
    private void CreateMesh(Vector3[,] vertices, Vector2[,] uvs, NeighBoursDirection direction)
    {
        Action createMeshAction = () =>
        {
            MeshData = MeshDataProvider.GenerateMeshData(vertices, uvs, Color.white, direction);

            Action updateMeshAction = () =>
            {
                GameObject go = TileGenerator.CreateMeshGO(transform);

                // Apply or remove the normal map from our material, based on the option set in the editor.
                Mesh mesh     = go.GetComponent <MeshFilter>().mesh;
                var  material = go.GetComponent <MeshRenderer>().material;
                if (UseNormalMap)
                {
                    ApplyNormalTexture(material);
                }
                else
                {
                    RemoveNormalTexture(material);
                }
                MeshData.UpdateMesh(mesh);
            };

            ThreadQueue.StartFunctionInMainThread(updateMeshAction);
        };

        ThreadQueue.StartThreadFunction(createMeshAction);
    }
示例#2
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);
    }