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); } } }
public void FillAsteroid(MyVoxelMap asteroid, IMyVoxelFillProperties fillProperties) { var properties = (AsteroidByteFillProperties)fillProperties; IList<byte> baseAssets; Dictionary<byte, long> materialVoxelCells; asteroid.CalculateMaterialCellAssets(out baseAssets, out materialVoxelCells); var distribution = new List<double> { Double.NaN }; var materialSelection = new List<byte> { SpaceEngineersCore.Resources.GetMaterialIndex(properties.MainMaterial.Value) }; if (properties.SecondPercent > 0) { distribution.Add((double)properties.SecondPercent / 100); materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.SecondMaterial.Value)); } if (properties.ThirdPercent > 0) { distribution.Add((double)properties.ThirdPercent / 100); materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.ThirdMaterial.Value)); } if (properties.FourthPercent > 0) { distribution.Add((double)properties.FourthPercent / 100); materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.FourthMaterial.Value)); } if (properties.FifthPercent > 0) { distribution.Add((double)properties.FifthPercent / 100); materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.FifthMaterial.Value)); } if (properties.SixthPercent > 0) { distribution.Add((double)properties.SixthPercent / 100); materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.SixthMaterial.Value)); } if (properties.SeventhPercent > 0) { distribution.Add((double)properties.SeventhPercent / 100); materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.SeventhMaterial.Value)); } var newDistributiuon = new List<byte>(); int count; for (var i = 1; i < distribution.Count(); i++) { count = (int)Math.Floor(distribution[i] * baseAssets.Count); // Round down. for (var j = 0; j < count; j++) { newDistributiuon.Add(materialSelection[i]); } } count = baseAssets.Count - newDistributiuon.Count; for (var j = 0; j < count; j++) { newDistributiuon.Add(materialSelection[0]); } newDistributiuon.Shuffle(); asteroid.SetMaterialAssets(newDistributiuon); //asteroid.ForceVoxelFaceMaterial(_dataModel.BaseMaterial.DisplayName); }
public void VoxelMaterialAssetsRandom() { SpaceEngineersCore.LoadDefinitions(); var materials = SpaceEngineersCore.Resources.GetMaterialList(); Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?"); var stoneMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Stone_05")); Assert.IsNotNull(stoneMaterial, "Stone material should exist."); var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold")); Assert.IsNotNull(goldMaterial, "Gold material should exist."); var uraniumMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Uraninite_01")); Assert.IsNotNull(uraniumMaterial, "Uranium material should exist."); const string fileOriginal = @".\TestAssets\Arabian_Border_7.vx2"; const string fileNewVoxel = @".\TestOutput\Arabian_Border_7_mixed.vx2"; var voxelMap = new MyVoxelMap(); voxelMap.Load(fileOriginal, materials[0].Id.SubtypeId); IList<byte> materialAssets; Dictionary<byte, long> materialVoxelCells; voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells); Assert.AreEqual(35465, materialAssets.Count, "Asset count should be equal."); var distribution = new[] { Double.NaN, .5, .25 }; var materialSelection = new[] { SpaceEngineersCore.Resources.GetMaterialIndex(stoneMaterial.Id.SubtypeId), SpaceEngineersCore.Resources.GetMaterialIndex(goldMaterial.Id.SubtypeId), SpaceEngineersCore.Resources.GetMaterialIndex(uraniumMaterial.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(); var assetNameCount = voxelMap.CountAssets(newDistributiuon); Assert.AreEqual(3, assetNameCount.Count, "Asset Mertials count should be equal."); Assert.AreEqual(8867, assetNameCount[stoneMaterial.Id.SubtypeId], "Asset Mertials count should be equal."); Assert.AreEqual(17732, assetNameCount[goldMaterial.Id.SubtypeId], "Asset Mertials count should be equal."); Assert.AreEqual(8866, assetNameCount[uraniumMaterial.Id.SubtypeId], "Asset Mertials count should be equal."); voxelMap.SetMaterialAssets(newDistributiuon); voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells); var cellCount = voxelMap.SumVoxelCells(); voxelMap.Save(fileNewVoxel); }