示例#1
0
 public PlanetMaterialRule(MyPlanetMaterialPlacementRule def, int index, float minimumSurfaceLayerDepth) : base(def, minimumSurfaceLayerDepth)
 {
     this.Height    = def.Height;
     this.Latitude  = def.Latitude;
     this.Longitude = def.Longitude;
     this.Slope     = def.Slope;
     this.Index     = index;
 }
示例#2
0
 public PlanetMaterialRule(MyPlanetMaterialPlacementRule def)
     : base(def)
 {
     Height    = def.Height;
     Latitude  = def.Latitude;
     Longitude = def.Longitude;
     Slope     = def.Slope;
 }
示例#3
0
        public MyPlanetMaterialPlacementRule(MyPlanetMaterialPlacementRule copyFrom)
        {
            // Rule data
            Height    = copyFrom.Height;
            Latitude  = copyFrom.Latitude;
            Longitude = copyFrom.Longitude;
            Slope     = copyFrom.Slope;

            // Material data
            Material = copyFrom.Material;
            Value    = copyFrom.Value;
            MaxDepth = copyFrom.MaxDepth;
            Layers   = copyFrom.Layers;
        }
示例#4
0
        private void InheritFrom(string generator)
        {
            MyPlanetGeneratorDefinition definition = MyDefinitionManager.Static.GetDefinition <MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(generator));

            if (definition == null)
            {
                MyDefinitionManager.Static.LoadingSet.m_planetGeneratorDefinitions.TryGetValue(new MyDefinitionId(typeof(MyObjectBuilder_PlanetGeneratorDefinition), generator), out definition);
            }
            if (definition == null)
            {
                MyLog.Default.WriteLine($"Could not find planet generator definition for '{generator}'.");
            }
            else
            {
                this.PlanetMaps                  = definition.PlanetMaps;
                this.HasAtmosphere               = definition.HasAtmosphere;
                this.Atmosphere                  = definition.Atmosphere;
                this.CloudLayers                 = definition.CloudLayers;
                this.SoundRules                  = definition.SoundRules;
                this.MusicCategories             = definition.MusicCategories;
                this.HillParams                  = definition.HillParams;
                this.MaterialsMaxDepth           = definition.MaterialsMaxDepth;
                this.MaterialsMinDepth           = definition.MaterialsMinDepth;
                this.GravityFalloffPower         = definition.GravityFalloffPower;
                this.HostileAtmosphereColorShift = definition.HostileAtmosphereColorShift;
                this.SurfaceMaterialTable        = definition.SurfaceMaterialTable;
                this.DistortionTable             = definition.DistortionTable;
                this.DefaultSurfaceMaterial      = definition.DefaultSurfaceMaterial;
                this.DefaultSubSurfaceMaterial   = definition.DefaultSubSurfaceMaterial;
                this.MaterialGroups              = definition.MaterialGroups;
                this.MaterialEnvironmentMappings = definition.MaterialEnvironmentMappings;
                this.SurfaceGravity              = definition.SurfaceGravity;
                this.AtmosphereSettings          = definition.AtmosphereSettings;
                this.FolderName                  = definition.FolderName;
                this.MaterialBlending            = definition.MaterialBlending;
                this.OreMappings                 = definition.OreMappings;
                this.AnimalSpawnInfo             = definition.AnimalSpawnInfo;
                this.NightAnimalSpawnInfo        = definition.NightAnimalSpawnInfo;
                this.Detail                   = definition.Detail;
                this.SectorDensity            = definition.SectorDensity;
                this.EnvironmentSectorType    = definition.EnvironmentSectorType;
                this.MesherPostprocessing     = definition.MesherPostprocessing;
                this.MinimumSurfaceLayerDepth = definition.MinimumSurfaceLayerDepth;
            }
        }
示例#5
0
        private void InheritFrom(string generator)
        {
            MyPlanetGeneratorDefinition parent = MyDefinitionManager.Static.GetDefinition <MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(generator));

            if (parent == null)
            {
                MyDefinitionManager.Static.LoadingSet.m_planetGeneratorDefinitions.TryGetValue(new MyDefinitionId(typeof(MyObjectBuilder_PlanetGeneratorDefinition), generator), out parent);
            }

            if (parent == null)
            {
                MyLog.Default.WriteLine(String.Format("Could not find planet generator definition for '{0}'.", generator));
                return;
            }

            PlanetMaps                  = parent.PlanetMaps;
            HasAtmosphere               = parent.HasAtmosphere;
            Atmosphere                  = parent.Atmosphere;
            CloudLayers                 = parent.CloudLayers;
            SoundRules                  = parent.SoundRules;
            MusicCategories             = parent.MusicCategories;
            HillParams                  = parent.HillParams;
            MaterialsMaxDepth           = parent.MaterialsMaxDepth;
            MaterialsMinDepth           = parent.MaterialsMinDepth;
            GravityFalloffPower         = parent.GravityFalloffPower;
            HostileAtmosphereColorShift = parent.HostileAtmosphereColorShift;
            SurfaceMaterialTable        = parent.SurfaceMaterialTable;
            DistortionTable             = parent.DistortionTable;
            DefaultSurfaceMaterial      = parent.DefaultSurfaceMaterial;
            DefaultSubSurfaceMaterial   = parent.DefaultSubSurfaceMaterial;
            MaterialGroups              = parent.MaterialGroups;
            MaterialEnvironmentMappings = parent.MaterialEnvironmentMappings;
            SurfaceGravity              = parent.SurfaceGravity;
            AtmosphereSettings          = parent.AtmosphereSettings;
            FolderName                  = parent.FolderName;
            MaterialBlending            = parent.MaterialBlending;
            OreMappings                 = parent.OreMappings;
            AnimalSpawnInfo             = parent.AnimalSpawnInfo;
            NightAnimalSpawnInfo        = parent.NightAnimalSpawnInfo;
            Detail                = parent.Detail;
            SectorDensity         = parent.SectorDensity;
            EnvironmentSectorType = parent.EnvironmentSectorType;
        }
示例#6
0
        protected override unsafe void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_PlanetGeneratorDefinition definition = builder as MyObjectBuilder_PlanetGeneratorDefinition;

            if ((definition.InheritFrom != null) && (definition.InheritFrom.Length > 0))
            {
                this.InheritFrom(definition.InheritFrom);
            }
            if (definition.Environment != null)
            {
                this.EnvironmentId = new MyDefinitionId?(definition.Environment.Value);
            }
            else
            {
                this.m_pgob = definition;
            }
            if (definition.PlanetMaps != null)
            {
                this.PlanetMaps = definition.PlanetMaps.Value;
            }
            if (definition.HasAtmosphere != null)
            {
                this.HasAtmosphere = definition.HasAtmosphere.Value;
            }
            if (definition.CloudLayers != null)
            {
                this.CloudLayers = definition.CloudLayers;
            }
            if (definition.SoundRules != null)
            {
                this.SoundRules = new MyPlanetEnvironmentalSoundRule[definition.SoundRules.Length];
                for (int i = 0; i < definition.SoundRules.Length; i++)
                {
                    MyPlanetEnvironmentalSoundRule rule = new MyPlanetEnvironmentalSoundRule {
                        Latitude           = definition.SoundRules[i].Latitude,
                        Height             = definition.SoundRules[i].Height,
                        SunAngleFromZenith = definition.SoundRules[i].SunAngleFromZenith,
                        EnvironmentSound   = MyStringHash.GetOrCompute(definition.SoundRules[i].EnvironmentSound)
                    };
                    rule.Latitude.ConvertToSine();
                    rule.SunAngleFromZenith.ConvertToCosine();
                    this.SoundRules[i] = rule;
                }
            }
            if (definition.MusicCategories != null)
            {
                this.MusicCategories = definition.MusicCategories;
            }
            if (definition.HillParams != null)
            {
                this.HillParams = definition.HillParams.Value;
            }
            if (definition.Atmosphere != null)
            {
                this.Atmosphere = definition.Atmosphere;
            }
            if (definition.GravityFalloffPower != null)
            {
                this.GravityFalloffPower = definition.GravityFalloffPower.Value;
            }
            if (definition.HostileAtmosphereColorShift != null)
            {
                this.HostileAtmosphereColorShift = definition.HostileAtmosphereColorShift;
            }
            if (definition.MaterialsMaxDepth != null)
            {
                this.MaterialsMaxDepth = definition.MaterialsMaxDepth.Value;
            }
            if (definition.MaterialsMinDepth != null)
            {
                this.MaterialsMinDepth = definition.MaterialsMinDepth.Value;
            }
            if ((definition.CustomMaterialTable != null) && (definition.CustomMaterialTable.Length != 0))
            {
                this.SurfaceMaterialTable = new MyPlanetMaterialDefinition[definition.CustomMaterialTable.Length];
                for (int i = 0; i < this.SurfaceMaterialTable.Length; i++)
                {
                    this.SurfaceMaterialTable[i] = definition.CustomMaterialTable[i].Clone() as MyPlanetMaterialDefinition;
                    if ((this.SurfaceMaterialTable[i].Material == null) && !this.SurfaceMaterialTable[i].HasLayers)
                    {
                        MyLog.Default.WriteLine("Custom material does not contain any material ids.");
                    }
                    else if (this.SurfaceMaterialTable[i].HasLayers)
                    {
                        float depth = this.SurfaceMaterialTable[i].Layers[0].Depth;
                        for (int j = 1; j < this.SurfaceMaterialTable[i].Layers.Length; j++)
                        {
                            float *singlePtr1 = (float *)ref this.SurfaceMaterialTable[i].Layers[j].Depth;
                            singlePtr1[0] += depth;
                            depth          = this.SurfaceMaterialTable[i].Layers[j].Depth;
                        }
                    }
                }
            }
            if ((definition.DistortionTable != null) && (definition.DistortionTable.Length != 0))
            {
                this.DistortionTable = definition.DistortionTable;
            }
            if (definition.DefaultSurfaceMaterial != null)
            {
                this.DefaultSurfaceMaterial = definition.DefaultSurfaceMaterial;
            }
            if (definition.DefaultSubSurfaceMaterial != null)
            {
                this.DefaultSubSurfaceMaterial = definition.DefaultSubSurfaceMaterial;
            }
            if (definition.SurfaceGravity != null)
            {
                this.SurfaceGravity = definition.SurfaceGravity.Value;
            }
            if (definition.AtmosphereSettings != null)
            {
                this.AtmosphereSettings = definition.AtmosphereSettings;
            }
            this.FolderName = (definition.FolderName != null) ? definition.FolderName : definition.Id.SubtypeName;
            if ((definition.ComplexMaterials != null) && (definition.ComplexMaterials.Length != 0))
            {
                this.MaterialGroups = new MyPlanetMaterialGroup[definition.ComplexMaterials.Length];
                int index = 0;
                while (index < definition.ComplexMaterials.Length)
                {
                    this.MaterialGroups[index] = definition.ComplexMaterials[index].Clone() as MyPlanetMaterialGroup;
                    MyPlanetMaterialGroup           group         = this.MaterialGroups[index];
                    MyPlanetMaterialPlacementRule[] materialRules = group.MaterialRules;
                    List <int> indices = new List <int>();
                    int        num6    = 0;
                    while (true)
                    {
                        if (num6 >= materialRules.Length)
                        {
                            if (indices.Count > 0)
                            {
                                materialRules = materialRules.RemoveIndices <MyPlanetMaterialPlacementRule>(indices);
                            }
                            group.MaterialRules = materialRules;
                            index++;
                            break;
                        }
                        if ((materialRules[num6].Material == null) && ((materialRules[num6].Layers == null) || (materialRules[num6].Layers.Length == 0)))
                        {
                            MyLog.Default.WriteLine("Material rule does not contain any material ids.");
                            indices.Add(num6);
                        }
                        else
                        {
                            if ((materialRules[num6].Layers != null) && (materialRules[num6].Layers.Length != 0))
                            {
                                float depth = materialRules[num6].Layers[0].Depth;
                                for (int i = 1; i < materialRules[num6].Layers.Length; i++)
                                {
                                    float *singlePtr2 = (float *)ref materialRules[num6].Layers[i].Depth;
                                    singlePtr2[0] += depth;
                                    depth          = materialRules[num6].Layers[i].Depth;
                                }
                            }
                            materialRules[num6].Slope.ConvertToCosine();
                            materialRules[num6].Latitude.ConvertToSine();
                            materialRules[num6].Longitude.ConvertToCosineLongitude();
                        }
                        num6++;
                    }
                }
            }
            if (definition.OreMappings != null)
            {
                this.OreMappings = definition.OreMappings;
            }
            if (definition.MaterialBlending != null)
            {
                this.MaterialBlending = definition.MaterialBlending.Value;
            }
            if (definition.SurfaceDetail != null)
            {
                this.Detail = definition.SurfaceDetail;
            }
            if (definition.AnimalSpawnInfo != null)
            {
                this.AnimalSpawnInfo = definition.AnimalSpawnInfo;
            }
            if (definition.NightAnimalSpawnInfo != null)
            {
                this.NightAnimalSpawnInfo = definition.NightAnimalSpawnInfo;
            }
            if (definition.SectorDensity != null)
            {
                this.SectorDensity = definition.SectorDensity.Value;
            }
            MyObjectBuilder_PlanetMapProvider mapProvider = definition.MapProvider;

            if (definition.MapProvider == null)
            {
                MyObjectBuilder_PlanetMapProvider        local1    = definition.MapProvider;
                MyObjectBuilder_PlanetTextureMapProvider provider1 = new MyObjectBuilder_PlanetTextureMapProvider();
                provider1.Path = this.FolderName;
                mapProvider    = provider1;
            }
            this.MapProvider          = mapProvider;
            this.MesherPostprocessing = definition.MesherPostprocessing;
            if (this.MesherPostprocessing == null)
            {
                MyLog.Default.Warning("PERFORMANCE WARNING: Postprocessing voxel triangle decimation steps not defined for " + this, Array.Empty <object>());
            }
            this.MinimumSurfaceLayerDepth = definition.MinimumSurfaceLayerDepth;
        }
示例#7
0
 public SerializableRangePair(RangePair rangePair)
 {
     min = new SerializableRange(rangePair.Min);
     max = new SerializableRange(rangePair.Max);
 }
示例#8
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            var ob = builder as MyObjectBuilder_PlanetGeneratorDefinition;

            if (ob.InheritFrom != null && ob.InheritFrom.Length > 0)
            {
                InheritFrom(ob.InheritFrom);
            }

            if (ob.Environment.HasValue)
            {
                EnvironmentId = ob.Environment.Value;
            }
            else
            {
                m_pgob = ob;
            }

            if (ob.PlanetMaps.HasValue)
            {
                PlanetMaps = ob.PlanetMaps.Value;
            }

            if (ob.HasAtmosphere.HasValue)
            {
                HasAtmosphere = ob.HasAtmosphere.Value;
            }

            if (ob.CloudLayers != null)
            {
                CloudLayers = ob.CloudLayers;
            }

            if (ob.SoundRules != null)
            {
                SoundRules = new MyPlanetEnvironmentalSoundRule[ob.SoundRules.Length];

                for (int ruleIndex = 0; ruleIndex < ob.SoundRules.Length; ++ruleIndex)
                {
                    MyPlanetEnvironmentalSoundRule sr;

                    sr = new MyPlanetEnvironmentalSoundRule()
                    {
                        Latitude           = ob.SoundRules[ruleIndex].Latitude,
                        Height             = ob.SoundRules[ruleIndex].Height,
                        SunAngleFromZenith = ob.SoundRules[ruleIndex].SunAngleFromZenith,
                        EnvironmentSound   = MyStringHash.GetOrCompute(ob.SoundRules[ruleIndex].EnvironmentSound)
                    };

                    sr.Latitude.ConvertToSine();
                    sr.SunAngleFromZenith.ConvertToCosine();
                    SoundRules[ruleIndex] = sr;
                }
            }
            if (ob.MusicCategories != null)
            {
                MusicCategories = ob.MusicCategories;
            }

            if (ob.HillParams.HasValue)
            {
                HillParams = ob.HillParams.Value;
            }

            if (ob.Atmosphere != null)
            {
                Atmosphere = ob.Atmosphere;
            }

            if (ob.GravityFalloffPower.HasValue)
            {
                GravityFalloffPower = ob.GravityFalloffPower.Value;
            }

            if (ob.HostileAtmosphereColorShift != null)
            {
                HostileAtmosphereColorShift = ob.HostileAtmosphereColorShift;
            }

            if (ob.MaterialsMaxDepth.HasValue)
            {
                MaterialsMaxDepth = ob.MaterialsMaxDepth.Value;
            }
            if (ob.MaterialsMinDepth.HasValue)
            {
                MaterialsMinDepth = ob.MaterialsMinDepth.Value;
            }

            if (ob.CustomMaterialTable != null && ob.CustomMaterialTable.Length > 0)
            {
                SurfaceMaterialTable = new MyPlanetMaterialDefinition[ob.CustomMaterialTable.Length];
                for (int i = 0; i < SurfaceMaterialTable.Length; i++)
                {
                    SurfaceMaterialTable[i] = ob.CustomMaterialTable[i].Clone() as MyPlanetMaterialDefinition;
                    if (SurfaceMaterialTable[i].Material == null && !SurfaceMaterialTable[i].HasLayers)
                    {
                        MyLog.Default.WriteLine("Custom material does not contain any material ids.");
                    }
                    else if (SurfaceMaterialTable[i].HasLayers)
                    {
                        // Make the depth cumulative so we don't have to calculate it later.
                        // If we want we can even binary search it.
                        float depth = SurfaceMaterialTable[i].Layers[0].Depth;
                        for (int j = 1; j < SurfaceMaterialTable[i].Layers.Length; j++)
                        {
                            SurfaceMaterialTable[i].Layers[j].Depth += depth;
                            depth = SurfaceMaterialTable[i].Layers[j].Depth;
                        }
                    }
                }
            }

            if (ob.DistortionTable != null && ob.DistortionTable.Length > 0)
            {
                DistortionTable = ob.DistortionTable;
            }

            if (ob.DefaultSurfaceMaterial != null)
            {
                DefaultSurfaceMaterial = ob.DefaultSurfaceMaterial;
            }

            if (ob.DefaultSubSurfaceMaterial != null)
            {
                DefaultSubSurfaceMaterial = ob.DefaultSubSurfaceMaterial;
            }

            if (ob.SurfaceGravity.HasValue)
            {
                SurfaceGravity = ob.SurfaceGravity.Value;
            }

            if (ob.AtmosphereSettings != null)
            {
                AtmosphereSettings = ob.AtmosphereSettings;
            }

            // Folder name is not inherited to avoid weirdness.
            FolderName = ob.FolderName != null ? ob.FolderName : ob.Id.SubtypeName;

            if (ob.ComplexMaterials != null && ob.ComplexMaterials.Length > 0)
            {
                MaterialGroups = new MyPlanetMaterialGroup[ob.ComplexMaterials.Length];

                for (int k = 0; k < ob.ComplexMaterials.Length; k++)
                {
                    MaterialGroups[k] = ob.ComplexMaterials[k].Clone() as MyPlanetMaterialGroup;

                    var        group        = MaterialGroups[k];
                    var        matRules     = group.MaterialRules;
                    List <int> badMaterials = new List <int>();

                    for (int i = 0; i < matRules.Length; i++)
                    {
                        if (matRules[i].Material == null && (matRules[i].Layers == null || matRules[i].Layers.Length == 0))
                        {
                            MyLog.Default.WriteLine("Material rule does not contain any material ids.");
                            badMaterials.Add(i);
                            continue;
                        }
                        else if (matRules[i].Layers != null && matRules[i].Layers.Length != 0)
                        {
                            // Make the depth cumulative so we don't have to calculate it later.
                            // If we want we can even binary search it.
                            float depth = matRules[i].Layers[0].Depth;
                            for (int j = 1; j < matRules[i].Layers.Length; j++)
                            {
                                matRules[i].Layers[j].Depth += depth;
                                depth = matRules[i].Layers[j].Depth;
                            }
                        }

                        // We use the cosine later so we precompute it here.
                        matRules[i].Slope.ConvertToCosine();
                        matRules[i].Latitude.ConvertToSine();
                        matRules[i].Longitude.ConvertToCosineLongitude();
                    }

                    if (badMaterials.Count > 0)
                    {
                        matRules = matRules.RemoveIndices(badMaterials);
                    }

                    group.MaterialRules = matRules;
                }
            }

            /*if (ob.EnvironmentItems != null && ob.EnvironmentItems.Length > 0)
             * {
             *  MaterialEnvironmentMappings = new Dictionary<int, Dictionary<string, List<MyPlanetEnvironmentMapping>>>();
             *
             *  for (int i = 0; i < ob.EnvironmentItems.Length; i++)
             *  {
             *      PlanetEnvironmentItemMapping map = ob.EnvironmentItems[i];
             *      if (map.Rule != null)
             *          map.Rule = map.Rule.Clone() as MyPlanetSurfaceRule;
             *      else
             *          map.Rule = new MyPlanetSurfaceRule();
             *      map.Rule.Slope.ConvertToCosine();
             *      map.Rule.Latitude.ConvertToSine();
             *      map.Rule.Longitude.ConvertToCosineLongitude();
             *
             *      // If the mapping does not assign a material it is ignored
             *      if (map.Materials == null) break;
             *
             *      if (map.Biomes == null) map.Biomes = m_arrayOfZero;
             *
             *      foreach (var biome in map.Biomes)
             *      {
             *          Dictionary<string, List<MyPlanetEnvironmentMapping>> matmap;
             *
             *          if (MaterialEnvironmentMappings.ContainsKey(biome))
             *          {
             *              matmap = MaterialEnvironmentMappings[biome];
             *          }
             *          else
             *          {
             *              matmap = new Dictionary<string, List<MyPlanetEnvironmentMapping>>();
             *              MaterialEnvironmentMappings.Add(biome, matmap);
             *          }
             *
             *          foreach (var material in map.Materials)
             *          {
             *              if (!matmap.ContainsKey(material))
             *                  matmap.Add(material, new List<MyPlanetEnvironmentMapping>());
             *
             *              matmap[material].Add(new MyPlanetEnvironmentMapping(map));
             *          }
             *      }
             *  }
             * }*/

            if (ob.OreMappings != null)
            {
                OreMappings = ob.OreMappings;
            }

            if (ob.MaterialBlending.HasValue)
            {
                MaterialBlending = ob.MaterialBlending.Value;
            }

            if (ob.SurfaceDetail != null)
            {
                Detail = ob.SurfaceDetail;
            }

            if (ob.AnimalSpawnInfo != null)
            {
                AnimalSpawnInfo = ob.AnimalSpawnInfo;
            }

            if (ob.NightAnimalSpawnInfo != null)
            {
                NightAnimalSpawnInfo = ob.NightAnimalSpawnInfo;
            }

            if (ob.SectorDensity.HasValue)
            {
                SectorDensity = ob.SectorDensity.Value;
            }
        }