| 7 |
using ModularRex.RexNetwork; |
using ModularRex.RexNetwork; |
| 8 |
using Nini.Config; |
using Nini.Config; |
| 9 |
using OpenMetaverse; |
using OpenMetaverse; |
| 10 |
using OpenSim.Region.Environment.Interfaces; |
using OpenSim.Region.Framework.Interfaces; |
| 11 |
using OpenSim.Region.Environment.Scenes; |
using OpenSim.Region.Framework.Scenes; |
| 12 |
using OpenSim.Data.NHibernate; |
using OpenSim.Data.NHibernate; |
| 13 |
using OpenSim.Framework; |
using OpenSim.Framework; |
| 14 |
|
using ModularRex.NHibernate; |
| 15 |
|
using OpenSim.Framework.Communications.Cache; |
| 16 |
|
|
| 17 |
namespace ModularRex.RexParts |
namespace ModularRex.RexParts |
| 18 |
{ |
{ |
| 34 |
{ |
{ |
| 35 |
m_scenes.Add(scene); |
m_scenes.Add(scene); |
| 36 |
|
|
| 37 |
|
scene.RegisterModuleInterface<ModrexObjects>(this); |
| 38 |
scene.EventManager.OnClientConnect += EventManager_OnClientConnect; |
scene.EventManager.OnClientConnect += EventManager_OnClientConnect; |
| 39 |
scene.m_sceneGraph.OnObjectDuplicate += SceneGraph_OnObjectDuplicate; |
scene.SceneContents.OnObjectDuplicate += SceneGraph_OnObjectDuplicate; |
| 40 |
|
scene.SceneContents.OnObjectRemove += SceneGraph_OnObjectRemove; |
| 41 |
|
|
| 42 |
|
scene.AddCommand(this, "modreximport", "load 0.4 rex database <connstring>", "conn string example: SQLiteDialect;SQLite20Driver;Data Source=beneath_the_waves.db;Version=3", HandleLoadRexLegacyData); |
| 43 |
|
|
| 44 |
if (m_db == null) |
if (m_db == null) |
| 45 |
{ |
{ |
| 67 |
|
|
| 68 |
void EventManager_OnClientConnect(OpenSim.Framework.Client.IClientCore client) |
void EventManager_OnClientConnect(OpenSim.Framework.Client.IClientCore client) |
| 69 |
{ |
{ |
| 70 |
RexClientView rcv; |
RexClientViewBase rcv; |
| 71 |
if (client.TryGet(out rcv)) |
if (client.TryGet(out rcv)) |
| 72 |
{ |
{ |
| 73 |
rcv.OnRexObjectProperties += rcv_OnRexObjectProperties; |
rcv.OnRexObjectProperties += rcv_OnRexObjectProperties; |
| 74 |
|
rcv.OnPrimFreeData += rcv_OnPrimFreeData; |
| 75 |
//rcv.OnChatFromClient += rcv_OnChatFromClient; |
//rcv.OnChatFromClient += rcv_OnChatFromClient; |
| 76 |
|
|
| 77 |
// Send them the current Scene. |
// Send them the current Scene. |
| 79 |
} |
} |
| 80 |
} |
} |
| 81 |
|
|
| 82 |
|
private void rcv_OnPrimFreeData(IClientAPI sender, List<string> parameters) |
| 83 |
|
{ |
| 84 |
|
m_log.Info("[REXOBJS] Received Prim free data"); |
| 85 |
|
if (parameters.Count >= 2) |
| 86 |
|
{ |
| 87 |
|
UUID primID = new UUID(parameters[0]); |
| 88 |
|
string data = String.Empty; |
| 89 |
|
if(parameters.Count == 2) |
| 90 |
|
{ |
| 91 |
|
data = parameters[1]; |
| 92 |
|
}else |
| 93 |
|
{ |
| 94 |
|
for (int i = 1; i < parameters.Count; i++) |
| 95 |
|
{ |
| 96 |
|
data += parameters[i]; |
| 97 |
|
} |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
RexObjectProperties props = GetObject(primID); |
| 101 |
|
props.RexData = data; |
| 102 |
|
|
| 103 |
|
SendPrimFreeDataToAllUsers(primID, data); |
| 104 |
|
} |
| 105 |
|
else |
| 106 |
|
{ |
| 107 |
|
m_log.Warn("[REXOBJS] unexpected number of parameters"); |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
void SendPrimFreeDataToAllUsers(UUID id, string data) |
| 112 |
|
{ |
| 113 |
|
foreach (Scene scene in m_scenes) |
| 114 |
|
{ |
| 115 |
|
scene.ForEachScenePresence( |
| 116 |
|
delegate(ScenePresence avatar) |
| 117 |
|
{ |
| 118 |
|
RexClientViewBase rex; |
| 119 |
|
if (avatar.ClientView.TryGet(out rex)) |
| 120 |
|
{ |
| 121 |
|
rex.SendRexPrimFreeData(id, data); |
| 122 |
|
} |
| 123 |
|
}); |
| 124 |
|
} |
| 125 |
|
} |
| 126 |
|
|
| 127 |
void SceneGraph_OnObjectDuplicate(EntityBase original, EntityBase clone) |
void SceneGraph_OnObjectDuplicate(EntityBase original, EntityBase clone) |
| 128 |
{ |
{ |
| 129 |
RexObjectProperties origprops = GetObject(original.UUID); |
RexObjectProperties origprops = GetObject(original.UUID); |
| 132 |
cloneprops.SetRexPrimDataFromObject(origprops); |
cloneprops.SetRexPrimDataFromObject(origprops); |
| 133 |
} |
} |
| 134 |
|
|
| 135 |
|
void SceneGraph_OnObjectRemove(EntityBase obj) |
| 136 |
|
{ |
| 137 |
|
DeleteObject(obj.UUID); |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
//void rcv_OnChatFromClient(object sender, OpenSim.Framework.OSChatMessage e) |
//void rcv_OnChatFromClient(object sender, OpenSim.Framework.OSChatMessage e) |
| 142 |
//{ |
//{ |
| 143 |
// if (e.Message.StartsWith("/rexobj ")) |
// if (e.Message.StartsWith("/rexobj ")) |
| 160 |
scene.ForEachScenePresence( |
scene.ForEachScenePresence( |
| 161 |
delegate(ScenePresence avatar) |
delegate(ScenePresence avatar) |
| 162 |
{ |
{ |
| 163 |
RexClientView rex; |
RexClientViewBase rex; |
| 164 |
if (avatar.ClientView.TryGet(out rex)) |
if (avatar.ClientView.TryGet(out rex)) |
| 165 |
{ |
{ |
| 166 |
rex.SendRexObjectProperties(id,props); |
rex.SendRexObjectProperties(id,props); |
| 169 |
} |
} |
| 170 |
} |
} |
| 171 |
|
|
| 172 |
void SendAllPropertiesToUser(RexClientView user) |
private void SendPreloadAssetsToUser(RexClientViewBase user) |
| 173 |
|
{ |
| 174 |
|
try |
| 175 |
|
{ |
| 176 |
|
Scene ourScene = null; |
| 177 |
|
foreach (Scene s in m_scenes) |
| 178 |
|
{ |
| 179 |
|
if (user.Scene.RegionInfo.RegionHandle == s.RegionInfo.RegionHandle) |
| 180 |
|
ourScene = s; |
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
if (ourScene != null) |
| 184 |
|
{ |
| 185 |
|
if (ourScene.Modules.ContainsKey("RexAssetPreload")) |
| 186 |
{ |
{ |
| 187 |
|
RexAssetPreload module = (RexAssetPreload)ourScene.Modules["RexAssetPreload"]; |
| 188 |
|
if (module.PreloadAssetDictionary.Count > 0) |
| 189 |
|
{ |
| 190 |
|
user.SendRexPreloadAssets(module.PreloadAssetDictionary); |
| 191 |
|
} |
| 192 |
|
} |
| 193 |
|
} |
| 194 |
|
} |
| 195 |
|
catch (Exception e) |
| 196 |
|
{ |
| 197 |
|
m_log.Error("[MODREXOBJECTS]: Sending preload assets failed.", e); |
| 198 |
|
} |
| 199 |
|
} |
| 200 |
|
|
| 201 |
|
void SendAllPropertiesToUser(RexClientViewBase user) |
| 202 |
|
{ |
| 203 |
|
SendPreloadAssetsToUser(user); |
| 204 |
|
|
| 205 |
foreach (RexObjectProperties p in GetObjects()) |
foreach (RexObjectProperties p in GetObjects()) |
| 206 |
{ |
{ |
| 207 |
user.SendRexObjectProperties(p.ParentObjectID, p); |
user.SendRexObjectProperties(p.ParentObjectID, p); |
| 208 |
|
if (p.RexData.Length > 0) //send rex data also if exists |
| 209 |
|
{ |
| 210 |
|
user.SendRexPrimFreeData(p.ParentObjectID, p.RexData); |
| 211 |
|
} |
| 212 |
} |
} |
| 213 |
} |
} |
| 214 |
|
|
| 215 |
void rcv_OnRexObjectProperties(RexClientView sender, UUID id, RexObjectProperties props) |
void rcv_OnRexObjectProperties(IClientAPI sender, UUID id, RexObjectProperties props) |
| 216 |
{ |
{ |
| 217 |
m_log.Info("[REXOBJS] Received RexObjData for " + id); |
m_log.Info("[REXOBJS] Received RexObjData for " + id); |
| 218 |
if (props.ParentObjectID == UUID.Zero) |
if (props.ParentObjectID == UUID.Zero) |
| 274 |
return; |
return; |
| 275 |
} |
} |
| 276 |
|
|
| 277 |
if (sop.ParentGroup != null && sop.PhysActor != null) |
if (sop.ParentGroup != null && sop.PhysActor is IRexPhysicsActor) |
| 278 |
{ |
{ |
| 279 |
if (p.RexCollisionMeshUUID != UUID.Zero) |
if (p.RexCollisionMeshUUID != UUID.Zero) |
| 280 |
RexUpdateCollisionMesh(id); |
RexUpdateCollisionMesh(id); |
| 281 |
else |
else |
| 282 |
sop.PhysActor.SetCollisionMesh(null, "", false); |
((IRexPhysicsActor)sop.PhysActor).SetCollisionMesh(null, "", false); |
| 283 |
} |
} |
| 284 |
} |
} |
| 285 |
|
|
| 297 |
return; |
return; |
| 298 |
} |
} |
| 299 |
|
|
| 300 |
if (sop.ParentGroup != null && sop.PhysActor != null) |
if (sop.ParentGroup != null && sop.PhysActor is IRexPhysicsActor) |
| 301 |
{ |
{ |
| 302 |
sop.PhysActor.SetBoundsScaling(p.RexScaleToPrim); |
((IRexPhysicsActor)sop.PhysActor).SetBoundsScaling(p.RexScaleToPrim); |
| 303 |
sop.ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(sop.PhysActor); |
sop.ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(sop.PhysActor); |
| 304 |
} |
} |
| 305 |
} |
} |
| 336 |
return; |
return; |
| 337 |
} |
} |
| 338 |
|
|
| 339 |
if (p.RexCollisionMeshUUID != UUID.Zero && sop.PhysActor != null) |
if (p.RexCollisionMeshUUID != UUID.Zero && sop.PhysActor is IRexPhysicsActor) |
| 340 |
{ |
{ |
| 341 |
AssetBase tempmodel = sop.ParentGroup.Scene.AssetCache.GetAsset(p.RexCollisionMeshUUID, false); |
AssetBase tempmodel = sop.ParentGroup.Scene.AssetService.Get(p.RexCollisionMeshUUID.ToString()); |
| 342 |
if (tempmodel != null) |
if (tempmodel != null) |
| 343 |
sop.PhysActor.SetCollisionMesh(tempmodel.Data, tempmodel.Metadata.Name, p.RexScaleToPrim); |
((IRexPhysicsActor)sop.PhysActor).SetCollisionMesh(tempmodel.Data, tempmodel.Name, p.RexScaleToPrim); |
| 344 |
} |
} |
| 345 |
} |
} |
| 346 |
|
|
| 347 |
|
public byte GetAssetType(UUID assetid) |
| 348 |
|
{ |
| 349 |
|
AssetBase tempmodel = m_scenes[0].AssetService.Get(assetid.ToString()); |
| 350 |
|
if (tempmodel == null) |
| 351 |
|
m_scenes[0].AssetService.Get(assetid.ToString()); |
| 352 |
|
|
| 353 |
|
if (tempmodel != null) |
| 354 |
|
return(byte)(tempmodel.Type); |
| 355 |
|
else |
| 356 |
|
return 0; |
| 357 |
|
} |
| 358 |
#endregion |
#endregion |
| 359 |
|
|
| 360 |
|
|
| 407 |
RexObjectProperties props = RexObjectPropertiesCache[id]; |
RexObjectProperties props = RexObjectPropertiesCache[id]; |
| 408 |
if (props == null) |
if (props == null) |
| 409 |
{ |
{ |
| 410 |
|
//Objects that are not in the scene can't be found from cache. |
| 411 |
|
//So before we create new properties, we try to find them from db |
| 412 |
|
props = m_db.LoadObject(id); |
| 413 |
|
if (props == null) |
| 414 |
|
{ |
| 415 |
props = new RexObjectProperties(id, this); |
props = new RexObjectProperties(id, this); |
| 416 |
|
} |
| 417 |
RexObjectPropertiesCache.Add(id, props); |
RexObjectPropertiesCache.Add(id, props); |
| 418 |
} |
} |
| 419 |
return props; |
return props; |
| 429 |
if (RexObjectPropertiesCache.ContainsKey(id)) |
if (RexObjectPropertiesCache.ContainsKey(id)) |
| 430 |
{ |
{ |
| 431 |
RexObjectPropertiesCache.Remove(id); |
RexObjectPropertiesCache.Remove(id); |
| 432 |
|
m_db.RemoveObject(id); |
| 433 |
return true; |
return true; |
| 434 |
} |
} |
| 435 |
return false; |
return false; |
| 436 |
} |
} |
| 437 |
|
|
|
|
|
| 438 |
#endregion |
#endregion |
| 439 |
|
|
| 440 |
|
|
| 441 |
|
public void HandleLoadRexLegacyData(string module, string[] args) |
| 442 |
|
{ |
| 443 |
|
NHibernateRexLegacyData legacydata = new NHibernateRexLegacyData(); |
| 444 |
|
|
| 445 |
|
legacydata.Initialise(args[1]); |
| 446 |
|
if(!legacydata.Inizialized) |
| 447 |
|
{ |
| 448 |
|
m_log.Info("[MODREXOBJECTS]: Legacy database failed to initialize."); |
| 449 |
|
return; |
| 450 |
|
} |
| 451 |
|
|
| 452 |
|
List<RexLegacyPrimData> rexprimdata = legacydata.LoadAllRexPrimData(); |
| 453 |
|
m_log.Info("[MODREXOBJECTS]: Legacy rexprimdata objects loaded:" + rexprimdata.Count.ToString()); |
| 454 |
|
|
| 455 |
|
List<RexLegacyPrimMaterialData> rexprimmaterialdata = legacydata.LoadAllRexPrimMaterialData(); |
| 456 |
|
m_log.Info("[MODREXOBJECTS]: Legacy rexprimmaterialdata objects loaded:" + rexprimmaterialdata.Count.ToString()); |
| 457 |
|
|
| 458 |
|
foreach (RexLegacyPrimData prim in rexprimdata) |
| 459 |
|
{ |
| 460 |
|
RexObjectProperties p = GetObject(prim.UUID); |
| 461 |
|
p.SetRexPrimDataFromLegacyData(prim); |
| 462 |
|
} |
| 463 |
|
|
| 464 |
|
foreach (RexLegacyPrimMaterialData primmat in rexprimmaterialdata) |
| 465 |
|
{ |
| 466 |
|
RexObjectProperties p = GetObject(primmat.UUID); |
| 467 |
|
p.RexMaterials.AddMaterial((uint)primmat.MaterialIndex,primmat.MaterialUUID); |
| 468 |
|
} |
| 469 |
|
} |
| 470 |
|
|
| 471 |
} |
} |
| 472 |
} |
} |