void ReadVoxelData(Stream s, VxlLimb l) { var baseSize = l.Size[0]*l.Size[1]; var colStart = new int[baseSize]; for (var i = 0; i < baseSize; i++) colStart[i] = s.ReadInt32(); s.Seek(4*baseSize, SeekOrigin.Current); var dataStart = s.Position; // Count the voxels in this limb l.VoxelCount = 0; for (var i = 0; i < baseSize; i++) { // Empty column if (colStart[i] == -1) continue; s.Seek(dataStart + colStart[i], SeekOrigin.Begin); var z = 0; do { z += s.ReadUInt8(); var count = s.ReadUInt8(); z += count; l.VoxelCount += count; s.Seek(2*count + 1, SeekOrigin.Current); } while (z < l.Size[2]); } // Read the data l.VoxelMap = new Dictionary<byte, VxlElement>[l.Size[0],l.Size[1]]; for (var i = 0; i < baseSize; i++) { // Empty column if (colStart[i] == -1) continue; s.Seek(dataStart + colStart[i], SeekOrigin.Begin); byte x = (byte)(i % l.Size[0]); byte y = (byte)(i / l.Size[0]); byte z = 0; l.VoxelMap[x,y] = new Dictionary<byte, VxlElement>(); do { z += s.ReadUInt8(); var count = s.ReadUInt8(); for (var j = 0; j < count; j++) { var v = new VxlElement(); v.Color = s.ReadUInt8(); v.Normal = s.ReadUInt8(); l.VoxelMap[x,y].Add(z, v); z++; } // Skip duplicate count s.ReadUInt8(); } while (z < l.Size[2]); } }
static void ReadVoxelData(Stream s, VxlLimb l) { var baseSize = l.Size[0] * l.Size[1]; var colStart = new int[baseSize]; for (var i = 0; i < baseSize; i++) { colStart[i] = s.ReadInt32(); } s.Seek(4 * baseSize, SeekOrigin.Current); var dataStart = s.Position; // Count the voxels in this limb l.VoxelCount = 0; for (var i = 0; i < baseSize; i++) { // Empty column if (colStart[i] == -1) { continue; } s.Seek(dataStart + colStart[i], SeekOrigin.Begin); var z = 0; do { z += s.ReadUInt8(); var count = s.ReadUInt8(); z += count; l.VoxelCount += count; s.Seek(2 * count + 1, SeekOrigin.Current); } while (z < l.Size[2]); } // Read the data l.VoxelMap = new Dictionary <byte, VxlElement> [l.Size[0], l.Size[1]]; for (var i = 0; i < baseSize; i++) { // Empty column if (colStart[i] == -1) { continue; } s.Seek(dataStart + colStart[i], SeekOrigin.Begin); var x = (byte)(i % l.Size[0]); var y = (byte)(i / l.Size[0]); byte z = 0; l.VoxelMap[x, y] = new Dictionary <byte, VxlElement>(); do { z += s.ReadUInt8(); var count = s.ReadUInt8(); for (var j = 0; j < count; j++) { var v = new VxlElement(); v.Color = s.ReadUInt8(); v.Normal = s.ReadUInt8(); l.VoxelMap[x, y].Add(z, v); z++; } // Skip duplicate count s.ReadUInt8(); } while (z < l.Size[2]); } }