diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs | 164 |
1 files changed, 79 insertions, 85 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs index 8cdebcd..8fd8d1f 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs | |||
@@ -66,14 +66,19 @@ namespace OpenSim.Region.ClientStack.Linden | |||
66 | private bool m_persistBakedTextures; | 66 | private bool m_persistBakedTextures; |
67 | 67 | ||
68 | private IBakedTextureModule m_BakedTextureModule; | 68 | private IBakedTextureModule m_BakedTextureModule; |
69 | private string m_URL; | ||
69 | 70 | ||
70 | public void Initialise(IConfigSource source) | 71 | public void Initialise(IConfigSource source) |
71 | { | 72 | { |
73 | IConfig config = source.Configs["ClientStack.LindenCaps"]; | ||
74 | if (config == null) | ||
75 | return; | ||
76 | |||
77 | m_URL = config.GetString("Cap_UploadBakedTexture", string.Empty); | ||
78 | |||
72 | IConfig appearanceConfig = source.Configs["Appearance"]; | 79 | IConfig appearanceConfig = source.Configs["Appearance"]; |
73 | if (appearanceConfig != null) | 80 | if (appearanceConfig != null) |
74 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); | 81 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); |
75 | |||
76 | |||
77 | } | 82 | } |
78 | 83 | ||
79 | public void AddRegion(Scene s) | 84 | public void AddRegion(Scene s) |
@@ -89,9 +94,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
89 | s.EventManager.OnRemovePresence -= DeRegisterPresence; | 94 | s.EventManager.OnRemovePresence -= DeRegisterPresence; |
90 | m_BakedTextureModule = null; | 95 | m_BakedTextureModule = null; |
91 | m_scene = null; | 96 | m_scene = null; |
92 | } | 97 | } |
93 | |||
94 | |||
95 | 98 | ||
96 | public void RegionLoaded(Scene s) | 99 | public void RegionLoaded(Scene s) |
97 | { | 100 | { |
@@ -103,44 +106,52 @@ namespace OpenSim.Region.ClientStack.Linden | |||
103 | 106 | ||
104 | private void DeRegisterPresence(UUID agentId) | 107 | private void DeRegisterPresence(UUID agentId) |
105 | { | 108 | { |
106 | ScenePresence presence = null; | ||
107 | if (m_scene.TryGetScenePresence(agentId, out presence)) | ||
108 | { | ||
109 | presence.ControllingClient.OnSetAppearance -= CaptureAppearanceSettings; | ||
110 | } | ||
111 | |||
112 | } | 109 | } |
113 | 110 | ||
114 | private void RegisterNewPresence(ScenePresence presence) | 111 | private void RegisterNewPresence(ScenePresence presence) |
115 | { | 112 | { |
116 | presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings; | 113 | // presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings; |
117 | |||
118 | } | 114 | } |
119 | 115 | ||
120 | private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems) | 116 | /* not in use. work done in AvatarFactoryModule ValidateBakedTextureCache() and UpdateBakedTextureCache() |
121 | { | 117 | private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems) |
122 | int maxCacheitemsLoop = cacheItems.Length; | ||
123 | if (maxCacheitemsLoop > AvatarWearable.MAX_WEARABLES) | ||
124 | { | ||
125 | maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES; | ||
126 | m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES); | ||
127 | } | ||
128 | |||
129 | m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); | ||
130 | if (cacheItems.Length > 0) | ||
131 | { | ||
132 | // m_log.Debug("[Cacheitems]: " + cacheItems.Length); | ||
133 | // for (int iter = 0; iter < maxCacheitemsLoop; iter++) | ||
134 | // { | ||
135 | // m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" + | ||
136 | // cacheItems[iter].TextureID); | ||
137 | // } | ||
138 | |||
139 | ScenePresence p = null; | ||
140 | if (m_scene.TryGetScenePresence(remoteClient.AgentId, out p)) | ||
141 | { | 118 | { |
119 | // if cacheItems.Length > 0 viewer is giving us current textures information. | ||
120 | // baked ones should had been uploaded and in assets cache as local itens | ||
121 | |||
122 | |||
123 | if (cacheItems.Length == 0) | ||
124 | return; // no textures information, nothing to do | ||
125 | |||
126 | ScenePresence p = null; | ||
127 | if (!m_scene.TryGetScenePresence(remoteClient.AgentId, out p)) | ||
128 | return; // what are we doing if there is no presence to cache for? | ||
129 | |||
130 | if (p.IsDeleted) | ||
131 | return; // does this really work? | ||
132 | |||
133 | int maxCacheitemsLoop = cacheItems.Length; | ||
134 | if (maxCacheitemsLoop > 20) | ||
135 | { | ||
136 | maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES; | ||
137 | m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES); | ||
138 | } | ||
139 | |||
140 | m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); | ||
141 | |||
142 | |||
143 | // some nice debug | ||
144 | m_log.Debug("[Cacheitems]: " + cacheItems.Length); | ||
145 | for (int iter = 0; iter < maxCacheitemsLoop; iter++) | ||
146 | { | ||
147 | m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" + | ||
148 | cacheItems[iter].TextureID); | ||
149 | } | ||
150 | |||
151 | // p.Appearance.WearableCacheItems is in memory primary cashID to textures mapper | ||
142 | 152 | ||
143 | WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems; | 153 | WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems; |
154 | |||
144 | if (existingitems == null) | 155 | if (existingitems == null) |
145 | { | 156 | { |
146 | if (m_BakedTextureModule != null) | 157 | if (m_BakedTextureModule != null) |
@@ -154,38 +165,22 @@ namespace OpenSim.Region.ClientStack.Linden | |||
154 | p.Appearance.WearableCacheItems = savedcache; | 165 | p.Appearance.WearableCacheItems = savedcache; |
155 | p.Appearance.WearableCacheItemsDirty = false; | 166 | p.Appearance.WearableCacheItemsDirty = false; |
156 | } | 167 | } |
157 | |||
158 | } | ||
159 | /* | ||
160 | * The following Catch types DO NOT WORK with m_BakedTextureModule.Get | ||
161 | * it jumps to the General Packet Exception Handler if you don't catch Exception! | ||
162 | * | ||
163 | catch (System.Net.Sockets.SocketException) | ||
164 | { | ||
165 | cacheItems = null; | ||
166 | } | 168 | } |
167 | catch (WebException) | 169 | |
168 | { | ||
169 | cacheItems = null; | ||
170 | } | ||
171 | catch (InvalidOperationException) | ||
172 | { | ||
173 | cacheItems = null; | ||
174 | } */ | ||
175 | catch (Exception) | 170 | catch (Exception) |
176 | { | 171 | { |
177 | // The service logs a sufficient error message. | 172 | // The service logs a sufficient error message. |
178 | } | 173 | } |
179 | 174 | ||
180 | 175 | ||
181 | if (savedcache != null) | 176 | if (savedcache != null) |
182 | existingitems = savedcache; | 177 | existingitems = savedcache; |
183 | } | 178 | } |
184 | } | 179 | } |
180 | |||
185 | // Existing items null means it's a fully new appearance | 181 | // Existing items null means it's a fully new appearance |
186 | if (existingitems == null) | 182 | if (existingitems == null) |
187 | { | 183 | { |
188 | |||
189 | for (int i = 0; i < maxCacheitemsLoop; i++) | 184 | for (int i = 0; i < maxCacheitemsLoop; i++) |
190 | { | 185 | { |
191 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) | 186 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) |
@@ -198,7 +193,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
198 | AppearanceManager.DEFAULT_AVATAR_TEXTURE; | 193 | AppearanceManager.DEFAULT_AVATAR_TEXTURE; |
199 | continue; | 194 | continue; |
200 | } | 195 | } |
201 | cacheItems[i].TextureID =face.TextureID; | 196 | cacheItems[i].TextureID = face.TextureID; |
202 | if (m_scene.AssetService != null) | 197 | if (m_scene.AssetService != null) |
203 | cacheItems[i].TextureAsset = | 198 | cacheItems[i].TextureAsset = |
204 | m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString()); | 199 | m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString()); |
@@ -207,15 +202,10 @@ namespace OpenSim.Region.ClientStack.Linden | |||
207 | { | 202 | { |
208 | m_log.WarnFormat("[CACHEDBAKES]: Invalid Texture Index Provided, Texture doesn't exist or hasn't been uploaded yet {0}, the max is {1}. Skipping!", cacheItems[i].TextureIndex, textureEntry.FaceTextures.Length); | 203 | m_log.WarnFormat("[CACHEDBAKES]: Invalid Texture Index Provided, Texture doesn't exist or hasn't been uploaded yet {0}, the max is {1}. Skipping!", cacheItems[i].TextureIndex, textureEntry.FaceTextures.Length); |
209 | } | 204 | } |
210 | |||
211 | |||
212 | } | 205 | } |
213 | } | 206 | } |
214 | else | 207 | else |
215 | 208 | { | |
216 | |||
217 | { | ||
218 | // for each uploaded baked texture | ||
219 | for (int i = 0; i < maxCacheitemsLoop; i++) | 209 | for (int i = 0; i < maxCacheitemsLoop; i++) |
220 | { | 210 | { |
221 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) | 211 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) |
@@ -246,23 +236,24 @@ namespace OpenSim.Region.ClientStack.Linden | |||
246 | } | 236 | } |
247 | } | 237 | } |
248 | } | 238 | } |
249 | |||
250 | |||
251 | |||
252 | p.Appearance.WearableCacheItems = cacheItems; | 239 | p.Appearance.WearableCacheItems = cacheItems; |
253 | |||
254 | |||
255 | 240 | ||
256 | if (m_BakedTextureModule != null) | 241 | if (m_BakedTextureModule != null) |
257 | { | 242 | { |
258 | m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems); | 243 | m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems); |
259 | p.Appearance.WearableCacheItemsDirty = true; | 244 | p.Appearance.WearableCacheItemsDirty = true; |
260 | 245 | ||
261 | } | 246 | } |
262 | } | 247 | else |
263 | } | 248 | p.Appearance.WearableCacheItemsDirty = false; |
264 | } | ||
265 | 249 | ||
250 | for (int iter = 0; iter < maxCacheitemsLoop; iter++) | ||
251 | { | ||
252 | m_log.Debug("[CacheitemsLeaving] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" + | ||
253 | cacheItems[iter].TextureID); | ||
254 | } | ||
255 | } | ||
256 | */ | ||
266 | public void PostInitialise() | 257 | public void PostInitialise() |
267 | { | 258 | { |
268 | } | 259 | } |
@@ -280,23 +271,26 @@ namespace OpenSim.Region.ClientStack.Linden | |||
280 | 271 | ||
281 | public void RegisterCaps(UUID agentID, Caps caps) | 272 | public void RegisterCaps(UUID agentID, Caps caps) |
282 | { | 273 | { |
283 | UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler( | 274 | //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture)); |
284 | caps, m_scene.AssetService, m_persistBakedTextures); | 275 | if (m_URL == "localhost") |
276 | { | ||
277 | UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler( | ||
278 | caps, m_scene.AssetService, m_persistBakedTextures); | ||
285 | 279 | ||
286 | 280 | caps.RegisterHandler( | |
287 | |||
288 | caps.RegisterHandler( | ||
289 | "UploadBakedTexture", | ||
290 | new RestStreamHandler( | ||
291 | "POST", | ||
292 | "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath, | ||
293 | avatarhandler.UploadBakedTexture, | ||
294 | "UploadBakedTexture", | 281 | "UploadBakedTexture", |
295 | agentID.ToString())); | 282 | new RestStreamHandler( |
296 | 283 | "POST", | |
297 | 284 | "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath, | |
298 | 285 | avatarhandler.UploadBakedTexture, | |
299 | 286 | "UploadBakedTexture", | |
287 | agentID.ToString())); | ||
288 | |||
289 | } | ||
290 | else | ||
291 | { | ||
292 | caps.RegisterHandler("UploadBakedTexture", m_URL); | ||
293 | } | ||
300 | } | 294 | } |
301 | } | 295 | } |
302 | } | 296 | } |