- Home /
Both way expandable array for voxels
I am looking for solution to create both way expandable 3D array for voxels. For example, when I start creating object from voxels, initial voxel location in array is [0, 0, 0]. When I will add something on the right, top, forward, it works great but it not work when I need to add voxel before initial voxel, because it pointing to negative values what is out of bounds of array. How to solve this?
Answer by Baste · Feb 03, 2015 at 07:59 AM
You'll need a structure that can expand in both directions.
If you have a fixed size game world, just start in the middle of the array. If you need to expand dynamically, you'll have to make a data structure that fits your needs.
The easiest thing would be to make a class containing two arrays, define a custom indexer for the class, and use one of the arrays for negative indexes. It's quick and dirty.
Your answer
![](https://koobas.hobune.stream/wayback/20220613182239im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Reading and Storing External Data into Memory (From Text) 1 Answer
Too large String Array which created from DB 0 Answers
How can I access the variables of arrays with multiple data types? 1 Answer
Lists and Structs instead of Arrays? 4 Answers
How to split 3D array in to two - Breaking voxelized objects. 0 Answers