From 858e232cec35bab9681cd49945cd4ba31197dc8d Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Mon, 2 Jul 2007 16:04:50 +0000 Subject: * Added "HiRAW" mode export for generating as precise outputs as possible in the .RAW format. Ideal for exporting a heightmap to a simulator only capable of reading the RAW format. If you are exporting between OpenSim regions, use F64 instead. --- .../Region/Terrain.BasicTerrain/TerrainEngine.cs | 81 +++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs index bf5e776..0ad60df 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs @@ -192,7 +192,7 @@ namespace OpenSim.Region.Terrain resultText += "terrain voronoi - generates a worley fractal with X points per block"; resultText += "terrain seed - sets the random seed value to \n"; resultText += "terrain load - loads a terrain from disk, type can be 'F32', 'F64', 'RAW' or 'IMG'\n"; - resultText += "terrain save - saves a terrain to disk, type can be 'F32', 'F64' or 'PNG'\n"; + resultText += "terrain save - saves a terrain to disk, type can be 'F32', 'F64', 'PNG', 'RAW' or 'HIRAW'\n"; resultText += "terrain save grdmap - creates a PNG snapshot of the region using a named gradient map\n"; resultText += "terrain rescale - rescales a terrain to be between and meters high\n"; resultText += "terrain erode aerobic \n"; @@ -295,6 +295,10 @@ namespace OpenSim.Region.Terrain writeToFileRAW(args[2]); break; + case "hiraw": + writeToFileHiRAW(args[2]); + break; + default: resultText = "Unknown image or data format"; return false; @@ -532,6 +536,7 @@ namespace OpenSim.Region.Terrain /// /// A very fast LL-RAW file output mechanism - lower precision mechanism but wont take 5 minutes to run either. + /// (is also editable in an image application) /// /// Filename to write to public void writeToFileRAW(string filename) @@ -595,6 +600,80 @@ namespace OpenSim.Region.Terrain } /// + /// Outputs to a LL compatible RAW in the most efficient manner possible + /// + /// Does not calculate the revert map + /// The filename to output to + public void writeToFileHiRAW(string filename) + { + System.IO.FileInfo file = new System.IO.FileInfo(filename); + System.IO.FileStream s = file.Open(System.IO.FileMode.CreateNew, System.IO.FileAccess.Write); + System.IO.BinaryWriter bs = new System.IO.BinaryWriter(s); + + // Generate a smegging big lookup table to speed the operation up (it needs it) + double[] lookupTable = new double[65536]; + int i, j, x, y; + for (i = 0; i < 256; i++) + { + for (j = 0; j < 256; j++) + { + lookupTable[i + (j * 256)] = ((double)i * ((double)j / 127.0)); + } + } + + // Output the calculated raw + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + double t = heightmap.get(x, y); + double min = double.MaxValue; + int index = 0; + + for (i = 0; i < 65536; i++) + { + if (Math.Abs(t - lookupTable[i]) < min) + { + min = Math.Abs(t - lookupTable[i]); + index = i; + } + } + + byte red = (byte)(index & 0xFF); + byte green = (byte)((index >> 8) & 0xFF); + byte blue = (byte)watermap.get(x, y); + byte alpha1 = 0; // Land Parcels + byte alpha2 = 0; // For Sale Land + byte alpha3 = 0; // Public Edit Object + byte alpha4 = 0; // Public Edit Land + byte alpha5 = 255; // Safe Land + byte alpha6 = 255; // Flying Allowed + byte alpha7 = 255; // Create Landmark + byte alpha8 = 255; // Outside Scripts + byte alpha9 = red; + byte alpha10 = green; + + bs.Write(red); + bs.Write(green); + bs.Write(blue); + bs.Write(alpha1); + bs.Write(alpha2); + bs.Write(alpha3); + bs.Write(alpha4); + bs.Write(alpha5); + bs.Write(alpha6); + bs.Write(alpha7); + bs.Write(alpha8); + bs.Write(alpha9); + bs.Write(alpha10); + } + } + + bs.Close(); + s.Close(); + } + + /// /// Sets the random seed to be used by procedural functions which involve random numbers. /// /// The desired seed -- cgit v1.1