private void CreatePlanet(int seed, float size)
        {
            Vector3D pos = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * size * 3 - new Vector3D(size);

            MyPlanetGeneratorDefinition planetDefinition = MyDefinitionManager.Static.GetDefinition <MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(m_selectedPlanetName));
            MyPlanetStorageProvider     provider         = new MyPlanetStorageProvider();

            provider.Init(seed, planetDefinition, size / 2f);

            IMyStorage storage = new MyOctreeStorage(provider, provider.StorageSize);

            float minHillSize = provider.Radius * planetDefinition.HillParams.Min;
            float maxHillSize = provider.Radius * planetDefinition.HillParams.Max;

            float averagePlanetRadius = provider.Radius;

            float outerRadius = averagePlanetRadius + maxHillSize;
            float innerRadius = averagePlanetRadius + minHillSize;

            float atmosphereRadius = planetDefinition.AtmosphereSettings.HasValue && planetDefinition.AtmosphereSettings.Value.Scale > 1f ? 1 + planetDefinition.AtmosphereSettings.Value.Scale : 1.75f;

            atmosphereRadius *= provider.Radius;

            var planet = new MyPlanet();

            planet.EntityId = MyRandom.Instance.NextLong();

            MyPlanetInitArguments planetInitArguments;

            planetInitArguments.StorageName           = "test";
            planetInitArguments.Storage               = storage;
            planetInitArguments.PositionMinCorner     = pos;
            planetInitArguments.Radius                = provider.Radius;
            planetInitArguments.AtmosphereRadius      = atmosphereRadius;
            planetInitArguments.MaxRadius             = outerRadius;
            planetInitArguments.MinRadius             = innerRadius;
            planetInitArguments.HasAtmosphere         = planetDefinition.HasAtmosphere;
            planetInitArguments.AtmosphereWavelengths = Vector3.Zero;
            planetInitArguments.GravityFalloff        = planetDefinition.GravityFalloffPower;
            planetInitArguments.MarkAreaEmpty         = true;
            planetInitArguments.AtmosphereSettings    = planetDefinition.AtmosphereSettings.HasValue ? planetDefinition.AtmosphereSettings.Value : MyAtmosphereSettings.Defaults();
            planetInitArguments.SurfaceGravity        = planetDefinition.SurfaceGravity;
            planetInitArguments.AddGps                = false;
            planetInitArguments.SpherizeWithDistance  = true;
            planetInitArguments.Generator             = planetDefinition;
            planetInitArguments.UserCreated           = true;

            planet.Init(planetInitArguments);

            m_lastAsteroidInfo = new SpawnAsteroidInfo()
            {
                Asteroid         = null,
                RandomSeed       = seed,
                Position         = Vector3D.Zero,
                IsProcedural     = true,
                ProceduralRadius = size,
            };

            MyCubeBuilder.Static.ActivateVoxelClipboard(planet.GetObjectBuilder(), storage, MySector.MainCamera.ForwardVector, (storage.Size * 0.5f).Length());
        }
Пример #2
0
        private Vector3D GetPlanetOffset(MyPlanetGeneratorDefinition definition, float size)
        {
            MyPlanetStorageProvider myPlanetStorageProvider = new MyPlanetStorageProvider();

            myPlanetStorageProvider.Init(0, definition, size / 2f);
            IMyStorage myStorage = new MyOctreeStorage(myPlanetStorageProvider, myPlanetStorageProvider.StorageSize);

            return(myStorage.Size / 2.0f);
        }
        private void CreateEmptyVoxelMapSpawnMenu(float separatorSize, float usableWidth)
        {
            int min = 2;
            int max = 10;

            var label = AddLabel("Voxel Size: ", Vector4.One, m_scale);

            MyGuiControlSlider slider = null;

            slider = new MyGuiControlSlider(
                position: m_currentPosition,
                width: 400f / MyGuiConstants.GUI_OPTIMAL_SIZE.X,
                minValue: min,
                maxValue: max,
                labelText: String.Empty,
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                labelFont: MyFontEnum.Debug,
                intValue: true);
            slider.DebugScale = m_sliderDebugScale;
            slider.ColorMask  = Color.White.ToVector4();
            Controls.Add(slider);

            label = new MyGuiControlLabel(
                position: m_currentPosition + new Vector2(slider.Size.X + 0.005f, slider.Size.Y / 2),
                text: String.Empty,
                colorMask: Color.White.ToVector4(),
                textScale: MyGuiConstants.DEFAULT_TEXT_SCALE * 0.8f * m_scale,
                font: MyFontEnum.Debug);
            label.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
            Controls.Add(label);

            m_currentPosition.Y += slider.Size.Y;
            m_currentPosition.Y += separatorSize;

            slider.ValueChanged += (MyGuiControlSlider s) =>
            {
                int size = 1 << ((int)s.Value);
                label.Text = size + "m";
                m_procAsteroidSizeValue = size;
            };
            slider.Value = 5;

            CreateDebugButton(usableWidth, MySpaceTexts.ScreenDebugSpawnMenu_SpawnAsteroid, x =>
            {
                int size = (int)m_procAsteroidSizeValue;
                Debug.Assert(MathHelper.IsPowerOfTwo(size));

                MyStorageBase storage = new MyOctreeStorage(null, new Vector3I(size));

                string name = MakeStorageName("MyEmptyVoxelMap");

                var builder = CreateAsteroidObjectBuilder(name);
                MyCubeBuilder.Static.ActivateVoxelClipboard(builder, storage, MySector.MainCamera.ForwardVector, (storage.Size * 0.5f).Length());

                CloseScreenNow();
            });
        }
Пример #4
0
            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);
                }
            }
        private MyOctreeStorage CreateAsteroidStorage(Vector3I storageSize, int seed, float size, int generatorSeed = 0, int?generator = default(int?))
        {
            object[] args = new object[] { seed, size, generatorSeed, generator };

            object prov = m_createRoid.Invoke(null, args);

            ConstructorInfo ctor     = typeof(MyOctreeStorage).GetConstructor(new Type[] { m_providerType, typeof(Vector3I) });
            MyOctreeStorage instance = (MyOctreeStorage)ctor.Invoke(new object[] { prov, storageSize });

            return(instance);
        }
        private void RemoveAllAsteroids(MyGuiControlButton sender)
        {
            MyCsgShapePlanetShapeAttributes shapeAttributes = new MyCsgShapePlanetShapeAttributes();

            shapeAttributes.Seed           = 12345;
            shapeAttributes.Diameter       = 60;
            shapeAttributes.Radius         = 60 / 2.0f;
            shapeAttributes.DeviationScale = 0.003f;
            float maxHillSize = 10;

            float planetHalfDeviation = (shapeAttributes.Diameter * shapeAttributes.DeviationScale) / 2.0f;
            float hillHalfDeviation   = planetHalfDeviation * maxHillSize;
            float canyonHalfDeviation = 1;


            float averagePlanetRadius = shapeAttributes.Radius - hillHalfDeviation;

            float outerRadius = averagePlanetRadius + hillHalfDeviation;
            float innerRadius = averagePlanetRadius - canyonHalfDeviation;

            float atmosphereRadius = MathHelper.Max(outerRadius, averagePlanetRadius * 1.08f);
            float minPlanetRadius  = MathHelper.Min(innerRadius, averagePlanetRadius - planetHalfDeviation * 2 * 2.5f);

            MyCsgShapePlanetMaterialAttributes materialAttributes = new MyCsgShapePlanetMaterialAttributes();

            materialAttributes.OreStartDepth = innerRadius;
            materialAttributes.OreEndDepth   = innerRadius;
            materialAttributes.OreEndDepth   = MathHelper.Max(materialAttributes.OreEndDepth, 0);
            materialAttributes.OreStartDepth = MathHelper.Max(materialAttributes.OreStartDepth, 0);

            materialAttributes.OreProbabilities = new MyOreProbability[10];

            for (int i = 0; i < 10; ++i)
            {
                materialAttributes.OreProbabilities[i]         = new MyOreProbability();
                materialAttributes.OreProbabilities[i].OreName = "Ice_01";
                materialAttributes.OreProbabilities[i].CummulativeProbability = 0.0f;
            }

            shapeAttributes.AveragePlanetRadius = averagePlanetRadius;

            IMyStorageDataProvider dataProvider = MyCompositeShapeProvider.CreatePlanetShape(0, ref shapeAttributes, maxHillSize, ref materialAttributes);
            IMyStorage             storage      = new MyOctreeStorage(dataProvider, MyVoxelCoordSystems.FindBestOctreeSize(shapeAttributes.Diameter));
            MyStorageDataCache     cache        = new MyStorageDataCache();

            cache.Resize(storage.Size);
            Vector3I start = Vector3I.Zero;
            Vector3I end   = storage.Size;

            storage.ReadRange(cache, MyStorageDataTypeFlags.Content, 1, ref start, ref end);
            dataProvider.ReleaseHeightMaps();
        }
        private static MyPlanet CreatePlanet(string storageName, ref Vector3D positionMinCorner, int seed, float size, long entityId, ref DictionaryValuesReader <MyDefinitionId, MyPlanetGeneratorDefinition> planetDefinitions)
        {
            if (MyFakes.ENABLE_PLANETS == false)
            {
                //return null;
            }

            m_materialsByOreType.Clear();
            m_oreProbalities.Clear();
            m_spawningMaterials.Clear();
            m_organicMaterials.Clear();

            foreach (var planetGeneratorDefinition in planetDefinitions)
            {
                var random = MyRandom.Instance;
                using (var stateToken = random.PushSeed(seed))
                {
                    BuildOreProbabilities(planetGeneratorDefinition);
                    FillMaterialCollections();

                    MyCsgShapePlanetShapeAttributes shapeAttributes = new MyCsgShapePlanetShapeAttributes();

                    shapeAttributes.Seed           = seed;
                    shapeAttributes.Diameter       = size;
                    shapeAttributes.Radius         = size / 2.0f;
                    shapeAttributes.DeviationScale = random.NextFloat(planetGeneratorDefinition.Deviation.Min, planetGeneratorDefinition.Deviation.Max);
                    float maxHillSize = random.NextFloat(planetGeneratorDefinition.HillParams.SizeRatio.Min, planetGeneratorDefinition.HillParams.SizeRatio.Max);


                    float planetHalfDeviation = (shapeAttributes.Diameter * shapeAttributes.DeviationScale) / 2.0f;
                    float hillHalfDeviation   = planetHalfDeviation * maxHillSize;
                    float canyonHalfDeviation = 1;


                    float averagePlanetRadius = shapeAttributes.Radius - hillHalfDeviation;

                    float outerRadius = averagePlanetRadius + hillHalfDeviation;
                    float innerRadius = averagePlanetRadius - canyonHalfDeviation;

                    float atmosphereRadius = MathHelper.Max(outerRadius, averagePlanetRadius * 1.08f);
                    float minPlanetRadius  = MathHelper.Min(innerRadius, averagePlanetRadius - planetHalfDeviation * 2 * 2.5f);

                    MyCsgShapePlanetMaterialAttributes materialAttributes = new MyCsgShapePlanetMaterialAttributes();
                    materialAttributes.OreStartDepth = innerRadius - random.NextFloat(planetGeneratorDefinition.MaterialsMinDepth.Min, planetGeneratorDefinition.MaterialsMinDepth.Max);
                    materialAttributes.OreEndDepth   = innerRadius - random.NextFloat(planetGeneratorDefinition.MaterialsMaxDepth.Min, planetGeneratorDefinition.MaterialsMaxDepth.Max);
                    materialAttributes.OreEndDepth   = MathHelper.Max(materialAttributes.OreEndDepth, 0);
                    materialAttributes.OreStartDepth = MathHelper.Max(materialAttributes.OreStartDepth, 0);

                    bool isHostile = random.NextFloat(0, 1) < planetGeneratorDefinition.HostilityProbability;

                    materialAttributes.OreProbabilities = new MyOreProbability[m_oreProbalities.Count];

                    for (int i = 0; i < m_oreProbalities.Count; ++i)
                    {
                        materialAttributes.OreProbabilities[i] = m_oreProbalities[i];
                        materialAttributes.OreProbabilities[i].CummulativeProbability /= m_oreCummulativeProbability;
                    }

                    shapeAttributes.AveragePlanetRadius = averagePlanetRadius;


                    IMyStorage storage = new MyOctreeStorage(MyCompositeShapeProvider.CreatePlanetShape(0, ref shapeAttributes, hillHalfDeviation, ref materialAttributes), MyVoxelCoordSystems.FindBestOctreeSize(size));

                    float redAtmosphereShift   = isHostile ? random.NextFloat(planetGeneratorDefinition.HostileAtmosphereColorShift.R.Min, planetGeneratorDefinition.HostileAtmosphereColorShift.R.Max) : 0;
                    float greenAtmosphereShift = isHostile ? random.NextFloat(planetGeneratorDefinition.HostileAtmosphereColorShift.G.Min, planetGeneratorDefinition.HostileAtmosphereColorShift.G.Max) : 0;
                    float blueAtmosphereShift  = isHostile ? random.NextFloat(planetGeneratorDefinition.HostileAtmosphereColorShift.B.Min, planetGeneratorDefinition.HostileAtmosphereColorShift.B.Max) : 0;

                    Vector3 atmosphereWavelengths = new Vector3(0.650f + redAtmosphereShift, 0.570f + greenAtmosphereShift, 0.475f + blueAtmosphereShift);

                    atmosphereWavelengths.X = MathHelper.Clamp(atmosphereWavelengths.X, 0.1f, 1.0f);
                    atmosphereWavelengths.Y = MathHelper.Clamp(atmosphereWavelengths.Y, 0.1f, 1.0f);
                    atmosphereWavelengths.Z = MathHelper.Clamp(atmosphereWavelengths.Z, 0.1f, 1.0f);

                    float gravityFalloff = random.NextFloat(planetGeneratorDefinition.GravityFalloffPower.Min, planetGeneratorDefinition.GravityFalloffPower.Max);

                    var voxelMap = new MyPlanet();
                    voxelMap.EntityId = entityId;

                    MyPlanetInitArguments planetInitArguments;
                    planetInitArguments.StorageName           = storageName;
                    planetInitArguments.Storage               = storage;
                    planetInitArguments.PositionMinCorner     = positionMinCorner;
                    planetInitArguments.AveragePlanetRadius   = averagePlanetRadius;
                    planetInitArguments.AtmosphereRadius      = atmosphereRadius;
                    planetInitArguments.MaximumHillRadius     = averagePlanetRadius + hillHalfDeviation;
                    planetInitArguments.MinimumSurfaceRadius  = minPlanetRadius;
                    planetInitArguments.HasAtmosphere         = planetGeneratorDefinition.HasAtmosphere;
                    planetInitArguments.AtmosphereWavelengths = atmosphereWavelengths;
                    planetInitArguments.MaxOxygen             = isHostile ? 0.0f : 1.0f;
                    planetInitArguments.GravityFalloff        = gravityFalloff;
                    planetInitArguments.MarkAreaEmpty         = false;

                    voxelMap.Init(planetInitArguments);

                    MyEntities.Add(voxelMap);

                    m_materialsByOreType.Clear();
                    m_oreProbalities.Clear();
                    m_spawningMaterials.Clear();
                    m_organicMaterials.Clear();

                    return(voxelMap);
                }
            }
            return(null);
        }
        public override void GenerateObjects(List <MyObjectSeed> objectsList)
        {
            ProfilerShort.Begin("GenerateObjects");
            foreach (var objectSeed in objectsList)
            {
                if (objectSeed.Generated)
                {
                    continue;
                }

                objectSeed.Generated = true;

                using (MyRandom.Instance.PushSeed(GetObjectIdSeed(objectSeed)))
                {
                    switch (objectSeed.Type)
                    {
                    case MyObjectSeedType.Asteroid:
                        ProfilerShort.Begin("Asteroid");

                        var bbox = objectSeed.BoundingVolume;
                        MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbox, m_tmpVoxelMapsList);

                        String storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", objectSeed.CellId.X, objectSeed.CellId.Y, objectSeed.CellId.Z, objectSeed.Index, objectSeed.Seed);

                        bool exists = false;
                        foreach (var voxelMap in m_tmpVoxelMapsList)
                        {
                            if (voxelMap.StorageName == storageName)
                            {
                                exists = true;
                                break;
                            }
                        }

                        if (!exists)
                        {
                            var           provider = MyCompositeShapeProvider.CreateAsteroidShape(objectSeed.Seed, objectSeed.Size, MySession.Static.Settings.VoxelGeneratorVersion);
                            MyStorageBase storage  = new MyOctreeStorage(provider, GetAsteroidVoxelSize(objectSeed.Size));
                            var           voxelMap = MyWorldGenerator.AddVoxelMap(storageName, storage, objectSeed.BoundingVolume.Center - VRageMath.MathHelper.GetNearestBiggerPowerOfTwo(objectSeed.Size) / 2, GetAsteroidEntityId(objectSeed));

                            if (voxelMap != null)
                            {
                                voxelMap.Save = false;
                                RangeChangedDelegate OnStorageRangeChanged = null;
                                OnStorageRangeChanged = delegate(Vector3I minVoxelChanged, Vector3I maxVoxelChanged, MyStorageDataTypeFlags changedData)
                                {
                                    voxelMap.Save         = true;
                                    storage.RangeChanged -= OnStorageRangeChanged;
                                };
                                storage.RangeChanged += OnStorageRangeChanged;
                            }
                        }
                        m_tmpVoxelMapsList.Clear();
                        ProfilerShort.End();
                        break;

                    case MyObjectSeedType.EncounterAlone:
                    case MyObjectSeedType.EncounterSingle:
                    case MyObjectSeedType.EncounterMulti:
                        ProfilerShort.Begin("Encounter");
                        MyEncounterGenerator.PlaceEncounterToWorld(objectSeed.BoundingVolume, objectSeed.Seed, objectSeed.Type);
                        ProfilerShort.End();
                        break;

                    default:
                        throw new InvalidBranchException();
                        break;
                    }
                }
            }
            ProfilerShort.End();
        }
Пример #9
0
        private static MyPlanet CreatePlanet(string storageName, string planetName, ref Vector3D positionMinCorner, int seed, float size, long entityId, ref MyPlanetGeneratorDefinition generatorDef, bool addGPS, bool userCreated = false)
        {
            if (MyFakes.ENABLE_PLANETS == false)
            {
                return(null);
            }

            var random = MyRandom.Instance;

            using (MyRandom.Instance.PushSeed(seed))
            {
                MyPlanetStorageProvider provider = new MyPlanetStorageProvider();
                provider.Init(seed, generatorDef, size / 2f);

                IMyStorage storage = new MyOctreeStorage(provider, provider.StorageSize);

                float minHillSize = provider.Radius * generatorDef.HillParams.Min;
                float maxHillSize = provider.Radius * generatorDef.HillParams.Max;

                float averagePlanetRadius = provider.Radius;

                float outerRadius = averagePlanetRadius + maxHillSize;
                float innerRadius = averagePlanetRadius + minHillSize;

                float atmosphereRadius = generatorDef.AtmosphereSettings.HasValue && generatorDef.AtmosphereSettings.Value.Scale > 1f ? 1 + generatorDef.AtmosphereSettings.Value.Scale : 1.75f;
                atmosphereRadius *= provider.Radius;

                float redAtmosphereShift   = random.NextFloat(generatorDef.HostileAtmosphereColorShift.R.Min, generatorDef.HostileAtmosphereColorShift.R.Max);
                float greenAtmosphereShift = random.NextFloat(generatorDef.HostileAtmosphereColorShift.G.Min, generatorDef.HostileAtmosphereColorShift.G.Max);
                float blueAtmosphereShift  = random.NextFloat(generatorDef.HostileAtmosphereColorShift.B.Min, generatorDef.HostileAtmosphereColorShift.B.Max);

                Vector3 atmosphereWavelengths = new Vector3(0.650f + redAtmosphereShift, 0.570f + greenAtmosphereShift, 0.475f + blueAtmosphereShift);

                atmosphereWavelengths.X = MathHelper.Clamp(atmosphereWavelengths.X, 0.1f, 1.0f);
                atmosphereWavelengths.Y = MathHelper.Clamp(atmosphereWavelengths.Y, 0.1f, 1.0f);
                atmosphereWavelengths.Z = MathHelper.Clamp(atmosphereWavelengths.Z, 0.1f, 1.0f);

                var planet = new MyPlanet();
                planet.EntityId = entityId;

                MyPlanetInitArguments planetInitArguments;
                planetInitArguments.StorageName           = storageName;
                planetInitArguments.Storage               = storage;
                planetInitArguments.PositionMinCorner     = positionMinCorner;
                planetInitArguments.Radius                = provider.Radius;
                planetInitArguments.AtmosphereRadius      = atmosphereRadius;
                planetInitArguments.MaxRadius             = outerRadius;
                planetInitArguments.MinRadius             = innerRadius;
                planetInitArguments.HasAtmosphere         = generatorDef.HasAtmosphere;
                planetInitArguments.AtmosphereWavelengths = atmosphereWavelengths;
                planetInitArguments.GravityFalloff        = generatorDef.GravityFalloffPower;
                planetInitArguments.MarkAreaEmpty         = true;
                planetInitArguments.AtmosphereSettings    = generatorDef.AtmosphereSettings.HasValue ? generatorDef.AtmosphereSettings.Value : MyAtmosphereSettings.Defaults();
                planetInitArguments.SurfaceGravity        = generatorDef.SurfaceGravity;
                planetInitArguments.AddGps                = addGPS;
                planetInitArguments.SpherizeWithDistance  = true;
                planetInitArguments.Generator             = generatorDef;
                planetInitArguments.UserCreated           = userCreated;

                planet.Init(planetInitArguments);

                MyEntities.Add(planet);
                MyEntities.RaiseEntityCreated(planet);

                return(planet);
            }
            return(null);
        }
Пример #10
0
        public override void GenerateObjects(List <MyObjectSeed> objectsList, HashSet <MyObjectSeedParams> existingObjectsSeeds)
        {
            ProfilerShort.Begin("GenerateObjects");
            foreach (var objectSeed in objectsList)
            {
                if (objectSeed.Params.Generated || existingObjectsSeeds.Contains(objectSeed.Params))
                {
                    continue;
                }

                objectSeed.Params.Generated = true;

                using (MyRandom.Instance.PushSeed(GetObjectIdSeed(objectSeed)))
                {
                    switch (objectSeed.Params.Type)
                    {
                    case MyObjectSeedType.Asteroid:
                        ProfilerShort.Begin("Asteroid");

                        var bbox = objectSeed.BoundingVolume;
                        MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbox, m_tmpVoxelMapsList);

                        String storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", objectSeed.CellId.X, objectSeed.CellId.Y, objectSeed.CellId.Z, objectSeed.Params.Index, objectSeed.Params.Seed);

                        bool exists = false;
                        foreach (var voxelMap in m_tmpVoxelMapsList)
                        {
                            if (voxelMap.StorageName == storageName)
                            {
                                existingObjectsSeeds.Add(objectSeed.Params);
                                exists = true;
                                break;
                            }
                        }

                        if (!exists)
                        {
                            var           provider = MyCompositeShapeProvider.CreateAsteroidShape(objectSeed.Params.Seed, objectSeed.Size, MySession.Static.Settings.VoxelGeneratorVersion);
                            MyStorageBase storage  = new MyOctreeStorage(provider, GetAsteroidVoxelSize(objectSeed.Size));
                            var           voxelMap = MyWorldGenerator.AddVoxelMap(storageName, storage, objectSeed.BoundingVolume.Center - VRageMath.MathHelper.GetNearestBiggerPowerOfTwo(objectSeed.Size) / 2, GetAsteroidEntityId(storageName));

                            if (voxelMap != null)
                            {
                                voxelMap.Save = false;
                                MyVoxelBase.StorageChanged OnStorageRangeChanged = null;
                                OnStorageRangeChanged = delegate(MyVoxelBase voxel, Vector3I minVoxelChanged, Vector3I maxVoxelChanged, MyStorageDataTypeFlags changedData)
                                {
                                    voxelMap.Save          = true;
                                    voxelMap.RangeChanged -= OnStorageRangeChanged;
                                };
                                voxelMap.RangeChanged += OnStorageRangeChanged;
                            }
                        }
                        m_tmpVoxelMapsList.Clear();
                        ProfilerShort.End();
                        break;

                    case MyObjectSeedType.EncounterAlone:
                    case MyObjectSeedType.EncounterSingle:
                    case MyObjectSeedType.EncounterMulti:
                        ProfilerShort.Begin("Encounter");
                        bool doSpawn = true;
                        foreach (var start in MySession.Static.Scenario.PossiblePlayerStarts)
                        {
                            Vector3D?startPos = start.GetStartingLocation();
                            if (!startPos.HasValue)
                            {
                                startPos = Vector3D.Zero;
                            }
                            if ((startPos.Value - objectSeed.BoundingVolume.Center).LengthSquared() < (15000 * 15000))
                            {
                                doSpawn = false;
                            }
                        }
                        if (doSpawn)
                        {
                            MyEncounterGenerator.PlaceEncounterToWorld(objectSeed.BoundingVolume, objectSeed.Params.Seed, objectSeed.Params.Type);
                        }
                        ProfilerShort.End();
                        break;

                    default:
                        throw new InvalidBranchException();
                        break;
                    }
                }
            }
            ProfilerShort.End();
        }