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

