diff options
author | onefang | 2019-09-11 16:36:50 +1000 |
---|---|---|
committer | onefang | 2019-09-11 16:36:50 +1000 |
commit | 50cd1ffd32f69228e566f2b0b89f86ea0d9fe489 (patch) | |
tree | 52f2ab0c04f1a5d7d6ac5dc872981b4b156447e7 /OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs | |
parent | Renamed branch to SledjChisl. (diff) | |
parent | Bump to release flavour, build 0. (diff) | |
download | opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.zip opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.gz opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.bz2 opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.xz |
Merge branch 'SledjChisl'
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs | 203 |
1 files changed, 23 insertions, 180 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs index 8cdebcd..b406b37 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs | |||
@@ -63,23 +63,23 @@ namespace OpenSim.Region.ClientStack.Linden | |||
63 | private static readonly string m_uploadBakedTexturePath = "0010/";// This is in the LandManagementModule. | 63 | private static readonly string m_uploadBakedTexturePath = "0010/";// This is in the LandManagementModule. |
64 | 64 | ||
65 | private Scene m_scene; | 65 | private Scene m_scene; |
66 | private bool m_persistBakedTextures; | ||
67 | 66 | ||
68 | private IBakedTextureModule m_BakedTextureModule; | 67 | private string m_URL; |
69 | 68 | ||
70 | public void Initialise(IConfigSource source) | 69 | public void Initialise(IConfigSource source) |
71 | { | 70 | { |
72 | IConfig appearanceConfig = source.Configs["Appearance"]; | 71 | IConfig config = source.Configs["ClientStack.LindenCaps"]; |
73 | if (appearanceConfig != null) | 72 | if (config == null) |
74 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); | 73 | return; |
75 | 74 | ||
75 | m_URL = config.GetString("Cap_UploadBakedTexture", string.Empty); | ||
76 | 76 | ||
77 | // IConfig appearanceConfig = source.Configs["Appearance"]; | ||
77 | } | 78 | } |
78 | 79 | ||
79 | public void AddRegion(Scene s) | 80 | public void AddRegion(Scene s) |
80 | { | 81 | { |
81 | m_scene = s; | 82 | m_scene = s; |
82 | |||
83 | } | 83 | } |
84 | 84 | ||
85 | public void RemoveRegion(Scene s) | 85 | public void RemoveRegion(Scene s) |
@@ -87,188 +87,28 @@ namespace OpenSim.Region.ClientStack.Linden | |||
87 | s.EventManager.OnRegisterCaps -= RegisterCaps; | 87 | s.EventManager.OnRegisterCaps -= RegisterCaps; |
88 | s.EventManager.OnNewPresence -= RegisterNewPresence; | 88 | s.EventManager.OnNewPresence -= RegisterNewPresence; |
89 | s.EventManager.OnRemovePresence -= DeRegisterPresence; | 89 | s.EventManager.OnRemovePresence -= DeRegisterPresence; |
90 | m_BakedTextureModule = null; | ||
91 | m_scene = null; | 90 | m_scene = null; |
92 | } | 91 | } |
93 | 92 | ||
94 | |||
95 | |||
96 | public void RegionLoaded(Scene s) | 93 | public void RegionLoaded(Scene s) |
97 | { | 94 | { |
98 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | 95 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; |
99 | m_scene.EventManager.OnNewPresence += RegisterNewPresence; | 96 | m_scene.EventManager.OnNewPresence += RegisterNewPresence; |
100 | m_scene.EventManager.OnRemovePresence += DeRegisterPresence; | 97 | m_scene.EventManager.OnRemovePresence += DeRegisterPresence; |
101 | |||
102 | } | 98 | } |
103 | 99 | ||
104 | private void DeRegisterPresence(UUID agentId) | 100 | private void DeRegisterPresence(UUID agentId) |
105 | { | 101 | { |
106 | ScenePresence presence = null; | ||
107 | if (m_scene.TryGetScenePresence(agentId, out presence)) | ||
108 | { | ||
109 | presence.ControllingClient.OnSetAppearance -= CaptureAppearanceSettings; | ||
110 | } | ||
111 | |||
112 | } | 102 | } |
113 | 103 | ||
114 | private void RegisterNewPresence(ScenePresence presence) | 104 | private void RegisterNewPresence(ScenePresence presence) |
115 | { | 105 | { |
116 | presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings; | ||
117 | |||
118 | } | ||
119 | |||
120 | private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems) | ||
121 | { | ||
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 | { | ||
142 | |||
143 | WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems; | ||
144 | if (existingitems == null) | ||
145 | { | ||
146 | if (m_BakedTextureModule != null) | ||
147 | { | ||
148 | WearableCacheItem[] savedcache = null; | ||
149 | try | ||
150 | { | ||
151 | if (p.Appearance.WearableCacheItemsDirty) | ||
152 | { | ||
153 | savedcache = m_BakedTextureModule.Get(p.UUID); | ||
154 | p.Appearance.WearableCacheItems = savedcache; | ||
155 | p.Appearance.WearableCacheItemsDirty = false; | ||
156 | } | ||
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 | } | ||
167 | catch (WebException) | ||
168 | { | ||
169 | cacheItems = null; | ||
170 | } | ||
171 | catch (InvalidOperationException) | ||
172 | { | ||
173 | cacheItems = null; | ||
174 | } */ | ||
175 | catch (Exception) | ||
176 | { | ||
177 | // The service logs a sufficient error message. | ||
178 | } | ||
179 | |||
180 | |||
181 | if (savedcache != null) | ||
182 | existingitems = savedcache; | ||
183 | } | ||
184 | } | ||
185 | // Existing items null means it's a fully new appearance | ||
186 | if (existingitems == null) | ||
187 | { | ||
188 | |||
189 | for (int i = 0; i < maxCacheitemsLoop; i++) | ||
190 | { | ||
191 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) | ||
192 | { | ||
193 | Primitive.TextureEntryFace face = textureEntry.FaceTextures[cacheItems[i].TextureIndex]; | ||
194 | if (face == null) | ||
195 | { | ||
196 | textureEntry.CreateFace(cacheItems[i].TextureIndex); | ||
197 | textureEntry.FaceTextures[cacheItems[i].TextureIndex].TextureID = | ||
198 | AppearanceManager.DEFAULT_AVATAR_TEXTURE; | ||
199 | continue; | ||
200 | } | ||
201 | cacheItems[i].TextureID =face.TextureID; | ||
202 | if (m_scene.AssetService != null) | ||
203 | cacheItems[i].TextureAsset = | ||
204 | m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString()); | ||
205 | } | ||
206 | else | ||
207 | { | ||
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); | ||
209 | } | ||
210 | |||
211 | |||
212 | } | ||
213 | } | ||
214 | else | ||
215 | |||
216 | |||
217 | { | ||
218 | // for each uploaded baked texture | ||
219 | for (int i = 0; i < maxCacheitemsLoop; i++) | ||
220 | { | ||
221 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) | ||
222 | { | ||
223 | Primitive.TextureEntryFace face = textureEntry.FaceTextures[cacheItems[i].TextureIndex]; | ||
224 | if (face == null) | ||
225 | { | ||
226 | textureEntry.CreateFace(cacheItems[i].TextureIndex); | ||
227 | textureEntry.FaceTextures[cacheItems[i].TextureIndex].TextureID = | ||
228 | AppearanceManager.DEFAULT_AVATAR_TEXTURE; | ||
229 | continue; | ||
230 | } | ||
231 | cacheItems[i].TextureID = | ||
232 | face.TextureID; | ||
233 | } | ||
234 | else | ||
235 | { | ||
236 | 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); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | for (int i = 0; i < maxCacheitemsLoop; i++) | ||
241 | { | ||
242 | if (cacheItems[i].TextureAsset == null) | ||
243 | { | ||
244 | cacheItems[i].TextureAsset = | ||
245 | m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString()); | ||
246 | } | ||
247 | } | ||
248 | } | ||
249 | |||
250 | |||
251 | |||
252 | p.Appearance.WearableCacheItems = cacheItems; | ||
253 | |||
254 | |||
255 | |||
256 | if (m_BakedTextureModule != null) | ||
257 | { | ||
258 | m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems); | ||
259 | p.Appearance.WearableCacheItemsDirty = true; | ||
260 | |||
261 | } | ||
262 | } | ||
263 | } | ||
264 | } | 106 | } |
265 | 107 | ||
266 | public void PostInitialise() | 108 | public void PostInitialise() |
267 | { | 109 | { |
268 | } | 110 | } |
269 | 111 | ||
270 | |||
271 | |||
272 | public void Close() { } | 112 | public void Close() { } |
273 | 113 | ||
274 | public string Name { get { return "UploadBakedTextureModule"; } } | 114 | public string Name { get { return "UploadBakedTextureModule"; } } |
@@ -280,23 +120,26 @@ namespace OpenSim.Region.ClientStack.Linden | |||
280 | 120 | ||
281 | public void RegisterCaps(UUID agentID, Caps caps) | 121 | public void RegisterCaps(UUID agentID, Caps caps) |
282 | { | 122 | { |
283 | UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler( | 123 | //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture)); |
284 | caps, m_scene.AssetService, m_persistBakedTextures); | 124 | if (m_URL == "localhost") |
125 | { | ||
126 | UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler( | ||
127 | caps, m_scene.AssetService); | ||
285 | 128 | ||
286 | 129 | caps.RegisterHandler( | |
287 | |||
288 | caps.RegisterHandler( | ||
289 | "UploadBakedTexture", | ||
290 | new RestStreamHandler( | ||
291 | "POST", | ||
292 | "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath, | ||
293 | avatarhandler.UploadBakedTexture, | ||
294 | "UploadBakedTexture", | 130 | "UploadBakedTexture", |
295 | agentID.ToString())); | 131 | new RestStreamHandler( |
296 | 132 | "POST", | |
297 | 133 | "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath, | |
298 | 134 | avatarhandler.UploadBakedTexture, | |
135 | "UploadBakedTexture", | ||
136 | agentID.ToString())); | ||
299 | 137 | ||
138 | } | ||
139 | else | ||
140 | { | ||
141 | caps.RegisterHandler("UploadBakedTexture", m_URL); | ||
142 | } | ||
300 | } | 143 | } |
301 | } | 144 | } |
302 | } | 145 | } |