public static BaseComponent LoadFromDefinition(ContentManager content, string definitionPath, BaseEntity parent) { TerrainComponentDefinition compDef = content.Load <TerrainComponentDefinition>(definitionPath); TerrainComponent newComponent = new TerrainComponent(parent, compDef); return(newComponent); }
/// <summary> /// Create an entire <see cref="Terrain"/> section. /// </summary> /// <param name="game">QSGame reference</param> public TerrainComponent(BaseEntity entity, TerrainComponentDefinition compDef) : base(entity) { // Register the terrain entity with the game. this.parentEntity.Game.TerrainID = this.parentEntity.UniqueID; this.vertexList = new List <VertexTerrain>(); this.detailDefault = LOD.High; this.detail = this.detailDefault; if (compDef.ElevationStrength < 1.0f) { throw new Exception("TerrainComponentDefinition's 'ElevationStrength' must be 1.0 or greater"); } this.elevationStrength = compDef.ElevationStrength; InitializeTerrain(compDef.HeightMapImagePath, compDef.ScaleFactor, compDef.SmoothingPasses); // Sets up the LOD arrays to allow for new LODs later on. SetupLODS(); // Setup a very low LOD terrain. This will allow the water // component to use a very low detail terrain for faster // rendering. This terrain is not the default unless specified // seperately, so the terrain will continue to render at // its default setting, this merely sets up a second LOD terrain // for use by other components. switch (this.parentEntity.Game.Settings.GraphicsLevel) { case GraphicsLevel.Highest: // No LOD needed at highest settings break; case GraphicsLevel.High: AddNew(LOD.Med); break; case GraphicsLevel.Med: case GraphicsLevel.Low: AddNew(LOD.Low); break; } }