public MyCsgShapePlanet(Vector3 translation, ref MyCsgShapePlanetShapeAttributes shapeAttributes, ref MyCsgShapePlanetHillAttributes hillAttributes, ref MyCsgShapePlanetHillAttributes canyonAttributes, float deviationFrequency = 0, float detailFrequency = 0)
        {
            m_detailSize       = 1.0f;
            m_translation      = translation;
            m_shapeAttributes  = shapeAttributes;
            m_hillAttributes   = hillAttributes;
            m_canyonAttributes = canyonAttributes;

            m_canyonBlendTreshold = m_canyonAttributes.Treshold + m_canyonAttributes.BlendTreshold;
            m_hillBlendTreshold   = m_hillAttributes.Treshold - m_hillAttributes.BlendTreshold;

            m_shapeAttributes.Radius   = (shapeAttributes.Diameter / 2.0f) * (1 - shapeAttributes.DeviationScale * m_hillAttributes.SizeRatio);
            m_shapeAttributes.Diameter = m_shapeAttributes.Radius * 2.0f;
            m_halfDeviation            = (shapeAttributes.Diameter / 2.0f) * shapeAttributes.DeviationScale;

            m_deviationFrequency = deviationFrequency;
            m_detailFrequency    = detailFrequency;

            m_hillHalfDeviation   = m_halfDeviation * m_hillAttributes.SizeRatio;
            m_canyonHalfDeviation = m_halfDeviation * m_canyonAttributes.SizeRatio;

            m_enableModulation = true;

            m_hillModule = new MyCompositeNoise(hillAttributes.NumNoises, hillAttributes.Frequency / m_shapeAttributes.Radius);

            ComputeDerivedProperties();
        }
        public MyCsgShapePlanet(MyRandom random, Vector3 translation, ref MyCsgShapePlanetShapeAttributes shapeAttributes, ref MyCsgShapePlanetHillAttributes hillAttributes, ref MyCsgShapePlanetHillAttributes canyonAttributes, float deviationFrequency = 0, float detailFrequency = 0)
        {
            m_translation = translation;
            m_random = random;
            m_shapeAttributes = shapeAttributes;
            m_hillAttributes = hillAttributes;
            m_canyonAttributes = canyonAttributes;

            m_canyonBlendTreshold = m_canyonAttributes.Treshold + m_canyonAttributes.BlendTreshold;
            m_hillBlendTreshold = m_hillAttributes.Treshold - m_hillAttributes.BlendTreshold;

            m_shapeAttributes.Radius = (shapeAttributes.Radius/2.0f) * (1 - shapeAttributes.DeviationScale * m_hillAttributes.SizeRatio);
            m_halfDeviation = (shapeAttributes.Radius / 2.0f) * shapeAttributes.DeviationScale;

            m_deviationFrequency = deviationFrequency;
            m_detailFrequency    = detailFrequency;

            m_hillHalfDeviation = m_halfDeviation * m_hillAttributes.SizeRatio;
            m_canyonHalfDeviation = m_halfDeviation * m_canyonAttributes.SizeRatio;
          
            m_enableModulation = true;

            m_hillModule = new MyCompositeNoise(hillAttributes.NumNoises, hillAttributes.Frequency / m_shapeAttributes.Radius, random);

            m_canyonModule = new MyCompositeNoise(canyonAttributes.NumNoises, canyonAttributes.Frequency / m_shapeAttributes.Radius, random);

            m_normalModule = new MySimplexFast(seed: random.Next(), frequency: shapeAttributes.NormalNoiseFrequency / m_shapeAttributes.Radius);

            ComputeDerivedProperties();
        }
Example #3
0
        public MyCsgShapePlanet(MyRandom random, Vector3 translation, ref MyCsgShapePlanetShapeAttributes shapeAttributes, ref MyCsgShapePlanetHillAttributes hillAttributes, ref MyCsgShapePlanetHillAttributes canyonAttributes, float deviationFrequency = 0, float detailFrequency = 0)
        {
            m_translation      = translation;
            m_random           = random;
            m_shapeAttributes  = shapeAttributes;
            m_hillAttributes   = hillAttributes;
            m_canyonAttributes = canyonAttributes;

            m_canyonBlendTreshold = m_canyonAttributes.Treshold + m_canyonAttributes.BlendTreshold;
            m_hillBlendTreshold   = m_hillAttributes.Treshold - m_hillAttributes.BlendTreshold;

            m_shapeAttributes.Radius = (shapeAttributes.Radius / 2.0f) * (1 - shapeAttributes.DeviationScale * m_hillAttributes.SizeRatio);
            m_halfDeviation          = (shapeAttributes.Radius / 2.0f) * shapeAttributes.DeviationScale;

            m_deviationFrequency = deviationFrequency;
            m_detailFrequency    = detailFrequency;

            m_hillHalfDeviation   = m_halfDeviation * m_hillAttributes.SizeRatio;
            m_canyonHalfDeviation = m_halfDeviation * m_canyonAttributes.SizeRatio;

            m_enableModulation = true;

            m_hillModule = new MyCompositeNoise(hillAttributes.NumNoises, hillAttributes.Frequency / m_shapeAttributes.Radius, random);

            m_canyonModule = new MyCompositeNoise(canyonAttributes.NumNoises, canyonAttributes.Frequency / m_shapeAttributes.Radius, random);

            m_normalModule = new MySimplexFast(seed: random.Next(), frequency: shapeAttributes.NormalNoiseFrequency / m_shapeAttributes.Radius);

            ComputeDerivedProperties();
        }
        public MyCsgShapePlanet(Vector3 translation, ref MyCsgShapePlanetShapeAttributes shapeAttributes, ref MyCsgShapePlanetHillAttributes hillAttributes, ref MyCsgShapePlanetHillAttributes canyonAttributes, float deviationFrequency = 0, float detailFrequency = 0)
        {
            m_translation = translation;
            m_shapeAttributes = shapeAttributes;
            m_hillAttributes = hillAttributes;
            m_canyonAttributes = canyonAttributes;

            m_canyonBlendTreshold = m_canyonAttributes.Treshold + m_canyonAttributes.BlendTreshold;
            m_hillBlendTreshold = m_hillAttributes.Treshold - m_hillAttributes.BlendTreshold;

            m_shapeAttributes.Radius = (shapeAttributes.Diameter / 2.0f) * (1 - shapeAttributes.DeviationScale * m_hillAttributes.SizeRatio);
            m_shapeAttributes.Diameter = m_shapeAttributes.Radius * 2.0f;
            m_halfDeviation = (shapeAttributes.Diameter / 2.0f) * shapeAttributes.DeviationScale;

            m_deviationFrequency = deviationFrequency;
            m_detailFrequency    = detailFrequency;

            m_hillHalfDeviation = m_halfDeviation * m_hillAttributes.SizeRatio;
            m_canyonHalfDeviation = m_halfDeviation * m_canyonAttributes.SizeRatio;
          
            m_enableModulation = true;

            m_hillModule = new MyCompositeNoise(hillAttributes.NumNoises, hillAttributes.Frequency / m_shapeAttributes.Radius);

            ComputeDerivedProperties();
        }
        // 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 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();
            }
        }
 private static void PlanetGenerator0(ref MyCsgShapePlanetShapeAttributes shapeAttributes, ref MyCsgShapePlanetHillAttributes hillAttributes, ref MyCsgShapePlanetHillAttributes canyonAttributes, MyMaterialLayer[] materialLevels, out MyCompositeShapeGeneratedData data)
 {
     PlanetGenerator(ref shapeAttributes, ref hillAttributes, ref canyonAttributes, materialLevels, out data);
 }
        private static MyCsgShapePlanetHillAttributes FillValues(MyStructureParams input, MyRandom random)
        {
            MyCsgShapePlanetHillAttributes outputValues = new MyCsgShapePlanetHillAttributes();

            outputValues.BlendTreshold = random.NextFloat(input.BlendSize.Min, input.BlendSize.Max);
            outputValues.Treshold = random.NextFloat(input.Treshold.Min, input.Treshold.Max);
            outputValues.Frequency = random.NextFloat(input.Frequency.Min, input.Frequency.Max);
            outputValues.SizeRatio = random.NextFloat(input.SizeRatio.Min, input.SizeRatio.Max);
            outputValues.NumNoises = random.Next((int)input.NumNoises.Min, (int)input.NumNoises.Max);

            return outputValues;
        }
 private void SpawnPlanet(ref MyCsgShapePlanetShapeAttributes planetShapeAttributes, ref MyCsgShapePlanetHillAttributes hillAttributes, ref MyCsgShapePlanetHillAttributes canyonAttributes, List<MyMaterialLayer> layers, Vector3D? pos = null)
 {
   
 }
 public static MyStorageBase CreatePlanetStorage(
     ref MyCsgShapePlanetShapeAttributes shapeAttributes,
     ref MyCsgShapePlanetHillAttributes hillAttributes,
     ref MyCsgShapePlanetHillAttributes canyonAttributes,
     MyMaterialLayer[] materialLayers)
 {
     //return new MyOctreeStorage(
     //    MyCompositeShapeProvider.CreatePlanetShape(0, ref shapeAttributes, ref hillAttributes, ref canyonAttributes, materialLayers),
     //    FindBestOctreeSize(shapeAttributes.Radius));
     return null;
 }
        private void GetPlanetAttributes(out MyCsgShapePlanetShapeAttributes planetShapeAttributes, out MyCsgShapePlanetHillAttributes hillAttributes, out MyCsgShapePlanetHillAttributes canyonAttributes)
        {
            int seed = GetProceduralAsteroidSeed(m_procAsteroidSeed);
            planetShapeAttributes = new MyCsgShapePlanetShapeAttributes();
            planetShapeAttributes.DeviationScale = m_planetDeviationScaleValue;
            planetShapeAttributes.Radius = m_procAsteroidSize.Value;
            planetShapeAttributes.Seed = seed;
            planetShapeAttributes.LayerDeviationSeed = GetProceduralAsteroidSeed(m_materialLayerDeviationSeed);
            planetShapeAttributes.NoiseFrequency = m_planetStructureRatio.Value;
            planetShapeAttributes.NormalNoiseFrequency = m_normalNoiseFrequency.Value;
            planetShapeAttributes.LayerDeviationNoiseFreqeuncy = m_materialLayerDeviationNoise.Value;

            hillAttributes = new MyCsgShapePlanetHillAttributes();
            hillAttributes.SizeRatio = m_planetHillSizeRatio.Value;
            hillAttributes.Treshold = m_planetHillTreshold.Value;
            hillAttributes.BlendTreshold = m_planetHillBlendTreshold.Value;
            hillAttributes.Frequency = m_planetHillFrequency.Value;
            hillAttributes.NumNoises = (int)Math.Ceiling(m_planetHillNumNoises.Value);

            canyonAttributes = new MyCsgShapePlanetHillAttributes();
            canyonAttributes.SizeRatio = m_planetCanyonSizeRatio.Value;
            canyonAttributes.Treshold = m_planetCanyonTreshold.Value;
            canyonAttributes.BlendTreshold =  m_planetCanyonBlendTreshold.Value;
            canyonAttributes.Frequency = m_planetCanyonFrequency.Value;
            canyonAttributes.NumNoises = (int)Math.Ceiling(m_planetCanyonNumNoises.Value);
        }
        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: 1);

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

                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();
            }
        }