Exemplo n.º 1
0
 public static void PaintInShape(MyVoxelBase voxelMap, MyShape shape, byte materialIdx)
 {
     using (voxelMap.Pin())
     {
         if (!voxelMap.MarkedForClose)
         {
             Vector3I vectori;
             Vector3I maxCorner;
             Vector3I minCorner;
             GetVoxelShapeDimensions(voxelMap, shape, out minCorner, out maxCorner, out vectori);
             if (m_cache == null)
             {
                 m_cache = new MyStorageData(MyStorageDataTypeFlags.All);
             }
             Vector3I_RangeIterator it = new Vector3I_RangeIterator(ref Vector3I.Zero, ref vectori);
             while (true)
             {
                 Vector3I vectori2;
                 Vector3I vectori3;
                 if (!it.IsValid())
                 {
                     MySandboxGame.Static.Invoke(delegate {
                         if (voxelMap.Storage != null)
                         {
                             voxelMap.Storage.NotifyChanged(minCorner, maxCorner, MyStorageDataTypeFlags.All);
                         }
                     }, "PaintInShape notify");
                     break;
                 }
                 GetCellCorners(ref minCorner, ref maxCorner, ref it, out vectori2, out vectori3);
                 m_cache.Resize(vectori2, vectori3);
                 MyVoxelRequestFlags considerContent = MyVoxelRequestFlags.ConsiderContent;
                 voxelMap.Storage.ReadRange(m_cache, MyStorageDataTypeFlags.All, 0, vectori2, vectori3, ref considerContent);
                 Vector3I_RangeIterator iterator2 = new Vector3I_RangeIterator(ref vectori2, ref vectori3);
                 while (true)
                 {
                     Vector3D vectord;
                     if (!iterator2.IsValid())
                     {
                         voxelMap.Storage.WriteRange(m_cache, MyStorageDataTypeFlags.Material, vectori2, vectori3, false, true);
                         it.MoveNext();
                         break;
                     }
                     Vector3I p = iterator2.Current - vectori2;
                     MyVoxelCoordSystems.VoxelCoordToWorldPosition(voxelMap.PositionLeftBottomCorner, ref iterator2.Current, out vectord);
                     if ((shape.GetVolume(ref vectord) > 0.5f) && (m_cache.Material(ref p) != 0xff))
                     {
                         m_cache.Material(ref p, materialIdx);
                     }
                     iterator2.MoveNext();
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 public static void RevertShape(MyVoxelBase voxelMap, MyShape shape)
 {
     using (voxelMap.Pin())
     {
         if (!voxelMap.MarkedForClose)
         {
             Vector3I vectori;
             Vector3I maxCorner;
             Vector3I minCorner;
             GetVoxelShapeDimensions(voxelMap, shape, out minCorner, out maxCorner, out vectori);
             minCorner = Vector3I.Max(Vector3I.One, minCorner);
             maxCorner = Vector3I.Max(minCorner, maxCorner - Vector3I.One);
             voxelMap.Storage.DeleteRange(MyStorageDataTypeFlags.All, minCorner, maxCorner, false);
             BoundingBoxD cutOutBox = shape.GetWorldBoundaries();
             MySandboxGame.Static.Invoke(delegate {
                 if (voxelMap.Storage != null)
                 {
                     voxelMap.Storage.NotifyChanged(minCorner, maxCorner, MyStorageDataTypeFlags.All);
                     NotifyVoxelChanged(MyVoxelBase.OperationType.Revert, voxelMap, ref cutOutBox);
                 }
             }, "RevertShape notify");
         }
     }
 }
Exemplo n.º 3
0
 public static unsafe void ChangeMaterialsInShape(MyVoxelBase voxelMap, MyShape shape, byte materialIdx, bool[] materialsToChange)
 {
     if ((voxelMap != null) && (shape != null))
     {
         using (voxelMap.Pin())
         {
             if (!voxelMap.MarkedForClose)
             {
                 Vector3I vectori;
                 Vector3I vectori2;
                 Vector3I vectori5;
                 MatrixD  xd     = shape.Transformation * voxelMap.PositionComp.WorldMatrixInvScaled;
                 MatrixD *xdPtr1 = (MatrixD *)ref xd;
                 xdPtr1.Translation  += voxelMap.SizeInMetresHalf;
                 shape.Transformation = xd;
                 BoundingBoxD worldBoundaries = shape.GetWorldBoundaries();
                 ComputeShapeBounds(voxelMap, ref worldBoundaries, Vector3.Zero, voxelMap.Storage.Size, out vectori, out vectori2);
                 Vector3I voxelCoord = vectori - 1;
                 Vector3I vectori4   = (Vector3I)(vectori2 + 1);
                 voxelMap.Storage.ClampVoxelCoord(ref voxelCoord, 1);
                 voxelMap.Storage.ClampVoxelCoord(ref vectori4, 1);
                 if (m_cache == null)
                 {
                     m_cache = new MyStorageData(MyStorageDataTypeFlags.All);
                 }
                 m_cache.Resize(voxelCoord, vectori4);
                 MyVoxelRequestFlags requestFlags = MyVoxelRequestFlags.AdviseCache | MyVoxelRequestFlags.ConsiderContent;
                 voxelMap.Storage.ReadRange(m_cache, MyStorageDataTypeFlags.Material, 0, voxelCoord, vectori4, ref requestFlags);
                 vectori5.X = vectori.X;
                 while (vectori5.X <= vectori2.X)
                 {
                     vectori5.Y = vectori.Y;
                     while (true)
                     {
                         if (vectori5.Y > vectori2.Y)
                         {
                             int *numPtr3 = (int *)ref vectori5.X;
                             numPtr3[0]++;
                             break;
                         }
                         vectori5.Z = vectori.Z;
                         while (true)
                         {
                             if (vectori5.Z > vectori2.Z)
                             {
                                 int *numPtr2 = (int *)ref vectori5.Y;
                                 numPtr2[0]++;
                                 break;
                             }
                             Vector3I p         = vectori5 - vectori;
                             int      linearIdx = m_cache.ComputeLinear(ref p);
                             byte     index     = m_cache.Material(linearIdx);
                             if (materialsToChange[index])
                             {
                                 Vector3D vectord;
                                 MyVoxelCoordSystems.VoxelCoordToWorldPosition(voxelMap.PositionLeftBottomCorner, ref vectori5, out vectord);
                                 if ((shape.GetVolume(ref vectord) > 0.5f) && (m_cache.Material(ref p) != 0xff))
                                 {
                                     m_cache.Material(ref p, materialIdx);
                                 }
                             }
                             int *numPtr1 = (int *)ref vectori5.Z;
                             numPtr1[0]++;
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
 public static void FillInShape(MyVoxelBase voxelMap, MyShape shape, byte materialIdx)
 {
     using (voxelMap.Pin())
     {
         if (!voxelMap.MarkedForClose)
         {
             Vector3I vectori;
             Vector3I maxCorner;
             Vector3I minCorner;
             ulong    num = 0UL;
             GetVoxelShapeDimensions(voxelMap, shape, out minCorner, out maxCorner, out vectori);
             minCorner = Vector3I.Max(Vector3I.One, minCorner);
             maxCorner = Vector3I.Max(minCorner, maxCorner - Vector3I.One);
             if (m_cache == null)
             {
                 m_cache = new MyStorageData(MyStorageDataTypeFlags.All);
             }
             Vector3I_RangeIterator it = new Vector3I_RangeIterator(ref Vector3I.Zero, ref vectori);
             while (true)
             {
                 Vector3I vectori2;
                 Vector3I vectori3;
                 if (!it.IsValid())
                 {
                     if (num > 0L)
                     {
                         BoundingBoxD cutOutBox = shape.GetWorldBoundaries();
                         MySandboxGame.Static.Invoke(delegate {
                             if (voxelMap.Storage != null)
                             {
                                 voxelMap.Storage.NotifyChanged(minCorner, maxCorner, MyStorageDataTypeFlags.All);
                                 NotifyVoxelChanged(MyVoxelBase.OperationType.Fill, voxelMap, ref cutOutBox);
                             }
                         }, "FillInShape Notify");
                     }
                     break;
                 }
                 GetCellCorners(ref minCorner, ref maxCorner, ref it, out vectori2, out vectori3);
                 Vector3I originalValue = vectori3;
                 voxelMap.Storage.ClampVoxelCoord(ref vectori2, 0);
                 voxelMap.Storage.ClampVoxelCoord(ref vectori3, 0);
                 ClampingInfo info  = CheckForClamping(vectori2, vectori2);
                 ClampingInfo info2 = CheckForClamping(originalValue, vectori3);
                 m_cache.Resize(vectori2, vectori3);
                 MyVoxelRequestFlags considerContent = MyVoxelRequestFlags.ConsiderContent;
                 voxelMap.Storage.ReadRange(m_cache, MyStorageDataTypeFlags.All, 0, vectori2, vectori3, ref considerContent);
                 ulong num2 = 0UL;
                 Vector3I_RangeIterator iterator2 = new Vector3I_RangeIterator(ref vectori2, ref vectori3);
                 while (true)
                 {
                     if (!iterator2.IsValid())
                     {
                         if (num2 > 0L)
                         {
                             RemoveSmallVoxelsUsingChachedVoxels();
                             voxelMap.Storage.WriteRange(m_cache, MyStorageDataTypeFlags.All, vectori2, vectori3, false, true);
                         }
                         num += num2;
                         it.MoveNext();
                         break;
                     }
                     Vector3I p    = iterator2.Current - vectori2;
                     byte     num3 = m_cache.Content(ref p);
                     if ((num3 != 0xff) || (m_cache.Material(ref p) != materialIdx))
                     {
                         if ((((iterator2.Current.X == vectori2.X) && info.X) || (((iterator2.Current.X == vectori3.X) && info2.X) || (((iterator2.Current.Y == vectori2.Y) && info.Y) || (((iterator2.Current.Y == vectori3.Y) && info2.Y) || ((iterator2.Current.Z == vectori2.Z) && info.Z))))) || ((iterator2.Current.Z == vectori3.Z) && info2.Z))
                         {
                             if (num3 != 0)
                             {
                                 m_cache.Material(ref p, materialIdx);
                             }
                         }
                         else
                         {
                             Vector3D vectord;
                             MyVoxelCoordSystems.VoxelCoordToWorldPosition(voxelMap.PositionLeftBottomCorner, ref iterator2.Current, out vectord);
                             float volume = shape.GetVolume(ref vectord);
                             if (volume > 0f)
                             {
                                 long num6 = Math.Max(num3, (int)(volume * 255f));
                                 m_cache.Content(ref p, (byte)num6);
                                 if (num6 != 0)
                                 {
                                     m_cache.Material(ref p, materialIdx);
                                 }
                                 num2 += ((ulong)num6) - num3;
                             }
                         }
                     }
                     iterator2.MoveNext();
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 public static void CutOutShape(MyVoxelBase voxelMap, MyShape shape, bool voxelHand = false)
 {
     if (MySession.Static.EnableVoxelDestruction || MySession.Static.HighSimulationQuality)
     {
         using (voxelMap.Pin())
         {
             if (!voxelMap.MarkedForClose)
             {
                 Vector3I vectori;
                 Vector3I maxCorner;
                 Vector3I minCorner;
                 GetVoxelShapeDimensions(voxelMap, shape, out minCorner, out maxCorner, out vectori);
                 ulong num = 0UL;
                 if (m_cache == null)
                 {
                     m_cache = new MyStorageData(MyStorageDataTypeFlags.All);
                 }
                 Vector3I_RangeIterator it = new Vector3I_RangeIterator(ref Vector3I.Zero, ref vectori);
                 while (true)
                 {
                     Vector3I vectori2;
                     Vector3I vectori3;
                     if (!it.IsValid())
                     {
                         if (num > 0L)
                         {
                             BoundingBoxD cutOutBox = shape.GetWorldBoundaries();
                             MySandboxGame.Static.Invoke(delegate {
                                 if (voxelMap.Storage != null)
                                 {
                                     voxelMap.Storage.NotifyChanged(minCorner, maxCorner, MyStorageDataTypeFlags.All);
                                     NotifyVoxelChanged(MyVoxelBase.OperationType.Cut, voxelMap, ref cutOutBox);
                                 }
                             }, "CutOutShape notify");
                         }
                         break;
                     }
                     GetCellCorners(ref minCorner, ref maxCorner, ref it, out vectori2, out vectori3);
                     Vector3I voxelCoord = vectori2 - 1;
                     Vector3I vectori5   = (Vector3I)(vectori3 + 1);
                     voxelMap.Storage.ClampVoxelCoord(ref voxelCoord, 1);
                     voxelMap.Storage.ClampVoxelCoord(ref vectori5, 1);
                     ulong num2 = 0UL;
                     m_cache.Resize(voxelCoord, vectori5);
                     MyVoxelRequestFlags considerContent = MyVoxelRequestFlags.ConsiderContent;
                     voxelMap.Storage.ReadRange(m_cache, MyStorageDataTypeFlags.All, 0, voxelCoord, vectori5, ref considerContent);
                     Vector3I_RangeIterator iterator2 = new Vector3I_RangeIterator(ref vectori2, ref vectori3);
                     while (true)
                     {
                         if (!iterator2.IsValid())
                         {
                             if (num2 > 0L)
                             {
                                 RemoveSmallVoxelsUsingChachedVoxels();
                                 voxelMap.Storage.WriteRange(m_cache, MyStorageDataTypeFlags.All, voxelCoord, vectori5, false, true);
                             }
                             num += num2;
                             it.MoveNext();
                             break;
                         }
                         Vector3I p    = iterator2.Current - voxelCoord;
                         byte     num3 = m_cache.Content(ref p);
                         if (num3 != 0)
                         {
                             Vector3D vectord;
                             MyVoxelCoordSystems.VoxelCoordToWorldPosition(voxelMap.PositionLeftBottomCorner, ref iterator2.Current, out vectord);
                             float volume = shape.GetVolume(ref vectord);
                             if (volume != 0f)
                             {
                                 int   num5 = Math.Min((int)(255f - (volume * 255f)), num3);
                                 ulong num6 = (ulong)Math.Abs((int)(num3 - num5));
                                 m_cache.Content(ref p, (byte)num5);
                                 if (num5 == 0)
                                 {
                                     m_cache.Material(ref p, 0xff);
                                 }
                                 num2 += num6;
                             }
                         }
                         iterator2.MoveNext();
                     }
                 }
             }
         }
     }
 }