Пример #1
0
    protected override void ApplyTopology(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if (Radius == 0f)
        {
            Radius = extents.x;
        }
        TextureData topologydata = new TextureData(topologymap.Get());
        Vector3     v            = localToWorld.MultiplyPoint3x4(offset + new Vector3(0f - Radius, 0f, 0f - Radius));
        Vector3     v2           = localToWorld.MultiplyPoint3x4(offset + new Vector3(Radius, 0f, 0f - Radius));
        Vector3     v3           = localToWorld.MultiplyPoint3x4(offset + new Vector3(0f - Radius, 0f, Radius));
        Vector3     v4           = localToWorld.MultiplyPoint3x4(offset + new Vector3(Radius, 0f, Radius));

        TerrainMeta.TopologyMap.ForEachParallel(v, v2, v3, v4, delegate(int x, int z)
        {
            GenerateCliffTopology.Process(x, z);
            float normZ         = TerrainMeta.TopologyMap.Coordinate(z);
            float normX         = TerrainMeta.TopologyMap.Coordinate(x);
            Vector3 point       = new Vector3(TerrainMeta.DenormalizeX(normX), 0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 vector      = worldToLocal.MultiplyPoint3x4(point) - offset;
            int interpolatedInt = topologydata.GetInterpolatedInt((vector.x + extents.x) / size.x, (vector.z + extents.z) / size.z);
            if (ShouldTopology(interpolatedInt))
            {
                TerrainMeta.TopologyMap.AddTopology(x, z, interpolatedInt & (int)TopologyMask);
            }
        });
    }
Пример #2
0
    protected override void ApplyHeight(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if (Radius == 0f)
        {
            Radius = extents.x;
        }
        bool        useBlendMap = blendmap.isValid;
        Vector3     position    = localToWorld.MultiplyPoint3x4(Vector3.zero);
        TextureData heightdata  = new TextureData(heightmap.Get());
        TextureData blenddata   = new TextureData(useBlendMap ? blendmap.Get() : null);
        float       num         = (useBlendMap ? extents.x : Radius);
        float       num2        = (useBlendMap ? extents.z : Radius);
        Vector3     v           = localToWorld.MultiplyPoint3x4(offset + new Vector3(0f - num, 0f, 0f - num2));
        Vector3     v2          = localToWorld.MultiplyPoint3x4(offset + new Vector3(num, 0f, 0f - num2));
        Vector3     v3          = localToWorld.MultiplyPoint3x4(offset + new Vector3(0f - num, 0f, num2));
        Vector3     v4          = localToWorld.MultiplyPoint3x4(offset + new Vector3(num, 0f, num2));

        TerrainMeta.HeightMap.ForEachParallel(v, v2, v3, v4, delegate(int x, int z)
        {
            float normZ   = TerrainMeta.HeightMap.Coordinate(z);
            float normX   = TerrainMeta.HeightMap.Coordinate(x);
            Vector3 point = new Vector3(TerrainMeta.DenormalizeX(normX), 0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 v5    = worldToLocal.MultiplyPoint3x4(point) - offset;
            float num3    = 1f;
            num3          = ((!useBlendMap) ? Mathf.InverseLerp(Radius, Radius - Fade, v5.Magnitude2D()) : blenddata.GetInterpolatedVector((v5.x + extents.x) / size.x, (v5.z + extents.z) / size.z).w);
            if (num3 != 0f)
            {
                float to = TerrainMeta.NormalizeY(position.y + offset.y + heightdata.GetInterpolatedHalf((v5.x + extents.x) / size.x, (v5.z + extents.z) / size.z) * size.y);
                to       = Mathf.SmoothStep(TerrainMeta.HeightMap.GetHeight01(x, z), to, num3);
                TerrainMeta.HeightMap.SetHeight(x, z, to);
            }
        });
    }
    public override void Process()
    {
        RaycastHit raycastHit;
        Collider   component = base.GetComponent <Collider>();
        Bounds     bound     = component.bounds;
        int        num       = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeX(bound.min.x));
        int        num1      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeZ(bound.max.x));
        int        num2      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeX(bound.min.z));
        int        num3      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeZ(bound.max.z));

        for (int i = num2; i <= num3; i++)
        {
            float single = TerrainMeta.HeightMap.Coordinate(i);
            for (int j = num; j <= num1; j++)
            {
                float   single1 = TerrainMeta.HeightMap.Coordinate(j);
                Vector3 vector3 = new Vector3(TerrainMeta.DenormalizeX(single1), bound.max.y, TerrainMeta.DenormalizeZ(single));
                Ray     ray     = new Ray(vector3, Vector3.down);
                if (component.Raycast(ray, out raycastHit, bound.size.y))
                {
                    float single2 = TerrainMeta.NormalizeY(raycastHit.point.y);
                    if (single2 > TerrainMeta.HeightMap.GetHeight01(j, i))
                    {
                        TerrainMeta.HeightMap.SetHeight(j, i, single2);
                    }
                }
            }
        }
        GameManager.Destroy(this, 0f);
    }
Пример #4
0
    protected override void ApplyAlpha(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if (Radius == 0f)
        {
            Radius = extents.x;
        }
        TextureData alphadata = new TextureData(alphamap.Get());
        Vector3     v         = localToWorld.MultiplyPoint3x4(offset + new Vector3(0f - Radius, 0f, 0f - Radius));
        Vector3     v2        = localToWorld.MultiplyPoint3x4(offset + new Vector3(Radius, 0f, 0f - Radius));
        Vector3     v3        = localToWorld.MultiplyPoint3x4(offset + new Vector3(0f - Radius, 0f, Radius));
        Vector3     v4        = localToWorld.MultiplyPoint3x4(offset + new Vector3(Radius, 0f, Radius));

        TerrainMeta.AlphaMap.ForEachParallel(v, v2, v3, v4, delegate(int x, int z)
        {
            float normZ   = TerrainMeta.AlphaMap.Coordinate(z);
            float normX   = TerrainMeta.AlphaMap.Coordinate(x);
            Vector3 point = new Vector3(TerrainMeta.DenormalizeX(normX), 0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 v5    = worldToLocal.MultiplyPoint3x4(point) - offset;
            float num     = Mathf.InverseLerp(Radius, Radius - Fade, v5.Magnitude2D());
            if (num != 0f)
            {
                float w = alphadata.GetInterpolatedVector((v5.x + extents.x) / size.x, (v5.z + extents.z) / size.z).w;
                TerrainMeta.AlphaMap.SetAlpha(x, z, w, num);
            }
        });
    }
Пример #5
0
    public override void Process()
    {
        Collider component = (Collider)((Component)this).GetComponent <Collider>();
        Bounds   bounds    = component.get_bounds();
        int      num1      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeX((float)((Bounds) ref bounds).get_min().x));
        int      num2      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeZ((float)((Bounds) ref bounds).get_max().x));
        int      num3      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeX((float)((Bounds) ref bounds).get_min().z));
        int      num4      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeZ((float)((Bounds) ref bounds).get_max().z));

        for (int index1 = num3; index1 <= num4; ++index1)
        {
            float normZ = TerrainMeta.HeightMap.Coordinate(index1);
            for (int index2 = num1; index2 <= num2; ++index2)
            {
                float   normX = TerrainMeta.HeightMap.Coordinate(index2);
                Vector3 vector3;
                ((Vector3) ref vector3).\u002Ector(TerrainMeta.DenormalizeX(normX), (float)((Bounds) ref bounds).get_max().y, TerrainMeta.DenormalizeZ(normZ));
                Ray ray;
                ((Ray) ref ray).\u002Ector(vector3, Vector3.get_down());
                RaycastHit raycastHit;
                if (component.Raycast(ray, ref raycastHit, (float)((Bounds) ref bounds).get_size().y))
                {
                    float height   = TerrainMeta.NormalizeY((float)((RaycastHit) ref raycastHit).get_point().y);
                    float height01 = TerrainMeta.HeightMap.GetHeight01(index2, index1);
                    if ((double)height > (double)height01)
                    {
                        TerrainMeta.HeightMap.SetHeight(index2, index1, height);
                    }
                }
            }
        }
        GameManager.Destroy((Component)this, 0.0f);
    }
Пример #6
0
    protected override void ApplyHeight(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if ((double)this.Radius == 0.0)
        {
            this.Radius = (float)this.extents.x;
        }
        bool        useBlendMap = Object.op_Inequality((Object)this.blendmap, (Object)null);
        Vector3     position    = ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.get_zero());
        TextureData heightdata  = new TextureData(this.heightmap);
        TextureData blenddata   = useBlendMap ? new TextureData(this.blendmap) : new TextureData();

        TerrainMeta.HeightMap.ForEachParallel(((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(-this.Radius, 0.0f, -this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(this.Radius, 0.0f, -this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(-this.Radius, 0.0f, this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(this.Radius, 0.0f, this.Radius))), (Action <int, int>)((x, z) =>
        {
            float normZ = TerrainMeta.HeightMap.Coordinate(z);
            float normX = TerrainMeta.HeightMap.Coordinate(x);
            Vector3 vector3_1;
            ((Vector3) ref vector3_1).\u002Ector(TerrainMeta.DenormalizeX(normX), 0.0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 vector3_2 = Vector3.op_Subtraction(((Matrix4x4) ref worldToLocal).MultiplyPoint3x4(vector3_1), this.offset);
            float num1        = !useBlendMap ? Mathf.InverseLerp(this.Radius, this.Radius - this.Fade + Noise.Billow((float)vector3_1.x, (float)vector3_1.z, 4, 0.005f, 0.25f * this.Fade, 2f, 0.5f), Vector3Ex.Magnitude2D(vector3_2)) : (float)blenddata.GetInterpolatedVector((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z)).w;
            if ((double)num1 == 0.0)
            {
                return;
            }
            float num2   = TerrainMeta.NormalizeY((float)(position.y + this.offset.y + (double)heightdata.GetInterpolatedHalf((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z)) * this.size.y));
            float height = Mathf.SmoothStep(TerrainMeta.HeightMap.GetHeight01(x, z), num2, num1);
            TerrainMeta.HeightMap.SetHeight(x, z, height);
        }));
    }
Пример #7
0
    protected override void ApplyAlpha(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if (this.Radius == 0f)
        {
            this.Radius = this.extents.x;
        }
        TextureData textureDatum = new TextureData(this.alphamap);
        Vector3     vector32     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.Radius, 0f, -this.Radius));
        Vector3     vector33     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.Radius, 0f, -this.Radius));
        Vector3     vector34     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.Radius, 0f, this.Radius));
        Vector3     vector35     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.Radius, 0f, this.Radius));

        TerrainMeta.AlphaMap.ForEachParallel(vector32, vector33, vector34, vector35, (int x, int z) => {
            float single     = TerrainMeta.AlphaMap.Coordinate(z);
            Vector3 vector3  = new Vector3(TerrainMeta.DenormalizeX(TerrainMeta.AlphaMap.Coordinate(x)), 0f, TerrainMeta.DenormalizeZ(single));
            Vector3 vector31 = worldToLocal.MultiplyPoint3x4(vector3) - this.offset;
            float single1    = Noise.Billow(vector3.x, vector3.z, 4, 0.005f, 0.25f * this.Fade, 2f, 0.5f);
            float single2    = Mathf.InverseLerp(this.Radius, this.Radius - this.Fade + single1, vector31.Magnitude2D());
            if (single2 == 0f)
            {
                return;
            }
            float interpolatedVector = textureDatum.GetInterpolatedVector((vector31.x + this.extents.x) / this.size.x, (vector31.z + this.extents.z) / this.size.z).w;
            TerrainMeta.AlphaMap.SetAlpha(x, z, interpolatedVector, single2);
        });
    }
Пример #8
0
    protected override void ApplyBiome(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if (Radius == 0f)
        {
            Radius = extents.x;
        }
        bool should0 = ShouldBiome(1);
        bool should1 = ShouldBiome(2);
        bool should2 = ShouldBiome(4);
        bool should3 = ShouldBiome(8);

        if (!should0 && !should1 && !should2 && !should3)
        {
            return;
        }
        TextureData biomedata = new TextureData(biomemap.Get());
        Vector3     v         = localToWorld.MultiplyPoint3x4(offset + new Vector3(0f - Radius, 0f, 0f - Radius));
        Vector3     v2        = localToWorld.MultiplyPoint3x4(offset + new Vector3(Radius, 0f, 0f - Radius));
        Vector3     v3        = localToWorld.MultiplyPoint3x4(offset + new Vector3(0f - Radius, 0f, Radius));
        Vector3     v4        = localToWorld.MultiplyPoint3x4(offset + new Vector3(Radius, 0f, Radius));

        TerrainMeta.BiomeMap.ForEachParallel(v, v2, v3, v4, delegate(int x, int z)
        {
            float normZ   = TerrainMeta.BiomeMap.Coordinate(z);
            float normX   = TerrainMeta.BiomeMap.Coordinate(x);
            Vector3 point = new Vector3(TerrainMeta.DenormalizeX(normX), 0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 v5    = worldToLocal.MultiplyPoint3x4(point) - offset;
            float num     = Mathf.InverseLerp(Radius, Radius - Fade, v5.Magnitude2D());
            if (num != 0f)
            {
                Vector4 interpolatedVector = biomedata.GetInterpolatedVector((v5.x + extents.x) / size.x, (v5.z + extents.z) / size.z);
                if (!should0)
                {
                    interpolatedVector.x = 0f;
                }
                if (!should1)
                {
                    interpolatedVector.y = 0f;
                }
                if (!should2)
                {
                    interpolatedVector.z = 0f;
                }
                if (!should3)
                {
                    interpolatedVector.w = 0f;
                }
                TerrainMeta.BiomeMap.SetBiomeRaw(x, z, interpolatedVector, num);
            }
        });
    }
Пример #9
0
    protected override void ApplyBiome(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if (this.Radius == 0f)
        {
            this.Radius = this.extents.x;
        }
        bool flag  = base.ShouldBiome(1);
        bool flag1 = base.ShouldBiome(2);
        bool flag2 = base.ShouldBiome(4);
        bool flag3 = base.ShouldBiome(8);

        if (!flag && !flag1 && !flag2 && !flag3)
        {
            return;
        }
        TextureData textureDatum = new TextureData(this.biomemap);
        Vector3     vector32     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.Radius, 0f, -this.Radius));
        Vector3     vector33     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.Radius, 0f, -this.Radius));
        Vector3     vector34     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.Radius, 0f, this.Radius));
        Vector3     vector35     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.Radius, 0f, this.Radius));

        TerrainMeta.BiomeMap.ForEachParallel(vector32, vector33, vector34, vector35, (int x, int z) => {
            float single     = TerrainMeta.BiomeMap.Coordinate(z);
            Vector3 vector3  = new Vector3(TerrainMeta.DenormalizeX(TerrainMeta.BiomeMap.Coordinate(x)), 0f, TerrainMeta.DenormalizeZ(single));
            Vector3 vector31 = worldToLocal.MultiplyPoint3x4(vector3) - this.offset;
            float single1    = Noise.Billow(vector3.x, vector3.z, 4, 0.005f, 0.25f * this.Fade, 2f, 0.5f);
            float single2    = Mathf.InverseLerp(this.Radius, this.Radius - this.Fade + single1, vector31.Magnitude2D());
            if (single2 == 0f)
            {
                return;
            }
            Vector4 interpolatedVector = textureDatum.GetInterpolatedVector((vector31.x + this.extents.x) / this.size.x, (vector31.z + this.extents.z) / this.size.z);
            if (!flag)
            {
                interpolatedVector.x = 0f;
            }
            if (!flag1)
            {
                interpolatedVector.y = 0f;
            }
            if (!flag2)
            {
                interpolatedVector.z = 0f;
            }
            if (!flag3)
            {
                interpolatedVector.w = 0f;
            }
            TerrainMeta.BiomeMap.SetBiomeRaw(x, z, interpolatedVector, single2);
        });
    }
Пример #10
0
    public override void Process()
    {
        Collider component = (Collider)((Component)this).GetComponent <Collider>();
        Bounds   bounds    = component.get_bounds();
        int      num1      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeX((float)((Bounds) ref bounds).get_min().x));
        int      num2      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeZ((float)((Bounds) ref bounds).get_max().x));
        int      num3      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeX((float)((Bounds) ref bounds).get_min().z));
        int      num4      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeZ((float)((Bounds) ref bounds).get_max().z));

        if (component is BoxCollider && Quaternion.op_Equality(((Component)this).get_transform().get_rotation(), Quaternion.get_identity()))
        {
            float height = TerrainMeta.NormalizeY((float)((Bounds) ref bounds).get_max().y);
            for (int z = num3; z <= num4; ++z)
            {
                for (int x = num1; x <= num2; ++x)
                {
                    float height01 = TerrainMeta.WaterMap.GetHeight01(x, z);
                    if ((double)height > (double)height01)
                    {
                        TerrainMeta.WaterMap.SetHeight(x, z, height);
                    }
                }
            }
        }
        else
        {
            for (int index1 = num3; index1 <= num4; ++index1)
            {
                float normZ = TerrainMeta.WaterMap.Coordinate(index1);
                for (int index2 = num1; index2 <= num2; ++index2)
                {
                    float   normX = TerrainMeta.WaterMap.Coordinate(index2);
                    Vector3 vector3;
                    ((Vector3) ref vector3).\u002Ector(TerrainMeta.DenormalizeX(normX), (float)(((Bounds) ref bounds).get_max().y + 1.0), TerrainMeta.DenormalizeZ(normZ));
                    Ray ray;
                    ((Ray) ref ray).\u002Ector(vector3, Vector3.get_down());
                    RaycastHit raycastHit;
                    if (component.Raycast(ray, ref raycastHit, (float)(((Bounds) ref bounds).get_size().y + 1.0 + 1.0)))
                    {
                        float height   = TerrainMeta.NormalizeY((float)((RaycastHit) ref raycastHit).get_point().y);
                        float height01 = TerrainMeta.WaterMap.GetHeight01(index2, index1);
                        if ((double)height > (double)height01)
                        {
                            TerrainMeta.WaterMap.SetHeight(index2, index1, height);
                        }
                    }
                }
            }
        }
        GameManager.Destroy((Component)this, 0.0f);
    }
Пример #11
0
    protected override void ApplyBiome(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        bool flag  = base.ShouldBiome(1);
        bool flag1 = base.ShouldBiome(2);
        bool flag2 = base.ShouldBiome(4);
        bool flag3 = base.ShouldBiome(8);

        if (!flag && !flag1 && !flag2 && !flag3)
        {
            return;
        }
        Vector3     vector32      = localToWorld.MultiplyPoint3x4(Vector3.zero);
        TextureData textureDatum  = new TextureData(this.heightmap);
        TextureData textureDatum1 = new TextureData(this.biomemap);
        Vector3     vector33      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.extents.x, 0f, -this.extents.z));
        Vector3     vector34      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.extents.x, 0f, -this.extents.z));
        Vector3     vector35      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.extents.x, 0f, this.extents.z));
        Vector3     vector36      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.extents.x, 0f, this.extents.z));

        TerrainMeta.BiomeMap.ForEachParallel(vector33, vector34, vector35, vector36, (int x, int z) => {
            float single           = TerrainMeta.BiomeMap.Coordinate(z);
            Vector3 vector3        = new Vector3(TerrainMeta.DenormalizeX(TerrainMeta.BiomeMap.Coordinate(x)), 0f, TerrainMeta.DenormalizeZ(single));
            Vector3 vector31       = worldToLocal.MultiplyPoint3x4(vector3) - this.offset;
            float u003cu003e4_this = vector32.y + this.offset.y + textureDatum.GetInterpolatedHalf((vector31.x + this.extents.x) / this.size.x, (vector31.z + this.extents.z) / this.size.z) * this.size.y;
            float single1          = Mathf.InverseLerp(vector32.y, vector32.y + this.Fade, u003cu003e4_this);
            if (single1 == 0f)
            {
                return;
            }
            Vector4 interpolatedVector = textureDatum1.GetInterpolatedVector((vector31.x + this.extents.x) / this.size.x, (vector31.z + this.extents.z) / this.size.z);
            if (!flag)
            {
                interpolatedVector.x = 0f;
            }
            if (!flag1)
            {
                interpolatedVector.y = 0f;
            }
            if (!flag2)
            {
                interpolatedVector.z = 0f;
            }
            if (!flag3)
            {
                interpolatedVector.w = 0f;
            }
            TerrainMeta.BiomeMap.SetBiomeRaw(x, z, interpolatedVector, single1);
        });
    }
Пример #12
0
    public override void Process()
    {
        Collider component = GetComponent <Collider>();
        Bounds   bounds    = component.bounds;
        int      num       = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeX(bounds.min.x));
        int      num2      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeZ(bounds.max.x));
        int      num3      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeX(bounds.min.z));
        int      num4      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeZ(bounds.max.z));

        if (component is BoxCollider && base.transform.rotation == Quaternion.identity)
        {
            float num5 = TerrainMeta.NormalizeY(bounds.max.y);
            for (int i = num3; i <= num4; i++)
            {
                for (int j = num; j <= num2; j++)
                {
                    float height = TerrainMeta.WaterMap.GetHeight01(j, i);
                    if (num5 > height)
                    {
                        TerrainMeta.WaterMap.SetHeight(j, i, num5);
                    }
                }
            }
        }
        else
        {
            for (int k = num3; k <= num4; k++)
            {
                float normZ = TerrainMeta.WaterMap.Coordinate(k);
                for (int l = num; l <= num2; l++)
                {
                    float      normX  = TerrainMeta.WaterMap.Coordinate(l);
                    Vector3    origin = new Vector3(TerrainMeta.DenormalizeX(normX), bounds.max.y + 1f, TerrainMeta.DenormalizeZ(normZ));
                    Ray        ray    = new Ray(origin, Vector3.down);
                    RaycastHit hitInfo;
                    if (component.Raycast(ray, out hitInfo, bounds.size.y + 1f + 1f))
                    {
                        float num6    = TerrainMeta.NormalizeY(hitInfo.point.y);
                        float height2 = TerrainMeta.WaterMap.GetHeight01(l, k);
                        if (num6 > height2)
                        {
                            TerrainMeta.WaterMap.SetHeight(l, k, num6);
                        }
                    }
                }
            }
        }
        GameManager.Destroy(this);
    }
Пример #13
0
    protected override void ApplyBiome(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if ((double)this.Radius == 0.0)
        {
            this.Radius = (float)this.extents.x;
        }
        bool should0 = this.ShouldBiome(1);
        bool should1 = this.ShouldBiome(2);
        bool should2 = this.ShouldBiome(4);
        bool should3 = this.ShouldBiome(8);

        if (!should0 && !should1 && (!should2 && !should3))
        {
            return;
        }
        TextureData biomedata = new TextureData(this.biomemap);

        TerrainMeta.BiomeMap.ForEachParallel(((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(-this.Radius, 0.0f, -this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(this.Radius, 0.0f, -this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(-this.Radius, 0.0f, this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(this.Radius, 0.0f, this.Radius))), (Action <int, int>)((x, z) =>
        {
            float normZ = TerrainMeta.BiomeMap.Coordinate(z);
            float normX = TerrainMeta.BiomeMap.Coordinate(x);
            Vector3 vector3_1;
            ((Vector3) ref vector3_1).\u002Ector(TerrainMeta.DenormalizeX(normX), 0.0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 vector3_2 = Vector3.op_Subtraction(((Matrix4x4) ref worldToLocal).MultiplyPoint3x4(vector3_1), this.offset);
            float opacity     = Mathf.InverseLerp(this.Radius, this.Radius - this.Fade + Noise.Billow((float)vector3_1.x, (float)vector3_1.z, 4, 0.005f, 0.25f * this.Fade, 2f, 0.5f), Vector3Ex.Magnitude2D(vector3_2));
            if ((double)opacity == 0.0)
            {
                return;
            }
            Vector4 interpolatedVector = biomedata.GetInterpolatedVector((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z));
            if (!should0)
            {
                interpolatedVector.x = (__Null)0.0;
            }
            if (!should1)
            {
                interpolatedVector.y = (__Null)0.0;
            }
            if (!should2)
            {
                interpolatedVector.z = (__Null)0.0;
            }
            if (!should3)
            {
                interpolatedVector.w = (__Null)0.0;
            }
            TerrainMeta.BiomeMap.SetBiomeRaw(x, z, interpolatedVector, opacity);
        }));
    }
Пример #14
0
    public override void Process()
    {
        RaycastHit raycastHit;
        Collider   component = base.GetComponent <Collider>();
        Bounds     bound     = component.bounds;
        int        num       = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeX(bound.min.x));
        int        num1      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeZ(bound.max.x));
        int        num2      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeX(bound.min.z));
        int        num3      = TerrainMeta.WaterMap.Index(TerrainMeta.NormalizeZ(bound.max.z));

        if (!(component is BoxCollider) || !(base.transform.rotation == Quaternion.identity))
        {
            for (int i = num2; i <= num3; i++)
            {
                float single = TerrainMeta.WaterMap.Coordinate(i);
                for (int j = num; j <= num1; j++)
                {
                    float   single1 = TerrainMeta.WaterMap.Coordinate(j);
                    Vector3 vector3 = new Vector3(TerrainMeta.DenormalizeX(single1), bound.max.y + 1f, TerrainMeta.DenormalizeZ(single));
                    Ray     ray     = new Ray(vector3, Vector3.down);
                    if (component.Raycast(ray, out raycastHit, bound.size.y + 1f + 1f))
                    {
                        float single2 = TerrainMeta.NormalizeY(raycastHit.point.y);
                        if (single2 > TerrainMeta.WaterMap.GetHeight01(j, i))
                        {
                            TerrainMeta.WaterMap.SetHeight(j, i, single2);
                        }
                    }
                }
            }
        }
        else
        {
            float single3 = TerrainMeta.NormalizeY(bound.max.y);
            for (int k = num2; k <= num3; k++)
            {
                for (int l = num; l <= num1; l++)
                {
                    if (single3 > TerrainMeta.WaterMap.GetHeight01(l, k))
                    {
                        TerrainMeta.WaterMap.SetHeight(l, k, single3);
                    }
                }
            }
        }
        GameManager.Destroy(this, 0f);
    }
Пример #15
0
    protected override void ApplyBiome(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        bool should0 = this.ShouldBiome(1);
        bool should1 = this.ShouldBiome(2);
        bool should2 = this.ShouldBiome(4);
        bool should3 = this.ShouldBiome(8);

        if (!should0 && !should1 && (!should2 && !should3))
        {
            return;
        }
        Vector3     position   = ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.get_zero());
        TextureData heightdata = new TextureData(this.heightmap);
        TextureData biomedata  = new TextureData(this.biomemap);

        TerrainMeta.BiomeMap.ForEachParallel(((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)this.extents.z))), (Action <int, int>)((x, z) =>
        {
            float normZ = TerrainMeta.BiomeMap.Coordinate(z);
            float normX = TerrainMeta.BiomeMap.Coordinate(x);
            Vector3 vector3_1;
            ((Vector3) ref vector3_1).\u002Ector(TerrainMeta.DenormalizeX(normX), 0.0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 vector3_2 = Vector3.op_Subtraction(((Matrix4x4) ref worldToLocal).MultiplyPoint3x4(vector3_1), this.offset);
            float opacity     = Mathf.InverseLerp((float)position.y, (float)position.y + this.Fade, (float)(position.y + this.offset.y + (double)heightdata.GetInterpolatedHalf((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z)) * this.size.y));
            if ((double)opacity == 0.0)
            {
                return;
            }
            Vector4 interpolatedVector = biomedata.GetInterpolatedVector((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z));
            if (!should0)
            {
                interpolatedVector.x = (__Null)0.0;
            }
            if (!should1)
            {
                interpolatedVector.y = (__Null)0.0;
            }
            if (!should2)
            {
                interpolatedVector.z = (__Null)0.0;
            }
            if (!should3)
            {
                interpolatedVector.w = (__Null)0.0;
            }
            TerrainMeta.BiomeMap.SetBiomeRaw(x, z, interpolatedVector, opacity);
        }));
    }
Пример #16
0
    protected override void ApplyTopology(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        TextureData topologydata = new TextureData(this.topologymap);

        TerrainMeta.TopologyMap.ForEachParallel(((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)this.extents.z))), (Action <int, int>)((x, z) =>
        {
            GenerateCliffTopology.Process(x, z);
            float normZ = TerrainMeta.TopologyMap.Coordinate(z);
            float normX = TerrainMeta.TopologyMap.Coordinate(x);
            Vector3 vector3_1;
            ((Vector3) ref vector3_1).\u002Ector(TerrainMeta.DenormalizeX(normX), 0.0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 vector3_2   = Vector3.op_Subtraction(((Matrix4x4) ref worldToLocal).MultiplyPoint3x4(vector3_1), this.offset);
            int interpolatedInt = topologydata.GetInterpolatedInt((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z));
            if (!this.ShouldTopology(interpolatedInt))
            {
                return;
            }
            TerrainMeta.TopologyMap.AddTopology(x, z, interpolatedInt & this.TopologyMask);
        }));
    }
Пример #17
0
    protected override void ApplyTopology(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        TextureData textureDatum = new TextureData(this.topologymap);
        Vector3     vector32     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.extents.x, 0f, -this.extents.z));
        Vector3     vector33     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.extents.x, 0f, -this.extents.z));
        Vector3     vector34     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.extents.x, 0f, this.extents.z));
        Vector3     vector35     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.extents.x, 0f, this.extents.z));

        TerrainMeta.TopologyMap.ForEachParallel(vector32, vector33, vector34, vector35, (int x, int z) => {
            GenerateCliffTopology.Process(x, z);
            float single        = TerrainMeta.TopologyMap.Coordinate(z);
            Vector3 vector3     = new Vector3(TerrainMeta.DenormalizeX(TerrainMeta.TopologyMap.Coordinate(x)), 0f, TerrainMeta.DenormalizeZ(single));
            Vector3 vector31    = worldToLocal.MultiplyPoint3x4(vector3) - this.offset;
            int interpolatedInt = textureDatum.GetInterpolatedInt((vector31.x + this.extents.x) / this.size.x, (vector31.z + this.extents.z) / this.size.z);
            if (base.ShouldTopology(interpolatedInt))
            {
                TerrainMeta.TopologyMap.AddTopology(x, z, interpolatedInt & (int)this.TopologyMask);
            }
        });
    }
Пример #18
0
    protected override void ApplyHeight(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if (this.Radius == 0f)
        {
            this.Radius = this.extents.x;
        }
        bool        flag          = this.blendmap != null;
        Vector3     vector32      = localToWorld.MultiplyPoint3x4(Vector3.zero);
        TextureData textureDatum  = new TextureData(this.heightmap);
        TextureData textureDatum1 = (flag ? new TextureData(this.blendmap) : new TextureData());
        Vector3     vector33      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.Radius, 0f, -this.Radius));
        Vector3     vector34      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.Radius, 0f, -this.Radius));
        Vector3     vector35      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.Radius, 0f, this.Radius));
        Vector3     vector36      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.Radius, 0f, this.Radius));

        TerrainMeta.HeightMap.ForEachParallel(vector33, vector34, vector35, vector36, (int x, int z) => {
            float single             = TerrainMeta.HeightMap.Coordinate(z);
            Vector3 vector3          = new Vector3(TerrainMeta.DenormalizeX(TerrainMeta.HeightMap.Coordinate(x)), 0f, TerrainMeta.DenormalizeZ(single));
            Vector3 vector31         = worldToLocal.MultiplyPoint3x4(vector3) - this.offset;
            float interpolatedVector = 1f;
            if (!flag)
            {
                float single1      = Noise.Billow(vector3.x, vector3.z, 4, 0.005f, 0.25f * this.Fade, 2f, 0.5f);
                interpolatedVector = Mathf.InverseLerp(this.Radius, this.Radius - this.Fade + single1, vector31.Magnitude2D());
            }
            else
            {
                interpolatedVector = textureDatum1.GetInterpolatedVector((vector31.x + this.extents.x) / this.size.x, (vector31.z + this.extents.z) / this.size.z).w;
            }
            if (interpolatedVector == 0f)
            {
                return;
            }
            float single2 = TerrainMeta.NormalizeY(vector32.y + this.offset.y + textureDatum.GetInterpolatedHalf((vector31.x + this.extents.x) / this.size.x, (vector31.z + this.extents.z) / this.size.z) * this.size.y);
            single2       = Mathf.SmoothStep(TerrainMeta.HeightMap.GetHeight01(x, z), single2, interpolatedVector);
            TerrainMeta.HeightMap.SetHeight(x, z, single2);
        });
    }
Пример #19
0
    public override void Process()
    {
        Collider component = GetComponent <Collider>();
        Bounds   bounds    = component.bounds;
        int      num       = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeX(bounds.min.x));
        int      num2      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeZ(bounds.max.x));
        int      num3      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeX(bounds.min.z));
        int      num4      = TerrainMeta.HeightMap.Index(TerrainMeta.NormalizeZ(bounds.max.z));

        for (int i = num3; i <= num4; i++)
        {
            float normZ = TerrainMeta.HeightMap.Coordinate(i);
            for (int j = num; j <= num2; j++)
            {
                float      normX  = TerrainMeta.HeightMap.Coordinate(j);
                Vector3    origin = new Vector3(TerrainMeta.DenormalizeX(normX), bounds.max.y, TerrainMeta.DenormalizeZ(normZ));
                Ray        ray    = new Ray(origin, Vector3.down);
                RaycastHit hitInfo;
                if (component.Raycast(ray, out hitInfo, bounds.size.y))
                {
                    float num5   = TerrainMeta.NormalizeY(hitInfo.point.y);
                    float height = TerrainMeta.HeightMap.GetHeight01(j, i);
                    if (num5 > height)
                    {
                        TerrainMeta.HeightMap.SetHeight(j, i, num5);
                    }
                }
            }
        }
        if (DestroyGameObject)
        {
            GameManager.Destroy(base.gameObject);
        }
        else
        {
            GameManager.Destroy(this);
        }
    }
Пример #20
0
    protected override void ApplyHeight(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        Vector3     position   = ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.get_zero());
        TextureData heightdata = new TextureData(this.heightmap);

        TerrainMeta.HeightMap.ForEachParallel(((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)-this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)-this.extents.x, 0.0f, (float)this.extents.z))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3((float)this.extents.x, 0.0f, (float)this.extents.z))), (Action <int, int>)((x, z) =>
        {
            float normZ = TerrainMeta.HeightMap.Coordinate(z);
            float normX = TerrainMeta.HeightMap.Coordinate(x);
            Vector3 vector3_1;
            ((Vector3) ref vector3_1).\u002Ector(TerrainMeta.DenormalizeX(normX), 0.0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 vector3_2 = Vector3.op_Subtraction(((Matrix4x4) ref worldToLocal).MultiplyPoint3x4(vector3_1), this.offset);
            float y           = (float)(position.y + this.offset.y + (double)heightdata.GetInterpolatedHalf((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z)) * this.size.y);
            float opacity     = Mathf.InverseLerp((float)position.y, (float)position.y + this.Fade, y);
            if ((double)opacity == 0.0)
            {
                return;
            }
            float num    = TerrainMeta.NormalizeY(y);
            float height = Mathx.SmoothMax(TerrainMeta.HeightMap.GetHeight01(x, z), num, 0.1f);
            TerrainMeta.HeightMap.SetHeight(x, z, height, opacity);
        }));
    }
Пример #21
0
    protected override void ApplyAlpha(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if ((double)this.Radius == 0.0)
        {
            this.Radius = (float)this.extents.x;
        }
        TextureData alphadata = new TextureData(this.alphamap);

        TerrainMeta.AlphaMap.ForEachParallel(((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(-this.Radius, 0.0f, -this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(this.Radius, 0.0f, -this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(-this.Radius, 0.0f, this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(this.Radius, 0.0f, this.Radius))), (Action <int, int>)((x, z) =>
        {
            float normZ = TerrainMeta.AlphaMap.Coordinate(z);
            float normX = TerrainMeta.AlphaMap.Coordinate(x);
            Vector3 vector3_1;
            ((Vector3) ref vector3_1).\u002Ector(TerrainMeta.DenormalizeX(normX), 0.0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 vector3_2 = Vector3.op_Subtraction(((Matrix4x4) ref worldToLocal).MultiplyPoint3x4(vector3_1), this.offset);
            float opacity     = Mathf.InverseLerp(this.Radius, this.Radius - this.Fade + Noise.Billow((float)vector3_1.x, (float)vector3_1.z, 4, 0.005f, 0.25f * this.Fade, 2f, 0.5f), Vector3Ex.Magnitude2D(vector3_2));
            if ((double)opacity == 0.0)
            {
                return;
            }
            float w = (float)alphadata.GetInterpolatedVector((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z)).w;
            TerrainMeta.AlphaMap.SetAlpha(x, z, w, opacity);
        }));
    }
Пример #22
0
    protected override void ApplyHeight(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        Vector3     vector32     = localToWorld.MultiplyPoint3x4(Vector3.zero);
        TextureData textureDatum = new TextureData(this.heightmap);
        Vector3     vector33     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.extents.x, 0f, -this.extents.z));
        Vector3     vector34     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.extents.x, 0f, -this.extents.z));
        Vector3     vector35     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.extents.x, 0f, this.extents.z));
        Vector3     vector36     = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.extents.x, 0f, this.extents.z));

        TerrainMeta.HeightMap.ForEachParallel(vector33, vector34, vector35, vector36, (int x, int z) => {
            float single           = TerrainMeta.HeightMap.Coordinate(z);
            Vector3 vector3        = new Vector3(TerrainMeta.DenormalizeX(TerrainMeta.HeightMap.Coordinate(x)), 0f, TerrainMeta.DenormalizeZ(single));
            Vector3 vector31       = worldToLocal.MultiplyPoint3x4(vector3) - this.offset;
            float u003cu003e4_this = vector32.y + this.offset.y + textureDatum.GetInterpolatedHalf((vector31.x + this.extents.x) / this.size.x, (vector31.z + this.extents.z) / this.size.z) * this.size.y;
            float single1          = Mathf.InverseLerp(vector32.y, vector32.y + this.Fade, u003cu003e4_this);
            if (single1 == 0f)
            {
                return;
            }
            float single2 = TerrainMeta.NormalizeY(u003cu003e4_this);
            single2       = Mathx.SmoothMax(TerrainMeta.HeightMap.GetHeight01(x, z), single2, 0.1f);
            TerrainMeta.HeightMap.SetHeight(x, z, single2, single1);
        });
    }
Пример #23
0
    protected override void ApplySplat(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if (Radius == 0f)
        {
            Radius = extents.x;
        }
        bool should0 = ShouldSplat(1);
        bool should1 = ShouldSplat(2);
        bool should2 = ShouldSplat(4);
        bool should3 = ShouldSplat(8);
        bool should4 = ShouldSplat(16);
        bool should5 = ShouldSplat(32);
        bool should6 = ShouldSplat(64);
        bool should7 = ShouldSplat(128);

        if (!should0 && !should1 && !should2 && !should3 && !should4 && !should5 && !should6 && !should7)
        {
            return;
        }
        TextureData splat0data = new TextureData(splatmap0.Get());
        TextureData splat1data = new TextureData(splatmap1.Get());
        Vector3     v          = localToWorld.MultiplyPoint3x4(offset + new Vector3(0f - Radius, 0f, 0f - Radius));
        Vector3     v2         = localToWorld.MultiplyPoint3x4(offset + new Vector3(Radius, 0f, 0f - Radius));
        Vector3     v3         = localToWorld.MultiplyPoint3x4(offset + new Vector3(0f - Radius, 0f, Radius));
        Vector3     v4         = localToWorld.MultiplyPoint3x4(offset + new Vector3(Radius, 0f, Radius));

        TerrainMeta.SplatMap.ForEachParallel(v, v2, v3, v4, delegate(int x, int z)
        {
            GenerateCliffSplat.Process(x, z);
            float normZ   = TerrainMeta.SplatMap.Coordinate(z);
            float normX   = TerrainMeta.SplatMap.Coordinate(x);
            Vector3 point = new Vector3(TerrainMeta.DenormalizeX(normX), 0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 v5    = worldToLocal.MultiplyPoint3x4(point) - offset;
            float num     = Mathf.InverseLerp(Radius, Radius - Fade, v5.Magnitude2D());
            if (num != 0f)
            {
                Vector4 interpolatedVector  = splat0data.GetInterpolatedVector((v5.x + extents.x) / size.x, (v5.z + extents.z) / size.z);
                Vector4 interpolatedVector2 = splat1data.GetInterpolatedVector((v5.x + extents.x) / size.x, (v5.z + extents.z) / size.z);
                if (!should0)
                {
                    interpolatedVector.x = 0f;
                }
                if (!should1)
                {
                    interpolatedVector.y = 0f;
                }
                if (!should2)
                {
                    interpolatedVector.z = 0f;
                }
                if (!should3)
                {
                    interpolatedVector.w = 0f;
                }
                if (!should4)
                {
                    interpolatedVector2.x = 0f;
                }
                if (!should5)
                {
                    interpolatedVector2.y = 0f;
                }
                if (!should6)
                {
                    interpolatedVector2.z = 0f;
                }
                if (!should7)
                {
                    interpolatedVector2.w = 0f;
                }
                TerrainMeta.SplatMap.SetSplatRaw(x, z, interpolatedVector, interpolatedVector2, num);
            }
        });
    }
Пример #24
0
    public override void Process(uint seed)
    {
        List <PathList>     pathLists   = new List <PathList>();
        TerrainHeightMap    heightMap   = TerrainMeta.HeightMap;
        TerrainTopologyMap  topologyMap = TerrainMeta.TopologyMap;
        List <MonumentInfo> monuments   = TerrainMeta.Path.Monuments;

        if (monuments.Count == 0)
        {
            return;
        }
        int num = Mathf.NextPowerOfTwo((int)((float)((float)World.Size) / 10f));

        int[,] numArray = new int[num, num];
        float single = 5f;

        for (int i = 0; i < num; i++)
        {
            float single1 = ((float)i + 0.5f) / (float)num;
            for (int j = 0; j < num; j++)
            {
                float single2  = ((float)j + 0.5f) / (float)num;
                int   num1     = SeedRandom.Range(ref seed, 100, 500);
                float slope    = heightMap.GetSlope(single2, single1);
                int   topology = topologyMap.GetTopology(single2, single1, single);
                int   num2     = 2295686;
                int   num3     = 49152;
                if (slope > 20f || (topology & num2) != 0)
                {
                    numArray[i, j] = 2147483647;
                }
                else if ((topology & num3) == 0)
                {
                    numArray[i, j] = 1 + (int)(slope * slope * 10f) + num1;
                }
                else
                {
                    numArray[i, j] = 2500;
                }
            }
        }
        PathFinder pathFinder = new PathFinder(numArray, true);
        List <GenerateRoadLayout.PathSegment> pathSegments = new List <GenerateRoadLayout.PathSegment>();
        List <GenerateRoadLayout.PathNode>    pathNodes    = new List <GenerateRoadLayout.PathNode>();
        List <GenerateRoadLayout.PathNode>    pathNodes1   = new List <GenerateRoadLayout.PathNode>();
        List <PathFinder.Point> points  = new List <PathFinder.Point>();
        List <PathFinder.Point> points1 = new List <PathFinder.Point>();
        List <PathFinder.Point> points2 = new List <PathFinder.Point>();

        foreach (MonumentInfo monument in monuments)
        {
            bool count = pathNodes.Count == 0;
            foreach (TerrainPathConnect target in monument.GetTargets(InfrastructureType.Road))
            {
                PathFinder.Node node = pathFinder.FindClosestWalkable(target.GetPoint(num), 100000);
                if (node == null)
                {
                    continue;
                }
                GenerateRoadLayout.PathNode pathNode = new GenerateRoadLayout.PathNode()
                {
                    monument = monument,
                    target   = target,
                    node     = node
                };
                if (!count)
                {
                    pathNodes1.Add(pathNode);
                }
                else
                {
                    pathNodes.Add(pathNode);
                }
            }
        }
        while (pathNodes1.Count != 0)
        {
            points1.Clear();
            points2.Clear();
            points1.AddRange(
                from x in pathNodes
                select x.node.point);
            points1.AddRange(points);
            points2.AddRange(
                from x in pathNodes1
                select x.node.point);
            PathFinder.Node node1 = pathFinder.FindPathUndirected(points1, points2, 100000);
            if (node1 != null)
            {
                GenerateRoadLayout.PathSegment pathSegment = new GenerateRoadLayout.PathSegment();
                for (PathFinder.Node k = node1; k != null; k = k.next)
                {
                    if (k == node1)
                    {
                        pathSegment.start = k;
                    }
                    if (k.next == null)
                    {
                        pathSegment.end = k;
                    }
                }
                pathSegments.Add(pathSegment);
                GenerateRoadLayout.PathNode pathNode1 = pathNodes1.Find((GenerateRoadLayout.PathNode x) => {
                    if (x.node.point == pathSegment.start.point)
                    {
                        return(true);
                    }
                    return(x.node.point == pathSegment.end.point);
                });
                pathNodes.AddRange(
                    from x in pathNodes1
                    where x.monument == pathNode1.monument
                    select x);
                pathNodes1.RemoveAll((GenerateRoadLayout.PathNode x) => x.monument == pathNode1.monument);
                int num4 = 1;
                for (PathFinder.Node l = node1; l != null; l = l.next)
                {
                    if (num4 % 8 == 0)
                    {
                        points.Add(l.point);
                    }
                    num4++;
                }
            }
            else
            {
                GenerateRoadLayout.PathNode item = pathNodes1[0];
                pathNodes.AddRange(
                    from x in pathNodes1
                    where x.monument == item.monument
                    select x);
                pathNodes1.RemoveAll((GenerateRoadLayout.PathNode x) => x.monument == item.monument);
            }
        }
        foreach (GenerateRoadLayout.PathNode pathNode2 in pathNodes)
        {
            GenerateRoadLayout.PathSegment pathSegment1 = pathSegments.Find((GenerateRoadLayout.PathSegment x) => {
                if (x.start.point == pathNode2.node.point)
                {
                    return(true);
                }
                return(x.end.point == pathNode2.node.point);
            });
            if (pathSegment1 == null)
            {
                continue;
            }
            if (pathSegment1.start.point != pathNode2.node.point)
            {
                if (pathSegment1.end.point != pathNode2.node.point)
                {
                    continue;
                }
                pathSegment1.end.next = pathNode2.node;
                pathSegment1.end      = pathFinder.FindEnd(pathNode2.node);
                pathSegment1.target   = pathNode2.target;
            }
            else
            {
                PathFinder.Node node2 = pathNode2.node;
                PathFinder.Node node3 = pathFinder.Reverse(pathNode2.node);
                node2.next          = pathSegment1.start;
                pathSegment1.start  = node3;
                pathSegment1.origin = pathNode2.target;
            }
        }
        List <Vector3> vector3s = new List <Vector3>();

        foreach (GenerateRoadLayout.PathSegment pathSegment2 in pathSegments)
        {
            bool flag  = false;
            bool flag1 = false;
            for (PathFinder.Node m = pathSegment2.start; m != null; m = m.next)
            {
                float single3 = ((float)m.point.x + 0.5f) / (float)num;
                float single4 = ((float)m.point.y + 0.5f) / (float)num;
                if (pathSegment2.start == m && pathSegment2.origin != null)
                {
                    flag    = true;
                    single3 = TerrainMeta.NormalizeX(pathSegment2.origin.transform.position.x);
                    single4 = TerrainMeta.NormalizeZ(pathSegment2.origin.transform.position.z);
                }
                else if (pathSegment2.end == m && pathSegment2.target != null)
                {
                    flag1   = true;
                    single3 = TerrainMeta.NormalizeX(pathSegment2.target.transform.position.x);
                    single4 = TerrainMeta.NormalizeZ(pathSegment2.target.transform.position.z);
                }
                float single5 = TerrainMeta.DenormalizeX(single3);
                float single6 = TerrainMeta.DenormalizeZ(single4);
                float single7 = Mathf.Max(heightMap.GetHeight(single3, single4), 1f);
                vector3s.Add(new Vector3(single5, single7, single6));
            }
            if (vector3s.Count == 0)
            {
                continue;
            }
            if (vector3s.Count >= 2)
            {
                PathList pathList = new PathList(string.Concat("Road ", pathLists.Count), vector3s.ToArray())
                {
                    Width         = 10f,
                    InnerPadding  = 1f,
                    OuterPadding  = 1f,
                    InnerFade     = 1f,
                    OuterFade     = 8f,
                    RandomScale   = 0.75f,
                    MeshOffset    = 0f,
                    TerrainOffset = -0.5f,
                    Topology      = 2048,
                    Splat         = 128,
                    Start         = flag,
                    End           = flag1
                };
                pathLists.Add(pathList);
            }
            vector3s.Clear();
        }
        foreach (PathList pathList1 in pathLists)
        {
            pathList1.Path.Smoothen(2);
        }
        TerrainMeta.Path.Roads.AddRange(pathLists);
    }
Пример #25
0
    public override void Process(uint seed)
    {
        List <PathList>     pathListList = new List <PathList>();
        TerrainHeightMap    heightMap    = TerrainMeta.HeightMap;
        TerrainTopologyMap  topologyMap  = TerrainMeta.TopologyMap;
        List <MonumentInfo> monuments    = TerrainMeta.Path.Monuments;

        if (monuments.Count == 0)
        {
            return;
        }
        int res = Mathf.NextPowerOfTwo((int)((double)World.Size / 10.0));

        int[,] costmap = new int[res, res];
        float radius = 5f;

        for (int index1 = 0; index1 < res; ++index1)
        {
            float normZ = ((float)index1 + 0.5f) / (float)res;
            for (int index2 = 0; index2 < res; ++index2)
            {
                float normX    = ((float)index2 + 0.5f) / (float)res;
                int   num1     = SeedRandom.Range(ref seed, 100, 500);
                float slope    = heightMap.GetSlope(normX, normZ);
                int   topology = topologyMap.GetTopology(normX, normZ, radius);
                int   num2     = 2295686;
                int   num3     = 49152;
                costmap[index1, index2] = (double)slope > 20.0 || (topology & num2) != 0 ? int.MaxValue : ((topology & num3) == 0 ? 1 + (int)((double)slope * (double)slope * 10.0) + num1 : 2500);
            }
        }
        PathFinder pathFinder = new PathFinder(costmap, true);
        List <GenerateRoadLayout.PathSegment> pathSegmentList = new List <GenerateRoadLayout.PathSegment>();
        List <GenerateRoadLayout.PathNode>    source1         = new List <GenerateRoadLayout.PathNode>();
        List <GenerateRoadLayout.PathNode>    source2         = new List <GenerateRoadLayout.PathNode>();
        List <PathFinder.Point> pointList = new List <PathFinder.Point>();
        List <PathFinder.Point> startList = new List <PathFinder.Point>();
        List <PathFinder.Point> endList   = new List <PathFinder.Point>();

        foreach (MonumentInfo monumentInfo in monuments)
        {
            bool flag = source1.Count == 0;
            foreach (TerrainPathConnect target in monumentInfo.GetTargets(InfrastructureType.Road))
            {
                PathFinder.Point point           = target.GetPoint(res);
                PathFinder.Node  closestWalkable = pathFinder.FindClosestWalkable(point, 100000);
                if (closestWalkable != null)
                {
                    GenerateRoadLayout.PathNode pathNode = new GenerateRoadLayout.PathNode();
                    pathNode.monument = monumentInfo;
                    pathNode.target   = target;
                    pathNode.node     = closestWalkable;
                    if (flag)
                    {
                        source1.Add(pathNode);
                    }
                    else
                    {
                        source2.Add(pathNode);
                    }
                }
            }
        }
        while (source2.Count != 0)
        {
            startList.Clear();
            endList.Clear();
            startList.AddRange(source1.Select <GenerateRoadLayout.PathNode, PathFinder.Point>((Func <GenerateRoadLayout.PathNode, PathFinder.Point>)(x => x.node.point)));
            startList.AddRange((IEnumerable <PathFinder.Point>)pointList);
            endList.AddRange(source2.Select <GenerateRoadLayout.PathNode, PathFinder.Point>((Func <GenerateRoadLayout.PathNode, PathFinder.Point>)(x => x.node.point)));
            PathFinder.Node pathUndirected = pathFinder.FindPathUndirected(startList, endList, 100000);
            if (pathUndirected == null)
            {
                GenerateRoadLayout.PathNode copy = source2[0];
                source1.AddRange(source2.Where <GenerateRoadLayout.PathNode>((Func <GenerateRoadLayout.PathNode, bool>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument))));
                source2.RemoveAll((Predicate <GenerateRoadLayout.PathNode>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument)));
            }
            else
            {
                GenerateRoadLayout.PathSegment segment = new GenerateRoadLayout.PathSegment();
                for (PathFinder.Node node = pathUndirected; node != null; node = node.next)
                {
                    if (node == pathUndirected)
                    {
                        segment.start = node;
                    }
                    if (node.next == null)
                    {
                        segment.end = node;
                    }
                }
                pathSegmentList.Add(segment);
                GenerateRoadLayout.PathNode copy = source2.Find((Predicate <GenerateRoadLayout.PathNode>)(x =>
                {
                    if (!(x.node.point == segment.start.point))
                    {
                        return(x.node.point == segment.end.point);
                    }
                    return(true);
                }));
                source1.AddRange(source2.Where <GenerateRoadLayout.PathNode>((Func <GenerateRoadLayout.PathNode, bool>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument))));
                source2.RemoveAll((Predicate <GenerateRoadLayout.PathNode>)(x => Object.op_Equality((Object)x.monument, (Object)copy.monument)));
                int num = 1;
                for (PathFinder.Node node = pathUndirected; node != null; node = node.next)
                {
                    if (num % 8 == 0)
                    {
                        pointList.Add(node.point);
                    }
                    ++num;
                }
            }
        }
        foreach (GenerateRoadLayout.PathNode pathNode in source1)
        {
            GenerateRoadLayout.PathNode    target      = pathNode;
            GenerateRoadLayout.PathSegment pathSegment = pathSegmentList.Find((Predicate <GenerateRoadLayout.PathSegment>)(x =>
            {
                if (!(x.start.point == target.node.point))
                {
                    return(x.end.point == target.node.point);
                }
                return(true);
            }));
            if (pathSegment != null)
            {
                if (pathSegment.start.point == target.node.point)
                {
                    PathFinder.Node node1 = target.node;
                    PathFinder.Node node2 = pathFinder.Reverse(target.node);
                    PathFinder.Node start = pathSegment.start;
                    node1.next         = start;
                    pathSegment.start  = node2;
                    pathSegment.origin = target.target;
                }
                else if (pathSegment.end.point == target.node.point)
                {
                    pathSegment.end.next = target.node;
                    pathSegment.end      = pathFinder.FindEnd(target.node);
                    pathSegment.target   = target.target;
                }
            }
        }
        List <Vector3> vector3List = new List <Vector3>();

        foreach (GenerateRoadLayout.PathSegment pathSegment in pathSegmentList)
        {
            bool flag1 = false;
            bool flag2 = false;
            for (PathFinder.Node node = pathSegment.start; node != null; node = node.next)
            {
                float normX = ((float)node.point.x + 0.5f) / (float)res;
                float normZ = ((float)node.point.y + 0.5f) / (float)res;
                if (pathSegment.start == node && Object.op_Inequality((Object)pathSegment.origin, (Object)null))
                {
                    flag1 = true;
                    normX = TerrainMeta.NormalizeX((float)((Component)pathSegment.origin).get_transform().get_position().x);
                    normZ = TerrainMeta.NormalizeZ((float)((Component)pathSegment.origin).get_transform().get_position().z);
                }
                else if (pathSegment.end == node && Object.op_Inequality((Object)pathSegment.target, (Object)null))
                {
                    flag2 = true;
                    normX = TerrainMeta.NormalizeX((float)((Component)pathSegment.target).get_transform().get_position().x);
                    normZ = TerrainMeta.NormalizeZ((float)((Component)pathSegment.target).get_transform().get_position().z);
                }
                float num1 = TerrainMeta.DenormalizeX(normX);
                float num2 = TerrainMeta.DenormalizeZ(normZ);
                float num3 = Mathf.Max(heightMap.GetHeight(normX, normZ), 1f);
                vector3List.Add(new Vector3(num1, num3, num2));
            }
            if (vector3List.Count != 0)
            {
                if (vector3List.Count >= 2)
                {
                    pathListList.Add(new PathList("Road " + (object)pathListList.Count, vector3List.ToArray())
                    {
                        Width         = 10f,
                        InnerPadding  = 1f,
                        OuterPadding  = 1f,
                        InnerFade     = 1f,
                        OuterFade     = 8f,
                        RandomScale   = 0.75f,
                        MeshOffset    = -0.0f,
                        TerrainOffset = -0.5f,
                        Topology      = 2048,
                        Splat         = 128,
                        Start         = flag1,
                        End           = flag2
                    });
                }
                vector3List.Clear();
            }
        }
        foreach (PathList pathList in pathListList)
        {
            pathList.Path.Smoothen(2);
        }
        TerrainMeta.Path.Roads.AddRange((IEnumerable <PathList>)pathListList);
    }
Пример #26
0
    public override void Process(uint seed)
    {
        if (World.Networked || World.Size < MinWorldSize)
        {
            return;
        }
        int[,] array = TerrainPath.CreateRoadCostmap(ref seed);
        PathFinder      pathFinder = new PathFinder(array);
        int             length     = array.GetLength(0);
        int             num        = length / 4;
        int             num2       = 4;
        int             stepcount  = num / num2;
        int             num3       = length / 2;
        int             pos_x      = num;
        int             pos_x2     = length - num;
        int             pos_y      = num;
        int             pos_y2     = length - num;
        int             num4       = 0;
        int             dir_x      = -num2;
        int             dir_x2     = num2;
        int             dir_y      = -num2;
        int             dir_y2     = num2;
        List <RingNode> list       = ((World.Size >= 5000) ? new List <RingNode>
        {
            new RingNode(num3, pos_y2, num4, dir_y, stepcount),
            new RingNode(pos_x2, pos_y2, dir_x, dir_y, stepcount),
            new RingNode(pos_x2, num3, dir_x, num4, stepcount),
            new RingNode(pos_x2, pos_y, dir_x, dir_y2, stepcount),
            new RingNode(num3, pos_y, num4, dir_y2, stepcount),
            new RingNode(pos_x, pos_y, dir_x2, dir_y2, stepcount),
            new RingNode(pos_x, num3, dir_x2, num4, stepcount),
            new RingNode(pos_x, pos_y2, dir_x2, dir_y, stepcount)
        } : new List <RingNode>
        {
            new RingNode(pos_x2, pos_y2, dir_x, dir_y, stepcount),
            new RingNode(pos_x2, pos_y, dir_x, dir_y2, stepcount),
            new RingNode(pos_x, pos_y, dir_x2, dir_y2, stepcount),
            new RingNode(pos_x, pos_y2, dir_x2, dir_y, stepcount)
        });

        for (int i = 0; i < list.Count; i++)
        {
            RingNode ringNode = list[i];
            RingNode next     = list[(i + 1) % list.Count];
            RingNode prev     = list[(i - 1 + list.Count) % list.Count];
            ringNode.next = next;
            ringNode.prev = prev;
            while (!pathFinder.IsWalkable(ringNode.position))
            {
                if (ringNode.attempts <= 0)
                {
                    return;
                }
                ringNode.position += ringNode.direction;
                ringNode.attempts--;
            }
        }
        foreach (RingNode item in list)
        {
            item.path = pathFinder.FindPath(item.position, item.next.position, 250000);
        }
        bool flag = false;

        while (!flag)
        {
            flag = true;
            PathFinder.Point point = new PathFinder.Point(0, 0);
            foreach (RingNode item2 in list)
            {
                point += item2.position;
            }
            point /= list.Count;
            float    num5      = float.MinValue;
            RingNode ringNode2 = null;
            foreach (RingNode item3 in list)
            {
                if (item3.path == null)
                {
                    float num6 = new Vector2(item3.position.x - point.x, item3.position.y - point.y).magnitude;
                    if (item3.prev.path == null)
                    {
                        num6 *= 1.5f;
                    }
                    if (num6 > num5)
                    {
                        num5      = num6;
                        ringNode2 = item3;
                    }
                }
            }
            if (ringNode2 == null)
            {
                continue;
            }
            do
            {
                if (ringNode2.attempts <= 0)
                {
                    return;
                }
                ringNode2.position += ringNode2.direction;
                ringNode2.attempts--;
            }while (!pathFinder.IsWalkable(ringNode2.position));
            ringNode2.path      = pathFinder.FindPath(ringNode2.position, ringNode2.next.position, 250000);
            ringNode2.prev.path = pathFinder.FindPath(ringNode2.prev.position, ringNode2.position, 250000);
            flag = false;
        }
        if (!flag)
        {
            return;
        }
        for (int j = 0; j < list.Count; j++)
        {
            RingNode ringNode3 = list[j];
            RingNode ringNode4 = list[(j + 1) % list.Count];
            for (PathFinder.Node node = ringNode3.path; node != null; node = node.next)
            {
                for (PathFinder.Node node2 = ringNode4.path; node2 != null; node2 = node2.next)
                {
                    if (Mathf.Abs(node.point.x - node2.point.x) <= 1 && Mathf.Abs(node.point.y - node2.point.y) <= 1)
                    {
                        node.next      = null;
                        ringNode4.path = node2;
                        break;
                    }
                }
            }
        }
        PathFinder.Node node3 = null;
        PathFinder.Node node4 = null;
        foreach (RingNode item4 in list)
        {
            if (node3 == null)
            {
                node3 = item4.path;
                node4 = item4.path;
            }
            else
            {
                node4.next = item4.path;
            }
            while (node4.next != null)
            {
                node4 = node4.next;
            }
        }
        node4.next = new PathFinder.Node(node3.point, node3.cost, node3.heuristic);
        List <Vector3> list2 = new List <Vector3>();

        for (PathFinder.Node node5 = node3; node5 != null; node5 = node5.next)
        {
            float normX = ((float)node5.point.x + 0.5f) / (float)length;
            float normZ = ((float)node5.point.y + 0.5f) / (float)length;
            float x     = TerrainMeta.DenormalizeX(normX);
            float z     = TerrainMeta.DenormalizeZ(normZ);
            float y     = Mathf.Max(TerrainMeta.HeightMap.GetHeight(normX, normZ), 1f);
            list2.Add(new Vector3(x, y, z));
        }
        if (list2.Count >= 2)
        {
            int      count    = TerrainMeta.Path.Roads.Count;
            PathList pathList = new PathList("Road " + count, list2.ToArray());
            pathList.Width            = 12f;
            pathList.InnerPadding     = 1f;
            pathList.OuterPadding     = 1f;
            pathList.InnerFade        = 1f;
            pathList.OuterFade        = 8f;
            pathList.RandomScale      = 0.75f;
            pathList.MeshOffset       = 0f;
            pathList.TerrainOffset    = -0.125f;
            pathList.Topology         = 2048;
            pathList.Splat            = 128;
            pathList.Start            = false;
            pathList.End              = false;
            pathList.ProcgenStartNode = node3;
            pathList.ProcgenEndNode   = node4;
            pathList.Path.Smoothen(4);
            pathList.Path.RecalculateTangents();
            pathList.AdjustPlacementMap(24f);
            TerrainMeta.Path.Roads.Add(pathList);
        }
    }
Пример #27
0
    public override void Process(uint seed)
    {
        if (World.Networked)
        {
            TerrainMeta.Path.Roads.Clear();
            TerrainMeta.Path.Roads.AddRange(World.GetPaths("Road"));
            return;
        }
        List <PathList> list = new List <PathList>();

        int[,] array = TerrainPath.CreateRoadCostmap(ref seed);
        PathFinder              pathFinder = new PathFinder(array);
        int                     length     = array.GetLength(0);
        List <PathSegment>      list2      = new List <PathSegment>();
        List <PathNode>         list3      = new List <PathNode>();
        List <PathNode>         list4      = new List <PathNode>();
        List <PathNode>         list5      = new List <PathNode>();
        List <PathFinder.Point> list6      = new List <PathFinder.Point>();
        List <PathFinder.Point> list7      = new List <PathFinder.Point>();
        List <PathFinder.Point> list8      = new List <PathFinder.Point>();

        foreach (PathList road in TerrainMeta.Path.Roads)
        {
            if (road.ProcgenStartNode == null || road.ProcgenEndNode == null)
            {
                continue;
            }
            int num = 1;
            for (PathFinder.Node node4 = road.ProcgenStartNode; node4 != null; node4 = node4.next)
            {
                if (num % 8 == 0)
                {
                    list6.Add(node4.point);
                }
                num++;
            }
        }
        foreach (MonumentInfo monument in TerrainMeta.Path.Monuments)
        {
            if (monument.Type == MonumentType.Roadside)
            {
                continue;
            }
            TerrainPathConnect[] componentsInChildren = monument.GetComponentsInChildren <TerrainPathConnect>(true);
            foreach (TerrainPathConnect terrainPathConnect in componentsInChildren)
            {
                if (terrainPathConnect.Type == RoadType)
                {
                    PathFinder.Point pathFinderPoint = terrainPathConnect.GetPathFinderPoint(length);
                    PathFinder.Node  node5           = pathFinder.FindClosestWalkable(pathFinderPoint, 100000);
                    if (node5 != null)
                    {
                        PathNode pathNode = new PathNode();
                        pathNode.monument = monument;
                        pathNode.target   = terrainPathConnect;
                        pathNode.node     = node5;
                        list4.Add(pathNode);
                    }
                }
            }
        }
        while (list4.Count != 0 || list5.Count != 0)
        {
            if (list4.Count == 0)
            {
                PathNode node3 = list5[0];
                list4.AddRange(list5.Where((PathNode x) => x.monument == node3.monument));
                list5.RemoveAll((PathNode x) => x.monument == node3.monument);
                pathFinder.PushPoint      = node3.monument.GetPathFinderPoint(length);
                pathFinder.PushRadius     = node3.monument.GetPathFinderRadius(length);
                pathFinder.PushDistance   = 40;
                pathFinder.PushMultiplier = 1;
            }
            list8.Clear();
            list8.AddRange(list4.Select((PathNode x) => x.node.point));
            list7.Clear();
            list7.AddRange(list3.Select((PathNode x) => x.node.point));
            list7.AddRange(list5.Select((PathNode x) => x.node.point));
            list7.AddRange(list6);
            PathFinder.Node node6 = pathFinder.FindPathUndirected(list7, list8, 100000);
            if (node6 == null)
            {
                PathNode node2 = list4[0];
                list5.AddRange(list4.Where((PathNode x) => x.monument == node2.monument));
                list4.RemoveAll((PathNode x) => x.monument == node2.monument);
                list5.Remove(node2);
                list3.Add(node2);
                continue;
            }
            PathSegment segment = new PathSegment();
            for (PathFinder.Node node7 = node6; node7 != null; node7 = node7.next)
            {
                if (node7 == node6)
                {
                    segment.start = node7;
                }
                if (node7.next == null)
                {
                    segment.end = node7;
                }
            }
            list2.Add(segment);
            PathNode node = list4.Find((PathNode x) => x.node.point == segment.start.point || x.node.point == segment.end.point);
            list5.AddRange(list4.Where((PathNode x) => x.monument == node.monument));
            list4.RemoveAll((PathNode x) => x.monument == node.monument);
            list5.Remove(node);
            list3.Add(node);
            PathNode pathNode2 = list5.Find((PathNode x) => x.node.point == segment.start.point || x.node.point == segment.end.point);
            if (pathNode2 != null)
            {
                list5.Remove(pathNode2);
                list3.Add(pathNode2);
            }
            int num2 = 1;
            for (PathFinder.Node node8 = node6; node8 != null; node8 = node8.next)
            {
                if (num2 % 8 == 0)
                {
                    list6.Add(node8.point);
                }
                num2++;
            }
        }
        foreach (PathNode target in list3)
        {
            PathSegment pathSegment = list2.Find((PathSegment x) => x.start.point == target.node.point || x.end.point == target.node.point);
            if (pathSegment != null)
            {
                if (pathSegment.start.point == target.node.point)
                {
                    PathFinder.Node node9 = target.node;
                    PathFinder.Node start = pathFinder.Reverse(target.node);
                    node9.next         = pathSegment.start;
                    pathSegment.start  = start;
                    pathSegment.origin = target.target;
                }
                else if (pathSegment.end.point == target.node.point)
                {
                    pathSegment.end.next = target.node;
                    pathSegment.end      = pathFinder.FindEnd(target.node);
                    pathSegment.target   = target.target;
                }
            }
        }
        List <Vector3> list9 = new List <Vector3>();

        foreach (PathSegment item in list2)
        {
            bool start2 = false;
            bool end    = false;
            for (PathFinder.Node node10 = item.start; node10 != null; node10 = node10.next)
            {
                float normX = ((float)node10.point.x + 0.5f) / (float)length;
                float normZ = ((float)node10.point.y + 0.5f) / (float)length;
                if (item.start == node10 && item.origin != null)
                {
                    start2 = true;
                    normX  = TerrainMeta.NormalizeX(item.origin.transform.position.x);
                    normZ  = TerrainMeta.NormalizeZ(item.origin.transform.position.z);
                }
                else if (item.end == node10 && item.target != null)
                {
                    end   = true;
                    normX = TerrainMeta.NormalizeX(item.target.transform.position.x);
                    normZ = TerrainMeta.NormalizeZ(item.target.transform.position.z);
                }
                float x2 = TerrainMeta.DenormalizeX(normX);
                float z  = TerrainMeta.DenormalizeZ(normZ);
                float y  = Mathf.Max(TerrainMeta.HeightMap.GetHeight(normX, normZ), 1f);
                list9.Add(new Vector3(x2, y, z));
            }
            if (list9.Count != 0)
            {
                if (list9.Count >= 2)
                {
                    int      number   = TerrainMeta.Path.Roads.Count + list.Count;
                    PathList pathList = CreateSegment(number, list9.ToArray());
                    pathList.Start            = start2;
                    pathList.End              = end;
                    pathList.ProcgenStartNode = item.start;
                    pathList.ProcgenEndNode   = item.end;
                    list.Add(pathList);
                }
                list9.Clear();
            }
        }
        foreach (PathList item2 in list)
        {
            item2.Path.Smoothen(4);
            item2.Path.RecalculateTangents();
            item2.AdjustPlacementMap(item2.Width * 2f);
        }
        TerrainMeta.Path.Roads.AddRange(list);
    }
Пример #28
0
    protected override void ApplySplat(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if ((double)this.Radius == 0.0)
        {
            this.Radius = (float)this.extents.x;
        }
        bool should0 = this.ShouldSplat(1);
        bool should1 = this.ShouldSplat(2);
        bool should2 = this.ShouldSplat(4);
        bool should3 = this.ShouldSplat(8);
        bool should4 = this.ShouldSplat(16);
        bool should5 = this.ShouldSplat(32);
        bool should6 = this.ShouldSplat(64);
        bool should7 = this.ShouldSplat(128);

        if (!should0 && !should1 && (!should2 && !should3) && (!should4 && !should5 && (!should6 && !should7)))
        {
            return;
        }
        TextureData splat0data = new TextureData(this.splatmap0);
        TextureData splat1data = new TextureData(this.splatmap1);

        TerrainMeta.SplatMap.ForEachParallel(((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(-this.Radius, 0.0f, -this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(this.Radius, 0.0f, -this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(-this.Radius, 0.0f, this.Radius))), ((Matrix4x4) ref localToWorld).MultiplyPoint3x4(Vector3.op_Addition(this.offset, new Vector3(this.Radius, 0.0f, this.Radius))), (Action <int, int>)((x, z) =>
        {
            GenerateCliffSplat.Process(x, z);
            float normZ = TerrainMeta.SplatMap.Coordinate(z);
            float normX = TerrainMeta.SplatMap.Coordinate(x);
            Vector3 vector3_1;
            ((Vector3) ref vector3_1).\u002Ector(TerrainMeta.DenormalizeX(normX), 0.0f, TerrainMeta.DenormalizeZ(normZ));
            Vector3 vector3_2 = Vector3.op_Subtraction(((Matrix4x4) ref worldToLocal).MultiplyPoint3x4(vector3_1), this.offset);
            float opacity     = Mathf.InverseLerp(this.Radius, this.Radius - this.Fade + Noise.Billow((float)vector3_1.x, (float)vector3_1.z, 4, 0.005f, 0.25f * this.Fade, 2f, 0.5f), Vector3Ex.Magnitude2D(vector3_2));
            if ((double)opacity == 0.0)
            {
                return;
            }
            Vector4 interpolatedVector1 = splat0data.GetInterpolatedVector((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z));
            Vector4 interpolatedVector2 = splat1data.GetInterpolatedVector((float)((vector3_2.x + this.extents.x) / this.size.x), (float)((vector3_2.z + this.extents.z) / this.size.z));
            if (!should0)
            {
                interpolatedVector1.x = (__Null)0.0;
            }
            if (!should1)
            {
                interpolatedVector1.y = (__Null)0.0;
            }
            if (!should2)
            {
                interpolatedVector1.z = (__Null)0.0;
            }
            if (!should3)
            {
                interpolatedVector1.w = (__Null)0.0;
            }
            if (!should4)
            {
                interpolatedVector2.x = (__Null)0.0;
            }
            if (!should5)
            {
                interpolatedVector2.y = (__Null)0.0;
            }
            if (!should6)
            {
                interpolatedVector2.z = (__Null)0.0;
            }
            if (!should7)
            {
                interpolatedVector2.w = (__Null)0.0;
            }
            TerrainMeta.SplatMap.SetSplatRaw(x, z, interpolatedVector1, interpolatedVector2, opacity);
        }));
    }
Пример #29
0
    protected override void ApplySplat(Matrix4x4 localToWorld, Matrix4x4 worldToLocal)
    {
        if (this.Radius == 0f)
        {
            this.Radius = this.extents.x;
        }
        bool flag  = base.ShouldSplat(1);
        bool flag1 = base.ShouldSplat(2);
        bool flag2 = base.ShouldSplat(4);
        bool flag3 = base.ShouldSplat(8);
        bool flag4 = base.ShouldSplat(16);
        bool flag5 = base.ShouldSplat(32);
        bool flag6 = base.ShouldSplat(64);
        bool flag7 = base.ShouldSplat(128);

        if (!flag && !flag1 && !flag2 && !flag3 && !flag4 && !flag5 && !flag6 && !flag7)
        {
            return;
        }
        TextureData textureDatum  = new TextureData(this.splatmap0);
        TextureData textureDatum1 = new TextureData(this.splatmap1);
        Vector3     vector32      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.Radius, 0f, -this.Radius));
        Vector3     vector33      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.Radius, 0f, -this.Radius));
        Vector3     vector34      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(-this.Radius, 0f, this.Radius));
        Vector3     vector35      = localToWorld.MultiplyPoint3x4(this.offset + new Vector3(this.Radius, 0f, this.Radius));

        TerrainMeta.SplatMap.ForEachParallel(vector32, vector33, vector34, vector35, (int x, int z) => {
            GenerateCliffSplat.Process(x, z);
            float single     = TerrainMeta.SplatMap.Coordinate(z);
            Vector3 vector3  = new Vector3(TerrainMeta.DenormalizeX(TerrainMeta.SplatMap.Coordinate(x)), 0f, TerrainMeta.DenormalizeZ(single));
            Vector3 vector31 = worldToLocal.MultiplyPoint3x4(vector3) - this.offset;
            float single1    = Noise.Billow(vector3.x, vector3.z, 4, 0.005f, 0.25f * this.Fade, 2f, 0.5f);
            float single2    = Mathf.InverseLerp(this.Radius, this.Radius - this.Fade + single1, vector31.Magnitude2D());
            if (single2 == 0f)
            {
                return;
            }
            Vector4 interpolatedVector = textureDatum.GetInterpolatedVector((vector31.x + this.extents.x) / this.size.x, (vector31.z + this.extents.z) / this.size.z);
            Vector4 vector4            = textureDatum1.GetInterpolatedVector((vector31.x + this.extents.x) / this.size.x, (vector31.z + this.extents.z) / this.size.z);
            if (!flag)
            {
                interpolatedVector.x = 0f;
            }
            if (!flag1)
            {
                interpolatedVector.y = 0f;
            }
            if (!flag2)
            {
                interpolatedVector.z = 0f;
            }
            if (!flag3)
            {
                interpolatedVector.w = 0f;
            }
            if (!flag4)
            {
                vector4.x = 0f;
            }
            if (!flag5)
            {
                vector4.y = 0f;
            }
            if (!flag6)
            {
                vector4.z = 0f;
            }
            if (!flag7)
            {
                vector4.w = 0f;
            }
            TerrainMeta.SplatMap.SetSplatRaw(x, z, interpolatedVector, vector4, single2);
        });
    }