master
Christopher 2020-06-28 13:18:37 +02:00
parent 95e82ec081
commit b19562e033
1 changed files with 119 additions and 0 deletions

119
src/TextureFetcher.cs Normal file
View File

@ -0,0 +1,119 @@
using Mono.Addins;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
[assembly: Addin("TextureFetcher", "0.1")]
[assembly: AddinDependency("OpenSim.Region.Framework", OpenSim.VersionInfo.VersionNumber)]
namespace OpenSim.Modules.TextureFetcher
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RegionFullPerm")]
class TextureFetcher : INonSharedRegionModule
{
Scene m_scene = null;
public string Name
{
get { return "TextureFetcher"; }
}
public void AddRegion(Scene scene)
{
}
public void RemoveRegion(Scene scene)
{
}
public void Close()
{
}
public void Initialise(IConfigSource source)
{
}
public Type ReplaceableInterface
{
get { return null; }
}
public void RegionLoaded(Scene scene)
{
scene.EventManager.OnObjectAddedToScene += AddObject;
scene.EventManager.OnSceneObjectLoaded += AddObject;
scene.EventManager.OnIncomingSceneObject += AddObject;
scene.EventManager.OnSceneObjectPartUpdated += UpdateObject;
scene.EventManager.OnSceneObjectPartCopy += CopyObject;
}
private void CopyObject(SceneObjectPart copy, SceneObjectPart original, bool userExposed)
{
copyTexturesToInventory(copy);
}
private void UpdateObject(SceneObjectPart sop, bool full)
{
copyTexturesToInventory(sop);
}
private void AddObject(SceneObjectGroup obj)
{
foreach(SceneObjectPart _part in obj.Parts)
copyTexturesToInventory(_part);
}
private void copyTexturesToInventory(SceneObjectPart part)
{
if (part.ParentGroup.IsAttachment)
return;
List<UUID> allTextures = new List<UUID>();
List<TaskInventoryItem> inventoryItems = new List<TaskInventoryItem>();
//Get all Textures from the scene object
Primitive.TextureEntry textures = part.Shape.Textures;
int allSides = part.GetNumberOfSides();
for (uint i = 0; i < allSides; i++)
if (textures.FaceTextures[i] != null)
allTextures.Add(textures.FaceTextures[i].TextureID);
//Convert texture uuid list to inventar items.
foreach (UUID texture in allTextures)
{
TaskInventoryItem item = new TaskInventoryItem();
item.AssetID = texture;
item.OwnerID = part.OwnerID;
item.CurrentPermissions = 581639;
item.Name = "tf-" + texture.ToString();
item.Description = "This item was generated by the texture fetcher module.";
item.OwnerID = part.OwnerID;
item.CreatorID = part.OwnerID;
item.LastOwnerID = part.OwnerID;
inventoryItems.Add(item);
}
//Check if the item is allready in the inventory and then add it.
List<UUID> inventarContend = part.Inventory.GetInventoryList();
bool updateNeeded = false;
foreach (TaskInventoryItem item in inventoryItems)
{
if(!inventarContend.Contains(item.AssetID))
{
updateNeeded = true;
part.Inventory.AddInventoryItem(item, false);
}
}
if(updateNeeded == true)
part.SendFullUpdateToAllClients();
}
}
}