예제 #1
0
    public void LoadHeights()
    {
        if (Teren)
        {
            DestroyImmediate(Teren.gameObject);
        }

        Teren = Terrain.CreateTerrainGameObject(Data).GetComponent <Terrain>();
        Teren.gameObject.name      = "TERRAIN";
        Teren.materialType         = Terrain.MaterialType.Custom;
        Teren.materialTemplate     = TerrainMaterial;
        Teren.heightmapPixelError  = 4f;
        Teren.basemapDistance      = 10000;
        Teren.shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
        Teren.drawTreesAndFoliage  = false;
        Teren.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;

        int   xRes = MapLuaParser.Current.ScenarioLuaFile.Data.Size[0];
        int   zRes = MapLuaParser.Current.ScenarioLuaFile.Data.Size[1];
        float yRes = (float)map.HeightScale;

        float HalfxRes = xRes / 10f;
        float HalfzRes = zRes / 10f;

        Data.heightmapResolution = (int)(xRes + 1);
        TerrainHeight            = 1f / yRes;
        TerrainHeight           *= 0.1f;
        TerrainHeight           *= 2;

        Data.size = new Vector3(
            HalfxRes,
            TerrainHeight,
            HalfzRes
            );

        Data.RefreshPrototypes();
        Teren.Flush();
        Teren.UpdateGIMaterials();
        SyncHeightmap();

        Teren.transform.localPosition = new Vector3(0, 0, -HalfzRes);

        heightsLength = (int)Mathf.Max((map.Height + 1), (map.Width + 1));
        heights       = new float[heightsLength, heightsLength];

        float HeightWidthMultiply = (map.Height / (float)map.Width);

        int y      = 0;
        int x      = 0;
        int localY = 0;

        for (y = 0; y < heightsLength; y++)
        {
            for (x = 0; x < heightsLength; x++)
            {
                localY = (int)(((heightsLength - 1) - y) * HeightWidthMultiply);

                //heights[y, x] = (float)((((double)map.GetHeight(x, localY)) / HeightResize));
                heights[y, x] = (float)(map.GetHeight(x, localY) / HeightResize);                 // 65536.0 / 2.0 // 32768.0

                if (HeightWidthMultiply == 0.5f && y > 0 && y % 2f == 0)
                {
                    heights[y - 1, x] = Mathf.Lerp(heights[y, x], heights[y - 2, x], 0.5f);
                }
            }
        }

        // Set terrain heights from heights array
        ApplyHeightmap(false);

        GenerateControlTex.StopAllTasks();
        GenerateControlTex.GenerateNormal();
        GenerateControlTex.GenerateWater();
    }
예제 #2
0
 public void RegenerateMaps()
 {
     GenerateControlTex.GenerateWater();
     GenerateControlTex.GenerateNormal();
 }
예제 #3
0
 public void RegenerateMaps()
 {
     GenerateControlTex.GenerateWater();
     GenerateControlTex.GenerateNormal();
     WavesRenderer.ClearShoreLine();
 }