public Chunck(double from, double size, int LODId, CelestialBodyData planet, CelestialBodyData.TerrainData.DetailLevel[] detailLevels, Transform parent, bool forMap, bool offset)
        {
            this.from        = from;
            this.LODId       = LODId;
            this.topSizeHalf = (double)detailLevels[LODId].angularSize / planet.terrainData.unitToAngle * 0.5;
            float num = (float)from / (float)planet.terrainData.heightMaps[0].heightMap.HeightDataArray.Length * 360f + detailLevels[LODId].angularSize * 0.5f;

            this.topPosition                   = new Double3(Math.Cos((double)(num * 0.0174532924f)), Math.Sin((double)(num * 0.0174532924f))) * (planet.radius + planet.terrainData.maxTerrainHeight);
            this.chunckTransform               = UnityEngine.Object.Instantiate <Transform>(Ref.planetManager.chunckPrefab).transform;
            this.chunckTransform.parent        = parent;
            this.chunckTransform.localPosition = Vector3.zero;
            PlanetManager.TerrainPoints terrainPoints = planet.GetTerrainPoints(from, size, detailLevels[LODId].LOD, offset);
            this.GenerateMesh(this.chunckTransform, terrainPoints, this.GenerateIndices(terrainPoints.points.Length), from, 1f / (float)((double)planet.terrainData.heightMaps[0].heightMap.HeightDataArray.Length * detailLevels[LODId].LOD), 1f / (float)detailLevels[LODId].LOD, "Default", 10, planet, forMap);
            if (offset)
            {
                this.chunckPosOffset = terrainPoints.points[0];
            }
        }
        private void GenerateMesh(Transform chunckTrans, PlanetManager.TerrainPoints terrainPoints, int[] indices, double fromForUV, float traingleAngularSizeOf1, float texMultiplier, string sortingLayer, int orderInLayer, CelestialBodyData planet, bool map)
        {
            Mesh mesh = chunckTrans.GetComponent <MeshFilter>().mesh;

            mesh.Clear();
            mesh.vertices  = terrainPoints.points;
            mesh.triangles = indices;
            mesh.RecalculateNormals();
            mesh.RecalculateBounds();
            Vector2[] array = new Vector2[terrainPoints.points.Length];
            for (int i = 0; i < terrainPoints.points.Length - 1; i++)
            {
                array[i + 1] = new Vector2((float)(fromForUV % 10.0) + (float)i * texMultiplier, 0f);
            }
            array[0] = Vector3.up;
            mesh.uv  = array;
            Vector2[] array2 = new Vector2[terrainPoints.points.Length];
            double    num    = fromForUV / (double)((float)planet.terrainData.heightMaps[0].heightMap.HeightDataArray.Length);

            for (int j = 0; j < terrainPoints.points.Length - 1; j++)
            {
                array2[j + 1] = new Vector2((float)num + (float)j * traingleAngularSizeOf1, 1f);
            }
            array2[0] = Vector3.zero;
            mesh.uv2  = array2;
            mesh.uv3  = terrainPoints.uvOthers;
            MeshRenderer component = chunckTrans.GetComponent <MeshRenderer>();

            component.sortingLayerName = sortingLayer;
            component.sortingOrder     = orderInLayer;
            if (map)
            {
                component.material       = planet.terrainData.mapMaterial;
                component.material.color = planet.terrainData.mapColor;
            }
            else
            {
                component.sharedMaterial = planet.terrainData.terrainMaterial;
            }
        }
    public PlanetManager.TerrainPoints GetTerrainPoints(double from, double size, double LOD, bool offset)
    {
        PlanetManager.TerrainPoints terrainPoints = new PlanetManager.TerrainPoints((int)(size * LOD) + 2);
        if (offset)
        {
            double   num            = 6.28319 / (double)this.terrainData.heightMaps[0].heightMap.HeightDataArray.Length / LOD;
            double   num2           = 6.28319 / (double)this.terrainData.heightMaps[0].heightMap.HeightDataArray.Length * from;
            Double3  @double        = new Double3((double)((int)(Math.Cos(num2) * this.radius / 1000.0) * 1000), (double)((int)(Math.Sin(num2) * this.radius / 1000.0) * 1000));
            int      num3           = (int)(size * LOD) + 1;
            double[] terrainSamples = this.GetTerrainSamples(from, LOD, num3 + 1, true);
            for (int i = 0; i < num3; i++)
            {
                double num4 = num2 + (double)i * num;
                terrainPoints.points[i + 1] = new Vector3((float)(Math.Cos(num4) * terrainSamples[i] - @double.x), (float)(Math.Sin(num4) * terrainSamples[i] - @double.y), 0f);
                float x = 0.5f + (float)((terrainSamples[i] - terrainSamples[i + 1]) * LOD * 0.001);
                terrainPoints.uvOthers[i + 1] = new Vector2(x, this.terrainData.texLayer.perlinCurve.Evaluate(Mathf.PerlinNoise((float)(from + (double)i / LOD) * this.terrainData.texLayer.repeatX, 0f)));
            }
            terrainPoints.points[0]   = [email protected];
            terrainPoints.uvOthers[0] = Vector2.zero;
            return(terrainPoints);
        }
        double num5 = 6.28319 / (double)this.terrainData.heightMaps[0].heightMap.HeightDataArray.Length / LOD;
        double num6 = 6.28319 / (double)this.terrainData.heightMaps[0].heightMap.HeightDataArray.Length * from;
        int    num7 = (int)(size * LOD) + 1;

        double[] terrainSamples2 = this.GetTerrainSamples(from, LOD, num7 + 1, true);
        for (int j = 0; j < num7; j++)
        {
            double num8 = (double)j * num5 + num6;
            terrainPoints.points[j + 1] = new Vector3((float)(Math.Cos(num8) * terrainSamples2[j]), (float)(Math.Sin(num8) * terrainSamples2[j]), 0f);
            float x2 = 0.5f + (float)((terrainSamples2[j] - terrainSamples2[j + 1]) * LOD * 0.001);
            terrainPoints.uvOthers[j + 1] = new Vector2(x2, this.terrainData.texLayer.perlinCurve.Evaluate(Mathf.PerlinNoise((float)(from + (double)j / LOD) * this.terrainData.texLayer.repeatX, 0f)));
        }
        terrainPoints.uvOthers[0] = Vector2.zero;
        return(terrainPoints);
    }