Пример #1
0
        public void ConstructMesh()
        {
            Vector3[] vertices  = new Vector3[resolution * resolution];
            int[]     triangles = new int[(resolution - 1) * (resolution - 1) * 6];
            int       triIndex  = 0;

            for (int y = 0; y < resolution; y++)
            {
                for (int x = 0; x < resolution; x++)
                {
                    int     i                 = x + y * resolution;
                    Vector2 percent           = new Vector2(x, y) / (resolution - 1);
                    Vector3 pointOnUnitCube   = height + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB;
                    Vector3 pointOnUnitSphere = SphereMaths.UnitCubeToUnitSphere(pointOnUnitCube);
                    vertices[i] = shapeGenerator.CalculatePointOnPlanet(pointOnUnitSphere);

                    if (x != resolution - 1 && y != resolution - 1)
                    {
                        triangles[triIndex]     = i;
                        triangles[triIndex + 1] = i + resolution + 1;
                        triangles[triIndex + 2] = i + resolution;

                        triangles[triIndex + 3] = i;
                        triangles[triIndex + 4] = i + 1;
                        triangles[triIndex + 5] = i + resolution + 1;
                        triIndex += 6;
                    }
                }
            }
            //mesh.Clear();
            mesh.vertices  = vertices;
            mesh.triangles = triangles;
            mesh.RecalculateNormals();
        }
Пример #2
0
        public Chunk(Planet planet, int i, int u, int v, ShapeGenerator shapeGenerator)
        {
            this.shapeGenerator = shapeGenerator;
            this.planet         = planet;
            this.face           = planet.terrainFaces[i];
            this.faceI          = i;
            this.faceU          = u;
            this.faceV          = v;
            this.shapeData      = this.planet.shapeData;

            chunkID = "Chunk " + faceI + " (" + faceU + "," + faceV + ")";

            SetLOD();

            //Centre point
            int ResM1 = chunkResolution - 1;

            float   UVstep = 1f / shapeData.chunksPerFace;
            float   step   = UVstep / ResM1;
            Vector2 offset = new Vector3((-0.5f + faceU * UVstep), (-0.5f + faceV * UVstep));

            int x = chunkResolution / 2;

            Vector2 p = offset + new Vector2(x * step, x * step);
            Vector3 pointOnUnitCube   = face.axisB * p.x + face.axisA * p.y + face.height * -0.5f;
            Vector3 pointOnUnitSphere = SphereMaths.UnitCubeToUnitSphere(pointOnUnitCube);
            Vector3 point             = planet.ShapeGenerator.CalculatePointOnPlanet(pointOnUnitSphere);

            this.centre = GeoCoord.GetLatLon(planet, point);
        }
Пример #3
0
        //Gets a vector for the centre of the chunk.
        public void CalculateCentre(int chunkResolution, float radius)
        {
            float   UVstep = 1f / chunkResolution;
            float   step   = UVstep / (resolution - 1);
            Vector2 offset = new Vector3((-0.5f + faceCoord.u * UVstep), (-0.5f + faceCoord.v * UVstep));

            int x = resolution / 2;

            Vector2 p = offset + new Vector2(x * step, x * step);
            Vector3 pointOnUnitCube   = face.axisB * p.x + face.axisA * p.y + face.axisC * -0.5f;
            Vector3 pointOnUnitSphere = SphereMaths.UnitCubeToUnitSphere(pointOnUnitCube);

            this.centre = pointOnUnitSphere * radius;
            this.latLon = GeoCoord.GetLatLon(planet, centre);
        }