Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public uint[] LoadVXL(byte[] bytes)
- {
- uint[] map = new uint[Width*Height*Depth];
- var r = new System.Random();
- int pos = 0;
- for (int y = 0; y < Depth; ++y)
- {
- for (int x = 0; x < Width; ++x)
- {
- int z = 0;
- uint color = 0;
- for (; z < Height; ++z)
- {
- uint col = 0x646250; //london color
- col ^= 0x070707 & (uint) r.Next();
- map[GetPosition(x, z, y)] = col;
- }
- z = 0;
- while (true)
- {
- int number_4byte_chunks = bytes[pos];
- int top_color_start = bytes[pos + 1];
- int top_color_end = bytes[pos + 2];
- int bottom_color_start;
- int bottom_color_end;
- int len_top;
- int len_bottom;
- for (; z < top_color_start; ++z)
- {
- map[GetPosition(x, z, y)] = 0x000000;
- }
- int colorpos = pos + 4;
- for (; z <= top_color_end; z++)
- {
- color = BitConverter.ToUInt32(bytes, colorpos);
- colorpos += 4;
- map[GetPosition(x, z, y)] = color;
- }
- if (top_color_end == Height - 2)
- {
- map[GetPosition(x, y, Height - 1)] = map[GetPosition(x, y, Height - 2)];
- }
- len_bottom = top_color_end - top_color_start + 1;
- if (number_4byte_chunks == 0)
- {
- pos += 4 * (len_bottom + 1);
- break;
- }
- len_top = (number_4byte_chunks - 1) - len_bottom;
- pos += (int) bytes[pos] * 4;
- bottom_color_end = bytes[pos + 3];
- bottom_color_start = bottom_color_end - len_top;
- for (z = bottom_color_start; z < bottom_color_end; z++)
- {
- color = BitConverter.ToUInt32(bytes, colorpos);
- colorpos += 4;
- map[GetPosition(x, z, y)] = color;
- }
- if (bottom_color_end == Height - 1)
- {
- map[GetPosition(x, y, Height - 1)] = map[GetPosition(x, y, Height - 2)];
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment