void ShrinkVMap() { Vector3I min, max; m_selectedVoxel.GetFilledStorageBounds(out min, out max); MyVoxelMapStorageDefinition def = null; if (m_selectedVoxel.AsteroidName != null) { MyDefinitionManager.Static.TryGetVoxelMapStorageDefinition(m_selectedVoxel.AsteroidName, out def); } var origSize = m_selectedVoxel.Size; var tightSize = max - min + 1; var storage = new MyOctreeStorage(null, tightSize); var offset = (storage.Size - tightSize) / 2 + 1; MyStorageData data = new MyStorageData(); data.Resize(tightSize); m_selectedVoxel.Storage.ReadRange(data, MyStorageDataTypeFlags.ContentAndMaterial, 0, min, max); min = offset; max = offset + tightSize - 1; storage.WriteRange(data, MyStorageDataTypeFlags.ContentAndMaterial, ref min, ref max); var newMap = MyWorldGenerator.AddVoxelMap(m_selectedVoxel.StorageName, storage, m_selectedVoxel.WorldMatrix); m_selectedVoxel.Close(); newMap.Save = true; if (def == null) { ShowAlert("Voxel map {0} does not have a definition, the shrunk voxel map will be saved with the world instead.", m_selectedVoxel.StorageName); } else { byte[] cVmapData; newMap.Storage.Save(out cVmapData); using (var ostream = MyFileSystem.OpenWrite(Path.Combine(MyFileSystem.ContentPath, def.StorageFile), FileMode.Open)) { ostream.Write(cVmapData, 0, cVmapData.Length); } var notification = new MyHudNotification(MyStringId.GetOrCompute("Voxel prefab {0} updated succesfuly (size changed from {1} to {2})."), 4000); notification.SetTextFormatArguments(def.Id.SubtypeName, origSize, storage.Size); MyHud.Notifications.Add(notification); } }