SetToEmpty() public method

public SetToEmpty ( ) : void
return void
Exemplo n.º 1
0
        public void RemoveContent(string materialName, string replaceFillMaterial)
        {
            var materialIndex = SpaceEngineersCore.Resources.GetMaterialIndex(materialName);
            var replaceMaterialIndex = materialIndex;
            if (!string.IsNullOrEmpty(replaceFillMaterial))
                replaceMaterialIndex = SpaceEngineersCore.Resources.GetMaterialIndex(replaceFillMaterial);
            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)
                            {
                                if (matCell.SingleMaterial == materialIndex)
                                {
                                    var newCell = new MyVoxelContentCell();
                                    _voxelContentCells[cellCoord.X][cellCoord.Y][cellCoord.Z] = newCell;
                                    newCell.SetToEmpty();
                                    matCell.Reset(replaceMaterialIndex, 0xff);
                                }
                            }
                            else
                            {
                                // A full cell, with mixed materials.
                                Vector3I voxelCoordInCell;
                                MyVoxelContentCell newCell = null;

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

                                            if (material == materialIndex)
                                            {
                                                if (newCell == null)
                                                {
                                                    newCell = new MyVoxelContentCell();
                                                    _voxelContentCells[cellCoord.X][cellCoord.Y][cellCoord.Z] = newCell;
                                                }

                                                newCell.SetVoxelContent(0x00, ref voxelCoordInCell);
                                                matCell.SetMaterialAndIndestructibleContent(replaceMaterialIndex, 0xff, ref voxelCoordInCell);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else if (voxelCell.CellType == MyVoxelCellType.MIXED)
                        {
                            if (matCell.IsSingleMaterialForWholeCell)
                            {
                                if (matCell.SingleMaterial == materialIndex)
                                {
                                    voxelCell.SetToEmpty();
                                    matCell.Reset(replaceMaterialIndex, 0xff);
                                }
                            }
                            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 material = matCell.GetMaterial(ref voxelCoordInCell);

                                            if (material == materialIndex)
                                            {
                                                voxelCell.SetVoxelContent(0x00, ref voxelCoordInCell);
                                                matCell.SetMaterialAndIndestructibleContent(replaceMaterialIndex, 0xff, ref voxelCoordInCell);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void LoadUncompressedV2(BinaryReader reader, bool loadMaterial, int materialBaseCount)
        {
            var materialIndexDict = new Dictionary<byte, byte>();
            for (byte i = 0; i < materialBaseCount; i++)
            {
                var idx = reader.ReadByte();
                var materialName = reader.ReadString();
                var resourceIdx = SpaceEngineersCore.Resources.GetMaterialIndex(materialName);
                materialIndexDict.Add(idx, resourceIdx);
            }

            var cellsCount = Size / _cellSize;

            for (var x = 0; x < cellsCount.X; x++)
            {
                for (var y = 0; y < cellsCount.Y; y++)
                {
                    for (var z = 0; z < cellsCount.Z; z++)
                    {
                        var cellType = (MyVoxelCellType)reader.ReadByte();

                        //  Cell's are FULL by default, therefore we don't need to change them
                        if (cellType != MyVoxelCellType.FULL)
                        {
                            var cellCoord = new Vector3I(x, y, z);
                            var newCell = new MyVoxelContentCell();
                            _voxelContentCells[cellCoord.X][cellCoord.Y][cellCoord.Z] = newCell;

                            if (cellType == MyVoxelCellType.EMPTY)
                            {
                                newCell.SetToEmpty();
                            }
                            else if (cellType == MyVoxelCellType.MIXED)
                            {
                                BoundingBoxD box;
                                newCell.SetAllVoxelContents(reader.ReadBytes(_cellSize.X * _cellSize.Y * _cellSize.Z), out box);
                                _boundingContent.Min = Vector3D.Min(_boundingContent.Min, new Vector3D((x << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS) + box.Min.X, (y << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS) + box.Min.Y, (z << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS) + box.Min.Z));
                                _boundingContent.Max = Vector3D.Max(_boundingContent.Max, new Vector3D((x << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS) + box.Max.X, (y << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS) + box.Max.Y, (z << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS) + box.Max.Z));
                            }
                            // ignore else condition
                        }
                        else
                        {
                            _boundingContent.Min = Vector3D.Min(_boundingContent.Min, new Vector3D(x << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS, y << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS, z << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS));
                            _boundingContent.Max = Vector3D.Max(_boundingContent.Max, new Vector3D((x + 1 << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS) - 1, (y + 1 << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS) - 1, (z + 1 << MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS) - 1));
                        }
                    }
                }
            }

            if (reader.PeekChar() == -1 || !loadMaterial)
            {
                return;
            }

            // Read materials.
            const byte indestructibleContent = 0xff;
            for (var x = 0; x < cellsCount.X; x++)
            {
                for (var y = 0; y < cellsCount.Y; y++)
                {
                    for (var z = 0; z < cellsCount.Z; z++)
                    {
                        var matCell = _voxelMaterialCells[x][y][z];

                        var materialCount = reader.ReadByte();

                        if (materialCount == (byte)MyVoxelCellType.FULL)
                        {
                            var materialIndex = reader.ReadByte();
                            matCell.Reset(materialIndexDict[materialIndex], indestructibleContent);
                        }
                        else
                        {
                            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 materialIndex = reader.ReadByte();
                                        materialCount = reader.ReadByte();
                                        matCell.SetMaterialAndIndestructibleContent(materialIndexDict[materialIndex], indestructibleContent, ref voxelCoordInCell);
                                    }
                                }
                            }
                            matCell.CalcAverageCellMaterial();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void RemoveContent()
        {
            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];

                        if (voxelCell == null)
                        {
                            var newCell = new MyVoxelContentCell();
                            _voxelContentCells[cellCoord.X][cellCoord.Y][cellCoord.Z] = newCell;
                            newCell.SetToEmpty();
                        }
                        else if (voxelCell.CellType == MyVoxelCellType.MIXED)
                        {
                            // A mixed cell.
                            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++)
                                    {
                                        voxelCell.SetVoxelContent(0x00, ref voxelCoordInCell);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }