public void VoxelMaterialChanges() { 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")); Assert.IsNotNull(stoneMaterial, "Stone material should exist."); var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold")); Assert.IsNotNull(goldMaterial, "Gold material should exist."); const string fileOriginal = @".\TestAssets\asteroid0moon4.vx2"; const string fileNew = @".\TestOutput\asteroid0moon4_gold.vx2"; MyVoxelBuilder.ConvertAsteroid(fileOriginal, fileNew, stoneMaterial.Id.SubtypeId, goldMaterial.Id.SubtypeId); var lengthOriginal = new FileInfo(fileOriginal).Length; var lengthNew = new FileInfo(fileNew).Length; Assert.AreEqual(9431, lengthOriginal, "Original file size must match."); Assert.AreNotEqual(9431, lengthNew, "New file size must match."); }
public void Voxel3DImportStl() { 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_02")); Assert.IsNotNull(stoneMaterial, "Stone material should exist."); var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold")); Assert.IsNotNull(goldMaterial, "Gold material should exist."); const string modelFile = @".\TestAssets\buddha-fixed-bottom.stl"; const string voxelFile = @".\TestOutput\buddha-fixed-bottom.vx2"; var transform = MeshHelper.TransformVector(new System.Windows.Media.Media3D.Vector3D(0, 0, 0), 0, 0, 180); var voxelMap = MyVoxelBuilder.BuildAsteroidFromModel(true, modelFile, goldMaterial.Id.SubtypeId, stoneMaterial.Id.SubtypeId, true, stoneMaterial.Id.SubtypeId, ModelTraceVoxel.ThinSmoothed, 0.766, transform); voxelMap.Save(voxelFile); Assert.AreEqual(50, voxelMap.BoundingContent.SizeInt().X + 1, "Voxel Content size must match."); Assert.AreEqual(46, voxelMap.BoundingContent.SizeInt().Y + 1, "Voxel Content size must match."); Assert.AreEqual(70, voxelMap.BoundingContent.SizeInt().Z + 1, "Voxel Content size must match."); var voxCells = voxelMap.SumVoxelCells(); Assert.AreEqual(18666335, voxCells, "Voxel cells must match."); }
public void VoxelMaterialAssets_FilledVolume() { SpaceEngineersCore.LoadDefinitions(); var materials = SpaceEngineersCore.Resources.GetMaterialList(); Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?"); const string fileNew = @".\TestOutput\test_filledvolume.vx2"; const int length = 64; var size = new Vector3I(length, length, length); var action = (Action <MyVoxelBuilderArgs>) delegate(MyVoxelBuilderArgs e) { e.Volume = 0xFF; }; var voxelMap = MyVoxelBuilder.BuildAsteroid(true, size, materials[06].Id.SubtypeId, null, action); voxelMap.Save(fileNew); var lengthNew = new FileInfo(fileNew).Length; Assert.AreEqual(163, lengthNew, "New file size must match."); Assert.AreEqual(64, voxelMap.Size.X, "Voxel Bounding size must match."); Assert.AreEqual(64, voxelMap.Size.Y, "Voxel Bounding size must match."); Assert.AreEqual(64, voxelMap.Size.Z, "Voxel Bounding size must match."); }
public void VoxelRebuild1() { SpaceEngineersCore.LoadDefinitions(); var materials = SpaceEngineersCore.Resources.GetMaterialList(); Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?"); var fileNew = @".\TestOutput\test_spike_cube1024.vx2"; var length = 1024; var min = 4; var max = length - 4; var size = new Vector3I(length, length, length); var buildparams = new int[][] { new[] { min, 0 }, new[] { min + 1, 1 }, new[] { max, 0 }, new[] { max - 1, -1 } }; var action = (Action <MyVoxelBuilderArgs>) delegate(MyVoxelBuilderArgs e) { e.Volume = 0x00; if (e.CoordinatePoint.X > 0 && e.CoordinatePoint.Y > 0 && e.CoordinatePoint.Z > 0 && e.CoordinatePoint.X < size.X - 1 && e.CoordinatePoint.Y < size.Y - 1 && e.CoordinatePoint.Z < size.Z - 1 && e.CoordinatePoint.X >= min && e.CoordinatePoint.Y >= min && e.CoordinatePoint.Z >= min && e.CoordinatePoint.X <= max && e.CoordinatePoint.Y <= max && e.CoordinatePoint.Z <= max) { foreach (int[] t in buildparams) { if (e.CoordinatePoint.X == t[0] && ((e.CoordinatePoint.Z + t[1]) % 2 == 0) && ((e.CoordinatePoint.Y + t[1]) % 2 == 0)) { e.Volume = 0x92; } if (e.CoordinatePoint.Y == t[0] && ((e.CoordinatePoint.X + t[1]) % 2 == 0) && ((e.CoordinatePoint.Z + t[1]) % 2 == 0)) { e.Volume = 0x92; } if (e.CoordinatePoint.Z == t[0] && ((e.CoordinatePoint.X + t[1]) % 2 == 0) && ((e.CoordinatePoint.Y + t[1]) % 2 == 0)) { e.Volume = 0x92; } } } }; var voxelMap = MyVoxelBuilder.BuildAsteroid(true, size, materials[0].Id.SubtypeId, null, action); voxelMap.Save(fileNew); }
private MyObjectBuilder_VoxelMap BuildAsteroidEntity() { var filenamepart = Path.GetFileNameWithoutExtension(Filename); var filename = MainViewModel.CreateUniqueVoxelStorageName(filenamepart + MyVoxelMap.V2FileExtension); Position = Position.RoundOff(1.0); Forward = Forward.RoundToAxis(); Up = Up.RoundToAxis(); var entity = new MyObjectBuilder_VoxelMap(Position.ToVector3(), filename) { EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ASTEROID), PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene, StorageName = Path.GetFileNameWithoutExtension(filename) }; double multiplier; if (IsMultipleScale) { multiplier = MultipleScale; } else { multiplier = MaxLengthScale / Math.Max(Math.Max(OriginalModelSize.Height, OriginalModelSize.Width), OriginalModelSize.Depth); } var transform = MeshHelper.TransformVector(new Vector3D(0, 0, 0), 0, 0, 0); SourceFile = TempfileUtil.NewFilename(MyVoxelMap.V2FileExtension); var baseMaterial = SpaceEngineersCore.Resources.VoxelMaterialDefinitions.FirstOrDefault(m => m.IsRare == false) ?? SpaceEngineersCore.Resources.VoxelMaterialDefinitions.FirstOrDefault(); var voxelMap = MyVoxelBuilder.BuildAsteroidFromModel(true, Filename, OutsideStockMaterial.MaterialIndex.Value, baseMaterial.Index, InsideStockMaterial.Value != null, InsideStockMaterial.MaterialIndex, ModelTraceVoxel.ThinSmoothed, multiplier, transform, MainViewModel.ResetProgress, MainViewModel.IncrementProgress); voxelMap.Save(SourceFile); MainViewModel.ClearProgress(); entity.PositionAndOrientation = new MyPositionAndOrientation { Position = Position.ToVector3D(), Forward = Forward.ToVector3(), Up = Up.ToVector3() }; IsValidModel = voxelMap.BoundingContent.Size.Volume() > 0; return(entity); }
public void VoxelGenerateSpikeWall() { SpaceEngineersCore.LoadDefinitions(); var materials = SpaceEngineersCore.Resources.GetMaterialList(); Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?"); const string fileNew = @".\TestOutput\test_spike_wall.vx2"; var size = new Vector3I(1024, 1024, 64); var action = (Action <MyVoxelBuilderArgs>) delegate(MyVoxelBuilderArgs e) { e.Volume = 0x00; if (e.CoordinatePoint.X > 0 && e.CoordinatePoint.Y > 0 && e.CoordinatePoint.Z > 0 && e.CoordinatePoint.X < size.X - 1 && e.CoordinatePoint.Y < size.Y - 1 && e.CoordinatePoint.Z < size.Z - 1) { if (e.CoordinatePoint.Z == 5 && (e.CoordinatePoint.X % 2 == 0) && (e.CoordinatePoint.Y % 2 == 0)) { e.Volume = 0x92; } if (e.CoordinatePoint.Z == 6 && ((e.CoordinatePoint.X + 1) % 2 == 0) && ((e.CoordinatePoint.Y + 1) % 2 == 0)) { e.Volume = 0x92; } } }; var voxelMap = MyVoxelBuilder.BuildAsteroid(true, size, materials[0].Id.SubtypeId, null, action); voxelMap.Save(fileNew); var lengthNew = new FileInfo(fileNew).Length; Assert.AreEqual(49809, lengthNew, "New file size must match."); Assert.AreEqual(1024, voxelMap.Size.X, "Voxel Bounding size must match."); Assert.AreEqual(1024, voxelMap.Size.Y, "Voxel Bounding size must match."); Assert.AreEqual(64, voxelMap.Size.Z, "Voxel Bounding size must match."); Assert.AreEqual(1022, voxelMap.BoundingContent.SizeInt().X + 1, "Voxel Content size must match."); Assert.AreEqual(1022, voxelMap.BoundingContent.SizeInt().Y + 1, "Voxel Content size must match."); Assert.AreEqual(2, voxelMap.BoundingContent.SizeInt().Z + 1, "Voxel Content size must match."); // Centered in the middle of the 512x512x512 cell. Assert.AreEqual(511.5, voxelMap.BoundingContent.Center.X, "Voxel Center must match."); Assert.AreEqual(511.5, voxelMap.BoundingContent.Center.Y, "Voxel Center must match."); Assert.AreEqual(5.5, voxelMap.BoundingContent.Center.Z, "Voxel Center must match."); }
public void VoxelGenerateSphereLarge() { 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_02")); Assert.IsNotNull(stoneMaterial, "Stone material should exist."); var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold")); Assert.IsNotNull(goldMaterial, "Gold material should exist."); const string fileNew = @".\TestOutput\test_sphere_solid_499_gold.vx2"; var voxelMap = MyVoxelBuilder.BuildAsteroidSphere(true, 250, goldMaterial.Id.SubtypeId, stoneMaterial.Id.SubtypeId, false, 0); voxelMap.Save(fileNew); var lengthNew = new FileInfo(fileNew).Length; var voxCells = voxelMap.SumVoxelCells(); Assert.AreEqual(16589770849, voxCells, "Voxel cells must match."); Assert.AreEqual(785439, lengthNew, "New file size must match."); Assert.AreEqual(512, voxelMap.Size.X, "Voxel Bounding size must match."); Assert.AreEqual(512, voxelMap.Size.Y, "Voxel Bounding size must match."); Assert.AreEqual(512, voxelMap.Size.Z, "Voxel Bounding size must match."); Assert.AreEqual(499, voxelMap.BoundingContent.SizeInt().X + 1, "Voxel Content size must match."); Assert.AreEqual(499, voxelMap.BoundingContent.SizeInt().Y + 1, "Voxel Content size must match."); Assert.AreEqual(499, voxelMap.BoundingContent.SizeInt().Z + 1, "Voxel Content size must match."); // Centered in the middle of the 512x512x512 cell. Assert.AreEqual(256, voxelMap.BoundingContent.Center.X, "Voxel Center must match."); Assert.AreEqual(256, voxelMap.BoundingContent.Center.Y, "Voxel Center must match."); Assert.AreEqual(256, voxelMap.BoundingContent.Center.Z, "Voxel Center must match."); }
public void VoxelGenerateBoxSmallMultiThread() { 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_02")); Assert.IsNotNull(stoneMaterial, "Stone material should exist."); var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold")); Assert.IsNotNull(goldMaterial, "Gold material should exist."); const string fileNew = @".\TestOutput\test_cube_solid_8x8x8_gold.vx2"; var voxelMap = MyVoxelBuilder.BuildAsteroidCube(true, 8, 8, 8, goldMaterial.Id.SubtypeId, stoneMaterial.Id.SubtypeId, false, 0); voxelMap.Save(fileNew); var lengthNew = new FileInfo(fileNew).Length; Assert.AreEqual(2085, lengthNew, "New file size must match."); Assert.AreEqual(64, voxelMap.Size.X, "Voxel Bounding size must match."); Assert.AreEqual(64, voxelMap.Size.Y, "Voxel Bounding size must match."); Assert.AreEqual(64, voxelMap.Size.Z, "Voxel Bounding size must match."); Assert.AreEqual(8, voxelMap.BoundingContent.SizeInt().X + 1, "Voxel Content size must match."); Assert.AreEqual(8, voxelMap.BoundingContent.SizeInt().Y + 1, "Voxel Content size must match."); Assert.AreEqual(8, voxelMap.BoundingContent.SizeInt().Z + 1, "Voxel Content size must match."); // Centered in the middle of 1 and 8. 1234-(4.5)-5678 Assert.AreEqual(4.5, voxelMap.BoundingContent.Center.X, "Voxel Center must match."); Assert.AreEqual(4.5, voxelMap.BoundingContent.Center.Y, "Voxel Center must match."); Assert.AreEqual(4.5, voxelMap.BoundingContent.Center.Z, "Voxel Center must match."); }
public void VoxelGenerateSphereSmall() { SpaceEngineersCore.LoadDefinitions(); var materials = SpaceEngineersCore.Resources.VoxelMaterialDefinitions; Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?"); var stoneMaterial = materials.FirstOrDefault(m => m.Id.SubtypeName.Contains("Stone_02")); Assert.IsNotNull(stoneMaterial, "Stone material should exist."); var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeName.Contains("Gold")); Assert.IsNotNull(goldMaterial, "Gold material should exist."); const string fileNew = @".\TestOutput\test_sphere_solid_7_gold.vx2"; var voxelMap = MyVoxelBuilder.BuildAsteroidSphere(false, 4, goldMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, false, 0); voxelMap.Save(fileNew); var lengthNew = new FileInfo(fileNew).Length; Assert.AreEqual(2278, lengthNew, "New file size must match."); Assert.AreEqual(64, voxelMap.Size.X, "Voxel Bounding size must match."); Assert.AreEqual(64, voxelMap.Size.Y, "Voxel Bounding size must match."); Assert.AreEqual(64, voxelMap.Size.Z, "Voxel Bounding size must match."); Assert.AreEqual(7, voxelMap.BoundingContent.SizeInt().X + 1, "Voxel Content size must match."); Assert.AreEqual(7, voxelMap.BoundingContent.SizeInt().Y + 1, "Voxel Content size must match."); Assert.AreEqual(7, voxelMap.BoundingContent.SizeInt().Z + 1, "Voxel Content size must match."); // Centered in the middle of the 64x64x64 cell. Assert.AreEqual(32, voxelMap.BoundingContent.Center.X, "Voxel Center must match."); Assert.AreEqual(32, voxelMap.BoundingContent.Center.Y, "Voxel Center must match."); Assert.AreEqual(32, voxelMap.BoundingContent.Center.Z, "Voxel Center must match."); }
public MyObjectBuilder_EntityBase BuildEntity() { var asteroidCenter = new VRageMath.Vector3D(); var asteroidSize = new Vector3I(); string originalFile = null; if (IsStockVoxel) { var stockfile = StockVoxel.SourceFilename; if (StockMaterial == null || StockMaterial.Value == null) { SourceFile = stockfile; originalFile = SourceFile; var asteroid = new MyVoxelMap(); asteroid.Load(stockfile); asteroidCenter = asteroid.BoundingContent.Center; asteroidSize = asteroid.BoundingContent.Size + 1; // Content size } else { var asteroid = new MyVoxelMap(); asteroid.Load(stockfile); asteroid.ForceBaseMaterial(SpaceEngineersCore.Resources.GetDefaultMaterialName(), StockMaterial.Value); SourceFile = TempfileUtil.NewFilename(MyVoxelMap.V2FileExtension); asteroid.Save(SourceFile); originalFile = StockVoxel.SourceFilename; asteroidCenter = asteroid.BoundingContent.Center; asteroidSize = asteroid.BoundingContent.Size + 1; // Content size } } else if (IsFileVoxel) { originalFile = SourceFile; var asteroid = new MyVoxelMap(); asteroid.Load(SourceFile); asteroidCenter = asteroid.BoundingContent.Center; asteroidSize = asteroid.BoundingContent.Size + 1; // Content size if (StockMaterial != null && StockMaterial.Value != null) { asteroid.ForceBaseMaterial(SpaceEngineersCore.Resources.GetDefaultMaterialName(), StockMaterial.Value); SourceFile = TempfileUtil.NewFilename(MyVoxelMap.V2FileExtension); asteroid.Save(SourceFile); } } else if (IsSphere) { byte materialIndex; if (StockMaterial?.MaterialIndex != null) { materialIndex = StockMaterial.MaterialIndex.Value; } else { materialIndex = SpaceEngineersCore.Resources.GetDefaultMaterialIndex(); } string materialName = SpaceEngineersCore.Resources.GetMaterialName(materialIndex); originalFile = string.Format("sphere_{0}_{1}_{2}{3}", materialName.ToLowerInvariant(), SphereRadius, SphereShellRadius, MyVoxelMap.V2FileExtension); var asteroid = MyVoxelBuilder.BuildAsteroidSphere(SphereRadius > 32, SphereRadius, materialIndex, materialIndex, SphereShellRadius != 0, SphereShellRadius); // TODO: progress bar. asteroidCenter = asteroid.BoundingContent.Center; asteroidSize = asteroid.BoundingContent.Size + 1; // Content size SourceFile = TempfileUtil.NewFilename(MyVoxelMap.V2FileExtension); asteroid.Save(SourceFile); } // automatically number all files, and check for duplicate filenames. Filename = MainViewModel.CreateUniqueVoxelStorageName(originalFile); // Figure out where the Character is facing, and plant the new constrcut right in front. // Calculate the hypotenuse, as it will be the safest distance to place in front. double distance = Math.Sqrt(Math.Pow(asteroidSize.X, 2) + Math.Pow(asteroidSize.Y, 2) + Math.Pow(asteroidSize.Z, 2)) / 2; var vector = new BindableVector3DModel(_dataModel.CharacterPosition.Forward).Vector3D; vector.Normalize(); vector = System.Windows.Media.Media3D.Vector3D.Multiply(vector, distance); Position = new BindablePoint3DModel(Point3D.Add(new BindablePoint3DModel(_dataModel.CharacterPosition.Position).Point3D, vector)); //Forward = new BindableVector3DModel(_dataModel.CharacterPosition.Forward); //Up = new BindableVector3DModel(_dataModel.CharacterPosition.Up); Forward = new BindableVector3DModel(Vector3.Forward); // Asteroids currently don't have any orientation. Up = new BindableVector3DModel(Vector3.Up); var entity = new MyObjectBuilder_VoxelMap { EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ASTEROID), PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene, StorageName = Path.GetFileNameWithoutExtension(Filename), PositionAndOrientation = new MyPositionAndOrientation { Position = Position.ToVector3D() - asteroidCenter, Forward = Forward.ToVector3(), Up = Up.ToVector3() } }; return(entity); }
public MyObjectBuilder_EntityBase BuildEntity() { // Realign both asteroids to a common grid, so voxels can be lined up. Vector3I roundedPosLeft = SelectionLeft.WorldAABB.Min.RoundToVector3I(); Vector3D offsetPosLeft = SelectionLeft.WorldAABB.Min - (Vector3D)roundedPosLeft; // Use for everything. Vector3I roundedPosRight = (SelectionRight.WorldAABB.Min - offsetPosLeft).RoundToVector3I(); Vector3D offsetPosRight = SelectionRight.WorldAABB.Min - (Vector3D)roundedPosRight; // Use for everything. // calculate smallest allowable size for contents of both. const int paddCells = 3; // Force a calculation of the ContentBounds, as multi select in the ListView doesn't necessarily make it happen, or make it happen fast enough. SelectionLeft.LoadDetailsSync(); SelectionRight.LoadDetailsSync(); var minLeft = SelectionLeft.WorldAABB.Min + SelectionLeft.InflatedContentBounds.Min - offsetPosLeft; var minRight = SelectionRight.WorldAABB.Min + SelectionRight.InflatedContentBounds.Min - offsetPosRight; var min = Vector3D.Zero; var posOffset = Vector3D.Zero; var asteroidSize = Vector3I.Zero; switch (VoxelMergeType) { case VoxelMergeType.UnionVolumeLeftToRight: case VoxelMergeType.UnionVolumeRightToLeft: min = Vector3D.Min(minLeft, minRight) - paddCells; var max = Vector3D.Max(SelectionLeft.WorldAABB.Min + SelectionLeft.InflatedContentBounds.Max - offsetPosLeft, SelectionRight.WorldAABB.Min + SelectionRight.InflatedContentBounds.Max - offsetPosRight) + paddCells; posOffset = new Vector3D(minLeft.X < minRight.X ? offsetPosLeft.X : offsetPosRight.X, minLeft.Y < minRight.Y ? offsetPosLeft.Y : offsetPosRight.Y, minLeft.Z < minRight.Z ? offsetPosLeft.Z : offsetPosRight.Z); var size = (max - min).RoundToVector3I(); asteroidSize = MyVoxelBuilder.CalcRequiredSize(size); break; case VoxelMergeType.UnionMaterialLeftToRight: min = SelectionRight.WorldAABB.Min - offsetPosRight; posOffset = new Vector3D(minLeft.X < minRight.X ? offsetPosLeft.X : offsetPosRight.X, minLeft.Y < minRight.Y ? offsetPosLeft.Y : offsetPosRight.Y, minLeft.Z < minRight.Z ? offsetPosLeft.Z : offsetPosRight.Z); asteroidSize = SelectionRight.Size; break; case VoxelMergeType.UnionMaterialRightToLeft: min = SelectionLeft.WorldAABB.Min - offsetPosLeft; posOffset = new Vector3D(minLeft.X < minRight.X ? offsetPosLeft.X : offsetPosRight.X, minLeft.Y < minRight.Y ? offsetPosLeft.Y : offsetPosRight.Y, minLeft.Z < minRight.Z ? offsetPosLeft.Z : offsetPosRight.Z); asteroidSize = SelectionLeft.Size; break; case VoxelMergeType.SubtractVolumeLeftFromRight: min = SelectionRight.WorldAABB.Min - offsetPosRight; posOffset = new Vector3D(minLeft.X < minRight.X ? offsetPosLeft.X : offsetPosRight.X, minLeft.Y < minRight.Y ? offsetPosLeft.Y : offsetPosRight.Y, minLeft.Z < minRight.Z ? offsetPosLeft.Z : offsetPosRight.Z); asteroidSize = SelectionRight.Size; break; case VoxelMergeType.SubtractVolumeRightFromLeft: min = SelectionLeft.WorldAABB.Min - offsetPosLeft; posOffset = new Vector3D(minLeft.X < minRight.X ? offsetPosLeft.X : offsetPosRight.X, minLeft.Y < minRight.Y ? offsetPosLeft.Y : offsetPosRight.Y, minLeft.Z < minRight.Z ? offsetPosLeft.Z : offsetPosRight.Z); asteroidSize = SelectionLeft.Size; break; } // Prepare new asteroid. var newAsteroid = new MyVoxelMap(); newAsteroid.Create(asteroidSize, SpaceEngineersCore.Resources.GetDefaultMaterialIndex()); if (string.IsNullOrEmpty(MergeFileName)) { MergeFileName = "merge"; } var filename = MainViewModel.CreateUniqueVoxelStorageName(MergeFileName); // merge. switch (VoxelMergeType) { case VoxelMergeType.UnionVolumeLeftToRight: MergeAsteroidVolumeInto(ref newAsteroid, min, SelectionRight, SelectionLeft, minRight, minLeft); break; case VoxelMergeType.UnionVolumeRightToLeft: MergeAsteroidVolumeInto(ref newAsteroid, min, SelectionLeft, SelectionRight, minLeft, minRight); break; case VoxelMergeType.UnionMaterialLeftToRight: MergeAsteroidMaterialFrom(ref newAsteroid, min, SelectionRight, SelectionLeft, minRight, minLeft); break; case VoxelMergeType.UnionMaterialRightToLeft: MergeAsteroidMaterialFrom(ref newAsteroid, min, SelectionLeft, SelectionRight, minLeft, minRight); break; case VoxelMergeType.SubtractVolumeLeftFromRight: SubtractAsteroidVolumeFrom(ref newAsteroid, min, SelectionRight, SelectionLeft, minRight, minLeft); break; case VoxelMergeType.SubtractVolumeRightFromLeft: SubtractAsteroidVolumeFrom(ref newAsteroid, min, SelectionLeft, SelectionRight, minLeft, minRight); break; } // Generate Entity var tempfilename = TempfileUtil.NewFilename(MyVoxelMap.V2FileExtension); newAsteroid.Save(tempfilename); SourceFile = tempfilename; var position = min + posOffset; var entity = new MyObjectBuilder_VoxelMap(position, filename) { EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ASTEROID), PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene, StorageName = Path.GetFileNameWithoutExtension(filename), PositionAndOrientation = new MyPositionAndOrientation { Position = position, Forward = Vector3.Forward, Up = Vector3.Up } }; return(entity); }
public void SeedFillVoxelFile() { 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_01")); Assert.IsNotNull(stoneMaterial, "Stone material should exist."); var ironMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Iron_02")); Assert.IsNotNull(ironMaterial, "Iron material should exist."); var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold")); Assert.IsNotNull(goldMaterial, "Gold material should exist."); var voxelMap = MyVoxelBuilder.BuildAsteroidCube(false, 64, 64, 64, stoneMaterial.Id.SubtypeId, stoneMaterial.Id.SubtypeId, false, 0); //var voxelMap = MyVoxelBuilder.BuildAsteroidSphere(true, 64, stoneMaterial.Id.SubtypeId, stoneMaterial.Id.SubtypeId, false, 0); var filler = new AsteroidSeedFiller(); var fillProperties = new AsteroidSeedFillProperties { MainMaterial = new SEToolbox.Models.MaterialSelectionModel { Value = stoneMaterial.Id.SubtypeId }, FirstMaterial = new SEToolbox.Models.MaterialSelectionModel { Value = ironMaterial.Id.SubtypeId }, FirstRadius = 3, FirstVeins = 2, SecondMaterial = new SEToolbox.Models.MaterialSelectionModel { Value = goldMaterial.Id.SubtypeId }, SecondRadius = 1, SecondVeins = 1, }; filler.FillAsteroid(voxelMap, fillProperties); Assert.AreEqual(128, voxelMap.Size.X, "Voxel Bounding size must match."); Assert.AreEqual(128, voxelMap.Size.Y, "Voxel Bounding size must match."); Assert.AreEqual(128, voxelMap.Size.Z, "Voxel Bounding size must match."); Assert.AreEqual(64, voxelMap.BoundingContent.SizeInt().X + 1, "Voxel Content size must match."); Assert.AreEqual(64, voxelMap.BoundingContent.SizeInt().Y + 1, "Voxel Content size must match."); Assert.AreEqual(64, voxelMap.BoundingContent.SizeInt().Z + 1, "Voxel Content size must match."); var voxCells = voxelMap.SumVoxelCells(); Assert.AreEqual(66846720, voxCells, "Voxel cells must match."); IList <byte> materialAssets; Dictionary <byte, long> materialVoxelCells; voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells); var stoneAssets = materialAssets.Where(c => c == SpaceEngineersCore.Resources.GetMaterialIndex(stoneMaterial.Id.SubtypeId)).ToList(); var ironAssets = materialAssets.Where(c => c == SpaceEngineersCore.Resources.GetMaterialIndex(ironMaterial.Id.SubtypeId)).ToList(); var goldAssets = materialAssets.Where(c => c == SpaceEngineersCore.Resources.GetMaterialIndex(goldMaterial.Id.SubtypeId)).ToList(); var sumAssets = (stoneAssets.Count + ironAssets.Count + goldAssets.Count) * 255; // A cube should produce full voxcells, so all of them are 255. Assert.AreEqual(voxCells, sumAssets, "Assets sum should equal cells"); // Seeder is too random to provide stable values. //Assert.AreEqual(236032, stoneAssets.Count, "Stone assets should equal."); //Assert.AreEqual(23040, ironAssets.Count , "Iron assets should equal."); //Assert.AreEqual(3072, goldAssets.Count, "Gold assets should equal."); // Strip the original material. //voxelMap.RemoveMaterial(stoneMaterial.Id.SubtypeId, null); //const string fileNew = @".\TestOutput\randomSeedMaterialCube.vx2"; //voxelMap.Save(fileNew); //var lengthNew = new FileInfo(fileNew).Length; }
public void VoxelGenerateSpikeCube() { SpaceEngineersCore.LoadDefinitions(); var materials = SpaceEngineersCore.Resources.GetMaterialList(); Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?"); var fileNew = @".\TestOutput\test_spike_cube256.vx2"; var length = 256; var min = 4; var max = length - 4; var size = new Vector3I(length, length, length); var buildparams = new int[][] { new[] { min, 0 }, new[] { min + 1, 1 }, new[] { max, 0 }, new[] { max - 1, -1 } }; var action = (Action <MyVoxelBuilderArgs>) delegate(MyVoxelBuilderArgs e) { e.Volume = 0x00; if (e.CoordinatePoint.X > 0 && e.CoordinatePoint.Y > 0 && e.CoordinatePoint.Z > 0 && e.CoordinatePoint.X < size.X - 1 && e.CoordinatePoint.Y < size.Y - 1 && e.CoordinatePoint.Z < size.Z - 1 && e.CoordinatePoint.X >= min && e.CoordinatePoint.Y >= min && e.CoordinatePoint.Z >= min && e.CoordinatePoint.X <= max && e.CoordinatePoint.Y <= max && e.CoordinatePoint.Z <= max) { foreach (int[] t in buildparams) { if (e.CoordinatePoint.X == t[0] && ((e.CoordinatePoint.Z + t[1]) % 2 == 0) && ((e.CoordinatePoint.Y + t[1]) % 2 == 0)) { e.Volume = 0x92; } if (e.CoordinatePoint.Y == t[0] && ((e.CoordinatePoint.X + t[1]) % 2 == 0) && ((e.CoordinatePoint.Z + t[1]) % 2 == 0)) { e.Volume = 0x92; } if (e.CoordinatePoint.Z == t[0] && ((e.CoordinatePoint.X + t[1]) % 2 == 0) && ((e.CoordinatePoint.Y + t[1]) % 2 == 0)) { e.Volume = 0x92; } } } }; var voxelMap = MyVoxelBuilder.BuildAsteroid(true, size, materials[0].Id.SubtypeId, null, action); voxelMap.Save(fileNew); var lengthNew = new FileInfo(fileNew).Length; Assert.AreEqual(22542, lengthNew, "New file size must match."); Assert.AreEqual(256, voxelMap.Size.X, "Voxel Bounding size must match."); Assert.AreEqual(256, voxelMap.Size.Y, "Voxel Bounding size must match."); Assert.AreEqual(256, voxelMap.Size.Z, "Voxel Bounding size must match."); Assert.AreEqual(249, voxelMap.BoundingContent.SizeInt().X + 1, "Voxel Content size must match."); Assert.AreEqual(249, voxelMap.BoundingContent.SizeInt().Y + 1, "Voxel Content size must match."); Assert.AreEqual(249, voxelMap.BoundingContent.SizeInt().Z + 1, "Voxel Content size must match."); // Centered in the middle of the 256x256x256 cell. Assert.AreEqual(128, voxelMap.BoundingContent.Center.X, "Voxel Center must match."); Assert.AreEqual(128, voxelMap.BoundingContent.Center.Y, "Voxel Center must match."); Assert.AreEqual(128, voxelMap.BoundingContent.Center.Z, "Voxel Center must match."); }