SEToolbox.Interop.Asteroids.MyVoxelMap.CalculateMaterialCellAssets C# (CSharp) Method

CalculateMaterialCellAssets() public method

public CalculateMaterialCellAssets ( IList &materialAssetList, long>.Dictionary &materialVoxelCells ) : void
materialAssetList IList
materialVoxelCells long>.Dictionary
return void
        public void CalculateMaterialCellAssets(out IList<byte> materialAssetList, out Dictionary<byte, long> materialVoxelCells)
        {
            materialAssetList = new List<byte>();
            materialVoxelCells = new Dictionary<byte, long>();
            Vector3I cellCoord;

            for (cellCoord.X = 0; cellCoord.X < _dataCellsCount.X; cellCoord.X++)
            {
                for (cellCoord.Y = 0; cellCoord.Y < _dataCellsCount.Y; cellCoord.Y++)
                {
                    for (cellCoord.Z = 0; cellCoord.Z < _dataCellsCount.Z; cellCoord.Z++)
                    {
                        var voxelCell = _voxelContentCells[cellCoord.X][cellCoord.Y][cellCoord.Z];
                        var matCell = _voxelMaterialCells[cellCoord.X][cellCoord.Y][cellCoord.Z];

                        if (voxelCell == null)
                        {
                            //  Voxel wasn't found in cell dictionary, so cell must be FULL
                            if (matCell.IsSingleMaterialForWholeCell)
                            {
                                for (var i = 0; i < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_TOTAL; i++)
                                {
                                    materialAssetList.Add(matCell.SingleMaterial);

                                    if (materialVoxelCells.ContainsKey(matCell.SingleMaterial))
                                        materialVoxelCells[matCell.SingleMaterial] += MyVoxelConstants.VOXEL_CONTENT_FULL;
                                    else
                                        materialVoxelCells.Add(matCell.SingleMaterial, MyVoxelConstants.VOXEL_CONTENT_FULL);
                                }
                            }
                            else
                            {
                                // A full cell, with mixed materials.
                                Vector3I voxelCoordInCell;
                                for (voxelCoordInCell.X = 0; voxelCoordInCell.X < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.X++)
                                {
                                    for (voxelCoordInCell.Y = 0; voxelCoordInCell.Y < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Y++)
                                    {
                                        for (voxelCoordInCell.Z = 0; voxelCoordInCell.Z < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Z++)
                                        {
                                            var material = matCell.GetMaterial(ref voxelCoordInCell);
                                            materialAssetList.Add(material);

                                            if (materialVoxelCells.ContainsKey(material))
                                                materialVoxelCells[material] += MyVoxelConstants.VOXEL_CONTENT_FULL;
                                            else
                                                materialVoxelCells.Add(material, MyVoxelConstants.VOXEL_CONTENT_FULL);
                                        }
                                    }
                                }
                            }
                        }
                        else if (voxelCell.CellType == MyVoxelCellType.MIXED)
                        {
                            if (matCell.IsSingleMaterialForWholeCell)
                            {
                                // a mixed cell, with one material.
                                Vector3I voxelCoordInCell;
                                for (voxelCoordInCell.X = 0; voxelCoordInCell.X < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.X++)
                                {
                                    for (voxelCoordInCell.Y = 0; voxelCoordInCell.Y < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Y++)
                                    {
                                        for (voxelCoordInCell.Z = 0; voxelCoordInCell.Z < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Z++)
                                        {
                                            var content = voxelCell.GetVoxelContent(ref voxelCoordInCell);

                                            if (content != MyVoxelConstants.VOXEL_CONTENT_EMPTY)
                                            {
                                                materialAssetList.Add(matCell.SingleMaterial);

                                                if (materialVoxelCells.ContainsKey(matCell.SingleMaterial))
                                                    materialVoxelCells[matCell.SingleMaterial] += content;
                                                else
                                                    materialVoxelCells.Add(matCell.SingleMaterial, content);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // A mixed cell, with mixed materials.
                                Vector3I voxelCoordInCell;
                                for (voxelCoordInCell.X = 0; voxelCoordInCell.X < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.X++)
                                {
                                    for (voxelCoordInCell.Y = 0; voxelCoordInCell.Y < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Y++)
                                    {
                                        for (voxelCoordInCell.Z = 0; voxelCoordInCell.Z < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Z++)
                                        {
                                            var content = voxelCell.GetVoxelContent(ref voxelCoordInCell);

                                            if (content != MyVoxelConstants.VOXEL_CONTENT_EMPTY)
                                            {
                                                var material = matCell.GetMaterial(ref voxelCoordInCell);
                                                materialAssetList.Add(material);

                                                if (materialVoxelCells.ContainsKey(material))
                                                    materialVoxelCells[material] += content;
                                                else
                                                    materialVoxelCells.Add(material, content);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

Usage Example

Ejemplo n.º 1
0
        public void FillAsteroid(MyVoxelMap asteroid, IMyVoxelFillProperties fillProperties)
        {
            var properties = (AsteroidByteFillProperties)fillProperties;

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

            asteroid.CalculateMaterialCellAssets(out baseAssets, out materialVoxelCells);

            var distribution = new List<double> { Double.NaN };
            var materialSelection = new List<byte> { SpaceEngineersCore.Resources.GetMaterialIndex(properties.MainMaterial.Value) };

            if (properties.SecondPercent > 0)
            {
                distribution.Add((double)properties.SecondPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.SecondMaterial.Value));
            }
            if (properties.ThirdPercent > 0)
            {
                distribution.Add((double)properties.ThirdPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.ThirdMaterial.Value));
            }
            if (properties.FourthPercent > 0)
            {
                distribution.Add((double)properties.FourthPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.FourthMaterial.Value));
            }
            if (properties.FifthPercent > 0)
            {
                distribution.Add((double)properties.FifthPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.FifthMaterial.Value));
            }
            if (properties.SixthPercent > 0)
            {
                distribution.Add((double)properties.SixthPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.SixthMaterial.Value));
            }
            if (properties.SeventhPercent > 0)
            {
                distribution.Add((double)properties.SeventhPercent / 100);
                materialSelection.Add(SpaceEngineersCore.Resources.GetMaterialIndex(properties.SeventhMaterial.Value));
            }

            var newDistributiuon = new List<byte>();
            int count;
            for (var i = 1; i < distribution.Count(); i++)
            {
                count = (int)Math.Floor(distribution[i] * baseAssets.Count); // Round down.
                for (var j = 0; j < count; j++)
                {
                    newDistributiuon.Add(materialSelection[i]);
                }
            }
            count = baseAssets.Count - newDistributiuon.Count;
            for (var j = 0; j < count; j++)
            {
                newDistributiuon.Add(materialSelection[0]);
            }

            newDistributiuon.Shuffle();
            asteroid.SetMaterialAssets(newDistributiuon);
            //asteroid.ForceVoxelFaceMaterial(_dataModel.BaseMaterial.DisplayName);
        }
All Usage Examples Of SEToolbox.Interop.Asteroids.MyVoxelMap::CalculateMaterialCellAssets