Ejemplo n.º 1
0
 public override void OnAddedToScene()
 {
     base.OnAddedToScene();
     if (this.m_mesher == null)
     {
         this.m_mesher = new MyVoxelMesherComponent();
         MyPlanet rootVoxel = this.m_voxelMap.RootVoxel as MyPlanet;
         if (rootVoxel != null)
         {
             MyObjectBuilder_VoxelMesherComponentDefinition mesherPostprocessing = rootVoxel.Generator.MesherPostprocessing;
             if (mesherPostprocessing != null)
             {
                 MyVoxelMesherComponentDefinition def = new MyVoxelMesherComponentDefinition();
                 def.Init(mesherPostprocessing, MyModContext.BaseGame);
                 this.m_mesher.Init(def);
             }
         }
         this.m_mesher.SetContainer(base.Entity.Components);
         this.m_mesher.OnAddedToScene();
     }
     if (!this.m_bodiesInitialized)
     {
         this.CreateRigidBodies();
     }
     ActiveVoxelPhysicsBodies++;
 }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
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;
        }