Exemplo n.º 1
0
 void Awake()
 {
     TextureController.Init();
     OptController.Init();
     VoronoiNoise.Init();
     tex = new TTexture(Vector3.zero, resolution, (int)size, type);
 }
Exemplo n.º 2
0
        private void InitModules()
        {
            // init everything here so they don't need to be instantiated later
            VoronoiNoise.Init();
            MaterialController.Init();
            TextureController.Init();
            OptController.Init();
            Seeder.Init(islandDensity);

            method = Constants.NoiseFuncs [(int)noiseType];
        }
Exemplo n.º 3
0
        // COMPUTATION HEAVY
        // part of async optimization
        public static void fillTexture(Params par)
        {
            TTextureParams pars = (TTextureParams)par;

            TTexture  t   = pars.texMeta;
            Texture2D tex = pars.tex;

            Vector3 pt = Vector3.zero;

            Color[] colors = tex.GetPixels();

            int v = 0;

            for (int i = 0; i < tex.width; i++)
            {
                for (int j = 0; j < tex.height; j++)
                {
                    pt.x = t.Loc.x + pars.localLoc.x + (float)i / t.resolution;
                    pt.y = t.Loc.z + pars.localLoc.y + (float)j / t.resolution;

                    TextureParams p = new TextureParams {
                        p      = pt,
                        par    = pars,
                        count  = v,
                        colors = colors,
                    };

                    if (optimize)
                    {
                        Job job = new Job {
                            func = textureAsyncFunc,
                            par  = p
                        };
                        newJobs.Add(job);
                    }
                    else
                    {
                        textureAsyncFunc(p);
                    }

                    v++;
                }
            }

            if (optimize)
            {
                OptController.RegisterTasks(newJobs);
            }

            newJobs.Clear();
        }
Exemplo n.º 4
0
        public void fillByTile()
        {
            for (int i = 0; i < density; i++)
            {
                for (int j = 0; j < density; j++)
                {
                    TTextureParams p = new TTextureParams {
                        texMeta  = this,
                        tex      = new Texture2D(resolution, resolution),
                        localLoc = new Vector2(i, j)
                    };

                    Job job = new Job {
                        func = TextureController.fillTexture,
                        par  = p
                    };
                    jobs.Add(job);
                }
            }

            _debug("# of jobs: " + jobs.Count.ToString());
            OptController.RegisterTasks(jobs);
            jobs.Clear();
        }
Exemplo n.º 5
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();
        }