Example #1
0
    public override void Process(uint seed)
    {
        List <PathList>    roads     = TerrainMeta.Path.Roads;
        TerrainHeightMap   heightmap = TerrainMeta.HeightMap;
        TerrainTopologyMap topomap   = TerrainMeta.TopologyMap;

        foreach (PathList pathList in roads)
        {
            pathList.Path.RecalculateTangents();
        }
        heightmap.Push();
        foreach (PathList pathList in roads)
        {
            pathList.AdjustTerrainHeight();
            pathList.AdjustTerrainTexture();
            pathList.AdjustTerrainTopology();
        }
        heightmap.Pop();
        int[] map = topomap.dst;
        int   res = topomap.res;

        ImageProcessing.Dilate2D(map, res, res, 6144, 6, (Action <int, int>)((x, y) =>
        {
            if ((map[x * res + y] & 49) != 0)
            {
                map[x * res + y] |= 4096;
            }
            if ((double)heightmap.GetSlope(topomap.Coordinate(x), topomap.Coordinate(y)) <= 40.0)
            {
                return;
            }
            map[x * res + y] |= 2;
        }));
    }
    public override void Process(uint seed)
    {
        List <PathList>    rivers      = TerrainMeta.Path.Rivers;
        TerrainHeightMap   heightMap   = TerrainMeta.HeightMap;
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;

        foreach (PathList river in rivers)
        {
            river.Path.RecalculateTangents();
        }
        heightMap.Push();
        foreach (PathList pathList in rivers)
        {
            pathList.AdjustTerrainHeight();
            pathList.AdjustTerrainTexture();
            pathList.AdjustTerrainTopology();
        }
        heightMap.Pop();
        int[] numArray = topologyMap.dst;
        int   num      = topologyMap.res;

        ImageProcessing.Dilate2D(numArray, num, num, 49152, 6, (int x, int y) => {
            if ((numArray[x * num + y] & 49) != 0)
            {
                numArray[x * num + y] |= 32768;
            }
            float single  = topologyMap.Coordinate(x);
            float single1 = topologyMap.Coordinate(y);
            if (heightMap.GetSlope(single, single1) > 40f)
            {
                numArray[x * num + y] |= 2;
            }
        });
    }
Example #3
0
    private static void Process(int x, int z, bool keepExisting)
    {
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float normZ    = topologyMap.Coordinate(z);
        float normX    = topologyMap.Coordinate(x);
        int   topology = topologyMap.GetTopology(x, z);

        if ((topology & 8389632) != 0)
        {
            return;
        }
        float slope = TerrainMeta.HeightMap.GetSlope(normX, normZ);
        float splat = TerrainMeta.SplatMap.GetSplat(normX, normZ, 8);

        if ((double)slope > 40.0 || (double)splat > 0.400000005960464)
        {
            topologyMap.AddTopology(x, z, 2);
        }
        else
        {
            if (keepExisting || (double)slope >= 20.0 || ((double)splat >= 0.200000002980232 || (topology & 55296) == 0))
            {
                return;
            }
            topologyMap.RemoveTopology(x, z, 2);
        }
    }
Example #4
0
    public void AdjustTerrainTopology()
    {
        if (this.Topology == 0)
        {
            return;
        }
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float   single3      = 1f;
        float   randomScale  = this.RandomScale;
        float   outerPadding = this.OuterPadding;
        float   innerPadding = this.InnerPadding;
        float   width        = this.Width * 0.5f;
        Vector3 startPoint   = this.Path.GetStartPoint();
        Vector3 endPoint     = this.Path.GetEndPoint();
        Vector3 startTangent = this.Path.GetStartTangent();
        Vector3 vector31     = PathList.rot90 * startTangent;
        Vector3 vector32     = startPoint - (vector31 * (width + outerPadding));
        Vector3 vector33     = startPoint + (vector31 * (width + outerPadding));
        float   length       = this.Path.Length + single3;

        for (float i = 0f; i < length; i += single3)
        {
            Vector3 vector34 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i));
            float   single4  = (startPoint - vector34).Magnitude2D();
            float   single5  = (endPoint - vector34).Magnitude2D();
            float   single6  = Mathf.InverseLerp(0f, width, Mathf.Min(single4, single5));
            float   single7  = Mathf.Lerp(width, width * randomScale, Noise.Billow(vector34.x, vector34.z, 2, 0.005f, 1f, 2f, 0.5f));
            Vector3 vector35 = this.Path.GetTangent(i).XZ3D();
            startTangent = vector35.normalized;
            vector31     = PathList.rot90 * startTangent;
            Ray     ray      = new Ray(vector34, startTangent);
            Vector3 vector36 = vector34 - (vector31 * (single7 + outerPadding));
            Vector3 vector37 = vector34 + (vector31 * (single7 + outerPadding));
            float   single8  = TerrainMeta.NormalizeY(vector34.y);
            topologyMap.ForEach(vector32, vector33, vector36, vector37, (int x, int z) => {
                float single    = topologyMap.Coordinate(x);
                float single1   = topologyMap.Coordinate(z);
                Vector3 vector3 = TerrainMeta.Denormalize(new Vector3(single, single8, single1));
                float single2   = (vector3 - ray.ClosestPoint(vector3)).Magnitude2D();
                if (Mathf.InverseLerp(single7 + outerPadding, single7 - innerPadding, single2) * single6 > 0.3f)
                {
                    topologyMap.SetTopology(x, z, this.Topology);
                }
            });
            vector32 = vector36;
            vector33 = vector37;
        }
    }
    public static void Process(int x, int z)
    {
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float normZ = topologyMap.Coordinate(z);
        float normX = topologyMap.Coordinate(x);

        if ((topologyMap.GetTopology(x, z) & 0x800400) == 0)
        {
            float slope = TerrainMeta.HeightMap.GetSlope(normX, normZ);
            float splat = TerrainMeta.SplatMap.GetSplat(normX, normZ, 8);
            if (slope > 40f || splat > 0.4f)
            {
                topologyMap.AddTopology(x, z, 2);
            }
            else
            {
                topologyMap.RemoveTopology(x, z, 2);
            }
        }
    }
    private static void Process(int x, int z, bool keepExisting)
    {
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float normZ    = topologyMap.Coordinate(z);
        float normX    = topologyMap.Coordinate(x);
        int   topology = topologyMap.GetTopology(x, z);

        if (!World.Procedural || (topology & 0x800400) == 0)
        {
            float slope = TerrainMeta.HeightMap.GetSlope(normX, normZ);
            float splat = TerrainMeta.SplatMap.GetSplat(normX, normZ, 8);
            if (slope > 40f || splat > 0.4f)
            {
                topologyMap.AddTopology(x, z, 2);
            }
            else if (!keepExisting)
            {
                topologyMap.RemoveTopology(x, z, 2);
            }
        }
    }
    public static void Process(int x, int z)
    {
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float single  = topologyMap.Coordinate(z);
        float single1 = topologyMap.Coordinate(x);

        if ((topologyMap.GetTopology(x, z) & 8389632) == 0)
        {
            float slope = TerrainMeta.HeightMap.GetSlope(single1, single);
            float splat = TerrainMeta.SplatMap.GetSplat(single1, single, 8);
            if (slope > 40f || splat > 0.4f)
            {
                topologyMap.AddTopology(x, z, 2);
                return;
            }
            if (slope < 20f && splat < 0.2f)
            {
                topologyMap.RemoveTopology(x, z, 2);
            }
        }
    }
    private void MarkRoadside()
    {
        TerrainHeightMap   heightmap = TerrainMeta.HeightMap;
        TerrainTopologyMap topomap   = TerrainMeta.TopologyMap;

        int[] map = topomap.dst;
        int   res = topomap.res;

        ImageProcessing.Dilate2D(map, res, res, 6144, 6, delegate(int x, int y)
        {
            if (((uint)map[x * res + y] & 0x31u) != 0)
            {
                map[x * res + y] |= 4096;
            }
            float normX = topomap.Coordinate(x);
            float normZ = topomap.Coordinate(y);
            if (heightmap.GetSlope(normX, normZ) > 40f)
            {
                map[x * res + y] |= 2;
            }
        });
    }
    private static void Process(int x, int z, bool keepExisting)
    {
        TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap;
        float single   = topologyMap.Coordinate(z);
        float single1  = topologyMap.Coordinate(x);
        int   topology = topologyMap.GetTopology(x, z);

        if ((topology & 8389632) == 0)
        {
            float slope = TerrainMeta.HeightMap.GetSlope(single1, single);
            float splat = TerrainMeta.SplatMap.GetSplat(single1, single, 8);
            if (slope > 40f || splat > 0.4f)
            {
                topologyMap.AddTopology(x, z, 2);
                return;
            }
            if (!keepExisting && slope < 20f && splat < 0.2f && (topology & 55296) != 0)
            {
                topologyMap.RemoveTopology(x, z, 2);
            }
        }
    }