private void InitVoxelMap(Vector3D position, Vector3I size, string materialName, bool defineMemory)
{
IsValid = true;
Size = size;
_sizeMinusOne = new Vector3I(Size.X - 1, Size.Y - 1, Size.Z - 1);
VoxelMaterial = SpaceEngineersCore.Resources.GetMaterialIndex(materialName);
_positionLeftBottomCorner = position;
_boundingContent = new BoundingBoxD(new Vector3I(Size.X, Size.Y, Size.Z), new Vector3I(0, 0, 0));
// this is too big for the current SEToolbox code to cope with, and is probably a planet.
if (!defineMemory)
return;
// If you need larged voxel maps, enlarge this constant.
Debug.Assert(Size.X <= MyVoxelConstants.MAX_VOXEL_MAP_SIZE_IN_VOXELS);
Debug.Assert(Size.Y <= MyVoxelConstants.MAX_VOXEL_MAP_SIZE_IN_VOXELS);
Debug.Assert(Size.Z <= MyVoxelConstants.MAX_VOXEL_MAP_SIZE_IN_VOXELS);
// Voxel map size must be multiple of a voxel data cell size.
Debug.Assert((Size.X & MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
Debug.Assert((Size.Y & MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
Debug.Assert((Size.Z & MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
_dataCellsCount.X = Size.X >> MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS;
_dataCellsCount.Y = Size.Y >> MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS;
_dataCellsCount.Z = Size.Z >> MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS;
// Voxel map size must be multiple of a voxel data cell size.
Debug.Assert((Size.X % MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS) == 0);
Debug.Assert((Size.Y % MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS) == 0);
Debug.Assert((Size.Z % MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS) == 0);
// Array of voxel cells in this voxel map.
_voxelContentCells = new MyVoxelContentCell[_dataCellsCount.X][][];
for (var x = 0; x < _voxelContentCells.Length; x++)
{
_voxelContentCells[x] = new MyVoxelContentCell[_dataCellsCount.Y][];
for (var y = 0; y < _voxelContentCells[x].Length; y++)
{
_voxelContentCells[x][y] = new MyVoxelContentCell[_dataCellsCount.Z];
}
}
// Set base material.
_voxelMaterialCells = new MyVoxelMaterialCell[_dataCellsCount.X][][];
for (var x = 0; x < _dataCellsCount.X; x++)
{
_voxelMaterialCells[x] = new MyVoxelMaterialCell[_dataCellsCount.Y][];
for (var y = 0; y < _dataCellsCount.Y; y++)
{
_voxelMaterialCells[x][y] = new MyVoxelMaterialCell[_dataCellsCount.Z];
for (var z = 0; z < _dataCellsCount.Z; z++)
{
_voxelMaterialCells[x][y][z] = new MyVoxelMaterialCell(VoxelMaterial, 0xFF);
}
}
}
}