Files
2026-06-01 17:19:55 +02:00

41 lines
740 B
C#

namespace BlockSpace.Voxels
{
public static class PackedVoxel
{
public const byte Air = 0;
public static byte Create(byte colorIndex, VoxelMaterial material)
{
colorIndex &= 0x3F;
if (material == VoxelMaterial.Invisible && colorIndex == 63)
{
colorIndex = 62;
}
return (byte)((byte)(((uint)material << 6) | colorIndex) + 1);
}
public static bool IsAir(byte voxel)
{
return voxel == 0;
}
public static byte GetColorIndex(byte voxel)
{
if (voxel != 0)
{
return (byte)((voxel - 1) & 0x3F);
}
return 0;
}
public static VoxelMaterial GetMaterial(byte voxel)
{
if (voxel != 0)
{
return (VoxelMaterial)((voxel - 1 >> 6) & 3);
}
return VoxelMaterial.Lit;
}
}
}