aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
diff options
context:
space:
mode:
authorRobert Adams2014-01-19 10:09:43 -0800
committerRobert Adams2014-01-19 10:09:43 -0800
commitdd6db7293975bffc3693e0164dda8307a4e4bcf7 (patch)
treecfd275e8cbc9e64913b1dbf033164956b37098c5 /OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
parentMerge branch 'master' into varregion (diff)
downloadopensim-SC_OLD-dd6db7293975bffc3693e0164dda8307a4e4bcf7.zip
opensim-SC_OLD-dd6db7293975bffc3693e0164dda8307a4e4bcf7.tar.gz
opensim-SC_OLD-dd6db7293975bffc3693e0164dda8307a4e4bcf7.tar.bz2
opensim-SC_OLD-dd6db7293975bffc3693e0164dda8307a4e4bcf7.tar.xz
varregion: add --displacement parameter to 'load oar'.
Adds displacment to all objects and terrain loaded from the oar. As an example, if you have a 512x512 region and an old 256x256 oar, doing load oar --displacement "<128,128,0>" oarFile.oar will load the object (and terrain) into the middle of the 512x512 region. If displacement is not specified, 'load oar' works like it always has. If you have a 5
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs38
1 files changed, 35 insertions, 3 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
index 9766bfe..7bc5e88 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
@@ -314,12 +314,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain
314 LoadFromStream(filename, URIFetch(pathToTerrainHeightmap)); 314 LoadFromStream(filename, URIFetch(pathToTerrainHeightmap));
315 } 315 }
316 316
317 public void LoadFromStream(string filename, Stream stream)
318 {
319 Vector2 defaultDisplacement = new Vector2(0f, 0f);
320 LoadFromStream(filename, defaultDisplacement, stream);
321 }
322
317 /// <summary> 323 /// <summary>
318 /// Loads a terrain file from a stream and installs it in the scene. 324 /// Loads a terrain file from a stream and installs it in the scene.
319 /// </summary> 325 /// </summary>
320 /// <param name="filename">Filename to terrain file. Type is determined by extension.</param> 326 /// <param name="filename">Filename to terrain file. Type is determined by extension.</param>
321 /// <param name="stream"></param> 327 /// <param name="stream"></param>
322 public void LoadFromStream(string filename, Stream stream) 328 public void LoadFromStream(string filename, Vector2 displacement, Stream stream)
323 { 329 {
324 foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) 330 foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
325 { 331 {
@@ -330,8 +336,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
330 try 336 try
331 { 337 {
332 ITerrainChannel channel = loader.Value.LoadStream(stream); 338 ITerrainChannel channel = loader.Value.LoadStream(stream);
333 m_scene.Heightmap = channel; 339 MergeTerrainIntoExisting(channel, displacement);
334 m_channel = channel;
335 UpdateRevertMap(); 340 UpdateRevertMap();
336 } 341 }
337 catch (NotImplementedException) 342 catch (NotImplementedException)
@@ -351,6 +356,33 @@ namespace OpenSim.Region.CoreModules.World.Terrain
351 throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename)); 356 throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename));
352 } 357 }
353 358
359 private void MergeTerrainIntoExisting(ITerrainChannel channel, Vector2 displacement)
360 {
361 if (displacement == Vector2.Zero)
362 {
363 // If there is no displacement, just use this channel as the new heightmap
364 m_scene.Heightmap = channel;
365 m_channel = channel;
366 }
367 else
368 {
369 // If there is a displacement, we copy the loaded heightmap into the overall region
370 for (int xx = 0; xx < channel.Width; xx++)
371 {
372 for (int yy = 0; yy < channel.Height; yy++)
373 {
374 int dispX = xx + (int)displacement.X;
375 int dispY = yy + (int)displacement.Y;
376 if (dispX >= 0 && dispX < m_channel.Width
377 && dispY >= 0 && dispY < m_channel.Height)
378 {
379 m_channel[dispX, dispY] = channel[xx, yy];
380 }
381 }
382 }
383 }
384 }
385
354 private static Stream URIFetch(Uri uri) 386 private static Stream URIFetch(Uri uri)
355 { 387 {
356 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); 388 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);