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
varregion
Robert Adams 2014-01-19 10:09:43 -08:00
parent f127e4b4ee
commit dd6db72939
8 changed files with 91 additions and 20 deletions

View File

@ -1484,8 +1484,9 @@ namespace OpenSim.ApplicationPlugins.RemoteController
}
IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
Vector3 displacement = new Vector3(0f, 0f, 0f);
if (archiver != null)
archiver.DearchiveRegion(filename, mergeOar, skipAssets, Guid.Empty);
archiver.DearchiveRegion(filename, mergeOar, skipAssets, displacement, Guid.Empty);
else
throw new Exception("Archiver module not present for scene");

View File

@ -266,10 +266,11 @@ namespace OpenSim
SavePrimsXml2);
m_console.Commands.AddCommand("Archiving", false, "load oar",
"load oar [--merge] [--skip-assets] [<OAR path>]",
"load oar [--merge] [--skip-assets] [--displacement \"<x,y,z>\"] [<OAR path>]",
"Load a region's data from an OAR archive.",
"--merge will merge the OAR with the existing scene." + Environment.NewLine
+ "--skip-assets will load the OAR but ignore the assets it contains." + Environment.NewLine
+ "--skip-assets will load the OAR but ignore the assets it contains." + Environment.NewLine
+ "--displacement will add this value to the position of every object loaded" + Environment.NewLine
+ "The path can be either a filesystem location or a URI."
+ " If this is not given then the command looks for an OAR named region.oar in the current directory.",
LoadOar);

View File

@ -104,6 +104,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
/// </value>
protected bool m_skipAssets;
/// <value>
/// Displacement added to each object as it is added to the world
/// </value>
protected Vector3 m_displacement = new Vector3(0f, 0f, 0f);
/// <summary>
/// Used to cache lookups for valid uuids.
/// </summary>
@ -132,7 +137,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
private IAssetService m_assetService = null;
public ArchiveReadRequest(Scene scene, string loadPath, bool merge, bool skipAssets, Guid requestId)
public ArchiveReadRequest(Scene scene, string loadPath, bool merge, bool skipAssets, Vector3 displacement, Guid requestId)
{
m_rootScene = scene;
@ -153,6 +158,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
m_merge = merge;
m_skipAssets = skipAssets;
m_requestId = requestId;
m_displacement = displacement;
// Zero can never be a valid user id
m_validUserUuids[UUID.Zero] = false;
@ -445,6 +451,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver
SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject);
// Happily this does not do much to the object since it hasn't been added to the scene yet
sceneObject.AbsolutePosition += m_displacement;
bool isTelehub = (sceneObject.UUID == oldTelehubUUID) && (oldTelehubUUID != UUID.Zero);
// For now, give all incoming scene objects new uuids. This will allow scenes to be cloned
@ -809,7 +819,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver
ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>();
MemoryStream ms = new MemoryStream(data);
terrainModule.LoadFromStream(terrainPath, ms);
if (m_displacement != Vector3.Zero)
{
Vector2 terrainDisplacement = new Vector2(m_displacement.X, m_displacement.Y);
terrainModule.LoadFromStream(terrainPath, terrainDisplacement, ms);
}
else
{
terrainModule.LoadFromStream(terrainPath, ms);
}
ms.Close();
m_log.DebugFormat("[ARCHIVER]: Restored terrain {0}", terrainPath);

View File

@ -33,11 +33,14 @@ using log4net;
using NDesk.Options;
using Nini.Config;
using Mono.Addins;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenMetaverse;
namespace OpenSim.Region.CoreModules.World.Archiver
{
/// <summary>
@ -101,9 +104,22 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{
bool mergeOar = false;
bool skipAssets = false;
Vector3 displacement = new Vector3(0f, 0f, 0f);
OptionSet options = new OptionSet().Add("m|merge", delegate (string v) { mergeOar = v != null; });
options.Add("s|skip-assets", delegate (string v) { skipAssets = v != null; });
OptionSet options = new OptionSet();
options.Add("m|merge", delegate (string v) { mergeOar = (v != null); });
options.Add("s|skip-assets", delegate (string v) { skipAssets = (v != null); });
options.Add("displacement=", delegate (string v) {
try
{
displacement = v == null ? new Vector3(0f, 0f, 0f) : Vector3.Parse(v);
}
catch (Exception e)
{
m_log.ErrorFormat("[ARCHIVER MODULE] failure parsing displacement");
displacement = new Vector3(0f, 0f, 0f);
}
});
// Send a message to the region ready module
/* bluewall* Disable this for the time being
@ -124,11 +140,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
if (mainParams.Count > 2)
{
DearchiveRegion(mainParams[2], mergeOar, skipAssets, Guid.Empty);
DearchiveRegion(mainParams[2], mergeOar, skipAssets, displacement, Guid.Empty);
}
else
{
DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, mergeOar, skipAssets, Guid.Empty);
DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, mergeOar, skipAssets, displacement, Guid.Empty);
}
}
@ -198,23 +214,23 @@ namespace OpenSim.Region.CoreModules.World.Archiver
public void DearchiveRegion(string loadPath)
{
DearchiveRegion(loadPath, false, false, Guid.Empty);
DearchiveRegion(loadPath, false, false, new Vector3(0f, 0f, 0f), Guid.Empty);
}
public void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId)
public void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Vector3 displacement, Guid requestId)
{
m_log.InfoFormat(
"[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath);
new ArchiveReadRequest(Scene, loadPath, merge, skipAssets, requestId).DearchiveRegion();
new ArchiveReadRequest(Scene, loadPath, merge, skipAssets, displacement, requestId).DearchiveRegion();
}
public void DearchiveRegion(Stream loadStream)
{
DearchiveRegion(loadStream, false, false, Guid.Empty);
DearchiveRegion(loadStream, false, false, new Vector3(0f, 0f, 0f), Guid.Empty);
}
public void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId)
public void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Vector3 displacement, Guid requestId)
{
new ArchiveReadRequest(Scene, loadStream, merge, skipAssets, requestId).DearchiveRegion();
}

View File

@ -752,7 +752,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
byte[] archive = archiveWriteStream.ToArray();
MemoryStream archiveReadStream = new MemoryStream(archive);
m_archiverModule.DearchiveRegion(archiveReadStream, true, false, Guid.Empty);
m_archiverModule.DearchiveRegion(archiveReadStream, true, false, new Vector3(0f, 0f, 0f), Guid.Empty);
SceneObjectPart object1Existing = m_scene.GetSceneObjectPart(part1.Name);
Assert.That(object1Existing, Is.Not.Null, "object1 was not present after merge");

View File

@ -314,12 +314,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain
LoadFromStream(filename, URIFetch(pathToTerrainHeightmap));
}
public void LoadFromStream(string filename, Stream stream)
{
Vector2 defaultDisplacement = new Vector2(0f, 0f);
LoadFromStream(filename, defaultDisplacement, stream);
}
/// <summary>
/// Loads a terrain file from a stream and installs it in the scene.
/// </summary>
/// <param name="filename">Filename to terrain file. Type is determined by extension.</param>
/// <param name="stream"></param>
public void LoadFromStream(string filename, Stream stream)
public void LoadFromStream(string filename, Vector2 displacement, Stream stream)
{
foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
{
@ -330,8 +336,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
try
{
ITerrainChannel channel = loader.Value.LoadStream(stream);
m_scene.Heightmap = channel;
m_channel = channel;
MergeTerrainIntoExisting(channel, displacement);
UpdateRevertMap();
}
catch (NotImplementedException)
@ -351,6 +356,33 @@ 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 void MergeTerrainIntoExisting(ITerrainChannel channel, Vector2 displacement)
{
if (displacement == Vector2.Zero)
{
// If there is no displacement, just use this channel as the new heightmap
m_scene.Heightmap = channel;
m_channel = channel;
}
else
{
// If there is a displacement, we copy the loaded heightmap into the overall region
for (int xx = 0; xx < channel.Width; xx++)
{
for (int yy = 0; yy < channel.Height; yy++)
{
int dispX = xx + (int)displacement.X;
int dispY = yy + (int)displacement.Y;
if (dispX >= 0 && dispX < m_channel.Width
&& dispY >= 0 && dispY < m_channel.Height)
{
m_channel[dispX, dispY] = channel[xx, yy];
}
}
}
}
}
private static Stream URIFetch(Uri uri)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

View File

@ -29,6 +29,8 @@ using System;
using System.Collections.Generic;
using System.IO;
using OpenMetaverse;
namespace OpenSim.Region.Framework.Interfaces
{
/// <summary>
@ -109,7 +111,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// assets are already known to be present in the grid's asset service.
/// </param>
/// <param name="requestId">If supplied, this request Id is later returned in the saved event</param>
void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId);
void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Vector3 displacement, Guid requestId);
/// <summary>
/// Dearchive a region from a stream. This replaces the existing scene.
@ -136,6 +138,6 @@ namespace OpenSim.Region.Framework.Interfaces
/// assets are already known to be present in the grid's asset service.
/// </param
/// <param name="requestId">If supplied, this request Id is later returned in the saved event</param>
void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId);
void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Vector3 displacement, Guid requestId);
}
}

View File

@ -51,6 +51,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// </param>
/// <param name="stream"></param>
void LoadFromStream(string filename, Stream stream);
void LoadFromStream(string filename, Vector2 displacement, Stream stream);
void LoadFromStream(string filename, System.Uri pathToTerrainHeightmap);
/// <summary>
/// Save a terrain to a stream.