Esempio n. 1
0
        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.");
        }
Esempio n. 2
0
        public void BaseModel1LoadSave()
        {
            SpaceEngineersCore.LoadDefinitions();
            var location = ToolboxUpdater.GetApplicationFilePath();

            Assert.IsNotNull(location, "Space Engineers should be installed on developer machine");
            Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine");

            var contentPath = ToolboxUpdater.GetApplicationContentPath();

            var largeThruster     = (MyObjectBuilder_CubeBlockDefinition)SpaceEngineersApi.GetDefinition(SpaceEngineersTypes.Thrust, "LargeBlockLargeThrust");
            var thrusterModelPath = Path.Combine(contentPath, largeThruster.Model);

            Assert.IsTrue(File.Exists(thrusterModelPath), "Filepath should exist on developer machine");

            var modelData = MyModel.LoadModelData(thrusterModelPath);
            //var modelData = MyModel.LoadCustomModelData(thrusterModelPath);

            var testFilePath = @".\TestOutput\Thruster.mwm";

            MyModel.SaveModelData(testFilePath, modelData);

            var originalBytes = File.ReadAllBytes(thrusterModelPath);
            var newBytes      = File.ReadAllBytes(testFilePath);

            Assert.AreEqual(originalBytes.Length, newBytes.Length, "Bytestream content must equal");
            Assert.IsTrue(originalBytes.SequenceEqual(newBytes), "Bytestream content must equal");
        }
Esempio n. 3
0
        public void VoxelLoadStock()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();

            Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");

            var contentPath = ToolboxUpdater.GetApplicationContentPath();
            var redShipCrashedAsteroidPath = Path.Combine(contentPath, "VoxelMaps", "RedShipCrashedAsteroid.vx2");

            var voxelMap = new MyVoxelMap();

            voxelMap.Load(redShipCrashedAsteroidPath, materials[0].Id.SubtypeId);

            Assert.AreEqual(1, voxelMap.FileVersion, "FileVersion should be equal.");

            IList <byte>            materialAssets;
            Dictionary <byte, long> materialVoxelCells;

            voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);
            Assert.AreEqual(563742, materialAssets.Count, "Asset count should be equal.");

            var asset0 = materialAssets.Where(c => c == 0).ToList();

            Assert.AreEqual(563742, asset0.Count, "asset0 count should be equal.");

            var assetNameCount = voxelMap.CountAssets(materialAssets);

            Assert.IsTrue(assetNameCount.Count > 0, "Contains assets.");

            var lengthOriginal = new FileInfo(redShipCrashedAsteroidPath).Length;

            Assert.AreEqual(51819, lengthOriginal, "File size must match.");
        }
Esempio n. 4
0
        public void CreateMenuTextures()
        {
            SpaceEngineersCore.LoadDefinitions();

            var location = ToolboxUpdater.GetApplicationFilePath();

            Assert.IsNotNull(location, "Space Engineers should be installed on developer machine");
            Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine");

            var contentPath = ToolboxUpdater.GetApplicationContentPath();

            var smallBlockLandingGear     = SpaceEngineersApi.GetDefinition(new MyObjectBuilderType(typeof(MyObjectBuilder_LandingGear)), "SmallBlockLandingGear");
            var smallBlockLandingGearPath = Path.Combine(contentPath, smallBlockLandingGear.Icons.First());

            Assert.IsTrue(File.Exists(smallBlockLandingGearPath), "Filepath should exist on developer machine");
            Assert.IsTrue(smallBlockLandingGear is MyObjectBuilder_CubeBlockDefinition, "Type should match");
            var smallBlockLandingGearBmp = TexUtil.CreateBitmap(smallBlockLandingGearPath);

            var gridItemPath = Path.Combine(contentPath, @"Textures\GUI\Controls\grid_item.dds");

            Assert.IsTrue(File.Exists(gridItemPath), "Filepath should exist on developer machine");
            var gridBmp = TexUtil.CreateBitmap(gridItemPath);

            var bmp = ImageTextureUtil.MergeImages(gridBmp, smallBlockLandingGearBmp, Brushes.Black);

            ImageTextureUtil.WriteImage(bmp, @".\TestOutput\Menu_SmallBlockLandingGear.png");
        }
Esempio n. 5
0
        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.");
        }
Esempio n. 6
0
        public void VoxelMaterials()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();

            Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");
        }
Esempio n. 7
0
        public void VoxelMaterialAssets_FixedSize_MixedContent()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();

            Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");

            var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold"));

            Assert.IsNotNull(goldMaterial, "Gold material should exist.");

            const string fileOriginal = @".\TestAssets\test_cube_mixed_2x2x2.vx2";

            var voxelMap = new MyVoxelMap();

            voxelMap.Load(fileOriginal, materials[0].Id.SubtypeId);
            var                     cellCount = voxelMap.SumVoxelCells();
            IList <byte>            materialAssets;
            Dictionary <byte, long> materialVoxelCells;

            voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);
            var assetNameCount = voxelMap.CountAssets(materialAssets);

            Assert.AreEqual(8 * 255, cellCount, "Cell count should be equal.");
            Assert.AreEqual(8, materialAssets.Count, "Asset count should be equal.");
            Assert.AreEqual(8, assetNameCount.Count, "Asset Mertials count should be equal.");
        }
Esempio n. 8
0
        public void Load(MyCubeSize cubeSize, MyObjectBuilderType typeId, string subTypeId)
        {
            CubeList.Clear();
            var list            = new SortedList <string, ComponentItemModel>();
            var contentPath     = ToolboxUpdater.GetApplicationContentPath();
            var cubeDefinitions = SpaceEngineersCore.Resources.Definitions.CubeBlocks.Where(c => c.CubeSize == cubeSize);

            foreach (var cubeDefinition in cubeDefinitions)
            {
                var c = new ComponentItemModel
                {
                    Name         = cubeDefinition.DisplayName,
                    TypeId       = cubeDefinition.Id.TypeId,
                    TypeIdString = cubeDefinition.Id.TypeIdString,
                    SubtypeId    = cubeDefinition.Id.SubtypeId,
                    TextureFile  = SpaceEngineersCore.GetDataPathOrDefault(cubeDefinition.Icons.First(), Path.Combine(contentPath, cubeDefinition.Icons.First())),
                    Time         = new TimeSpan((long)(TimeSpan.TicksPerSecond * cubeDefinition.BuildTimeSeconds)),
                    Accessible   = cubeDefinition.Public,
                    Mass         = SpaceEngineersApi.FetchCubeBlockMass(cubeDefinition.Id.TypeId, cubeDefinition.CubeSize, cubeDefinition.Id.SubtypeId),
                    CubeSize     = cubeDefinition.CubeSize,
                    Size         = new BindableSize3DIModel(cubeDefinition.Size),
                };

                list.Add(c.FriendlyName + c.TypeIdString + c.SubtypeId, c);
            }

            foreach (var kvp in list)
            {
                CubeList.Add(kvp.Value);
            }

            CubeItem = CubeList.FirstOrDefault(c => c.TypeId == typeId && c.SubtypeId == subTypeId);
        }
Esempio n. 9
0
        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.");
        }
Esempio n. 10
0
        public void CustomModel1LoadSave()
        {
            SpaceEngineersCore.LoadDefinitions();
            var location = ToolboxUpdater.GetApplicationFilePath();

            Assert.IsNotNull(location, "Space Engineers should be installed on developer machine");
            Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine");

            var contentPath = ToolboxUpdater.GetApplicationContentPath();

            var cockpitModelPath = Path.Combine(contentPath, @"Models\Characters\Animations\cockpit1_large.mwm");

            Assert.IsTrue(File.Exists(cockpitModelPath), "Filepath should exist on developer machine");

            var modelData = MyModel.LoadCustomModelData(cockpitModelPath);

            var testFilePath = @".\TestOutput\cockpit_animation.mwm";

            MyModel.SaveModelData(testFilePath, modelData);

            var originalBytes = File.ReadAllBytes(cockpitModelPath);
            var newBytes      = File.ReadAllBytes(testFilePath);

            Assert.AreEqual(originalBytes.Length, newBytes.Length, "Bytestream content must equal");
            Assert.IsTrue(originalBytes.SequenceEqual(newBytes), "Bytestream content must equal");
        }
Esempio n. 11
0
        public void VoxelMaterialAssets_MixedGeneratedAsset()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();

            Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");

            var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold"));

            Assert.IsNotNull(goldMaterial, "Gold material should exist.");

            const string fileOriginal = @".\TestAssets\asteroid0moon4.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(44135, materialAssets.Count, "Asset count should be equal.");

            var otherAssets = materialAssets.Where(c => c != 4).ToList();

            Assert.AreEqual(0, otherAssets.Count, "Other Asset count should be equal.");

            var assetNameCount = voxelMap.CountAssets(materialAssets);

            Assert.IsTrue(assetNameCount.Count > 0, "Contains assets.");
        }
Esempio n. 12
0
        public void InitTest()
        {
            SpaceEngineersCore.LoadDefinitions();
            _path = Path.GetFullPath(".\\TestOutput");

            if (!Directory.Exists(_path))
            {
                Directory.CreateDirectory(_path);
            }
        }
Esempio n. 13
0
        public void InitTest()
        {
            SpaceEngineersCore.LoadDefinitions();
            _path = Path.GetFullPath(".\\TestOutput");
            //_path = @"D:\Development\GitHub\SEToolbox development\Main\SEToolbox\ToolboxTest\bin\x64\Debug\TestOutput";

            if (!Directory.Exists(_path))
            {
                Directory.CreateDirectory(_path);
            }
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
 public void InitTest()
 {
     try
     {
         SpaceEngineersCore.LoadDefinitions();
     }
     // For debugging tests.
     catch (Exception ex)
     {
         throw;
     }
 }
Esempio n. 16
0
        public void VoxelConvertToVolmeticCancel()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();

            var stoneMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Stone"));

            Assert.IsNotNull(stoneMaterial, "Stone material should exist.");

            var modelFile       = @".\TestAssets\Sphere_Gold.3ds";
            var scale           = new ScaleTransform3D(50, 50, 50);
            var rotateTransform = MeshHelper.TransformVector(new System.Windows.Media.Media3D.Vector3D(0, 0, 0), 0, 0, 0);
            var traceType       = SEToolbox.Interop.Asteroids.TraceType.Odd;
            var traceCount      = SEToolbox.Interop.Asteroids.TraceCount.Trace5;
            var traceDirection  = SEToolbox.Interop.Asteroids.TraceDirection.XYZ;

            var model  = MeshHelper.Load(modelFile, ignoreErrors: true);
            var meshes = new List <SEToolbox.Interop.Asteroids.MyVoxelRayTracer.MyMeshModel>();

            foreach (var model3D in model.Children)
            {
                var gm       = (GeometryModel3D)model3D;
                var geometry = gm.Geometry as MeshGeometry3D;

                if (geometry != null)
                {
                    meshes.Add(new MyVoxelRayTracer.MyMeshModel(new[] { geometry }, stoneMaterial.Id.SubtypeId, stoneMaterial.Id.SubtypeId));
                }
            }

            bool doCancel = false;

            // cancel the convertion after 5 seconds.
            var timer = new Timer(5000);

            timer.Elapsed += delegate
            {
                Debug.WriteLine("Cancelling!!!");
                doCancel = true;
                timer.Stop();
            };
            timer.Start();

            var cancelFunc = (Func <bool>) delegate
            {
                return(doCancel);
            };

            var voxelMap = MyVoxelRayTracer.ReadModelAsteroidVolmetic(model, meshes, scale, rotateTransform, traceType, traceCount, traceDirection,
                                                                      ResetProgress, IncrementProgress, cancelFunc, CompleteProgress);

            Assert.IsNull(voxelMap, "Asteroid must not exist.");
        }
Esempio n. 17
0
        //[TestMethod]
        public void LoadModelFailures()
        {
            SpaceEngineersCore.LoadDefinitions();
            var location = ToolboxUpdater.GetApplicationFilePath();

            Assert.IsNotNull(location, "Space Engineers should be installed on developer machine");
            Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine");

            var contentPath = ToolboxUpdater.GetApplicationContentPath();

            var files          = Directory.GetFiles(Path.Combine(contentPath, "Models"), "*.mwm", SearchOption.AllDirectories);
            var badList        = new List <string>();
            var convertDiffers = new List <string>();

            foreach (var file in files)
            {
                Dictionary <string, object> data = null;
                try
                {
                    data = MyModel.LoadModelData(file);
                    //data = MyModel.LoadCustomModelData(file);
                }
                catch (Exception)
                {
                    badList.Add(file);
                    continue;
                }

                if (data != null)
                {
                    var testFilePath = @".\TestOutput\TempModelTest.mwm";

                    MyModel.SaveModelData(testFilePath, data);

                    var originalBytes = File.ReadAllBytes(file);
                    var newBytes      = File.ReadAllBytes(testFilePath);

                    if (!originalBytes.SequenceEqual(newBytes))
                    {
                        convertDiffers.Add(file);
                    }

                    //Assert.AreEqual(originalBytes.Length, newBytes.Length, "File {0} Bytestream content must equal", file);
                    //Assert.IsTrue(originalBytes.SequenceEqual(newBytes), "File {0} Bytestream content must equal", file);
                }
            }

            Assert.IsTrue(convertDiffers.Count > 0, "");
            Assert.IsTrue(badList.Count > 0, "");
        }
Esempio n. 18
0
        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.");
        }
Esempio n. 19
0
        public void InitTest()
        {
            try
            {
                SpaceEngineersCore.LoadDefinitions();
            }
#pragma warning disable 168
            // For debugging tests.
            catch (Exception ex)
#pragma warning restore 168
            {
                throw;
            }
        }
Esempio n. 20
0
        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);
                }
            }
        }
Esempio n. 21
0
        public void VoxelMaterialIndexes()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();

            Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");

            for (byte i = 0; i < materials.Count; i++)
            {
                Assert.AreEqual(i, SpaceEngineersCore.Resources.GetMaterialIndex(materials[i].Id.SubtypeId), "Material index should equal original.");
            }

            Assert.AreEqual(0xFF, SpaceEngineersCore.Resources.GetMaterialIndex("blaggg"), "Material index should not exist.");
        }
Esempio n. 22
0
        public void VoxelConvertToVolmeticOdd()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();

            var stoneMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Stone"));

            Assert.IsNotNull(stoneMaterial, "Stone material should exist.");

            var modelFile       = @".\TestAssets\Sphere_Gold.3ds";
            var scale           = new ScaleTransform3D(5, 5, 5);
            var rotateTransform = MeshHelper.TransformVector(new System.Windows.Media.Media3D.Vector3D(0, 0, 0), 0, 0, 0);
            var traceType       = SEToolbox.Interop.Asteroids.TraceType.Odd;
            var traceCount      = SEToolbox.Interop.Asteroids.TraceCount.Trace5;
            var traceDirection  = SEToolbox.Interop.Asteroids.TraceDirection.XYZ;

            var asteroidFile = @".\TestOutput\test_sphere_odd.vx2";

            var model  = MeshHelper.Load(modelFile, ignoreErrors: true);
            var meshes = new List <SEToolbox.Interop.Asteroids.MyVoxelRayTracer.MyMeshModel>();

            foreach (var model3D in model.Children)
            {
                var gm       = (GeometryModel3D)model3D;
                var geometry = gm.Geometry as MeshGeometry3D;

                if (geometry != null)
                {
                    meshes.Add(new MyVoxelRayTracer.MyMeshModel(new[] { geometry }, stoneMaterial.Id.SubtypeId, stoneMaterial.Id.SubtypeId));
                }
            }

            var voxelMap = MyVoxelRayTracer.ReadModelAsteroidVolmetic(model, meshes, scale, rotateTransform, traceType, traceCount, traceDirection,
                                                                      ResetProgress, IncrementProgress, null, CompleteProgress);

            voxelMap.Save(asteroidFile);

            Assert.IsTrue(File.Exists(asteroidFile), "Generated file must exist");

            var voxelFileLength = new FileInfo(asteroidFile).Length;

            Assert.AreEqual(2133, voxelFileLength, "File size must match.");
            Assert.AreEqual(new Vector3I(64, 64, 64), voxelMap.Size, "Voxel Bounding size must match.");
            Assert.AreEqual(new Vector3I(25, 25, 25), voxelMap.BoundingContent.SizeInt() + 1, "Voxel Content size must match.");

            var voxCells = voxelMap.SumVoxelCells();

            Assert.AreEqual(2031782, voxCells, "Voxel cells must match.");
        }
Esempio n. 23
0
        public void Load(MyPositionAndOrientation characterPosition)
        {
            CharacterPosition = characterPosition;

            var vms         = SpaceEngineersCore.Resources.Definitions.VoxelMapStorages;
            var contentPath = ToolboxUpdater.GetApplicationContentPath();

            foreach (var voxelMap in vms)
            {
                var fileName = SpaceEngineersCore.GetDataPathOrDefault(voxelMap.StorageFile, Path.Combine(contentPath, voxelMap.StorageFile));

                if (!File.Exists(fileName))
                {
                    continue;
                }

                var voxel = new GenerateVoxelDetailModel
                {
                    Name           = Path.GetFileNameWithoutExtension(voxelMap.StorageFile),
                    SourceFilename = fileName,
                    FileSize       = new FileInfo(fileName).Length,
                    Size           = MyVoxelMap.LoadVoxelSize(fileName)
                };
                VoxelFileList.Add(voxel);
            }

            // Custom voxel files directory.
            List <string> files = new List <string>();

            if (!string.IsNullOrEmpty(GlobalSettings.Default.CustomVoxelPath) && Directory.Exists(GlobalSettings.Default.CustomVoxelPath))
            {
                files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V1FileExtension));
                files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V2FileExtension));
            }

            VoxelFileList.AddRange(files.Select(file => new GenerateVoxelDetailModel
            {
                Name           = Path.GetFileNameWithoutExtension(file),
                SourceFilename = file,
                FileSize       = new FileInfo(file).Length,
                Size           = MyVoxelMap.LoadVoxelSize(file)
            }));


            VoxelFileList = VoxelFileList.OrderBy(s => s.Name).ToList();
        }
Esempio n. 24
0
        public StructureVoxelModel(MyObjectBuilder_EntityBase entityBase, string voxelPath)
            : base(entityBase)
        {
            var contentPath = ToolboxUpdater.GetApplicationContentPath();

            if (voxelPath != null)
            {
                VoxelFilepath = Path.Combine(voxelPath, Name + MyVoxelMap.V2FileExtension);
                var previewFile = VoxelFilepath;

                if (!File.Exists(VoxelFilepath))
                {
                    var oldFilepath = Path.Combine(voxelPath, Name + MyVoxelMap.V1FileExtension);
                    if (File.Exists(oldFilepath))
                    {
                        SourceVoxelFilepath = oldFilepath;
                        previewFile         = oldFilepath;
                        SpaceEngineersCore.ManageDeleteVoxelList.Add(oldFilepath);
                    }
                }

                // Has a huge upfront loading cost
                //ReadVoxelDetails(previewFile);
            }

            var materialList = new Dictionary <string, string>();

            foreach (MyVoxelMaterialDefinition item in SpaceEngineersCore.Resources.VoxelMaterialDefinitions.OrderBy(m => m.Id.SubtypeName))
            {
                string texture = item.GetVoxelDisplayTexture();
                materialList.Add(item.Id.SubtypeName, texture == null ? null : SpaceEngineersCore.GetDataPathOrDefault(texture, Path.Combine(contentPath, texture)));
            }

            GameMaterialList = new List <VoxelMaterialAssetModel>(materialList.Select(m => new VoxelMaterialAssetModel {
                MaterialName = m.Key, DisplayName = m.Key, TextureFile = m.Value
            }));
            EditMaterialList = new List <VoxelMaterialAssetModel> {
                new VoxelMaterialAssetModel {
                    MaterialName = null, DisplayName = Res.CtlVoxelMnuRemoveMaterial
                }
            };
            EditMaterialList.AddRange(materialList.Select(m => new VoxelMaterialAssetModel {
                MaterialName = m.Key, DisplayName = m.Key, TextureFile = m.Value
            }));
        }
Esempio n. 25
0
        private InventoryModel CreateItem(MyObjectBuilder_InventoryItem item, string contentPath)
        {
            var definition = SpaceEngineersApi.GetDefinition(item.Content.TypeId, item.Content.SubtypeName) as MyObjectBuilder_PhysicalItemDefinition;

            string name;
            string textureFile;
            double massMultiplyer;
            double volumeMultiplyer;

            if (definition == null)
            {
                name             = item.Content.SubtypeName + " " + item.Content.TypeId.ToString();
                massMultiplyer   = 1;
                volumeMultiplyer = 1;
                textureFile      = null;
            }
            else
            {
                name             = definition.DisplayName;
                massMultiplyer   = definition.Mass;
                volumeMultiplyer = definition.Volume.Value;
                textureFile      = SpaceEngineersCore.GetDataPathOrDefault(definition.Icon, Path.Combine(contentPath, definition.Icon));
            }

            var newItem = new InventoryModel(item)
            {
                Name             = name,
                Amount           = (decimal)item.Amount,
                SubtypeId        = item.Content.SubtypeName,
                TypeId           = item.Content.TypeId,
                MassMultiplyer   = massMultiplyer,
                VolumeMultiplyer = volumeMultiplyer,
                TextureFile      = textureFile,
                IsUnique         = item.Content.TypeId == SpaceEngineersTypes.PhysicalGunObject || item.Content.TypeId == SpaceEngineersTypes.OxygenContainerObject,
                IsInteger        = item.Content.TypeId == SpaceEngineersTypes.Component || item.Content.TypeId == SpaceEngineersTypes.AmmoMagazine,
                IsDecimal        = item.Content.TypeId == SpaceEngineersTypes.Ore || item.Content.TypeId == SpaceEngineersTypes.Ingot,
                Exists           = definition != null, // item no longer exists in Space Engineers definitions.
            };

            TotalVolume += newItem.Volume;
            TotalMass   += newItem.Mass;

            return(newItem);
        }
Esempio n. 26
0
        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.");
        }
Esempio n. 27
0
        public void VoxelLoadSaveVox()
        {
            SpaceEngineersCore.LoadDefinitions();
            var materials = SpaceEngineersCore.Resources.GetMaterialList();

            Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");

            const string fileOriginal = @".\TestAssets\asteroid0moon4.vox";
            const string fileNew      = @".\TestOutput\asteroid0moon4_save.vox";

            var voxelMap = new MyVoxelMap();

            voxelMap.Load(fileOriginal, materials[0].Id.SubtypeId);
            voxelMap.Save(fileNew);

            var lengthOriginal = new FileInfo(fileOriginal).Length;
            var lengthNew      = new FileInfo(fileNew).Length;

            Assert.AreEqual(9428, lengthOriginal, "File size must match.");
            Assert.AreEqual(9428, lengthNew, "File size must match.");
        }
        public void ReplaceCubesExecuted()
        {
            var model  = new SelectCubeModel();
            var loadVm = new SelectCubeViewModel(this, model);

            model.Load(GridSize, SelectedCubeItem.Cube.TypeId, SelectedCubeItem.SubtypeId);
            var result = _dialogService.ShowDialog <WindowSelectCube>(this, loadVm);

            if (result == true)
            {
                MainViewModel.IsBusy = true;
                var contentPath = ToolboxUpdater.GetApplicationContentPath();
                var change      = false;
                MainViewModel.ResetProgress(0, Selections.Count);

                foreach (var cube in Selections)
                {
                    MainViewModel.Progress++;
                    if (cube.TypeId != model.CubeItem.TypeId || cube.SubtypeId != model.CubeItem.SubtypeId)
                    {
                        var idx = DataModel.CubeGrid.CubeBlocks.IndexOf(cube.Cube);
                        DataModel.CubeGrid.CubeBlocks.RemoveAt(idx);

                        var cubeDefinition = SpaceEngineersApi.GetCubeDefinition(model.CubeItem.TypeId, GridSize, model.CubeItem.SubtypeId);
                        var newCube        = cube.CreateCube(model.CubeItem.TypeId, model.CubeItem.SubtypeId, cubeDefinition);
                        cube.TextureFile = SpaceEngineersCore.GetDataPathOrDefault(cubeDefinition.Icon, Path.Combine(contentPath, cubeDefinition.Icon));
                        DataModel.CubeGrid.CubeBlocks.Insert(idx, newCube);

                        change = true;
                    }
                }

                MainViewModel.ClearProgress();
                if (change)
                {
                    MainViewModel.IsModified = true;
                }
                MainViewModel.IsBusy = false;
            }
        }
Esempio n. 29
0
        public void ApiInterop()
        {
            SpaceEngineersCore.LoadDefinitions();

            var d1 = SpaceEngineersApi.GetCubeDefinition(new MyObjectBuilderType(typeof(MyObjectBuilder_GravityGenerator)), MyCubeSize.Large, "");

            Assert.AreEqual("DisplayName_Block_GravityGenerator", d1.DisplayName, "Must match");
            Assert.AreEqual(MyCubeSize.Large, d1.CubeSize, "Must match");

            var d2 = SpaceEngineersApi.GetCubeDefinition(new MyObjectBuilderType(typeof(MyObjectBuilder_GravityGenerator)), MyCubeSize.Small, "");

            Assert.IsNull(d2, "Must be null");

            var d3 = SpaceEngineersApi.GetCubeDefinition(new MyObjectBuilderType(typeof(MyObjectBuilder_Gyro)), MyCubeSize.Small, "SmallBlockGyro");

            Assert.AreEqual("DisplayName_Block_Gyroscope", d3.DisplayName, "Must match");
            Assert.AreEqual(MyCubeSize.Small, d3.CubeSize, "Must match");

            var d4 = SpaceEngineersApi.GetCubeDefinition(new MyObjectBuilderType(typeof(MyObjectBuilder_Gyro)), MyCubeSize.Small, "Fake");

            Assert.IsNull(d4, "Must be null");
        }
Esempio n. 30
0
        public void LoadAllVoxelFiles()
        {
            SpaceEngineersCore.LoadDefinitions();

            var files = Directory.GetFiles(Path.Combine(ToolboxUpdater.GetApplicationContentPath(), "VoxelMaps"), "*.vx2");

            foreach (var filename in files)
            {
                var voxelMap = new MyVoxelMap();
                voxelMap.Load(filename, SpaceEngineersCore.Resources.GetDefaultMaterialName(), true);

                Assert.IsTrue(voxelMap.Size.X > 0, "Voxel Size must be greater than zero.");
                Assert.IsTrue(voxelMap.Size.Y > 0, "Voxel Size must be greater than zero.");
                Assert.IsTrue(voxelMap.Size.Z > 0, "Voxel Size must be greater than zero.");

                Debug.WriteLine(string.Format("Filename:\t{0}.vx2", Path.GetFileName(filename)));
                Debug.WriteLine(string.Format("Bounding Size:\t{0} × {1} × {2} blocks", voxelMap.Size.X, voxelMap.Size.Y, voxelMap.Size.Z));
                Debug.WriteLine(string.Format("Size:\t{0} m × {1} m × {2} m", voxelMap.BoundingContent.SizeInt().X + 1, voxelMap.BoundingContent.SizeInt().Y + 1, voxelMap.BoundingContent.SizeInt().Z + 1));
                Debug.WriteLine(string.Format("Volume:\t{0:##,###.00} m³", (double)voxelMap.SumVoxelCells() / 255));
                Debug.WriteLine("");
            }
        }