public void TestSaveMethod() { HeightmapFile heightmapFile = new HeightmapFile(); heightmapFile.Load(TEST_FILE); MemoryStream savedStream = new MemoryStream(); heightmapFile.Save(savedStream); heightmapFile.Load(TEST_FILE); savedStream.Seek(0, SeekOrigin.Begin); HeightmapFile savedHeightmapFile = new HeightmapFile(); savedHeightmapFile.Load(savedStream); savedStream.Close(); for (int x = 0; x < heightmapFile.Height; x++) { for (int y = 0; y < heightmapFile.Width; y++) { Assert.AreEqual(heightmapFile[x, y], savedHeightmapFile[x, y], "Height values do not match"); } } for (int x = 0; x < heightmapFile.Patches.GetLength(0); x++) { for (int y = 0; y < heightmapFile.Patches.GetLength(1); y++) { Assert.AreEqual(heightmapFile.Patches[x, y].Minimum, savedHeightmapFile.Patches[x, y].Minimum, "Minimum patch values do not match"); Assert.AreEqual(heightmapFile.Patches[x, y].Maximum, savedHeightmapFile.Patches[x, y].Maximum, "Maximum patch values do not match"); } } for (int i = 0; i < heightmapFile.QuadPatches.Length; i++) { Assert.AreEqual(heightmapFile.QuadPatches[i].Minimum, savedHeightmapFile.QuadPatches[i].Minimum, "Minimum quad patch values do not match"); Assert.AreEqual(heightmapFile.QuadPatches[i].Maximum, savedHeightmapFile.QuadPatches[i].Maximum, "Maximum quad patch values do not match"); } }
public void TestLoadMethod() { const int HEIGHT = 65; const int WIDTH = 65; Stream stream = File.OpenRead(TEST_FILE); stream.Seek(0, SeekOrigin.End); long fileSize = stream.Position; stream.Seek(0, SeekOrigin.Begin); HeightmapFile heightmapFile = new HeightmapFile(); heightmapFile.Load(stream); long streamPosition = stream.Position; stream.Close(); Assert.AreEqual(fileSize, streamPosition, "Not all of the file was read"); Assert.AreEqual(WIDTH, heightmapFile.Width, "Incorrect width"); Assert.AreEqual(HEIGHT, heightmapFile.Height, "Incorrect height"); }
static Terrain ImportTerrain(string planet, string map, Revise.Files.ZON.ZoneFile zon, int x, int y) { var blockName = x.ToString() + "_" + y.ToString(); var basePath = rootPath + "3DDATA/MAPS/" + planet + "/" + map + "/" + blockName; float blockX = (x - 32) * 160; float blockY = (32 - y) * 160; Object.DestroyImmediate(GameObject.Find(blockName)); var ifo = new Revise.Files.IFO.MapDataFile(); ifo.Load(basePath + ".IFO"); for (int i = 0; i < ifo.Objects.Count; ++i) { var obj = ifo.Objects[i]; ImportObject("JUNON_JDT_DECO", x, y, "DECO", i, obj); } for (int i = 0; i < ifo.Buildings.Count; ++i) { var obj = ifo.Buildings[i]; ImportObject("JUNON_JDT_CNST", x, y, "CNST", i, obj); } for (int i = 0; i < ifo.Animations.Count; ++i) { //var obj = ifo.Animations[i]; Debug.LogWarning("Got unexpected animation object."); } for (int i = 0; i < ifo.Sounds.Count; ++i) { var snd = ifo.Sounds[i]; var sndName = "SND_" + snd.ObjectID.ToString() + " (" + blockName + "_" + i.ToString() + ")"; var a = new GameObject(); //var s = a.AddComponent<AudioSource>(); //TODO: Need to link to audio after copy in prestage a.transform.localPosition = ifotruPosition(snd.Position); a.transform.localRotation = rtuRotation(snd.Rotation); a.transform.localScale = rtuScale(snd.Scale); a.name = sndName; a.isStatic = true; } var tex = ImportPlanMap(planet, map, x, y); var him = new Revise.Files.HIM.HeightmapFile(); him.Load(basePath + ".HIM"); float[,] heights = new float[65,65]; float heightMin = him.Heights[0, 0]; float heightMax = him.Heights[0, 0]; for (int ix = 0; ix < 65; ++ix) { for (int iy = 0; iy < 65; ++iy) { if (him.Heights[ix, iy] < heightMin) { heightMin = him.Heights[ix, iy]; } if (him.Heights[ix, iy] > heightMax) { heightMax = him.Heights[ix, iy]; } } } float heightBase = heightMin; float heightDelta = heightMax - heightMin; for (int ix = 0; ix < 65; ++ix) { for (int iy = 0; iy < 65; ++iy) { heights[ix, iy] = (him.Heights[64 - ix, iy] - heightBase) / heightDelta; } } var til = new Revise.Files.TIL.TileFile(); til.Load(basePath + ".TIL"); /* for (int ix = 0; ix < til.Width; ++ix) { for (int iy = 0; iy < til.Height; ++iy) { var t = til[ix, iy].Tile; Debug.Log( til[ix, iy].Brush.ToString() + "," + til[ix, iy].TileSet.ToString() + "," + til[ix, iy].TileIndex.ToString() + "," + til[ix, iy].Tile.ToString()); Debug.Log( zon.Tiles[t].Layer1.ToString() + "," + zon.Tiles[t].Offset1.ToString() + "," + zon.Tiles[t].Layer2.ToString() + "," + zon.Tiles[t].Offset2.ToString() + "," + zon.Tiles[t].TileType.ToString() + "," + zon.Tiles[t].TileType.ToString() + "," + zon.Tiles[t].Rotation.ToString()); Debug.Log(zon.Textures[zon.Tiles[t].Layer1 + zon.Tiles[t].Offset1]); Debug.Log(zon.Textures[zon.Tiles[t].Layer2 + zon.Tiles[t].Offset2]); } } */ var td = new TerrainData(); td.size = new Vector3(80, heightDelta/100, 80); td.heightmapResolution = 65; td.SetHeights(0, 0, heights); var ts = new SplatPrototype[1]; ts[0] = new SplatPrototype(); ts[0].texture = tex; ts[0].tileSize = new Vector2(160, 160); td.splatPrototypes = ts; var ter = Terrain.CreateTerrainGameObject(td).GetComponent<Terrain>(); ter.name = blockName; ter.transform.localPosition = new Vector3(blockX, heightBase/100, blockY); return ter; }