void Update() { //Swap frames, so we update everything at 30 FPS, for descrete voxel space it still nice. //And we have a massive perfomance boost. frame = !frame; if (frame) { //Begin draw. voxelRender.BeginDraw(); //Draw random boxes to static layer. //Random position. int x = Random.Range(0, voxelRender.Width); int y = 0; int z = Random.Range(0, voxelRender.Width); //Random size. int width = Random.Range(1, 10); int height = Random.Range(1, 64); int depth = Random.Range(1, 10); //Random color from palette. byte color = (byte)Random.Range(1, 255); //And put it to static layer. voxelRender.DrawBox(x, y, z, width, height, depth, color, Layer.Static); //End draw, it starts a multithreading geometry building. voxelRender.EndDraw(); } else { //Wait geometry. voxelRender.WaitGeometry(); } }
// Use this for initialization void Start() { //Creat new VoxelRender voxelRender = new VoxelRender(128, 128, 64, 2, 2); //Fill VoxelRender palette with random colors voxelRender.GenerateRandomPalette(); //Create random cubes as level. for (int cube = 0; cube < 128; cube++) { voxelRender.DrawBox(Random.Range(0, 128 * 2), 0, Random.Range(0, 128 * 2), Random.Range(8, 32), Random.Range(4, 24), Random.Range(8, 32), (byte)Random.Range(1, 254), Layer.Static); } }
// Use this for initialization void Start() { //Creat new VoxelRender with 192x192x64 resolution. voxelRender = new VoxelRender(192, 192, 64); //Fill VoxelRender palette with random colors. voxelRender.GenerateRandomPalette(); //Create Ground byte color = 106; for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { voxelRender.DrawBox(x * 12, 0, z * 12, 12, 4, 12, (byte)(color + 8 * ((x + z) % 2)), Layer.Static); } } }