public void Start(Vector3 position, float scale, MyMwcVoxelMaterialsEnum voxelMaterial, MyGroupMask groupMask, bool explosionType)
        {
            base.Start(position, scale, groupMask, explosionType);

            if (explosionType)
            {
                //apply random rotation impulse
                base.Physics.AngularVelocity = new Vector3(MyMwcUtils.GetRandomRadian(), MyMwcUtils.GetRandomRadian(), MyMwcUtils.GetRandomRadian()) * 0.7f;
                if (base.Physics.AngularVelocity.Length() == 0)
                {
                    Debug.Assert(false);
                }

                if (!Physics.Enabled)
                {
                    Physics.Enabled = true;
                }
            }
            else
            {
                if (Physics.Enabled)
                {
                    Physics.Enabled = false;
                }
            }

            VoxelMaterial = voxelMaterial;

            InitDrawTechniques();

            RenderObjects[0].NeedsResolveCastShadow = true;
            RenderObjects[0].FastCastShadowResolve  = true;
        }
Exemple #2
0
 public MyMwcObjectBuilder_VoxelMap(Vector3 position, MyMwcVoxelFilesEnum voxelFile, MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     PositionAndOrientation.Position = position;
     VoxelFile     = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
        public static MyMwcVoxelMaterialsEnum GetAllowedVoxelMaterial(MyMwcVoxelMaterialsEnum materialEnum)
        {
            if (MySector.AllowedMaterials == null)
            {
                return(materialEnum);
            }

            bool materialAllowed = MySector.AllowedMaterials.Contains((int)materialEnum);

            materialAllowed |= MySector.AllowedMaterials.Count == 0;

            if (!materialAllowed)
            {
                //System.Diagnostics.Debug.Assert(false, "Usage of non compatible sector voxel material! (" + materialEnum.ToString() + ")"); // Assert temporarily turned off
                //To avoid asserts
                //MySector.PrimaryMaterials.Add(materialEnum);

                MyMwcVoxelMaterialsEnum newMaterialEnum = materialEnum;

                if (MySector.AllowedMaterials.Count > 0)
                {
                    newMaterialEnum = (MyMwcVoxelMaterialsEnum)MySector.AllowedMaterials[0];
                }

                //MyMwcLog.WriteLine("Voxel material " + materialEnum.ToString() + " is not compatible with this sector and is replaced by " + newMaterialEnum.ToString());

                materialEnum = newMaterialEnum;
            }

            return(materialEnum);
        }
        //  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(Vector3 position, MyMwcVoxelFilesEnum voxelFile, MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     PositionAndOrientation.Position = position;
     VoxelFile = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
        public void UpdateVoxelTextures(MyMwcVoxelMaterialsEnum material)
        {
            m_multimaterial = false;

            //  Get with lazy-load
            MyVoxelMaterial         voxelMaterial = MyVoxelMaterials.Get(material);
            MyVoxelMaterialTextures voxelTexture  = voxelMaterial.GetTextures();

            if (MyRender.DebugDiffuseTexture)
            {
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisXZ, (Texture)MyRender.GetDebugTexture());
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisY, (Texture)MyRender.GetDebugTexture());
            }
            else
            {
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisXZ, (Texture)voxelTexture.TextureDiffuseForAxisXZ);
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisY, (Texture)voxelTexture.TextureDiffuseForAxisY);
            }

            if (MyRender.DebugNormalTexture)
            {
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisXZ, (Texture)MyRender.GetDebugNormalTexture());
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisY, (Texture)MyRender.GetDebugNormalTexture());
            }
            else
            {
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisXZ, (Texture)voxelTexture.TextureNormalMapForAxisXZ);
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisY, (Texture)voxelTexture.TextureNormalMapForAxisY);
            }

            m_D3DEffect.SetValue(m_specularIntensity, voxelMaterial.SpecularIntensity);
            m_D3DEffect.SetValue(m_specularPower, voxelMaterial.SpecularPower);
        }
        public void Start(Vector3 position, float scale, MyMwcVoxelMaterialsEnum voxelMaterial, MyGroupMask groupMask, bool explosionType)
        {
            base.Start(position, scale, groupMask, explosionType);

            if (explosionType)
            {
                //apply random rotation impulse
                base.Physics.AngularVelocity = new Vector3(MyMwcUtils.GetRandomRadian(), MyMwcUtils.GetRandomRadian(), MyMwcUtils.GetRandomRadian()) * 0.7f;
                if (base.Physics.AngularVelocity.Length() == 0)
                    Debug.Assert(false);

                if (!Physics.Enabled)
                    Physics.Enabled = true;

            }
            else
            {
                if (Physics.Enabled)
                    Physics.Enabled = false;
            }

            VoxelMaterial = voxelMaterial;

            InitDrawTechniques();

            RenderObjects[0].NeedsResolveCastShadow = true;
            RenderObjects[0].FastCastShadowResolve = true;
        }
        //  Calculate and then remember average material in this cell. It isn't single material, but average.
        public void CalcAverageCellMaterial()
        {
            if (m_singleMaterialForWholeCell == true)
            {
                //  For single material it's easy
                m_averageCellMaterial = m_singleMaterial;
            }
            else
            {
                //  If materials are stored in 3D array, we need to really calculate average material
                //  Iterate materials in this data cell
                for (int xyz = 0; xyz < voxelsInCell; xyz++)
                {
                    MyMwcVoxelMaterialsEnum material = m_materials[xyz];
                    m_cellMaterialCounts[(int)material]++;
                }

                int maxNum = 0;
                for (int i = 0; i < m_cellMaterialCounts.Length; i++)
                {
                    if (m_cellMaterialCounts[i] > maxNum)
                    {
                        maxNum = m_cellMaterialCounts[i];
                        m_averageCellMaterial = (MyMwcVoxelMaterialsEnum)i;
                    }
                    m_cellMaterialCounts[i] = 0; // Erase for next operation
                }
            }

            MyCommonDebugUtils.AssertRelease(m_averageCellMaterial.HasValue);
        }
 public MyMwcObjectBuilder_VoxelMap_MergeMaterial(MyMwcVector3Short positionInVoxelMapInVoxelCoords, MyMwcVoxelFilesEnum voxelFile,
     MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     PositionInVoxelMapInVoxelCoords = positionInVoxelMapInVoxelCoords;
     VoxelFile = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
 private static void Add(MyMwcVoxelMaterialsEnum voxelMaterial, MyMwcObjectBuilder_Ore_TypesEnum?ore, float percents)
 {
     MaterialProperties.Add((int)voxelMaterial, new MyMwcVoxelMaterialProperties
     {
         Ore      = ore,
         Percents = percents
     });
 }
 public static MyGuiVoxelMaterialHelper GetMyGuiVoxelMaterialHelper(MyMwcVoxelMaterialsEnum voxelMaterial)
 {
     MyGuiVoxelMaterialHelper ret;
     if (m_voxelMaterialHelpers.TryGetValue(voxelMaterial, out ret))
         return ret;
     else
         return null;
 }
 private bool HasMaterial(MyMwcVoxelMaterialsEnum material)
 {
     if (material == Material0 || material == Material1 || material == Material2)
     {
         return(true);
     }
     return(false);
 }
Exemple #13
0
 public MyMwcObjectBuilder_VoxelMap_MergeMaterial(MyMwcVector3Short positionInVoxelMapInVoxelCoords, MyMwcVoxelFilesEnum voxelFile,
                                                  MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     PositionInVoxelMapInVoxelCoords = positionInVoxelMapInVoxelCoords;
     VoxelFile     = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
 private static void Add(MyMwcVoxelMaterialsEnum voxelMaterial, MyMwcObjectBuilder_Ore_TypesEnum? ore, float percents)
 {
     MaterialProperties.Add((int)voxelMaterial, new MyMwcVoxelMaterialProperties
     {
         Ore = ore,
         Percents = percents
     });
 }
Exemple #15
0
        private void RecalculatePositions()
        {
            ClearPositionsAndMaxContent();
            int sizeInVoxels = MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS * MyVoxelConstants.VOXEL_MAP_ORE_DEPOSIT_CELL_IN_DATA_CELLS;

            MyMwcVector3Int voxelStartCoord = new MyMwcVector3Int(sizeInVoxels * m_coord.X, sizeInVoxels * m_coord.Y, sizeInVoxels * m_coord.Z);
            MyMwcVector3Int voxelEndCoord   = new MyMwcVector3Int(voxelStartCoord.X + sizeInVoxels - 1, voxelStartCoord.Y + sizeInVoxels - 1, voxelStartCoord.Z + sizeInVoxels - 1);

            MyMwcVector3Int voxelCoord;

            for (voxelCoord.X = voxelStartCoord.X; voxelCoord.X <= voxelEndCoord.X; voxelCoord.X++)
            {
                for (voxelCoord.Y = voxelStartCoord.Y; voxelCoord.Y <= voxelEndCoord.Y; voxelCoord.Y++)
                {
                    for (voxelCoord.Z = voxelStartCoord.Z; voxelCoord.Z <= voxelEndCoord.Z; voxelCoord.Z++)
                    {
                        byte content = m_voxelMap.GetVoxelContent(ref voxelCoord);
                        if (content >= MyVoxelConstants.VOXEL_ISO_LEVEL)
                        {
                            MyMwcVoxelMaterialsEnum material = m_voxelMap.GetVoxelMaterial(ref voxelCoord);
                            byte maxContent;
                            m_helpersMaxContentForMaterial.TryGetValue((int)material, out maxContent);

                            if (!m_allMaterialsPositions.ContainsKey((int)material) || content > maxContent)
                            {
                                if (!m_allMaterialsPositions.ContainsKey((int)material))
                                {
                                    m_allMaterialsPositions.Add((int)material, m_voxelMap.GetVoxelCenterPositionAbsolute(ref voxelCoord));
                                }
                                else
                                {
                                    m_allMaterialsPositions[(int)material] = m_voxelMap.GetVoxelCenterPositionAbsolute(ref voxelCoord);
                                }

                                if (!m_helpersMaxContentForMaterial.ContainsKey((int)material))
                                {
                                    m_helpersMaxContentForMaterial.Add((int)material, content);
                                }
                                else
                                {
                                    m_helpersMaxContentForMaterial[(int)material] = content;
                                }
                            }
                        }
                    }
                }
            }

            //if (m_oreWithContent.Count > 0)
            //{
            //    SortByContent();
            //    m_position = m_allMaterialsPositions[(int)m_oreWithContent[0]].Value;
            //}
            //else
            //{
            //    m_position = WorldAABB.GetCenter();
            //}
        }
Exemple #16
0
        public void SetOreContent(MyMwcVoxelMaterialsEnum ore, int content)
        {
            if (content == 0 || !MyVoxelMapOreMaterials.IsRareOre(ore))
            {
                return;
            }

            int previousTotalOreContentSum = m_totalSumOfOreContent;


            int existingContent = 0;

            m_allMaterialsContent.TryGetValue((int)ore, out existingContent);

            int contentToAdd = content;

            if (content < 0)
            {
                contentToAdd = Math.Max(content, -existingContent);
            }

            if (!m_allMaterialsContent.ContainsKey((int)ore))
            {
                m_allMaterialsContent.Add((int)ore, 0);
            }
            m_allMaterialsContent[(int)ore] += contentToAdd;
            m_totalSumOfOreContent          += contentToAdd;

            // this ore hasn't any content before, so we add it to oreWithContent collection
            if (contentToAdd > 0 && existingContent == 0)
            {
                m_oreWithContent.Add(ore);
            }
            // this ore has no content now, so we remove it from oreWithContent collection
            else if (contentToAdd < 0 && m_allMaterialsContent[(int)ore] == 0)
            {
                m_oreWithContent.Remove(ore);
            }

            bool containsOreChanged = false;

            // detect if cell was changed from empty to not empty
            if (m_totalSumOfOreContent > 0 && previousTotalOreContentSum == 0)
            {
                containsOreChanged = true;
            }
            // detect if cell was changed from not empty to empty
            else if (previousTotalOreContentSum > 0 && m_totalSumOfOreContent <= 0)
            {
                containsOreChanged = true;
            }

            if (containsOreChanged && OnVoxelMapOreDepositCellContainsOreChanged != null)
            {
                OnVoxelMapOreDepositCellContainsOreChanged(this, m_totalSumOfOreContent == 0);
            }
            m_positionIsDirty = true;
        }
 //  Use when you want to change whole cell to one single material
 public void Reset(MyMwcVoxelMaterialsEnum defaultMaterial, byte defaultIndestructibleContents)
 {
     m_singleMaterialForWholeCell  = true;
     m_singleMaterial              = defaultMaterial;
     m_singleIndestructibleContent = defaultIndestructibleContents;
     m_averageCellMaterial         = m_singleMaterial;
     m_materials             = null;
     m_indestructibleContent = null;
 }
 //  Use when you want to change whole cell to one single material
 public void Reset(MyMwcVoxelMaterialsEnum defaultMaterial, byte defaultIndestructibleContents)
 {
     m_singleMaterialForWholeCell = true;
     m_singleMaterial = defaultMaterial;
     m_singleIndestructibleContent = defaultIndestructibleContents;
     m_averageCellMaterial = m_singleMaterial;
     m_materials = null;
     m_indestructibleContent = null;
 }
Exemple #19
0
 public MyMwcObjectBuilder_VoxelMap_Neighbour(MyMwcVector3Sbyte relativeSectorPosition,
                                              MyMwcVector3Short voxelMapPositionInVoxelCoords, MyMwcVoxelFilesEnum voxelFile,
                                              MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     RelativeSectorPosition        = relativeSectorPosition;
     VoxelMapPositionInVoxelCoords = voxelMapPositionInVoxelCoords;
     VoxelFile     = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
 public MyMwcObjectBuilder_VoxelMap_Neighbour(MyMwcVector3Sbyte relativeSectorPosition, 
     MyMwcVector3Short voxelMapPositionInVoxelCoords, MyMwcVoxelFilesEnum voxelFile,
     MyMwcVoxelMaterialsEnum voxelMaterial)
     : base()
 {
     RelativeSectorPosition = relativeSectorPosition;
     VoxelMapPositionInVoxelCoords = voxelMapPositionInVoxelCoords;
     VoxelFile = voxelFile;
     VoxelMaterial = voxelMaterial;
 }
        private static void GetMultimaterialsFromId(int id, out MyMwcVoxelMaterialsEnum mat0, out MyMwcVoxelMaterialsEnum mat1, out MyMwcVoxelMaterialsEnum mat2)
        {
            int div = id;

            mat0 = (MyMwcVoxelMaterialsEnum)(div % VoxelMaterialCount);
            div /= VoxelMaterialCount;
            mat1 = (MyMwcVoxelMaterialsEnum)(div % VoxelMaterialCount);
            div /= VoxelMaterialCount;
            mat2 = (MyMwcVoxelMaterialsEnum)(div % VoxelMaterialCount);
        }
        //  Change material for specified voxel
        //  If this material is single material for whole cell, we do nothing. Otherwise we allocate 3D arrays and start using them.
        public void SetMaterialAndIndestructibleContent(MyMwcVoxelMaterialsEnum material, byte indestructibleContent, ref MyMwcVector3Int voxelCoordInCell)
        {
            CheckInitArrays(material);

            if (m_singleMaterialForWholeCell == false)
            {
                int xyz = voxelCoordInCell.X * xStep + voxelCoordInCell.Y * yStep + voxelCoordInCell.Z * zStep;
                m_materials[xyz] = material;
                m_indestructibleContent[xyz] = indestructibleContent;
            }
        }
        //  Change material for specified voxel
        //  If this material is single material for whole cell, we do nothing. Otherwise we allocate 3D arrays and start using them.
        public void SetMaterialAndIndestructibleContent(MyMwcVoxelMaterialsEnum material, byte indestructibleContent, ref MyMwcVector3Int voxelCoordInCell)
        {
            CheckInitArrays(material);

            if (m_singleMaterialForWholeCell == false)
            {
                int xyz = voxelCoordInCell.X * xStep + voxelCoordInCell.Y * yStep + voxelCoordInCell.Z * zStep;
                m_materials[xyz]             = material;
                m_indestructibleContent[xyz] = indestructibleContent;
            }
        }
        public void SetOreContent(MyMwcVoxelMaterialsEnum ore, int content)
        {
            if (content == 0 || !MyVoxelMapOreMaterials.IsRareOre(ore))
            {
                return;
            }

            int previousTotalOreContentSum = m_totalSumOfOreContent;


            int existingContent = 0;
            m_allMaterialsContent.TryGetValue((int)ore, out existingContent);

            int contentToAdd = content;
            if (content < 0) 
            {
                contentToAdd = Math.Max(content, -existingContent);
            }

            if (!m_allMaterialsContent.ContainsKey((int)ore))
                m_allMaterialsContent.Add((int)ore, 0);
            m_allMaterialsContent[(int)ore] += contentToAdd;
            m_totalSumOfOreContent += contentToAdd;

            // this ore hasn't any content before, so we add it to oreWithContent collection
            if (contentToAdd > 0 && existingContent == 0)
            {
                m_oreWithContent.Add(ore);
            }
            // this ore has no content now, so we remove it from oreWithContent collection
            else if (contentToAdd < 0 && m_allMaterialsContent[(int)ore] == 0)
            {
                m_oreWithContent.Remove(ore);
            }
            
            bool containsOreChanged = false;
            // detect if cell was changed from empty to not empty
            if (m_totalSumOfOreContent > 0 && previousTotalOreContentSum == 0)
            {                
                containsOreChanged = true;
            }
            // detect if cell was changed from not empty to empty
            else if (previousTotalOreContentSum > 0 && m_totalSumOfOreContent <= 0)
            {                
                containsOreChanged = true;
            }
            
            if (containsOreChanged && OnVoxelMapOreDepositCellContainsOreChanged != null)
            {
                OnVoxelMapOreDepositCellContainsOreChanged(this, m_totalSumOfOreContent == 0);
            }
            m_positionIsDirty = true;
        }
        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);
        }
Exemple #26
0
        public Vector3?GetPosition(MyMwcVoxelMaterialsEnum material)
        {
            if (m_positionIsDirty)
            {
                RecalculatePositions();
                m_positionIsDirty = false;
            }

            Vector3?pos;

            m_allMaterialsPositions.TryGetValue((int)material, out pos);
            return(pos);
        }
        public static MySingleMaterialHelper GetForMaterial(MyMwcVoxelMaterialsEnum material)
        {
            if (m_preallocatedSingleMaterialHelpers[(int)material] == null)
            {
                m_preallocatedSingleMaterialHelpers[(int)material] = new MySingleMaterialHelper();
                m_preallocatedSingleMaterialHelpers[(int)material].LoadData();
                m_preallocatedSingleMaterialHelpers[(int)material].SetMaterial(material);
            }

            return(m_preallocatedSingleMaterialHelpers[(int)material]);
            //m_singleMaterialHelper.SetMaterial(material);
            //return m_singleMaterialHelper;
        }
Exemple #28
0
        //  Parameter 'useTwoTexturesPerMaterial' tells us if we use two textures per material. One texture for axis XZ and second for axis Y.
        //  Use it for rock/stone materials. Don't use it for gold/silver, because there you don't need to make difference between side and bottom materials.
        //  Using this we save texture memory, but pixel shader still used differenced textures (two samplers looking to same texture)
        public MyVoxelMaterial(MyMwcVoxelMaterialsEnum materialEnum, string assetName, bool isIndestructible, bool useTwoTextures, float specularIntensity, float specularPower, bool hasBuilderVersion)
        {
            //  SpecularPower must be > 0, because pow() makes NaN results if called with zero
            MyCommonDebugUtils.AssertRelease(specularPower > 0);

            m_assetName         = assetName;
            IsIndestructible    = isIndestructible;
            SpecularIntensity   = specularIntensity;
            SpecularPower       = specularPower;
            UseTwoTextures      = useTwoTextures;
            m_materialEnum      = materialEnum;
            m_hasBuilderVersion = hasBuilderVersion && MyFakes.MWBUILDER;
        }
        static void Add(MyMwcVoxelMaterialsEnum materialEnum, string assetName, bool isIndestructible, bool useTwoTextures, float specularShininess, float specularPower, bool hasBuilderVersion)
        {
            //  Check if not yet assigned
            MyCommonDebugUtils.AssertRelease(m_materials[(int)materialEnum] == null);

            //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("new MyVoxelMaterial");

            //  Create and add into array
            MyVoxelMaterial voxelMaterial = new MyVoxelMaterial(materialEnum, assetName, isIndestructible, useTwoTextures, specularShininess, specularPower, hasBuilderVersion);

            m_materials[(int)materialEnum]     = voxelMaterial;
            m_meshMaterials[(int)materialEnum] = new MyMeshMaterial("Textures\\Voxels\\" + assetName + "_ForAxisXZ", assetName, voxelMaterial.GetTextures().TextureDiffuseForAxisXZ, voxelMaterial.GetTextures().TextureNormalMapForAxisXZ);
        }
        //  Parameter 'useTwoTexturesPerMaterial' tells us if we use two textures per material. One texture for axis XZ and second for axis Y.
        //  Use it for rock/stone materials. Don't use it for gold/silver, because there you don't need to make difference between side and bottom materials.
        //  Using this we save texture memory, but pixel shader still used differenced textures (two samplers looking to same texture)
        public MyVoxelMaterial(MyMwcVoxelMaterialsEnum materialEnum, string assetName, bool isIndestructible, bool useTwoTextures, float specularIntensity, float specularPower, bool hasBuilderVersion)
        {
            //  SpecularPower must be > 0, because pow() makes NaN results if called with zero
            MyCommonDebugUtils.AssertRelease(specularPower > 0);

            m_assetName = assetName;
            IsIndestructible = isIndestructible;
            SpecularIntensity = specularIntensity;
            SpecularPower = specularPower;
            UseTwoTextures = useTwoTextures;
            m_materialEnum = materialEnum;
            m_hasBuilderVersion = hasBuilderVersion && MyFakes.MWBUILDER;
        }
        public void UpdateVoxelMultiTextures(MyMwcVoxelMaterialsEnum mat0, MyMwcVoxelMaterialsEnum?mat1, MyMwcVoxelMaterialsEnum?mat2)
        {
            m_multimaterial = false;
            //  Get with lazy-load
            // Material 0
            MyVoxelMaterial         voxelMaterial = MyVoxelMaterials.Get(mat0);
            MyVoxelMaterialTextures voxelTexture  = voxelMaterial.GetTextures();

            m_D3DEffect.SetTexture(m_textureDiffuseForAxisXZ, (Texture)voxelTexture.TextureDiffuseForAxisXZ);
            m_D3DEffect.SetTexture(m_textureNormalMapForAxisXZ, (Texture)voxelTexture.TextureNormalMapForAxisXZ);
            m_D3DEffect.SetTexture(m_textureDiffuseForAxisY, (Texture)voxelTexture.TextureDiffuseForAxisY);
            m_D3DEffect.SetTexture(m_textureNormalMapForAxisY, (Texture)voxelTexture.TextureNormalMapForAxisY);

            m_D3DEffect.SetValue(m_specularIntensity, voxelMaterial.SpecularIntensity);
            m_D3DEffect.SetValue(m_specularPower, voxelMaterial.SpecularPower);

            // Material 1
            if (mat1.HasValue)
            {
                m_multimaterial = true;
                MyVoxelMaterial         voxelMaterial2 = MyVoxelMaterials.Get(mat1.Value);
                MyVoxelMaterialTextures voxelTexture2  = voxelMaterial2.GetTextures();

                m_D3DEffect.SetTexture(m_textureDiffuseForAxisXZ2, (Texture)voxelTexture2.TextureDiffuseForAxisXZ);
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisXZ2, (Texture)voxelTexture2.TextureNormalMapForAxisXZ);
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisY2, (Texture)voxelTexture2.TextureDiffuseForAxisY);
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisY2, (Texture)voxelTexture2.TextureNormalMapForAxisY);

                m_D3DEffect.SetValue(m_specularIntensity2, voxelMaterial2.SpecularIntensity);
                m_D3DEffect.SetValue(m_specularPower2, voxelMaterial2.SpecularPower);
            }

            // Material 2
            if (mat2.HasValue)
            {
                m_multimaterial = true;

                MyVoxelMaterial         voxelMaterial3 = MyVoxelMaterials.Get(mat2.Value);
                MyVoxelMaterialTextures voxelTexture3  = voxelMaterial3.GetTextures();

                m_D3DEffect.SetTexture(m_textureDiffuseForAxisXZ3, (Texture)voxelTexture3.TextureDiffuseForAxisXZ);
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisXZ3, (Texture)voxelTexture3.TextureNormalMapForAxisXZ);
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisY3, (Texture)voxelTexture3.TextureDiffuseForAxisY);
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisY3, (Texture)voxelTexture3.TextureNormalMapForAxisY);

                m_D3DEffect.SetValue(m_specularIntensity3, voxelMaterial3.SpecularIntensity);
                m_D3DEffect.SetValue(m_specularPower3, voxelMaterial3.SpecularPower);
            }
        }
        public void OptimizeSize()
        {
            if (!m_singleMaterialForWholeCell && TestIsSingleMaterial())
            {
                m_singleMaterialForWholeCell  = true;
                m_singleMaterial              = m_materials[0];
                m_singleIndestructibleContent = m_indestructibleContent[0];
            }

            if (m_singleMaterialForWholeCell)
            {
                m_materials             = null;
                m_indestructibleContent = null;
            }
        }
        //  Check if we new material differs from one main material and if yes, we need to start using 3D arrays
        void CheckInitArrays(MyMwcVoxelMaterialsEnum material)
        {
            if ((m_singleMaterialForWholeCell == true) && (m_singleMaterial != material))
            {
                m_materials             = new MyMwcVoxelMaterialsEnum[voxelsInCell];
                m_indestructibleContent = new byte[voxelsInCell];
                //  Fill with present cell values
                for (int xyz = 0; xyz < voxelsInCell; xyz++)
                {
                    m_materials[xyz]             = m_singleMaterial;
                    m_indestructibleContent[xyz] = m_singleIndestructibleContent;
                }

                //  From now, this cell contains more than one material
                m_singleMaterialForWholeCell = false;
            }
        }
Exemple #34
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);
        }
Exemple #35
0
        private int OreComparer(MyMwcVoxelMaterialsEnum ore1, MyMwcVoxelMaterialsEnum ore2)
        {
            int content1 = m_allMaterialsContent[(int)ore1];
            int content2 = m_allMaterialsContent[(int)ore2];

            if (content1 == content2)
            {
                return(0);
            }
            else if (content1 < content2)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }
        public static MyMultiMaterialHelper GetForMultimaterial(MyMwcVoxelMaterialsEnum material0, MyMwcVoxelMaterialsEnum material1, MyMwcVoxelMaterialsEnum material2)
        {
            int id = MyVoxelCacheCellRender.GetMultimaterialId(material0, material1, material2);
            MyMultiMaterialHelper helper = null;

            m_preallocatedMultiMaterialHelpers.TryGetValue(id, out helper);
            if (helper == null)
            {
                helper = new MyMultiMaterialHelper();
                helper.LoadData();
                helper.SetMaterials(material0, material1, material2);
                m_preallocatedMultiMaterialHelpers.Add(id, helper);
            }
            return(helper);

            //m_multiMaterialHelper.SetMaterials(material0, material1, material2);
            //return m_multiMaterialHelper;
        }
        public static int GetMultimaterialId(MyMwcVoxelMaterialsEnum mat0, MyMwcVoxelMaterialsEnum mat1, MyMwcVoxelMaterialsEnum mat2)
        {
            int i0 = (int)mat0;
            int i1 = (int)mat1;
            int i2 = (int)mat2;

            if (i0 > i1)
            {
                MyUtils.Swap(ref i0, ref i1);
            }
            if (i1 > i2)
            {
                MyUtils.Swap(ref i1, ref i2);
            }
            if (i0 > i1)
            {
                MyUtils.Swap(ref i0, ref i1);
            }
            return(i0 + i1 * VoxelMaterialCount + i2 * VoxelMaterialCount * VoxelMaterialCount);
        }
        public override void RecreateControls(bool contructor)
        {
            Controls.Clear();



            m_scale = 0.7f;

            AddCaption(new System.Text.StringBuilder("Render Model FX"), Color.Yellow.ToVector4());

            MyGuiControlLabel label = new MyGuiControlLabel(this, new Vector2(0.01f, -m_size.Value.Y / 2.0f + 0.07f), null, new System.Text.StringBuilder("(press ALT to share focus)"), Color.Yellow.ToVector4(), MyGuiConstants.LABEL_TEXT_SCALE * 0.7f,
                                                            MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP);

            Controls.Add(label);

            m_currentPosition = -m_size.Value / 2.0f + new Vector2(0.02f, 0.10f);


            m_currentPosition.Y += 0.01f;

            /*
             * AddLabel(new StringBuilder("Channels"), Color.Yellow.ToVector4(), 1.2f);
             * AddSlider(new StringBuilder("Channel0"), 0, 1.0f, null, MemberHelper.GetMember(() => MyRender.Channel0Intensity));
             * AddSlider(new StringBuilder("Channel1"), 0, 1.0f, null, MemberHelper.GetMember(() => MyRender.Channel1Intensity));
             */
            AddLabel(new StringBuilder("Environmental maps"), Color.Yellow.ToVector4(), 1.2f);
            AddSlider(new StringBuilder("LOD0 max distance"), 50.0f, 1000.0f, null, MemberHelper.GetMember(() => MyEnvironmentMap.NearDistance));
            AddSlider(new StringBuilder("LOD1 max distance"), 50.0f, 1000.0f, null, MemberHelper.GetMember(() => MyEnvironmentMap.FarDistance));
            AddButton(new StringBuilder("Rebuild"), delegate { MyEnvironmentMap.Reset(); });

            var listbox = AddListbox();

            listbox.ItemSelect += new OnListboxItemSelect(listbox_ItemSelect);
            listbox.AddItem(-1, new StringBuilder("None"));
            for (int i = 0; i < MyVoxelMaterials.GetMaterialsCount(); i++)
            {
                MyMwcVoxelMaterialsEnum mat = (MyMwcVoxelMaterialsEnum)i;
                listbox.AddItem((int)mat, new StringBuilder(mat.ToString()));
            }
            listbox.SetSelectedItem(-1);
        }
Exemple #39
0
        //  When tube/head mounted into voxels and is harvesting
        void StartInVoxel(MyVoxelMap voxelMap)
        {
            //  We found voxel so we stop here
            m_inVoxelMap = voxelMap;
            CurrentState = MyHarvestingDeviceEnum.InVoxel;
            StopTubeMovingCue();
            StartGrindingCue();
            m_lastTimeParticleAdded = null;
            m_parentMinerShip.Physics.Clear();
            m_parentMinerShip.Physics.Immovable = true;

            MyMwcVector3Int tempVoxelCoord = voxelMap.GetVoxelCenterCoordinateFromMeters(ref m_headPositionTransformed);

            m_originalVoxelContent = voxelMap.GetVoxelContent(ref tempVoxelCoord);
            m_voxelMaterial        = voxelMap.GetVoxelMaterial(ref tempVoxelCoord);


            m_harvestingParticleEffect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Harvester_Harvesting);
            m_harvestingParticleEffect.UserBirthMultiplier  = 0.25f;
            m_harvestingParticleEffect.UserRadiusMultiplier = 1;
            m_harvestingParticleEffect.UserColorMultiplier  = new Vector4(3, 3, 3, 3);
            Matrix dirMatrix = MyMath.MatrixFromDir(WorldMatrix.Forward);

            m_harvestingParticleEffect.WorldMatrix = Matrix.CreateWorld(m_headPositionTransformed, dirMatrix.Forward, dirMatrix.Up);

            //  Empty voxels are problematic and can lead to "extremely fast harvesting". So here we do this
            //  trick and its effect will be that even empty voxels will take few seconds to harvest.
            if (m_originalVoxelContent == 0)
            {
                m_originalVoxelContent = 1;
            }

            m_actualVoxelContent = (float)m_originalVoxelContent;
            m_harvestingSpeed    = m_actualVoxelContent / TIME_TO_HARVEST_WHOLE_VOXEL_IN_UPDATE_TIMES;

            if (!MyVoxelMapOreMaterials.CanBeHarvested(m_voxelMaterial))
            {
                HUD.MyHud.ShowIndestructableAsteroidNotification();
                StartReturningBack();
            }
        }
 public static void Run(MyVoxelMap voxelMap, MyModel model, MyvoxelImportAction importAction, Matrix modelWorld, float modelScale, MyMwcVoxelMaterialsEnum? voxelMaterial, ref bool changed)
 {
     MyVoxelImport voxelImport = new MyVoxelImport(voxelMap, model, importAction, modelWorld, modelScale, voxelMaterial, ref changed);
 }
        public static MyVoxelMaterial Get(MyMwcVoxelMaterialsEnum materialEnum)
        {
            materialEnum = GetAllowedVoxelMaterial(materialEnum);

            return m_materials[(int)materialEnum];
        }
 public static MyMeshMaterial GetMaterialForMesh(MyMwcVoxelMaterialsEnum materialEnum)
 {
     return m_meshMaterials[(int)materialEnum];
 }
        public Texture RenderAsteroidMaterialPreview(MyMwcVoxelMaterialsEnum material, int width, int height, float lightsIntensity = 2f)
        {               
            m_fullSizeRT = MyRender.GetRenderTarget(MyRenderTargets.Auxiliary0);

            if (m_fullSizeRT == null || MyGuiScreenGamePlay.Static == null)
                return null;

            Device device = MyMinerGame.Static.GraphicsDevice;

            Texture renderTarget = new Texture(device, width, height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);

            PrepareRender(width, height);

            MyRender.Sun.Direction = new Vector3(1.5f, -1.5f, -1);
            MyRender.Sun.Direction.Normalize();

            MyRender.Sun.Intensity = lightsIntensity;
            foreach (var light in m_setup.LightsToUse)
            {
                light.Intensity = 3 * lightsIntensity;
            }

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = false;
            }

            float distance = 2.1f;

            Matrix viewMatrix = Matrix.Identity;
            m_setup.ViewMatrix = viewMatrix;

            m_setup.EnableNear = false;


            //var modelEnum = MyStaticAsteroid.GetModelsFromType(MyMwcObjectBuilder_StaticAsteroid_TypesEnum.StaticAsteroid20m_A).LOD0;
            var modelEnum = MyModelsEnum.sphere_smooth;
            var model = MyModels.GetModelOnlyData(modelEnum);
            var test = model.BoundingSphere.Radius;
            model.SetDrawTechnique(MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID);

            
            FakeEntity.VoxelMaterial = material;
            FakeEntity.InitDrawTechniques();


            //generate world matrix
            Matrix worldMatrix = Matrix.Identity;

            worldMatrix.Translation = -model.BoundingSphere.Center;
            //worldMatrix *= Matrix.CreateRotationY(-3.0f * MathHelper.PiOver4);
            //worldMatrix *= Matrix.CreateRotationX(0.7f * MathHelper.PiOver4);
            worldMatrix.Translation += new Vector3(0, 0, -model.BoundingSphere.Radius * distance);

            SetupRenderElements(model, worldMatrix, staticAsteroid: true);

            SetupLights(model);

            MyRender.PushRenderSetup(m_setup);
            MyRender.Draw();
            MyRender.PopRenderSetup();

            BlitToThumbnail(device, renderTarget);

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = true;
            }

            return renderTarget; 

            return null;
        }
        MyVoxelImport(MyVoxelMap voxelMap, MyModel model, MyvoxelImportAction importAction, Matrix modelWorld, float modelScale, MyMwcVoxelMaterialsEnum? voxelMaterial, ref bool changed)
        {
            // Load model, get triangles transformed to model's world matrix
            LoadModel(model, modelWorld, modelScale);

            RescaleModel(voxelMap, MyVoxelImportOptions.KeepScale);

            //  Fill lookup array with triangles located at specified voxel positions. Array is 2D.
            FillTrianglesLookup(voxelMap);

            // Performs action
           //PerformAction(voxelMap, importAction, voxelMaterial, ref changed);
            Import(voxelMap);
        }
        bool PerformGridAction(MyVoxelMap voxelMap, MyvoxelImportAction action, int gridX, int gridZ, ref MyMwcVector3Int minChanged, ref MyMwcVector3Int maxChanged, MyMwcVoxelMaterialsEnum? voxelMaterial, ref bool changed)
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("PerformGridAction");

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("get content sum");
            int[, ,] voxelContentSum = GetVoxelContentSum(voxelMap, gridX, gridZ);
            if (voxelContentSum == null)
            {
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

                return false;
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("loop");
            bool anyContentChanged = false;

            //  Transform grid values to voxels
            int voxelStartX = gridX * VOXELS_IN_GRID_IN_ONE_DIRECTION;
            int voxelStartZ = gridZ * VOXELS_IN_GRID_IN_ONE_DIRECTION;


            switch (action)
            {
                case MyvoxelImportAction.AddVoxels:
                    MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyvoxelImportAction.AddVoxels");
                    for (int x = 0; x < VOXELS_IN_GRID_IN_ONE_DIRECTION; x++) for (int y = 0; y < voxelMap.Size.Y; y++) for (int z = 0; z < VOXELS_IN_GRID_IN_ONE_DIRECTION; z++)
                    {
                        MyMwcVector3Int voxelCoord = new MyMwcVector3Int(voxelStartX + x, y, voxelStartZ + z);

                        byte newContent =  (byte)(voxelContentSum[x, y, z] * MyVoxelConstants.VOXEL_CONTENT_FULL / GRID_POINTS_IN_ONE_VOXEL_TOTAL);
                        if (newContent == 0) continue;

                        bool c = PerformAddVoxels(voxelMap, voxelCoord, newContent, ref changed);
                        c |= PerformChangeMaterialVoxels(voxelMap, voxelCoord, voxelMaterial, ref changed);
                        if (c)
                        {
                            anyContentChanged = true;
                            if (voxelCoord.X < minChanged.X) minChanged.X = voxelCoord.X;
                            if (voxelCoord.Y < minChanged.Y) minChanged.Y = voxelCoord.Y;
                            if (voxelCoord.Z < minChanged.Z) minChanged.Z = voxelCoord.Z;
                            if (voxelCoord.X > maxChanged.X) maxChanged.X = voxelCoord.X;
                            if (voxelCoord.Y > maxChanged.Y) maxChanged.Y = voxelCoord.Y;
                            if (voxelCoord.Z > maxChanged.Z) maxChanged.Z = voxelCoord.Z;
                        }
                    }
                    MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                    break;

                case MyvoxelImportAction.RemoveVoxels:
                    for (int x = 0; x < VOXELS_IN_GRID_IN_ONE_DIRECTION; x++) for (int y = 0; y < voxelMap.Size.Y; y++) for (int z = 0; z < VOXELS_IN_GRID_IN_ONE_DIRECTION; z++)
                    {
                        MyMwcVector3Int voxelCoord = new MyMwcVector3Int(voxelStartX + x, y, voxelStartZ + z);

                        byte newContent = (byte)(voxelContentSum[x, y, z] * MyVoxelConstants.VOXEL_CONTENT_FULL / GRID_POINTS_IN_ONE_VOXEL_TOTAL);
                        if (newContent == 0) continue;

                        if (PerformRemoveVoxels(voxelMap, voxelCoord, newContent, ref changed))
                        {
                            anyContentChanged = true;
                            if (voxelCoord.X < minChanged.X) minChanged.X = voxelCoord.X;
                            if (voxelCoord.Y < minChanged.Y) minChanged.Y = voxelCoord.Y;
                            if (voxelCoord.Z < minChanged.Z) minChanged.Z = voxelCoord.Z;
                            if (voxelCoord.X > maxChanged.X) maxChanged.X = voxelCoord.X;
                            if (voxelCoord.Y > maxChanged.Y) maxChanged.Y = voxelCoord.Y;
                            if (voxelCoord.Z > maxChanged.Z) maxChanged.Z = voxelCoord.Z;
                        }
                    }
                    break;

                case MyvoxelImportAction.ChangeMaterial:
                    for (int x = 0; x < VOXELS_IN_GRID_IN_ONE_DIRECTION; x++) for (int y = 0; y < voxelMap.Size.Y; y++) for (int z = 0; z < VOXELS_IN_GRID_IN_ONE_DIRECTION; z++)
                    {
                        MyMwcVector3Int voxelCoord = new MyMwcVector3Int(voxelStartX + x, y, voxelStartZ + z);

                        byte newContent = (byte)(voxelContentSum[x, y, z] * MyVoxelConstants.VOXEL_CONTENT_FULL / GRID_POINTS_IN_ONE_VOXEL_TOTAL);
                        if (newContent == 0) continue;

                        if (PerformChangeMaterialVoxels(voxelMap, voxelCoord, voxelMaterial, ref changed))
                        {
                            anyContentChanged = true;
                            if (voxelCoord.X < minChanged.X) minChanged.X = voxelCoord.X;
                            if (voxelCoord.Y < minChanged.Y) minChanged.Y = voxelCoord.Y;
                            if (voxelCoord.Z < minChanged.Z) minChanged.Z = voxelCoord.Z;
                            if (voxelCoord.X > maxChanged.X) maxChanged.X = voxelCoord.X;
                            if (voxelCoord.Y > maxChanged.Y) maxChanged.Y = voxelCoord.Y;
                            if (voxelCoord.Z > maxChanged.Z) maxChanged.Z = voxelCoord.Z;
                        }
                    }
                    break;

                case MyvoxelImportAction.SoftenVoxels:
                    for (int x = 0; x < VOXELS_IN_GRID_IN_ONE_DIRECTION; x++) for (int y = 0; y < voxelMap.Size.Y; y++) for (int z = 0; z < VOXELS_IN_GRID_IN_ONE_DIRECTION; z++)
                    {
                        MyMwcVector3Int voxelCoord = new MyMwcVector3Int(voxelStartX + x, y, voxelStartZ + z);

                        byte newContent = (byte)(voxelContentSum[x, y, z] * MyVoxelConstants.VOXEL_CONTENT_FULL / GRID_POINTS_IN_ONE_VOXEL_TOTAL);
                        if (newContent == 0) continue;

                        if (PerformSoftenVoxels(voxelMap, voxelCoord, ref changed))
                        {
                            anyContentChanged = true;
                            if (voxelCoord.X < minChanged.X) minChanged.X = voxelCoord.X;
                            if (voxelCoord.Y < minChanged.Y) minChanged.Y = voxelCoord.Y;
                            if (voxelCoord.Z < minChanged.Z) minChanged.Z = voxelCoord.Z;
                            if (voxelCoord.X > maxChanged.X) maxChanged.X = voxelCoord.X;
                            if (voxelCoord.Y > maxChanged.Y) maxChanged.Y = voxelCoord.Y;
                            if (voxelCoord.Z > maxChanged.Z) maxChanged.Z = voxelCoord.Z;
                        }
                    }
                    break;

                case MyvoxelImportAction.WrinkleVoxels:
                    for (int x = 0; x < VOXELS_IN_GRID_IN_ONE_DIRECTION; x++) for (int y = 0; y < voxelMap.Size.Y; y++) for (int z = 0; z < VOXELS_IN_GRID_IN_ONE_DIRECTION; z++)
                    {
                        MyMwcVector3Int voxelCoord = new MyMwcVector3Int(voxelStartX + x, y, voxelStartZ + z);

                        byte newContent = (byte)(voxelContentSum[x, y, z] * MyVoxelConstants.VOXEL_CONTENT_FULL / GRID_POINTS_IN_ONE_VOXEL_TOTAL);

                        if (newContent == 0) continue;

                        if (PerformWrinkleVoxels(voxelMap, voxelCoord, ref changed))
                        {
                            anyContentChanged = true;
                            if (voxelCoord.X < minChanged.X) minChanged.X = voxelCoord.X;
                            if (voxelCoord.Y < minChanged.Y) minChanged.Y = voxelCoord.Y;
                            if (voxelCoord.Z < minChanged.Z) minChanged.Z = voxelCoord.Z;
                            if (voxelCoord.X > maxChanged.X) maxChanged.X = voxelCoord.X;
                            if (voxelCoord.Y > maxChanged.Y) maxChanged.Y = voxelCoord.Y;
                            if (voxelCoord.Z > maxChanged.Z) maxChanged.Z = voxelCoord.Z;
                        }
                    }
                    break;
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
            return anyContentChanged;
        }
        public void AddVoxelHand(uint voxelMapId, uint entityId, float radius, MyMwcVoxelHandModeTypeEnum handMode, MyMwcVoxelMaterialsEnum? material)
        {
            var msg = new MyEventAddVoxelHand();
            msg.EntityId = entityId;
            msg.Radius = radius;
            msg.HandMode = handMode;
            msg.VoxelMaterial = material;
            msg.VoxelMapEntityId = voxelMapId;

            Peers.SendToAll(ref msg, NetDeliveryMethod.ReliableOrdered, 0);
        }
 public override void Start(MySmallShip ship, MyDetectorConfiguration configuration) 
 {
     base.Start(ship, configuration);
     m_oreMaterial = (MyMwcVoxelMaterialsEnum)configuration.Parameters[0];
 }        
 public static bool IsIndestructible(MyMwcVoxelMaterialsEnum material)
 {
     return(m_materials[(int)material].IsIndestructible);
 }
 public static bool IsIndestructible(MyMwcVoxelMaterialsEnum material)
 {
     return m_materials[(int)material].IsIndestructible;
 }
 public static MyMeshMaterial GetMaterialForMesh(MyMwcVoxelMaterialsEnum materialEnum)
 {
     return(m_meshMaterials[(int)materialEnum]);
 }
        static void SetupShaderForMaterialAlternative(MyEffectBase shader, MyVoxelCacheCellRenderBatchType batchType, MyMwcVoxelMaterialsEnum m0, MyMwcVoxelMaterialsEnum? m1, MyMwcVoxelMaterialsEnum? m2)
        {
            MyEffectVoxels effectVoxels = shader as MyEffectVoxels;

            if (batchType == MyVoxelCacheCellRenderBatchType.SINGLE_MATERIAL)
            {
                effectVoxels.UpdateVoxelTextures(OverrideVoxelMaterial ?? m0);
            }
            else if (batchType == MyVoxelCacheCellRenderBatchType.MULTI_MATERIAL)
            {
                effectVoxels.UpdateVoxelMultiTextures(OverrideVoxelMaterial ?? m0, OverrideVoxelMaterial ?? m1, OverrideVoxelMaterial ?? m2);
            }
        }
 public static MyMwcVoxelMaterialProperties GetShipTypeProperties(MyMwcVoxelMaterialsEnum material)
 {
     Debug.Assert(MaterialProperties.ContainsKey((int)material));
     return MaterialProperties[(int)material];
 }
 public static void Run(MyVoxelMap voxelMap, Vector3[] vertexes, MyTriangleVertexIndices[] triangles, MyvoxelImportAction importAction, Matrix modelWorld, MyMwcVoxelMaterialsEnum? voxelMaterial, ref bool changed)
 {
     MyVoxelImport voxelImport = new MyVoxelImport(voxelMap, vertexes, triangles, importAction, modelWorld, voxelMaterial, ref changed);
 }
        public void UpdateVoxelTextures(MyMwcVoxelMaterialsEnum material)
        {
            m_multimaterial = false;

            //  Get with lazy-load
            MyVoxelMaterial voxelMaterial = MyVoxelMaterials.Get(material);
            MyVoxelMaterialTextures voxelTexture = voxelMaterial.GetTextures();

            if (MyRender.DebugDiffuseTexture)
            {
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisXZ, (Texture)MyRender.GetDebugTexture());
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisY, (Texture)MyRender.GetDebugTexture());
            }
            else
            {
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisXZ, (Texture)voxelTexture.TextureDiffuseForAxisXZ);
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisY, (Texture)voxelTexture.TextureDiffuseForAxisY);
            }

            if (MyRender.DebugNormalTexture)
            {
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisXZ, (Texture)MyRender.GetDebugNormalTexture());
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisY, (Texture)MyRender.GetDebugNormalTexture());
            }
            else
            {
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisXZ, (Texture)voxelTexture.TextureNormalMapForAxisXZ);
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisY, (Texture)voxelTexture.TextureNormalMapForAxisY);
            }

            m_D3DEffect.SetValue(m_specularIntensity, voxelMaterial.SpecularIntensity);
            m_D3DEffect.SetValue(m_specularPower, voxelMaterial.SpecularPower);
        }
        MyVoxelImport(MyVoxelMap voxelMap, Vector3[] vertexes, MyTriangleVertexIndices[] triangles, MyvoxelImportAction importAction, Matrix modelWorld, MyMwcVoxelMaterialsEnum? voxelMaterial, ref bool changed)
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("voxel import");

            // Load model, get triangles transformed to model's world matrix
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("load model");
            LoadModel(vertexes, triangles, modelWorld);

            //  Fill lookup array with triangles located at specified voxel positions. Array is 2D.
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("fill lookup");
            FillTrianglesLookup(voxelMap);

            // Performs action
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("perform action");
            PerformAction(voxelMap, importAction, voxelMaterial, ref changed);

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
        public void UpdateVoxelMultiTextures(MyMwcVoxelMaterialsEnum mat0, MyMwcVoxelMaterialsEnum? mat1, MyMwcVoxelMaterialsEnum? mat2)
        {
            m_multimaterial = false;
            //  Get with lazy-load
            // Material 0
            MyVoxelMaterial voxelMaterial = MyVoxelMaterials.Get(mat0);
            MyVoxelMaterialTextures voxelTexture = voxelMaterial.GetTextures();

            m_D3DEffect.SetTexture(m_textureDiffuseForAxisXZ, (Texture)voxelTexture.TextureDiffuseForAxisXZ);
            m_D3DEffect.SetTexture(m_textureNormalMapForAxisXZ, (Texture)voxelTexture.TextureNormalMapForAxisXZ);
            m_D3DEffect.SetTexture(m_textureDiffuseForAxisY, (Texture)voxelTexture.TextureDiffuseForAxisY);
            m_D3DEffect.SetTexture(m_textureNormalMapForAxisY, (Texture)voxelTexture.TextureNormalMapForAxisY);

            m_D3DEffect.SetValue(m_specularIntensity, voxelMaterial.SpecularIntensity);
            m_D3DEffect.SetValue(m_specularPower, voxelMaterial.SpecularPower);

            // Material 1
            if (mat1.HasValue)
            {
                m_multimaterial = true;
                MyVoxelMaterial voxelMaterial2 = MyVoxelMaterials.Get(mat1.Value);
                MyVoxelMaterialTextures voxelTexture2 = voxelMaterial2.GetTextures();

                m_D3DEffect.SetTexture(m_textureDiffuseForAxisXZ2, (Texture)voxelTexture2.TextureDiffuseForAxisXZ);
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisXZ2, (Texture)voxelTexture2.TextureNormalMapForAxisXZ);
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisY2, (Texture)voxelTexture2.TextureDiffuseForAxisY);
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisY2, (Texture)voxelTexture2.TextureNormalMapForAxisY);

                m_D3DEffect.SetValue(m_specularIntensity2, voxelMaterial2.SpecularIntensity);
                m_D3DEffect.SetValue(m_specularPower2, voxelMaterial2.SpecularPower);
            }

            // Material 2
            if (mat2.HasValue)
            {
                m_multimaterial = true;

                MyVoxelMaterial voxelMaterial3 = MyVoxelMaterials.Get(mat2.Value);
                MyVoxelMaterialTextures voxelTexture3 = voxelMaterial3.GetTextures();

                m_D3DEffect.SetTexture(m_textureDiffuseForAxisXZ3, (Texture)voxelTexture3.TextureDiffuseForAxisXZ);
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisXZ3, (Texture)voxelTexture3.TextureNormalMapForAxisXZ);
                m_D3DEffect.SetTexture(m_textureDiffuseForAxisY3, (Texture)voxelTexture3.TextureDiffuseForAxisY);
                m_D3DEffect.SetTexture(m_textureNormalMapForAxisY3, (Texture)voxelTexture3.TextureNormalMapForAxisY);

                m_D3DEffect.SetValue(m_specularIntensity3, voxelMaterial3.SpecularIntensity);
                m_D3DEffect.SetValue(m_specularPower3, voxelMaterial3.SpecularPower);
            }
        }
        void PerformAction(MyVoxelMap voxelMap, MyvoxelImportAction action, MyMwcVoxelMaterialsEnum? voxelMaterial, ref bool changed)
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("PerformAction");

            //  Voxel map size must be multiple of grid size. Or, whole grid must fit exactly into X times into voxel map, without crossing border!
            MyCommonDebugUtils.AssertRelease((voxelMap.Size.X % VOXELS_IN_GRID_IN_ONE_DIRECTION) == 0);

            //  Voxel map size must be multiple of grid size. Or, whole grid must fit exactly into X times into voxel map, without crossing border!
            MyCommonDebugUtils.AssertRelease((voxelMap.Size.Z % VOXELS_IN_GRID_IN_ONE_DIRECTION) == 0);

            int gridsCountX = voxelMap.Size.X / VOXELS_IN_GRID_IN_ONE_DIRECTION;
            int gridsCountZ = voxelMap.Size.Z / VOXELS_IN_GRID_IN_ONE_DIRECTION;

            //  Space between two grid points in metres
            m_gridPointsSize = MyVoxelConstants.VOXEL_SIZE_IN_METRES / (float)GRID_POINTS_IN_ONE_VOXEL_IN_ONE_DIRECTION;
            m_gridPointsSizeHalf = m_gridPointsSize / 2.0f;

            //  Get min corner of the box
            MyMwcVector3Int minCorner = voxelMap.GetVoxelCoordinateFromMeters(m_minCoord);

            //  Get max corner of the box
            MyMwcVector3Int maxCorner = voxelMap.GetVoxelCoordinateFromMeters(m_maxCoord);

            voxelMap.FixVoxelCoord(ref minCorner);
            voxelMap.FixVoxelCoord(ref maxCorner);

            //  We are tracking which voxels were changed, so we can invalidate only needed cells in the cache
            MyMwcVector3Int minChanged = maxCorner;
            MyMwcVector3Int maxChanged = minCorner;

            bool contentChanged = false;

            for (int gridX = 0; gridX < gridsCountX; gridX++)
            {
                for (int gridZ = 0; gridZ < gridsCountZ; gridZ++)
                {
                    if (PerformGridAction(voxelMap, action, gridX, gridZ, ref minChanged, ref maxChanged, voxelMaterial, ref changed))
                    {
                        contentChanged = true;
                    }
                }
            }

            if (contentChanged)
            {
                //  Extend borders for cleaning, so it's one pixel on both sides
                minChanged.X -= 1;
                minChanged.Y -= 1;
                minChanged.Z -= 1;
                maxChanged.X += 1;
                maxChanged.Y += 1;
                maxChanged.Z += 1;
                voxelMap.FixVoxelCoord(ref minChanged);
                voxelMap.FixVoxelCoord(ref maxChanged);

                voxelMap.InvalidateCache(minChanged, maxChanged);
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
 public void SetVoxelProperties(MyMwcVoxelHandModeTypeEnum modeType, MyMwcVoxelMaterialsEnum? materialEnum) 
 {
     this.ModeType = modeType;
     this.Material = materialEnum;
 }
        bool PerformChangeMaterialVoxels(MyVoxelMap voxelMap, MyMwcVector3Int voxelCoord, MyMwcVoxelMaterialsEnum? voxelMaterial, ref bool changed)
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("PerformChangeMaterialVoxels");
            if (voxelMaterial != null)
            {
                byte originalContent = voxelMap.GetVoxelContent(ref voxelCoord);
                if (originalContent == MyVoxelConstants.VOXEL_CONTENT_EMPTY)
                {
                    // if there are no voxel content then do nothing
                    MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                    return false;
                }

                MyMwcVoxelMaterialsEnum originalMaterial;
                byte originalIndestructibleContent;
                voxelMap.GetMaterialAndIndestructibleContent(ref voxelCoord, out originalMaterial,
                                                             out originalIndestructibleContent);
                if (originalMaterial == voxelMaterial.Value)
                {
                    // if original material is same as new material then do nothing
                    MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                    return false;
                }

                byte indestructibleContent = MyVoxelConstants.VOXEL_CONTENT_EMPTY;

                voxelMap.SetVoxelMaterialAndIndestructibleContent(voxelMaterial.Value, indestructibleContent, ref voxelCoord);
                changed = true;
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                return true;
            }
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
            return false;
        }
        //  When tube/head mounted into voxels and is harvesting
        void StartInVoxel(MyVoxelMap voxelMap)
        {
            //  We found voxel so we stop here
            m_inVoxelMap = voxelMap;
            CurrentState = MyHarvestingDeviceEnum.InVoxel;
            StopTubeMovingCue();
            StartGrindingCue();
            m_lastTimeParticleAdded = null;
            m_parentMinerShip.Physics.Clear();
            m_parentMinerShip.Physics.Immovable = true;

            MyMwcVector3Int tempVoxelCoord = voxelMap.GetVoxelCenterCoordinateFromMeters(ref m_headPositionTransformed);
            m_originalVoxelContent = voxelMap.GetVoxelContent(ref tempVoxelCoord);
            m_voxelMaterial = voxelMap.GetVoxelMaterial(ref tempVoxelCoord);


            m_harvestingParticleEffect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Harvester_Harvesting);
            m_harvestingParticleEffect.UserBirthMultiplier = 0.25f;
            m_harvestingParticleEffect.UserRadiusMultiplier = 1;
            m_harvestingParticleEffect.UserColorMultiplier = new Vector4(3, 3, 3, 3);
            Matrix dirMatrix = MyMath.MatrixFromDir(WorldMatrix.Forward);
            m_harvestingParticleEffect.WorldMatrix = Matrix.CreateWorld(m_headPositionTransformed, dirMatrix.Forward, dirMatrix.Up);

            //  Empty voxels are problematic and can lead to "extremely fast harvesting". So here we do this
            //  trick and its effect will be that even empty voxels will take few seconds to harvest.
            if (m_originalVoxelContent == 0) m_originalVoxelContent = 1;

            m_actualVoxelContent = (float)m_originalVoxelContent;
            m_harvestingSpeed = m_actualVoxelContent / TIME_TO_HARVEST_WHOLE_VOXEL_IN_UPDATE_TIMES;

            if (!MyVoxelMapOreMaterials.CanBeHarvested(m_voxelMaterial))
            {
                HUD.MyHud.ShowIndestructableAsteroidNotification();
                StartReturningBack();
            }
        }