It is currently Wed Nov 20, 2019 12:48 pm


All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: SanquiryVoxel ( Procedural Generation ) with cubiquity
PostPosted: Sun Sep 25, 2016 8:38 am 
User avatar

Joined: Tue Sep 20, 2016 8:51 pm
Posts: 6
Location: Utah
SanquiryVoxel ( Procedural Generation ) with cubiquity

Taking alot of memories working with these and remember how many headaches because of overly complication of tese....

I will be on and gone for a long time ... so I will leave you with my last script for generation .....

Til...

*Nothing fancy with brushes , but add a few more .... functions tweak this that...
All there is a sphere brush but!!!
Add a new color instead of the quant 0000
Then we have alot of other things going on...
Magica voxel ... I wanted to get into ....

With trees....
Maybe...

When you go under the huge block there are brushes visible which is suppose to happen ...
if you want caves....... so give the range a bigger number... and more hole brushes you got something cool trust me.... and make a square brushes.

and yes I need higher clifffys



but this a good start the only problem i'm having personally...

Is the load time.... I know you guys were not exactly planning on random proc.

However hopefully sos...

You can help me with asynching this in chunks... I know it says not to .. I could do this by mapping objects......... but not exactly ... the best plan... because there is no way its killing cubes that fast without it already containing chunks..... but the loading time eats eats... I need to be able to load the rendering on the fly of position some how..... it's very hard... I tryed messing with the max sync values it did not help......

?!Maybe I will be back and some kind gentlemen or david will pick on me with this one.

Image
Code:
using UnityEngine;
using System.Collections;

using Cubiquity;
using UnityEngine.UI;



//[ExecuteInEditMode]

public class ProceduralColoredCubes : MonoBehaviour {

   public int width = 128;
   public int height = 32;
   public int depth = 128;

   QuantizedColor green = new QuantizedColor(18, 115, 38, 255);
   QuantizedColor brown = new QuantizedColor(115, 87, 18, 255);
   QuantizedColor gray = new QuantizedColor(127, 127, 127, 255);

   QuantizedColor drkgry = new QuantizedColor(92, 90, 90, 255);
   QuantizedColor white = new QuantizedColor(255, 255, 255, 255);

   QuantizedColor[] rockColor;
   ColoredCubesVolumeData data;
   ColoredCubesVolume volume;
   ColoredCubesVolumeRenderer volumeRenderer;

   public int DiceRollMax = 100;
   private Text LoadingObject;
   private int loadP = 0;

   // Use this for initialization
   void Start () {

      //LoadingObject = GameObject.FindGameObjectWithTag ("Loading").GetComponent<Text> ();
      //LoadingObject.text = "Loading: 0 ";


      // FIXME - Where should we delete this?
      /// [DoxygenSnippet-CreateEmptyTerrainVolumeData]
      //Create an empty TerrainVolumeData with dimensions width * height * depth

      //ColoredCubesVolumeData data = VolumeData.CreateEmptyVolumeData<ColoredCubesVolumeData>(new Region(0, 0, 0, width-1, height-1, depth-1));
      /// [DoxygenSnippet-CreateEmptyTerrainVolumeData]
      ///
      ///



      data = VolumeData.CreateEmptyVolumeData<ColoredCubesVolumeData>(new Region(0, 0, 0, width-1, height-1, depth-1));

       volume = GetComponent<ColoredCubesVolume>();
       volumeRenderer = GetComponent<ColoredCubesVolumeRenderer>();

      volume.data = data;

      // Defines colors for each cubic square.
      rockColor = new QuantizedColor[2];
      rockColor[0] = gray;
      rockColor [1] = drkgry;


      float rockScale = 0.01F ;      
      float randomSeed = Random.Range (-0.05F, 0.05F);

      // Iterate over every voxel of our volume
      for (int z = 0; z < depth; z++)
      {
         loadP += z;
         //LoadingObject.text = "Loading: " + loadP.ToString();
         for (int y = height - 1; y > 0; y--)
         {
            loadP += y;
            //LoadingObject.text = "Loading: " + loadP.ToString();
            for (int x = 0; x < width; x++)
            {
               loadP += z;

               float sampleX = (float)x * rockScale;
               float sampleY = (float)y * rockScale;
               float sampleZ = (float)z * rockScale;

               QuantizedColor rockChangeColor = rockColor [Random.Range (0, 2)];

               float simplexNoiseValue = SimplexNoise.Noise.Generate(sampleX, sampleY, sampleZ);
               //float simplexNoiseValue2 = SimplexNoise.Noise.Generate(sampleX, sampleY, sampleZ);


               float altitude = (float)(y + 0.05F) / (float)height;
               //float altitude2 = (float)(y + 0.02f) / (float)height;
            
               // Map the altitude to the range -1.0 to +1.0..


               altitude = (altitude * simplexNoiseValue) - randomSeed;
               //altitude2 = (altitude * simplexNoiseValue) - randomSeed;


               simplexNoiseValue -= altitude;
               //simplexNoiseValue2 -= altitude2;
               //float simplexNoiseValue -= SimplexNoise.Noise.Generate(sampleX, sampleY, sampleZ);


               //simplexNoiseValue *= 0.5f;
               simplexNoiseValue = Mathf.Clamp(simplexNoiseValue, -0.005f, 0.05f);
               //simplexNoiseValue2 =  Mathf.Clamp(simplexNoiseValue2, -0.005f, 0.05f);

               simplexNoiseValue *= 15;
               //simplexNoiseValue2 *= 15;

               int simplexCubicValue = Mathf.RoundToInt (simplexNoiseValue);
            


               //data.SetVoxel(x* simplexCubicValue  , y * simplexCubicValue , z* simplexCubicValue  , green);
               if(y < height-1)
               {
                  // Add to bedrock material channel.
                  data.SetVoxel(x* simplexCubicValue  , y * simplexCubicValue , z* simplexCubicValue  , white);
                  //data.SetVoxel(x  , y   , z   , green);
               }
               if(y < height-8)
               {
                  // Add to bedrock material channel.
                  data.SetVoxel(x* simplexCubicValue  , y * simplexCubicValue , z* simplexCubicValue  , rockChangeColor);
                  //data.SetVoxel(x  , y   , z   , green);
               }

               if(y <  height-62)
               {
                  // Add to bedrock material channel.
                  data.SetVoxel(x* simplexCubicValue  , y * simplexCubicValue , z* simplexCubicValue  , brown);
                  //data.SetVoxel(x  , y   , z   , brown);

               }

               if(y < height-28)
               {
                  // Add to bedrock material channel.
                  //data.SetVoxel(x* simplexCubicValue  , y * simplexCubicValue , z* simplexCubicValue  , green);
                  data.SetVoxel(x  , y   , z   , green);
               }
               if(y < height-30)
               {
                  // Add to bedrock material channel.
                  //data.SetVoxel(x* simplexCubicValue  , y * simplexCubicValue , z* simplexCubicValue  , green);
                  data.SetVoxel(x  , y   , z   , brown);
               }
               //data.SetVoxel(x* simplexCubicValue  , y * simplexCubicValue  , z* simplexCubicValue   , new QuantizedColor(0,0,0,0));




               //data.SetVoxel(x* simplexCubicValue  , y * simplexCubicValue , z* simplexCubicValue , new QuantizedColor(0,0,0,0));
            }

         }
         //LoadingObject.text = "Loading: " + loadP.ToString();

      }//End the loop of voxeling
   
      Vector3 bPos = new Vector3 (0,0,0);

      //Brush loops
      int k = 1;
      int ix = 0;
      int iy = 0;
      int iz = 0;
      while (k < 100+Random.Range(10,DiceRollMax)) {
         /*
         for (int iz = 0; iz + 20 < Random.RandomRange ((int)1, (int)depth + 1 * 2); iz++) {
            for (int iy = 0; iy + 20 > Random.Range ((int)1, (int)height + 1); iy++) {
               for (int ix = 0; ix + 20 < Random.Range ((int)1, (int)width + 1); ix++) {
                  bPos = new Vector3 (Mathf.RoundToInt (ix), Mathf.RoundToInt (ix), Mathf.RoundToInt (ix));
                  //Debug.Log (bPos);
                  
               }
            }
         */
         ix = Random.Range (0, width);
         iy = Random.Range (0, height);
         iz = Random.Range (0, depth);
         bPos = new Vector3 (ix, iy, iz);

         Sphere ((int)bPos.x, (int)bPos.y, (int)bPos.z, new QuantizedColor (0, 0, 0, 0), 10);
         k++;
      }

   
   }



   void Sphere(int posx, int posy, int posz, QuantizedColor color, int range)
   {
      
      int rangeSquared = range * range;
      // FIXME - Where should we delete this?
      /// [DoxygenSnippet-CreateEmptyTerrainVolumeData]
      //Create an empty TerrainVolumeData with dimensions width * height * depth
      for (int z = posz - range ; z < posz + range  ; z++) {
         for (int y = posy - range ; y < posy + range ; y++) {
            for (int x = posx - range ; x < posx + range ; x++) {         
               
                  int xDistance = x - posx;
                  int yDistance = y - posy;
                  int zDistance = z - posz;
                  int distSquared = xDistance * xDistance + yDistance * yDistance + zDistance * zDistance;
                  if (distSquared < rangeSquared) {   
                     // Working with squared distances avoids costly square root operations.
                     

                     data.SetVoxel (x , y , z , color);
               }
            }
         }
      }
   }


   

}


Top
Offline Profile  
Reply with quote  
 Post subject: Re: SanquiryVoxel ( Procedural Generation ) with cubiquity
PostPosted: Tue Sep 27, 2016 9:44 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
12aithe wrote:
but this a good start the only problem i'm having personally...

Is the load time.... I know you guys were not exactly planning on random proc.


Indeed, procedural generation was unfortunately never the focus of Cubiquity. The most practical option is to generate procedurally offline and then save the results to a .vbd. Of course, this doesn't help if you need to generate on-the-fly.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: SanquiryVoxel ( Procedural Generation ) with cubiquity
PostPosted: Wed Sep 28, 2016 1:00 am 
User avatar

Joined: Tue Sep 20, 2016 8:51 pm
Posts: 6
Location: Utah
True...... Offcourse the maze gen ... and all that can create some different games.... that's refreshing...... writing 100000 or whatever cubes I got to ..... instead of rouge like mazes is a different story .


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net