public MyMwcObjectBuilder_VoxelMap(Vector3 position, MyMwcVoxelFilesEnum voxelFile, MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     PositionAndOrientation.Position = position;
     VoxelFile = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
示例#2
0
 public MyMwcObjectBuilder_VoxelMap(Vector3 position, MyMwcVoxelFilesEnum voxelFile, MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     PositionAndOrientation.Position = position;
     VoxelFile     = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
        //  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();

            MyMwcVector3Sbyte? relativeSectorPosition = MyMwcMessageIn.ReadVector3SbyteEx(binaryReader, senderEndPoint);
            if (relativeSectorPosition == null) return NetworkError();
            RelativeSectorPosition = relativeSectorPosition.Value;
            MyMwcLog.IfNetVerbose_AddToLog("RelativeSectorPosition: " + RelativeSectorPosition.ToString());

            MyMwcVector3Short? voxelMapPositionInVoxelCoords = MyMwcMessageIn.ReadVector3ShortEx(binaryReader, senderEndPoint);
            if (voxelMapPositionInVoxelCoords == null) return NetworkError();
            VoxelMapPositionInVoxelCoords = voxelMapPositionInVoxelCoords.Value;
            MyMwcLog.IfNetVerbose_AddToLog("VoxelMapPositionInVoxelCoords: " + VoxelMapPositionInVoxelCoords.ToString());

            MyMwcVoxelFilesEnum? voxelFile = MyMwcMessageIn.ReadVoxelFileEnumEx(binaryReader, senderEndPoint);
            if (voxelFile == null) return NetworkError();
            VoxelFile = voxelFile.Value;
            MyMwcLog.IfNetVerbose_AddToLog("VoxelFile: " + VoxelFile.ToString());

            MyMwcVoxelMaterialsEnum? voxelMaterial = MyMwcMessageIn.ReadVoxelMaterialsEnumEx(binaryReader, senderEndPoint);
            if (voxelMaterial == null) return NetworkError();
            VoxelMaterial = voxelMaterial.Value;
            MyMwcLog.IfNetVerbose_AddToLog("VoxelMaterial: " + VoxelMaterial.ToString());

            return true;
        }
 public MyMwcObjectBuilder_VoxelMap_MergeMaterial(MyMwcVector3Short positionInVoxelMapInVoxelCoords, MyMwcVoxelFilesEnum voxelFile,
     MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     PositionInVoxelMapInVoxelCoords = positionInVoxelMapInVoxelCoords;
     VoxelFile = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
 public MyMwcObjectBuilder_VoxelMap_MergeContent(MyMwcVector3Short positionInVoxelMapInVoxelCoords, MyMwcVoxelFilesEnum voxelFile,
     MyMwcVoxelMapMergeTypeEnum mergeType)
     : base()
 {
     PositionInVoxelMapInVoxelCoords = positionInVoxelMapInVoxelCoords;
     VoxelFile = voxelFile;
     MergeType = mergeType;
 }
 public static MyGuiAsteroidHelper GetMyGuiVoxelFileHelper(MyMwcVoxelFilesEnum voxelFile)
 {
     MyGuiAsteroidHelper ret;
     if (m_voxelFilesHelpers.TryGetValue(voxelFile, out ret))
         return ret;
     else
         return null;
 }
示例#7
0
 public MyMwcObjectBuilder_VoxelMap_MergeMaterial(MyMwcVector3Short positionInVoxelMapInVoxelCoords, MyMwcVoxelFilesEnum voxelFile,
                                                  MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     PositionInVoxelMapInVoxelCoords = positionInVoxelMapInVoxelCoords;
     VoxelFile     = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
 public MyMwcObjectBuilder_VoxelMap_MergeContent(MyMwcVector3Short positionInVoxelMapInVoxelCoords, MyMwcVoxelFilesEnum voxelFile,
                                                 MyMwcVoxelMapMergeTypeEnum mergeType)
     : base()
 {
     PositionInVoxelMapInVoxelCoords = positionInVoxelMapInVoxelCoords;
     VoxelFile = voxelFile;
     MergeType = mergeType;
 }
 public MyMwcObjectBuilder_VoxelMap_Neighbour(MyMwcVector3Sbyte relativeSectorPosition, 
     MyMwcVector3Short voxelMapPositionInVoxelCoords, MyMwcVoxelFilesEnum voxelFile,
     MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     RelativeSectorPosition = relativeSectorPosition;
     VoxelMapPositionInVoxelCoords = voxelMapPositionInVoxelCoords;
     VoxelFile = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
示例#10
0
 public MyMwcObjectBuilder_VoxelMap_Neighbour(MyMwcVector3Sbyte relativeSectorPosition,
                                              MyMwcVector3Short voxelMapPositionInVoxelCoords, MyMwcVoxelFilesEnum voxelFile,
                                              MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     RelativeSectorPosition        = relativeSectorPosition;
     VoxelMapPositionInVoxelCoords = voxelMapPositionInVoxelCoords;
     VoxelFile     = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
        public override void OnOkClick(MyGuiControlButton sender)
        {
            base.OnOkClick(sender);

            if (HasEntity())
            {
                if (m_changeMaterial.Checked)
                {
                    m_entity.VoxelMaterial = ((MyMwcVoxelMaterialsEnum)m_selectVoxelMapMaterialCombobox.GetSelectedKey());
                }

                float x, y, z;
                if (float.TryParse(m_positionX.Text, out x) && float.TryParse(m_positionY.Text, out y) && float.TryParse(m_positionZ.Text, out z))
                {
                    m_entity.SetPosition(new Vector3(x, y, z));
                }
            }
            else
            {
                if (GetAsteroidType() == MyGuiAsteroidTypesEnum.VOXEL)
                {
                    MyMwcObjectBuilder_SmallShip_TypesEnum shipType = (MyMwcObjectBuilder_SmallShip_TypesEnum)
                                                                      Enum.ToObject(typeof(MyMwcObjectBuilder_SmallShip_TypesEnum), m_selectVoxelMapCombobox.GetSelectedKey());
                    MyMwcVoxelFilesEnum voxelFileEnum = (MyMwcVoxelFilesEnum)
                                                        Enum.ToObject(typeof(MyMwcVoxelFilesEnum), m_selectVoxelMapCombobox.GetSelectedKey());
                    MyMwcVoxelMaterialsEnum materialEnum = (MyMwcVoxelMaterialsEnum)
                                                           Enum.ToObject(typeof(MyMwcVoxelMaterialsEnum), m_selectVoxelMapMaterialCombobox.GetSelectedKey());

                    MyMwcObjectBuilder_VoxelMap voxelMapBuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.VoxelMap, null) as MyMwcObjectBuilder_VoxelMap;
                    voxelMapBuilder.VoxelMaterial = materialEnum;
                    voxelMapBuilder.VoxelFile     = voxelFileEnum;
                    MyEditor.Static.CreateFromObjectBuilder(voxelMapBuilder, Matrix.CreateWorld(m_newObjectPosition, Vector3.Forward, Vector3.Up), m_screenPosition);
                }
                else if (GetAsteroidType() == MyGuiAsteroidTypesEnum.STATIC)
                {
                    MyMwcObjectBuilder_StaticAsteroid_TypesEnum staticAsteroidType = (MyMwcObjectBuilder_StaticAsteroid_TypesEnum)
                                                                                     Enum.ToObject(typeof(MyMwcObjectBuilder_StaticAsteroid_TypesEnum), m_selectVoxelMapCombobox.GetSelectedKey());

                    MyMwcVoxelMaterialsEnum?materialEnum = null;
                    int materialKey = m_selectVoxelMapMaterialCombobox.GetSelectedKey();
                    if (materialKey != -1)
                    {
                        materialEnum = (MyMwcVoxelMaterialsEnum)Enum.ToObject(typeof(MyMwcVoxelMaterialsEnum), materialKey);
                    }

                    MyMwcObjectBuilder_StaticAsteroid staticAsteroidBuilder = new MyMwcObjectBuilder_StaticAsteroid(staticAsteroidType, materialEnum);
                    MyEditor.Static.CreateFromObjectBuilder(staticAsteroidBuilder, Matrix.CreateWorld(m_newObjectPosition, Vector3.Forward, Vector3.Up), m_screenPosition);
                }
            }

            MyGuiManager.CloseAllScreensExcept(MyGuiScreenGamePlay.Static);
        }
示例#12
0
        public static bool IsCollidingWithVoxelMap(MyMwcVoxelFilesEnum voxelFileEnum, Vector3 voxelPosition)
        {
            MyVoxelFile voxelFile    = MyVoxelFiles.Get(voxelFileEnum);
            Vector3     sizeInMeters = MyVoxelMap.GetVoxelSizeInMetres(ref voxelFile.SizeInVoxels);

            BoundingBox newBoundingBox       = MyUtils.GetNewBoundingBox(voxelPosition, sizeInMeters);
            MyVoxelMap  intersectingVoxelMap = MyVoxelMaps.GetVoxelMapWhoseBoundingBoxIntersectsBox(ref newBoundingBox, null);

            if (intersectingVoxelMap != null)
            {
                return(true);
            }
            return(false);
        }
示例#13
0
        public bool IsCollidingWithVoxelMap(MyMwcVoxelFilesEnum voxelFileEnum, Vector3 voxelPosition)
        {
            MyVoxelFile voxelFile    = MyVoxelFiles.Get(voxelFileEnum);
            Vector3     sizeInMeters = voxelFile.SizeInVoxels * MyVoxelConstants.VOXEL_SIZE_IN_METRES;

            BoundingBox newBoundingBox       = MyUtils.GetNewBoundingBox(voxelPosition, sizeInMeters);
            MyVoxelMap  intersectingVoxelMap = GetVoxelMapWhoseBoundingBoxIntersectsBox(ref newBoundingBox, null);

            if (intersectingVoxelMap != null)
            {
                return(true);
            }

            return(false);
        }
示例#14
0
        //  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());
            }

            MyMwcVector3Sbyte?relativeSectorPosition = MyMwcMessageIn.ReadVector3SbyteEx(binaryReader, senderEndPoint);

            if (relativeSectorPosition == null)
            {
                return(NetworkError());
            }
            RelativeSectorPosition = relativeSectorPosition.Value;
            MyMwcLog.IfNetVerbose_AddToLog("RelativeSectorPosition: " + RelativeSectorPosition.ToString());

            MyMwcVector3Short?voxelMapPositionInVoxelCoords = MyMwcMessageIn.ReadVector3ShortEx(binaryReader, senderEndPoint);

            if (voxelMapPositionInVoxelCoords == null)
            {
                return(NetworkError());
            }
            VoxelMapPositionInVoxelCoords = voxelMapPositionInVoxelCoords.Value;
            MyMwcLog.IfNetVerbose_AddToLog("VoxelMapPositionInVoxelCoords: " + VoxelMapPositionInVoxelCoords.ToString());

            MyMwcVoxelFilesEnum?voxelFile = MyMwcMessageIn.ReadVoxelFileEnumEx(binaryReader, senderEndPoint);

            if (voxelFile == null)
            {
                return(NetworkError());
            }
            VoxelFile = voxelFile.Value;
            MyMwcLog.IfNetVerbose_AddToLog("VoxelFile: " + VoxelFile.ToString());

            MyMwcVoxelMaterialsEnum?voxelMaterial = MyMwcMessageIn.ReadVoxelMaterialsEnumEx(binaryReader, senderEndPoint);

            if (voxelMaterial == null)
            {
                return(NetworkError());
            }
            VoxelMaterial = voxelMaterial.Value;
            MyMwcLog.IfNetVerbose_AddToLog("VoxelMaterial: " + VoxelMaterial.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;
        }
        //  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);
        }
示例#17
0
 public static MyVoxelFile Get(MyMwcVoxelFilesEnum voxelFileEnum)
 {
     return DefaultVoxelFiles[(int)voxelFileEnum];
 }
示例#18
0
 public MyVoxelFile(MyMwcVoxelFilesEnum voxelFileEnum, MyMwcVector3Int sizeInVoxels, string voxelName)
 {
     VoxelFileEnum = voxelFileEnum;
     SizeInVoxels = sizeInVoxels;
     VoxelName = voxelName;
 }
示例#19
0
 static void Add(MyMwcVoxelFilesEnum voxelFileEnum, MyMwcVector3Int sizeInVoxels, string filename)
 {
     DefaultVoxelFiles[(int)voxelFileEnum] = new MyVoxelFile(voxelFileEnum, sizeInVoxels, filename);
 }
示例#20
0
 public static MyVoxelFile Get(MyMwcVoxelFilesEnum voxelFileEnum)
 {
     return(DefaultVoxelFiles[(int)voxelFileEnum]);
 }
示例#21
0
 public MyVoxelFile(MyMwcVoxelFilesEnum voxelFileEnum, Vector3I sizeInVoxels, string voxelName)
 {
     VoxelFileEnum = voxelFileEnum;
     SizeInVoxels  = sizeInVoxels;
     VoxelName     = voxelName;
 }
示例#22
0
 public void MergeVoxelMaterials(MyMwcVoxelFilesEnum voxelFile, Vector3I voxelPosition, MyVoxelMaterialDefinition materialToSet)
 {
     Storage.MergeVoxelMaterials(voxelFile, voxelPosition, materialToSet);
 }
示例#23
0
 static void Add(MyMwcVoxelFilesEnum voxelFileEnum, Vector3I sizeInVoxels, string filename)
 {
     DefaultVoxelFiles[(int)voxelFileEnum] = new MyVoxelFile(voxelFileEnum, sizeInVoxels, filename);
 }
示例#24
0
 public static bool IsNewAllowed(MyMwcVoxelFilesEnum voxelFileEnum)
 {
     int totalDataCells = MyVoxelMaps.GetTotalDataCellsCount();
     return IsNewAllowed(voxelFileEnum, ref totalDataCells);
 }
示例#25
0
        bool Read01089000(BinaryReader binaryReader, EndPoint senderEndPoint, int gameVersion)
        {
            MyMwcVoxelFilesEnum?voxelFile = MyMwcMessageIn.ReadVoxelFileEnumEx(binaryReader, senderEndPoint);

            if (voxelFile == null)
            {
                return(NetworkError());
            }
            VoxelFile = voxelFile.Value;
            MyMwcLog.IfNetVerbose_AddToLog("VoxelFile: " + VoxelFile.ToString());

            MyMwcVoxelMaterialsEnum?voxelMaterial = MyMwcMessageIn.ReadVoxelMaterialsEnumEx(binaryReader, senderEndPoint);

            if (voxelMaterial == null)
            {
                return(NetworkError());
            }
            VoxelMaterial = voxelMaterial.Value;
            MyMwcLog.IfNetVerbose_AddToLog("VoxelMaterial: " + VoxelMaterial.ToString());

            //  Merge Contents
            int?countMergeContents = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);

            if (countMergeContents == null)
            {
                return(NetworkError());
            }
            MyMwcLog.IfNetVerbose_AddToLog("countMergeContents: " + countMergeContents);
            MergeContents = new List <MyMwcObjectBuilder_VoxelMap_MergeContent>(countMergeContents.Value);
            for (int i = 0; i < countMergeContents; i++)
            {
                MyMwcObjectBuilder_VoxelMap_MergeContent newMC = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_VoxelMap_MergeContent;
                if (newMC == null)
                {
                    return(NetworkError());
                }
                if (newMC.Read(binaryReader, senderEndPoint, gameVersion) == false)
                {
                    return(NetworkError());
                }
                MergeContents.Add(newMC);
            }

            //  Merge Materials
            int?countMergeMaterials = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);

            if (countMergeMaterials == null)
            {
                return(NetworkError());
            }
            MyMwcLog.IfNetVerbose_AddToLog("countMergeMaterials: " + countMergeMaterials);
            MergeMaterials = new List <MyMwcObjectBuilder_VoxelMap_MergeMaterial>(countMergeMaterials.Value);
            for (int i = 0; i < countMergeMaterials; i++)
            {
                MyMwcObjectBuilder_VoxelMap_MergeMaterial newMM = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_VoxelMap_MergeMaterial;
                if (newMM == null)
                {
                    return(NetworkError());
                }
                if (newMM.Read(binaryReader, senderEndPoint, gameVersion) == false)
                {
                    return(NetworkError());
                }
                MergeMaterials.Add(newMM);
            }

            //  Voxel Hand Shapes
            int?countVoxelHandShapes = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);

            if (countVoxelHandShapes == null)
            {
                return(NetworkError());
            }
            MyMwcLog.IfNetVerbose_AddToLog("countVoxelHandShapes: " + countVoxelHandShapes);
            VoxelHandShapes = new List <MyMwcObjectBuilder_VoxelHand_Shape>(countVoxelHandShapes.Value);
            for (int i = 0; i < countVoxelHandShapes; i++)
            {
                MyMwcObjectBuilder_VoxelHand_Shape voxelHandShape = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_VoxelHand_Shape;
                if (voxelHandShape == null)
                {
                    return(NetworkError());
                }
                if (voxelHandShape.Read(binaryReader, senderEndPoint, gameVersion) == false)
                {
                    return(NetworkError());
                }
                VoxelHandShapes.Add(voxelHandShape);
            }

            return(true);
        }
示例#26
0
 protected abstract void MergeVoxelMaterialsInternal(MyMwcVoxelFilesEnum voxelFile, Vector3I voxelPosition, MyVoxelMaterialDefinition materialToSet);
示例#27
0
 public void MergeVoxelMaterials(MyMwcVoxelFilesEnum voxelFile, Vector3I voxelPosition, MyVoxelMaterialDefinition materialToSet)
 {
     Storage.MergeVoxelMaterials(voxelFile, voxelPosition, materialToSet);
 }
示例#28
0
        public static bool IsNewAllowed(MyMwcVoxelFilesEnum voxelFileEnum, ref int totalDataCells)
        {
            bool allowed = false;

            MyVoxelFile voxelFile = MyVoxelFiles.Get(voxelFileEnum);
            MyCompressionFileLoad decompressFile = new MyCompressionFileLoad(voxelFile.GetVoxFilePath());

            int fileVersion = decompressFile.GetInt32();

            //  Size of this voxel map (in voxels)
            int sizeX = decompressFile.GetInt32();
            int sizeY = decompressFile.GetInt32();
            int sizeZ = decompressFile.GetInt32();

            int dataCellCountX = sizeX >> MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS;
            int dataCellCountY = sizeY >> MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS;
            int dataCellCountZ = sizeZ >> MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS;

            int newVoxelCellCount = dataCellCountX * dataCellCountY * dataCellCountZ;

            totalDataCells = newVoxelCellCount + totalDataCells;
            if (totalDataCells < MyVoxelConstants.MAX_VOXEL_MAPS_DATA_CELL_COUNT)
            {
                allowed = true;
            }

            return allowed;
        }
示例#29
0
        // 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();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#30
0
 protected abstract void MergeVoxelMaterialsInternal(MyMwcVoxelFilesEnum voxelFile, Vector3I voxelPosition, MyVoxelMaterialDefinition materialToSet);
示例#31
0
 // mk:TODO Remove
 public void MergeVoxelMaterials(MyMwcVoxelFilesEnum voxelFile, Vector3I voxelPosition, MyVoxelMaterialDefinition materialToSet)
 {
     m_compressedData = null;
     MergeVoxelMaterialsInternal(voxelFile, voxelPosition, materialToSet);
 }
示例#32
0
        //  Merges specified materials (from file) into our actual voxel map - overwriting materials only.
        //  We are using a regular voxel map to define areas where we want to set a specified material. Empty voxels are ignored and 
        //  only mixed/full voxels are used to tell us that that voxel will contain new material - 'materialToSet'.
        //  If we are seting indestructible material, voxel content values from merged voxel map will be used to define indestructible content.
        //  Parameter 'voxelPosition' - place where we will place merged voxel map withing actual voxel map. It's in voxel coords.
        //  IMPORTANT: THIS METHOD WILL WORK ONLY IF WE PLACE THE MAP THAT WE TRY TO MERGE FROM IN VOXEL COORDINATES THAT ARE MULTIPLY OF DATA CELL SIZE
        //  This method is used to load small material areas, overwriting actual material only if value from file is 1. Zeros are ignored (it's empty space).
        //  This method is quite fast, even on large maps - 512x512x512, so we can do more overwrites.
        //  Parameter 'materialToSet' tells us what material to set at places which are full in file. Empty are ignored - so stay as they were before this method was called.
        //  IMPORTANT: THIS MERGE MATERIAL CAN BE CALLED ONLY AFTER ALL VOXEL CONTENTS ARE LOADED. THAT'S BECAUSE WE NEED TO KNOW THEM FOR MIN CONTENT / INDESTRUCTIBLE CONTENT.
        //  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.
        public void MergeVoxelMaterials(MyMwcVoxelFilesEnum voxelFile, MyMwcVector3Short voxelPosition, MyMwcVoxelMaterialsEnum materialToSet)
        {
            MyMwcLog.WriteLine("MyVoxelMap.MergeVoxelMaterials() - Start");
            MyMwcLog.IncreaseIndent();

            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;

            //  This method will work only if we place the map that we try to merge from in voxel coordinates that are multiply of data cell size
            MyCommonDebugUtils.AssertRelease((voxelPosition.X & MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
            MyCommonDebugUtils.AssertRelease((voxelPosition.Y & MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
            MyCommonDebugUtils.AssertRelease((voxelPosition.Z & MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
            MyMwcVector3Int cellFullForVoxelPosition = GetDataCellCoordinate(ref voxelPosition);

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

                        //  We can do "continue" here, becase we need to read this file properly, even if we will ignore that data
                        bool isDataCellInVoxelMap = IsDataCellInVoxelMap(
                            new MyMwcVector3Int(
                                cellFullForVoxelPosition.X + cellCoord.X,
                                cellFullForVoxelPosition.Y + cellCoord.Y,
                                cellFullForVoxelPosition.Z + cellCoord.Z));

                        if (cellType == MyVoxelCellType.EMPTY)
                        {
                            //  If merged cell is empty, there is nothing to overwrite, so we can skip this cell
                            continue;
                        }
                        else if (cellType == MyVoxelCellType.FULL)
                        {
                            //  If merged cell is full, than we reset whole material cell to 'materialToSet'
                            if (isDataCellInVoxelMap)
                            {
                                m_voxelMaterialCells[cellFullForVoxelPosition.X + cellCoord.X][cellFullForVoxelPosition.Y +
                                    cellCoord.Y][cellFullForVoxelPosition.Z + cellCoord.Z].Reset(
                                    materialToSet, GetIndestructibleContentByMaterial(materialToSet));
                            }
                        }
                        else
                        {
                            MyMwcVector3Int cellCoordInVoxels = GetVoxelCoordinatesOfDataCell(ref cellCoord);

                            MyMwcVector3Int voxelCoordRelative;
                            voxelCoordRelative.X = voxelPosition.X + cellCoordInVoxels.X;
                            voxelCoordRelative.Y = voxelPosition.Y + cellCoordInVoxels.Y;
                            voxelCoordRelative.Z = voxelPosition.Z + cellCoordInVoxels.Z;

                            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 voxelFromFile = decompressFile.GetByte();

                                        if (isDataCellInVoxelMap)
                                        {
                                            //  Ignore empty voxels, but use mixed/full for seting the material
                                            if (voxelFromFile > MyVoxelConstants.VOXEL_CONTENT_EMPTY)
                                            {
                                                MyMwcVector3Int voxelCoord = new MyMwcVector3Int(
                                                    voxelCoordRelative.X + voxelCoordInCell.X,
                                                    voxelCoordRelative.Y + voxelCoordInCell.Y,
                                                    voxelCoordRelative.Z + voxelCoordInCell.Z);

                                                //  Actual voxel content
                                                byte voxelContent = GetVoxelContent(ref voxelCoord);

                                                //  If this is indestructible material, here we will get 'min content' for this voxel
                                                byte indestructibleContent = GetIndestructibleContentsByMaterialAndContent(materialToSet, voxelFromFile);

                                                //  Indestructible content can be less than real voxel at this place. First I made this mistake.
                                                //  If forgoten, then during explosions we will in fact create matter from 'indestructible content' array.
                                                if (indestructibleContent > voxelContent)
                                                {
                                                    indestructibleContent = voxelContent;
                                                }

                                                SetVoxelMaterialAndIndestructibleContent(materialToSet, indestructibleContent, ref voxelCoord);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyVoxelMap.MergeVoxelMaterials() - End");
        }
示例#33
0
 // mk:TODO Remove
 public void MergeVoxelMaterials(MyMwcVoxelFilesEnum voxelFile, Vector3I voxelPosition, MyVoxelMaterialDefinition materialToSet)
 {
     m_compressedData = null;
     MergeVoxelMaterialsInternal(voxelFile, voxelPosition, materialToSet);
 }
        bool Read01089000(BinaryReader binaryReader, EndPoint senderEndPoint, int gameVersion)
        {
            MyMwcVoxelFilesEnum? voxelFile = MyMwcMessageIn.ReadVoxelFileEnumEx(binaryReader, senderEndPoint);
            if (voxelFile == null) return NetworkError();
            VoxelFile = voxelFile.Value;
            MyMwcLog.IfNetVerbose_AddToLog("VoxelFile: " + VoxelFile.ToString());

            MyMwcVoxelMaterialsEnum? voxelMaterial = MyMwcMessageIn.ReadVoxelMaterialsEnumEx(binaryReader, senderEndPoint);
            if (voxelMaterial == null) return NetworkError();
            VoxelMaterial = voxelMaterial.Value;
            MyMwcLog.IfNetVerbose_AddToLog("VoxelMaterial: " + VoxelMaterial.ToString());

            //  Merge Contents
            int? countMergeContents = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);
            if (countMergeContents == null) return NetworkError();
            MyMwcLog.IfNetVerbose_AddToLog("countMergeContents: " + countMergeContents);
            MergeContents = new List<MyMwcObjectBuilder_VoxelMap_MergeContent>(countMergeContents.Value);
            for (int i = 0; i < countMergeContents; i++)
            {
                MyMwcObjectBuilder_VoxelMap_MergeContent newMC = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_VoxelMap_MergeContent;
                if (newMC == null) return NetworkError();
                if (newMC.Read(binaryReader, senderEndPoint, gameVersion) == false) return NetworkError();
                MergeContents.Add(newMC);
            }

            //  Merge Materials
            int? countMergeMaterials = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);
            if (countMergeMaterials == null) return NetworkError();
            MyMwcLog.IfNetVerbose_AddToLog("countMergeMaterials: " + countMergeMaterials);
            MergeMaterials = new List<MyMwcObjectBuilder_VoxelMap_MergeMaterial>(countMergeMaterials.Value);
            for (int i = 0; i < countMergeMaterials; i++)
            {
                MyMwcObjectBuilder_VoxelMap_MergeMaterial newMM = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_VoxelMap_MergeMaterial;
                if (newMM == null) return NetworkError();
                if (newMM.Read(binaryReader, senderEndPoint, gameVersion) == false) return NetworkError();
                MergeMaterials.Add(newMM);
            }

            //  Voxel Hand Shapes
            int? countVoxelHandShapes = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);
            if (countVoxelHandShapes == null) return NetworkError();
            MyMwcLog.IfNetVerbose_AddToLog("countVoxelHandShapes: " + countVoxelHandShapes);
            VoxelHandShapes = new List<MyMwcObjectBuilder_VoxelHand_Shape>(countVoxelHandShapes.Value);
            for (int i = 0; i < countVoxelHandShapes; i++)
            {
                MyMwcObjectBuilder_VoxelHand_Shape voxelHandShape = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_VoxelHand_Shape;
                if (voxelHandShape == null) return NetworkError();
                if (voxelHandShape.Read(binaryReader, senderEndPoint, gameVersion) == false) return NetworkError();
                VoxelHandShapes.Add(voxelHandShape);
            }

            return true;
        }
示例#35
0
        //  Merges specified materials (from file) into our actual voxel map - overwriting materials only.
        //  We are using a regular voxel map to define areas where we want to set a specified material. Empty voxels are ignored and 
        //  only mixed/full voxels are used to tell us that that voxel will contain new material - 'materialToSet'.
        //  If we are seting indestructible material, voxel content values from merged voxel map will be used to define indestructible content.
        //  Parameter 'voxelPosition' - place where we will place merged voxel map withing actual voxel map. It's in voxel coords.
        //  IMPORTANT: THIS METHOD WILL WORK ONLY IF WE PLACE THE MAP THAT WE TRY TO MERGE FROM IN VOXEL COORDINATES THAT ARE MULTIPLY OF DATA CELL SIZE
        //  This method is used to load small material areas, overwriting actual material only if value from file is 1. Zeros are ignored (it's empty space).
        //  This method is quite fast, even on large maps - 512x512x512, so we can do more overwrites.
        //  Parameter 'materialToSet' tells us what material to set at places which are full in file. Empty are ignored - so stay as they were before this method was called.
        //  IMPORTANT: THIS MERGE MATERIAL CAN BE CALLED ONLY AFTER ALL VOXEL CONTENTS ARE LOADED. THAT'S BECAUSE WE NEED TO KNOW THEM FOR MIN CONTENT / INDESTRUCTIBLE CONTENT.
        //  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.
        // mk:TODO move to Data storage, hide behind interface and make sure this does not overwrite empty area material (in target voxel map)
        protected override void MergeVoxelMaterialsInternal(MyMwcVoxelFilesEnum voxelFile, Vector3I voxelPosition, MyVoxelMaterialDefinition materialToSet)
        {
            Profiler.Begin("MyVoxelMap.MergeVoxelMaterials");

            using (var fileStream = File.OpenRead(MyVoxelFiles.Get(voxelFile).GetVoxFilePath()))
            using (var gzip = new GZipStream(fileStream, CompressionMode.Decompress))
            {
                var storage = gzip.ReadString();
                Debug.Assert(storage == "Cell");

                //  Version of a VOX file
                int fileVersion = gzip.Read7BitEncodedInt();

                //  Not supported VOX file version
                Debug.Assert(fileVersion == CURRENT_FILE_VERSION);

                //  Size of this voxel map (in voxels)
                int sizeX = gzip.ReadInt32();
                int sizeY = gzip.ReadInt32();
                int sizeZ = gzip.ReadInt32();

                //  Size of data cell in voxels, doesn't have to be same as current size specified by our constants.
                int cellSizeX = gzip.ReadInt32();
                int cellSizeY = gzip.ReadInt32();
                int cellSizeZ = gzip.ReadInt32();

                int cellsCountX = sizeX / cellSizeX;
                int cellsCountY = sizeY / cellSizeY;
                int cellsCountZ = sizeZ / cellSizeZ;

                //  This method will work only if we place the map that we try to merge from in voxel coordinates that are multiply of data cell size
                Debug.Assert((voxelPosition.X & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
                Debug.Assert((voxelPosition.Y & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
                Debug.Assert((voxelPosition.Z & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
                Vector3I cellFullForVoxelPosition;
                MyCellStorage.ComputeCellCoord(ref voxelPosition, out cellFullForVoxelPosition);

                Vector3I 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++)
                        {
                            MyVoxelRangeType cellType = (MyVoxelRangeType)gzip.ReadByteNoAlloc();

                            //  We can do "continue" here, becase we need to read this file properly, even if we will ignore that data
                            var tmp = new Vector3I(
                                    cellFullForVoxelPosition.X + cellCoord.X,
                                    cellFullForVoxelPosition.Y + cellCoord.Y,
                                    cellFullForVoxelPosition.Z + cellCoord.Z);
                            bool isDataCellInVoxelMap = IsValidCellCoord(ref tmp);

                            if (cellType == MyVoxelRangeType.EMPTY)
                            {
                                //  If merged cell is empty, there is nothing to overwrite, so we can skip this cell
                                continue;
                            }
                            else if (cellType == MyVoxelRangeType.FULL)
                            {
                                //  If merged cell is full, than we reset whole material cell to 'materialToSet'
                                if (isDataCellInVoxelMap)
                                {

                                    var coord = cellFullForVoxelPosition + cellCoord;
                                    ResetCellMaterial(ref coord, materialToSet);
                                }
                            }
                            else
                            {
                                //Vector3I cellCoordInVoxels = GetVoxelCoordinatesOfDataCell(ref cellCoord);
                                Vector3I cellCoordInVoxels;
                                MyCellStorage.ComputeVoxelCoordOfCell(ref cellCoord, out cellCoordInVoxels);

                                Vector3I voxelCoordRelative;
                                voxelCoordRelative.X = voxelPosition.X + cellCoordInVoxels.X;
                                voxelCoordRelative.Y = voxelPosition.Y + cellCoordInVoxels.Y;
                                voxelCoordRelative.Z = voxelPosition.Z + cellCoordInVoxels.Z;

                                Vector3I 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 voxelFromFile = gzip.ReadByteNoAlloc();

                                            if (isDataCellInVoxelMap)
                                            {
                                                //  Ignore empty voxels, but use mixed/full for seting the material
                                                if (voxelFromFile > MyVoxelConstants.VOXEL_CONTENT_EMPTY)
                                                {
                                                    Vector3I voxelCoord = new Vector3I(
                                                        voxelCoordRelative.X + voxelCoordInCell.X,
                                                        voxelCoordRelative.Y + voxelCoordInCell.Y,
                                                        voxelCoordRelative.Z + voxelCoordInCell.Z);

                                                    //  Actual voxel content
                                                    byte voxelContent = GetContent(ref voxelCoord);

                                                    SetMaterial(materialToSet, ref voxelCoord);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Profiler.End();
        }
示例#36
0
 void IMyStorage.MergeVoxelMaterials(MyMwcVoxelFilesEnum voxelFile, Vector3I voxelPosition, MyVoxelMaterialDefinition materialToSet)
 {
     EnsureMutable();
     m_trueStorage.MergeVoxelMaterials(voxelFile, voxelPosition, materialToSet);
 }
示例#37
0
 void IMyStorage.MergeVoxelMaterials(MyMwcVoxelFilesEnum voxelFile, Vector3I voxelPosition, MyVoxelMaterialDefinition materialToSet)
 {
     EnsureMutable();
     m_trueStorage.MergeVoxelMaterials(voxelFile, voxelPosition, materialToSet);
 }
示例#38
0
 public static void WriteVoxelFilesEnum(MyMwcVoxelFilesEnum val, BinaryWriter binaryWriter)
 {
     binaryWriter.Write((short)val);
 }