//  Checks if cell didn't change to FULL and if is, we set it to null
 private void CheckIfCellChangedToFull(MyVoxelContentCell voxelCell, ref Vector3I cellCoord)
 {
     if (voxelCell.CellType == MyVoxelRangeType.FULL)
     {
         m_contentCells[ComputeCellIndex(ref cellCoord)] = null;
     }
 }
        private void ReadRange(
            MyStorageDataCache target,
            MyVoxelContentCell cell,
            ref Vector3I startInCell,
            ref Vector3I endInCell,
            ref Vector3I writeOffset)
        {
            Vector3I coordInCell;
            Vector3I writeCoord;
            byte? cellValue = null;
            if (cell == null || cell.CellType == MyVoxelRangeType.FULL)
            {
                cellValue = MyVoxelConstants.VOXEL_CONTENT_FULL;
            }
            else if (cell != null && cell.CellType == MyVoxelRangeType.EMPTY)
            {
                cellValue = MyVoxelConstants.VOXEL_CONTENT_EMPTY;
            }
            var offset = writeOffset + startInCell;

            if (cellValue.HasValue)
            { // write same value everywhere
                var value = cellValue.Value;
                for (coordInCell.Z = startInCell.Z, writeCoord.Z = offset.Z; coordInCell.Z <= endInCell.Z; ++coordInCell.Z, ++writeCoord.Z)
                {
                    for (coordInCell.Y = startInCell.Y, writeCoord.Y = offset.Y; coordInCell.Y <= endInCell.Y; ++coordInCell.Y, ++writeCoord.Y)
                    {
                        for (coordInCell.X = startInCell.X, writeCoord.X = offset.X; coordInCell.X <= endInCell.X; ++coordInCell.X, ++writeCoord.X)
                        {
                            target.Content(ref writeCoord, value);
                        }
                    }
                }
            }
            else
            { // read value for each voxel
                for (coordInCell.Z = startInCell.Z, writeCoord.Z = offset.Z; coordInCell.Z <= endInCell.Z; ++coordInCell.Z, ++writeCoord.Z)
                {
                    for (coordInCell.Y = startInCell.Y, writeCoord.Y = offset.Y; coordInCell.Y <= endInCell.Y; ++coordInCell.Y, ++writeCoord.Y)
                    {
                        for (coordInCell.X = startInCell.X, writeCoord.X = offset.X; coordInCell.X <= endInCell.X; ++coordInCell.X, ++writeCoord.X)
                        {
                            target.Content(ref writeCoord, cell.GetContent(ref coordInCell));
                        }
                    }
                }
            }
        }
        private MyVoxelContentCell AddCell(ref Vector3I cellCoord)
        {
            //  Adding or creating cell can be made only once
            Debug.Assert(GetContentCell(ref cellCoord) == null);

            MyVoxelContentCell ret = new MyVoxelContentCell();
            m_contentCells[ComputeCellIndex(ref cellCoord)] = ret;

            return ret;
        }
        private MyVoxelRangeType GetRangeTypeInCell(MyVoxelContentCell contentCell, ref Vector3I startInCell, ref Vector3I endInCell)
        {
            Vector3I c = Vector3I.Zero;
            bool foundFull = false, foundEmpty = false;
            for (c.Z = startInCell.Z; c.Z <= endInCell.Z; ++c.Z)
            {
                for (c.Y = startInCell.Y; c.Y <= endInCell.Y; ++c.Y)
                {
                    for (c.X = startInCell.X; c.X <= endInCell.X; ++c.X)
                    {
                        var content = contentCell.GetContent(ref c);
                        if (content >= MyVoxelConstants.VOXEL_CONTENT_FULL)
                            foundFull = true;
                        else if (content <= MyVoxelConstants.VOXEL_CONTENT_EMPTY)
                            foundEmpty = true;
                        else
                            return MyVoxelRangeType.MIXED;

                        if (foundFull && foundEmpty)
                            return MyVoxelRangeType.MIXED;
                    }
                }
            }
            Debug.Assert(foundFull != foundEmpty);
            return foundFull ? MyVoxelRangeType.FULL : MyVoxelRangeType.EMPTY;
        }