diff options
author | dahlia | 2013-04-19 22:19:57 -0700 |
---|---|---|
committer | dahlia | 2013-04-19 22:19:57 -0700 |
commit | 258804cc043530927f442cd76337a3dab4ec742b (patch) | |
tree | 091a4f8b18525b9dd3514622f6dd24ae1ac06bb5 /OpenSim | |
parent | Materials-capable viewers send ImageUpdate packets when updating materials th... (diff) | |
download | opensim-SC_OLD-258804cc043530927f442cd76337a3dab4ec742b.zip opensim-SC_OLD-258804cc043530927f442cd76337a3dab4ec742b.tar.gz opensim-SC_OLD-258804cc043530927f442cd76337a3dab4ec742b.tar.bz2 opensim-SC_OLD-258804cc043530927f442cd76337a3dab4ec742b.tar.xz |
RenderMaterials POST Cap now return material entries when invoked with an OSDArray of MaterialIDs
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs | 169 |
1 files changed, 108 insertions, 61 deletions
diff --git a/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs b/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs index 74a4ea7..7002e66 100644 --- a/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs +++ b/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs | |||
@@ -48,7 +48,7 @@ using Ionic.Zlib; | |||
48 | // You will need to uncomment these lines if you are adding a region module to some other assembly which does not already | 48 | // You will need to uncomment these lines if you are adding a region module to some other assembly which does not already |
49 | // specify its assembly. Otherwise, the region modules in the assembly will not be picked up when OpenSimulator scans | 49 | // specify its assembly. Otherwise, the region modules in the assembly will not be picked up when OpenSimulator scans |
50 | // the available DLLs | 50 | // the available DLLs |
51 | //[assembly: Addin("MyModule", "1.0")] | 51 | //[assembly: Addin("MaterialsDemoModule", "1.0")] |
52 | //[assembly: AddinDependency("OpenSim", "0.5")] | 52 | //[assembly: AddinDependency("OpenSim", "0.5")] |
53 | 53 | ||
54 | namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | 54 | namespace OpenSim.Region.OptionalModules.MaterialsDemoModule |
@@ -159,6 +159,8 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
159 | 159 | ||
160 | OSDMap materialsFromViewer = null; | 160 | OSDMap materialsFromViewer = null; |
161 | 161 | ||
162 | OSDArray respArr = new OSDArray(); | ||
163 | |||
162 | if (req.ContainsKey("Zipped")) | 164 | if (req.ContainsKey("Zipped")) |
163 | { | 165 | { |
164 | OSD osd = null; | 166 | OSD osd = null; |
@@ -169,101 +171,145 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
169 | { | 171 | { |
170 | osd = ZDecompressBytesToOsd(inBytes); | 172 | osd = ZDecompressBytesToOsd(inBytes); |
171 | 173 | ||
172 | if (osd != null && osd is OSDMap) | 174 | if (osd != null) |
173 | { | 175 | { |
174 | materialsFromViewer = osd as OSDMap; | 176 | if (osd is OSDArray) // assume array of MaterialIDs designating requested material entries |
175 | |||
176 | if (materialsFromViewer.ContainsKey("FullMaterialsPerFace")) | ||
177 | { | 177 | { |
178 | OSD matsOsd = materialsFromViewer["FullMaterialsPerFace"]; | 178 | foreach (OSD elem in (OSDArray)osd) |
179 | if (matsOsd is OSDArray) | ||
180 | { | 179 | { |
181 | OSDArray matsArr = matsOsd as OSDArray; | ||
182 | 180 | ||
183 | try | 181 | try |
184 | { | 182 | { |
185 | foreach (OSDMap matsMap in matsArr) | 183 | UUID id = new UUID(elem.AsBinary(), 0); |
184 | |||
185 | if (m_knownMaterials.ContainsKey(id)) | ||
186 | { | ||
187 | m_log.Info("[MaterialsDemoModule]: request for known material ID: " + id.ToString()); | ||
188 | OSDMap matMap = new OSDMap(); | ||
189 | matMap["ID"] = OSD.FromBinary(id.GetBytes()); | ||
190 | |||
191 | matMap["Material"] = m_knownMaterials[id]; | ||
192 | respArr.Add(matMap); | ||
193 | } | ||
194 | else | ||
195 | m_log.Info("[MaterialsDemoModule]: request for UNKNOWN material ID: " + id.ToString()); | ||
196 | } | ||
197 | catch (Exception e) | ||
198 | { | ||
199 | // report something here? | ||
200 | continue; | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | else if (osd is OSDMap) // reqest to assign a material | ||
205 | { | ||
206 | materialsFromViewer = osd as OSDMap; | ||
207 | |||
208 | if (materialsFromViewer.ContainsKey("FullMaterialsPerFace")) | ||
209 | { | ||
210 | OSD matsOsd = materialsFromViewer["FullMaterialsPerFace"]; | ||
211 | if (matsOsd is OSDArray) | ||
212 | { | ||
213 | OSDArray matsArr = matsOsd as OSDArray; | ||
214 | |||
215 | try | ||
186 | { | 216 | { |
187 | m_log.Debug("[MaterialsDemoModule]: processing matsMap: " + OSDParser.SerializeJsonString(matsMap)); | 217 | foreach (OSDMap matsMap in matsArr) |
218 | { | ||
219 | m_log.Debug("[MaterialsDemoModule]: processing matsMap: " + OSDParser.SerializeJsonString(matsMap)); | ||
188 | 220 | ||
189 | uint matLocalID = 0; | 221 | uint matLocalID = 0; |
190 | try { matLocalID = matsMap["ID"].AsUInteger(); } | 222 | try { matLocalID = matsMap["ID"].AsUInteger(); } |
191 | catch (Exception e) { m_log.Warn("[MaterialsDemoModule]: cannot decode \"ID\" from matsMap: " + e.Message); } | 223 | catch (Exception e) { m_log.Warn("[MaterialsDemoModule]: cannot decode \"ID\" from matsMap: " + e.Message); } |
192 | m_log.Debug("[MaterialsDemoModule]: matLocalId: " + matLocalID.ToString()); | 224 | m_log.Debug("[MaterialsDemoModule]: matLocalId: " + matLocalID.ToString()); |
193 | 225 | ||
194 | 226 | ||
195 | OSDMap mat = null; | 227 | OSDMap mat = null; |
196 | try { mat = matsMap["Material"] as OSDMap; } | 228 | try { mat = matsMap["Material"] as OSDMap; } |
197 | catch (Exception e) { m_log.Warn("[MaterialsDemoModule]: cannot decode \"Material\" from matsMap: " + e.Message); } | 229 | catch (Exception e) { m_log.Warn("[MaterialsDemoModule]: cannot decode \"Material\" from matsMap: " + e.Message); } |
198 | m_log.Debug("[MaterialsDemoModule]: mat: " + OSDParser.SerializeJsonString(mat)); | 230 | m_log.Debug("[MaterialsDemoModule]: mat: " + OSDParser.SerializeJsonString(mat)); |
199 | 231 | ||
200 | UUID id = HashOsd(mat); | 232 | UUID id = HashOsd(mat); |
201 | m_knownMaterials[id] = mat; | 233 | m_knownMaterials[id] = mat; |
202 | 234 | ||
203 | 235 | ||
204 | var sop = m_scene.GetSceneObjectPart(matLocalID); | 236 | var sop = m_scene.GetSceneObjectPart(matLocalID); |
205 | if (sop == null) | 237 | if (sop == null) |
206 | m_log.Debug("[MaterialsDemoModule]: null SOP for localId: " + matLocalID.ToString()); | 238 | m_log.Debug("[MaterialsDemoModule]: null SOP for localId: " + matLocalID.ToString()); |
207 | else | ||
208 | { | ||
209 | var te = sop.Shape.Textures; | ||
210 | |||
211 | if (te == null) | ||
212 | { | ||
213 | m_log.Debug("[MaterialsDemoModule]: null TextureEntry for localId: " + matLocalID.ToString()); | ||
214 | } | ||
215 | else | 239 | else |
216 | { | 240 | { |
217 | int face = -1; | 241 | //var te = sop.Shape.Textures; |
242 | var te = new Primitive.TextureEntry(sop.Shape.TextureEntry, 0, sop.Shape.TextureEntry.Length); | ||
218 | 243 | ||
219 | if (matsMap.ContainsKey("Face")) | 244 | if (te == null) |
245 | { | ||
246 | m_log.Debug("[MaterialsDemoModule]: null TextureEntry for localId: " + matLocalID.ToString()); | ||
247 | } | ||
248 | else | ||
220 | { | 249 | { |
221 | face = matsMap["Face"].AsInteger(); | 250 | int face = -1; |
222 | if (te.FaceTextures == null) // && face == 0) | 251 | |
252 | if (matsMap.ContainsKey("Face")) | ||
223 | { | 253 | { |
224 | if (te.DefaultTexture == null) | 254 | face = matsMap["Face"].AsInteger(); |
225 | m_log.Debug("[MaterialsDemoModule]: te.DefaultTexture is null"); | 255 | if (te.FaceTextures == null) // && face == 0) |
226 | else | ||
227 | { | 256 | { |
228 | if (te.DefaultTexture.MaterialID == null) | 257 | if (te.DefaultTexture == null) |
229 | m_log.Debug("[MaterialsDemoModule]: te.DefaultTexture.MaterialID is null"); | 258 | m_log.Debug("[MaterialsDemoModule]: te.DefaultTexture is null"); |
230 | else | 259 | else |
231 | { | 260 | { |
232 | te.DefaultTexture.MaterialID = id; | 261 | if (te.DefaultTexture.MaterialID == null) |
262 | m_log.Debug("[MaterialsDemoModule]: te.DefaultTexture.MaterialID is null"); | ||
263 | else | ||
264 | { | ||
265 | te.DefaultTexture.MaterialID = id; | ||
266 | } | ||
267 | } | ||
268 | } | ||
269 | else | ||
270 | { | ||
271 | if (te.FaceTextures.Length >= face - 1) | ||
272 | { | ||
273 | if (te.FaceTextures[face] == null) | ||
274 | te.DefaultTexture.MaterialID = id; | ||
275 | else | ||
276 | te.FaceTextures[face].MaterialID = id; | ||
233 | } | 277 | } |
234 | } | 278 | } |
235 | } | 279 | } |
236 | else | 280 | else |
237 | { | 281 | { |
238 | if (te.FaceTextures.Length >= face - 1) | 282 | if (te.DefaultTexture != null) |
239 | { | 283 | te.DefaultTexture.MaterialID = id; |
240 | if (te.FaceTextures[face] == null) | ||
241 | te.DefaultTexture.MaterialID = id; | ||
242 | else | ||
243 | te.FaceTextures[face].MaterialID = id; | ||
244 | } | ||
245 | } | 284 | } |
246 | } | ||
247 | else | ||
248 | { | ||
249 | if (te.DefaultTexture != null) | ||
250 | te.DefaultTexture.MaterialID = id; | ||
251 | } | ||
252 | 285 | ||
253 | m_log.Debug("[MaterialsDemoModule]: setting material ID for face " + face.ToString() + " to " + id.ToString()); | 286 | m_log.Debug("[MaterialsDemoModule]: setting material ID for face " + face.ToString() + " to " + id.ToString()); |
287 | |||
288 | //we cant use sop.UpdateTextureEntry(te); because it filters so do it manually | ||
254 | 289 | ||
255 | sop.UpdateTextureEntry(te); | 290 | if (sop.ParentGroup != null) |
291 | { | ||
292 | sop.Shape.TextureEntry = te.GetBytes(); | ||
293 | sop.TriggerScriptChangedEvent(Changed.TEXTURE); | ||
294 | sop.UpdateFlag = UpdateRequired.FULL; | ||
295 | sop.ParentGroup.HasGroupChanged = true; | ||
296 | |||
297 | sop.ScheduleFullUpdate(); | ||
298 | |||
299 | } | ||
300 | } | ||
256 | } | 301 | } |
257 | } | 302 | } |
258 | } | 303 | } |
259 | } | 304 | catch (Exception e) |
260 | catch (Exception e) | 305 | { |
261 | { | 306 | m_log.Warn("[MaterialsDemoModule]: exception processing received material: " + e.Message); |
262 | m_log.Warn("[MaterialsDemoModule]: exception processing received material: " + e.Message); | 307 | } |
263 | } | 308 | } |
264 | } | 309 | } |
265 | } | 310 | } |
266 | } | 311 | } |
312 | |||
267 | } | 313 | } |
268 | catch (Exception e) | 314 | catch (Exception e) |
269 | { | 315 | { |
@@ -273,7 +319,8 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
273 | m_log.Debug("[MaterialsDemoModule]: knownMaterials.Count: " + m_knownMaterials.Count.ToString()); | 319 | m_log.Debug("[MaterialsDemoModule]: knownMaterials.Count: " + m_knownMaterials.Count.ToString()); |
274 | } | 320 | } |
275 | 321 | ||
276 | 322 | ||
323 | resp["Zipped"] = ZCompressOSD(respArr, false); | ||
277 | string response = OSDParser.SerializeLLSDXmlString(resp); | 324 | string response = OSDParser.SerializeLLSDXmlString(resp); |
278 | 325 | ||
279 | m_log.Debug("[MaterialsDemoModule]: cap request: " + request); | 326 | m_log.Debug("[MaterialsDemoModule]: cap request: " + request); |