SetAllVoxelContents() 공개 메소드

public SetAllVoxelContents ( byte buffer, BoundingBoxD &bounding ) : void
buffer byte
bounding BoundingBoxD
리턴 void
예제 #1
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();
                        }
                    }
                }
            }
        }