From 30fe88b80892e4538dc2b6f71992c3f51d35e95a Mon Sep 17 00:00:00 2001
From: Adam Frisby
Date: Thu, 3 Dec 2009 02:44:12 +1100
Subject: * Terrain uploads via the Estate Tools now support a multitude of
file formats. Specifically: . bmp, .raw, .r32 & .r64. (in ascending order of
precision) * It uses file length as the detection routine (as each of these
formats has a distinct size in bytes for a 256x256 array.) - more formats
should be possible to add.
---
.../World/Estate/EstateManagementModule.cs | 50 ++++++++++++++--------
1 file changed, 31 insertions(+), 19 deletions(-)
(limited to 'OpenSim/Region/CoreModules')
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
index e3a395e..b1dcb14 100644
--- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
+++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
@@ -471,20 +471,45 @@ namespace OpenSim.Region.CoreModules.World.Estate
if (terr != null)
{
m_log.Warn("[CLIENT]: Got Request to Send Terrain in region " + m_scene.RegionInfo.RegionName);
- if (File.Exists(Util.dataDir() + "/terrain.raw"))
- {
- File.Delete(Util.dataDir() + "/terrain.raw");
- }
+
try
{
- FileStream input = new FileStream(Util.dataDir() + "/terrain.raw", FileMode.CreateNew);
+
+ string localfilename = "terrain.raw";
+
+ if (terrainData.Length == 851968)
+ {
+ localfilename = Path.Combine(Util.dataDir(),"terrain.raw"); // It's a .LLRAW
+ }
+
+ if (terrainData.Length == 196662) // 24-bit 256x256 Bitmap
+ localfilename = Path.Combine(Util.dataDir(), "terrain.bmp");
+
+ if (terrainData.Length == 256 * 256 * 4) // It's a .R32
+ localfilename = Path.Combine(Util.dataDir(), "terrain.r32");
+
+ if (terrainData.Length == 256 * 256 * 8) // It's a .R64
+ localfilename = Path.Combine(Util.dataDir(), "terrain.r64");
+
+ if (File.Exists(localfilename))
+ {
+ File.Delete(localfilename);
+ }
+
+ FileStream input = new FileStream(localfilename, FileMode.CreateNew);
input.Write(terrainData, 0, terrainData.Length);
input.Close();
+
+ FileInfo x = new FileInfo(localfilename);
+
+ terr.LoadFromFile(localfilename);
+ remoteClient.SendAlertMessage("Your terrain was loaded as a ." + x.Extension + " file. It may take a few moments to appear.");
+
}
catch (IOException e)
{
m_log.ErrorFormat("[TERRAIN]: Error Saving a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString());
- remoteClient.SendAlertMessage("There was an IO Exception loading your terrain. Please check free space");
+ remoteClient.SendAlertMessage("There was an IO Exception loading your terrain. Please check free space.");
return;
}
@@ -502,29 +527,16 @@ namespace OpenSim.Region.CoreModules.World.Estate
return;
}
-
-
-
-
- try
- {
- terr.LoadFromFile(Util.dataDir() + "/terrain.raw");
- remoteClient.SendAlertMessage("Your terrain was loaded. Give it a minute or two to apply");
- }
catch (Exception e)
{
m_log.ErrorFormat("[TERRAIN]: Error loading a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString());
remoteClient.SendAlertMessage("There was a general error loading your terrain. Please fix the terrain file and try again");
}
-
}
else
{
remoteClient.SendAlertMessage("Unable to apply terrain. Cannot get an instance of the terrain module");
}
-
-
-
}
private void handleUploadTerrain(IClientAPI remote_client, string clientFileName)
--
cgit v1.1
From c0f3a4c8332f235e998714214011c5412bdcacf0 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 4 Dec 2009 18:26:58 +0000
Subject: Allow terrain heightmaps to be loaded directly from URIs via the
remote admin plugin See http://opensimulator.org/mantis/view.php?id=4418
Thanks StrawberryFride See
---
.../CoreModules/World/Terrain/TerrainModule.cs | 32 +++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Region/CoreModules')
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
index ba271fd..a40828b 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
@@ -29,6 +29,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
+using System.Net;
using log4net;
using Nini.Config;
using OpenMetaverse;
@@ -259,6 +260,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain
}
///
+ /// Loads a terrain file from the specified URI
+ ///
+ /// The name of the terrain to load
+ /// The URI to the terrain height map
+ public void LoadFromStream(string filename, Uri pathToTerrainHeightmap)
+ {
+ LoadFromStream(filename, URIFetch(pathToTerrainHeightmap));
+ }
+
+ ///
/// Loads a terrain file from a stream and installs it in the scene.
///
/// Filename to terrain file. Type is determined by extension.
@@ -267,7 +278,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
{
foreach (KeyValuePair loader in m_loaders)
{
- if (@filename.EndsWith(loader.Key))
+ if (filename.EndsWith(loader.Key))
{
lock (m_scene)
{
@@ -295,6 +306,25 @@ namespace OpenSim.Region.CoreModules.World.Terrain
throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename));
}
+ private static Stream URIFetch(Uri uri)
+ {
+ HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
+
+ // request.Credentials = credentials;
+
+ request.ContentLength = 0;
+ request.KeepAlive = false;
+
+ WebResponse response = request.GetResponse();
+ Stream file = response.GetResponseStream();
+
+ if (response.ContentLength == 0)
+ throw new Exception(String.Format("{0} returned an empty file", uri.ToString()));
+
+ // return new BufferedStream(file, (int) response.ContentLength);
+ return new BufferedStream(file, 1000000);
+ }
+
///
/// Modify Land
///
--
cgit v1.1