public MyMwcObjectBuilder_VoxelMap_MergeContent(MyMwcVector3Short positionInVoxelMapInVoxelCoords, MyMwcVoxelFilesEnum voxelFile, MyMwcVoxelMapMergeTypeEnum mergeType) : base() { PositionInVoxelMapInVoxelCoords = positionInVoxelMapInVoxelCoords; VoxelFile = voxelFile; MergeType = mergeType; }
// Read this object from message-in internal override bool Read(BinaryReader binaryReader, EndPoint senderEndPoint, int gameVersion) { if (base.Read(binaryReader, senderEndPoint, gameVersion) == false) return NetworkError(); MyMwcVector3Short? positionInVoxelMapInVoxelCoords = MyMwcMessageIn.ReadVector3ShortEx(binaryReader, senderEndPoint); if (positionInVoxelMapInVoxelCoords == null) return NetworkError(); PositionInVoxelMapInVoxelCoords = positionInVoxelMapInVoxelCoords.Value; MyMwcLog.IfNetVerbose_AddToLog("PositionInVoxelMapInVoxelCoords: " + PositionInVoxelMapInVoxelCoords.ToString()); MyMwcVoxelFilesEnum? voxelFile = MyMwcMessageIn.ReadVoxelFileEnumEx(binaryReader, senderEndPoint); if (voxelFile == null) return NetworkError(); VoxelFile = voxelFile.Value; MyMwcLog.IfNetVerbose_AddToLog("VoxelFile: " + VoxelFile.ToString()); MyMwcVoxelMapMergeTypeEnum? mergeType = MyMwcMessageIn.ReadVoxelMapMergeTypeEnumEx(binaryReader, senderEndPoint); if (mergeType == null) return NetworkError(); MergeType = mergeType.Value; MyMwcLog.IfNetVerbose_AddToLog("VoxelMaterial: " + MergeType.ToString()); return true; }
// Read this object from message-in internal override bool Read(BinaryReader binaryReader, EndPoint senderEndPoint, int gameVersion) { if (base.Read(binaryReader, senderEndPoint, gameVersion) == false) { return(NetworkError()); } MyMwcVector3Short?positionInVoxelMapInVoxelCoords = MyMwcMessageIn.ReadVector3ShortEx(binaryReader, senderEndPoint); if (positionInVoxelMapInVoxelCoords == null) { return(NetworkError()); } PositionInVoxelMapInVoxelCoords = positionInVoxelMapInVoxelCoords.Value; MyMwcLog.IfNetVerbose_AddToLog("PositionInVoxelMapInVoxelCoords: " + PositionInVoxelMapInVoxelCoords.ToString()); MyMwcVoxelFilesEnum?voxelFile = MyMwcMessageIn.ReadVoxelFileEnumEx(binaryReader, senderEndPoint); if (voxelFile == null) { return(NetworkError()); } VoxelFile = voxelFile.Value; MyMwcLog.IfNetVerbose_AddToLog("VoxelFile: " + VoxelFile.ToString()); MyMwcVoxelMapMergeTypeEnum?mergeType = MyMwcMessageIn.ReadVoxelMapMergeTypeEnumEx(binaryReader, senderEndPoint); if (mergeType == null) { return(NetworkError()); } MergeType = mergeType.Value; MyMwcLog.IfNetVerbose_AddToLog("VoxelMaterial: " + MergeType.ToString()); return(true); }
// Not used //public void Reinitialize() //{ // if (m_isClosed) // { // Init(this.Name, this.PositionLeftBottomCorner, (MyMwcObjectBuilder_VoxelMap)this.GetObjectBuilderInternal()); // m_isClosed = false; // } //} // Merges a specified voxel map (from a file) into our actual voxel map at a specified position. // This merging is slower than loading voxel map through constructor (because we are setting voxels through SetVoxelContent) - so use it only // for merging-in small areas. // Parameter 'voxelPosition' - where will be placed new merged voxel map withing actual voxel map. It's in voxel coords. // Voxel map we are trying to merge into existing voxel map can be bigger or outside of area of existing voxel map. This method will just ignore those parts. // Coordinate of 'voxelPosition' DOESN'T NEED to be aligned to data cell (multiplies of 8). public void MergeVoxelContents(MyMwcVoxelFilesEnum voxelFile, MyMwcVector3Short voxelPosition, MyMwcVoxelMapMergeTypeEnum mergeType) { MyCompressionFileLoad decompressFile = new MyCompressionFileLoad(MyVoxelFiles.Get(voxelFile).GetVoxFilePath()); // Version of a VOX file int fileVersion = decompressFile.GetInt32(); // Not supported VOX file version MyCommonDebugUtils.AssertRelease(fileVersion == MyVoxelConstants.VOXEL_FILE_ACTUAL_VERSION); // Size of this voxel map (in voxels) int sizeX = decompressFile.GetInt32(); int sizeY = decompressFile.GetInt32(); int sizeZ = decompressFile.GetInt32(); // Size of data cell in voxels, doesn't have to be same as current size specified by our constants. int cellSizeX = decompressFile.GetInt32(); int cellSizeY = decompressFile.GetInt32(); int cellSizeZ = decompressFile.GetInt32(); int cellsCountX = sizeX / cellSizeX; int cellsCountY = sizeY / cellSizeY; int cellsCountZ = sizeZ / cellSizeZ; MyMwcVector3Int cellCoord; for (cellCoord.X = 0; cellCoord.X < cellsCountX; cellCoord.X++) { for (cellCoord.Y = 0; cellCoord.Y < cellsCountY; cellCoord.Y++) { for (cellCoord.Z = 0; cellCoord.Z < cellsCountZ; cellCoord.Z++) { MyVoxelCellType cellType = (MyVoxelCellType)decompressFile.GetByte(); MyMwcVector3Int cellCoordInVoxels = GetVoxelCoordinatesOfDataCell(ref cellCoord); // Go through every voxel in a cell and change it's value. If cell is empty, set all voxels to empty. Otherwise set by value from file. MyMwcVector3Int voxelCoordInCell; for (voxelCoordInCell.X = 0; voxelCoordInCell.X < cellSizeX; voxelCoordInCell.X++) { for (voxelCoordInCell.Y = 0; voxelCoordInCell.Y < cellSizeY; voxelCoordInCell.Y++) { for (voxelCoordInCell.Z = 0; voxelCoordInCell.Z < cellSizeZ; voxelCoordInCell.Z++) { byte newContent; if (cellType == MyVoxelCellType.EMPTY) { newContent = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else if (cellType == MyVoxelCellType.FULL) { newContent = MyVoxelConstants.VOXEL_CONTENT_FULL; } else { newContent = decompressFile.GetByte(); } MyMwcVector3Int voxelCoord; voxelCoord.X = voxelPosition.X + cellCoordInVoxels.X + voxelCoordInCell.X; voxelCoord.Y = voxelPosition.Y + cellCoordInVoxels.Y + voxelCoordInCell.Y; voxelCoord.Z = voxelPosition.Z + cellCoordInVoxels.Z + voxelCoordInCell.Z; if (IsVoxelInVoxelMap(ref voxelCoord) == true) { byte originalContent = GetVoxelContent(ref voxelCoord); if (mergeType == MyMwcVoxelMapMergeTypeEnum.ADD) { // Set new content only if its value is higher than actual - so we only can add matter if (newContent > originalContent) { SetVoxelContent(newContent, ref voxelCoord); } } else if (mergeType == MyMwcVoxelMapMergeTypeEnum.INVERSE_AND_SUBTRACT) { // Subtract new content from original, so if original voxel is full and new is full too, result will be empty voxel // If new is empty, nothing will happen. If new is full but original is empty, nothing will happen either. SetVoxelContent((byte)MyMwcUtils.GetClampInt((int)originalContent - (int)newContent, MyVoxelConstants.VOXEL_CONTENT_EMPTY, MyVoxelConstants.VOXEL_CONTENT_FULL), ref voxelCoord); } else { throw new MyMwcExceptionApplicationShouldNotGetHere(); } } } } } } } } }
public static void WriteVoxelMapMergeTypeEnum(MyMwcVoxelMapMergeTypeEnum val, BinaryWriter binaryWriter) { binaryWriter.Write((byte)val); }