示例#1
0
        internal List <Point> ExtractAnchors(int scanInterval, int threshold)
        {
            var anchors = new List <Point>();

            // iterate through the Rows
            for (int row = 1, rowEnd = _rows - 1; row < rowEnd; row += scanInterval)
            {
                // iterate through the columns
                for (int col = 1, colEnd = _columns - 1; col < colEnd; col += scanInterval)
                {
                    var gradient = GradientMap.GetReal(row, col);

                    if (DirectionMap.GetReal(row, col) == HorizontalValue)
                    {
                        // compare to horizontal neighbors
                        if (Math.Abs(gradient - GradientMap.GetReal(row - 1, col)) > threshold &&
                            Math.Abs(gradient - GradientMap.GetReal(row + 1, col)) > threshold)
                        {
                            anchors.Add(new Point(col, row));
                        }
                    }
                    else
                    {
                        // compare to vertical neighbors
                        if (Math.Abs(gradient - GradientMap.GetReal(row, col - 1)) > threshold &&
                            Math.Abs(gradient - GradientMap.GetReal(row, col + 1)) > threshold)
                        {
                            anchors.Add(new Point(col, row));
                        }
                    }
                }
            }

            return(anchors);
        }
        public void TestSampleGradientCentre()
        {
            int width  = 400;
            int height = 400;

            GradientMap.GenerateCircleGradient(width, height, 40);
            float[,] mask = GradientMap.GetMask();
            float expected = mask[200, 200];
            float actual   = GradientMap.sampleGradient(0.5f, 0.5f);
        }
        public void TestCreateSquareMap()
        {
            int width  = 512;
            int height = 1028;

            GradientMap.GenerateCircleGradient(width, height, 40);
            float[,] mask = GradientMap.GetMask();

            Assert.AreEqual(width, mask.GetLength(0));
            Assert.AreEqual(height, mask.GetLength(1));
        }
        public void TestCreateIslandMask()
        {
            int width  = 400;
            int height = 200;

            GradientMap.GenerateCircleGradient(width, height, 40);
            float[,] mask = GradientMap.GetMask();

            Assert.AreEqual(width, mask.GetLength(0));
            Assert.AreEqual(height, mask.GetLength(1));
        }
示例#5
0
 public void CreateIslandMask()
 {
     if (noiseSettings.mapType == MapType.Island)
     {
         GradientMap.GenerateIslandMask((mapChunkSize - 1) * 3, (mapChunkSize - 1) * 3, maskThreshold);
     }
     if (noiseSettings.mapType == MapType.SquareIsland)
     {
         GradientMap.GenerateSquareIslandMask((mapChunkSize - 1) * 3, (mapChunkSize - 1) * 3, maskThreshold);
     }
 }
示例#6
0
    public MeshMatData GetGeneratedData(Vector2 centre, Vector2 coord)
    {
        heightTracker = new MinMaxTracker();

        float[,] map = new float[noiseSettings.mapChunkSize, noiseSettings.mapChunkSize];
        for (int i = 0; i < noiseSettings.SettingsVariations.Length; i++)
        {
            float[,] firstLayerValue = new float[noiseSettings.mapChunkSize, noiseSettings.mapChunkSize];
            if (noiseSettings.SettingsVariations.Length > 0)
            {
                firstLayerValue = NoiseGenerator.GenerateNoise(noiseSettings.SettingsVariations[0], seed, centre);
            }

            SettingsVariation sv = noiseSettings.SettingsVariations[i];
            if (sv.enabled)
            {
                float[,] newMap = NoiseGenerator.GenerateNoise(sv, seed, centre);
                for (int y = 0; y < newMap.GetLength(0); y++)
                {
                    for (int x = 0; x < newMap.GetLength(1); x++)
                    {
                        if (sv.noiseMode == NoiseMode.Add)
                        {
                            float mask = 1;

                            if (sv.useLayerAsMask)
                            {
                                mask = firstLayerValue[x, y];
                                if (sv.InverseLayer)
                                {
                                    mask = 1 - mask;
                                    if (mask <= sv.sampleBelow)
                                    {
                                        mask = 0;
                                    }
                                }
                                else
                                {
                                    if (mask <= sv.sampleBelow)
                                    {
                                        mask = 0;
                                    }
                                }
                            }
                            newMap[x, y] = Mathf.Max(0, newMap[x, y] - sv.minValue);
                            map[x, y]   += newMap[x, y] * sv.strength * mask;
                        }
                        else
                        if (sv.noiseMode == NoiseMode.Multiply)
                        {
                            map[x, y] *= newMap[x, y];
                        }
                        else
                        if (sv.noiseMode == NoiseMode.Subtract)
                        {
                            float mask = 1;

                            if (sv.useLayerAsMask)
                            {
                                mask = firstLayerValue[x, y];
                                if (sv.InverseLayer)
                                {
                                    mask = 1 - mask;
                                    if (mask <= sv.sampleBelow)
                                    {
                                        mask = 0;
                                    }
                                }
                            }
                            newMap[x, y] += Mathf.Min(0, -newMap[x, y] * sv.minValue);
                            map[x, y]    += newMap[x, y] * sv.strength * mask;
                        }
                    }
                }
            }
        }

        Debug.Log(centre);


        for (int x = 0; x < map.GetLength(0); x++)
        {
            for (int y = 0; y < map.GetLength(1); y++)
            {
                heightTracker.AddValue(map[x, y]);
            }
        }

        if (noiseSettings.mapType != MapType.None)
        {
            for (int x = 0; x < map.GetLength(0); x++)
            {
                for (int y = 0; y < map.GetLength(1); y++)
                {
                    float m1     = (map.GetLength(0) - 1) * 3f;
                    float m2     = (map.GetLength(1) - 1) * 3f;
                    float pointX = ((float)x + (centre.x)) / m1;
                    float pointY = ((float)y + (-centre.y)) / m2;


                    map[x, y] = map[x, y] * GradientMap.sampleGradient(pointY, pointX);
                }
            }
        }

        //SmoothenTerrain(map,1,1);
        map = SmoothenTerrain(map);


        colorGen.UpdateSettings(colorSettings);
        colorGen.UpdateHeight(heightTracker);
        colorGen.UpdateColors();
        return(new MeshMatData(map, colorSettings.terrainMaterial));
    }