Annotation of /trunk/DefaultDataControl/DefaultDataControl.cs
Parent Directory
|
Revision Log
Revision 36 - (view) (download)
| 1 : | albert | 33 | 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 : | |||
| 11 : | namespace Xenki.DefaultDataControl | ||
| 12 : | { | ||
| 13 : | public delegate void OnNewPrimitive(uint primid); | ||
| 14 : | |||
| 15 : | public class DefaultDataControl:IPrimitiveData | ||
| 16 : | { | ||
| 17 : | |||
| 18 : | public event OnNewPrimitive onNewPrimitive; | ||
| 19 : | |||
| 20 : | private readonly Dictionary<uint, Visual3D> m_models = new Dictionary<uint, Visual3D>(); | ||
| 21 : | albert | 34 | |
| 22 : | //key:children key value:parent | ||
| 23 : | private readonly Dictionary<uint, uint> primitiveParent = new Dictionary<uint, uint>(); | ||
| 24 : | |||
| 25 : | albert | 33 | private readonly Dictionary<uint, Vector3> m_parentPositions = new Dictionary<uint, Vector3>(); |
| 26 : | private readonly Dictionary<uint, Primitive> m_modelsWatingParent = new Dictionary<uint, Primitive>(); | ||
| 27 : | albert | 36 | private readonly Dictionary<uint, UUID> unAttachedTextures = new Dictionary<uint, UUID>(); |
| 28 : | albert | 35 | |
| 29 : | //private IRendering m_mesher; | ||
| 30 : | albert | 33 | |
| 31 : | public Dictionary<uint, Visual3D> ModelsInScene | ||
| 32 : | { | ||
| 33 : | get { return m_models; } | ||
| 34 : | } | ||
| 35 : | |||
| 36 : | public Dictionary<uint, Vector3> ModelsParentPositions | ||
| 37 : | { | ||
| 38 : | get { return m_parentPositions; } | ||
| 39 : | } | ||
| 40 : | public Dictionary<uint, Primitive> ModelsWaitingParent | ||
| 41 : | { | ||
| 42 : | get { return m_modelsWatingParent; } | ||
| 43 : | } | ||
| 44 : | albert | 35 | //public IRendering Mesher |
| 45 : | //{ | ||
| 46 : | // set { m_mesher = value; } | ||
| 47 : | //} | ||
| 48 : | |||
| 49 : | albert | 36 | public Dictionary<uint, UUID> UnAttachedTextures |
| 50 : | albert | 33 | { |
| 51 : | albert | 35 | get { return unAttachedTextures; } |
| 52 : | albert | 33 | } |
| 53 : | albert | 35 | |
| 54 : | albert | 34 | public void AddNewPrimitive(uint id,Visual3D visual,uint parentID)// Primitive prim) |
| 55 : | { | ||
| 56 : | albert | 33 | lock (m_models) |
| 57 : | { | ||
| 58 : | if (m_models.ContainsKey(id)) | ||
| 59 : | m_models.Remove(id); | ||
| 60 : | albert | 34 | m_models.Add(id,visual);// DefaultRenderer.DefaultUtil.CreateModel(prim, m_mesher)); |
| 61 : | if (primitiveParent.ContainsKey(id)) | ||
| 62 : | primitiveParent.Remove(id); | ||
| 63 : | primitiveParent.Add(id, parentID); | ||
| 64 : | |||
| 65 : | albert | 33 | } |
| 66 : | } | ||
| 67 : | |||
| 68 : | |||
| 69 : | /* | ||
| 70 : | bool Broken =false; | ||
| 71 : | |||
| 72 : | public void AddNewPrimitive(uint id, Primitive prim) | ||
| 73 : | { | ||
| 74 : | lock (m_parentPositions) | ||
| 75 : | { | ||
| 76 : | m_parentPositions[id] = prim.Position; | ||
| 77 : | } | ||
| 78 : | if (Broken) | ||
| 79 : | return; | ||
| 80 : | |||
| 81 : | lock (m_models) | ||
| 82 : | { | ||
| 83 : | try | ||
| 84 : | { | ||
| 85 : | if (m_models.ContainsKey(id)) | ||
| 86 : | { | ||
| 87 : | m_models.Remove(id); | ||
| 88 : | } | ||
| 89 : | bool WaitParentIn = true; | ||
| 90 : | lock (m_parentPositions) | ||
| 91 : | { | ||
| 92 : | if (m_parentPositions.ContainsKey(prim.ParentID)) | ||
| 93 : | { | ||
| 94 : | prim.Position += m_parentPositions[prim.ParentID]; | ||
| 95 : | |||
| 96 : | WaitParentIn = false; | ||
| 97 : | } | ||
| 98 : | else if (prim.ParentID == 0) | ||
| 99 : | { | ||
| 100 : | WaitParentIn = false; | ||
| 101 : | } | ||
| 102 : | } | ||
| 103 : | |||
| 104 : | // Add it to the scene appropriately. | ||
| 105 : | if (WaitParentIn == false) | ||
| 106 : | { | ||
| 107 : | ModelVisual3D model = DefaultRenderer.DefaultUtil.CreateModel(prim,m_mesher); | ||
| 108 : | |||
| 109 : | m_models.Add(prim.LocalID,model); | ||
| 110 : | |||
| 111 : | foreach (Primitive m in ModelsWaitingParent.Values) | ||
| 112 : | { | ||
| 113 : | if (m.ParentID == id) | ||
| 114 : | { | ||
| 115 : | model = DefaultRenderer.DefaultUtil.CreateModel(m, m_mesher); | ||
| 116 : | m_models.Add(m.LocalID, model); | ||
| 117 : | |||
| 118 : | RemoveWaitingParentPrimitive(m.LocalID); | ||
| 119 : | } | ||
| 120 : | } | ||
| 121 : | } | ||
| 122 : | else | ||
| 123 : | AddWaitingParentPrimitive(id, prim); | ||
| 124 : | |||
| 125 : | } | ||
| 126 : | catch (Exception e) | ||
| 127 : | { | ||
| 128 : | Broken = true; | ||
| 129 : | } | ||
| 130 : | } | ||
| 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 : | public void RemoveWaitingParentPrimitive(uint id) | ||
| 145 : | { | ||
| 146 : | lock (m_modelsWatingParent) | ||
| 147 : | { | ||
| 148 : | if(m_modelsWatingParent.ContainsKey(id)) | ||
| 149 : | m_modelsWatingParent.Remove(id); | ||
| 150 : | } | ||
| 151 : | } | ||
| 152 : | public List<Primitive> GetModelsWaitingParent() | ||
| 153 : | { | ||
| 154 : | return m_modelsWatingParent.Values.ToList(); | ||
| 155 : | } | ||
| 156 : | albert | 34 | |
| 157 : | albert | 35 | private uint? FindKeyByValue(Visual3D value) |
| 158 : | albert | 34 | { |
| 159 : | uint? returnValue=null; | ||
| 160 : | lock (m_models) | ||
| 161 : | { | ||
| 162 : | foreach (KeyValuePair<uint, Visual3D> pair in m_models) | ||
| 163 : | { | ||
| 164 : | if (pair.Value.Equals(value)) | ||
| 165 : | returnValue = pair.Key; | ||
| 166 : | } | ||
| 167 : | } | ||
| 168 : | |||
| 169 : | return returnValue; | ||
| 170 : | |||
| 171 : | } | ||
| 172 : | public List<Visual3D> GetChildrenByVisual3D(Visual3D parent) | ||
| 173 : | { | ||
| 174 : | uint? key = FindKeyByValue(parent); | ||
| 175 : | if (key.HasValue == false) | ||
| 176 : | return new List<Visual3D>(); | ||
| 177 : | |||
| 178 : | List<Visual3D> children = new List<Visual3D>(); | ||
| 179 : | foreach (KeyValuePair<uint, uint> child in primitiveParent) | ||
| 180 : | { | ||
| 181 : | if (child.Value == key.Value) | ||
| 182 : | children.Add(m_models[child.Key]); | ||
| 183 : | } | ||
| 184 : | return children; | ||
| 185 : | } | ||
| 186 : | albert | 35 | |
| 187 : | albert | 36 | public void AddUnAttachedTexture( uint model,UUID textureID) |
| 188 : | albert | 35 | { |
| 189 : | lock (unAttachedTextures) | ||
| 190 : | { | ||
| 191 : | if (unAttachedTextures.ContainsKey(model) == true) | ||
| 192 : | unAttachedTextures.Remove(model); | ||
| 193 : | unAttachedTextures.Add(model, textureID); | ||
| 194 : | } | ||
| 195 : | } | ||
| 196 : | |||
| 197 : | public List<Visual3D> GetVisualByTextureID(UUID textureID) | ||
| 198 : | { | ||
| 199 : | List<Visual3D> list = new List<Visual3D>(); | ||
| 200 : | lock (unAttachedTextures) | ||
| 201 : | { | ||
| 202 : | albert | 36 | foreach (KeyValuePair<uint,UUID> pair in unAttachedTextures) |
| 203 : | albert | 35 | { |
| 204 : | if (pair.Value == textureID) | ||
| 205 : | albert | 36 | { |
| 206 : | if(list.Contains(m_models[pair.Key])==false) | ||
| 207 : | |||
| 208 : | list.Add(m_models[ pair.Key]); | ||
| 209 : | |||
| 210 : | } | ||
| 211 : | albert | 35 | } |
| 212 : | } | ||
| 213 : | |||
| 214 : | return list; | ||
| 215 : | } | ||
| 216 : | |||
| 217 : | albert | 33 | } |
| 218 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

