void NewHeightMap(int heightmapwidth, int heightmapheight) { Terrain terrain = Terrain.GetInstance(); terrain.HeightMapWidth = heightmapwidth; terrain.HeightMapHeight = heightmapheight; terrain.Map = new double[terrain.HeightMapWidth, terrain.HeightMapHeight]; terrain.HeightmapFilename = ""; terrain.OnTerrainModified(); }
void on_btnAddStage_clicked(object o, EventArgs e) { //MapTextureStage maptexturestage = GetSelectedMapTextureStage(); //if (maptexturestage != null) //{ Terrain.GetInstance().texturestages.Add(new MapTextureStage(MapTextureStage.OperationType.Blend)); terrain.OnTerrainModified(); //} }
public void LoadSm3(string filename) { terrain.tdfparser = TdfParser.FromFile(filename); TdfParser.Section terrainsection = terrain.tdfparser.RootSection.SubSection("map/terrain"); string tdfdirectory = Path.GetDirectoryName(Path.GetDirectoryName(filename)); LoadTextureStages(tdfdirectory, terrainsection); LoadHeightMap(tdfdirectory, terrainsection); terrain.OnTerrainModified(); MainUI.GetInstance().uiwindow.InfoMessage("SM3 load completed"); }
public void LoadFeatures(string featurelistfilename, string featuredatafilename) { LogFile.GetInstance().WriteLine("LoadFeatures()"); TdfParser tdfparser = TdfParser.FromFile(featurelistfilename); Terrain terrain = Terrain.GetInstance(); terrain.FeatureMap = new Unit[terrain.MapWidth, terrain.MapHeight]; Dictionary <int, string> featurenamebynumber = new Dictionary <int, string>(); int numfeaturetypes = tdfparser.RootSection.GetIntValue("map/featuretypes/numtypes"); LogFile.GetInstance().WriteLine("Num types: " + numfeaturetypes); for (int i = 0; i < numfeaturetypes; i++) { string featurename = tdfparser.RootSection.GetStringValue("map/featuretypes/type" + i); if (!File.Exists(Path.Combine("objects3d", featurename + ".s3o"))) { MainUI.GetInstance().uiwindow.WarningMessage("Warning: objects3d/" + featurename + ".s3o not found"); } else { LogFile.GetInstance().WriteLine("Feature type " + i + " " + featurename.ToLower()); featurenamebynumber.Add(i, featurename.ToLower()); } } List <Sm3Feature> features = new List <Sm3Feature>(); // from FeaturePlacer Form1.cs by Jelmer Cnossen FileStream fs = new FileStream(featuredatafilename, FileMode.Open); if (fs != null) { BinaryReader br = new BinaryReader(fs); if (br.ReadByte() != 0) { MainUI.GetInstance().uiwindow.WarningMessage("The featuredata you are trying to load was saved using a different version."); return; } int numFeatures = br.ReadInt32(); features.Clear(); for (int a = 0; a < numFeatures; a++) { Sm3Feature f = new Sm3Feature(); features.Add(f); f.type = br.ReadInt32(); f.x = br.ReadSingle(); f.y = br.ReadSingle(); f.z = br.ReadSingle(); f.rotation = br.ReadSingle(); } } foreach (Sm3Feature sm3feature in features) { if (featurenamebynumber.ContainsKey(sm3feature.type)) { string featurename = featurenamebynumber[sm3feature.type].ToLower(); if (!UnitCache.GetInstance().UnitsByName.ContainsKey(featurename)) { LogFile.GetInstance().WriteLine("Loading unit " + Path.Combine("objects3d", featurename + ".s3o") + " ... "); Unit unit = new S3oLoader().LoadS3o(Path.Combine("objects3d", featurename + ".s3o")); UnitCache.GetInstance().UnitsByName.Add(featurename, unit); } LogFile.GetInstance().WriteLine("Adding " + featurename + " at " + (int)(sm3feature.x / Terrain.SquareSize) + " " + (int)(sm3feature.y / Terrain.SquareSize)); terrain.FeatureMap[(int)(sm3feature.x / Terrain.SquareSize), (int)(sm3feature.y / Terrain.SquareSize)] = UnitCache.GetInstance().UnitsByName[featurename]; } } terrain.OnTerrainModified(); }