public void VoxelMaterialAssetsGenerateFixed()
{
SpaceEngineersCore.LoadDefinitions();
var materials = SpaceEngineersCore.Resources.GetMaterialList();
Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");
var files = new[] { @".\TestAssets\Arabian_Border_7.vx2", @".\TestAssets\cube_52x52x52.vx2" };
foreach (var fileOriginal in files)
{
foreach (var material in materials)
{
var fileNewVoxel =
Path.Combine(Path.GetDirectoryName(Path.GetFullPath(fileOriginal)),
Path.GetFileNameWithoutExtension(fileOriginal) + "_" + material.Id.SubtypeId + ".vx2").ToLower();
var voxelMap = new MyVoxelMap();
voxelMap.Load(fileOriginal, materials[0].Id.SubtypeId);
IList<byte> materialAssets;
Dictionary<byte, long> materialVoxelCells;
voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);
var distribution = new[] { Double.NaN, .99, };
var materialSelection = new byte[] { 0, SpaceEngineersCore.Resources.GetMaterialIndex(material.Id.SubtypeId) };
var newDistributiuon = new List<byte>();
int count;
for (var i = 1; i < distribution.Count(); i++)
{
count = (int)Math.Floor(distribution[i] * materialAssets.Count); // Round down.
for (var j = 0; j < count; j++)
{
newDistributiuon.Add(materialSelection[i]);
}
}
count = materialAssets.Count - newDistributiuon.Count;
for (var j = 0; j < count; j++)
{
newDistributiuon.Add(materialSelection[0]);
}
newDistributiuon.Shuffle();
voxelMap.SetMaterialAssets(newDistributiuon);
voxelMap.Save(fileNewVoxel);
}
}
}