Exemple #1
0
        private static void PlanetGenerator(ref MyCsgShapePlanetShapeAttributes shapeAttributes, ref MyCsgShapePlanetHillAttributes hillAttributes, ref MyCsgShapePlanetHillAttributes canyonAttributes, ref MyCsgShapePlanetMaterialAttributes materialAttributes, out MyCompositeShapeGeneratedData data)
        {
            var random = MyRandom.Instance;

            using (var stateToken = random.PushSeed(shapeAttributes.Seed))
            {
                data = new MyCompositeShapeGeneratedData();
                data.FilledShapes  = new MyCsgShapeBase[1];
                data.RemovedShapes = new MyCsgShapeBase[0];


                data.MacroModule = new MyBillowFast(quality: MyNoiseQuality.Low, seed: shapeAttributes.Seed, frequency: shapeAttributes.NoiseFrequency / shapeAttributes.Diameter, layerCount: 3);

                data.DetailModule = new MyBillowFast(
                    seed: shapeAttributes.Seed,
                    quality: MyNoiseQuality.Low,
                    frequency: random.NextFloat() * 0.09f + 0.11f,
                    layerCount: 2);

                float halfSize        = shapeAttributes.Radius;
                float storageSize     = VRageMath.MathHelper.GetNearestBiggerPowerOfTwo(shapeAttributes.Diameter);
                float halfStorageSize = storageSize * 0.5f;
                float storageOffset   = halfStorageSize - halfSize;

                data.FilledShapes[0] = new MyCsgShapePlanet(
                    new Vector3(halfStorageSize),
                    ref shapeAttributes,
                    ref hillAttributes,
                    ref canyonAttributes,
                    detailFrequency: 0.5f,
                    deviationFrequency: 10.0f);


                FillMaterials(2);

                data.DefaultMaterial = m_surfaceMaterials[(int)random.Next() % m_surfaceMaterials.Count];

                int depositCount = 1;
                data.Deposits = new MyCompositeShapeOreDeposit[depositCount];


                data.Deposits[0] = new MyCompositeLayeredOreDeposit(new MyCsgSimpleSphere(
                                                                        new Vector3(halfStorageSize), halfSize), materialAttributes.Layers,
                                                                    new MyBillowFast(layerCount: 3,
                                                                                     seed: shapeAttributes.LayerDeviationSeed, frequency: shapeAttributes.LayerDeviationNoiseFrequency / shapeAttributes.Diameter),
                                                                    new MyCompositeOrePlanetDeposit(new MyCsgSimpleSphere(new Vector3(halfStorageSize), materialAttributes.OreStartDepth), shapeAttributes.Seed, materialAttributes.OreStartDepth, materialAttributes.OreEndDepth, materialAttributes.OreProbabilities));

                m_depositMaterials.Clear();
                m_surfaceMaterials.Clear();
                m_coreMaterials.Clear();
            }
        }
        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 void PlanetGenerator(ref MyCsgShapePlanetShapeAttributes shapeAttributes, float maxHillHeight, ref MyCsgShapePlanetMaterialAttributes materialAttributes, out MyCompositeShapeGeneratedData data)
        {
            var random = MyRandom.Instance;

            using (var stateToken = random.PushSeed(shapeAttributes.Seed))
            {
                data = new MyCompositeShapeGeneratedData();
                data.FilledShapes  = new MyCsgShapeBase[1];
                data.RemovedShapes = new MyCsgShapeBase[0];


                data.MacroModule = null;

                data.DetailModule = null;

                float halfSize        = shapeAttributes.Radius;
                float storageSize     = VRageMath.MathHelper.GetNearestBiggerPowerOfTwo(shapeAttributes.Diameter);
                float halfStorageSize = storageSize * 0.5f;
                float storageOffset   = halfStorageSize - halfSize;

                string planetPath = Path.Combine(MyFileSystem.ContentPath, "Data", "PlanetDataFiles", "Test");
                data.FilledShapes[0] = new MyCsgShapePrecomputed(new Vector3(halfStorageSize), shapeAttributes.AveragePlanetRadius, planetPath, maxHillHeight);

                /*MyCsgShapePlanet(
                 *                  new Vector3(halfStorageSize),
                 *                  ref shapeAttributes,
                 *                  ref hillAttributes,
                 *                  ref canyonAttributes,
                 *                  detailFrequency: 0.5f,
                 *                  deviationFrequency: 10.0f);*/

                FillMaterials(2);

                data.DefaultMaterial = m_surfaceMaterials[(int)random.Next() % m_surfaceMaterials.Count];

                int depositCount = 1;
                data.Deposits = new MyCompositeShapeOreDeposit[depositCount];


                data.Deposits[0] = new MyCompositePrecomputedOreDeposit(new MyCsgSimpleSphere(
                                                                            new Vector3(halfStorageSize), halfSize),
                                                                        planetPath,
                                                                        new MyCompositeOrePlanetDeposit(new MyCsgSimpleSphere(new Vector3(halfStorageSize), materialAttributes.OreStartDepth), shapeAttributes.Seed, materialAttributes.OreStartDepth, materialAttributes.OreEndDepth, materialAttributes.OreProbabilities),
                                                                        data.FilledShapes[0] as MyCsgShapePrecomputed);

                m_depositMaterials.Clear();
                m_surfaceMaterials.Clear();
                m_coreMaterials.Clear();
            }
        }
        // Do NOT use! Work in progress which is likely to change, breaking all saves that use this.
        public static MyCompositeShapeProvider CreatePlanetShape(int generatorEntry,
                                                                 ref MyCsgShapePlanetShapeAttributes shapeAttributes,
                                                                 float maxHillHeight,
                                                                 ref MyCsgShapePlanetMaterialAttributes materialAttributes)
        {
            var result = new MyCompositeShapeProvider();

            result.m_state.Version      = CURRENT_VERSION;
            result.m_state.Generator    = generatorEntry;
            result.m_state.Seed         = shapeAttributes.Seed;
            result.m_state.Size         = shapeAttributes.Diameter;
            result.m_state.IsPlanet     = 1;
            result.m_materialAttributes = materialAttributes;
            result.m_shapeAttributes    = shapeAttributes;
            result.m_maxHillHeight      = maxHillHeight;

            MyCompositeShapes.PlanetGenerators[result.m_state.Generator](ref shapeAttributes, maxHillHeight, ref materialAttributes, out result.m_data);

            return(result);
        }
        // Do NOT use! Work in progress which is likely to change, breaking all saves that use this.
        private static MyCompositeShapeProvider CreatePlanetShape(int generatorEntry,
                                                                  ref MyCsgShapePlanetShapeAttributes shapeAttributes,
                                                                  ref MyCsgShapePlanetHillAttributes hillAttributes,
                                                                  ref MyCsgShapePlanetHillAttributes canyonAttributes,
                                                                  MyMaterialLayer[] materialLevels)
        {
            var result = new MyCompositeShapeProvider();

            result.m_state.Version    = CURRENT_VERSION;
            result.m_state.Generator  = generatorEntry;
            result.m_state.Seed       = shapeAttributes.Seed;
            result.m_state.Size       = shapeAttributes.Radius;
            result.m_state.IsPlanet   = 1;
            result.m_materialLayers   = materialLevels;
            result.m_shapeAttributes  = shapeAttributes;
            result.m_hillAttributes   = hillAttributes;
            result.m_canyonAttributes = canyonAttributes;

            MyCompositeShapes.PlanetGenerators[result.m_state.Generator](ref shapeAttributes, ref hillAttributes, ref canyonAttributes, materialLevels, out result.m_data);

            return(result);
        }
        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);
        }
Exemple #7
0
 private static void PlanetGenerator0(ref MyCsgShapePlanetShapeAttributes shapeAttributes, ref MyCsgShapePlanetHillAttributes hillAttributes, ref MyCsgShapePlanetHillAttributes canyonAttributes, ref MyCsgShapePlanetMaterialAttributes materialAttributes, out MyCompositeShapeGeneratedData data)
 {
     PlanetGenerator(ref shapeAttributes, ref hillAttributes, ref canyonAttributes, ref materialAttributes, out data);
 }
 private static void PlanetGenerator0(ref MyCsgShapePlanetShapeAttributes shapeAttributes, float maxHillHeight, ref MyCsgShapePlanetMaterialAttributes materialAttributes, out MyCompositeShapeGeneratedData data)
 {
     PlanetGenerator(ref shapeAttributes, maxHillHeight, ref materialAttributes, out data);
 }
        private static void PlanetGenerator(ref MyCsgShapePlanetShapeAttributes shapeAttributes, ref MyCsgShapePlanetHillAttributes hillAttributes, ref MyCsgShapePlanetHillAttributes canyonAttributes, MyMaterialLayer[] materialLevels, out MyCompositeShapeGeneratedData data)
        {
            var random = MyRandom.Instance;

            using (var stateToken = random.PushSeed(shapeAttributes.Seed))
            {
                data = new MyCompositeShapeGeneratedData();
                data.FilledShapes  = new MyCsgShapeBase[1];
                data.RemovedShapes = new MyCsgShapeBase[0];


                data.MacroModule = new MyBillowFast(quality: MyNoiseQuality.Low, seed: shapeAttributes.Seed, frequency: shapeAttributes.NoiseFrequency / shapeAttributes.Radius, layerCount: 4);

                data.DetailModule = new MyBillowFast(
                    seed: shapeAttributes.Seed,
                    quality: MyNoiseQuality.Low,
                    frequency: shapeAttributes.NoiseFrequency / shapeAttributes.Radius,
                    layerCount: 1);

                float halfSize        = shapeAttributes.Radius * 0.5f;
                float storageSize     = VRageMath.MathHelper.GetNearestBiggerPowerOfTwo(shapeAttributes.Radius);
                float halfStorageSize = storageSize * 0.5f;
                float storageOffset   = halfStorageSize - halfSize;

                data.FilledShapes[0] = new MyCsgShapePlanet(
                    random,
                    new Vector3(halfStorageSize),
                    ref shapeAttributes,
                    ref hillAttributes,
                    ref canyonAttributes,
                    detailFrequency: 0.09f,
                    deviationFrequency: 10.0f);


                foreach (var material in MyDefinitionManager.Static.GetVoxelMaterialDefinitions())
                {
                    if (material.MinedOre == "Stone") // Surface
                    {
                        m_surfaceMaterials.Add(material);
                    }
                }

                data.DefaultMaterial = m_surfaceMaterials[(int)random.Next() % m_surfaceMaterials.Count];

                int depositCount = 1;
                data.Deposits = new MyCompositeShapeOreDeposit[depositCount];

                MyMaterialLayer[] materialLayers = new MyMaterialLayer[materialLevels.Length];

                float surfaceSize = (shapeAttributes.Radius / 2.0f) * (1 - shapeAttributes.DeviationScale * hillAttributes.SizeRatio);
                for (int i = 0; i < materialLayers.Length; ++i)
                {
                    materialLayers[i]                      = new MyMaterialLayer();
                    materialLayers[i].StartHeight          = materialLevels[i].StartHeight + surfaceSize;
                    materialLayers[i].EndHeight            = materialLevels[i].EndHeight + surfaceSize;
                    materialLayers[i].MaterialDefinition   = GetMaterialByName(materialLevels[i].MaterialName);
                    materialLayers[i].StartAngle           = materialLevels[i].StartAngle;
                    materialLayers[i].EndAngle             = materialLevels[i].EndAngle;
                    materialLayers[i].HeightStartDeviation = materialLevels[i].HeightStartDeviation;
                    materialLayers[i].AngleStartDeviation  = materialLevels[i].AngleStartDeviation;
                    materialLayers[i].HeightEndDeviation   = materialLevels[i].HeightEndDeviation;
                    materialLayers[i].AngleEndDeviation    = materialLevels[i].AngleEndDeviation;
                }

                for (int i = 0; i < depositCount; ++i)
                {
                    data.Deposits[i] = new MyCompositeLayeredOreDeposit(new MyCsgSimpleSphere(
                                                                            new Vector3(halfStorageSize), halfSize), materialLayers,
                                                                        new MyBillowFast(layerCount: 3,
                                                                                         seed: shapeAttributes.LayerDeviationSeed, frequency: shapeAttributes.LayerDeviationNoiseFreqeuncy / shapeAttributes.Radius));
                }

                m_surfaceMaterials.Clear();
                m_coreMaterials.Clear();
            }
        }