public unsafe void GetMaterialForPositionDebug(ref Vector3 pos, out MyPlanetStorageProvider.SurfacePropertiesExtended props)
        {
            byte spawns = 0;

            MaterialSampleParams ps;
            GetPositionParams(ref pos, 1.0f, out ps, true);

            props.Position = pos;
            props.Gravity = ps.Gravity;

            props.Material = m_defaultMaterial.FirstOrDefault;

            props.Slope = ps.Normal.Z;
            props.HeightRatio = m_planetShape.AltitudeToRatio(ps.SampledHeight);
            props.Depth = ps.SurfaceDepth;
            props.Latitude = ps.Latitude;
            props.Longitude = ps.Longitude;
            props.Altitude = ps.DistanceToCenter - m_planetShape.Radius;

            props.Face = ps.Face;
            props.Texcoord = ps.Texcoord;


            props.BiomeValue = 0;
            props.MaterialValue = 0;
            props.OcclusionValue = 0;
            props.OreValue = 0;

            props.EffectiveRule = null;
            props.Biome = null;
            props.Ore = new PlanetOre();

            props.Origin = MyPlanetStorageProvider.SurfacePropertiesExtended.MaterialOrigin.Default;

            PlanetMaterial voxelMaterial = null;

            // Ore depositis from map come first.

            if (m_oreMap != null)
            {
                props.OreValue = m_oreMap.Faces[ps.Face].GetValue(ps.Texcoord.X, ps.Texcoord.Y);
                PlanetOre om;
                if (m_ores.TryGetValue(props.OreValue, out om))
                {
                    props.Ore = om;
                    if (om.Start <= -ps.SurfaceDepth && om.Start + om.Depth >= -ps.SurfaceDepth)
                    {
                        props.Material = om.Material;
                        props.Origin = MyPlanetStorageProvider.SurfacePropertiesExtended.MaterialOrigin.Ore;
                    }
                }
            }

            if (ps.DistanceToCenter < 0.01)
            {
                return;
            }

            Byte roundedMaterial = 0;

            if (m_biomePixelSize < ps.LodSize)
            {
                if (m_materialMap != null)
                    m_materialMap.Faces[ps.Face].GetValue((int)ps.Texcoord.X, (int)ps.Texcoord.Y, out roundedMaterial);

                if (m_occlusionMap != null)
                    m_occlusionMap.Faces[ps.Face].GetValue((int)ps.Texcoord.X, (int)ps.Texcoord.Y, out props.OcclusionValue);
            }
            else
            {
                if (m_biomeMap != null)
                    roundedMaterial = ComputeMapBlend(ps.Texcoord, ps.Face, ref m_materialBC,
                        m_materialMap.Faces[ps.Face]);

                if (m_occlusionMap != null)
                    props.OcclusionValue = ComputeMapBlend(ps.Texcoord, ps.Face, ref m_occlusionBC,
                        m_occlusionMap.Faces[ps.Face]);
            }

            m_materials.TryGetValue(roundedMaterial, out voxelMaterial);
            props.Origin = MyPlanetStorageProvider.SurfacePropertiesExtended.MaterialOrigin.Map;

            props.MaterialValue = roundedMaterial;

            if (voxelMaterial == null && m_biomes != null)
            {
                PlanetBiome b;

                m_biomes.TryGetValue(roundedMaterial, out b);

                props.Biome = b;

                // When the sample material is zero calculate the material using the definition rules;
                if (MyFakes.ENABLE_DEFINITION_ENVIRONMENTS && b != null && b.IsValid)
                {
                    foreach (var rule in b.Rules)
                    {
                        if (rule.Check(props.HeightRatio, ps.Latitude, ps.Longitude, ps.Normal.Z))
                        {
                            voxelMaterial = rule;
                            props.Origin = MyPlanetStorageProvider.SurfacePropertiesExtended.MaterialOrigin.Rule;
                            break;
                        }
                    }
                }

            }

            if (voxelMaterial == null)
            {
                voxelMaterial = m_defaultMaterial;
                props.Origin = MyPlanetStorageProvider.SurfacePropertiesExtended.MaterialOrigin.Default;
            }

            props.BiomeValue = spawns;

            // calc depth with what we already have
            float voxelDepth = ps.SurfaceDepth + .5f;

            // Check layers

            if (voxelMaterial.HasLayers)
            {
                var layers = voxelMaterial.Layers;

                for (int i = 0; i < layers.Length; i++)
                {
                    if (voxelDepth >= -layers[i].Depth)
                    {
                        props.Material = voxelMaterial.Layers[i].Material;
                        break;
                    }
                }
            }
            // Check single layered
            else
            {
                if (voxelDepth >= -voxelMaterial.Depth)
                {
                    props.Material = voxelMaterial.Material;
                }
            }

            props.EffectiveRule = voxelMaterial;
        }
        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,
            };

            MyClipboardComponent.Static.ActivateVoxelClipboard(planet.GetObjectBuilder(), storage, MySector.MainCamera.ForwardVector, (storage.Size * 0.5f).Length());
        }
        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;
                planetInitArguments.InitializeComponents = true;

                planet.Init(planetInitArguments);

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

                return planet;
            }
            return null;
        }