Esempio n. 1
0
        // async stuff
        public void noiseAsyncFunc(Params par)
        {
            NoiseParams pa = (NoiseParams)par;
            // adjusted for global position
            Vector3 n = new Vector3(pa.p.x + this.Loc.x, pa.p.y + this.Loc.z);

            float height = genNoise(n, this.Method);

            // apply maske
            height = MeshLib.Mask.Transform(pa.p, height, pa.mask);

            // readjust height to find color
            Color newColor = this.Coloring.Evaluate(height + 0.5f);

            this.Colors [pa.v]     = newColor;
            this.Vertices [pa.v].y = height;

            if (pa.v == this.MeshCount - 1)
            {
                this.Mesh.vertices = this.Vertices;
                this.Mesh.colors   = this.Colors;
                this.Mesh.RecalculateNormals();

                this.finished = true;
            }
        }
Esempio n. 2
0
        //==============================================
        // Originally taken from TerrainCreatorScript

        public void renderTerrain(MaskMethod mask = null, Gradient coloring = null)
        {
            if (this.Mesh == null)
            {
                Debug.LogError("[GenericTerrain] Mesh should not be null!!!");
                return;
            }

            _debug("[renderTerrain] about to determine the vertices and colors for the terrain.");

            // get constants
            Vector3[] vecs = MeshUtil.Constants.UnitVectors2D;

            // extract parameters
            float dx = 1f / resolution;

            if (coloring == null)
            {
                coloring = Coloring;
            }

            // counter for vertices
            int v = 0;

            Colors   = this.Mesh.colors;
            Vertices = this.Mesh.vertices;

            for (int i = 0; i <= resolution; i++)
            {
                Vector3 p0 = Vector3.Lerp(vecs [0], vecs [2], i * dx);
                Vector3 p1 = Vector3.Lerp(vecs [1], vecs [3], i * dx);

                for (int j = 0; j <= resolution; j++)
                {
                    // localposition
                    Vector3 p = Vector3.Lerp(p0, p1, j * dx);

                    NoiseParams par = new NoiseParams {
                        p    = p,
                        v    = v,
                        mask = mask,
                    };

                    if (optimize)
                    {
                        OptController.RegisterTask(new Job {
                            func = noiseAsyncFunc,
                            par  = par,
                        });
                    }
                    else
                    {
                        noiseAsyncFunc(par);
                    }

                    v++;
                }
            }

            Debug.Log("Registered all tasks: " + OptController.jobQueue.Count.ToString());

            this.Texture.fill();
        }