* Implements IGraphics interface for MRM Scripting.

* This allows you to utilize System.Drawing tools on textures within the region.
* Example: use System.Drawing.Bitmap to make your texture, then use Host.Graphics.SaveBitmap to make an asset from it in JPEG2K. You can edit (but not overwrite) existing textures using Host.Graphics.LoadBitmap.
0.6.5-rc1
Adam Frisby 2009-04-09 14:19:49 +00:00
parent 98eda9ebdb
commit c77e7fce9e
6 changed files with 75 additions and 6 deletions

View File

@ -0,0 +1,48 @@
using System.Drawing;
using OpenMetaverse;
using OpenMetaverse.Imaging;
using OpenSim.Framework;
using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
class Graphics : IGraphics
{
private readonly Scene m_scene;
public Graphics(Scene m_scene)
{
this.m_scene = m_scene;
}
public UUID SaveBitmap(Bitmap data)
{
return SaveBitmap(data, false, true);
}
public UUID SaveBitmap(Bitmap data, bool lossless, bool temporary)
{
AssetBase asset = new AssetBase();
asset.FullID = UUID.Random();
asset.Data = OpenJPEG.EncodeFromImage(data, lossless);
asset.Name = "MRMDynamicImage" + Util.RandomClass.Next(1, 10000);
asset.Type = 0;
asset.Description = "MRM Image";
asset.Local = false;
asset.Temporary = temporary;
m_scene.CommsManager.AssetCache.AddAsset(asset);
return asset.FullID;
}
public Bitmap LoadBitmap(UUID assetID)
{
AssetBase bmp = m_scene.CommsManager.AssetCache.GetAsset(assetID, true);
ManagedImage outimg;
Image img;
OpenJPEG.DecodeToImage(bmp.Data, out outimg, out img);
return new Bitmap(img);
}
}
}

View File

@ -27,6 +27,7 @@
using System.Reflection;
using log4net;
using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
@ -34,10 +35,15 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
private readonly IObject m_obj;
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private readonly IGraphics m_graphics;
private Scene m_scene;
public Host(IObject m_obj)
public Host(IObject m_obj, Scene m_scene)
{
this.m_obj = m_obj;
this.m_scene = m_scene;
m_graphics = new Graphics(m_scene);
}
public IObject Object
@ -49,5 +55,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
get { return m_log; }
}
public IGraphics Graphics
{
get { return m_graphics; }
}
}
}

View File

@ -0,0 +1,12 @@
using System.Drawing;
using OpenMetaverse;
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
public interface IGraphics
{
UUID SaveBitmap(Bitmap data);
UUID SaveBitmap(Bitmap data, bool lossless, bool temporary);
Bitmap LoadBitmap(UUID assetID);
}
}

View File

@ -36,5 +36,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
IObject Object { get; }
ILog Console { get; }
IGraphics Graphics { get; }
}
}

View File

@ -82,7 +82,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
m_log.Info("[MRM] Found C# MRM");
IWorld m_world = new World(m_scene);
IHost m_host = new Host(new SOPObject(m_scene, localID));
IHost m_host = new Host(new SOPObject(m_scene, localID), m_scene);
MRMBase mmb = (MRMBase)AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap(
CompileFromDotNetText(script, itemID.ToString()),

View File

@ -26,10 +26,7 @@
*/
using System.Collections.Generic;
using System.Reflection;
using log4net;
using OpenSim.Framework;
using OpenSim.Framework.Client;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
@ -159,7 +156,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
// Skip if other
}
void EventManager_OnChatFromClient(object sender, OpenSim.Framework.OSChatMessage chat)
void EventManager_OnChatFromClient(object sender, OSChatMessage chat)
{
if (_OnChat != null)
{