Vector3 3d array! for voxel Chunks. How to?

Hi guys,

I always think twice before asking a question scouring the web first but I couldn’t find anything related to what I want to achieve. So I am using Craig Perko’s voxel terrain generator (version 1/ old version) found on YouTube to create a minecraft like voxel terrain. A couple of months ago I was able to achieve voxel terrain generation with byte chunks and then a terrain script that stores all info of the chunks in dictionaries. Also the thing was multithreaded and really fast but I want to change my way of doing things now and I have NO clue on how to proceed. I want to spawn chunks normally with a byte array and I want to create an array of bytes that contains the chunk byte array positions or a Vector3 3d or 2d or 1d array that contains the Chunk info. Since we can’t really put negative integers or decimals in an array and that I have no clue on how to initialise a 3d array of Vectors3 than I dont know what to do. Any help is appreciated.

I thought that this below would be sufficient in adding all Vector3s of that loop in the array but I was wrong. Its a bit of a noObie question I suppose but I couldnt really find a good source of info on the web. Thank you in advance for replying.

for (int x = 0; x < 2; x++)
  {
   for (int y = 0; y < 2; y++)
      {
        for (int z = 0; z < 2; z++)
        {
              Vector3[,,] = new Vector3[,,]
              {
                 {
                      {
                         new Vector3[x,y,z]
                      }
                 }
             };
        }
     }
}


}

Craig perko has been saying on stream that he is not fond of people using is voxel video as a tutorial lol, beside that you need a circular 2d array and find the relative position based on a floating origin and the offset to the real origin, transformed back into teh circular array coordinate … XD

oh really as in he wont let people use his voxel generation technique for their own games or? I will start searching for a circular 2d array because i got no clue what it is. Thank you for the fast response Neoshaman and for the tips!

Just circular array but for two indices, I would advise you to read the entire thread of after playing minecraft on the forums:

You will found tuts and some tips

Craig perko just think it’s not the best t learn voxel, it was meant as an overall introduction rather than a tut (if I understood it).

Ok I never got around reading it coz I was lazy and I thought 57 page was too huge to pinpoint exact stuff I was searching for. Im gonna start right now reading it and see what treasures I can find in it.

I tried to study many tutorials on Minecraft and most of them were too complicated for me. I just have 1 year and a half of programming knowlege overall and no complete projects to date. The first tutorial of Craig Perko on YouTube definitely was the starting point of understanding how the whole process worked. The thing I liked about it is it’s in no way huge and complicated (complicated for a noOb like me ) with codes and references to 10+ scripts all over the place. Not to underestimate any other programmers that did Minecraft Tuts but for a noObie like me Craig’s Old minecraft tut was my favorite.

Well that’s maybe why it’s nor working well lol, other cover the remaining part and teh necessary optimization, voxel is not for noob, that’s why it hasn’t been use massively before minecraft lol

You can get away with a simpler version, but you need to define your limit. You can also look at terrain generation for other type of problem (past voxel chunk).

The advantage of the thread is that you see solution emerging as they met them, but some solution get perfected and tested later in the thread, so the progression might be smoother to understand the problem as they struggle with it too! So implement and revise as you progress on the thread lol.

yeah you are right its not for noObs but hehe im giving it a try lol silly me. Just found out this page right here 2D Circular Array - Unity Engine - Unity Discussions about the circular Array and tried it out. I understand the concept but dont understand the coding. Here I go for another couple days trying to get that Under my belt. nope sorry more like weeks hopefully not months. Oh and Ive got to check what the modulo operator means first. Ill be back here or post in the Minecraft thread after reading it through.

The thing is I dont see how flat arrays can handle height. Which is why I was hoping that a function that creates new arrays once the first arrays are filled would kinda resolve my problem. Like in the small array there is 1 small chunk which is the chunk itself. In the medium array there is 4 small chunks. in the large array there is 16 medium chunks…No chunks but the small chunks are created right away when player is near and medium chunks are created when player goes outside of what it is supposed to contain. That would take care of height/width/depth if its a 3d array. But again i probably have no clue of what I am talking about coz maybe flat arrays do handle height. Brb I gotta go back to the drawing board here! :wink: thank you for sharing your knowledge neoshaman!

I’m not sure what you are saying when you say flat array don’t handle height lol, you may or may not mix up concept. Flat array are just another way to enumerate x dimension array, in the machine there is actually no difference in how they are store, they are all adress on ram. Basically when coding try to schema and drawing of what you are trying to achieve. A 2d flat array just emulate the second index by using the regularity of 2d dimensions, let say you have a 6x6 array, it’s a 36 long 1d array, they have the same number of item. so let say it start with 0, the first item of the first row is 0, the first column is 0 and the last item on the same row is 5 (assuming we enumerate item using row first then column), on the second row the first item in the first column is the number 6 and the last item in the last column is 11, etc … you should start to see some regularity, ie that all first column of each row is simply +6 and the last column is always index of row x size of row -1 (-1 becausse we start with 0), so a flat array is equivalent to the enumeration of items in a 2d array. it works the same for 3d array or any number of dimensions. once you figure out the enumeration, finding the equivalence is easy. For example given a flat array of 36, finding the 6x6 2d array index of the 31th item is 31/6 = row n5, 31 mod 6 = column n1.

Thank you by the way. I had kind of forgotten to post back in here. So I’ve kinda managed to to use a single flat array that is pretty much the same as a 3d array but maybe faster but still havent used it that much since im nowhere close testing for performance issues! Thank you Neoshaman for sharing your thoughts and hints. it really helped a lot!

1 Like