Пример #1
0
    void Update()
    {
        CalculatePoints();
        var m = SphereMeshGenerator.GenerateTerrainMesh(pointsReal);

        mf.sharedMesh = m.CreateMesh();
        //for (int i = 0; i < 18; i++)
        {
            //filters[i].mesh = MakeMesh(i);
            //combine[i].mesh = MakeMesh(i);
        }

        //var m = new Mesh();
        //m.CombineMeshes(combine, true);
        //mf.sharedMesh= m;
    }
Пример #2
0
    void ReadBinaryFile(string fileName, PDSData data)
    {
        _imgData = File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath, $"{fileName}.IMG"));

        float[] floatData = new float[_imgData.Length / 4];
        float[,] floatDataDimensional = new float[data.ColumnCount, data.RowCount];

        for (int y = 0; y < data.RowCount; y++)
        {
            for (int x = 0; x < data.ColumnCount; x++)
            {
                var i = x + Width * y;
                floatData[i] = BitConverter.ToSingle(_imgData, i * 4);
                floatDataDimensional[x, y] = floatData[i];
            }
        }

        var min = floatData.Min();
        var max = floatData.Max();

        print($"min: {min}, max: {max}");
        if (DrawTexture)
        {
            renderer.sharedMaterial = new Material(Shader.Find("Standard"));
            _texture = new Texture2D(data.ColumnCount, data.RowCount, TextureFormat.RGBA32, false);
            for (var y = 0; y < data.RowCount; y++)
            {
                for (var x = 0; x < data.ColumnCount; x++)
                {
                    byte c = (byte)RemapValue(floatDataDimensional[x, y], min, max, 0,
                                              255);

                    var color = new Color32(c, c, c, 255);
                    _texture.SetPixel(x, y, color, 0);
                }
            }

            _texture.Apply();
            renderer.sharedMaterial.mainTexture = _texture;
        }

        if (DrawMesh)
        {
            var verts = new Vector3[data.ColumnCount, data.RowCount];
            print($"width: {verts.GetLength(0)}");
            print($"height: {verts.GetLength(1)}");
            Assert.AreEqual(verts.GetLength(0), Width);
            Assert.AreEqual(verts.GetLength(1), Height);
            for (var y = 0; y < data.RowCount; y++)
            {
                for (var x = 0; x < data.ColumnCount; x++)
                {
                    float z = RemapValue(floatDataDimensional[x, data.RowCount - 1 - y], min, max,
                                         MoonConstants.LowestPointOnTheMoon,
                                         MoonConstants.HighestPointOnTheMoon);
                    verts[x, y] = (new Vector3(x, z, -y) + new Vector3(-data.ColumnCount / 2f, 0, data.RowCount / 2f)) *
                                  (Radius * 2f / data.RowCount);
                }
            }

            var mf = GetComponent <MeshFilter>();
            var mr = GetComponent <MeshRenderer>();
            if (!DrawTexture)
            {
                mr.material = MoonMaterial;
            }

            var d    = SphereMeshGenerator.GenerateTerrainMesh(verts);
            var mesh = d.CreateMesh32Bit();
            mesh          = FlipMesh(mesh);
            mf.sharedMesh = mesh;
        }

        if (DrawChunk)
        {
            var verts = new Vector3[Height, Height];

            for (int i = 0; i < 2; i++)
            {
                for (var y = 0; y < data.RowCount; y++)
                {
                    for (var x = 0; x < data.ColumnCount / 2; x++)
                    {
                        var   offset = i * Height;
                        float z      = RemapValue(floatDataDimensional[x + offset, data.RowCount - 1 - y], min, max,
                                                  MoonConstants.LowestPointOnTheMoon,
                                                  MoonConstants.HighestPointOnTheMoon);
                        verts[x, y] = (new Vector3(x + offset, z, -y) + new Vector3(-data.ColumnCount / 2f, 0, data.RowCount / 2f)) *
                                      (Radius * 2f / data.RowCount);
                    }
                }

                if (i == 0)
                {
                    var a    = SphereMeshGenerator.GenerateTerrainMesh(verts);
                    var mesh = a.CreateMesh32Bit();
                    mesh             = FlipMesh(mesh);
                    meshA.sharedMesh = mesh;
                }
                else
                {
                    var b    = SphereMeshGenerator.GenerateTerrainMesh(verts);
                    var mesh = b.CreateMesh32Bit();
                    mesh             = FlipMesh(mesh);
                    meshB.sharedMesh = mesh;
                }
            }
        }
    }