- Home /
Optimization and generating terrains
If I were to generate a terrain at runtime using a random terrain generator using 1 meter cubes (similar to Minecraft), would it be possible to optimize it enough to render without freezing the computer?
What if I wanted to be able to access each individual cube?
Answer by Eric5h5 · Nov 22, 2010 at 04:06 AM
Use the Mesh class to construct the terrain. See this topic about Minecraft-like terrains.
Answer by ckfinite · Nov 22, 2010 at 03:08 AM
You could use a 3D array (in C# T[,,] (where T is type)) to store the block values. To the best of my knowledge, this is how Minecraft does it. As for optimization, that is tricker. As far as I am aware, Minecraft does it by figuring out which faces are exposed to water, air, glass, or something transparent. I think this is done in the loading screens, and was the cause of the weirdness when sand fell on you. Because of this, Unity might not be your best choice. Using OpenGL (see the OpenTK project) directly might be your best choice, since Unity does not like drawing faces on the framebuffer directly.
Using OpenGL directly won't gain you anything except a lot of pain (unless you like program$$anonymous$$g your own engines of course ;) ). You can just use the $$anonymous$$esh class in Unity.
Yes, OpenGL is really painful and difficult, but for this application, not as hard as normal, since almost no shaders are nessacary. I had not ran into the $$anonymous$$esh class before, but it looks like it might work. It might get clunky with caves and chunks though, and being able to delete blocks might be difficult.
Not any more so than doing it with OpenGL; you have to update your data structures in either case. Plus you have the entire rest of your game to think about.