Beispiel #1
0
        public void MakeCavesque()
        {
            marchingGrid.CopyTo(ref marchingGridCopy);
            float val;
            bool  randomize;

            for (int i = 0; i < marchingGrid.width; i++)
            {
                for (int f = 0; f < marchingGrid.height; f++)
                {
                    for (int g = 0; g < marchingGrid.depth; g++)
                    {
                        randomize = false;
                        val       = marchingGrid.Get(i, f, g);
                        //if(val==1&& marchingGridCopy.AdjEdges(i, f, g) == 0) { randomize = true; }
                        if (val == 1 && marchingGrid.AdjEdges(i, f, g) == 0 && marchingGrid.Adg(i, f, g, 0) > 0)
                        {
                            randomize = true;
                        }
                        //if (val == 0 && marchingGridCopy.Adg(i, f, g, 1) > 0) { randomize = true; }
                        if (randomize)
                        {
                            val = Random.Range(0.0f, 1.0f);
                            //Debug.Log(val);
                            marchingGridCopy.Set(i, f, g, val);
                        }
                    }
                }
            }
            marchingGridCopy.CopyTo(ref marchingGrid);
        }
Beispiel #2
0
        public Chunk



            (int x, int y, int z, int width, ref Grid3f copyGrid)
        {
            position     = new Vector3(x, y, z);
            marchingGrid = new Grid3f(width);
            for (int i = 0; i < width; i++)
            {
                for (int f = 0; f < width; f++)
                {
                    for (int g = 0; g < width; g++)
                    {
                        if (copyGrid.OnGrid(x + i, y + f, z + g))
                        {
                            val = copyGrid.Get(x + i, y + f, z + g);
                        }
                        else
                        {
                            val = 1;
                        }
                        marchingGrid.Set(i, f, g, val);
                    }
                }
            }
        }
Beispiel #3
0
        public void SmoothMesh(float smoothness)
        {
            float val;

            for (int i = 0; i < marchingGrid.width; i++)
            {
                for (int f = 0; f < marchingGrid.height; f++)
                {
                    for (int g = 0; g < marchingGrid.depth; g++)
                    {
                        //marchingGrid.Set(i, f, g, marchingGridCopy.GetRegionAverage(i - 1, f - 1, g - 1, 3, 3, 3));
                        val = marchingGridCopy.Get(i, f, g);
                        if (val != 0 && val != 1)
                        {
                            val = Mathf.Lerp(val, marchingGridCopy.GetRegionAverage(i - 1, f - 1, g - 1, 3, 3, 3), smoothness);
                            //marchingGrid.Set(i, f, g, (marchingGridCopy.GetRegionAverage(i - 1, f - 1, g - 1, 3, 3, 3)+marchingGridCopy.Get(i,f,g))/2) ;
                            marchingGrid.Set(i, f, g, val);
                        }
                    }
                }
            }
        }
Beispiel #4
0
 public void CopyToMarching(ref Grid3f grid)
 {
     for (int i = 0; i < width; i++)
     {
         for (int f = 0; f < height; f++)
         {
             for (int g = 0; g < depth; g++)
             {
                 if (Get(i, f, g) == 0)
                 {
                     grid.Set(i, f, g, 1);
                     grid.Set(i, f + 1, g, 1);
                     grid.Set(i, f, g + 1, 1);
                     grid.Set(i, f + 1, g + 1, 1);
                     grid.Set(i + 1, f, g, 1);
                     grid.Set(i + 1, f + 1, g, 1);
                     grid.Set(i + 1, f, g + 1, 1);
                     grid.Set(i + 1, f + 1, g + 1, 1);
                 }
             }
         }
     }
 }