SEToolbox.Models.GenerateVoxelFieldModel.Load C# (CSharp) Method

Load() public method

public Load ( VRage.MyPositionAndOrientation characterPosition ) : void
characterPosition VRage.MyPositionAndOrientation
return void
        public void Load(MyPositionAndOrientation characterPosition)
        {
            if (!_isInitialValueSet)
            {
                // only set the position first time opened and cache.
                CenterPositionX = characterPosition.Position.X;
                CenterPositionY = characterPosition.Position.Y;
                CenterPositionZ = characterPosition.Position.Z;
                AsteroidFillType = AsteroidFillType.ByteFiller;
                _isInitialValueSet = true;
            }

            MaterialsCollection.Clear();
            foreach (var material in SpaceEngineersCore.Resources.VoxelMaterialDefinitions)
            {
                MaterialsCollection.Add(new MaterialSelectionModel { Value = material.Id.SubtypeName, DisplayName = material.Id.SubtypeName, IsRare = material.IsRare, MinedRatio = material.MinedOreRatio });
            }

            BaseMaterial = MaterialsCollection.FirstOrDefault(m => m.IsRare == false) ?? MaterialsCollection.FirstOrDefault();

            // Voxel Map Storage, includes stock and mod asteroids.
            var vms = SpaceEngineersCore.Resources.VoxelMapStorageDefinitions;
            var contentPath = ToolboxUpdater.GetApplicationContentPath();
            var list = new List<GenerateVoxelDetailModel>();

            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)
                };
                list.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));
 	        }

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

            VoxelFileList = new ObservableCollection<GenerateVoxelDetailModel>(list.OrderBy(s => s.Name));

            // Set up a default start.
            if (VoxelStore.Count == 0)
            {
                VoxelCollection.Add(NewDefaultVoxel(1));
            }
            else
            {
                foreach (var item in VoxelStore)
                {
                    var v1 = (AsteroidByteFillProperties)item.Clone();
                    v1.VoxelFile = VoxelFileList.FirstOrDefault(v => v.Name == v1.VoxelFile.Name);
                    v1.MainMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.MainMaterial.DisplayName);
                    v1.SecondMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.SecondMaterial.DisplayName);
                    v1.ThirdMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.ThirdMaterial.DisplayName);
                    v1.FourthMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.FourthMaterial.DisplayName);
                    v1.FifthMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.FifthMaterial.DisplayName);
                    v1.SixthMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.SixthMaterial.DisplayName);
                    v1.SeventhMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.SeventhMaterial.DisplayName);
                    VoxelCollection.Add(v1);
                }
                RenumberCollection();
            }

            for (var i = 0; i < 100; i++)
            {
                PercentList.Add(i);
            }
        }

Usage Example

コード例 #1
0
        public void GenerateVoxelFieldExecuted()
        {
            var model = new GenerateVoxelFieldModel();
            var position = ThePlayerCharacter != null ? ThePlayerCharacter.PositionAndOrientation.Value : new MyPositionAndOrientation(Vector3D.Zero, Vector3.Forward, Vector3.Up);
            model.Load(position);
            var loadVm = new GenerateVoxelFieldViewModel(this, model);

            var result = _dialogService.ShowDialog<WindowGenerateVoxelField>(this, loadVm);
            model.Unload();
            if (result == true)
            {
                IsBusy = true;
                string[] sourceVoxelFiles;
                MyObjectBuilder_EntityBase[] newEntities;
                loadVm.BuildEntities(out sourceVoxelFiles, out newEntities);
                _selectNewStructure = true;

                ResetProgress(0, newEntities.Length);

                for (var i = 0; i < newEntities.Length; i++)
                {
                    var structure = _dataModel.AddEntity(newEntities[i]);
                    ((StructureVoxelModel)structure).SourceVoxelFilepath = sourceVoxelFiles[i]; // Set the temporary file location of the Source Voxel, as it hasn't been written yet.
                    Progress++;
                }
                _selectNewStructure = false;
                IsBusy = false;
                ClearProgress();
            }
        }