Annotation of /trunk/DefaultRenderer/DefaultDataControl.cs
Parent Directory
|
Revision Log
Revision 115 - (view) (download)
| 1 : | albert | 94 | using System; |
| 2 : | using System.Collections.Generic; | ||
| 3 : | using System.Linq; | ||
| 4 : | using System.Text; | ||
| 5 : | using Xenki.Framework; | ||
| 6 : | using System.Windows.Media.Media3D; | ||
| 7 : | using OpenMetaverse; | ||
| 8 : | using OpenMetaverse.Rendering; | ||
| 9 : | using Quaternion = System.Windows.Media.Media3D.Quaternion; | ||
| 10 : | using Material = System.Windows.Media.Media3D.Material; | ||
| 11 : | |||
| 12 : | namespace Xenki.DefaultRenderer | ||
| 13 : | { | ||
| 14 : | public delegate void OnNewPrimitive(Visual3D visualPrim); | ||
| 15 : | |||
| 16 : | public class DefaultDataControl | ||
| 17 : | { | ||
| 18 : | public static int ModelsCount = 10000; | ||
| 19 : | public static int ActivePrimCount = 1000; | ||
| 20 : | public static int TextureCachedCount = 1000; | ||
| 21 : | |||
| 22 : | albert | 115 | //primitives in the scene with visual format |
| 23 : | albert | 94 | private readonly Dictionary<uint, Visual3D> m_models = new Dictionary<uint, Visual3D>(); |
| 24 : | albert | 115 | //primitives in scene with original data format |
| 25 : | albert | 94 | private readonly Dictionary<uint, Primitive> m_PrimModelsInScene = new Dictionary<uint, Primitive>(); |
| 26 : | |||
| 27 : | albert | 115 | //primitives and their parent. key:childlocalid value:parentlocalid |
| 28 : | albert | 94 | private readonly Dictionary<uint, uint> primitiveParent = new Dictionary<uint, uint>(); |
| 29 : | |||
| 30 : | private readonly Dictionary<uint, Primitive> m_modelsWatingParent = new Dictionary<uint, Primitive>(); | ||
| 31 : | |||
| 32 : | private readonly Dictionary<uint, UUID> m_VisualNeedTextures = new Dictionary<uint, UUID>(); | ||
| 33 : | albert | 115 | //texture materials. |
| 34 : | albert | 94 | private readonly Dictionary<UUID, Material> m_materials = new Dictionary<UUID, Material>(); |
| 35 : | albert | 115 | //used for store the models around the first person avatar within a certain distance. |
| 36 : | albert | 94 | private readonly Dictionary<uint, Visual3D> m_ActivedModels = new Dictionary<uint, Visual3D>(); |
| 37 : | |||
| 38 : | albert | 115 | //temp variable store the search result of certain models in scene. |
| 39 : | albert | 94 | public Dictionary<uint, Visual3D> workingDictionary_ModelsInscene = new Dictionary<uint, Visual3D>(); |
| 40 : | public Dictionary<uint, Visual3D> workingDic_ActivedModels = new Dictionary<uint, Visual3D>(); | ||
| 41 : | |||
| 42 : | |||
| 43 : | public Dictionary<uint, Visual3D>.Enumerator ModelsInScene | ||
| 44 : | { | ||
| 45 : | get | ||
| 46 : | { | ||
| 47 : | workingDictionary_ModelsInscene.Clear(); | ||
| 48 : | workingDictionary_ModelsInscene = null; | ||
| 49 : | |||
| 50 : | lock (m_models) | ||
| 51 : | { | ||
| 52 : | workingDictionary_ModelsInscene = m_models.ToDictionary(p => p.Key, v => v.Value); | ||
| 53 : | } | ||
| 54 : | |||
| 55 : | return workingDictionary_ModelsInscene.GetEnumerator(); | ||
| 56 : | } | ||
| 57 : | } | ||
| 58 : | |||
| 59 : | public Dictionary<uint, Primitive>.Enumerator PrimModelsInScene | ||
| 60 : | { | ||
| 61 : | get { return m_PrimModelsInScene.GetEnumerator(); } | ||
| 62 : | } | ||
| 63 : | |||
| 64 : | public IEnumerator<Primitive> ModelsWaitingParent | ||
| 65 : | { | ||
| 66 : | get { return m_modelsWatingParent.Values.GetEnumerator(); } | ||
| 67 : | } | ||
| 68 : | |||
| 69 : | public IEnumerator<uint> ModelsNeedTextures | ||
| 70 : | { | ||
| 71 : | get { return m_VisualNeedTextures.Keys.GetEnumerator(); } | ||
| 72 : | } | ||
| 73 : | |||
| 74 : | private static readonly DefaultDataControl singleton = new DefaultDataControl(); | ||
| 75 : | |||
| 76 : | public static DefaultDataControl SingleSceneDataManager() | ||
| 77 : | { | ||
| 78 : | return singleton; | ||
| 79 : | } | ||
| 80 : | private DefaultDataControl() { } | ||
| 81 : | |||
| 82 : | public void AddNewPrimitive(uint id, Visual3D visual, uint parentID) | ||
| 83 : | { | ||
| 84 : | lock (m_models) | ||
| 85 : | { | ||
| 86 : | m_models[id] = visual; | ||
| 87 : | primitiveParent[id] = parentID; | ||
| 88 : | } | ||
| 89 : | } | ||
| 90 : | |||
| 91 : | public bool SceneContainVisual(uint modelid) | ||
| 92 : | { | ||
| 93 : | bool b = false; | ||
| 94 : | lock (m_models) | ||
| 95 : | { | ||
| 96 : | b = m_models.ContainsKey(modelid); | ||
| 97 : | } | ||
| 98 : | |||
| 99 : | return b; | ||
| 100 : | } | ||
| 101 : | |||
| 102 : | public Visual3D GetVisualInScene(uint id) | ||
| 103 : | { | ||
| 104 : | Visual3D v = null; | ||
| 105 : | lock (m_models) | ||
| 106 : | if (m_models.ContainsKey(id)) | ||
| 107 : | v = m_models[id]; | ||
| 108 : | |||
| 109 : | return v; | ||
| 110 : | } | ||
| 111 : | |||
| 112 : | public void RemoveVisualInScene(uint id) | ||
| 113 : | { | ||
| 114 : | lock (m_models) | ||
| 115 : | { | ||
| 116 : | m_models.Remove(id); | ||
| 117 : | } | ||
| 118 : | } | ||
| 119 : | |||
| 120 : | public void AddNewPrimitivePrimData(Primitive data) | ||
| 121 : | { | ||
| 122 : | lock (m_PrimModelsInScene) | ||
| 123 : | { | ||
| 124 : | m_PrimModelsInScene[data.LocalID] = data; | ||
| 125 : | } | ||
| 126 : | } | ||
| 127 : | public void RemovePrimtivePrimData(uint id) | ||
| 128 : | { | ||
| 129 : | lock (m_PrimModelsInScene) | ||
| 130 : | m_PrimModelsInScene.Remove(id); | ||
| 131 : | } | ||
| 132 : | |||
| 133 : | |||
| 134 : | public void AddWaitingParentPrimitive(uint id, Primitive data) | ||
| 135 : | { | ||
| 136 : | lock (m_modelsWatingParent) | ||
| 137 : | { | ||
| 138 : | if (m_modelsWatingParent.ContainsKey(id)) | ||
| 139 : | m_modelsWatingParent.Remove(id); | ||
| 140 : | |||
| 141 : | m_modelsWatingParent.Add(id, data); | ||
| 142 : | } | ||
| 143 : | } | ||
| 144 : | |||
| 145 : | public void RemoveWaitingParentPrimitive(uint id) | ||
| 146 : | { | ||
| 147 : | lock (m_modelsWatingParent) | ||
| 148 : | { | ||
| 149 : | m_modelsWatingParent.Remove(id); | ||
| 150 : | } | ||
| 151 : | } | ||
| 152 : | public IEnumerator<Primitive> GetModelsWaitingParent(uint parentID) | ||
| 153 : | { | ||
| 154 : | List<Primitive> list = new List<Primitive>(); | ||
| 155 : | lock (m_modelsWatingParent) | ||
| 156 : | { | ||
| 157 : | foreach (Primitive child in m_modelsWatingParent.Values) | ||
| 158 : | { | ||
| 159 : | if (child.ParentID == parentID) | ||
| 160 : | list.Add(child); | ||
| 161 : | } | ||
| 162 : | } | ||
| 163 : | |||
| 164 : | return list.GetEnumerator(); | ||
| 165 : | } | ||
| 166 : | |||
| 167 : | private uint? FindKeyByValue(Visual3D value) | ||
| 168 : | { | ||
| 169 : | uint? returnValue = null; | ||
| 170 : | object obj = value.GetValue(DefaultRenderer.depIdentity); | ||
| 171 : | if (obj != null) | ||
| 172 : | { | ||
| 173 : | returnValue = (uint)obj; | ||
| 174 : | return returnValue; | ||
| 175 : | } | ||
| 176 : | |||
| 177 : | //lock (m_models) | ||
| 178 : | //{ | ||
| 179 : | // foreach (KeyValuePair<uint, Visual3D> pair in m_models) | ||
| 180 : | // { | ||
| 181 : | // if (pair.Value.Equals(value)) | ||
| 182 : | // returnValue = pair.Key; | ||
| 183 : | // } | ||
| 184 : | //} | ||
| 185 : | return returnValue; | ||
| 186 : | } | ||
| 187 : | |||
| 188 : | public uint? GetKeyInSceneByValue(Visual3D visual) | ||
| 189 : | { | ||
| 190 : | return FindKeyByValue(visual); | ||
| 191 : | } | ||
| 192 : | |||
| 193 : | public IEnumerator<Visual3D> GetChildrenByVisual3D(Visual3D parent) | ||
| 194 : | { | ||
| 195 : | uint? key = FindKeyByValue(parent); | ||
| 196 : | if (key.HasValue == false) | ||
| 197 : | return new List<Visual3D>.Enumerator(); | ||
| 198 : | |||
| 199 : | List<Visual3D> children = new List<Visual3D>(); | ||
| 200 : | foreach (KeyValuePair<uint, uint> child in primitiveParent) | ||
| 201 : | { | ||
| 202 : | if (child.Value == key.Value) | ||
| 203 : | children.Add(m_models[child.Key]); | ||
| 204 : | } | ||
| 205 : | return children.GetEnumerator(); | ||
| 206 : | } | ||
| 207 : | |||
| 208 : | public void AddNeedTextureModel(uint model, UUID textureID) | ||
| 209 : | { | ||
| 210 : | lock (m_VisualNeedTextures) | ||
| 211 : | { | ||
| 212 : | if (m_VisualNeedTextures.ContainsKey(model) == true) | ||
| 213 : | m_VisualNeedTextures.Remove(model); | ||
| 214 : | m_VisualNeedTextures.Add(model, textureID); | ||
| 215 : | } | ||
| 216 : | } | ||
| 217 : | public void RemoveUnAttachedTexture(uint model) | ||
| 218 : | { | ||
| 219 : | lock (m_VisualNeedTextures) | ||
| 220 : | { | ||
| 221 : | if (m_VisualNeedTextures.ContainsKey(model)) | ||
| 222 : | m_VisualNeedTextures.Remove(model); | ||
| 223 : | } | ||
| 224 : | } | ||
| 225 : | |||
| 226 : | public IEnumerator<Primitive> GetVisualByTextureID(UUID textureID) | ||
| 227 : | { | ||
| 228 : | List<Primitive> list = new List<Primitive>(); | ||
| 229 : | lock (m_VisualNeedTextures) | ||
| 230 : | { | ||
| 231 : | foreach (KeyValuePair<uint, UUID> pair in m_VisualNeedTextures) | ||
| 232 : | { | ||
| 233 : | if (pair.Value == textureID) | ||
| 234 : | { | ||
| 235 : | if (m_modelsWatingParent.ContainsKey(pair.Key) == true) | ||
| 236 : | continue; | ||
| 237 : | |||
| 238 : | lock (m_PrimModelsInScene) | ||
| 239 : | { | ||
| 240 : | if (m_PrimModelsInScene.ContainsKey(pair.Key) == false) | ||
| 241 : | continue; | ||
| 242 : | list.Add(m_PrimModelsInScene[pair.Key]); | ||
| 243 : | } | ||
| 244 : | } | ||
| 245 : | } | ||
| 246 : | } | ||
| 247 : | |||
| 248 : | return list.GetEnumerator(); | ||
| 249 : | } | ||
| 250 : | |||
| 251 : | //public void AddModelsParentPositions(uint id, Vector3 pos) | ||
| 252 : | //{ | ||
| 253 : | // lock (m_parentPositions) | ||
| 254 : | // { | ||
| 255 : | // if (m_parentPositions.ContainsKey(id)) | ||
| 256 : | // m_parentPositions[id] = pos; | ||
| 257 : | // else | ||
| 258 : | // m_parentPositions.Add(id, pos); | ||
| 259 : | // } | ||
| 260 : | //} | ||
| 261 : | //public Vector3 GetModelsParentPosition(uint id) | ||
| 262 : | //{ | ||
| 263 : | // Vector3 vec = new Vector3(); | ||
| 264 : | // lock (m_parentPositions) | ||
| 265 : | // { | ||
| 266 : | // if (m_parentPositions.ContainsKey(id)) | ||
| 267 : | // vec = m_parentPositions[id]; | ||
| 268 : | // } | ||
| 269 : | // return vec; | ||
| 270 : | //} | ||
| 271 : | |||
| 272 : | public Primitive GetParentRotation(uint parentid) | ||
| 273 : | { | ||
| 274 : | uint temp = parentid; | ||
| 275 : | lock (m_PrimModelsInScene) | ||
| 276 : | while (m_PrimModelsInScene.ContainsKey(parentid)) | ||
| 277 : | { | ||
| 278 : | temp = parentid; | ||
| 279 : | parentid = m_PrimModelsInScene[parentid].ParentID; | ||
| 280 : | } | ||
| 281 : | |||
| 282 : | return m_PrimModelsInScene[temp]; | ||
| 283 : | } | ||
| 284 : | |||
| 285 : | public void AddNewMaterial2Cache(UUID textureID, System.Windows.Media.Media3D.Material material) | ||
| 286 : | { | ||
| 287 : | lock (m_materials) | ||
| 288 : | { | ||
| 289 : | if (m_materials.ContainsKey(textureID) == false) | ||
| 290 : | { | ||
| 291 : | m_materials.Add(textureID, material); | ||
| 292 : | } | ||
| 293 : | } | ||
| 294 : | } | ||
| 295 : | public Material GetMaterialFromCache(UUID textureID) | ||
| 296 : | { | ||
| 297 : | Material m = null; | ||
| 298 : | lock (m_materials) | ||
| 299 : | if (m_materials.ContainsKey(textureID)) | ||
| 300 : | m = m_materials[textureID]; | ||
| 301 : | |||
| 302 : | |||
| 303 : | return m; | ||
| 304 : | } | ||
| 305 : | public void RemoveMaterialFromCache(UUID textureID) | ||
| 306 : | { | ||
| 307 : | lock (m_materials) | ||
| 308 : | { | ||
| 309 : | m_materials.Remove(textureID); | ||
| 310 : | } | ||
| 311 : | } | ||
| 312 : | |||
| 313 : | public void AddActiveModel(Visual3D v) | ||
| 314 : | { | ||
| 315 : | uint? key = FindKeyByValue(v); | ||
| 316 : | if (key.HasValue) | ||
| 317 : | { | ||
| 318 : | lock (m_ActivedModels) | ||
| 319 : | { | ||
| 320 : | if (m_ActivedModels.ContainsKey(key.Value)) | ||
| 321 : | m_ActivedModels.Remove(key.Value); | ||
| 322 : | m_ActivedModels.Add(key.Value, v); | ||
| 323 : | } | ||
| 324 : | } | ||
| 325 : | } | ||
| 326 : | |||
| 327 : | public void RemoveActiveModel(Visual3D v) | ||
| 328 : | { | ||
| 329 : | uint? key = FindKeyByValue(v); | ||
| 330 : | if (key.HasValue) | ||
| 331 : | { | ||
| 332 : | lock (m_ActivedModels) | ||
| 333 : | { | ||
| 334 : | m_ActivedModels.Remove(key.Value); | ||
| 335 : | } | ||
| 336 : | } | ||
| 337 : | |||
| 338 : | } | ||
| 339 : | |||
| 340 : | public Dictionary<uint, Visual3D>.Enumerator GetActivedModelList() | ||
| 341 : | { | ||
| 342 : | workingDic_ActivedModels.Clear(); | ||
| 343 : | |||
| 344 : | lock (m_ActivedModels) | ||
| 345 : | workingDic_ActivedModels = m_ActivedModels.ToDictionary(p => p.Key, v => v.Value); | ||
| 346 : | |||
| 347 : | return workingDic_ActivedModels.GetEnumerator(); | ||
| 348 : | } | ||
| 349 : | |||
| 350 : | public Visual3D GetActivedModel(uint localid) | ||
| 351 : | { | ||
| 352 : | lock (m_ActivedModels) | ||
| 353 : | if (m_ActivedModels.ContainsKey(localid)) | ||
| 354 : | return m_ActivedModels[localid]; | ||
| 355 : | |||
| 356 : | return null; | ||
| 357 : | } | ||
| 358 : | |||
| 359 : | |||
| 360 : | public Primitive GetPrimInScene(uint localid) | ||
| 361 : | { | ||
| 362 : | lock (m_PrimModelsInScene) | ||
| 363 : | { | ||
| 364 : | if (m_PrimModelsInScene.ContainsKey(localid) == false) | ||
| 365 : | return null; | ||
| 366 : | } | ||
| 367 : | |||
| 368 : | return m_PrimModelsInScene[localid]; | ||
| 369 : | } | ||
| 370 : | public void RemovePrimInScene(uint localid) | ||
| 371 : | { | ||
| 372 : | lock (m_PrimModelsInScene) | ||
| 373 : | m_PrimModelsInScene.Remove(localid); | ||
| 374 : | } | ||
| 375 : | public Dictionary<uint, Primitive>.Enumerator GetPrimChildrenInScene(uint parentid) | ||
| 376 : | { | ||
| 377 : | Dictionary<uint, Primitive> result = new Dictionary<uint, Primitive>(); | ||
| 378 : | foreach (KeyValuePair<uint, uint> value in primitiveParent) | ||
| 379 : | if (value.Value == parentid) | ||
| 380 : | { | ||
| 381 : | |||
| 382 : | lock (m_PrimModelsInScene) | ||
| 383 : | { | ||
| 384 : | result.Add(value.Key, m_PrimModelsInScene[value.Key]); | ||
| 385 : | } | ||
| 386 : | } | ||
| 387 : | return result.GetEnumerator(); | ||
| 388 : | } | ||
| 389 : | |||
| 390 : | #region Friends | ||
| 391 : | |||
| 392 : | private Dictionary<string, Friend> FriendList = new Dictionary<string, Friend>(); | ||
| 393 : | |||
| 394 : | #endregion | ||
| 395 : | } | ||
| 396 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

