diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs index bf5e77696b..0ad60df87e 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) @@ -594,6 +599,80 @@ namespace OpenSim.Region.Terrain s.Close(); } + /// + /// 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. ///