예제 #1
0
        public void VoxelConvertToVolmeticEven()
        {
            var materials = SpaceEngineersCore.Resources.VoxelMaterialDefinitions;

            // Use anything except for stone for testing, as Stone is a default material, and it shouldn't show up in the test.
            var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeName.Contains("Gold"));

            Assert.IsNotNull(goldMaterial, "Gold 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.Even;
            var traceCount      = SEToolbox.Interop.Asteroids.TraceCount.Trace5;
            var traceDirection  = SEToolbox.Interop.Asteroids.TraceDirection.XYZ;
            var asteroidFile    = @".\TestOutput\test_sphere_even.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 }, goldMaterial.Index, goldMaterial.Index));
                }
            }

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

            voxelMap.Save(asteroidFile);

            Dictionary <string, long> assetNameCount = voxelMap.RefreshAssets();

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

            var voxelFileLength = new FileInfo(asteroidFile).Length;

            Assert.AreEqual(13073, voxelFileLength, "File size must match.");
            Assert.AreEqual(new Vector3I(32, 32, 32), voxelMap.Size, "Voxel Bounding size must match.");
            Assert.AreEqual(new Vector3I(26, 26, 26), voxelMap.BoundingContent.Size + 1, "Voxel Content size must match.");
            Assert.AreEqual(new VRageMath.Vector3D(15.5, 15.5, 15.5), voxelMap.ContentCenter, "Voxel Content Center must match.");

            Assert.AreEqual(2047046, voxelMap.VoxCells, "Voxel cells must match.");

            Assert.AreEqual(1, assetNameCount.Count, "Asset count should be equal.");
            Assert.IsTrue(assetNameCount.ContainsKey(goldMaterial.Id.SubtypeName), $"{goldMaterial.Id.SubtypeName} asset should exist.");
            Assert.AreEqual(2047046, assetNameCount[goldMaterial.Id.SubtypeName], $"{goldMaterial.Id.SubtypeName} count should be equal.");
        }
예제 #2
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.");
        }
예제 #3
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.");
        }
예제 #4
0
        private bool BuildEntity()
        {
            var filenamepart = Path.GetFileNameWithoutExtension(Filename);
            var filename     = MainViewModel.CreateUniqueVoxelStorageName(filenamepart + MyVoxelMap.V2FileExtension);

            double multiplier;

            if (IsMultipleScale)
            {
                multiplier = MultipleScale;
            }
            else
            {
                multiplier = MaxLengthScale / Math.Max(Math.Max(OriginalModelSize.Height, OriginalModelSize.Width), OriginalModelSize.Depth);
            }

            var scale           = new ScaleTransform3D(multiplier, multiplier, multiplier);
            var rotateTransform = MeshHelper.TransformVector(new System.Windows.Media.Media3D.Vector3D(0, 0, 0), -RotateRoll, RotateYaw - 90, RotatePitch + 90);

            SourceFile = TempfileUtil.NewFilename(MyVoxelMap.V2FileExtension);

            var model = MeshHelper.Load(Filename, ignoreErrors: true);

            var meshes      = new List <MyVoxelRayTracer.MyMeshModel>();
            var geometeries = new List <MeshGeometry3D>();

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

                if (geometry != null)
                {
                    geometeries.Add(geometry);
                }
            }
            meshes.Add(new MyVoxelRayTracer.MyMeshModel(geometeries.ToArray(), InsideStockMaterial.MaterialIndex, InsideStockMaterial.MaterialIndex));

            #region handle dialogs and process the conversion

            var doCancel = false;

            var progressModel = new ProgressCancelModel {
                Title = Res.WnProgressTitle, SubTitle = Res.WnProgressTitle, DialogText = Res.WnProgressTxtTimeRemain + " " + Res.WnProgressTxtTimeCalculating
            };
            var progressVm = new ProgressCancelViewModel(this, progressModel);
            progressVm.CloseRequested += delegate(object sender, EventArgs e)
            {
                doCancel = true;
            };

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

            var completedAction = (Action) delegate
            {
                progressVm.Close();
            };

            MyVoxelMap voxelMap = null;

            var action = (Action) delegate
            {
                voxelMap = MyVoxelRayTracer.ReadModelAsteroidVolmetic(model, meshes, scale, rotateTransform, TraceType, TraceCount, TraceDirection,
                                                                      progressModel.ResetProgress, progressModel.IncrementProgress, cancelFunc, completedAction);
            };

            if (RunInLowPrioity)
            {
                System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle;
            }

            _dialogService.ShowDialog <WindowProgressCancel>(this, progressVm, action);

            if (RunInLowPrioity)
            {
                System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Normal;
            }

            #endregion

            if (doCancel || voxelMap == null)
            {
                IsValidEntity = false;
                NewEntity     = null;
            }
            else
            {
                voxelMap.ForceShellMaterial(OutsideStockMaterial.Value, (byte)OutsideMaterialDepth);
                voxelMap.Save(SourceFile);

                var position = VRageMath.Vector3D.Zero;
                var forward  = Vector3.Forward;
                var up       = Vector3.Up;

                if (IsAbsolutePosition)
                {
                    position = Position.ToVector3();
                }
                else if (IsInfrontofPlayer)
                {
                    // Figure out where the Character is facing, and plant the new construct centered in front of the Character, but "BuildDistance" units out in front.
                    var lookVector = (VRageMath.Vector3D)_dataModel.CharacterPosition.Forward.ToVector3();
                    lookVector.Normalize();

                    BoundingBoxD       content = voxelMap.BoundingContent.ToBoundingBoxD();
                    VRageMath.Vector3D?boundingIntersectPoint = content.IntersectsRayAt(content.Center, -lookVector * 5000d);

                    if (!boundingIntersectPoint.HasValue)
                    {
                        boundingIntersectPoint = content.Center;
                    }

                    var distance = VRageMath.Vector3D.Distance(boundingIntersectPoint.Value, content.Center) + (float)BuildDistance;
                    VRageMath.Vector3D vector = lookVector * distance;
                    position = VRageMath.Vector3D.Add(_dataModel.CharacterPosition.Position, vector) - content.Center;
                }

                var entity = new MyObjectBuilder_VoxelMap(position, filename)
                {
                    EntityId        = SpaceEngineersApi.GenerateEntityId(IDType.ASTEROID),
                    PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene,
                    StorageName     = Path.GetFileNameWithoutExtension(filename)
                };

                entity.PositionAndOrientation = new MyPositionAndOrientation
                {
                    Position = position,
                    Forward  = forward,
                    Up       = up
                };

                IsValidEntity = voxelMap.BoundingContent.Size.Volume() > 0;

                NewEntity = entity;

                if (BeepWhenFinished)
                {
                    System.Media.SystemSounds.Asterisk.Play();
                }
            }

            return(!doCancel);
        }
예제 #5
0
        public void VoxelConvertToVolmeticMisc()
        {
            var materials = SpaceEngineersCore.Resources.VoxelMaterialDefinitions;

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

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

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

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

            var silverMaterial = materials.FirstOrDefault(m => m.Id.SubtypeName.Contains("Silver"));

            Assert.IsNotNull(silverMaterial, "Silver material should exist.");

            // Basic test...
            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;

            // Basic model test...
            //var modelFile = @".\TestAssets\TwoSpheres.3ds";
            //var scale = new ScaleTransform3D(5, 5, 5);

            // Scale test...
            //var modelFile = @".\TestAssets\Sphere_Gold.3ds";
            //var scale = new ScaleTransform3D(20, 20, 20);
            //Transform3D rotateTransform = null;

            // Max Scale test...  will cause an OutOfMemory exception at this scale because MSTest runs in x86.
            //var modelFile = @".\TestAssets\Sphere_Gold.3ds";
            //var scale = new ScaleTransform3D(120, 120, 120);
            //Transform3D rotateTransform = null;

            // Memory test (probably won't load in Space Engineers) ...  will cause an OutOfMemory exception at this scale because MSTest runs in x86.
            //var modelFile = @".\TestAssets\Sphere_Gold.3ds";
            //var scale = new ScaleTransform3D(200, 200, 200);

            // Complexity test...
            //var modelFile = @".\TestAssets\buddha-fixed-bottom.stl";
            //var scale = new ScaleTransform3D(0.78, 0.78, 0.78);
            //var rotateTransform = MeshHelper.TransformVector(new Vector3D(0, 0, 0), 180, 0, 0);

            var modelMaterials = new string[] { stoneMaterial.Id.SubtypeName, goldMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName, stoneMaterial.Id.SubtypeName };
            var fillerMaterial = silverMaterial.Id.SubtypeName;
            var asteroidFile   = @".\TestOutput\test_sphere.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.Index, stoneMaterial.Index));
                }
            }

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

            voxelMap.Save(asteroidFile);

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

            var voxelFileLength = new FileInfo(asteroidFile).Length;

            Assert.IsTrue(voxelFileLength > 0, "File must not be empty.");

            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.");

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

            Assert.IsTrue(voxelMap.VoxCells > 0, "voxCells must be greater than zero.");
        }