| 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 |
|
|
| 15 |
namespace ModularRex.RexParts |
namespace ModularRex.RexParts |
| 16 |
{ |
{ |
| 17 |
public class ModrexObjects : IRegionModule |
public class ModrexObjects : IRegionModule, IRexObjectPropertiesEventManager |
| 18 |
{ |
{ |
| 19 |
private static readonly ILog m_log = |
private static readonly ILog m_log = |
| 20 |
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
| 21 |
|
|
| 22 |
//private Dictionary<UUID,RexObjectProperties> m_objs = new Dictionary<UUID, RexObjectProperties>(); |
private RexObjectPropertiesManager RexObjectPropertiesCache = new RexObjectPropertiesManager(); |
| 23 |
private List<Scene> m_scenes = new List<Scene>(); |
private List<Scene> m_scenes = new List<Scene>(); |
| 24 |
|
|
| 25 |
private NHibernateRexObjectData m_db; |
private NHibernateRexObjectData m_db; |
| 26 |
private string m_db_connectionstring; |
private string m_db_connectionstring; |
| 27 |
|
|
| 28 |
|
public delegate void OnChangePythonClassDelegate(UUID id); |
| 29 |
public event OnChangePythonClassDelegate OnPythonClassChange; |
public event OnChangePythonClassDelegate OnPythonClassChange; |
| 30 |
|
|
| 31 |
public void Initialise(Scene scene, IConfigSource source) |
public void Initialise(Scene scene, IConfigSource source) |
| 33 |
m_scenes.Add(scene); |
m_scenes.Add(scene); |
| 34 |
|
|
| 35 |
scene.EventManager.OnClientConnect += EventManager_OnClientConnect; |
scene.EventManager.OnClientConnect += EventManager_OnClientConnect; |
| 36 |
|
scene.m_sceneGraph.OnObjectDuplicate += SceneGraph_OnObjectDuplicate; |
| 37 |
|
scene.m_sceneGraph.OnObjectRemove += SceneGraph_OnObjectRemove; |
| 38 |
|
|
| 39 |
|
|
| 40 |
if (m_db == null) |
if (m_db == null) |
| 74 |
} |
} |
| 75 |
} |
} |
| 76 |
|
|
| 77 |
|
void SceneGraph_OnObjectDuplicate(EntityBase original, EntityBase clone) |
| 78 |
|
{ |
| 79 |
|
RexObjectProperties origprops = GetObject(original.UUID); |
| 80 |
|
RexObjectProperties cloneprops = GetObject(clone.UUID); |
| 81 |
|
|
| 82 |
|
cloneprops.SetRexPrimDataFromObject(origprops); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
void SceneGraph_OnObjectRemove(EntityBase obj) |
| 86 |
|
{ |
| 87 |
|
DeleteObject(obj.UUID); |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
|
| 91 |
//void rcv_OnChatFromClient(object sender, OpenSim.Framework.OSChatMessage e) |
//void rcv_OnChatFromClient(object sender, OpenSim.Framework.OSChatMessage e) |
| 92 |
//{ |
//{ |
| 93 |
// if (e.Message.StartsWith("/rexobj ")) |
// if (e.Message.StartsWith("/rexobj ")) |
| 119 |
} |
} |
| 120 |
} |
} |
| 121 |
|
|
| 122 |
void SendAllPropertiesToUser(RexClientView user) |
private void SendPreloadAssetsToUser(RexClientView user) |
| 123 |
{ |
{ |
| 124 |
if (m_db.Inizialized) |
try |
| 125 |
{ |
{ |
| 126 |
|
Scene ourScene = null; |
| 127 |
foreach (Scene s in m_scenes) |
foreach (Scene s in m_scenes) |
| 128 |
{ |
{ |
| 129 |
foreach (EntityBase e in s.Entities) |
if (user.Scene.RegionInfo.RegionHandle == s.RegionInfo.RegionHandle) |
| 130 |
|
ourScene = s; |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
if (ourScene != null) |
| 134 |
{ |
{ |
| 135 |
RexObjectProperties p = m_db.LoadObject(e.UUID); |
if (ourScene.Modules.ContainsKey("RexAssetPreload")) |
|
if (p != null) |
|
| 136 |
{ |
{ |
| 137 |
user.SendRexObjectProperties(e.UUID, p); |
RexAssetPreload module = (RexAssetPreload)ourScene.Modules["RexAssetPreload"]; |
| 138 |
//p.OnPythonClassChange += PythonClassNameChanged; |
if (module.PreloadAssetDictionary.Count > 0) |
|
if (p.RexClassName.Length > 0) |
|
| 139 |
{ |
{ |
| 140 |
s.GetSceneObjectPart(e.UUID).SetScriptEvents(e.UUID, (int)scriptEvents.touch_start); |
user.SendRexPreloadAssets(module.PreloadAssetDictionary); |
| 141 |
} |
} |
| 142 |
} |
} |
| 143 |
} |
} |
| 144 |
} |
} |
| 145 |
|
catch (Exception e) |
| 146 |
|
{ |
| 147 |
|
m_log.Error("[MODREXOBJECTS]: Sending preload assets failed.", e); |
| 148 |
} |
} |
| 149 |
} |
} |
| 150 |
|
|
| 151 |
private void PythonClassNameChanged(UUID id) |
void SendAllPropertiesToUser(RexClientView user) |
| 152 |
{ |
{ |
| 153 |
if (OnPythonClassChange != null) |
SendPreloadAssetsToUser(user); |
| 154 |
|
|
| 155 |
|
foreach (RexObjectProperties p in GetObjects()) |
| 156 |
{ |
{ |
| 157 |
OnPythonClassChange(id); |
user.SendRexObjectProperties(p.ParentObjectID, p); |
| 158 |
} |
} |
| 159 |
} |
} |
| 160 |
|
|
| 164 |
if (props.ParentObjectID == UUID.Zero) |
if (props.ParentObjectID == UUID.Zero) |
| 165 |
props.ParentObjectID = id; |
props.ParentObjectID = id; |
| 166 |
|
|
| 167 |
props.PrintRexPrimdata(); // fixme, debugdata |
// debugdata props.PrintRexPrimdata(); |
|
|
|
|
// Before saving to db, check if values have changed from the previous values. |
|
|
RexObjectProperties oldprops = Load(id); |
|
|
|
|
|
m_db.StoreObject(props); |
|
|
|
|
|
// Compare values |
|
|
if (oldprops.RexClassName != props.RexClassName) |
|
|
PythonClassNameChanged(props.ParentObjectID); |
|
|
if (oldprops.RexScaleToPrim != props.RexScaleToPrim) |
|
|
ScaleToPrimChanged(id); |
|
|
if (oldprops.RexCollisionMeshUUID != props.RexCollisionMeshUUID) |
|
|
CollisionMeshChanged(id); |
|
| 168 |
|
|
| 169 |
SendPropertiesToAllUsers(id, props); |
RexObjectProperties currentprops = GetObject(id); |
| 170 |
|
currentprops.SetRexPrimDataFromObject(props); |
| 171 |
} |
} |
| 172 |
|
|
| 173 |
public void PostInitialise() |
public void PostInitialise() |
| 179 |
m_db.Initialise(m_db_connectionstring); |
m_db.Initialise(m_db_connectionstring); |
| 180 |
} |
} |
| 181 |
} |
} |
| 182 |
|
LoadRexObjectPropertiesToCache(); |
| 183 |
} |
} |
| 184 |
|
|
| 185 |
public void Close() |
public void Close() |
| 197 |
get { return true; } |
get { return true; } |
| 198 |
} |
} |
| 199 |
|
|
|
public RexObjectProperties Load(UUID id) |
|
|
{ |
|
|
RexObjectProperties robject = m_db.LoadObject(id); |
|
|
if (robject == null) |
|
|
{ |
|
|
robject = new RexObjectProperties(); |
|
|
robject.ParentObjectID = id; |
|
|
} |
|
|
return robject; |
|
|
} |
|
| 200 |
|
|
| 201 |
public void Save(RexObjectProperties obj) |
|
| 202 |
|
#region Trigger/handle rexobjectproperties events |
| 203 |
|
public void TriggerOnChangePythonClass(UUID id) |
| 204 |
{ |
{ |
| 205 |
m_db.StoreObject(obj); |
if (OnPythonClassChange != null) |
| 206 |
|
OnPythonClassChange(id); |
| 207 |
} |
} |
| 208 |
|
|
| 209 |
private void CollisionMeshChanged(UUID id) |
public void TriggerOnChangeCollisionMesh(UUID id) |
| 210 |
{ |
{ |
| 211 |
// tucofixme, add |
// tucofixme, add |
| 212 |
//if (!GlobalSettings.Instance.m_3d_collision_models) |
//if (!GlobalSettings.Instance.m_3d_collision_models) |
| 213 |
// return; |
// return; |
| 214 |
|
|
| 215 |
RexObjectProperties p = m_db.LoadObject(id); |
RexObjectProperties p = GetObject(id); |
|
if (p == null) |
|
|
{ |
|
|
m_log.Error("[REXOBJS] CollisionMeshChanged, no RexObjectProperties for id:" + id.ToString()); |
|
|
return; |
|
|
} |
|
|
|
|
| 216 |
SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); |
SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); |
| 217 |
if (sop == null) |
if (sop == null) |
| 218 |
{ |
{ |
| 219 |
m_log.Error("[REXOBJS] CollisionMeshChanged, no SceneObjectPart for id:" + id.ToString()); |
m_log.Error("[REXOBJS] TriggerOnChangeCollisionMesh, no SceneObjectPart for id:" + id.ToString()); |
| 220 |
return; |
return; |
| 221 |
} |
} |
| 222 |
|
|
| 223 |
if (sop.ParentGroup != null) |
if (sop.ParentGroup != null && sop.PhysActor is IRexPhysicsActor) |
|
{ |
|
|
if (sop.PhysActor != null) |
|
| 224 |
{ |
{ |
| 225 |
if (p.RexCollisionMeshUUID != UUID.Zero) |
if (p.RexCollisionMeshUUID != UUID.Zero) |
| 226 |
RexUpdateCollisionMesh(id); |
RexUpdateCollisionMesh(id); |
| 227 |
else |
else |
| 228 |
sop.PhysActor.SetCollisionMesh(null, "", false); |
((IRexPhysicsActor)sop.PhysActor).SetCollisionMesh(null, "", false); |
|
} |
|
| 229 |
} |
} |
| 230 |
} |
} |
| 231 |
|
|
| 232 |
private void ScaleToPrimChanged(UUID id) |
public void TriggerOnChangeScaleToPrim(UUID id) |
| 233 |
{ |
{ |
| 234 |
// tucofixme, add |
// tucofixme, add |
| 235 |
//if (!GlobalSettings.Instance.m_3d_collision_models) |
//if (!GlobalSettings.Instance.m_3d_collision_models) |
| 236 |
// return; |
// return; |
| 237 |
|
|
| 238 |
RexObjectProperties p = m_db.LoadObject(id); |
RexObjectProperties p = GetObject(id); |
|
if(p == null) |
|
|
{ |
|
|
m_log.Error("[REXOBJS] ScaleToPrimChanged, no RexObjectProperties for id:" + id.ToString()); |
|
|
return; |
|
|
} |
|
|
|
|
| 239 |
SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); |
SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); |
| 240 |
if (sop == null) |
if (sop == null) |
| 241 |
{ |
{ |
| 242 |
m_log.Error("[REXOBJS] ScaleToPrimChanged, no SceneObjectPart for id:" + id.ToString()); |
m_log.Error("[REXOBJS] TriggerOnChangeScaleToPrim, no SceneObjectPart for id:" + id.ToString()); |
| 243 |
return; |
return; |
| 244 |
} |
} |
| 245 |
|
|
| 246 |
if (sop.ParentGroup != null) |
if (sop.ParentGroup != null && sop.PhysActor is IRexPhysicsActor) |
| 247 |
{ |
{ |
| 248 |
if (sop.PhysActor != null) |
((IRexPhysicsActor)sop.PhysActor).SetBoundsScaling(p.RexScaleToPrim); |
|
{ |
|
|
sop.PhysActor.SetBoundsScaling(p.RexScaleToPrim); |
|
| 249 |
sop.ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(sop.PhysActor); |
sop.ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(sop.PhysActor); |
| 250 |
} |
} |
| 251 |
} |
} |
| 252 |
|
|
| 253 |
|
public void TriggerOnChangeRexObjectProperties(UUID id) |
| 254 |
|
{ |
| 255 |
|
RexObjectProperties props = GetObject(id); |
| 256 |
|
|
| 257 |
|
m_db.StoreObject(props); |
| 258 |
|
SendPropertiesToAllUsers(id,props); |
| 259 |
|
} |
| 260 |
|
|
| 261 |
|
public void TriggerOnChangeRexObjectMetaData(UUID id) |
| 262 |
|
{ |
| 263 |
|
RexObjectProperties props = GetObject(id); |
| 264 |
|
|
| 265 |
|
m_db.StoreObject(props); |
| 266 |
|
// tucofixme, send metadata to all users |
| 267 |
} |
} |
| 268 |
|
|
| 269 |
|
|
| 270 |
|
|
| 271 |
public void RexUpdateCollisionMesh(UUID id) |
public void RexUpdateCollisionMesh(UUID id) |
| 272 |
{ |
{ |
| 273 |
// tucofixme |
// tucofixme, add |
| 274 |
//if (!GlobalSettings.Instance.m_3d_collision_models) |
//if (!GlobalSettings.Instance.m_3d_collision_models) |
| 275 |
// return; |
// return; |
| 276 |
|
|
| 277 |
RexObjectProperties p = m_db.LoadObject(id); |
RexObjectProperties p = GetObject(id); |
|
if (p == null) |
|
|
{ |
|
|
m_log.Error("[REXOBJS] RexUpdateCollisionMesh, no RexObjectProperties for id:" + id.ToString()); |
|
|
return; |
|
|
} |
|
|
|
|
| 278 |
SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); |
SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); |
| 279 |
if (sop == null) |
if (sop == null) |
| 280 |
{ |
{ |
| 282 |
return; |
return; |
| 283 |
} |
} |
| 284 |
|
|
| 285 |
if (p.RexCollisionMeshUUID != UUID.Zero && sop.PhysActor != null) |
if (p.RexCollisionMeshUUID != UUID.Zero && sop.PhysActor is IRexPhysicsActor) |
| 286 |
{ |
{ |
| 287 |
AssetBase tempmodel = sop.ParentGroup.Scene.AssetCache.GetAsset(p.RexCollisionMeshUUID,false); |
AssetBase tempmodel = sop.ParentGroup.Scene.AssetCache.GetAsset(p.RexCollisionMeshUUID,false); |
| 288 |
if (tempmodel != null) |
if (tempmodel != null) |
| 289 |
sop.PhysActor.SetCollisionMesh(tempmodel.Data, tempmodel.Metadata.Name, p.RexScaleToPrim); |
((IRexPhysicsActor)sop.PhysActor).SetCollisionMesh(tempmodel.Data, tempmodel.Metadata.Name, p.RexScaleToPrim); |
| 290 |
} |
} |
| 291 |
} |
} |
| 292 |
|
|
| 293 |
|
public byte GetAssetType(UUID assetid) |
| 294 |
|
{ |
| 295 |
|
AssetBase tempmodel = m_scenes[0].AssetCache.GetAsset(assetid, true); |
| 296 |
|
if (tempmodel == null) |
| 297 |
|
m_scenes[0].AssetCache.GetAsset(assetid, false); |
| 298 |
|
|
| 299 |
|
if (tempmodel != null) |
| 300 |
|
return(byte)(tempmodel.Metadata.Type); |
| 301 |
|
else |
| 302 |
|
return 0; |
| 303 |
|
} |
| 304 |
|
#endregion |
| 305 |
|
|
| 306 |
|
|
| 307 |
|
#region RexObjectProperties Cache |
| 308 |
|
|
| 309 |
|
private void LoadRexObjectPropertiesToCache() |
| 310 |
|
{ |
| 311 |
|
if (!m_db.Inizialized) |
| 312 |
|
{ |
| 313 |
|
m_log.ErrorFormat("LoadRexObjectPropertiesToCache failed, db not initialized"); |
| 314 |
|
return; |
| 315 |
|
} |
| 316 |
|
|
| 317 |
|
foreach (Scene s in m_scenes) |
| 318 |
|
{ |
| 319 |
|
foreach (EntityBase e in s.Entities) |
| 320 |
|
{ |
| 321 |
|
RexObjectProperties p = LoadObject(e.UUID); |
| 322 |
|
p.ParentObjectID = e.UUID; |
| 323 |
|
p.SetRexEventManager(this); |
| 324 |
|
RexObjectPropertiesCache.Add(e.UUID,p); |
| 325 |
|
|
| 326 |
|
// Since loaded objects have their properties already set, any initialization that needs to be done should be here. |
| 327 |
|
if(p.RexCollisionMeshUUID != UUID.Zero) |
| 328 |
|
TriggerOnChangeCollisionMesh(e.UUID); |
| 329 |
|
|
| 330 |
|
if (p.RexClassName.Length > 0) |
| 331 |
|
{ |
| 332 |
|
SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(p.ParentObjectID); |
| 333 |
|
if (sop != null) |
| 334 |
|
sop.SetScriptEvents(p.ParentObjectID, (int)scriptEvents.touch_start); |
| 335 |
|
} |
| 336 |
|
} |
| 337 |
|
} |
| 338 |
|
} |
| 339 |
|
|
| 340 |
|
private RexObjectProperties LoadObject(UUID id) |
| 341 |
|
{ |
| 342 |
|
RexObjectProperties robject = m_db.LoadObject(id); |
| 343 |
|
if (robject == null) |
| 344 |
|
{ |
| 345 |
|
robject = new RexObjectProperties(); |
| 346 |
|
robject.ParentObjectID = id; |
| 347 |
|
} |
| 348 |
|
return robject; |
| 349 |
|
} |
| 350 |
|
|
| 351 |
|
public RexObjectProperties GetObject(UUID id) |
| 352 |
|
{ |
| 353 |
|
RexObjectProperties props = RexObjectPropertiesCache[id]; |
| 354 |
|
if (props == null) |
| 355 |
|
{ |
| 356 |
|
props = new RexObjectProperties(id, this); |
| 357 |
|
RexObjectPropertiesCache.Add(id, props); |
| 358 |
|
} |
| 359 |
|
return props; |
| 360 |
|
} |
| 361 |
|
|
| 362 |
|
public List<RexObjectProperties> GetObjects() |
| 363 |
|
{ |
| 364 |
|
return RexObjectPropertiesCache.GetAllRexObjectProperties(); |
| 365 |
|
} |
| 366 |
|
|
| 367 |
|
public bool DeleteObject(UUID id) |
| 368 |
|
{ |
| 369 |
|
if (RexObjectPropertiesCache.ContainsKey(id)) |
| 370 |
|
{ |
| 371 |
|
RexObjectPropertiesCache.Remove(id); |
| 372 |
|
m_db.RemoveObject(id); |
| 373 |
|
return true; |
| 374 |
|
} |
| 375 |
|
return false; |
| 376 |
|
} |
| 377 |
|
|
| 378 |
|
|
| 379 |
|
#endregion |
| 380 |
|
|
| 381 |
} |
} |
| 382 |
} |
} |